You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sm...@apache.org on 2015/11/13 06:14:02 UTC
airavata git commit: adding implimenttaions for storage resource
Repository: airavata
Updated Branches:
refs/heads/develop 96687a6b7 -> a6de53904
adding implimenttaions for storage resource
Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/a6de5390
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/a6de5390
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/a6de5390
Branch: refs/heads/develop
Commit: a6de5390478194a63da242ef6bca0e9b0f4f9a76
Parents: 96687a6
Author: smarru <sm...@apache.org>
Authored: Fri Nov 13 00:13:57 2015 -0500
Committer: smarru <sm...@apache.org>
Committed: Fri Nov 13 00:13:57 2015 -0500
----------------------------------------------------------------------
.../server/handler/AiravataServerHandler.java | 57 ++-
.../core/app/catalog/impl/AppCatalogImpl.java | 4 +
.../app/catalog/impl/StorageResourceImpl.java | 248 +++++++++++++
.../core/app/catalog/model/StorageResource.java | 102 ++++++
.../resources/AppCatAbstractResource.java | 8 +
.../resources/StorageResourceResource.java | 350 +++++++++++++++++++
.../catalog/util/AppCatalogResourceType.java | 1 +
.../util/AppCatalogThriftConversion.java | 27 ++
.../airavata/registry/cpi/AppCatalog.java | 6 +
.../airavata/registry/cpi/StorageResource.java | 90 +++++
10 files changed, 888 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/airavata/blob/a6de5390/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
----------------------------------------------------------------------
diff --git a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
index 569efcd..e1f53bf 100644
--- a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
+++ b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
@@ -2483,7 +2483,16 @@ public class AiravataServerHandler implements Airavata.Iface {
*/
@Override
public String registerStorageResource(AuthzToken authzToken, StorageResourceDescription storageResourceDescription) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
- return null;
+ try {
+ appCatalog = RegistryFactory.getAppCatalog();
+ return appCatalog.getStorageResource().addStorageResource(storageResourceDescription);
+ } catch (AppCatalogException e) {
+ logger.error("Error while saving storage resource...", e);
+ AiravataSystemException exception = new AiravataSystemException();
+ exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
+ exception.setMessage("Error while saving storage resource. More info : " + e.getMessage());
+ throw exception;
+ }
}
/**
@@ -2496,7 +2505,16 @@ public class AiravataServerHandler implements Airavata.Iface {
*/
@Override
public StorageResourceDescription getStorageResource(AuthzToken authzToken, String storageResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
- return null;
+ try {
+ appCatalog = RegistryFactory.getAppCatalog();
+ return appCatalog.getStorageResource().getStorageResource(storageResourceId);
+ } catch (AppCatalogException e) {
+ logger.error(storageResourceId, "Error while retrieving storage resource...", e);
+ AiravataSystemException exception = new AiravataSystemException();
+ exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
+ exception.setMessage("Error while retrieving storage resource. More info : " + e.getMessage());
+ throw exception;
+ }
}
/**
@@ -2508,7 +2526,16 @@ public class AiravataServerHandler implements Airavata.Iface {
*/
@Override
public Map<String, String> getAllStorageResourceNames(AuthzToken authzToken) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
- return null;
+ try {
+ appCatalog = RegistryFactory.getAppCatalog();
+ return appCatalog.getStorageResource().getAllStorageResourceIdList();
+ } catch (AppCatalogException e) {
+ logger.error("Error while retrieving storage resource...", e);
+ AiravataSystemException exception = new AiravataSystemException();
+ exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
+ exception.setMessage("Error while retrieving storage resource. More info : " + e.getMessage());
+ throw exception;
+ }
}
/**
@@ -2522,7 +2549,17 @@ public class AiravataServerHandler implements Airavata.Iface {
*/
@Override
public boolean updateStorageResource(AuthzToken authzToken, String storageResourceId, StorageResourceDescription storageResourceDescription) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
- return false;
+ try {
+ appCatalog = RegistryFactory.getAppCatalog();
+ appCatalog.getStorageResource().updateStorageResource(storageResourceId, storageResourceDescription);
+ return true;
+ } catch (AppCatalogException e) {
+ logger.error(storageResourceId, "Error while updating storage resource...", e);
+ AiravataSystemException exception = new AiravataSystemException();
+ exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
+ exception.setMessage("Error while updaing storage resource. More info : " + e.getMessage());
+ throw exception;
+ }
}
/**
@@ -2535,7 +2572,17 @@ public class AiravataServerHandler implements Airavata.Iface {
*/
@Override
public boolean deleteStorageResource(AuthzToken authzToken, String storageResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
- return false;
+ try {
+ appCatalog = RegistryFactory.getAppCatalog();
+ appCatalog.getStorageResource().removeStorageResource(storageResourceId);
+ return true;
+ } catch (AppCatalogException e) {
+ logger.error(storageResourceId, "Error while deleting storage resource...", e);
+ AiravataSystemException exception = new AiravataSystemException();
+ exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
+ exception.setMessage("Error while deleting storage resource. More info : " + e.getMessage());
+ throw exception;
+ }
}
/**
http://git-wip-us.apache.org/repos/asf/airavata/blob/a6de5390/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/impl/AppCatalogImpl.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/impl/AppCatalogImpl.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/impl/AppCatalogImpl.java
index 279746f..054b0e0 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/impl/AppCatalogImpl.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/impl/AppCatalogImpl.java
@@ -29,6 +29,10 @@ public class AppCatalogImpl implements AppCatalog {
return new ComputeResourceImpl();
}
+ public StorageResource getStorageResource() throws AppCatalogException {
+ return new StorageResourceImpl();
+ }
+
public ApplicationInterface getApplicationInterface() {
return new ApplicationInterfaceImpl();
}
http://git-wip-us.apache.org/repos/asf/airavata/blob/a6de5390/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/impl/StorageResourceImpl.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/impl/StorageResourceImpl.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/impl/StorageResourceImpl.java
new file mode 100644
index 0000000..64b9e73
--- /dev/null
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/impl/StorageResourceImpl.java
@@ -0,0 +1,248 @@
+/*
+ *
+ * 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.impl;
+
+import org.apache.airavata.model.appcatalog.storageresource.StorageResourceDescription;
+import org.apache.airavata.model.commons.airavata_commonsConstants;
+import org.apache.airavata.registry.core.app.catalog.resources.AppCatAbstractResource;
+import org.apache.airavata.registry.core.app.catalog.resources.AppCatalogResource;
+import org.apache.airavata.registry.core.app.catalog.resources.StorageResourceResource;
+import org.apache.airavata.registry.core.app.catalog.util.AppCatalogThriftConversion;
+import org.apache.airavata.registry.core.app.catalog.util.AppCatalogUtils;
+import org.apache.airavata.registry.cpi.AppCatalogException;
+import org.apache.airavata.registry.cpi.StorageResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class StorageResourceImpl implements StorageResource {
+ private final static Logger logger = LoggerFactory.getLogger(StorageResourceImpl.class);
+
+
+ protected String saveStorageResourceDescriptorData(
+ StorageResourceDescription description) throws AppCatalogException {
+ //TODO remove existing one
+ StorageResourceResource storageResourceResource = saveStorageResource(description);
+ return storageResourceResource.getResourceId();
+ }
+
+ protected StorageResourceResource saveStorageResource(
+ StorageResourceDescription description) throws AppCatalogException {
+ StorageResourceResource storageResourceResource = AppCatalogThriftConversion.getStorageResource(description);
+ storageResourceResource.save();
+ return storageResourceResource;
+ }
+
+ /**
+ * This function will add a storage resource description to the database
+ *
+ * @param description storage resource description
+ * @return unique resource ID generated by airavata
+ */
+ @Override
+ public String addStorageResource(StorageResourceDescription description) throws AppCatalogException {
+ try {
+ if (description.getStorageResourceDescription().equals("") || description.getStorageResourceId().equals(airavata_commonsConstants.DEFAULT_ID)){
+ description.setStorageResourceId(AppCatalogUtils.getID(description.getHostName()));
+ }
+ return saveStorageResourceDescriptorData(description);
+ } catch (Exception e) {
+ logger.error("Error while saving storage resource...", e);
+ throw new AppCatalogException(e);
+ }
+ }
+
+ /**
+ * This method will update storage resource
+ *
+ * @param storageResourceId unique storage resource id
+ * @param updatedStorageResource updated storage resource
+ */
+ @Override
+ public void updateStorageResource(String storageResourceId, StorageResourceDescription updatedStorageResource) throws AppCatalogException {
+ try {
+ saveStorageResourceDescriptorData(updatedStorageResource);
+ } catch (Exception e) {
+ logger.error("Error while updating storage resource...", e);
+ throw new AppCatalogException(e);
+ }
+ }
+
+ /**
+ * This method will retrieve storage resource object on given resource id
+ *
+ * @param resourceId unique resource id
+ * @return StorageResource object
+ */
+ @Override
+ public StorageResourceDescription getStorageResource(String resourceId) throws AppCatalogException {
+ try {
+ StorageResourceResource resource = new StorageResourceResource();
+ StorageResourceResource storageResource = (StorageResourceResource)resource.get(resourceId);
+ return AppCatalogThriftConversion.getStorageDescription(storageResource);
+ }catch (Exception e){
+ logger.error("Error while retrieving storage resource...", e);
+ throw new AppCatalogException(e);
+ }
+ }
+
+ /**
+ * This method will return a list of storageResource descriptions according to given search criteria
+ *
+ * @param filters map should be provided as the field name and it's value
+ * @return list of storage resources
+ */
+ @Override
+ public List<StorageResourceDescription> getStorageResourceList(Map<String, String> filters) throws AppCatalogException {
+ List<StorageResourceDescription> storageResourceDescriptions = new ArrayList<StorageResourceDescription>();
+ try {
+ //TODO check if this is correct way to do this
+ StorageResourceResource resource = new StorageResourceResource();
+ for (String fieldName : filters.keySet() ){
+ if (fieldName.equals(AppCatAbstractResource.StorageResourceConstants.HOST_NAME)){
+ List<AppCatalogResource> resources = resource.get(AppCatAbstractResource.ComputeResourceConstants.HOST_NAME, filters.get(fieldName));
+ if (resources != null && !resources.isEmpty()){
+ storageResourceDescriptions = AppCatalogThriftConversion.getStorageDescriptionList(resources);
+ }
+ }else {
+ logger.error("Unsupported field name for storage resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for storage resource.");
+ }
+ }
+ }catch (Exception e){
+ logger.error("Error while retrieving storage resource list...", e);
+ throw new AppCatalogException(e);
+ }
+ return storageResourceDescriptions;
+ }
+
+ /**
+ * This method will retrieve all the storage resources
+ *
+ * @return list of storage resources
+ * @throws AppCatalogException
+ */
+ @Override
+ public List<StorageResourceDescription> getAllStorageResourceList() throws AppCatalogException {
+ List<StorageResourceDescription> storageResourceDescriptions = new ArrayList<StorageResourceDescription>();
+ try {
+ StorageResourceResource resource = new StorageResourceResource();
+ List<AppCatalogResource> resources = resource.getAll();
+ if (resources != null && !resources.isEmpty()){
+ storageResourceDescriptions = AppCatalogThriftConversion.getStorageDescriptionList(resources);
+ }
+ }catch (Exception e){
+ logger.error("Error while retrieving storage resource list...", e);
+ throw new AppCatalogException(e);
+ }
+ return storageResourceDescriptions;
+ }
+
+ /**
+ * This method will retrieve all the storage resource id with it's name
+ *
+ * @return map of storage resource ids + name
+ * @throws AppCatalogException
+ */
+ @Override
+ public Map<String, String> getAllStorageResourceIdList() throws AppCatalogException {
+ try {
+ Map<String, String> storageResourceMap = new HashMap<String, String>();
+ StorageResourceResource resource = new StorageResourceResource();
+ List<AppCatalogResource> allStorageResources = resource.getAll();
+ if (allStorageResources != null && !allStorageResources.isEmpty()){
+ for (AppCatalogResource sr : allStorageResources){
+ StorageResourceResource srr = (StorageResourceResource)allStorageResources;
+ storageResourceMap.put(srr.getResourceId(), srr.getHostName());
+ }
+ }
+ return storageResourceMap;
+ }catch (Exception e){
+ logger.error("Error while retrieving storage resource list...", e);
+ throw new AppCatalogException(e);
+ }
+ }
+
+ /**
+ * This method will retrieve all the enabled storage resource id with it's name
+ *
+ * @return
+ * @throws AppCatalogException
+ */
+ @Override
+ public Map<String, String> getAvailableStorageResourceIdList() throws AppCatalogException {
+ try {
+ Map<String, String> storageResourceMap = new HashMap<String, String>();
+ StorageResourceResource resource = new StorageResourceResource();
+ List<AppCatalogResource> allStorageResources = resource.getAll();
+ if (allStorageResources != null && !allStorageResources.isEmpty()){
+ for (AppCatalogResource sr : allStorageResources){
+ StorageResourceResource srr = (StorageResourceResource)sr;
+ if(srr.isEnabled()) {
+ storageResourceMap.put(srr.getResourceId(), srr.getHostName());
+ }
+ }
+ }
+ return storageResourceMap;
+ }catch (Exception e){
+ logger.error("Error while retrieving storage resource list...", e);
+ throw new AppCatalogException(e);
+ }
+ }
+
+ /**
+ * This method will check whether the given resource already exists in the system
+ *
+ * @param resourceId unique resource id
+ * @return true or false
+ */
+ @Override
+ public boolean isStorageResourceExists(String resourceId) throws AppCatalogException {
+ try {
+ StorageResourceResource resource = new StorageResourceResource();
+ return resource.isExists(resourceId);
+ }catch (Exception e){
+ logger.error("Error while retrieving storage resource...", e);
+ throw new AppCatalogException(e);
+ }
+ }
+
+ /**
+ * This method will remove given resource from the system
+ *
+ * @param resourceId unique resource id
+ */
+ @Override
+ public void removeStorageResource(String resourceId) throws AppCatalogException {
+ try {
+ StorageResourceResource resource = new StorageResourceResource();
+ resource.remove(resourceId);
+ }catch (Exception e){
+ logger.error("Error while removing storage resource...", e);
+ throw new AppCatalogException(e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/a6de5390/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/model/StorageResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/model/StorageResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/model/StorageResource.java
new file mode 100644
index 0000000..51f0ec9
--- /dev/null
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/model/StorageResource.java
@@ -0,0 +1,102 @@
+/*
+ *
+ * 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.model;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import java.io.Serializable;
+import java.sql.Timestamp;
+
+@Entity
+@Table(name = "STORAGE_RESOURCE")
+public class StorageResource implements Serializable {
+
+ @Column(name = "RESOURCE_DESCRIPTION")
+ private String resourceDescription;
+
+ @Id
+ @Column(name = "RESOURCE_ID")
+ private String resourceId;
+
+ @Column(name = "HOST_NAME")
+ private String hostName;
+
+ @Column(name = "CREATION_TIME")
+ private Timestamp creationTime;
+
+ @Column(name = "UPDATE_TIME")
+ private Timestamp updateTime;
+
+ @Column(name = "ENABLED")
+ private boolean enabled;
+
+ public Timestamp getCreationTime() {
+ return creationTime;
+ }
+
+ public void setCreationTime(Timestamp creationTime) {
+ this.creationTime = creationTime;
+ }
+
+ public Timestamp getUpdateTime() {
+ return updateTime;
+ }
+
+ public void setUpdateTime(Timestamp updateTime) {
+ this.updateTime = updateTime;
+ }
+
+ public String getResourceDescription() {
+ return resourceDescription;
+ }
+
+ public String getResourceId() {
+ return resourceId;
+ }
+
+ public String getHostName() {
+ return hostName;
+ }
+
+ public Boolean getEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(Boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public void setResourceDescription(String resourceDescription) {
+ this.resourceDescription=resourceDescription;
+ }
+
+ public void setResourceId(String resourceId) {
+ this.resourceId=resourceId;
+ }
+
+ public void setHostName(String hostName) {
+ this.hostName=hostName;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/a6de5390/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppCatAbstractResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppCatAbstractResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppCatAbstractResource.java
index 3707f79..926bfae 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppCatAbstractResource.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppCatAbstractResource.java
@@ -24,6 +24,7 @@ package org.apache.airavata.registry.core.app.catalog.resources;
public abstract class AppCatAbstractResource implements AppCatalogResource {
// table names
public static final String COMPUTE_RESOURCE = "ComputeResource";
+ public static final String STORAGE_RESOURCE = "StorageResource";
public static final String HOST_ALIAS = "HostAlias";
public static final String HOST_IPADDRESS = "HostIPAddress";
public static final String GSISSH_SUBMISSION = "GSISSHSubmission";
@@ -79,6 +80,13 @@ public abstract class AppCatAbstractResource implements AppCatalogResource {
public static final String HOST_NAME = "hostName";
}
+ // Storage Resource Table
+ public final class StorageResourceConstants {
+ public static final String RESOURCE_DESCRIPTION = "resourceDescription";
+ public static final String RESOURCE_ID = "resourceId";
+ public static final String HOST_NAME = "hostName";
+ }
+
// Host Alias Table
public final class HostAliasConstants {
public static final String RESOURCE_ID = "resourceID";
http://git-wip-us.apache.org/repos/asf/airavata/blob/a6de5390/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/StorageResourceResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/StorageResourceResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/StorageResourceResource.java
new file mode 100644
index 0000000..868c5ab
--- /dev/null
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/StorageResourceResource.java
@@ -0,0 +1,350 @@
+/*
+ *
+ * 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.common.utils.AiravataUtils;
+import org.apache.airavata.registry.core.app.catalog.model.StorageResource;
+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.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.List;
+
+public class StorageResourceResource extends AppCatAbstractResource {
+ private final static Logger logger = LoggerFactory.getLogger(StorageResourceResource.class);
+ private String resourceDescription;
+ private String resourceId;
+ private String hostName;
+ private Timestamp createdTime;
+ private Timestamp updatedTime;
+ private boolean enabled;
+
+ 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 boolean isEnabled() {
+ return enabled;
+ }
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ @Override
+ public void remove(Object identifier) throws AppCatalogException {
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(STORAGE_RESOURCE);
+ generator.setParameter(StorageResourceConstants.RESOURCE_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(STORAGE_RESOURCE);
+ generator.setParameter(StorageResourceConstants.RESOURCE_ID, identifier);
+ Query q = generator.selectQuery(em);
+ StorageResource storageResource = (StorageResource) q.getSingleResult();
+ StorageResourceResource storageResourceResource = (StorageResourceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.STORAGE_RESOURCE, storageResource);
+ em.getTransaction().commit();
+ em.close();
+ return storageResourceResource;
+ } 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> storageResourceResources = new ArrayList<AppCatalogResource>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(STORAGE_RESOURCE);
+ Query q;
+ if ((fieldName.equals(StorageResourceConstants.RESOURCE_DESCRIPTION)) || (fieldName.equals(StorageResourceConstants.RESOURCE_ID)) || (fieldName.equals(StorageResourceConstants.HOST_NAME))) {
+ generator.setParameter(fieldName, value);
+ q = generator.selectQuery(em);
+ List<?> results = q.getResultList();
+ for (Object result : results) {
+ StorageResource storageResource = (StorageResource) result;
+ StorageResourceResource storageResourceResource = (StorageResourceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.STORAGE_RESOURCE, storageResource);
+ storageResourceResources.add(storageResourceResource);
+ }
+ } else {
+ em.getTransaction().commit();
+ em.close();
+ logger.error("Unsupported field name for Storage Resource Resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for Storage Resource 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 storageResourceResources;
+ }
+
+ @Override
+ public List<AppCatalogResource> getAll() throws AppCatalogException {
+ List<AppCatalogResource> storageResourceResources = new ArrayList<AppCatalogResource>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(STORAGE_RESOURCE);
+ Query q = generator.selectQuery(em);
+ List<?> results = q.getResultList();
+ for (Object result : results) {
+ StorageResource storageResource = (StorageResource) result;
+ StorageResourceResource storageResourceResource = (StorageResourceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.STORAGE_RESOURCE, storageResource);
+ storageResourceResources.add(storageResourceResource);
+ }
+ 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 storageResourceResources;
+ }
+
+ @Override
+ public List<String> getAllIds() throws AppCatalogException {
+ List<String> storageResourceResources = new ArrayList<String>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(STORAGE_RESOURCE);
+ Query q = generator.selectQuery(em);
+ List<?> results = q.getResultList();
+ for (Object result : results) {
+ StorageResource storageResource = (StorageResource) result;
+ storageResourceResources.add(storageResource.getResourceId());
+ }
+ 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 storageResourceResources;
+ }
+
+ @Override
+ public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
+ List<String> storageResourceResourceIDs = new ArrayList<String>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(STORAGE_RESOURCE);
+ Query q;
+ if ((fieldName.equals(StorageResourceConstants.RESOURCE_DESCRIPTION)) || (fieldName.equals(StorageResourceConstants.RESOURCE_ID)) || (fieldName.equals(StorageResourceConstants.HOST_NAME))) {
+ generator.setParameter(fieldName, value);
+ q = generator.selectQuery(em);
+ List<?> results = q.getResultList();
+ for (Object result : results) {
+ StorageResource storageResource = (StorageResource) result;
+ StorageResourceResource storageResourceResource = (StorageResourceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.STORAGE_RESOURCE, storageResource);
+ storageResourceResourceIDs.add(storageResourceResource.getResourceId());
+ }
+ } else {
+ em.getTransaction().commit();
+ em.close();
+ logger.error("Unsupported field name for Storage Resource Resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for Storage Resource 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 storageResourceResourceIDs;
+ }
+
+ @Override
+ public void save() throws AppCatalogException {
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ StorageResource existingStorageResource = em.find(StorageResource.class, resourceId);
+ em.close();
+ StorageResource storageResource;
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ if (existingStorageResource == null) {
+ storageResource = new StorageResource();
+ storageResource.setCreationTime(AiravataUtils.getCurrentTimestamp());
+ } else {
+ storageResource = existingStorageResource;
+ storageResource.setUpdateTime(AiravataUtils.getCurrentTimestamp());
+ }
+ storageResource.setResourceDescription(getResourceDescription());
+ storageResource.setResourceId(getResourceId());
+ storageResource.setHostName(getHostName());
+ storageResource.setEnabled(isEnabled());
+ if (existingStorageResource == null) {
+ em.persist(storageResource);
+ } else {
+ em.merge(storageResource);
+ }
+ 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();
+ StorageResource storageResource = em.find(StorageResource.class, identifier);
+ em.close();
+ return storageResource != 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 getResourceDescription() {
+ return resourceDescription;
+ }
+
+ public String getResourceId() {
+ return resourceId;
+ }
+
+ public String getHostName() {
+ return hostName;
+ }
+
+ public void setResourceDescription(String resourceDescription) {
+ this.resourceDescription=resourceDescription;
+ }
+
+ public void setResourceId(String resourceId) {
+ this.resourceId=resourceId;
+ }
+
+ public void setHostName(String hostName) {
+ this.hostName=hostName;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/a6de5390/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogResourceType.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogResourceType.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogResourceType.java
index 91f59ec..0f31464 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogResourceType.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogResourceType.java
@@ -23,6 +23,7 @@ package org.apache.airavata.registry.core.app.catalog.util;
public enum AppCatalogResourceType {
COMPUTE_RESOURCE,
+ STORAGE_RESOURCE,
HOST_ALIAS,
HOST_IPADDRESS,
GSISSH_SUBMISSION,
http://git-wip-us.apache.org/repos/asf/airavata/blob/a6de5390/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogThriftConversion.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogThriftConversion.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogThriftConversion.java
index 045cd75..aa681be 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogThriftConversion.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogThriftConversion.java
@@ -36,6 +36,7 @@ import org.apache.airavata.model.appcatalog.computeresource.UnicoreJobSubmission
import org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference;
import org.apache.airavata.model.appcatalog.gatewayprofile.DataStoragePreference;
import org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile;
+import org.apache.airavata.model.appcatalog.storageresource.StorageResourceDescription;
import org.apache.airavata.model.application.io.DataType;
import org.apache.airavata.model.application.io.InputDataObjectType;
import org.apache.airavata.model.application.io.OutputDataObjectType;
@@ -55,6 +56,15 @@ public class AppCatalogThriftConversion {
return resource;
}
+ public static StorageResourceResource getStorageResource (StorageResourceDescription description){
+ StorageResourceResource resource = new StorageResourceResource();
+ resource.setHostName(description.getHostName());
+ resource.setResourceDescription(description.getStorageResourceDescription());
+ resource.setResourceId(description.getStorageResourceId());
+ resource.setEnabled(description.isEnabled());
+ return resource;
+ }
+
public static ComputeResourceDescription getComputeHostDescription (ComputeResourceResource resource) throws AppCatalogException {
ComputeResourceDescription description = new ComputeResourceDescription();
description.setComputeResourceId(resource.getResourceId());
@@ -103,6 +113,15 @@ public class AppCatalogThriftConversion {
return description;
}
+ public static StorageResourceDescription getStorageDescription (StorageResourceResource resource) throws AppCatalogException {
+ StorageResourceDescription description = new StorageResourceDescription();
+ description.setStorageResourceId(resource.getResourceId());
+ description.setHostName(resource.getHostName());
+ description.setStorageResourceDescription(resource.getResourceDescription());
+ description.setEnabled(resource.isEnabled());
+ return description;
+ }
+
public static List<ComputeResourceDescription> getComputeDescriptionList (List<AppCatalogResource> resources) throws AppCatalogException {
List<ComputeResourceDescription> list = new ArrayList<ComputeResourceDescription>();
for (AppCatalogResource resource : resources){
@@ -111,6 +130,14 @@ public class AppCatalogThriftConversion {
return list;
}
+ public static List<StorageResourceDescription> getStorageDescriptionList (List<AppCatalogResource> resources) throws AppCatalogException {
+ List<StorageResourceDescription> list = new ArrayList<StorageResourceDescription>();
+ for (AppCatalogResource resource : resources){
+ list.add(getStorageDescription((StorageResourceResource) resource));
+ }
+ return list;
+ }
+
public static List<String> getHostAliases (List<AppCatalogResource> resources){
List<String> hostAliases = new ArrayList<String>();
for (AppCatalogResource alias : resources){
http://git-wip-us.apache.org/repos/asf/airavata/blob/a6de5390/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/AppCatalog.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/AppCatalog.java b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/AppCatalog.java
index 4595de7..0f7c2c9 100644
--- a/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/AppCatalog.java
+++ b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/AppCatalog.java
@@ -27,6 +27,12 @@ public interface AppCatalog {
ComputeResource getComputeResource() throws AppCatalogException;
/**
+ * Get StorageResource interface
+ * @return StorageResource interface
+ */
+ StorageResource getStorageResource() throws AppCatalogException;
+
+ /**
* Get application interface
* @return application interface
*/
http://git-wip-us.apache.org/repos/asf/airavata/blob/a6de5390/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/StorageResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/StorageResource.java b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/StorageResource.java
new file mode 100644
index 0000000..8579303
--- /dev/null
+++ b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/StorageResource.java
@@ -0,0 +1,90 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.cpi;
+
+import org.apache.airavata.model.appcatalog.storageresource.StorageResourceDescription;
+
+import java.util.List;
+import java.util.Map;
+
+public interface StorageResource {
+ /**
+ * This function will add a storage resource description to the database
+ * @param description storage resource description
+ * @return unique resource ID generated by airavata
+ */
+ String addStorageResource(StorageResourceDescription description) throws AppCatalogException;
+
+ /**
+ * This method will update storage resource
+ * @param storageResourceId unique storage resource id
+ * @param updatedStorageResource updated storage resource
+ */
+ void updateStorageResource(String storageResourceId, StorageResourceDescription updatedStorageResource) throws AppCatalogException;
+
+ /**
+ * This method will retrieve storage resource object on given resource id
+ * @param resourceId unique resource id
+ * @return StorageResource object
+ */
+ StorageResourceDescription getStorageResource(String resourceId) throws AppCatalogException;
+
+ /**
+ * This method will return a list of storageResource descriptions according to given search criteria
+ * @param filters map should be provided as the field name and it's value
+ * @return list of storage resources
+ */
+ List<StorageResourceDescription> getStorageResourceList(Map<String, String> filters) throws AppCatalogException;
+
+ /**
+ * This method will retrieve all the storage resources
+ * @return list of storage resources
+ * @throws AppCatalogException
+ */
+ List<StorageResourceDescription> getAllStorageResourceList() throws AppCatalogException;
+
+ /**
+ * This method will retrieve all the storage resource id with it's name
+ * @return map of storage resource ids + name
+ * @throws AppCatalogException
+ */
+ Map<String, String> getAllStorageResourceIdList() throws AppCatalogException;
+
+ /**
+ * This method will retrieve all the enabled storage resource id with it's name
+ * @return
+ * @throws AppCatalogException
+ */
+ Map<String, String> getAvailableStorageResourceIdList() throws AppCatalogException;
+
+ /**
+ * This method will check whether the given resource already exists in the system
+ * @param resourceId unique resource id
+ * @return true or false
+ */
+ boolean isStorageResourceExists(String resourceId) throws AppCatalogException;
+
+ /**
+ * This method will remove given resource from the system
+ * @param resourceId unique resource id
+ */
+ void removeStorageResource(String resourceId) throws AppCatalogException;
+
+}