Skip to Content.
Sympa Menu

perfsonar-dev - [pS-dev] [GEANT/SA2/ps-java-services] r6046 - trunk/perfsonar-java-sql-ma/src/main/java/org/perfsonar/se rvice/measurementArchive/sqlType

Subject: perfsonar development work

List archive

[pS-dev] [GEANT/SA2/ps-java-services] r6046 - trunk/perfsonar-java-sql-ma/src/main/java/org/perfsonar/se rvice/measurementArchive/sqlType


Chronological Thread 
  • From:
  • To:
  • Subject: [pS-dev] [GEANT/SA2/ps-java-services] r6046 - trunk/perfsonar-java-sql-ma/src/main/java/org/perfsonar/se rvice/measurementArchive/sqlType
  • Date: Fri, 30 Nov 2012 11:48:50 +0000 (GMT)

Author: nordunet.behrmann
Date: 2012-11-30 11:48:50 +0000 (Fri, 30 Nov 2012)
New Revision: 6046

Modified:

trunk/perfsonar-java-sql-ma/src/main/java/org/perfsonar/service/measurementArchive/sqlType/SQLTypeMAServiceEngine.java
Log:
perfsonar-java-sql-ma: Refactor getKey operation

Cleans up the code dealing with the getKey operation. A few minor
optimisations are made to the message handling (avoids repeated
copies of the response elements).

A race condition in the getSeq() method is fixed.

Modified:
trunk/perfsonar-java-sql-ma/src/main/java/org/perfsonar/service/measurementArchive/sqlType/SQLTypeMAServiceEngine.java
===================================================================
---
trunk/perfsonar-java-sql-ma/src/main/java/org/perfsonar/service/measurementArchive/sqlType/SQLTypeMAServiceEngine.java
2012-11-28 15:00:03 UTC (rev 6045)
+++
trunk/perfsonar-java-sql-ma/src/main/java/org/perfsonar/service/measurementArchive/sqlType/SQLTypeMAServiceEngine.java
2012-11-30 11:48:50 UTC (rev 6046)
@@ -11,7 +11,6 @@
import java.util.Random;
import java.util.Iterator;
import java.util.Set;
-import java.util.Vector;

import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Element;
@@ -22,6 +21,7 @@
import org.ggf.ns.nmwg.base.v2_0.Parameter;
import org.ggf.ns.nmwg.base.v2_0.Parameters;

+import org.ggf.ns.nmwg.base.v2_0.Subject;
import org.perfsonar.base.auxiliary.ComponentNames;
import
org.perfsonar.base.auxiliary.components.configuration.ConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
@@ -502,25 +502,13 @@

private static long seq = 0;

- public static String getSeq()
+ private static synchronized String getSeq()
{
-
- String strSeq;
- try {
- seq = seq + 1;
- strSeq = Long.toString(seq);
- } catch (Exception ex) {
- strSeq = "0";
- seq = 0;
- }
-
- return strSeq;
+ return Long.toString(++seq);
}

