airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sma...@apache.org
Subject svn commit: r1525715 - in /airavata/trunk/modules: registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ regi...
Date Mon, 23 Sep 2013 22:18:04 GMT
Author: smarru
Date: Mon Sep 23 22:18:03 2013
New Revision: 1525715

URL: http://svn.apache.org/r1525715
Log:
committing Viknes's patch for AIRAVATA-345

Modified:
    airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/AiravataJPARegistry.java
    airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ExperimentDataRetriever.java
    airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/ProvenanceRegistry.java
    airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/RegistryClient.java
    airavata/trunk/modules/rest/mappings/src/main/java/org/apache/airavata/rest/mappings/utils/ResourcePathConstants.java
    airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/ProvenanceRegistryResource.java

Modified: airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/AiravataJPARegistry.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/AiravataJPARegistry.java?rev=1525715&r1=1525714&r2=1525715&view=diff
==============================================================================
--- airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/AiravataJPARegistry.java
(original)
+++ airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/AiravataJPARegistry.java
Mon Sep 23 22:18:03 2013
@@ -1721,6 +1721,15 @@ public class AiravataJPARegistry extends
         }
         return (new ExperimentDataRetriever()).getExperiments(user);
 	}
+	
+	@Override
+	public List<ExperimentData> getExperiments(HashMap<String,String> params)
+			throws RegistryException {
+        if (provenanceRegistry != null){
+            return provenanceRegistry.getExperiments(params);
+        }
+        return (new ExperimentDataRetriever()).getExperiments(params);
+	}
 
 
 	@Override

Modified: airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ExperimentDataRetriever.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ExperimentDataRetriever.java?rev=1525715&r1=1525714&r2=1525715&view=diff
==============================================================================
--- airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ExperimentDataRetriever.java
(original)
+++ airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ExperimentDataRetriever.java
Mon Sep 23 22:18:03 2013
@@ -21,6 +21,11 @@
 
 package org.apache.airavata.persistance.registry.jpa.resources;
 
+import org.apache.airavata.persistance.registry.jpa.Resource;
+import org.apache.airavata.persistance.registry.jpa.ResourceType;
+import org.apache.airavata.persistance.registry.jpa.ResourceUtils;
+import org.apache.airavata.persistance.registry.jpa.model.Users;
+import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
 import org.apache.airavata.registry.api.exception.worker.ExperimentLazyLoadedException;
 import org.apache.airavata.registry.api.impl.ExperimentDataImpl;
 import org.apache.airavata.registry.api.impl.WorkflowExecutionDataImpl;
