perfsonar-dev - [pS-dev] [GEANT/SA2/ps-java-services] r6189 - in branches: . perfsonar-java-rrd-ma-3.4-stable/src/ main/java/org/perfsonar/service/measurementArchive/rrdType /storage/sql
Subject: perfsonar development work
List archive
[pS-dev] [GEANT/SA2/ps-java-services] r6189 - in branches: . perfsonar-java-rrd-ma-3.4-stable/src/ main/java/org/perfsonar/service/measurementArchive/rrdType /storage/sql
Chronological Thread
- From:
- To:
- Subject: [pS-dev] [GEANT/SA2/ps-java-services] r6189 - in branches: . perfsonar-java-rrd-ma-3.4-stable/src/ main/java/org/perfsonar/service/measurementArchive/rrdType /storage/sql
- Date: Wed, 13 Mar 2013 11:50:48 +0000 (GMT)
- Authentication-results: sfpop-ironport03.merit.edu; dkim=neutral (message not signed) header.i=none
Author: dante.delvaux
Date: 2013-03-13 11:50:48 +0000 (Wed, 13 Mar 2013)
New Revision: 6189
Added:
branches/perfsonar-java-rrd-ma-3.4-stable/
branches/perfsonar-java-rrd-ma-3.4-stable/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/sql/MysqlMetadataStorageDAOImpl.java
Removed:
branches/perfsonar-java-rrd-ma-3.4-stable/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/sql/MysqlMetadataStorageDAOImpl.java
Log:
Creating stabilisation branch for the RRD MA with SQL backend. This is
numbered v3.4 series.
Deleted:
branches/perfsonar-java-rrd-ma-3.4-stable/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/sql/MysqlMetadataStorageDAOImpl.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/sql/MysqlMetadataStorageDAOImpl.java
2013-03-06 21:07:18 UTC (rev 6182)
+++
branches/perfsonar-java-rrd-ma-3.4-stable/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/sql/MysqlMetadataStorageDAOImpl.java
2013-03-13 11:50:48 UTC (rev 6189)
@@ -1,193 +0,0 @@
-package org.perfsonar.service.measurementArchive.rrdType.storage.sql;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
-import javax.persistence.Query;
-
-import org.perfsonar.base2.service.configuration.Component;
-import org.perfsonar.base2.service.configuration.ConfigurationManager;
-import org.perfsonar.base2.service.exceptions.PerfSONARException;
-import org.perfsonar.base2.xml.Element;
-import org.perfsonar.base2.xml.nmwg.Message;
-import org.perfsonar.base2.xml.nmwg.Metadata;
-import
org.perfsonar.service.measurementArchive.rrdType.storage.MetadataStorageDAO;
-import
org.perfsonar.service.measurementArchive.rrdType.storage.MetadataStorageDAOFactory;
-import
org.perfsonar.service.measurementArchive.rrdType.storage.persistence.MetadaKeyResponse;
-import
org.perfsonar.service.measurementArchive.rrdType.storage.persistence.SetupDataKeyResponse;
-import
org.perfsonar.service.measurementArchive.rrdType.storage.persistence.entity.Interfaces;
-import
org.perfsonar.service.measurementArchive.rrdType.storage.sql.query.QueryGenerator;
-
-public class MysqlMetadataStorageDAOImpl extends Component implements
MetadataStorageDAO
-{
- public static final String PERSISTENCE_UNIT_NAME =
"org.perfsonar.service.measurementArchive.rrdType.storage.sql";
- protected EntityManager em;
- protected final QueryGenerator qg = new QueryGenerator();
- private EntityManagerFactory entityManagerFactory;
-
- @Override
- public void destroy() throws PerfSONARException
- {
- em.close();
- entityManagerFactory.close();
- }
-
- @Override
- public void init() throws PerfSONARException
- {
- Component configuration =
ConfigurationManager.getInstance().getConfiguration().getAuxiliaryComponent(
- MetadataStorageDAOFactory.METADATA_STORAGE_DAO_NAME);
- String dbUri = configuration.getOption("uri").getValue();
- String schema = configuration.getOption("schema").getValue();
- String username = configuration.getOption("username").getValue();
- String password = configuration.getOption("password").getValue();
-
- if (!dbUri.endsWith("/")) {
- dbUri = dbUri + "/";
- }
-
- try {
- Map<String, Object> jpaConfig = new HashMap<String, Object>();
- jpaConfig.put("javax.persistence.jdbc.driver",
"com.mysql.jdbc.Driver");
- jpaConfig.put("javax.persistence.jdbc.url", dbUri + schema);
- jpaConfig.put("javax.persistence.jdbc.user", username);
- jpaConfig.put("javax.persistence.jdbc.password", password);
- entityManagerFactory =
Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, jpaConfig);
- em = entityManagerFactory.createEntityManager();
- } catch (RuntimeException e) {
- throw new PerfSONARException("Persistence initialization failed:
" + e.getMessage(), e);
- }
- }
-
- @Override
- public void run() throws PerfSONARException
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public Collection<Element> fetch(Element request) throws
PerfSONARException
- {
- // TODO Auto-generated method stub
- long t1 = System.currentTimeMillis();
- checkMetadataCorectness((Message) request);
-
- if (!(request instanceof Message)) {
- throw new PerfSONARException("parse",
- "Object [" + request.getClass() +
"] is not a valid Message [" + Message.class
- + "] element.");
- }
-
- Message message = (Message) request;
- SetupDataKeyResponse sdkr = new SetupDataKeyResponse();
-
- Collection<Element> result = new ArrayList<Element>();
- for (Metadata metadata : message.getMetadataCollection()) {
- Query query = qg.getQuery(em, metadata, Interfaces.TABLE);
- result = sdkr.fetchElements(query.getResultList().iterator());
- }
-
- long t2 = System.currentTimeMillis();
- logger.info("TIME of Fetch: " + (t2 - t1));
-
- return result;
- }
-
- /**
- * @return String with the response message (in NMWG format) of
MetadataKeyRequest
- * @throws PerfSONARException
- */
- public String rawFetch() throws PerfSONARException
- {
-
-
- List<Interfaces> resultList = (List<Interfaces>)
em.createNamedQuery(Interfaces.ALL).getResultList();
- MetadaKeyResponse mKRR = new MetadaKeyResponse();
-
- return mKRR.fetchMetadataMessage(resultList.iterator());
- }
-
- @Override
- public String rawFetch(Element request) throws PerfSONARException
- {
-
- long t1 = System.currentTimeMillis();
- checkMetadataCorectness((Message) request);
- Metadata metadata = ((Message)
request).getMetadataCollection().iterator().next();
-
- Query query = qg.getQuery(em, metadata, Interfaces.TABLE);
-
- MetadaKeyResponse mKRR = new MetadaKeyResponse();
- String result =
mKRR.fetchMetadataMessage(query.getResultList().iterator());
-
- long t2 = System.currentTimeMillis();
- logger.info("TIME of rawFetch: " + (t2 - t1));
-
- return result;
-
- }
-
- @Override
- public void remove(Element request) throws PerfSONARException
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void store(Element request) throws PerfSONARException
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void update(Element request) throws PerfSONARException
- {
- // TODO Auto-generated method stub
-
- }
-
-
- private void checkMetadataCorectness(Message request) throws
PerfSONARException
- {
-
- if (request.getMetadataCollection().isEmpty()) {
- logger.warn("can not find any metadatas with a valid content");
- throw new PerfSONARException("query_exception", "can not find
any metadatas with a valid content");
- }
-
- String eventType = null;
- for (Metadata m : request.getMetadataCollection()) {
-
- try {
- eventType = m.getFirstEventType().getEventType().trim();
- } catch (Exception ex) {
-
- logger.warn("can not find correct eventType in metadata
element");
- throw new PerfSONARException("query_exception", "can not
find correct eventType in metadata element");
- }
- if (eventType != null) {
- break;
- }
-
- }
-
-
- if (eventType == null || eventType.isEmpty()) {
- logger.warn("can not find correct eventType in metadata
element");
- throw new PerfSONARException("query_exception", "can not find
eventType in metadata element");
- }
-
-
- }
-
-
-}
Copied:
branches/perfsonar-java-rrd-ma-3.4-stable/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/sql/MysqlMetadataStorageDAOImpl.java
(from rev 6188,
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/sql/MysqlMetadataStorageDAOImpl.java)
===================================================================
---
branches/perfsonar-java-rrd-ma-3.4-stable/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/sql/MysqlMetadataStorageDAOImpl.java
(rev 0)
+++
branches/perfsonar-java-rrd-ma-3.4-stable/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/sql/MysqlMetadataStorageDAOImpl.java
2013-03-13 11:50:48 UTC (rev 6189)
@@ -0,0 +1,194 @@
+package org.perfsonar.service.measurementArchive.rrdType.storage.sql;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import javax.persistence.Query;
+
+import org.perfsonar.base2.service.configuration.Component;
+import org.perfsonar.base2.service.configuration.ConfigurationManager;
+import org.perfsonar.base2.service.exceptions.PerfSONARException;
+import org.perfsonar.base2.xml.Element;
+import org.perfsonar.base2.xml.nmwg.Message;
+import org.perfsonar.base2.xml.nmwg.Metadata;
+import
org.perfsonar.service.measurementArchive.rrdType.storage.MetadataStorageDAO;
+import
org.perfsonar.service.measurementArchive.rrdType.storage.MetadataStorageDAOFactory;
+import
org.perfsonar.service.measurementArchive.rrdType.storage.persistence.MetadaKeyResponse;
+import
org.perfsonar.service.measurementArchive.rrdType.storage.persistence.SetupDataKeyResponse;
+import
org.perfsonar.service.measurementArchive.rrdType.storage.persistence.entity.Interfaces;
+import
org.perfsonar.service.measurementArchive.rrdType.storage.sql.query.QueryGenerator;
+
+public class MysqlMetadataStorageDAOImpl extends Component implements
MetadataStorageDAO
+{
+ public static final String PERSISTENCE_UNIT_NAME =
"org.perfsonar.service.measurementArchive.rrdType.storage.sql";
+ protected EntityManager em;
+ protected final QueryGenerator qg = new QueryGenerator();
+ private EntityManagerFactory entityManagerFactory;
+
+ @Override
+ public void destroy() throws PerfSONARException
+ {
+ em.close();
+ entityManagerFactory.close();
+ }
+
+ @Override
+ public void init() throws PerfSONARException
+ {
+ Component configuration =
ConfigurationManager.getInstance().getConfiguration().getAuxiliaryComponent(
+ MetadataStorageDAOFactory.METADATA_STORAGE_DAO_NAME);
+ String dbUri = configuration.getOption("uri").getValue();
+ String schema = configuration.getOption("schema").getValue();
+ String username = configuration.getOption("username").getValue();
+ String password = configuration.getOption("password").getValue();
+
+ if (!dbUri.endsWith("/")) {
+ dbUri = dbUri + "/";
+ }
+
+ try {
+ Map<String, Object> jpaConfig = new HashMap<String, Object>();
+ jpaConfig.put("javax.persistence.jdbc.driver",
"com.mysql.jdbc.Driver");
+ //FIXME: check if we need '&' or '&'
+ jpaConfig.put("javax.persistence.jdbc.url", dbUri + schema +
"?autoReconnectForPools=true&autoReconnectForPools=true");
+ jpaConfig.put("javax.persistence.jdbc.user", username);
+ jpaConfig.put("javax.persistence.jdbc.password", password);
+ entityManagerFactory =
Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, jpaConfig);
+ em = entityManagerFactory.createEntityManager();
+ } catch (RuntimeException e) {
+ throw new PerfSONARException("Persistence initialization failed:
" + e.getMessage(), e);
+ }
+ }
+
+ @Override
+ public void run() throws PerfSONARException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public Collection<Element> fetch(Element request) throws
PerfSONARException
+ {
+ // TODO Auto-generated method stub
+ long t1 = System.currentTimeMillis();
+ checkMetadataCorectness((Message) request);
+
+ if (!(request instanceof Message)) {
+ throw new PerfSONARException("parse",
+ "Object [" + request.getClass() +
"] is not a valid Message [" + Message.class
+ + "] element.");
+ }
+
+ Message message = (Message) request;
+ SetupDataKeyResponse sdkr = new SetupDataKeyResponse();
+
+ Collection<Element> result = new ArrayList<Element>();
+ for (Metadata metadata : message.getMetadataCollection()) {
+ Query query = qg.getQuery(em, metadata, Interfaces.TABLE);
+ result = sdkr.fetchElements(query.getResultList().iterator());
+ }
+
+ long t2 = System.currentTimeMillis();
+ logger.info("TIME of Fetch: " + (t2 - t1));
+
+ return result;
+ }
+
+ /**
+ * @return String with the response message (in NMWG format) of
MetadataKeyRequest
+ * @throws PerfSONARException
+ */
+ public String rawFetch() throws PerfSONARException
+ {
+
+
+ List<Interfaces> resultList = (List<Interfaces>)
em.createNamedQuery(Interfaces.ALL).getResultList();
+ MetadaKeyResponse mKRR = new MetadaKeyResponse();
+
+ return mKRR.fetchMetadataMessage(resultList.iterator());
+ }
+
+ @Override
+ public String rawFetch(Element request) throws PerfSONARException
+ {
+
+ long t1 = System.currentTimeMillis();
+ checkMetadataCorectness((Message) request);
+ Metadata metadata = ((Message)
request).getMetadataCollection().iterator().next();
+
+ Query query = qg.getQuery(em, metadata, Interfaces.TABLE);
+
+ MetadaKeyResponse mKRR = new MetadaKeyResponse();
+ String result =
mKRR.fetchMetadataMessage(query.getResultList().iterator());
+
+ long t2 = System.currentTimeMillis();
+ logger.info("TIME of rawFetch: " + (t2 - t1));
+
+ return result;
+
+ }
+
+ @Override
+ public void remove(Element request) throws PerfSONARException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void store(Element request) throws PerfSONARException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void update(Element request) throws PerfSONARException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ private void checkMetadataCorectness(Message request) throws
PerfSONARException
+ {
+
+ if (request.getMetadataCollection().isEmpty()) {
+ logger.warn("can not find any metadatas with a valid content");
+ throw new PerfSONARException("query_exception", "can not find
any metadatas with a valid content");
+ }
+
+ String eventType = null;
+ for (Metadata m : request.getMetadataCollection()) {
+
+ try {
+ eventType = m.getFirstEventType().getEventType().trim();
+ } catch (Exception ex) {
+
+ logger.warn("can not find correct eventType in metadata
element");
+ throw new PerfSONARException("query_exception", "can not
find correct eventType in metadata element");
+ }
+ if (eventType != null) {
+ break;
+ }
+
+ }
+
+
+ if (eventType == null || eventType.isEmpty()) {
+ logger.warn("can not find correct eventType in metadata
element");
+ throw new PerfSONARException("query_exception", "can not find
eventType in metadata element");
+ }
+
+
+ }
+
+
+}
- [pS-dev] [GEANT/SA2/ps-java-services] r6189 - in branches: . perfsonar-java-rrd-ma-3.4-stable/src/ main/java/org/perfsonar/service/measurementArchive/rrdType /storage/sql, svn-noreply, 03/13/2013
Archive powered by MHonArc 2.6.16.