-
protected LoggerComponent getLogger() throws PerfSONARException
{
-
try {
return (LoggerComponent) AuxiliaryComponentManager.getInstance().
getComponent(ComponentNames.LOGGER);
@@ -566,58 +554,27 @@
*/
protected Message getKey(Message request) throws PerfSONARException
{
+ request = mergeMetaData(request);

- //process the base chaining
- request = messageProcess(request);
-
Message response = new Message();

- Collection<Message> messageVector = new Vector<Message>();
-
Collection<Data> dataTriggers = request.getDataMap().values();
for (Data data : dataTriggers) {
-
- Message message = new Message();
-
- Map metadataMap = request.getMetadataMap();
- Metadata metadata = (Metadata)
metadataMap.get(data.getMetadataIdRef());
-
try {
-
- getKeyImpl(metadata, null, metadataMap, message,
metadataConfig);
-
+ Metadata metadata =
request.getMetadata(data.getMetadataIdRef());
+ getKeyImpl(request, metadata, response);
} catch (NullPointerException npex) {
-
throw new PerfSONARException(
"error.ma.query",
"SQLTypeMAServiceEngine.getKey: "
+ "getting the key is impossible "
+ "because of some problem with the format of the
request; "
+ npex.toString());
-
}
-
- messageVector.add(message);
-
}
-
- for (Message m : messageVector) {
-
- for (Object meta : m.getMetadataMap().values()) {
- response.addChild((Metadata) meta);
- }
-
- for (Object data : m.getDataMap().values()) {
- response.addChild((Data) data);
- }
-
- }
-
return response;
-
}

-
/**
* Removes base chaining (chains of metadata blocks linked by
* metadataIdRef attribute) from the message.
@@ -626,179 +583,138 @@
* @return Message processed message object
* @throws PerfSONARException
*/
- protected Message messageProcess(Message message)
+ protected Message mergeMetaData(Message message)
throws PerfSONARException
{
-
- String mergerNames = null;
+ String mergerNames;
try {
- mergerNames =
-
configuration.getProperty("service.ma.base_chaining_mergers");
- } catch (Exception ex) {
- }
-
- if (mergerNames == null || mergerNames.trim().isEmpty()) {
+ mergerNames =
configuration.getProperty("service.ma.base_chaining_mergers");
+ } catch (PerfSONARException ex) {
return message;
}

- Set<BaseChaining> baseChainingMergers =
- BaseChainingMergerFactory.getBaseChainingMergers(mergerNames);
+ if (!mergerNames.trim().isEmpty()) {
+ Set<BaseChaining> baseChainingMergers =
+
BaseChainingMergerFactory.getBaseChainingMergers(mergerNames);

- if (baseChainingMergers == null) {
- return message;
+ if (baseChainingMergers != null) {
+ for (BaseChaining baseChaining : baseChainingMergers) {
+ message = baseChaining.processChaining(message);
+ }
+ }
}

- for (BaseChaining baseChaining : baseChainingMergers) {
- message = baseChaining.processChaining(message);
-
- }
-
return message;
-
}

-
/**
* Method used in getKey method. Helps to find a key for a request
message.
- *
- * @throws PerfSONARException
*/
- protected void getKeyImpl(Metadata metadata,
- Data data,
- Map metadataMap,
- Message message,
- NMWGStorageManager metadataConfig)
+ protected void getKeyImpl(Message request, Metadata metadata, Message
response)
throws PerfSONARException
{
+ Subject subject = metadata.getSubject();
+ Key key = metadata.getKey();
+ EventType eventType = metadata.getEventType();

-
- if (metadata.getSubject() != null) {
-
- if (metadata.getSubject().getMetadataIdRef().isEmpty()) {
-
- // getting data from configuration storage manager
-
- Message query = new Message();
- query.addChild(metadata);
-
- Message msg = metadataConfig.fetch(query);
-
- //logger.debug(
- // "SQLTypeMAServiceEngine.getKeyImpl: "
- // + "found in metadata configuration: "
- // + msg);
-
- getEventType(metadata, msg);
-
- for (Object m : msg.getMetadataMap().values()) {
- message.addChild((Metadata) m);
- }
-
- for (Object d : msg.getDataMap().values()) {
- message.addChild((Data) d);
- }
-
+ if (subject != null) {
+ String metadataIdRef = subject.getMetadataIdRef();
+ if (!metadataIdRef.isEmpty()) {
+ getKeyByOperationChaining(request, metadata, response);
} else {
-
- String eventType;
- try {
- eventType =
metadata.getEventType().getEventType().trim();
- } catch (Exception ex) {
- throw new PerfSONARException(
- "error.ma.query",
- "SQLTypeMAServiceEngine.getKeyImpl: "
- + "something wrong with eventType in metadata
id=" + metadata.getId());
- }
-
- if
(metadata.getEventType().getEventType().trim().equals(SELECT_NAMESPACE)) {
- Parameters params = metadata.getParameters();
- String metadataIdRef =
metadata.getSubject().getMetadataIdRef();
- Metadata m = (Metadata) metadataMap.get(metadataIdRef);
-
- getKeyImpl(m, null, metadataMap, message,
metadataConfig);
-
- for (Object d : message.getDataMap().values()) {
-
- Key key = ((Data) d).getKey();
- if (key != null) {
- key.setParameters(params);
- }
-
- }
-
- } else {
-
- throw new PerfSONARException(
- "error.ma.query",
- "SQLTypeMAServiceEngine.getKeyImpl: "
- + "eventType " + eventType + " in metadata id="
+ metadata.getId()
- + " is not supported");
-
- }
-
+ getKeyFromConfigurationStore(metadata, response);
}
-
+ } else if (key != null || eventType != null) {
+ if (key != null) {
+ getKeyByIdentity(metadata.getKey(), response);
+ }
+ if (eventType != null) {
+ getKeyFromConfigurationStore(metadata, response);
+ }
} else {
+ throw new PerfSONARException(
+ "error.ma.query",
+ "SQLTypeMAServiceEngine.getKeyImpl: "
+ + "no subject, eventType or key element in metadata "
+ + metadata.getId());
+ }
+ }

- Key key = metadata.getKey();
+ /** Passes the query on to metadataConfig for lookup in Exist. */
+ private void getKeyFromConfigurationStore(Metadata metadata, Message
response) throws PerfSONARException
+ {
+ Message query = new Message();
+ query.addChild(metadata);

- if (key != null) {
- if (data == null) {
- data = new Data();
- message.addChild(data);
+ Message msg = metadataConfig.fetch(query);

- // this new metadata is created to not corrupt
- // already existed id
- Metadata metadata2 = new Metadata();
- metadata2.setKey(key);
-
- //long seed = (new Date()).getTime();
- //int intId = (new Random(seed)).nextInt();
- //String strId = Integer.toString(intId);
- String strId = getSeq();
-
- metadata2.setId(strId);
- message.addChild(metadata2);
- data.setMetadataIdRef(metadata2.getId());
-
+ if (metadata.getEventType() != null) {
+ String eventType = metadata.getEventType().getEventType();
+ for (Object d : msg.getDataMap().values()) {
+ Key key = ((Data) d).getKey();
+ if (key.getParameters().getParameterMap().get("eventType")
== null) {
+ key.addParameter("eventType", eventType);
}
-
- data.addChild(key);
-
}
+ }

- if (metadata.getEventType() != null) {
+ for (Object m : msg.getMetadataMap().values()) {
+ response.addChild((Metadata) m);
+ }

- // getting data from configuration storage manager
+ for (Object d : msg.getDataMap().values()) {
+ response.addChild((Data) d);
+ }
+ }

- Message query = new Message();
- query.addChild(metadata);
+ /** Copies the metadata key verbatim to the result. */
+ private void getKeyByIdentity(Key key, Message response)
+ {
+ Metadata metadata = new Metadata();
+ metadata.setKey(key);
+ metadata.setId(getSeq());
+ response.addChild(metadata);

- Message msg = metadataConfig.fetch(query);
+ Data data = new Data();
+ data.setMetadataIdRef(metadata.getId());
+ data.addChild(key);

- getEventType(metadata, msg);
+ response.addChild(data);
+ }

- for (Object m : msg.getMetadataMap().values()) {
- message.addChild((Metadata) m);
- }
+ /** Operation chaining. Only the select operation is supported. */
+ private void getKeyByOperationChaining(Message request, Metadata
metadata, Message response)
+ throws PerfSONARException
+ {
+ if (metadata.getEventType() == null) {
+ throw new PerfSONARException(
+ "error.ma.query",
+ "SQLTypeMAServiceEngine.getKeyImpl: "
+ + "Operation chaining requires event type in metadata "
+ metadata.getId());
+ }
+ String eventType = metadata.getEventType().getEventType().trim();
+ if (!eventType.equals(SELECT_NAMESPACE)) {
+ throw new PerfSONARException(
+ "error.ma.query",
+ "SQLTypeMAServiceEngine.getKeyImpl: "
+ + "eventType " + eventType + " in metadata " +
metadata.getId()
+ + " is not supported");
+ }

- for (Object d : msg.getDataMap().values()) {
- message.addChild((Data) d);
- }
+ Metadata chained =
request.getMetadata(metadata.getSubject().getMetadataIdRef());
+ getKeyImpl(request, chained, response);

- } else if (key == null) {
-
- throw new PerfSONARException(
- "error.ma.query",
- "SQLTypeMAServiceEngine.getKeyImpl: "
- + "no eventType or key element in metadata id="
- + metadata.getId());
-
+ /* Select parameters are added verbatim to the output key. When
subsequently fetching data,
+ * the select parameters will be interpreted and used to restrict
the data set being returned.
+ * @see DaoJdbcTemplate
+ */
+ Parameters selectParameters = metadata.getParameters();
+ for (Object d : response.getDataMap().values()) {
+ Key key = ((Data) d).getKey();
+ if (key != null) {
+ key.setParameters(selectParameters);
}
-
}
-
-
}


@@ -1018,27 +934,4 @@
return response;

}
-
-
- private String getEventType(Metadata metadata, Message msg)
- {
-
- String eventType = null;
- try {
- eventType = metadata.getEventType().getEventType();
- } catch (Exception ex1) {
- }
-
- for (Object d : msg.getDataMap().values()) {
- Key key = ((Data) d).getKey();
- if (key.getParameters().getParameterMap().get("eventType") ==
null) {
- key.addParameter("eventType", eventType);
- }
- }
-
- return eventType;
-
- }
-
-
} //SQLTypeMAServiceEngine



  • [pS-dev] [GEANT/SA2/ps-java-services] r6046 - trunk/perfsonar-java-sql-ma/src/main/java/org/perfsonar/se rvice/measurementArchive/sqlType, svn-noreply, 11/30/2012

Archive powered by MHonArc 2.6.16.

Top of Page