You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ch...@apache.org on 2015/06/05 17:03:12 UTC
[13/22] airavata git commit: adding registry changes
http://git-wip-us.apache.org/repos/asf/airavata/blob/5a648a60/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/WorkflowResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/WorkflowResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/WorkflowResource.java
deleted file mode 100644
index 3e52019..0000000
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/WorkflowResource.java
+++ /dev/null
@@ -1,382 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.aiaravata.application.catalog.data.resources;
-
-import org.airavata.appcatalog.cpi.AppCatalogException;
-import org.apache.aiaravata.application.catalog.data.model.Workflow;
-import org.apache.aiaravata.application.catalog.data.util.AppCatalogJPAUtils;
-import org.apache.aiaravata.application.catalog.data.util.AppCatalogQueryGenerator;
-import org.apache.aiaravata.application.catalog.data.util.AppCatalogResourceType;
-import org.apache.airavata.common.exception.ApplicationSettingsException;
-import org.apache.airavata.common.utils.AiravataUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.persistence.EntityManager;
-import javax.persistence.Query;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.List;
-
-public class WorkflowResource extends AbstractResource {
- private final static Logger logger = LoggerFactory.getLogger(WorkflowResource.class);
- private String wfName;
- private String createdUser;
- private String graph;
- private String wfTemplateId;
- private Timestamp createdTime;
- private Timestamp updatedTime;
- private String image;
- private String gatewayId;
-
- public Timestamp getCreatedTime() {
- return createdTime;
- }
-
- public void setCreatedTime(Timestamp createdTime) {
- this.createdTime = createdTime;
- }
-
- public Timestamp getUpdatedTime() {
- return updatedTime;
- }
-
- public void setUpdatedTime(Timestamp updatedTime) {
- this.updatedTime = updatedTime;
- }
-
- public String getImage() {
- return image;
- }
-
- public void setImage(String image) {
- this.image = image;
- }
-
- public String getGatewayId() {
- return gatewayId;
- }
-
- public void setGatewayId(String gatewayId) {
- this.gatewayId = gatewayId;
- }
-
- @Override
- public void remove(Object identifier) throws AppCatalogException {
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW);
- generator.setParameter(WorkflowConstants.WF_TEMPLATE_ID, identifier);
- Query q = generator.deleteQuery(em);
- q.executeUpdate();
- em.getTransaction().commit();
- em.close();
- } catch (ApplicationSettingsException e) {
- logger.error(e.getMessage(), e);
- throw new AppCatalogException(e);
- } finally {
- if (em != null && em.isOpen()) {
- if (em.getTransaction().isActive()) {
- em.getTransaction().rollback();
- }
- em.close();
- }
- }
- }
-
- @Override
- public Resource get(Object identifier) throws AppCatalogException {
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW);
- generator.setParameter(WorkflowConstants.WF_TEMPLATE_ID, identifier);
- Query q = generator.selectQuery(em);
- Workflow workflow = (Workflow) q.getSingleResult();
- WorkflowResource workflowResource = (WorkflowResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.WORKFLOW, workflow);
- em.getTransaction().commit();
- em.close();
- return workflowResource;
- } catch (ApplicationSettingsException e) {
- logger.error(e.getMessage(), e);
- throw new AppCatalogException(e);
- } finally {
- if (em != null && em.isOpen()) {
- if (em.getTransaction().isActive()) {
- em.getTransaction().rollback();
- }
- em.close();
- }
- }
- }
-
- @Override
- public List<Resource> get(String fieldName, Object value) throws AppCatalogException {
- List<Resource> workflowResources = new ArrayList<Resource>();
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW);
- Query q;
- if ((fieldName.equals(WorkflowConstants.WF_NAME)) || (fieldName.equals(WorkflowConstants.CREATED_USER)) || (fieldName.equals(WorkflowConstants.GRAPH)) || (fieldName.equals(WorkflowConstants.WF_TEMPLATE_ID))) {
- generator.setParameter(fieldName, value);
- q = generator.selectQuery(em);
- List<?> results = q.getResultList();
- for (Object result : results) {
- Workflow workflow = (Workflow) result;
- WorkflowResource workflowResource = (WorkflowResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.WORKFLOW, workflow);
- workflowResources.add(workflowResource);
- }
- } else {
- em.getTransaction().commit();
- em.close();
- logger.error("Unsupported field name for Workflow Resource.", new IllegalArgumentException());
- throw new IllegalArgumentException("Unsupported field name for Workflow Resource.");
- }
- em.getTransaction().commit();
- em.close();
- } catch (ApplicationSettingsException e) {
- logger.error(e.getMessage(), e);
- throw new AppCatalogException(e);
- } finally {
- if (em != null && em.isOpen()) {
- if (em.getTransaction().isActive()) {
- em.getTransaction().rollback();
- }
- em.close();
- }
- }
- return workflowResources;
- }
-
- @Override
- public List<Resource> getAll() throws AppCatalogException {
- List<Resource> workflows = new ArrayList<Resource>();
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW);
- generator.setParameter(WorkflowConstants.GATEWAY_ID, gatewayId);
- Query q = generator.selectQuery(em);
- List results = q.getResultList();
- if (results.size() != 0) {
- for (Object result : results) {
- Workflow workflow = (Workflow) result;
- WorkflowResource wfResource =
- (WorkflowResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.WORKFLOW, workflow);
- workflows.add(wfResource);
- }
- }
- em.getTransaction().commit();
- em.close();
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- throw new AppCatalogException(e);
- } finally {
- if (em != null && em.isOpen()) {
- if (em.getTransaction().isActive()) {
- em.getTransaction().rollback();
- }
- em.close();
- }
- }
- return workflows;
- }
-
- @Override
- public List<String> getAllIds() throws AppCatalogException {
- List<String> workflowIds = new ArrayList<String>();
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW);
- generator.setParameter(WorkflowConstants.GATEWAY_ID, gatewayId);
- Query q = generator.selectQuery(em);
- List results = q.getResultList();
- if (results.size() != 0) {
- for (Object result : results) {
- Workflow workflow = (Workflow) result;
- workflowIds.add(workflow.getWfTemplateId());
- }
- }
- em.getTransaction().commit();
- em.close();
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- throw new AppCatalogException(e);
- } finally {
- if (em != null && em.isOpen()) {
- if (em.getTransaction().isActive()) {
- em.getTransaction().rollback();
- }
- em.close();
- }
- }
- return workflowIds;
- }
-
- @Override
- public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
- List<String> workflowResourceIDs = new ArrayList<String>();
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW);
- Query q;
- if ((fieldName.equals(WorkflowConstants.WF_NAME)) || (fieldName.equals(WorkflowConstants.CREATED_USER)) || (fieldName.equals(WorkflowConstants.GRAPH)) || (fieldName.equals(WorkflowConstants.WF_TEMPLATE_ID))) {
- generator.setParameter(fieldName, value);
- q = generator.selectQuery(em);
- List<?> results = q.getResultList();
- for (Object result : results) {
- Workflow workflow = (Workflow) result;
- WorkflowResource workflowResource = (WorkflowResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.WORKFLOW, workflow);
- workflowResourceIDs.add(workflowResource.getWfTemplateId());
- }
- } else {
- em.getTransaction().commit();
- em.close();
- logger.error("Unsupported field name for Workflow Resource.", new IllegalArgumentException());
- throw new IllegalArgumentException("Unsupported field name for Workflow Resource.");
- }
- em.getTransaction().commit();
- em.close();
- } catch (ApplicationSettingsException e) {
- logger.error(e.getMessage(), e);
- throw new AppCatalogException(e);
- } finally {
- if (em != null && em.isOpen()) {
- if (em.getTransaction().isActive()) {
- em.getTransaction().rollback();
- }
- em.close();
- }
- }
- return workflowResourceIDs;
- }
-
- @Override
- public void save() throws AppCatalogException {
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- Workflow existingWorkflow = em.find(Workflow.class, wfTemplateId);
- em.close();
- Workflow workflow;
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- if (existingWorkflow == null) {
- workflow = new Workflow();
- workflow.setCreationTime(AiravataUtils.getCurrentTimestamp());
- } else {
- workflow = existingWorkflow;
- workflow.setUpdateTime(AiravataUtils.getCurrentTimestamp());
- }
- workflow.setWfName(getWfName());
- workflow.setCreatedUser(getCreatedUser());
- workflow.setGatewayId(gatewayId);
- if (getGraph() != null){
- workflow.setGraph(getGraph().toCharArray());
- }
- if (image != null){
- workflow.setImage(image.getBytes());
- }
- workflow.setWfTemplateId(getWfTemplateId());
- if (existingWorkflow == null) {
- em.persist(workflow);
- } else {
- em.merge(workflow);
- }
- em.getTransaction().commit();
- em.close();
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- throw new AppCatalogException(e);
- } finally {
- if (em != null && em.isOpen()) {
- if (em.getTransaction().isActive()) {
- em.getTransaction().rollback();
- }
- em.close();
- }
- }
- }
-
- @Override
- public boolean isExists(Object identifier) throws AppCatalogException {
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- Workflow workflow = em.find(Workflow.class, identifier);
- em.close();
- return workflow != null;
- } catch (ApplicationSettingsException e) {
- logger.error(e.getMessage(), e);
- throw new AppCatalogException(e);
- } finally {
- if (em != null && em.isOpen()) {
- if (em.getTransaction().isActive()) {
- em.getTransaction().rollback();
- }
- em.close();
- }
- }
- }
-
- public String getWfName() {
- return wfName;
- }
-
- public String getCreatedUser() {
- return createdUser;
- }
-
- public String getGraph() {
- return graph;
- }
-
- public String getWfTemplateId() {
- return wfTemplateId;
- }
-
- public void setWfName(String wfName) {
- this.wfName=wfName;
- }
-
- public void setCreatedUser(String createdUser) {
- this.createdUser=createdUser;
- }
-
- public void setGraph(String graph) {
- this.graph=graph;
- }
-
- public void setWfTemplateId(String wfTemplateId) {
- this.wfTemplateId=wfTemplateId;
- }
-}
http://git-wip-us.apache.org/repos/asf/airavata/blob/5a648a60/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ExperimentCatalogImpl.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ExperimentCatalogImpl.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ExperimentCatalogImpl.java
index 88fbe29..6a7f723 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ExperimentCatalogImpl.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ExperimentCatalogImpl.java
@@ -19,7 +19,7 @@
*
*/
-package org.apache.airavata.experiment.catalog.impl;
+package org.apache.airavata.registry.core.experiment.catalog.impl;
import org.apache.airavata.common.exception.ApplicationSettingsException;
import org.apache.airavata.common.utils.ServerSettings;
http://git-wip-us.apache.org/repos/asf/airavata/blob/5a648a60/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ExperimentRegistry.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ExperimentRegistry.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ExperimentRegistry.java
index 1178461..35605f8 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ExperimentRegistry.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ExperimentRegistry.java
@@ -19,7 +19,7 @@
*
*/
-package org.apache.airavata.experiment.catalog.impl;
+package org.apache.airavata.registry.core.experiment.catalog.impl;
import org.apache.airavata.common.logger.AiravataLogger;
import org.apache.airavata.common.logger.AiravataLoggerFactory;
http://git-wip-us.apache.org/repos/asf/airavata/blob/5a648a60/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/GatewayRegistry.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/GatewayRegistry.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/GatewayRegistry.java
index 1aa165c..d97f0d4 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/GatewayRegistry.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/GatewayRegistry.java
@@ -19,7 +19,7 @@
*
*/
-package org.apache.airavata.experiment.catalog.impl;
+package org.apache.airavata.registry.core.experiment.catalog.impl;
import org.apache.airavata.common.exception.ApplicationSettingsException;
import org.apache.airavata.common.utils.ServerSettings;
http://git-wip-us.apache.org/repos/asf/airavata/blob/5a648a60/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/LoggingExperimentCatalogImpl.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/LoggingExperimentCatalogImpl.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/LoggingExperimentCatalogImpl.java
index d45c4c5..4849385 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/LoggingExperimentCatalogImpl.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/LoggingExperimentCatalogImpl.java
@@ -18,7 +18,7 @@
* under the License.
*
*/
-package org.apache.airavata.experiment.catalog.impl;
+package org.apache.airavata.registry.core.experiment.catalog.impl;
import org.apache.airavata.registry.cpi.*;
import org.slf4j.Logger;
http://git-wip-us.apache.org/repos/asf/airavata/blob/5a648a60/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ProjectRegistry.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ProjectRegistry.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ProjectRegistry.java
index c045a93..f0c4965 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ProjectRegistry.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ProjectRegistry.java
@@ -19,7 +19,7 @@
*
*/
-package org.apache.airavata.experiment.catalog.impl;
+package org.apache.airavata.registry.core.experiment.catalog.impl;
import org.apache.airavata.common.utils.AiravataUtils;
import org.apache.airavata.model.workspace.Project;
http://git-wip-us.apache.org/repos/asf/airavata/blob/5a648a60/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/RegistryFactory.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/RegistryFactory.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/RegistryFactory.java
index 5b8ce18..b54e0cf 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/RegistryFactory.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/RegistryFactory.java
@@ -19,7 +19,7 @@
*
*/
-package org.apache.airavata.experiment.catalog.impl;
+package org.apache.airavata.registry.core.experiment.catalog.impl;
import org.apache.airavata.common.exception.ApplicationSettingsException;
import org.apache.airavata.common.utils.ServerSettings;
http://git-wip-us.apache.org/repos/asf/airavata/blob/5a648a60/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/UserReg.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/UserReg.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/UserReg.java
index c7f80c7..e720df0 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/UserReg.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/UserReg.java
@@ -19,7 +19,7 @@
*
*/
-package org.apache.airavata.experiment.catalog.impl;
+package org.apache.airavata.registry.core.experiment.catalog.impl;
import org.apache.airavata.common.exception.ApplicationSettingsException;
import org.apache.airavata.common.utils.ServerSettings;
http://git-wip-us.apache.org/repos/asf/airavata/blob/5a648a60/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experimet/catalog/JPAConstants.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experimet/catalog/JPAConstants.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experimet/catalog/JPAConstants.java
deleted file mode 100644
index b558d03..0000000
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experimet/catalog/JPAConstants.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.airavata.experiment.catalog;
-
-public class JPAConstants {
- public static final String KEY_JDBC_URL = "registry.jdbc.url";
- public static final String KEY_JDBC_USER = "registry.jdbc.user";
- public static final String KEY_JDBC_PASSWORD = "registry.jdbc.password";
- public static final String KEY_JDBC_DRIVER = "registry.jdbc.driver";
- public static final String KEY_DERBY_START_ENABLE = "start.derby.server.mode";
- public static final String VALIDATION_QUERY = "validationQuery";
- public static final String JPA_CACHE_SIZE = "jpa.cache.size";
- public static final String ENABLE_CACHING = "cache.enable";
-}
http://git-wip-us.apache.org/repos/asf/airavata/blob/5a648a60/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experimet/catalog/Resource.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experimet/catalog/Resource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experimet/catalog/Resource.java
deleted file mode 100644
index bdfd948..0000000
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experimet/catalog/Resource.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-package org.apache.airavata.experiment.catalog;
-
-import org.apache.airavata.registry.cpi.RegistryException;
-
-import java.util.List;
-
-public interface Resource {
- /**
- * This method will create associate resource objects for the given resource type.
- * @param type child resource type
- * @return associate child resource
- */
- Resource create(ResourceType type) throws RegistryException, RegistryException;
-
- /**
- * This method will remove the given child resource from the database
- * @param type child resource type
- * @param name child resource name
- */
- void remove(ResourceType type, Object name) throws RegistryException;
-
- /**
- * This method will return the given child resource from the database
- * @param type child resource type
- * @param name child resource name
- * @return associate child resource
- */
- Resource get(ResourceType type, Object name) throws RegistryException;
-
- /**
- * This method will list all the child resources for the given resource type
- * @param type child resource type
- * @return list of child resources of the given child resource type
- */
- List<Resource> get(ResourceType type) throws RegistryException;
-
- /**
- * This method will save the resource to the database.
- */
- void save() throws RegistryException;
-
- /**
- * This method will check whether an entry from the given resource type and resource name
- * exists in the database
- * @param type child resource type
- * @param name child resource name
- * @return whether the entry exists in the database or not
- */
- boolean isExists(ResourceType type, Object name) throws RegistryException;
-
-}
http://git-wip-us.apache.org/repos/asf/airavata/blob/5a648a60/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experimet/catalog/ResourceType.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experimet/catalog/ResourceType.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experimet/catalog/ResourceType.java
deleted file mode 100644
index ea66a90..0000000
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experimet/catalog/ResourceType.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-package org.apache.airavata.experiment.catalog;
-
-public enum ResourceType {
- GATEWAY,
- PROJECT,
- USER,
- PROJECT_USER,
- CONFIGURATION,
- GATEWAY_WORKER,
- EXPERIMENT,
- EXPERIMENT_SUMMARY,
- NOTIFICATION_EMAIL,
- EXPERIMENT_INPUT,
- EXPERIMENT_OUTPUT,
- WORKFLOW_NODE_DETAIL,
- TASK_DETAIL,
- ERROR_DETAIL,
- APPLICATION_INPUT,
- APPLICATION_OUTPUT,
- NODE_INPUT,
- NODE_OUTPUT,
- JOB_DETAIL,
- DATA_TRANSFER_DETAIL,
- STATUS,
- CONFIG_DATA,
- COMPUTATIONAL_RESOURCE_SCHEDULING,
- ADVANCE_INPUT_DATA_HANDLING,
- ADVANCE_OUTPUT_DATA_HANDLING,
- QOS_PARAM
-}
http://git-wip-us.apache.org/repos/asf/airavata/blob/5a648a60/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experimet/catalog/ResourceUtils.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experimet/catalog/ResourceUtils.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experimet/catalog/ResourceUtils.java
deleted file mode 100644
index a8d8e83..0000000
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experimet/catalog/ResourceUtils.java
+++ /dev/null
@@ -1,525 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-package org.apache.airavata.experiment.catalog;
-
-import org.apache.airavata.experiment.catalog.model.*;
-import org.apache.airavata.experiment.catalog.resources.*;
-import org.apache.airavata.experiment.catalog.utils.QueryGenerator;
-import org.apache.airavata.registry.cpi.RegistryException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
-import javax.persistence.Query;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class ResourceUtils {
- private final static Logger logger = LoggerFactory.getLogger(ResourceUtils.class);
- private static final String PERSISTENCE_UNIT_NAME = "airavata_data";
- protected static EntityManagerFactory factory;
-
- public static void reset(){
- factory=null;
- }
-
- public static EntityManager getEntityManager(){
- if (factory == null) {
- String connectionProperties = "DriverClassName=" + Utils.getJDBCDriver() + "," + "Url=" + Utils.getJDBCURL() + "?autoReconnect=true,," +
- "Username=" + Utils.getJDBCUser() + "," + "Password=" + Utils.getJDBCPassword() + ",validationQuery=" +
- Utils.getValidationQuery();
- System.out.println(connectionProperties);
- Map<String, String> properties = new HashMap<String, String>();
- properties.put("openjpa.ConnectionDriverName", "org.apache.commons.dbcp.BasicDataSource");
- properties.put("openjpa.ConnectionProperties", connectionProperties);
- properties.put("openjpa.DynamicEnhancementAgent", "true");
- properties.put("openjpa.RuntimeUnenhancedClasses", "unsupported");
- properties.put("openjpa.DataCache","" + Utils.isCachingEnabled() + "(CacheSize=" + Utils.getJPACacheSize() + ", SoftReferenceSize=0)");
- properties.put("openjpa.QueryCache","" + Utils.isCachingEnabled() + "(CacheSize=" + Utils.getJPACacheSize() + ", SoftReferenceSize=0)");
- properties.put("openjpa.RemoteCommitProvider","sjvm");
- properties.put("openjpa.Log","DefaultLevel=INFO, Runtime=INFO, Tool=INFO, SQL=INFO");
- properties.put("openjpa.jdbc.DBDictionary","SupportsMultipleNontransactionalResultSets=false");
-// properties.put("openjpa.ReadLockLevel", "none");
-// properties.put("openjpa.WriteLockLevel", "none");
-// properties.put("openjpa.LockTimeout", "30000");
-// properties.put("openjpa.LockManager", "none");
- properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
- properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72, PrintParameters=true, MaxActive=10, MaxIdle=5, MinIdle=2, MaxWait=31536000, autoReconnect=true");
- properties.put("openjpa.jdbc.QuerySQLCache", "false");
- factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties);
- }
- return factory.createEntityManager();
- }
-
- /**
- * @param gatewayId
- * @return
- */
- public static Resource createGateway(String gatewayId) throws RegistryException {
- if (!isGatewayExist(gatewayId)) {
- GatewayResource gatewayResource = new GatewayResource();
- gatewayResource.setGatewayId(gatewayId);
- return gatewayResource;
- }else {
- return getGateway(gatewayId);
- }
- }
-
- public static UserResource createUser(String username, String password) throws RegistryException {
- if (!isUserExist(username)) {
- UserResource userResource = new UserResource();
- userResource.setUserName(username);
- userResource.setPassword(password);
- return userResource;
- }else {
- return (UserResource)getUser(username);
- }
-
- }
-
- public static Resource getGateway(String gatewayId) throws RegistryException{
- EntityManager em = null;
- try {
- if (isGatewayExist(gatewayId)) {
- em = getEntityManager();
- Gateway gateway = em.find(Gateway.class, gatewayId);
- GatewayResource gatewayResource = (GatewayResource)Utils.getResource(ResourceType.GATEWAY, gateway);
- em.close();
- return gatewayResource;
- }
- }catch (Exception e){
- logger.error(e.getMessage(), e);
- throw new RegistryException(e);
- }finally {
- if (em != null && em.isOpen()){
- if (em.getTransaction().isActive()){
- em.getTransaction().rollback();
- }
- em.close();
- }
- }
- return null;
- }
-
- public static void addUser (String userName, String password) throws RegistryException{
- UserResource resource = new UserResource();
- resource.setUserName(userName);
- resource.setPassword(password);
- resource.save();
- }
-
- public static boolean isUserExist (String username) throws RegistryException{
- EntityManager em = null;
- try {
- em = getEntityManager();
- em.getTransaction().begin();
- QueryGenerator generator = new QueryGenerator(AbstractResource.USERS);
- generator.setParameter(AbstractResource.UserConstants.USERNAME, username);
- Query q = generator.selectQuery(em);
- int size = q.getResultList().size();
- em.getTransaction().commit();
- em.close();
- return size>0;
- } catch (Exception e){
- logger.error(e.getMessage(), e);
- throw new RegistryException(e);
- }finally {
- if (em != null && em.isOpen()){
- if (em.getTransaction().isActive()){
- em.getTransaction().rollback();
- }
- em.close();
- }
- }
- }
-
-
- public static Resource getUser(String userName) throws RegistryException{
- EntityManager em = null;
- try {
- if (isUserExist(userName)) {
- em = getEntityManager();
- Users user = em.find(Users.class, userName);
- UserResource userResource = (UserResource)Utils.getResource(ResourceType.USER, user);
- em.close();
- return userResource;
- }
- }catch (Exception e){
- logger.error(e.getMessage(), e);
- throw new RegistryException(e);
- }finally {
- if (em != null && em.isOpen()){
- if (em.getTransaction().isActive()){
- em.getTransaction().rollback();
- }
- em.close();
- }
- }
- return null;
-
- }
-
- public static Resource getWorker(String gatewayId, String userName) throws RegistryException{
- EntityManager em = null;
- try {
- em = getEntityManager();
- Gateway_Worker gatewayWorker = em.find(Gateway_Worker.class, new Gateway_Worker_PK(gatewayId, userName));
- WorkerResource workerResource = (WorkerResource) Utils.getResource(ResourceType.GATEWAY_WORKER, gatewayWorker);
- em.close();
- return workerResource;
- }catch (Exception e){
- logger.error(e.getMessage(), e);
- throw new RegistryException(e);
- }finally {
- if (em != null && em.isOpen()){
- if (em.getTransaction().isActive()){
- em.getTransaction().rollback();
- }
- em.close();
- }
- }
-
-
- }
-
-
- /**
- * @param gatewayId
- * @return
- */
- public static boolean isGatewayExist(String gatewayId) throws RegistryException{
- EntityManager em = null;
- try {
- em = getEntityManager();
- em.getTransaction().begin();
- QueryGenerator generator = new QueryGenerator(AbstractResource.GATEWAY);
- generator.setParameter(AbstractResource.GatewayConstants.GATEWAY_ID, gatewayId);
- Query q = generator.selectQuery(em);
- int size = q.getResultList().size();
- em.getTransaction().commit();
- em.close();
- return size>0;
- }catch (Exception e){
- logger.error(e.getMessage(), e);
- throw new RegistryException(e);
- }finally {
- if (em != null && em.isOpen()){
- if (em.getTransaction().isActive()){
- em.getTransaction().rollback();
- }
- em.close();
- }
- }
-
- }
-
- public static List<Resource> getAllGateways() throws RegistryException{
- List<Resource> resourceList = new ArrayList<Resource>();
- EntityManager em = null;
- try {
- em = getEntityManager();
- em.getTransaction().begin();
- QueryGenerator generator = new QueryGenerator(AbstractResource.GATEWAY);
- Query q = generator.selectQuery(em);
- List results = q.getResultList();
- if (results.size() != 0) {
- for (Object result : results) {
- Gateway gateway = (Gateway) result;
- GatewayResource gatewayResource =
- (GatewayResource) Utils.getResource(ResourceType.GATEWAY, gateway);
- resourceList.add(gatewayResource);
- }
- }
- em.getTransaction().commit();
- em.close();
- }catch (Exception e){
- logger.error(e.getMessage(), e);
- throw new RegistryException(e);
- }finally {
- if (em != null && em.isOpen()){
- if (em.getTransaction().isActive()){
- em.getTransaction().rollback();
- }
- em.close();
- }
- }
- return resourceList;
- }
-
- /**
- * @param gatewayId
- * @return
- */
- public static boolean removeGateway(String gatewayId) {
- EntityManager em = null;
- try {
- em = getEntityManager();
- em.getTransaction().begin();
- QueryGenerator generator = new QueryGenerator(AbstractResource.GATEWAY);
- generator.setParameter(AbstractResource.GatewayConstants.GATEWAY_ID, gatewayId);
- Query q = generator.deleteQuery(em);
- q.executeUpdate();
- em.getTransaction().commit();
- em.close();
- return true;
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- return false;
- }finally {
- if (em != null && em.isOpen()){
- if (em.getTransaction().isActive()){
- em.getTransaction().rollback();
- }
- em.close();
- }
- }
- }
-
- /**
- * @param gatewayResource
- * @param userResource
- */
- public static WorkerResource addGatewayWorker(GatewayResource gatewayResource, UserResource userResource) throws RegistryException{
- EntityManager em = null;
- try {
- em = getEntityManager();
- em.getTransaction().begin();
- if (!isGatewayExist(gatewayResource.getGatewayName())){
- gatewayResource.save();
- }
- if (!isUserExist(userResource.getUserName())){
- userResource.save();
- }
- Gateway gateway = em.find(Gateway.class, gatewayResource.getGatewayId());
- Users user = em.find(Users.class, userResource.getUserName());
- Gateway_Worker gatewayWorker = new Gateway_Worker();
- gatewayWorker.setGateway(gateway);
- gatewayWorker.setUser(user);
- em.persist(gatewayWorker);
- em.getTransaction().commit();
- em.close();
- return (WorkerResource)Utils.getResource(ResourceType.GATEWAY_WORKER, gatewayWorker);
- } catch (Exception e){
- logger.error(e.getMessage(), e);
- throw new RegistryException(e);
- }finally {
- if (em != null && em.isOpen()){
- if (em.getTransaction().isActive()){
- em.getTransaction().rollback();
- }
- em.close();
- }
- }
- }
-
- /**
- * @param gatewayResource
- * @param userResource
- * @return
- */
- public static boolean removeGatewayWorker(GatewayResource gatewayResource, UserResource userResource) {
- EntityManager em = null;
- try {
- em = getEntityManager();
- em.getTransaction().begin();
- QueryGenerator generator = new QueryGenerator(AbstractResource.GATEWAY_WORKER);
- generator.setParameter(AbstractResource.GatewayWorkerConstants.GATEWAY_ID,
- gatewayResource.getGatewayName());
- generator.setParameter(AbstractResource.UserConstants.USERNAME, userResource.getUserName());
- Query q = generator.deleteQuery(em);
- q.executeUpdate();
- em.getTransaction().commit();
- em.close();
- return true;
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- return false;
- }finally {
- if (em != null && em.isOpen()){
- if (em.getTransaction().isActive()){
- em.getTransaction().rollback();
- }
- em.close();
- }
- }
-
- }
-
- /**
- * @param configKey
- * @return
- */
- public static List<ConfigurationResource> getConfigurations(String configKey){
- List<ConfigurationResource> list = new ArrayList<ConfigurationResource>();
- EntityManager em = null;
- try {
- em = getEntityManager();
- em.getTransaction().begin();
- QueryGenerator generator = new QueryGenerator(AbstractResource.CONFIGURATION);
- generator.setParameter(AbstractResource.ConfigurationConstants.CONFIG_KEY, configKey);
- Query q = generator.selectQuery(em);
- List<?> resultList = q.getResultList();
- if (resultList.size() != 0) {
- for (Object result : resultList) {
- ConfigurationResource configurationResource = createConfigurationResourceObject(result);
- list.add(configurationResource);
- }
- }
- em.getTransaction().commit();
- em.close();
- }catch (Exception e) {
- logger.error(e.getMessage(), e);
- }finally {
- if (em != null && em.isOpen()){
- if (em.getTransaction().isActive()){
- em.getTransaction().rollback();
- }
- em.close();
- }
- }
- return list;
- }
-
- /**
- * @param configKey
- * @return
- */
- public static ConfigurationResource getConfiguration(String configKey){
- List<ConfigurationResource> configurations = getConfigurations(configKey);
- return (configurations != null && configurations.size() > 0) ? configurations.get(0) : null;
- }
-
- /**
- * @param configKey
- * @return
- */
- public static boolean isConfigurationExist(String configKey){
- List<ConfigurationResource> configurations = getConfigurations(configKey);
- return (configurations != null && configurations.size() > 0);
- }
-
- /**
- * @param configKey
- * @return
- */
- public static ConfigurationResource createConfiguration(String configKey) {
- ConfigurationResource config = new ConfigurationResource();
- config.setConfigKey(configKey);
- return config;
- }
-
- /**
- * @param result
- * @return
- */
- private static ConfigurationResource createConfigurationResourceObject(
- Object result) {
- Configuration configuration = (Configuration) result;
- ConfigurationResource configurationResource = new ConfigurationResource(configuration.getConfig_key(), configuration.getConfig_val());
- configurationResource.setExpireDate(configuration.getExpire_date());
- return configurationResource;
- }
-
- /**
- * @param configkey
- * @param configValue
- */
- public static void removeConfiguration(String configkey, String configValue) throws RegistryException{
- QueryGenerator queryGenerator = new QueryGenerator(AbstractResource.CONFIGURATION);
- queryGenerator.setParameter(AbstractResource.ConfigurationConstants.CONFIG_KEY, configkey);
- queryGenerator.setParameter(AbstractResource.ConfigurationConstants.CONFIG_VAL, configValue);
- EntityManager em = null;
- try {
- if(isConfigurationExists(configkey, configValue)){
- em = getEntityManager();
- em.getTransaction().begin();
- Query q = queryGenerator.deleteQuery(em);
- q.executeUpdate();
- em.getTransaction().commit();
- em.close();
- }
- }catch (Exception e){
- logger.error(e.getMessage(), e);
- throw new RegistryException(e);
- }finally {
- if (em != null && em.isOpen()){
- if (em.getTransaction().isActive()){
- em.getTransaction().rollback();
- }
- em.close();
- }
- }
- }
-
- /**
- * @param configkey
- */
- public static void removeConfiguration(String configkey) throws RegistryException{
- QueryGenerator queryGenerator = new QueryGenerator(AbstractResource.CONFIGURATION);
- queryGenerator.setParameter(AbstractResource.ConfigurationConstants.CONFIG_KEY, configkey);
- EntityManager em = null;
- try {
- if(isConfigurationExist(configkey)){
- em = getEntityManager();
- em.getTransaction().begin();
- Query q = queryGenerator.deleteQuery(em);
- q.executeUpdate();
- em.getTransaction().commit();
- em.close();
- }
- }catch (Exception e){
- logger.error(e.getMessage(), e);
- throw new RegistryException(e);
- }finally {
- if (em != null && em.isOpen()){
- if (em.getTransaction().isActive()){
- em.getTransaction().rollback();
- }
- em.close();
- }
- }
- }
-
- public static boolean isConfigurationExists(String configKey, String configVal) throws RegistryException{
- EntityManager em = null;
- try{
- //Currently categoryID is hardcoded value
- em = ResourceUtils.getEntityManager();
- Configuration existing = em.find(Configuration.class, new Configuration_PK(configKey, configVal, AbstractResource.ConfigurationConstants.CATEGORY_ID_DEFAULT_VALUE));
- em.close();
- return existing!= null;
- } catch (Exception e){
- logger.error(e.getMessage(), e);
- throw new RegistryException(e);
- }finally {
- if (em != null && em.isOpen()){
- if (em.getTransaction().isActive()){
- em.getTransaction().rollback();
- }
- em.close();
- }
- }
- }
-}