Skip to Content.
Sympa Menu

perfsonar-dev - perfsonar: r5383 - branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice

Subject: perfsonar development work

List archive

perfsonar: r5383 - branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice


Chronological Thread 
  • From:
  • To:
  • Subject: perfsonar: r5383 - branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice
  • Date: Tue, 8 Dec 2009 07:22:03 -0500

Author: trzaszcz
Date: 2009-12-08 07:22:03 -0500 (Tue, 08 Dec 2009)
New Revision: 5383

Modified:

branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/DiscoveryQueryGenerator.java

branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSCleanupServiceEngine.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/LSDiscoveryAction.java
Log:
Discovery Message processing improved

Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/DiscoveryQueryGenerator.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/DiscoveryQueryGenerator.java
2009-12-08 09:35:33 UTC (rev 5382)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/DiscoveryQueryGenerator.java
2009-12-08 12:22:03 UTC (rev 5383)
@@ -14,235 +14,225 @@
*/
public class DiscoveryQueryGenerator {

- private Element discoverySubject = null;
+ private Element discoverySubject = null;
+ private boolean extracted = false;
+ private HashSet<String> ipAddresses = new HashSet<String>();
+ private HashSet<String> domains = new HashSet<String>();
+ private HashSet<String> eventTypes = new HashSet<String>();
+ private HashSet<String> keywords = new HashSet<String>();
+ private String query = null;

- private boolean extracted = false;
+ public DiscoveryQueryGenerator(Element subject) {
+ setSubject(subject);
+ }

- HashSet<String> ipAddresses = new HashSet<String>();
+ public void setSubject(Element discoverySubject) {

- HashSet<String> domains = new HashSet<String>();
+ this.discoverySubject = discoverySubject;
+ extracted = false;
+ ipAddresses.clear();
+ domains.clear();
+ eventTypes.clear();
+ keywords.clear();
+ }

- HashSet<String> eventTypes = new HashSet<String>();
+ public void extractSubject() throws PerfSONARException {

- HashSet<String> keywords = new HashSet<String>();
+ if (discoverySubject == null)
+ throw new PerfSONARException("No subject");
+ if (!extracted) {

- String query = null;
+ for (Element e : discoverySubject.getChildren()) {
+ String elementName = e.getName();
+ if (elementName.equals("address")) {
+ addIpAddress(e);

+ } else if (elementName.equals("domain")) {
+ addDomain(e);

+ } else if (elementName.equals("eventType")) {
+ addEventType(e);

- public DiscoveryQueryGenerator(Element subject) {
+ } else if (elementName.equals("parameters")) {

- setSubject(subject);
- }
+ Collection<Element> params =
e.getChildren("parameter");
+ if (params != null) {
+ for (Element p : params) {

+ String name =
p.getAttribute("name");
+ String value =
p.getText();

- public void setSubject(Element discoverySubject) {
+ if (value != null) {
+ value =
value.trim();
+ if
("keyword".equals(name)) {
+
keywords.add(value);
+ } else if
("eventType".equals(name)) {
+
eventTypes.add(value);
+ }
+ }
+ }

- this.discoverySubject = discoverySubject;
- extracted = false;
- ipAddresses.clear();
- domains.clear();
- eventTypes.clear();
- keywords.clear();
- }
+ }
+ }
+ }
+ }
+ extracted = true;
+ }

+ private void addEventType(Element eventType) {

- public void extractSubject() throws PerfSONARException {
+ String evt = eventType.getText();
+ if (evt != null) {
+ eventTypes.add(evt.trim());
+ }
+ }

- if (discoverySubject == null)
- throw new PerfSONARException("No subject");
- if (!extracted) {
+ private void addDomain(Element domain) {

- for (Element e : discoverySubject.getChildren()) {
- String elementName = e.getName();
- if (elementName.equals("address")) {
- addIpAddress(e);
+ Element name = domain.getFirstChild("name");
+ if (name != null) {
+ String n = name.getText();
+ if (n != null)
+ domains.add(n.trim());
+ }
+ }

- } else if (elementName.equals("domain")) {
- addDomain(e);
+ private void addIpAddress(Element ipAddress) {

- } else if (elementName.equals("eventType")) {
- addEventType(e);
+ String ip = ipAddress.getText();
+ if (ip != null) {
+ ipAddresses.add(ip.trim());
+ }
+ }

- } else if (elementName.equals("parameters")) {
+ /**
+ * Generates query and stores to query property
+ *
+ * @return
+ * @throws PerfSONARException
+ */
+ public String generateQuery() throws PerfSONARException {

- for (Element p : e.getChildren("parameter")) {
+ if (!extracted) {
+ extractSubject();
+ }

- String name = p.getAttribute("name");
- String val = p.getAttribute("value");
+ StringBuffer q = new StringBuffer();

- if (val != null) {
- val = val.trim();
- if ("keyword".equals(name))
- keywords.add(val);
- else if ("eventType".equals(name))
- eventTypes.add(val);
- } // if
+ // add declarations
+ q
+ .append("declare namespace
nmwg='http://ggf.org/ns/nmwg/base/2.0/'; \n");
+ q
+ .append("declare namespace
nmwgt='http://ggf.org/ns/nmwg/topology/2.0/'; \n");

- } // for
- } // else
- }// for
- }
- extracted = true;
- }
+ // add for expression
+ q.append("for $d in
/nmwg:store[@type='LSStore']/nmwg:data
\n");
+ if (!ipAddresses.isEmpty() || !domains.isEmpty() ||
!keywords.isEmpty()
+ || !!eventTypes.isEmpty()) {

+ // generate query conditions
+ q.append("where \n");

- private void addEventType(Element eventType) {
+ int i = 0;
+ i += putCollectionToQueryBuffer(q, ipAddresses,
+ "$d/nmwg:metadata//nmwgt:ifAddress",
(i > 0), null);
+ i += putCollectionToQueryBuffer(q, domains,
+ "$d/nmwg:metadata//nmwgt:hostName",
(i > 0), "ends-with");
+ i += putCollectionToQueryBuffer(q, eventTypes,
+ "$d/nmwg:metadata/nmwg:eventType", (i
> 0), null);
+ i += putCollectionToQueryBuffer(q, keywords,
+
"$d/nmwg:metadata//nmwg:parameter[@name='keyword']",
+ (i > 0), null);

- String evt = eventType.getText();
- if (evt != null) {
- eventTypes.add(evt.trim());
- }
- }
+ }
+ // add return statemet
+ q.append("return data($d/@metadataIdRef)");

+ query = q.toString();
+ return query;

- private void addDomain(Element domain) {
+ }

- Element name = domain.getFirstChild("name");
- if (name != null) {
- String n = name.getName();
- if (n != null)
- domains.add(n.trim());
- }
- }
+ /**
+ * Makes AND/OR query
+ *
+ * @param q
+ * buffer to be appended
+ * @param col
+ * collection where to take data from
+ * @param element
+ * name of an element to be checked
+ * @param addAND
+ * indicates whether to add AND at the beginning of the
+ * expression
+ * @param function
+ * name of function, if null then equal "=" will be used
+ * @return number of elements added
+ */
+ private int putCollectionToQueryBuffer(StringBuffer q,
+ Collection<String> col, String element, boolean
addAND,
+ String function) {

- private void addIpAddress(Element ipAddress) {
+ if ((col.size() > 0) && (addAND == true))
+ q.append(" and \n");

- String ip = ipAddress.getText();
- if (ip != null) {
- ipAddresses.add(ip.trim());
- }
- }
+ int i = 0;
+ for (String c : col) {
+ if (i == 0)
+ q.append("(");
+ else
+ q.append(" or ");
+ if (function == null) {
+ q.append(" ");
+ q.append(element);
+ q.append(" = '");
+ q.append(c);
+ q.append("' ");
+ } else {
+ q.append(" ");
+ q.append(function);
+ q.append("(");
+ q.append(element);
+ q.append(",'");
+ q.append(c);
+ q.append("') ");
+ }
+ i++;
+ }
+ if (i > 0)
+ q.append(")\n");
+ return i;

+ }

- /**
- * Generates query and stores to query property
- *
- * @return
- * @throws PerfSONARException
- */
- public String generateQuery() throws PerfSONARException {
+ /**
+ * Returns formatted query parameters string in string buffer
+ *
+ * @return
+ */
+ public StringBuffer printQueryParameters() {

- if (!extracted)
- extractSubject();
+ StringBuffer sb = new StringBuffer();
+ sb.append("Discovery Query Parameters\n");
+
sb.append("==================================================\n");
+ sb.append(ipAddresses);
+ sb.append("\n");
+
sb.append("==================================================\n");
+ sb.append(domains);
+ sb.append("\n");
+
sb.append("==================================================\n");
+ sb.append(eventTypes);
+ sb.append("\n");
+
sb.append("==================================================\n");
+ sb.append(keywords);
+ sb.append("\n");
+
sb.append("==================================================\n");
+ return sb;
+ }

- StringBuffer q = new StringBuffer();
+ public String getQuery() {

- // add declarations
- q.append("declare namespace nmwg='http://ggf.org/ns/nmwg/base/2.0/';
\n");
- q.append("declare namespace
nmwgt='http://ggf.org/ns/nmwg/topology/2.0/'; \n");
+ return query;
+ }

- // add for expression
- q.append("for $d in
/nmwg:store[@type='LSStore']/nmwg:data
\n");
- if ((ipAddresses.size() + domains.size() + keywords.size() +
eventTypes
- .size()) > 0) {
-
- // generate query conditions
- q.append("where \n");
-
- int i = 0;
- i += putCollectionToQueryBuffer(q, ipAddresses,
- "$d/nmwg:metadata//nmwgt:ifAddress", (i > 0), null);
- i += putCollectionToQueryBuffer(q, domains,
- "$d/nmwg:metadata//nmwgt:hostName", (i > 0),
"ends-with");
- i += putCollectionToQueryBuffer(q, eventTypes,
- "$d/nmwg:metadata/nmwg:eventType", (i > 0), null);
- i += putCollectionToQueryBuffer(q, keywords,
-
"$d/nmwg:metadata//nmwg:parameter[@name='keyword']",
- (i > 0), null);
-
- }
- // add return statemet
- q.append("return data($d/@metadataIdRef)");
-
- query = q.toString();
- return query;
-
- }
-
-
- /**
- * Makes AND/OR query
- *
- * @param q
- * buffer to be appended
- * @param col
- * collection where to take data from
- * @param element
- * name of an element to be checked
- * @param addAND
- * indicates whether to add AND at the beginning of the
- * expression
- * @param function
- * name of function, if null then equal "=" will be used
- * @return number of elements added
- */
- private int putCollectionToQueryBuffer(StringBuffer q,
- Collection<String> col, String element, boolean addAND,
- String function) {
-
- if ((col.size() > 0) && (addAND == true))
- q.append(" and \n");
-
- int i = 0;
- for (String c : col) {
- if (i == 0)
- q.append("(");
- else
- q.append(" or ");
- if (function == null) {
- q.append(" ");
- q.append(element);
- q.append(" = '");
- q.append(c);
- q.append("' ");
- } else {
- q.append(" ");
- q.append(function);
- q.append("(");
- q.append(element);
- q.append(",'");
- q.append(c);
- q.append("') ");
- }
- i++;
- }
- if (i > 0)
- q.append(")\n");
- return i;
-
- }
-
-
- /**
- * Returns formatted query parameters string in string buffer
- *
- * @return
- */
- public StringBuffer printQueryParameters() {
-
- StringBuffer sb = new StringBuffer();
- sb.append("Discovery Query Parameters\n");
- sb.append("==================================================\n");
- sb.append(ipAddresses);
- sb.append("\n");
- sb.append("==================================================\n");
- sb.append(domains);
- sb.append("\n");
- sb.append("==================================================\n");
- sb.append(eventTypes);
- sb.append("\n");
- sb.append("==================================================\n");
- sb.append(keywords);
- sb.append("\n");
- sb.append("==================================================\n");
- return sb;
- }
-
-
- public String getQuery() {
-
- return query;
- }
-
}

Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSCleanupServiceEngine.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSCleanupServiceEngine.java
2009-12-08 09:35:33 UTC (rev 5382)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSCleanupServiceEngine.java
2009-12-08 12:22:03 UTC (rev 5383)
@@ -10,75 +10,39 @@



-
/**
+ *
* Action that removes all obsolete lookup information
- * @author Maciej Glowiak
+ * @author Maciej Glowiak, Slawomir Trzaszczka
*
*/
+//TODO: refactor this class - remove LSGenericRegisterServiceEngine - it is
not ServiceEngine - this class supports only for CleanupScheduleAction !
public class LSCleanupServiceEngine extends LSGenericRegisterServiceEngine {

+ private final Logger logger =
Logger.getLogger(LSKeepaliveServiceEngine.class.getName());

- // ----------------------------------------------------- Constants
-
-
- private static final Logger logger = Logger
- .getLogger(LSKeepaliveServiceEngine.class.getName());
-
/**
* default value of LS TTL
*/
public static final long DEFAULT_LS_TTL = 60; //seconds

- // -------------------------------------------- Instance variables
-
/**
* Value of LS TTL in seconds
*/
- long lsTTL = DEFAULT_LS_TTL; //in seconds
+ private long lsTTL = DEFAULT_LS_TTL; //in seconds


- // --------------------------------------------------- Constructor
-
-
/**
* LSCleanup constructor
*/
public LSCleanupServiceEngine() throws PerfSONARException {
-
super();
-
- //read service.ls.lookup_info_timeout
-// String prop = null;
-// try {
-// prop = configuration.getProperty(LS_TTL_PROPERTY);
-// } catch (PerfSONARException sex) {
-// prop=null;
-// }
-//
-// if (prop!=null) {
-// try {
-// lsTTL = Long.parseLong(prop);
-// } catch (Exception ex) {
-// logger.debug("LSRegisterAction: LS TTL=default");
-// lsTTL = DEFAULT_LS_TTL;
-// }
-// } else {
-// logger.debug("LSRegisterAction: LS TTL=default");
-// lsTTL = DEFAULT_LS_TTL;
-// }
-// logger.debug("LSRegisterAction: LS TTL="+lsTTL+" seconds");
-
-
-
}


public void takeAction(ServiceMessage request, ServiceMessage response)
throws PerfSONARException {
-
Message msg = cleanup(request.getMessageElement());
response.setElement(msg);
-
}


@@ -109,9 +73,9 @@

}

-
private Message getCleanupResponse() {
-
+ //TODO : remove it !
+
Message msg = ResultCodesUtil.generateResultMessage(null,
"success/ls/cleanup", "Action succeeded");

@@ -122,32 +86,19 @@

}

-
- // -------------------------------------------------------- private
methods
-
-
/**
* get LS TTL in milliseconds
*/
private long getLsTTLInSeconds() {
-
- return lsTTL; //lsTTL is already in seconds
-
+ return lsTTL;
}
-
-

public long getLsTTL() {
-
return lsTTL;
}

-
-
public void setLsTTL(long lsTTL) {
-
this.lsTTL = lsTTL;
}
-

-} //LSCleanup
+}

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-08 09:35:33 UTC (rev 5382)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSDeregisterServiceEngine.java
2009-12-08 12:22:03 UTC (rev 5383)
@@ -9,89 +9,88 @@
import org.perfsonar.base2.xml.nmwg.Metadata;
import
org.perfsonar.service.lookupservice.summarization.ModificationCounterComponent;

-
/**
* DEREGISTER Action
*
- * @author Maciej Glowiak
- *
+ * @author Maciej Glowiak,Slawomir Trzaszczka
+ *
*/
public class LSDeregisterServiceEngine extends
LSGenericRegisterServiceEngine {

- // --------------------------------------------------------------
Constants
+ private final Logger logger = Logger
+ .getLogger(LSDeregisterServiceEngine.class);

- private static final Logger logger =
Logger.getLogger(LSDeregisterServiceEngine.class.getName());
+
+ public LSDeregisterServiceEngine() throws PerfSONARException {
+ super();
+ }
+

-
- // ----------------------------------------------------- Instance
variables
-
- // ------------------------------------------------------------
Constructor
-
-
- public LSDeregisterServiceEngine()
- throws PerfSONARException {
- super();
- }
+ public void takeAction(ServiceMessage serviceRequest,
+ ServiceMessage serviceResponse) throws
PerfSONARException {

-
- // --------------------------------------------------------- Public
methods
-
- public void takeAction(ServiceMessage serviceRequest, ServiceMessage
serviceResponse)
- throws PerfSONARException {
-
- logger.debug("LS deregister - action DEREGISTER started");
+ logger.debug("LS deregister - action DEREGISTER started");
+
+ // extract message
+ Message requestMessage = serviceRequest.getMessageElement();

- //extract message
- Message requestMessage = serviceRequest.getMessageElement();
-
- //Get Metadata from Request
- Metadata requestMetadata =
- getFirstMetadataFromRequest(requestMessage);
-
- if (requestMetadata==null) {
- String m="LSDeregisterAction: No metadata in request";
- logger.warn(m);
- throw new PerfSONARException("error/ls/no_metadata", m);
- }
-
- //Get Key from Metadata
-
- String keyValue = getParameterFromKey(requestMetadata, LS_KEY);
- logger.debug("LSDeregisterAction: LS key=["+keyValue+"]");
-
- if (keyValue==null) {
- String m="LSDeregisterAction: No key in metadata";
- logger.warn(m);
- throw new PerfSONARException("error/ls/no_key", m);
- }
- int elementsRemoved = dao.removeLookupInfo(keyValue);
-
- Message msg;
-
-
- if (elementsRemoved<1){
- //given key not found !
-
msg=ResultCodesUtil.generateResultMessage("error/ls/key_not_found", "There
were no metadata and data for key ["+keyValue+"]");
- logger.debug("given key "+keyValue+" not found in DB");
- }else{
- //metadata with key existed - deregistration successful
-
- // inform about changes Component !
- ConfigurationManager cm = ConfigurationManager.getInstance();
- ModificationCounterComponent component =
(ModificationCounterComponent) cm
- .getConfiguration().getAuxiliaryComponent(
-
"modificationCounterComponent");
- component.increaseCounter();
-
- msg = ResultCodesUtil.generateResultMessage(null,
- "success/ls/deregister", "Removed total ["+
- elementsRemoved+"] metadata and data elements for key ["+
- keyValue+"]");
- }
-
-
- serviceResponse.setElement(msg);
- }
-
+ // Get Metadata from Request
+ Metadata requestMetadata =
getFirstMetadataFromRequest(requestMessage);

-} //LSLookupAction
+ if (requestMetadata == null) {
+ String m = "LSDeregisterAction: No metadata in
request";
+ logger.warn(m);
+ throw new PerfSONARException("error/ls/no_metadata",
m);
+ }
+
+ // Get Key from Metadata
+
+ String keyValue = getParameterFromKey(requestMetadata,
LS_KEY);
+ logger.debug("LSDeregisterAction: LS key=[" + keyValue + "]");
+
+ if (keyValue == null) {
+ String m = "LSDeregisterAction: No key in metadata";
+ logger.warn(m);
+ throw new PerfSONARException("error/ls/no_key", m);
+ }
+
+ int elementsRemoved = dao.removeLookupInfo(keyValue);
+
+ Message msg;
+
+ if (elementsRemoved < 1) {
+ // given key not found !
+ msg = ResultCodesUtil.generateResultMessage(
+ "error/ls/key_not_found",
+ "There were no metadata and data for
key [" + keyValue
+ + "]");
+ logger.debug("given key " + keyValue + " not found in
DB");
+ } else {
+ // metadata with key existed - deregistration
successful
+
+ // inform about changes Component !
+
+ ModificationCounterComponent component =
getModifcationCounter();
+ component.increaseCounter();
+
+ msg = ResultCodesUtil.generateResultMessage(null,
+ "success/ls/deregister", "Removed
total ["
+ + elementsRemoved
+ + "] metadata and
data elements for key ["
+ + keyValue + "]");
+ }
+
+ serviceResponse.setElement(msg);
+ }
+
+ private ModificationCounterComponent getModifcationCounter() throws
PerfSONARException{
+
+ ConfigurationManager cm = ConfigurationManager.getInstance();
+ ModificationCounterComponent modificationCounter =
(ModificationCounterComponent) cm
+ .getConfiguration().getAuxiliaryComponent(
+
"modificationCounterComponent");
+ return modificationCounter;
+
+ }
+
+}

Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSDiscoveryAction.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSDiscoveryAction.java
2009-12-08 09:35:33 UTC (rev 5382)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSDiscoveryAction.java
2009-12-08 12:22:03 UTC (rev 5383)
@@ -21,17 +21,14 @@
*/
public class LSDiscoveryAction {

- private static final Logger logger = Logger
- .getLogger(LSDiscoveryAction.class.getName());
-
+ private final Logger logger =
Logger.getLogger(LSDiscoveryAction.class);
+ private final String
SUBJECT_NAMESPACE="http://ggf.org/ns/nmwg/tools/org/perfsonar/service/lookup/summarization/2.0/";;

private LookupServiceDAO dao;

protected boolean verbose = true;

public LSDiscoveryAction(LookupServiceDAO dao) {
-
this.dao = dao;
-
}

public void performAction(ServiceMessage serviceRequest,
@@ -43,10 +40,11 @@

// check subject URI
// if not <summary:subject> return error
- if
(!"http://ggf.org/ns/nmwg/tools/org/perfsonar/service/lookup/summarization/2.0/";
- .equals(subject.getNamespaceUri()))
+ if (!SUBJECT_NAMESPACE.equals(subject.getNamespaceUri())){
throw new PerfSONARException("error/ls/no_subject",
- "Subject is not summary:subject");
+ "Subject is not summary:subject");
+ }
+

// query for list of services
HashSet<String> resultSet = queryForListOfServices(subject);



  • perfsonar: r5383 - branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice, svnlog, 12/08/2009

Archive powered by MHonArc 2.6.16.

Top of Page