@@ -36,6 +41,9 @@ import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.Date;
 
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
 public class ExperimentDataRetriever {
     private static final Logger logger = LoggerFactory.getLogger(ExperimentDataRetriever.class);
 
@@ -304,6 +312,101 @@ public class ExperimentDataRetriever {
        return experimentDataList;
 
     }
+    
+    public List<ExperimentData> getExperiments(HashMap<String, String> params)
{
+    	String connectionURL = Utils.getJDBCURL();
+        Connection connection = null;
+        ResultSet rs = null;
+        Statement statement;
+        Map<String, ExperimentData> experimentDataMap = new HashMap<String, ExperimentData>();
+        List<ExperimentData> experimentDataList = new ArrayList<ExperimentData>();
+        List<WorkflowExecution> experimentWorkflowInstances = new ArrayList<WorkflowExecution>();
+
+        try {
+            Class.forName(Utils.getJDBCDriver()).newInstance();
+            connection = DriverManager.getConnection(connectionURL, Utils.getJDBCUser(),
+                    Utils.getJDBCPassword());
+            statement = connection.createStatement();
+            String queryString = "SELECT e.experiment_ID, ed.name, ed.username, em.metadata,
" +
+                    "wd.workflow_instanceID, wd.template_name, wd.status, wd.start_time,"
+
+                    "wd.last_update_time, nd.node_id, nd.inputs, nd.outputs, " +
+                    "e.project_name, e.submitted_date, nd.node_type, nd.status," +
+                    "nd.start_time, nd.last_update_time" +
+                    " FROM Experiment e INNER JOIN Experiment_Data ed " +
+                    "ON e.experiment_ID = ed.experiment_ID " +
+                    "LEFT JOIN Experiment_Metadata em " +
+                    "ON ed.experiment_ID = em.experiment_ID  " +
+                    "LEFT JOIN Workflow_Data wd " +
+                    "ON e.experiment_ID = wd.experiment_ID " +
+                    "LEFT JOIN Node_Data nd " +
+                    "ON wd.workflow_instanceID = nd.workflow_instanceID ";
+            
+            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            if(params.keySet().size()>0) {
+            	queryString += "WHERE ";
+            	String username = params.get("username");
+            	String from = params.get("fromDate");
+            	String to = params.get("toDate");
+            	
+            	if(username!=null && !username.isEmpty()) {
+            		queryString += "ed.username='" + username + "'";
+            		if((from!=null && !from.isEmpty()) || (to!=null && !to.isEmpty()))
{
+            			queryString += " AND ";
+            		}
+            	}
+            	if(from!=null && !from.isEmpty()) {
+            		Date fromDate = dateFormat.parse(from);
+            		Timestamp fromTime = new Timestamp(fromDate.getTime());
+            		queryString += "e.submitted_date>='" + fromTime + "'";
+            		if(to!=null && to!="") {
+            			queryString += " AND ";
+            		}
+            	}
+            	if(to!=null && !to.isEmpty()) {
+            		Date toDate = dateFormat.parse(to);
+            		Timestamp toTime = new Timestamp(toDate.getTime());
+            		queryString += "e.submitted_date<='" + toTime + "'";
+            	}
+            }
+            rs = statement.executeQuery(queryString);
+            if (rs != null) {
+                while (rs.next()) {
+                    ExperimentData experimentData = null;
+                    if (experimentDataMap.containsKey(rs.getString(1))) {
+                        experimentData = experimentDataMap.get(rs.getString(1));
+                    }else{
+                        experimentData = new ExperimentDataImpl();
+                        experimentData.setExperimentId(rs.getString(1));
+                        experimentData.setExperimentName(rs.getString(2));
+                        experimentData.setUser(rs.getString(3));
+                        experimentData.setMetadata(rs.getString(4));
+                        experimentData.setTopic(rs.getString(1));
+                        experimentDataMap.put(experimentData.getExperimentId(),experimentData);
+                        experimentDataList.add(experimentData);
+                    }
+                    fillWorkflowInstanceData(experimentData, rs, experimentWorkflowInstances);
+                }
+            }
+            if (rs != null) {
+                rs.close();
+            }
+            statement.close();
+            connection.close();
+        } catch (InstantiationException e) {
+            logger.error(e.getMessage(), e);
+        } catch (IllegalAccessException e) {
+            logger.error(e.getMessage(), e);
+        } catch (ClassNotFoundException e) {
+            logger.error(e.getMessage(), e);
+        } catch (SQLException e) {
+            logger.error(e.getMessage(), e);
+        } catch (ExperimentLazyLoadedException e) {
+            logger.error(e.getMessage(), e);
+        } catch (ParseException e) {
+            logger.error(e.getMessage(), e);
+        }
+       return experimentDataList;
+	}
 
 
     public ExperimentData getExperimentMetaInformation(String experimentId){
@@ -451,4 +554,6 @@ public class ExperimentDataRetriever {
         }
         return experimentDataList;
     }
-}
+
+	
+}

Modified: airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/ProvenanceRegistry.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/ProvenanceRegistry.java?rev=1525715&r1=1525714&r2=1525715&view=diff
==============================================================================
--- airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/ProvenanceRegistry.java
(original)
+++ airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/ProvenanceRegistry.java
Mon Sep 23 22:18:03 2013
@@ -22,6 +22,7 @@
 package org.apache.airavata.registry.api;
 
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 
 import org.apache.airavata.registry.api.exception.RegistryException;
@@ -279,6 +280,8 @@ public interface ProvenanceRegistry exte
 	 */
     public List<ExperimentData> getExperimentByUser(String user) throws RegistryException;
     
