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 18:26:07 UTC
[17/30] airavata git commit: registry refactoring changes
http://git-wip-us.apache.org/repos/asf/airavata/blob/4045c094/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PostJobCommandAppCatalogResourceAppCat.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PostJobCommandAppCatalogResourceAppCat.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PostJobCommandAppCatalogResourceAppCat.java
deleted file mode 100644
index 201b45b..0000000
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PostJobCommandAppCatalogResourceAppCat.java
+++ /dev/null
@@ -1,333 +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.registry.core.app.catalog.resources;
-
-import org.apache.airavata.common.exception.ApplicationSettingsException;
-import org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment;
-import org.apache.airavata.registry.core.app.catalog.model.PostJobCommand;
-import org.apache.airavata.registry.core.app.catalog.model.PostJobCommandPK;
-import org.apache.airavata.registry.core.app.catalog.util.AppCatalogJPAUtils;
-import org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator;
-import org.apache.airavata.registry.core.app.catalog.util.AppCatalogResourceType;
-import org.apache.airavata.registry.cpi.AppCatalogException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.persistence.EntityManager;
-import javax.persistence.Query;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class PostJobCommandAppCatalogResourceAppCat extends AppCatAbstractResource {
- private final static Logger logger = LoggerFactory.getLogger(PostJobCommandAppCatalogResourceAppCat.class);
-
- private String appDeploymentId;
- private String command;
-
- private AppDeploymentAppCatalogResourceAppCat appDeploymentResource;
-
-
- public void remove(Object identifier) throws AppCatalogException {
- HashMap<String, String> ids;
- if (identifier instanceof Map){
- ids = (HashMap)identifier;
- }else {
- logger.error("Identifier should be a map with the field name and it's value");
- throw new AppCatalogException("Identifier should be a map with the field name and it's value");
- }
-
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- AppCatalogQueryGenerator generator= new AppCatalogQueryGenerator(POST_JOBCOMMAND);
- generator.setParameter(PostJobCommandConstants.DEPLOYMENT_ID,
- ids.get(PostJobCommandConstants.DEPLOYMENT_ID));
- if (ids.get(PostJobCommandConstants.COMMAND) != null){
- generator.setParameter(PostJobCommandConstants.COMMAND, ids.get(PostJobCommandConstants.COMMAND));
- }
- 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();
- }
- }
- }
-
- public AppCatalogResource get(Object identifier) throws AppCatalogException {
- HashMap<String, String> ids;
- if (identifier instanceof Map){
- ids = (HashMap)identifier;
- }else {
- logger.error("Identifier should be a map with the field name and it's value");
- throw new AppCatalogException("Identifier should be a map with the field name and it's value");
- }
-
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(POST_JOBCOMMAND);
- generator.setParameter(PostJobCommandConstants.DEPLOYMENT_ID,
- ids.get(PostJobCommandConstants.DEPLOYMENT_ID));
- generator.setParameter(PostJobCommandConstants.COMMAND, ids.get(PostJobCommandConstants.COMMAND));
- Query q = generator.selectQuery(em);
- PostJobCommand postJobCommand = (PostJobCommand) q.getSingleResult();
- PostJobCommandAppCatalogResourceAppCat postJobCommandResource =
- (PostJobCommandAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(
- AppCatalogResourceType.POST_JOBCOMMAND, postJobCommand);
- em.getTransaction().commit();
- em.close();
- return postJobCommandResource;
- } 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 List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
- List<AppCatalogResource> gsiSSHPostJobCommandResources = new ArrayList<AppCatalogResource>();
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- Query q;
- AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(POST_JOBCOMMAND);
- List results;
- if (fieldName.equals(PostJobCommandConstants.DEPLOYMENT_ID)) {
- generator.setParameter(PostJobCommandConstants.DEPLOYMENT_ID, value);
- q = generator.selectQuery(em);
- results = q.getResultList();
- if (results.size() != 0) {
- for (Object result : results) {
- PostJobCommand postJobCommand = (PostJobCommand) result;
- PostJobCommandAppCatalogResourceAppCat postJobCommandResource =
- (PostJobCommandAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(
- AppCatalogResourceType.POST_JOBCOMMAND, postJobCommand);
- gsiSSHPostJobCommandResources.add(postJobCommandResource);
- }
- }
- } else if (fieldName.equals(PostJobCommandConstants.COMMAND)) {
- generator.setParameter(PostJobCommandConstants.COMMAND, value);
- q = generator.selectQuery(em);
- results = q.getResultList();
- if (results.size() != 0) {
- for (Object result : results) {
- PostJobCommand postJobCommand = (PostJobCommand) result;
- PostJobCommandAppCatalogResourceAppCat postJobCommandResource =
- (PostJobCommandAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(
- AppCatalogResourceType.POST_JOBCOMMAND, postJobCommand);
- gsiSSHPostJobCommandResources.add(postJobCommandResource);
- }
- }
- } else {
- em.getTransaction().commit();
- em.close();
- logger.error("Unsupported field name for GSISSH Post Job Command Resource.", new IllegalArgumentException());
- throw new IllegalArgumentException("Unsupported field name for GSISSH Post Job Command Resource.");
- }
- 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 gsiSSHPostJobCommandResources;
- }
-
- @Override
- public List<AppCatalogResource> getAll() throws AppCatalogException {
- return null;
- }
-
- @Override
- public List<String> getAllIds() throws AppCatalogException {
- return null;
- }
-
- public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
- List<String> gsiSSHPostJobResourceIDs = new ArrayList<String>();
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- Query q;
- AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(POST_JOBCOMMAND);
- List results;
- if (fieldName.equals(PostJobCommandConstants.DEPLOYMENT_ID)) {
- generator.setParameter(PostJobCommandConstants.DEPLOYMENT_ID, value);
- q = generator.selectQuery(em);
- results = q.getResultList();
- if (results.size() != 0) {
- for (Object result : results) {
- PostJobCommand postJobCommand = (PostJobCommand) result;
- gsiSSHPostJobResourceIDs.add(postJobCommand.getDeploymentId());
- }
- }
- } else if (fieldName.equals(PostJobCommandConstants.COMMAND)) {
- generator.setParameter(PostJobCommandConstants.COMMAND, value);
- q = generator.selectQuery(em);
- results = q.getResultList();
- if (results.size() != 0) {
- for (Object result : results) {
- PostJobCommand postJobCommand = (PostJobCommand) result;
- gsiSSHPostJobResourceIDs.add(postJobCommand.getDeploymentId());
- }
- }
- } else {
- em.getTransaction().commit();
- em.close();
- logger.error("Unsupported field name for GSISSH Post Job resource.", new IllegalArgumentException());
- throw new IllegalArgumentException("Unsupported field name for GSISSH Post JOb Resource.");
- }
- 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 gsiSSHPostJobResourceIDs;
- }
-
- public void save() throws AppCatalogException {
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- PostJobCommand existingPostJobCommand = em.find(PostJobCommand.class,
- new PostJobCommandPK(appDeploymentId, command));
- em.close();
-
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- ApplicationDeployment deployment = em.find(ApplicationDeployment.class, appDeploymentId);
- if (existingPostJobCommand != null){
- existingPostJobCommand.setDeploymentId(appDeploymentId);
- existingPostJobCommand.setCommand(command);
- existingPostJobCommand.setDeployment(deployment);
- em.merge(existingPostJobCommand);
- }else {
- PostJobCommand postJobCommand = new PostJobCommand();
- postJobCommand.setDeploymentId(appDeploymentId);
- postJobCommand.setCommand(command);
- postJobCommand.setDeployment(deployment);
- em.persist(postJobCommand);
- }
- 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();
- }
- }
- }
-
- public boolean isExists(Object identifier) throws AppCatalogException {
- HashMap<String, String> ids;
- if (identifier instanceof Map){
- ids = (HashMap)identifier;
- }else {
- logger.error("Identifier should be a map with the field name and it's value");
- throw new AppCatalogException("Identifier should be a map with the field name and it's value");
- }
-
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- PostJobCommand postJobCommand = em.find(PostJobCommand.class, new PostJobCommandPK(
- ids.get(PostJobCommandConstants.DEPLOYMENT_ID),
- ids.get(PostJobCommandConstants.COMMAND)));
-
- em.close();
- return postJobCommand != 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 getAppDeploymentId() {
- return appDeploymentId;
- }
-
- public void setAppDeploymentId(String appDeploymentId) {
- this.appDeploymentId = appDeploymentId;
- }
-
- public String getCommand() {
- return command;
- }
-
- public void setCommand(String command) {
- this.command = command;
- }
-
- public AppDeploymentAppCatalogResourceAppCat getAppDeploymentResource() {
- return appDeploymentResource;
- }
-
- public void setAppDeploymentResource(AppDeploymentAppCatalogResourceAppCat appDeploymentResource) {
- this.appDeploymentResource = appDeploymentResource;
- }
-}
http://git-wip-us.apache.org/repos/asf/airavata/blob/4045c094/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PostJobCommandResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PostJobCommandResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PostJobCommandResource.java
new file mode 100644
index 0000000..e9d770b
--- /dev/null
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PostJobCommandResource.java
@@ -0,0 +1,333 @@
+/**
+ * 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.registry.core.app.catalog.resources;
+
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment;
+import org.apache.airavata.registry.core.app.catalog.model.PostJobCommand;
+import org.apache.airavata.registry.core.app.catalog.model.PostJobCommandPK;
+import org.apache.airavata.registry.core.app.catalog.util.AppCatalogJPAUtils;
+import org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator;
+import org.apache.airavata.registry.core.app.catalog.util.AppCatalogResourceType;
+import org.apache.airavata.registry.cpi.AppCatalogException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class PostJobCommandResource extends AppCatAbstractResource {
+ private final static Logger logger = LoggerFactory.getLogger(PostJobCommandResource.class);
+
+ private String appDeploymentId;
+ private String command;
+
+ private AppDeploymentResource appDeploymentResource;
+
+
+ public void remove(Object identifier) throws AppCatalogException {
+ HashMap<String, String> ids;
+ if (identifier instanceof Map){
+ ids = (HashMap)identifier;
+ }else {
+ logger.error("Identifier should be a map with the field name and it's value");
+ throw new AppCatalogException("Identifier should be a map with the field name and it's value");
+ }
+
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ AppCatalogQueryGenerator generator= new AppCatalogQueryGenerator(POST_JOBCOMMAND);
+ generator.setParameter(PostJobCommandConstants.DEPLOYMENT_ID,
+ ids.get(PostJobCommandConstants.DEPLOYMENT_ID));
+ if (ids.get(PostJobCommandConstants.COMMAND) != null){
+ generator.setParameter(PostJobCommandConstants.COMMAND, ids.get(PostJobCommandConstants.COMMAND));
+ }
+ 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();
+ }
+ }
+ }
+
+ public AppCatalogResource get(Object identifier) throws AppCatalogException {
+ HashMap<String, String> ids;
+ if (identifier instanceof Map){
+ ids = (HashMap)identifier;
+ }else {
+ logger.error("Identifier should be a map with the field name and it's value");
+ throw new AppCatalogException("Identifier should be a map with the field name and it's value");
+ }
+
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(POST_JOBCOMMAND);
+ generator.setParameter(PostJobCommandConstants.DEPLOYMENT_ID,
+ ids.get(PostJobCommandConstants.DEPLOYMENT_ID));
+ generator.setParameter(PostJobCommandConstants.COMMAND, ids.get(PostJobCommandConstants.COMMAND));
+ Query q = generator.selectQuery(em);
+ PostJobCommand postJobCommand = (PostJobCommand) q.getSingleResult();
+ PostJobCommandResource postJobCommandResource =
+ (PostJobCommandResource) AppCatalogJPAUtils.getResource(
+ AppCatalogResourceType.POST_JOBCOMMAND, postJobCommand);
+ em.getTransaction().commit();
+ em.close();
+ return postJobCommandResource;
+ } 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 List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
+ List<AppCatalogResource> gsiSSHPostJobCommandResources = new ArrayList<AppCatalogResource>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ Query q;
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(POST_JOBCOMMAND);
+ List results;
+ if (fieldName.equals(PostJobCommandConstants.DEPLOYMENT_ID)) {
+ generator.setParameter(PostJobCommandConstants.DEPLOYMENT_ID, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ PostJobCommand postJobCommand = (PostJobCommand) result;
+ PostJobCommandResource postJobCommandResource =
+ (PostJobCommandResource) AppCatalogJPAUtils.getResource(
+ AppCatalogResourceType.POST_JOBCOMMAND, postJobCommand);
+ gsiSSHPostJobCommandResources.add(postJobCommandResource);
+ }
+ }
+ } else if (fieldName.equals(PostJobCommandConstants.COMMAND)) {
+ generator.setParameter(PostJobCommandConstants.COMMAND, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ PostJobCommand postJobCommand = (PostJobCommand) result;
+ PostJobCommandResource postJobCommandResource =
+ (PostJobCommandResource) AppCatalogJPAUtils.getResource(
+ AppCatalogResourceType.POST_JOBCOMMAND, postJobCommand);
+ gsiSSHPostJobCommandResources.add(postJobCommandResource);
+ }
+ }
+ } else {
+ em.getTransaction().commit();
+ em.close();
+ logger.error("Unsupported field name for GSISSH Post Job Command Resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for GSISSH Post Job Command Resource.");
+ }
+ 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 gsiSSHPostJobCommandResources;
+ }
+
+ @Override
+ public List<AppCatalogResource> getAll() throws AppCatalogException {
+ return null;
+ }
+
+ @Override
+ public List<String> getAllIds() throws AppCatalogException {
+ return null;
+ }
+
+ public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
+ List<String> gsiSSHPostJobResourceIDs = new ArrayList<String>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ Query q;
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(POST_JOBCOMMAND);
+ List results;
+ if (fieldName.equals(PostJobCommandConstants.DEPLOYMENT_ID)) {
+ generator.setParameter(PostJobCommandConstants.DEPLOYMENT_ID, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ PostJobCommand postJobCommand = (PostJobCommand) result;
+ gsiSSHPostJobResourceIDs.add(postJobCommand.getDeploymentId());
+ }
+ }
+ } else if (fieldName.equals(PostJobCommandConstants.COMMAND)) {
+ generator.setParameter(PostJobCommandConstants.COMMAND, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ PostJobCommand postJobCommand = (PostJobCommand) result;
+ gsiSSHPostJobResourceIDs.add(postJobCommand.getDeploymentId());
+ }
+ }
+ } else {
+ em.getTransaction().commit();
+ em.close();
+ logger.error("Unsupported field name for GSISSH Post Job resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for GSISSH Post JOb Resource.");
+ }
+ 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 gsiSSHPostJobResourceIDs;
+ }
+
+ public void save() throws AppCatalogException {
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ PostJobCommand existingPostJobCommand = em.find(PostJobCommand.class,
+ new PostJobCommandPK(appDeploymentId, command));
+ em.close();
+
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ ApplicationDeployment deployment = em.find(ApplicationDeployment.class, appDeploymentId);
+ if (existingPostJobCommand != null){
+ existingPostJobCommand.setDeploymentId(appDeploymentId);
+ existingPostJobCommand.setCommand(command);
+ existingPostJobCommand.setDeployment(deployment);
+ em.merge(existingPostJobCommand);
+ }else {
+ PostJobCommand postJobCommand = new PostJobCommand();
+ postJobCommand.setDeploymentId(appDeploymentId);
+ postJobCommand.setCommand(command);
+ postJobCommand.setDeployment(deployment);
+ em.persist(postJobCommand);
+ }
+ 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();
+ }
+ }
+ }
+
+ public boolean isExists(Object identifier) throws AppCatalogException {
+ HashMap<String, String> ids;
+ if (identifier instanceof Map){
+ ids = (HashMap)identifier;
+ }else {
+ logger.error("Identifier should be a map with the field name and it's value");
+ throw new AppCatalogException("Identifier should be a map with the field name and it's value");
+ }
+
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ PostJobCommand postJobCommand = em.find(PostJobCommand.class, new PostJobCommandPK(
+ ids.get(PostJobCommandConstants.DEPLOYMENT_ID),
+ ids.get(PostJobCommandConstants.COMMAND)));
+
+ em.close();
+ return postJobCommand != 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 getAppDeploymentId() {
+ return appDeploymentId;
+ }
+
+ public void setAppDeploymentId(String appDeploymentId) {
+ this.appDeploymentId = appDeploymentId;
+ }
+
+ public String getCommand() {
+ return command;
+ }
+
+ public void setCommand(String command) {
+ this.command = command;
+ }
+
+ public AppDeploymentResource getAppDeploymentResource() {
+ return appDeploymentResource;
+ }
+
+ public void setAppDeploymentResource(AppDeploymentResource appDeploymentResource) {
+ this.appDeploymentResource = appDeploymentResource;
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/4045c094/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PreJobCommandAppCatalogResourceAppCat.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PreJobCommandAppCatalogResourceAppCat.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PreJobCommandAppCatalogResourceAppCat.java
deleted file mode 100644
index 6fe515e..0000000
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PreJobCommandAppCatalogResourceAppCat.java
+++ /dev/null
@@ -1,333 +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.registry.core.app.catalog.resources;
-
-import org.apache.airavata.common.exception.ApplicationSettingsException;
-import org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment;
-import org.apache.airavata.registry.core.app.catalog.model.PreJobCommand;
-import org.apache.airavata.registry.core.app.catalog.model.PreJobCommandPK;
-import org.apache.airavata.registry.core.app.catalog.util.AppCatalogJPAUtils;
-import org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator;
-import org.apache.airavata.registry.core.app.catalog.util.AppCatalogResourceType;
-import org.apache.airavata.registry.cpi.AppCatalogException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.persistence.EntityManager;
-import javax.persistence.Query;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class PreJobCommandAppCatalogResourceAppCat extends AppCatAbstractResource {
- private final static Logger logger = LoggerFactory.getLogger(PreJobCommandAppCatalogResourceAppCat.class);
-
- private String appDeploymentId;
- private String command;
-
- private AppDeploymentAppCatalogResourceAppCat appDeploymentResource;
-
-
- public void remove(Object identifier) throws AppCatalogException {
- HashMap<String, String> ids;
- if (identifier instanceof Map){
- ids = (HashMap)identifier;
- }else {
- logger.error("Identifier should be a map with the field name and it's value");
- throw new AppCatalogException("Identifier should be a map with the field name and it's value");
- }
-
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- AppCatalogQueryGenerator generator= new AppCatalogQueryGenerator(PRE_JOBCOMMAND);
- generator.setParameter(PreJobCommandConstants.DEPLOYMENT_ID,
- ids.get(PreJobCommandConstants.DEPLOYMENT_ID));
- if (ids.get(PreJobCommandConstants.COMMAND) != null){
- generator.setParameter(PreJobCommandConstants.COMMAND, ids.get(PreJobCommandConstants.COMMAND));
- }
- 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();
- }
- }
- }
-
- public AppCatalogResource get(Object identifier) throws AppCatalogException {
- HashMap<String, String> ids;
- if (identifier instanceof Map){
- ids = (HashMap)identifier;
- }else {
- logger.error("Identifier should be a map with the field name and it's value");
- throw new AppCatalogException("Identifier should be a map with the field name and it's value");
- }
-
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(PRE_JOBCOMMAND);
- generator.setParameter(PreJobCommandConstants.DEPLOYMENT_ID,
- ids.get(PreJobCommandConstants.DEPLOYMENT_ID));
- generator.setParameter(PreJobCommandConstants.COMMAND, ids.get(PreJobCommandConstants.COMMAND));
- Query q = generator.selectQuery(em);
- PreJobCommand preJobCommand = (PreJobCommand) q.getSingleResult();
- PreJobCommandAppCatalogResourceAppCat preJobCommandResource =
- (PreJobCommandAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(
- AppCatalogResourceType.PRE_JOBCOMMAND, preJobCommand);
- em.getTransaction().commit();
- em.close();
- return preJobCommandResource;
- } 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 List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
- List<AppCatalogResource> gsiSSHPreJobResources = new ArrayList<AppCatalogResource>();
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- Query q;
- AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(PRE_JOBCOMMAND);
- List results;
- if (fieldName.equals(PreJobCommandConstants.DEPLOYMENT_ID)) {
- generator.setParameter(PreJobCommandConstants.DEPLOYMENT_ID, value);
- q = generator.selectQuery(em);
- results = q.getResultList();
- if (results.size() != 0) {
- for (Object result : results) {
- PreJobCommand preJobCommand = (PreJobCommand) result;
- PreJobCommandAppCatalogResourceAppCat preJobCommandResource =
- (PreJobCommandAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(
- AppCatalogResourceType.PRE_JOBCOMMAND, preJobCommand);
- gsiSSHPreJobResources.add(preJobCommandResource);
- }
- }
- } else if (fieldName.equals(PreJobCommandConstants.COMMAND)) {
- generator.setParameter(PreJobCommandConstants.COMMAND, value);
- q = generator.selectQuery(em);
- results = q.getResultList();
- if (results.size() != 0) {
- for (Object result : results) {
- PreJobCommand preJobCommand = (PreJobCommand) result;
- PreJobCommandAppCatalogResourceAppCat preJobCommandResource =
- (PreJobCommandAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(
- AppCatalogResourceType.PRE_JOBCOMMAND, preJobCommand);
- gsiSSHPreJobResources.add(preJobCommandResource);
- }
- }
- } else {
- em.getTransaction().commit();
- em.close();
- logger.error("Unsupported field name for GSISSH Pre Job Command Resource.", new IllegalArgumentException());
- throw new IllegalArgumentException("Unsupported field name for GSISSH Pre Job Command Resource.");
- }
- 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 gsiSSHPreJobResources;
- }
-
- @Override
- public List<AppCatalogResource> getAll() throws AppCatalogException {
- return null;
- }
-
- @Override
- public List<String> getAllIds() throws AppCatalogException {
- return null;
- }
-
- public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
- List<String> gsiSSHPreJobResourceIDs = new ArrayList<String>();
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- Query q;
- AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(PRE_JOBCOMMAND);
- List results;
- if (fieldName.equals(PreJobCommandConstants.DEPLOYMENT_ID)) {
- generator.setParameter(PreJobCommandConstants.DEPLOYMENT_ID, value);
- q = generator.selectQuery(em);
- results = q.getResultList();
- if (results.size() != 0) {
- for (Object result : results) {
- PreJobCommand preJobCommand = (PreJobCommand) result;
- gsiSSHPreJobResourceIDs.add(preJobCommand.getDeploymentId());
- }
- }
- } else if (fieldName.equals(PreJobCommandConstants.COMMAND)) {
- generator.setParameter(PreJobCommandConstants.COMMAND, value);
- q = generator.selectQuery(em);
- results = q.getResultList();
- if (results.size() != 0) {
- for (Object result : results) {
- PreJobCommand preJobCommand = (PreJobCommand) result;
- gsiSSHPreJobResourceIDs.add(preJobCommand.getDeploymentId());
- }
- }
- } else {
- em.getTransaction().commit();
- em.close();
- logger.error("Unsupported field name for GSISSH Pre Job resource.", new IllegalArgumentException());
- throw new IllegalArgumentException("Unsupported field name for GSISSH Pre JOb Resource.");
- }
- 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 gsiSSHPreJobResourceIDs;
- }
-
- public void save() throws AppCatalogException {
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- PreJobCommand existingGSIsshPreJobCommand = em.find(PreJobCommand.class,
- new PreJobCommandPK(appDeploymentId, command));
- em.close();
-
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- ApplicationDeployment deployment = em.find(ApplicationDeployment.class, appDeploymentId);
- if (existingGSIsshPreJobCommand != null){
- existingGSIsshPreJobCommand.setDeploymentId(appDeploymentId);
- existingGSIsshPreJobCommand.setCommand(command);
- existingGSIsshPreJobCommand.setApplicationDeployment(deployment);
- em.merge(existingGSIsshPreJobCommand);
- }else {
- PreJobCommand preJobCommand = new PreJobCommand();
- preJobCommand.setDeploymentId(appDeploymentId);
- preJobCommand.setCommand(command);
- preJobCommand.setApplicationDeployment(deployment);
- em.persist(preJobCommand);
- }
- 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();
- }
- }
- }
-
- public boolean isExists(Object identifier) throws AppCatalogException {
- HashMap<String, String> ids;
- if (identifier instanceof Map){
- ids = (HashMap)identifier;
- }else {
- logger.error("Identifier should be a map with the field name and it's value");
- throw new AppCatalogException("Identifier should be a map with the field name and it's value");
- }
-
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- PreJobCommand preJobCommand = em.find(PreJobCommand.class, new PreJobCommandPK(
- ids.get(PreJobCommandConstants.DEPLOYMENT_ID),
- ids.get(PreJobCommandConstants.COMMAND)));
-
- em.close();
- return preJobCommand != 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 getAppDeploymentId() {
- return appDeploymentId;
- }
-
- public void setAppDeploymentId(String appDeploymentId) {
- this.appDeploymentId = appDeploymentId;
- }
-
- public String getCommand() {
- return command;
- }
-
- public void setCommand(String command) {
- this.command = command;
- }
-
- public AppDeploymentAppCatalogResourceAppCat getAppDeploymentResource() {
- return appDeploymentResource;
- }
-
- public void setAppDeploymentResource(AppDeploymentAppCatalogResourceAppCat appDeploymentResource) {
- this.appDeploymentResource = appDeploymentResource;
- }
-}
http://git-wip-us.apache.org/repos/asf/airavata/blob/4045c094/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PreJobCommandResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PreJobCommandResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PreJobCommandResource.java
new file mode 100644
index 0000000..fcd494b
--- /dev/null
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/PreJobCommandResource.java
@@ -0,0 +1,333 @@
+/**
+ * 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.registry.core.app.catalog.resources;
+
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment;
+import org.apache.airavata.registry.core.app.catalog.model.PreJobCommand;
+import org.apache.airavata.registry.core.app.catalog.model.PreJobCommandPK;
+import org.apache.airavata.registry.core.app.catalog.util.AppCatalogJPAUtils;
+import org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator;
+import org.apache.airavata.registry.core.app.catalog.util.AppCatalogResourceType;
+import org.apache.airavata.registry.cpi.AppCatalogException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class PreJobCommandResource extends AppCatAbstractResource {
+ private final static Logger logger = LoggerFactory.getLogger(PreJobCommandResource.class);
+
+ private String appDeploymentId;
+ private String command;
+
+ private AppDeploymentResource appDeploymentResource;
+
+
+ public void remove(Object identifier) throws AppCatalogException {
+ HashMap<String, String> ids;
+ if (identifier instanceof Map){
+ ids = (HashMap)identifier;
+ }else {
+ logger.error("Identifier should be a map with the field name and it's value");
+ throw new AppCatalogException("Identifier should be a map with the field name and it's value");
+ }
+
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ AppCatalogQueryGenerator generator= new AppCatalogQueryGenerator(PRE_JOBCOMMAND);
+ generator.setParameter(PreJobCommandConstants.DEPLOYMENT_ID,
+ ids.get(PreJobCommandConstants.DEPLOYMENT_ID));
+ if (ids.get(PreJobCommandConstants.COMMAND) != null){
+ generator.setParameter(PreJobCommandConstants.COMMAND, ids.get(PreJobCommandConstants.COMMAND));
+ }
+ 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();
+ }
+ }
+ }
+
+ public AppCatalogResource get(Object identifier) throws AppCatalogException {
+ HashMap<String, String> ids;
+ if (identifier instanceof Map){
+ ids = (HashMap)identifier;
+ }else {
+ logger.error("Identifier should be a map with the field name and it's value");
+ throw new AppCatalogException("Identifier should be a map with the field name and it's value");
+ }
+
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(PRE_JOBCOMMAND);
+ generator.setParameter(PreJobCommandConstants.DEPLOYMENT_ID,
+ ids.get(PreJobCommandConstants.DEPLOYMENT_ID));
+ generator.setParameter(PreJobCommandConstants.COMMAND, ids.get(PreJobCommandConstants.COMMAND));
+ Query q = generator.selectQuery(em);
+ PreJobCommand preJobCommand = (PreJobCommand) q.getSingleResult();
+ PreJobCommandResource preJobCommandResource =
+ (PreJobCommandResource) AppCatalogJPAUtils.getResource(
+ AppCatalogResourceType.PRE_JOBCOMMAND, preJobCommand);
+ em.getTransaction().commit();
+ em.close();
+ return preJobCommandResource;
+ } 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 List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
+ List<AppCatalogResource> gsiSSHPreJobResources = new ArrayList<AppCatalogResource>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ Query q;
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(PRE_JOBCOMMAND);
+ List results;
+ if (fieldName.equals(PreJobCommandConstants.DEPLOYMENT_ID)) {
+ generator.setParameter(PreJobCommandConstants.DEPLOYMENT_ID, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ PreJobCommand preJobCommand = (PreJobCommand) result;
+ PreJobCommandResource preJobCommandResource =
+ (PreJobCommandResource) AppCatalogJPAUtils.getResource(
+ AppCatalogResourceType.PRE_JOBCOMMAND, preJobCommand);
+ gsiSSHPreJobResources.add(preJobCommandResource);
+ }
+ }
+ } else if (fieldName.equals(PreJobCommandConstants.COMMAND)) {
+ generator.setParameter(PreJobCommandConstants.COMMAND, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ PreJobCommand preJobCommand = (PreJobCommand) result;
+ PreJobCommandResource preJobCommandResource =
+ (PreJobCommandResource) AppCatalogJPAUtils.getResource(
+ AppCatalogResourceType.PRE_JOBCOMMAND, preJobCommand);
+ gsiSSHPreJobResources.add(preJobCommandResource);
+ }
+ }
+ } else {
+ em.getTransaction().commit();
+ em.close();
+ logger.error("Unsupported field name for GSISSH Pre Job Command Resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for GSISSH Pre Job Command Resource.");
+ }
+ 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 gsiSSHPreJobResources;
+ }
+
+ @Override
+ public List<AppCatalogResource> getAll() throws AppCatalogException {
+ return null;
+ }
+
+ @Override
+ public List<String> getAllIds() throws AppCatalogException {
+ return null;
+ }
+
+ public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
+ List<String> gsiSSHPreJobResourceIDs = new ArrayList<String>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ Query q;
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(PRE_JOBCOMMAND);
+ List results;
+ if (fieldName.equals(PreJobCommandConstants.DEPLOYMENT_ID)) {
+ generator.setParameter(PreJobCommandConstants.DEPLOYMENT_ID, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ PreJobCommand preJobCommand = (PreJobCommand) result;
+ gsiSSHPreJobResourceIDs.add(preJobCommand.getDeploymentId());
+ }
+ }
+ } else if (fieldName.equals(PreJobCommandConstants.COMMAND)) {
+ generator.setParameter(PreJobCommandConstants.COMMAND, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ PreJobCommand preJobCommand = (PreJobCommand) result;
+ gsiSSHPreJobResourceIDs.add(preJobCommand.getDeploymentId());
+ }
+ }
+ } else {
+ em.getTransaction().commit();
+ em.close();
+ logger.error("Unsupported field name for GSISSH Pre Job resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for GSISSH Pre JOb Resource.");
+ }
+ 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 gsiSSHPreJobResourceIDs;
+ }
+
+ public void save() throws AppCatalogException {
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ PreJobCommand existingGSIsshPreJobCommand = em.find(PreJobCommand.class,
+ new PreJobCommandPK(appDeploymentId, command));
+ em.close();
+
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ ApplicationDeployment deployment = em.find(ApplicationDeployment.class, appDeploymentId);
+ if (existingGSIsshPreJobCommand != null){
+ existingGSIsshPreJobCommand.setDeploymentId(appDeploymentId);
+ existingGSIsshPreJobCommand.setCommand(command);
+ existingGSIsshPreJobCommand.setApplicationDeployment(deployment);
+ em.merge(existingGSIsshPreJobCommand);
+ }else {
+ PreJobCommand preJobCommand = new PreJobCommand();
+ preJobCommand.setDeploymentId(appDeploymentId);
+ preJobCommand.setCommand(command);
+ preJobCommand.setApplicationDeployment(deployment);
+ em.persist(preJobCommand);
+ }
+ 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();
+ }
+ }
+ }
+
+ public boolean isExists(Object identifier) throws AppCatalogException {
+ HashMap<String, String> ids;
+ if (identifier instanceof Map){
+ ids = (HashMap)identifier;
+ }else {
+ logger.error("Identifier should be a map with the field name and it's value");
+ throw new AppCatalogException("Identifier should be a map with the field name and it's value");
+ }
+
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ PreJobCommand preJobCommand = em.find(PreJobCommand.class, new PreJobCommandPK(
+ ids.get(PreJobCommandConstants.DEPLOYMENT_ID),
+ ids.get(PreJobCommandConstants.COMMAND)));
+
+ em.close();
+ return preJobCommand != 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 getAppDeploymentId() {
+ return appDeploymentId;
+ }
+
+ public void setAppDeploymentId(String appDeploymentId) {
+ this.appDeploymentId = appDeploymentId;
+ }
+
+ public String getCommand() {
+ return command;
+ }
+
+ public void setCommand(String command) {
+ this.command = command;
+ }
+
+ public AppDeploymentResource getAppDeploymentResource() {
+ return appDeploymentResource;
+ }
+
+ public void setAppDeploymentResource(AppDeploymentResource appDeploymentResource) {
+ this.appDeploymentResource = appDeploymentResource;
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/4045c094/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ResourceJobManagerAppCatalogResourceAppCat.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ResourceJobManagerAppCatalogResourceAppCat.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ResourceJobManagerAppCatalogResourceAppCat.java
deleted file mode 100644
index 19e65a3..0000000
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ResourceJobManagerAppCatalogResourceAppCat.java
+++ /dev/null
@@ -1,301 +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.registry.core.app.catalog.resources;
-
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.persistence.EntityManager;
-import javax.persistence.Query;
-
-import org.apache.airavata.common.exception.ApplicationSettingsException;
-import org.apache.airavata.common.utils.AiravataUtils;
-import org.apache.airavata.registry.core.app.catalog.model.ResourceJobManager;
-import org.apache.airavata.registry.core.app.catalog.util.AppCatalogJPAUtils;
-import org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator;
-import org.apache.airavata.registry.core.app.catalog.util.AppCatalogResourceType;
-import org.apache.airavata.registry.cpi.AppCatalogException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class ResourceJobManagerAppCatalogResourceAppCat extends AppCatAbstractResource {
- private final static Logger logger = LoggerFactory.getLogger(ResourceJobManagerAppCatalogResourceAppCat.class);
- private String resourceJobManagerId;
- private String pushMonitoringEndpoint;
- private String jobManagerBinPath;
- private String resourceJobManagerType;
- private Timestamp createdTime;
- private Timestamp updatedTime;
-
- 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;
- }
-
- @Override
- public void remove(Object identifier) throws AppCatalogException {
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(RESOURCE_JOB_MANAGER);
- generator.setParameter(ResourceJobManagerConstants.RESOURCE_JOB_MANAGER_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 AppCatalogResource get(Object identifier) throws AppCatalogException {
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(RESOURCE_JOB_MANAGER);
- generator.setParameter(ResourceJobManagerConstants.RESOURCE_JOB_MANAGER_ID, identifier);
- Query q = generator.selectQuery(em);
- ResourceJobManager resourceJobManager = (ResourceJobManager) q.getSingleResult();
- ResourceJobManagerAppCatalogResourceAppCat resourceJobManagerResource = (ResourceJobManagerAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(AppCatalogResourceType.RESOURCE_JOB_MANAGER, resourceJobManager);
- em.getTransaction().commit();
- em.close();
- return resourceJobManagerResource;
- } 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<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
- List<AppCatalogResource> resourceJobManagerResources = new ArrayList<AppCatalogResource>();
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(RESOURCE_JOB_MANAGER);
- Query q;
- if ((fieldName.equals(ResourceJobManagerConstants.RESOURCE_JOB_MANAGER_ID)) || (fieldName.equals(ResourceJobManagerConstants.PUSH_MONITORING_ENDPOINT)) || (fieldName.equals(ResourceJobManagerConstants.JOB_MANAGER_BIN_PATH)) || (fieldName.equals(ResourceJobManagerConstants.RESOURCE_JOB_MANAGER_TYPE))) {
- generator.setParameter(fieldName, value);
- q = generator.selectQuery(em);
- List<?> results = q.getResultList();
- for (Object result : results) {
- ResourceJobManager resourceJobManager = (ResourceJobManager) result;
- ResourceJobManagerAppCatalogResourceAppCat resourceJobManagerResource = (ResourceJobManagerAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(AppCatalogResourceType.RESOURCE_JOB_MANAGER, resourceJobManager);
- resourceJobManagerResources.add(resourceJobManagerResource);
- }
- } else {
- em.getTransaction().commit();
- em.close();
- logger.error("Unsupported field name for Resource Job Manager Resource.", new IllegalArgumentException());
- throw new IllegalArgumentException("Unsupported field name for Resource Job Manager 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 resourceJobManagerResources;
- }
-
- @Override
- public List<AppCatalogResource> getAll() throws AppCatalogException {
- return null;
- }
-
- @Override
- public List<String> getAllIds() throws AppCatalogException {
- return null;
- }
-
- @Override
- public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
- List<String> resourceJobManagerResourceIDs = new ArrayList<String>();
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(RESOURCE_JOB_MANAGER);
- Query q;
- if ((fieldName.equals(ResourceJobManagerConstants.RESOURCE_JOB_MANAGER_ID)) || (fieldName.equals(ResourceJobManagerConstants.PUSH_MONITORING_ENDPOINT)) || (fieldName.equals(ResourceJobManagerConstants.JOB_MANAGER_BIN_PATH)) || (fieldName.equals(ResourceJobManagerConstants.RESOURCE_JOB_MANAGER_TYPE))) {
- generator.setParameter(fieldName, value);
- q = generator.selectQuery(em);
- List<?> results = q.getResultList();
- for (Object result : results) {
- ResourceJobManager resourceJobManager = (ResourceJobManager) result;
- ResourceJobManagerAppCatalogResourceAppCat resourceJobManagerResource = (ResourceJobManagerAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(AppCatalogResourceType.RESOURCE_JOB_MANAGER, resourceJobManager);
- resourceJobManagerResourceIDs.add(resourceJobManagerResource.getResourceJobManagerId());
- }
- } else {
- em.getTransaction().commit();
- em.close();
- logger.error("Unsupported field name for Resource Job Manager Resource.", new IllegalArgumentException());
- throw new IllegalArgumentException("Unsupported field name for Resource Job Manager 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 resourceJobManagerResourceIDs;
- }
-
- @Override
- public void save() throws AppCatalogException {
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- ResourceJobManager existingResourceJobManager = em.find(ResourceJobManager.class, resourceJobManagerId);
- em.close();
- ResourceJobManager resourceJobManager;
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- if (existingResourceJobManager == null) {
- resourceJobManager = new ResourceJobManager();
- resourceJobManager.setCreationTime(AiravataUtils.getCurrentTimestamp());
- } else {
- resourceJobManager = existingResourceJobManager;
- resourceJobManager.setUpdateTime(AiravataUtils.getCurrentTimestamp());
- }
- resourceJobManager.setResourceJobManagerId(getResourceJobManagerId());
- resourceJobManager.setPushMonitoringEndpoint(getPushMonitoringEndpoint());
- resourceJobManager.setJobManagerBinPath(getJobManagerBinPath());
- resourceJobManager.setResourceJobManagerType(getResourceJobManagerType());
- if (existingResourceJobManager == null) {
- em.persist(resourceJobManager);
- } else {
- em.merge(resourceJobManager);
- }
- 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();
- ResourceJobManager resourceJobManager = em.find(ResourceJobManager.class, identifier);
- em.close();
- return resourceJobManager != 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 getResourceJobManagerId() {
- return resourceJobManagerId;
- }
-
- public String getPushMonitoringEndpoint() {
- return pushMonitoringEndpoint;
- }
-
- public String getJobManagerBinPath() {
- return jobManagerBinPath;
- }
-
- public String getResourceJobManagerType() {
- return resourceJobManagerType;
- }
-
- public void setResourceJobManagerId(String resourceJobManagerId) {
- this.resourceJobManagerId=resourceJobManagerId;
- }
-
- public void setPushMonitoringEndpoint(String pushMonitoringEndpoint) {
- this.pushMonitoringEndpoint=pushMonitoringEndpoint;
- }
-
- public void setJobManagerBinPath(String jobManagerBinPath) {
- this.jobManagerBinPath=jobManagerBinPath;
- }
-
- public void setResourceJobManagerType(String resourceJobManagerType) {
- this.resourceJobManagerType=resourceJobManagerType;
- }
-}
http://git-wip-us.apache.org/repos/asf/airavata/blob/4045c094/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ResourceJobManagerResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ResourceJobManagerResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ResourceJobManagerResource.java
new file mode 100644
index 0000000..e84506c
--- /dev/null
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ResourceJobManagerResource.java
@@ -0,0 +1,301 @@
+/*
+ *
+ * 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.registry.core.app.catalog.resources;
+
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.common.utils.AiravataUtils;
+import org.apache.airavata.registry.core.app.catalog.model.ResourceJobManager;
+import org.apache.airavata.registry.core.app.catalog.util.AppCatalogJPAUtils;
+import org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator;
+import org.apache.airavata.registry.core.app.catalog.util.AppCatalogResourceType;
+import org.apache.airavata.registry.cpi.AppCatalogException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ResourceJobManagerResource extends AppCatAbstractResource {
+ private final static Logger logger = LoggerFactory.getLogger(ResourceJobManagerResource.class);
+ private String resourceJobManagerId;
+ private String pushMonitoringEndpoint;
+ private String jobManagerBinPath;
+ private String resourceJobManagerType;
+ private Timestamp createdTime;
+ private Timestamp updatedTime;
+
+ 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;
+ }
+
+ @Override
+ public void remove(Object identifier) throws AppCatalogException {
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(RESOURCE_JOB_MANAGER);
+ generator.setParameter(ResourceJobManagerConstants.RESOURCE_JOB_MANAGER_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 AppCatalogResource get(Object identifier) throws AppCatalogException {
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(RESOURCE_JOB_MANAGER);
+ generator.setParameter(ResourceJobManagerConstants.RESOURCE_JOB_MANAGER_ID, identifier);
+ Query q = generator.selectQuery(em);
+ ResourceJobManager resourceJobManager = (ResourceJobManager) q.getSingleResult();
+ ResourceJobManagerResource resourceJobManagerResource = (ResourceJobManagerResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.RESOURCE_JOB_MANAGER, resourceJobManager);
+ em.getTransaction().commit();
+ em.close();
+ return resourceJobManagerResource;
+ } 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<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
+ List<AppCatalogResource> resourceJobManagerResources = new ArrayList<AppCatalogResource>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(RESOURCE_JOB_MANAGER);
+ Query q;
+ if ((fieldName.equals(ResourceJobManagerConstants.RESOURCE_JOB_MANAGER_ID)) || (fieldName.equals(ResourceJobManagerConstants.PUSH_MONITORING_ENDPOINT)) || (fieldName.equals(ResourceJobManagerConstants.JOB_MANAGER_BIN_PATH)) || (fieldName.equals(ResourceJobManagerConstants.RESOURCE_JOB_MANAGER_TYPE))) {
+ generator.setParameter(fieldName, value);
+ q = generator.selectQuery(em);
+ List<?> results = q.getResultList();
+ for (Object result : results) {
+ ResourceJobManager resourceJobManager = (ResourceJobManager) result;
+ ResourceJobManagerResource resourceJobManagerResource = (ResourceJobManagerResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.RESOURCE_JOB_MANAGER, resourceJobManager);
+ resourceJobManagerResources.add(resourceJobManagerResource);
+ }
+ } else {
+ em.getTransaction().commit();
+ em.close();
+ logger.error("Unsupported field name for Resource Job Manager Resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for Resource Job Manager 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 resourceJobManagerResources;
+ }
+
+ @Override
+ public List<AppCatalogResource> getAll() throws AppCatalogException {
+ return null;
+ }
+
+ @Override
+ public List<String> getAllIds() throws AppCatalogException {
+ return null;
+ }
+
+ @Override
+ public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
+ List<String> resourceJobManagerResourceIDs = new ArrayList<String>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(RESOURCE_JOB_MANAGER);
+ Query q;
+ if ((fieldName.equals(ResourceJobManagerConstants.RESOURCE_JOB_MANAGER_ID)) || (fieldName.equals(ResourceJobManagerConstants.PUSH_MONITORING_ENDPOINT)) || (fieldName.equals(ResourceJobManagerConstants.JOB_MANAGER_BIN_PATH)) || (fieldName.equals(ResourceJobManagerConstants.RESOURCE_JOB_MANAGER_TYPE))) {
+ generator.setParameter(fieldName, value);
+ q = generator.selectQuery(em);
+ List<?> results = q.getResultList();
+ for (Object result : results) {
+ ResourceJobManager resourceJobManager = (ResourceJobManager) result;
+ ResourceJobManagerResource resourceJobManagerResource = (ResourceJobManagerResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.RESOURCE_JOB_MANAGER, resourceJobManager);
+ resourceJobManagerResourceIDs.add(resourceJobManagerResource.getResourceJobManagerId());
+ }
+ } else {
+ em.getTransaction().commit();
+ em.close();
+ logger.error("Unsupported field name for Resource Job Manager Resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for Resource Job Manager 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 resourceJobManagerResourceIDs;
+ }
+
+ @Override
+ public void save() throws AppCatalogException {
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ ResourceJobManager existingResourceJobManager = em.find(ResourceJobManager.class, resourceJobManagerId);
+ em.close();
+ ResourceJobManager resourceJobManager;
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ if (existingResourceJobManager == null) {
+ resourceJobManager = new ResourceJobManager();
+ resourceJobManager.setCreationTime(AiravataUtils.getCurrentTimestamp());
+ } else {
+ resourceJobManager = existingResourceJobManager;
+ resourceJobManager.setUpdateTime(AiravataUtils.getCurrentTimestamp());
+ }
+ resourceJobManager.setResourceJobManagerId(getResourceJobManagerId());
+ resourceJobManager.setPushMonitoringEndpoint(getPushMonitoringEndpoint());
+ resourceJobManager.setJobManagerBinPath(getJobManagerBinPath());
+ resourceJobManager.setResourceJobManagerType(getResourceJobManagerType());
+ if (existingResourceJobManager == null) {
+ em.persist(resourceJobManager);
+ } else {
+ em.merge(resourceJobManager);
+ }
+ 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();
+ ResourceJobManager resourceJobManager = em.find(ResourceJobManager.class, identifier);
+ em.close();
+ return resourceJobManager != 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 getResourceJobManagerId() {
+ return resourceJobManagerId;
+ }
+
+ public String getPushMonitoringEndpoint() {
+ return pushMonitoringEndpoint;
+ }
+
+ public String getJobManagerBinPath() {
+ return jobManagerBinPath;
+ }
+
+ public String getResourceJobManagerType() {
+ return resourceJobManagerType;
+ }
+
+ public void setResourceJobManagerId(String resourceJobManagerId) {
+ this.resourceJobManagerId=resourceJobManagerId;
+ }
+
+ public void setPushMonitoringEndpoint(String pushMonitoringEndpoint) {
+ this.pushMonitoringEndpoint=pushMonitoringEndpoint;
+ }
+
+ public void setJobManagerBinPath(String jobManagerBinPath) {
+ this.jobManagerBinPath=jobManagerBinPath;
+ }
+
+ public void setResourceJobManagerType(String resourceJobManagerType) {
+ this.resourceJobManagerType=resourceJobManagerType;
+ }
+}