perfsonar-dev - perfsonar: r5426 - in branches/new-structure-with-base2/ps-mdm-ls/src: main/java/org/perfsonar/service/lookupservice main/java/org/perfsonar/service/lookupservice/registration/summarization main/java/org/perfsonar/service/lookupservice/schedulerActions main/java/org/perfsonar/service/lookupservice/storage/exist/dao main/java/org/perfsonar/service/lookupservice/summarization test/java/org/perfsonar/tests/actions
Subject: perfsonar development work
List archive
perfsonar: r5426 - in branches/new-structure-with-base2/ps-mdm-ls/src: main/java/org/perfsonar/service/lookupservice main/java/org/perfsonar/service/lookupservice/registration/summarization main/java/org/perfsonar/service/lookupservice/schedulerActions main/java/org/perfsonar/service/lookupservice/storage/exist/dao main/java/org/perfsonar/service/lookupservice/summarization test/java/org/perfsonar/tests/actions
Chronological Thread
- From:
- To:
- Subject: perfsonar: r5426 - in branches/new-structure-with-base2/ps-mdm-ls/src: main/java/org/perfsonar/service/lookupservice main/java/org/perfsonar/service/lookupservice/registration/summarization main/java/org/perfsonar/service/lookupservice/schedulerActions main/java/org/perfsonar/service/lookupservice/storage/exist/dao main/java/org/perfsonar/service/lookupservice/summarization test/java/org/perfsonar/tests/actions
- Date: Mon, 21 Dec 2009 08:48:15 -0500
Author: trzaszcz
Date: 2009-12-21 08:48:15 -0500 (Mon, 21 Dec 2009)
New Revision: 5426
Removed:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSCleanupServiceEngine.java
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/AbstractRegisterServiceEngine.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/EchoServiceEngine.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/GenericLSServiceEngine.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSDeregisterServiceEngine.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSQueryServiceEngine.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSRegisterServiceEngine.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSRegistrationMessageHandler.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/TrieNode.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/schedulerActions/CleanupSchedulerAction.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/schedulerActions/GLSRegistrationAction.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/dao/MultipleFilesDAOImpl.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/ModificationCounterComponent.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/SummarizationBuilder.java
branches/new-structure-with-base2/ps-mdm-ls/src/test/java/org/perfsonar/tests/actions/EchoActionTests.java
Log:
code improvement
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/AbstractRegisterServiceEngine.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/AbstractRegisterServiceEngine.java
2009-12-17 14:03:13 UTC (rev 5425)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/AbstractRegisterServiceEngine.java
2009-12-21 13:48:15 UTC (rev 5426)
@@ -19,8 +19,6 @@
public abstract class AbstractRegisterServiceEngine
extends GenericLSServiceEngine implements ServiceEngine {
- //TODO: refactor - this class i superClass of others services which
aren't a typically registration
-
public final static String SERVICE_EVENT_TYPE =
"http://ogf.org/ns/nmwg/tools/org/perfsonar/service/lookup/registration/service/2.0";
public final static String SUMMARY_EVENT_TYPE =
"http://ogf.org/ns/nmwg/tools/org/perfsonar/service/lookup/registration/summary/2.0";
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/EchoServiceEngine.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/EchoServiceEngine.java
2009-12-17 14:03:13 UTC (rev 5425)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/EchoServiceEngine.java
2009-12-21 13:48:15 UTC (rev 5426)
@@ -39,20 +39,6 @@
super();
}
-
-
- private boolean isStringOccurInArray(String key,String [] array){
- for (String s : array) {
- if (s.equals(key)) {
- return true;
- }
- if ((s + "/").equals(key)) {
- return true;
- }
- }
- return false;
- }
-
/**
* Tests whether eventType is echo
*
@@ -60,7 +46,7 @@
* @return true if selftest
*/
private boolean isSelfTestEventTypeSupported(String evt) {
- return
isStringOccurInArray(evt,SUPPORTED_SELFTEST_EVENT_TYPES);
+ return isEventTypeOccurInArray(evt,
SUPPORTED_SELFTEST_EVENT_TYPES);
}
/**
@@ -70,7 +56,7 @@
* @return true if echo
*/
private boolean isEchoEventTypeSupported(String evt) {
- return isStringOccurInArray(evt,SUPPORTED_ECHO_EVENT_TYPES);
+ return isEventTypeOccurInArray(evt,
SUPPORTED_ECHO_EVENT_TYPES);
}
/**
@@ -109,41 +95,40 @@
Metadata metadata = getFirstMetadataFromRequest(request);
boolean selftest = false;
boolean echo = false;
- String eventType = null;
+ String strEventType = null;
- try {
- // check eventtype
- eventType =
metadata.getFirstEventType().getEventType();
- selftest = isSelfTestEventTypeSupported(eventType);
- echo = isEchoEventTypeSupported(eventType);
+ // check eventtype
+ EventType eventType = metadata.getFirstEventType();
+ if (eventType == null) {
+ throw new PerfSONARException(
+ "error/ls/no_eventtype",
+ "LS EchoRequest error: "
+ + "Error while
determining eventType (possibly no eventType at all). "
+ + "EventType must be
[" + getEventTypesString()
+ + "]. ");
+ } else {
+ strEventType = eventType.getEventType();
+ selftest = isSelfTestEventTypeSupported(strEventType);
+ echo = isEchoEventTypeSupported(strEventType);
if (!selftest && !echo)
throw new PerfSONARException(
"error/ls/eventtype_not_supported",
"LS EchoRequest error: " +
"Not supported event type ["
- + eventType +
"]. " + "Must be: ["
+ +
strEventType + "]. " + "Must be: ["
+
getEventTypesString() + "]");
- } catch (RuntimeException ex) {
- //TODO : refactor - change exception this exception !
- throw new PerfSONARException(
- "error/ls/no_eventtype",
- "LS EchoRequest error: "
- + "Error while
determining eventType (possibly no eventType at all). "
- + "EventType must be
[" + getEventTypesString()
- + "]. " + "Nested
exception is : "
- + ex.getMessage());
}
// Take action
Message msg = null;
logger.debug("Taking ECHO action");
-
+
// ECHO
if (echo) {
msg = takeEchoAction(serviceRequest);
- }else if (selftest) {// or SELFTEST
+ } else if (selftest) {// or SELFTEST
msg = takeSelfTestAction(serviceRequest);
}
@@ -199,33 +184,34 @@
* to be filled with result code
*/
private void testDBCollectionControl(Data data) {
-
- String messageName="exist-db-collection-store-control";
- String messageDescription="";
- String
postfixResult="/ls/selftest/collection/lsstore-control";
- String prefixResult="success";
-
+
+ String messageName = "exist-db-collection-store-control";
+ String messageDescription = "";
+ String postfixResult =
"/ls/selftest/collection/lsstore-control";
+ String prefixResult = "success";
+
try {
boolean test = dao
.isDBCollection(XQueryDAOSupportImpl.LS_STORE_CONTROL_COLLECTION_TYPE);
-
- if (test){
- prefixResult="success";
- messageDescription="collection
LSStore-control exists and is accessible";
- }else{
- prefixResult="error";
- messageDescription="collection
LSStore-control doesn't exist and isn't accessible";
+
+ if (test) {
+ prefixResult = "success";
+ messageDescription = "collection
LSStore-control exists and is accessible";
+ } else {
+ prefixResult = "error";
+ messageDescription = "collection
LSStore-control doesn't exist and isn't accessible";
}
-
+
} catch (PerfSONARException ex) {
- prefixResult="error";
- messageDescription="collection LSStore-control does
not exist or is not accessible:"+ ex.getMessage();
+ prefixResult = "error";
+ messageDescription = "collection LSStore-control does
not exist or is not accessible:"
+ + ex.getMessage();
}
-
- addResultCode(data, messageName, prefixResult+postfixResult,
messageDescription);
+
+ addResultCode(data, messageName, prefixResult + postfixResult,
+ messageDescription);
}
-
/**
* Tests whether there is LSStorecollection
*
@@ -233,27 +219,30 @@
* to be filled with result code
*/
private void testDBCollectionSummary(Data data) {
-
- String messageName="exist-db-collection-store-summary";
- String messageDescription="";
- String postfixResult="/ls/selftest/collection/summary";
- String prefixResult="success";
-
+
+ String messageName = "exist-db-collection-store-summary";
+ String messageDescription = "";
+ String postfixResult = "/ls/selftest/collection/summary";
+ String prefixResult = "success";
+
try {
- boolean test =
dao.isDBCollection(XQueryDAOSupportImpl.LS_STORE_SUMMARY_COLLECTION_TYPE);
- if (test){
- prefixResult="success";
- messageDescription="collection
LSStore-summary exists and is accessible";
- }else{
- prefixResult="error";
- messageDescription="collection
LSStore-summary doesn't exist";
+ boolean test = dao
+
.isDBCollection(XQueryDAOSupportImpl.LS_STORE_SUMMARY_COLLECTION_TYPE);
+ if (test) {
+ prefixResult = "success";
+ messageDescription = "collection
LSStore-summary exists and is accessible";
+ } else {
+ prefixResult = "error";
+ messageDescription = "collection
LSStore-summary doesn't exist";
}
} catch (PerfSONARException ex) {
- prefixResult="error";
- messageDescription="collection LSStore-summary does
not exist or is not accessible:"+ ex.getMessage();
+ prefixResult = "error";
+ messageDescription = "collection LSStore-summary does
not exist or is not accessible:"
+ + ex.getMessage();
}
-
- addResultCode(data, messageName, prefixResult+postfixResult,
messageDescription);
+
+ addResultCode(data, messageName, prefixResult + postfixResult,
+ messageDescription);
}
/**
@@ -264,7 +253,7 @@
*/
private void testDBConnectivity(Data data) {
try {
- if(dao.isDBConnectivity()){
+ if (dao.isDBConnectivity()) {
addResultCode(data, "exist-db-connectivity",
"success/ls/selftest/dbconnectivity",
"eXist DB connection
established");
@@ -306,7 +295,7 @@
meta.setId(name);
EventType evt = new EventType();
- evt.setEventType(PerfSONARException.RESULT_CODE_PREFIX+code);
+ evt.setEventType(PerfSONARException.RESULT_CODE_PREFIX +
code);
meta.setEventType(evt);
incomingData.addChild(meta);
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/GenericLSServiceEngine.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/GenericLSServiceEngine.java
2009-12-17 14:03:13 UTC (rev 5425)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/GenericLSServiceEngine.java
2009-12-21 13:48:15 UTC (rev 5426)
@@ -135,5 +135,24 @@
String txt = p.getText().trim();
return txt;
}
+
+ /**
+ *
+ * checks whether string occurs in string array
+ *
+ * @param needle
+ * @param haystack
+ * @return
+ */
+ protected boolean isEventTypeOccurInArray(String needle, String[]
haystack) {
+ for (String h : haystack) {
+ if (h.equals(needle))
+ return true;
+ else if (h.equals(needle + "/"))
+ return true;
+ }
+ return false;
+ }
+
}
\ No newline at end of file
Deleted:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSCleanupServiceEngine.java
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSDeregisterServiceEngine.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSDeregisterServiceEngine.java
2009-12-17 14:03:13 UTC (rev 5425)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSDeregisterServiceEngine.java
2009-12-21 13:48:15 UTC (rev 5426)
@@ -71,7 +71,7 @@
// inform about changes Component !
ModificationCounterComponent component =
getModifcationCounter();
- component.increaseCounter();
+ component.incrementCounter();
msg = ResultCodesUtil.generateResultMessage(null,
"success/ls/deregister", "Removed
total ["
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSQueryServiceEngine.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSQueryServiceEngine.java
2009-12-17 14:03:13 UTC (rev 5425)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSQueryServiceEngine.java
2009-12-21 13:48:15 UTC (rev 5426)
@@ -126,25 +126,12 @@
}
- private boolean eventTypeInArray(String needle, String[] haystack) {
-
- // TODO: this piece of code occurs somewhere in code ...
-
- for (String h : haystack) {
- if (h.equals(needle))
- return true;
- else if (h.equals(needle + "/"))
- return true;
- }
- return false;
- }
-
private boolean isLookupDiscovery(String queryType) {
- return eventTypeInArray(queryType, discoveryEventTypes);
+ return isEventTypeOccurInArray(queryType,
discoveryEventTypes);
}
private boolean isLookupQuery(String queryType) {
- return eventTypeInArray(queryType, queryEventTypes);
+ return isEventTypeOccurInArray(queryType, queryEventTypes);
}
}
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSRegisterServiceEngine.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSRegisterServiceEngine.java
2009-12-17 14:03:13 UTC (rev 5425)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSRegisterServiceEngine.java
2009-12-21 13:48:15 UTC (rev 5426)
@@ -232,7 +232,7 @@
// some element was added, ChangesRecorder should be informed
about it
ModificationCounterComponent component =
getModificationCounterComponent();
- component.increaseCounter();
+ component.incrementCounter();
logger.info("Put new Lookup Info (" + metadataId + ")
metadata + "
+ dataElements.length + " data elements");
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSRegistrationMessageHandler.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSRegistrationMessageHandler.java
2009-12-17 14:03:13 UTC (rev 5425)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSRegistrationMessageHandler.java
2009-12-21 13:48:15 UTC (rev 5426)
@@ -14,100 +14,81 @@
import org.perfsonar.base2.xml.nmwg.Message;
import org.perfsonar.base2.xml.nmwg.Metadata;
-
public class LSRegistrationMessageHandler extends GenericMessageHandler {
- private static final Logger logger =
Logger.getLogger(LSRegistrationMessageHandler.class.getName());
-
- public LSRegistrationMessageHandler() throws PerfSONARException {
+ private static final Logger logger = Logger
+
.getLogger(LSRegistrationMessageHandler.class.getName());
- super();
-
- }
+ public LSRegistrationMessageHandler() throws PerfSONARException {
+ super();
+ }
- protected ArrayList<Message> extractMultipleRequests(Message reqMessage)
{
-
- ArrayList<Message> messagesList = new ArrayList<Message>();
-
- //data chains container <String metadataIdRef, ArrayList<Data>>
- HashMap<String,Message> dataChains = new HashMap<String,Message>();
- org.perfsonar.base2.xml.Element parameters=null;
- List<org.perfsonar.base2.xml.Element>
parametersNodesList=(List<Element>) reqMessage.getChildren("parameters");
- if(parametersNodesList!=null && parametersNodesList.size()==1){
- parameters=parametersNodesList.get(0);
- }
-
- //get input data elements
- Collection<Data> dataTriggers = reqMessage.getDataMap().values();
-
- //for all data elelemtns
- for (Data data : dataTriggers) {
-
- //put all data having the same metadataIdRef to the same
container
- String metaref = data.getMetadataIdRef();
- if (dataChains.get(metaref)==null)
- dataChains.put(metaref, new Message());
- Message m = dataChains.get(metaref);
- m.setData(data);
- //System.out.println("## data ["+data.getId()+"] ->
["+metaref+"]");
-
- }
-
- //for each data elements set find chaining
- for (Map.Entry<String, Message> e : dataChains.entrySet()) {
+ protected ArrayList<Message> extractMultipleRequests(Message
reqMessage) {
- try {
+ ArrayList<Message> messagesList = new ArrayList<Message>();
- //get previously added message with data elements
- Message message = e.getValue();
- if(parameters!=null){
- message.addChild(parameters);
- }
-
-
- //get reference to metadata
- String metadataIdRef = e.getKey();
+ // data chains container <String metadataIdRef,
ArrayList<Data>>
+ HashMap<String, Message> dataChains = new HashMap<String,
Message>();
+ org.perfsonar.base2.xml.Element parameters = null;
+ List<org.perfsonar.base2.xml.Element> parametersNodesList =
(List<Element>) reqMessage
+ .getChildren("parameters");
+ if (parametersNodesList != null && parametersNodesList.size()
== 1) {
+ parameters = parametersNodesList.get(0);
+ }
- //System.out.println("## metadata chain for
["+metadataIdRef+"]");
-
- //find metadata chaining
- Map<String,Metadata> metadatas = new
HashMap<String,Metadata>();
- getChaining(reqMessage, metadataIdRef, metadatas);
- Map<String,Metadata> mergedMetadatas =
mergeAllMetadata(metadatas);
- for (Metadata metadata : mergedMetadatas.values()) {
- message.setMetadata(metadata);
- }
+ // get input data elements
+ Collection<Data> dataTriggers =
reqMessage.getDataMap().values();
- //copy id, type from request
- message.setId(reqMessage.getId());
- message.setType(reqMessage.getType());
+ // for all data elelemtns
+ for (Data data : dataTriggers) {
- //add to result set
- messagesList.add(message);
-
-// System.out.println(" --
["+message.getMetadataArray().length+"] metadatas");
-// System.out.println(" --
["+message.getDataArray().length+"] datas");
-// try {
-//
System.out.println("--------------------------------------\n"+
-// XMLUtils.serializeXML(message)+
-// "--------------------------------------\n");
-// } catch (PerfSONARException e1) {
-// // TODO Auto-generated catch block
-// e1.printStackTrace();
-// }
-
- } catch (NoSuchMetadataException e1) {
- logger.error("LSRegisterRequest: no such metadata, cannot
find chain!");
- }
-
- }
-
- return messagesList;
-
- }
-
-
-
-
-
+ // put all data having the same metadataIdRef to the
same container
+ String metaref = data.getMetadataIdRef();
+ if (dataChains.get(metaref) == null)
+ dataChains.put(metaref, new Message());
+ Message m = dataChains.get(metaref);
+ m.setData(data);
+ // System.out.println("## data ["+data.getId()+"] ->
["+metaref+"]");
+
+ }
+
+ // for each data elements set find chaining
+ for (Map.Entry<String, Message> e : dataChains.entrySet()) {
+
+ try {
+
+ // get previously added message with data
elements
+ Message message = e.getValue();
+ if (parameters != null) {
+ message.addChild(parameters);
+ }
+
+ // get reference to metadata
+ String metadataIdRef = e.getKey();
+
+ // System.out.println("## metadata chain for
["+metadataIdRef+"]");
+
+ // find metadata chaining
+ Map<String, Metadata> metadatas = new
HashMap<String, Metadata>();
+ getChaining(reqMessage, metadataIdRef,
metadatas);
+ Map<String, Metadata> mergedMetadatas =
mergeAllMetadata(metadatas);
+ for (Metadata metadata :
mergedMetadatas.values()) {
+ message.setMetadata(metadata);
+ }
+
+ // copy id, type from request
+ message.setId(reqMessage.getId());
+ message.setType(reqMessage.getType());
+
+ // add to result set
+ messagesList.add(message);
+
+ } catch (NoSuchMetadataException e1) {
+ logger.error("LSRegisterRequest: no such
metadata, cannot find chain!");
+ }
+ }
+ return messagesList;
+
+ }
+
}
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/TrieNode.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/TrieNode.java
2009-12-17 14:03:13 UTC (rev 5425)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/TrieNode.java
2009-12-21 13:48:15 UTC (rev 5426)
@@ -200,7 +200,7 @@
}
} else {
this.valueCount = 1;
- // this.data = data; //XXX
+ // this.data = data;
}
}
return this;
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/schedulerActions/CleanupSchedulerAction.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/schedulerActions/CleanupSchedulerAction.java
2009-12-17 14:03:13 UTC (rev 5425)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/schedulerActions/CleanupSchedulerAction.java
2009-12-21 13:48:15 UTC (rev 5426)
@@ -2,40 +2,45 @@
import org.apache.log4j.Logger;
import org.perfsonar.base2.service.configuration.Action;
+import org.perfsonar.base2.service.configuration.ConfigurationManager;
import org.perfsonar.base2.service.configuration.Option;
import org.perfsonar.base2.service.exceptions.PerfSONARException;
import org.perfsonar.base2.service.scheduler.SchedulerAction;
-import org.perfsonar.service.lookupservice.LSCleanupServiceEngine;
+import org.perfsonar.service.lookupservice.storage.LookupServiceDAO;
+import org.perfsonar.service.lookupservice.storage.LookupServiceDAOFactory;
+import
org.perfsonar.service.lookupservice.summarization.ModificationCounterComponent;
/**
*
* executes cleanup operations on Database
*
*
- * @author roman,Slawomir Trzaszczka
+ * @author roman,Slawomir Trzaszczka
*
*/
public class CleanupSchedulerAction extends Action implements
SchedulerAction {
+ private final Logger logger =
Logger.getLogger(CleanupSchedulerAction.class);
- private final Logger logger =
Logger.getLogger(CleanupSchedulerAction.class.getName());
-
private boolean isInitialized = false;
- private LSCleanupServiceEngine engine;
- private int ttl;
+ private LookupServiceDAO dao;
+ /**
+ * lsTTL parameter value from configuration file - configuration.xml
+ */
+ private int lsTTL;
+
public CleanupSchedulerAction() {
super();
}
private void initialize() throws PerfSONARException {
- engine = new LSCleanupServiceEngine();
+ dao=LookupServiceDAOFactory.getDAO();
Option lsTTLOption = getOption("lsTTL");
if (lsTTLOption != null) {
try {
- ttl =
Integer.parseInt(lsTTLOption.getValue());
- engine.setLsTTL(ttl);
- logger.debug("Setting LS TTL to [" + ttl +
"]");
+ lsTTL =
Integer.parseInt(lsTTLOption.getValue());
+ logger.debug("Setting LS TTL to [" + lsTTL +
"]");
} catch (NumberFormatException ex) {
logger.debug("Taking default LS TTL");
}
@@ -44,7 +49,6 @@
}
}
- // TODO: run Action should throw an exception
public void runAction() {
try {
if (!isInitialized) {
@@ -52,13 +56,34 @@
initialize();
isInitialized = true;
}
-
- // run cleanup
- engine.cleanup(null);
-
+ cleanup();
} catch (PerfSONARException e) {
logger.error(e);
}
}
+
+ /**
+ * this method invokes cleanup operation
+ *
+ * @throws PerfSONARException
+ */
+ private void cleanup() throws PerfSONARException {
+
+ // current timestamp in sec
+ long now = System.currentTimeMillis() / 1000;
+
+ logger.debug("[LSCleanup] cleanup action started,
timestamp=[" + now+ "]s lsTTL=[" + lsTTL + "]s");
+ // perform cleanup operation
+ int elementRemoved = dao.cleanupLookupInfo(now, lsTTL);
+ if (elementRemoved > 0) {
+ // if some elements were removed,
modificationCounterComponent should be incremented
+ ConfigurationManager cm =
ConfigurationManager.getInstance();
+ ModificationCounterComponent component =
(ModificationCounterComponent) cm
+
.getConfiguration().getAuxiliaryComponent(
+
"modificationCounterComponent");
+ component.incrementCounter();
+ }
+ }
+
}
\ No newline at end of file
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/schedulerActions/GLSRegistrationAction.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/schedulerActions/GLSRegistrationAction.java
2009-12-17 14:03:13 UTC (rev 5425)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/schedulerActions/GLSRegistrationAction.java
2009-12-21 13:48:15 UTC (rev 5426)
@@ -82,8 +82,7 @@
} catch (PerfSONARException e) {
logger.debug("Problem with sending KeepAlive
message to :"
+ glsAddress.toString());
- URL brokenGLSURL = glsAddresses.poll();
- glsAddresses.add(brokenGLSURL);
+ poolElement(glsAddresses);
registrationSuccess = false;
}
@@ -119,6 +118,7 @@
registeredKey =
getKeyFromResponse(response);
if (registeredKey == null) {
logger.debug("no
registerd key in registration response");
+
poolElement(glsAddresses);
} else {
break;
}
@@ -126,8 +126,7 @@
logger
.warn("Problem with sending registration message to :"
+ glsAddress.toString());
- URL brokenGLSURL =
glsAddresses.poll();
-
glsAddresses.add(brokenGLSURL);
+ poolElement(glsAddresses);
}
}
@@ -142,6 +141,11 @@
}
}
+
+ private void poolElement(LinkedList<URL> urls){
+ URL brokenGLSURL = glsAddresses.poll();
+ glsAddresses.add(brokenGLSURL);
+ }
public void refresh() {
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/dao/MultipleFilesDAOImpl.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/dao/MultipleFilesDAOImpl.java
2009-12-17 14:03:13 UTC (rev 5425)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/dao/MultipleFilesDAOImpl.java
2009-12-21 13:48:15 UTC (rev 5426)
@@ -90,7 +90,6 @@
throw new PerfSONARException("md5 - algorithm not
found",e);
}
- //TODO: improve this query
String xquery = XQUERY_DECLARE_NAMESPACES + " for $i in " +
"("
+
"/nmwg:store[@type='"
+ LS_STORE_CONTROL_COLLECTION_TYPE
+
"']/nmwg:metadata[@id='"
+ metadataId + "']" + ")"
@@ -125,12 +124,18 @@
+ defaultInterval
+ "\n"
+
- // to be changed - get interval from parameter
-
"for $meta in
/nmwg:store[@type='LSStore-control']/nmwg:metadata
\n"
+ " let $ts :=
data($meta/nmwg:parameters/nmwg:parameter[@name='timestamp']/@value)
cast as xs:integer\n"
+ " let $metaid := data($meta/@id)\n "
- + " where $ts + $interval < $now\n" +
"return $metaid\n";
+ + "where ("
+ + "
if(exists($meta/nmwg:parameters/nmwg:parameter[@name='lsTTL']))"
+ + " then ( let $serviceLsTTL :=
data($meta/nmwg:parameters/nmwg:parameter[@name='lsTTL']/@value)
cast as xs:double"
+ + " where ($ts +
$serviceLsTTL) < $now return true()"
+ + " )"
+ + " else"
+ + " ($ts + $interval) <
$now"
+ + " )"
+ + "return $metaid\n";
XMLDBResult res = performXQuery(xquery);
result = res.getResults().size();
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/ModificationCounterComponent.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/ModificationCounterComponent.java
2009-12-17 14:03:13 UTC (rev 5425)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/ModificationCounterComponent.java
2009-12-21 13:48:15 UTC (rev 5426)
@@ -43,7 +43,7 @@
* - deregistration
* - cleanup
*/
- public void increaseCounter(){
+ public void incrementCounter(){
counter++;
diffsBetweenRegistrationCounter++;
logger.debug("Counter increased " +counter+ " diffs "+
diffsBetweenRegistrationCounter);
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/SummarizationBuilder.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/SummarizationBuilder.java
2009-12-17 14:03:13 UTC (rev 5425)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/SummarizationBuilder.java
2009-12-21 13:48:15 UTC (rev 5426)
@@ -45,14 +45,15 @@
Map<String, ServiceSummaryBean> summaries = null;
try {
summaries = getAllServicesSummaries();
-
-
- // now having all data in "summaries" structure and
need to summarize
+
+ // now having all data in "summaries" structure and
need to
+ // summarize
// IPs, domains separately. EventTypes will remain
the same.
// boolean doIPSummarization =
//
config.getProperty("service.ls.do_ip_summarization");
- // work on the same data - summarize and store in
"summaries" structure
+ // work on the same data - summarize and store in
"summaries"
+ // structure
for (ServiceSummaryBean s : summaries.values()) {
// summarize IPs
@@ -79,7 +80,8 @@
for (String ip :
s.getValue().getIpAddresses()) {
- // split results - ip/netmask or
assume 32 as netmask if wrong
+ // split results - ip/netmask or
assume 32 as netmask if
+ // wrong
// format
String[] ipvals = ip.split("/", 2);
if (ipvals.length != 2) {
@@ -92,7 +94,8 @@
gen.createDomainElement(subject, dom);
}
- // get sum of parameters to determine whether
there is any parameter
+ // get sum of parameters to determine whether
there is any
+ // parameter
// to be printed
int paramsSum =
s.getValue().getEventTypes().size()
+
s.getValue().getKeywords().size();
@@ -102,24 +105,23 @@
.createParametersElement(subject);
for (String evt :
s.getValue().getEventTypes()) {
-
gen.createParameterElement(parametersElement, "eventType",
- evt);
+
gen.createParameterElement(parametersElement,
+ "eventType",
evt);
}
for (String kw :
s.getValue().getKeywords()) {
- gen
-
.createParameterElement(parametersElement,
-
"keyword", kw);
+
gen.createParameterElement(parametersElement,
+ "keyword",
kw);
}
}
}
return gen.getDataList();
-
+
} catch (PerfSONARException e) {
e.printStackTrace();
}
-
+
return null;
}
@@ -139,10 +141,11 @@
String[] eventTypeResults = dao.queryEventTypeResults();
String[] keywordResults = dao.queryKeywordResults();
-
logger.debug("LSSummaryServiceContent.getAllServicesSummaries: got summary
from database. Number of: ");
+ logger
+
.debug("LSSummaryServiceContent.getAllServicesSummaries: got summary from
database. Number of: ");
logger.debug("- IP: [" + ipResults.length + "]");
logger.debug("- domains: [" + domainResults.length + "]");
- logger.debug("- eventvTypes: [" + eventTypeResults.length+
"]");
+ logger.debug("- eventvTypes: [" + eventTypeResults.length +
"]");
populateSummary(summaries, ipResults,
SummarizationVariableType.IP);
populateSummary(summaries, domainResults,
@@ -164,19 +167,8 @@
* @return
*/
private Set<String> summarizeIPAddresses(Set<String> ipAddresses) {
-
- Set<String> result;
-
- try {
- result = SummarizeIpAddrs.getSummary(ipAddresses);
- } catch (Exception ex) {
- // TODO: change exception !!
- logger.warn("IP summarization failed. " + "Exception:
" + ex
- + " : " + ex.getMessage());
- result = ipAddresses;
- }
+ Set<String> result = SummarizeIpAddrs.getSummary(ipAddresses);
return result;
-
}
/**
@@ -239,7 +231,7 @@
case KEYWORD:
summary.getKeywords().add(content);
break;
- default :
+ default:
System.err.print("Uknown
SummarizationVariableType");
}
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/test/java/org/perfsonar/tests/actions/EchoActionTests.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/test/java/org/perfsonar/tests/actions/EchoActionTests.java
2009-12-17 14:03:13 UTC (rev 5425)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/test/java/org/perfsonar/tests/actions/EchoActionTests.java
2009-12-21 13:48:15 UTC (rev 5426)
@@ -21,14 +21,17 @@
Metadata meta = new Metadata();
meta.setId("meta");
- EventType eventType = new EventType();
- eventType.setText(eventTypeStr);
+ if(eventTypeStr!=null){
+ EventType eventType = new EventType();
+ eventType.setText(eventTypeStr);
+ meta.addChild(eventType);
+ }
Data data = new Data();
data.setMetadataIdRef(meta.getId());
msg.addChild(meta);
- meta.addChild(eventType);
+
msg.addChild(data);
return msg;
@@ -61,5 +64,18 @@
}
}
+
+
+ public void testMessageWithoutEventType() {
+ EchoServiceEngine ese = new EchoServiceEngine();
+ ServiceMessage responseMessage = new ServiceMessage();
+ try {
+ ese.takeAction(new ServiceMessage(
+ getEchoRequest(null)),
responseMessage);
+ fail();
+ } catch (PerfSONARException ex) {
+ }
+ }
+
}
- perfsonar: r5426 - in branches/new-structure-with-base2/ps-mdm-ls/src: main/java/org/perfsonar/service/lookupservice main/java/org/perfsonar/service/lookupservice/registration/summarization main/java/org/perfsonar/service/lookupservice/schedulerActions main/java/org/perfsonar/service/lookupservice/storage/exist/dao main/java/org/perfsonar/service/lookupservice/summarization test/java/org/perfsonar/tests/actions, svnlog, 12/21/2009
Archive powered by MHonArc 2.6.16.