+	public List<ExperimentData> getExperiments(HashMap<String, String> params) throws
RegistryException;
+    
     /**
      * Return the pageNo set of experiments launched by the given user if grouped in to pages
of size pageSize
      * @param user

Modified: airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/RegistryClient.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/RegistryClient.java?rev=1525715&r1=1525714&r2=1525715&view=diff
==============================================================================
--- airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/RegistryClient.java
(original)
+++ airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/RegistryClient.java
Mon Sep 23 22:18:03 2013
@@ -23,6 +23,7 @@ package org.apache.airavata.rest.client;
 
 import java.net.URI;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -640,6 +641,10 @@ public class RegistryClient extends Aira
     public List<ExperimentData> getExperimentByUser(String user) throws RegistryException
{
         return getProvenanceResourceClient().getExperimentByUser(user);
     }
+    
+    public List<ExperimentData> getExperiments(HashMap<String,String> params)
throws RegistryException {
+        return null;
+    }
 
 
     public List<ExperimentData> getExperimentByUser(String user, int pageSize, int
pageNo) throws RegistryException {

Modified: airavata/trunk/modules/rest/mappings/src/main/java/org/apache/airavata/rest/mappings/utils/ResourcePathConstants.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/mappings/src/main/java/org/apache/airavata/rest/mappings/utils/ResourcePathConstants.java?rev=1525715&r1=1525714&r2=1525715&view=diff
==============================================================================
--- airavata/trunk/modules/rest/mappings/src/main/java/org/apache/airavata/rest/mappings/utils/ResourcePathConstants.java
(original)
+++ airavata/trunk/modules/rest/mappings/src/main/java/org/apache/airavata/rest/mappings/utils/ResourcePathConstants.java
Mon Sep 23 22:18:03 2013
@@ -124,6 +124,7 @@ public class ResourcePathConstants {
         public static final String GET_EXPERIMENT = "get/experiment";
         public static final String GET_EXPERIMENT_ID_USER = "get/experimentId/user";
         public static final String GET_EXPERIMENT_USER = "get/experiment/user";
+        public static final String GET_EXPERIMENTS = "get/experiments";
         public static final String UPDATE_WORKFLOWNODE_STATUS = "update/workflownode/status";
         public static final String GET_WORKFLOWNODE_STATUS = "get/workflownode/status";
         public static final String GET_WORKFLOWNODE_STARTTIME = "get/workflownode/starttime";

Modified: airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/ProvenanceRegistryResource.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/ProvenanceRegistryResource.java?rev=1525715&r1=1525714&r2=1525715&view=diff
==============================================================================
--- airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/ProvenanceRegistryResource.java
(original)
+++ airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/ProvenanceRegistryResource.java
Mon Sep 23 22:18:03 2013
@@ -36,11 +36,13 @@ import javax.ws.rs.*;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
+
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 
 /**
@@ -811,11 +813,45 @@ public class ProvenanceRegistryResource 
             }
         }
     }
+    
+    @GET
+    @Path(ResourcePathConstants.ProvenanceResourcePathConstants.GET_EXPERIMENTS)
+    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+    public Response getExperiments(@QueryParam("username") String username, @QueryParam("fromDate")
String from, @QueryParam("toDate") String to) {
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry(context);
+        try {
+            HashMap<String, String> params = new HashMap<String, String>();
+            if(username!=null && !username.isEmpty()) params.put("username", username);
+            if(from!=null && !from.isEmpty()) params.put("fromDate", from);
+            if(to!=null && !to.isEmpty()) params.put("toDate", to);
+            List<ExperimentData> experiments = airavataRegistry.getExperiments(params);
+            ExperimentDataList experimentData = new ExperimentDataList();
+            List<ExperimentDataImpl> experimentDatas = new ArrayList<ExperimentDataImpl>();
+            for (ExperimentData anExperimentDataList : experiments) {
+                experimentDatas.add((ExperimentDataImpl)anExperimentDataList);
+            }
+            experimentData.setExperimentDataList(experimentDatas);
+            if (experiments.size() != 0) {
+                Response.ResponseBuilder builder = Response.status(Response.Status.OK);
+                builder.entity(experimentData);
+                return builder.build();
+            } else {
+                Response.ResponseBuilder builder = Response.status(Response.Status.NO_CONTENT);
+                return builder.build();
+            }
+        } catch (Throwable e) {
+            return WebAppUtil.reportInternalServerError(ResourcePathConstants.ProvenanceResourcePathConstants.GET_EXPERIMENT_USER,
e);
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(context, airavataRegistry);
+            }
+        }
+    }
+
 
     /**
      * This method will update the workflow node status
-     *
-     * @param workflowInstanceId workflow instance ID
+     *     * @param workflowInstanceId workflow instance ID
      * @param nodeId             node ID
      * @param executionStatus    node execution status
      * @return HTTP response



Mime
View raw message