http://git-wip-us.apache.org/repos/asf/airavata/blob/ec8c6202/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/ApplicationInterfaceImpl.java ---------------------------------------------------------------------- diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/ApplicationInterfaceImpl.java b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/ApplicationInterfaceImpl.java deleted file mode 100644 index 80a974c..0000000 --- a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/ApplicationInterfaceImpl.java +++ /dev/null @@ -1,450 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -package org.apache.aiaravata.application.catalog.data.impl; - -import org.airavata.appcatalog.cpi.AppCatalogException; -import org.airavata.appcatalog.cpi.ApplicationInterface; -import org.apache.aiaravata.application.catalog.data.resources.*; -import org.apache.aiaravata.application.catalog.data.util.AppCatalogThriftConversion; -import org.apache.aiaravata.application.catalog.data.util.AppCatalogUtils; -import org.apache.airavata.model.appcatalog.appdeployment.ApplicationModule; -import org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDescription; -import org.apache.airavata.model.appcatalog.appinterface.InputDataObjectType; -import org.apache.airavata.model.appcatalog.appinterface.OutputDataObjectType; -import org.apache.airavata.model.appcatalog.appinterface.applicationInterfaceModelConstants; -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 ApplicationInterfaceImpl implements ApplicationInterface { - private final static Logger logger = LoggerFactory.getLogger(ApplicationInterfaceImpl.class); - - @Override - public String addApplicationModule(ApplicationModule applicationModule, String gatewayId) throws AppCatalogException { - try { - AppModuleResource moduleResource = new AppModuleResource(); - moduleResource.setModuleName(applicationModule.getAppModuleName()); - moduleResource.setGatewayId(gatewayId); - if (!applicationModule.getAppModuleId().equals("") && !applicationModule.getAppModuleId().equals(applicationInterfaceModelConstants.DEFAULT_ID)){ - moduleResource.setModuleId(applicationModule.getAppModuleId()); - }else { - moduleResource.setModuleId(AppCatalogUtils.getID(applicationModule.getAppModuleName())); - } - moduleResource.setModuleDesc(applicationModule.getAppModuleDescription()); - moduleResource.setModuleVersion(applicationModule.getAppModuleVersion()); - moduleResource.save(); - applicationModule.setAppModuleId(moduleResource.getModuleId()); - return moduleResource.getModuleId(); - }catch (Exception e) { - logger.error("Error while adding application module "+applicationModule.getAppModuleName()+" ["+applicationModule.getAppModuleVersion()+"]", e); - throw new AppCatalogException(e); - } - } - - @Override - public String addApplicationInterface(ApplicationInterfaceDescription applicationInterfaceDescription, String gatewayId) throws AppCatalogException { - try { - AppInterfaceResource resource = new AppInterfaceResource(); - resource.setAppName(applicationInterfaceDescription.getApplicationName()); - if (!applicationInterfaceDescription.getApplicationInterfaceId().equals("") && !applicationInterfaceDescription.getApplicationInterfaceId().equals(applicationInterfaceModelConstants.DEFAULT_ID)){ - resource.setInterfaceId(applicationInterfaceDescription.getApplicationInterfaceId()); - }else { - resource.setInterfaceId(AppCatalogUtils.getID(applicationInterfaceDescription.getApplicationName())); - } - resource.setAppDescription(applicationInterfaceDescription.getApplicationDescription()); - resource.setGatewayId(gatewayId); - resource.save(); - applicationInterfaceDescription.setApplicationInterfaceId(resource.getInterfaceId()); - - List<String> applicationModules = applicationInterfaceDescription.getApplicationModules(); - if (applicationModules != null && !applicationModules.isEmpty()){ - for (String moduleId : applicationModules){ - AppModuleResource appModuleResource = new AppModuleResource(); - AppModuleMappingResource moduleMappingResource = new AppModuleMappingResource(); - moduleMappingResource.setInterfaceId(resource.getInterfaceId()); - moduleMappingResource.setModuleId(moduleId); - moduleMappingResource.setModuleResource((AppModuleResource)appModuleResource.get(moduleId)); - moduleMappingResource.setAppInterfaceResource(resource); - moduleMappingResource.save(); - } - } - - List<InputDataObjectType> applicationInputs = applicationInterfaceDescription.getApplicationInputs(); - if (applicationInputs != null && !applicationInputs.isEmpty()){ - for (InputDataObjectType input : applicationInputs){ - ApplicationInputResource inputResource = new ApplicationInputResource(); - inputResource.setAppInterfaceResource(resource); - inputResource.setInterfaceID(resource.getInterfaceId()); - inputResource.setUserFriendlyDesc(input.getUserFriendlyDescription()); - inputResource.setInputKey(input.getName()); - inputResource.setInputVal(input.getValue()); - inputResource.setDataType(input.getType().toString()); - inputResource.setMetadata(input.getMetaData()); - inputResource.setStandardInput(input.isStandardInput()); - inputResource.setAppArgument(input.getApplicationArgument()); - inputResource.setInputOrder(input.getInputOrder()); - inputResource.setRequired(input.isIsRequired()); - inputResource.setRequiredToCMD(input.isRequiredToAddedToCommandLine()); - inputResource.save(); - } - } - - List<OutputDataObjectType> applicationOutputs = applicationInterfaceDescription.getApplicationOutputs(); - if (applicationOutputs != null && !applicationOutputs.isEmpty()) { - for (OutputDataObjectType output : applicationOutputs) { - ApplicationOutputResource outputResource = new ApplicationOutputResource(); - outputResource.setInterfaceID(resource.getInterfaceId()); - outputResource.setAppInterfaceResource(resource); - outputResource.setOutputKey(output.getName()); - outputResource.setOutputVal(output.getValue()); - outputResource.setDataType(output.getType().toString()); - outputResource.setRequired(output.isIsRequired()); - outputResource.setRequiredToCMD(output.isRequiredToAddedToCommandLine()); - outputResource.setDataMovement(output.isDataMovement()); - outputResource.setDataNameLocation(output.getLocation()); - outputResource.setAppArgument(output.getApplicationArgument()); - outputResource.setSearchQuery(output.getSearchQuery()); - outputResource.save(); - } - } - return resource.getInterfaceId(); - }catch (Exception e) { - logger.error("Error while adding application interface "+applicationInterfaceDescription.getApplicationName(), e); - throw new AppCatalogException(e); - } - } - - @Override - public void addApplicationModuleMapping(String moduleId, String interfaceId) throws AppCatalogException { - try { - AppModuleResource appModuleResource = new AppModuleResource(); - AppInterfaceResource interfaceResource = new AppInterfaceResource(); - AppModuleMappingResource moduleMappingResource = new AppModuleMappingResource(); - moduleMappingResource.setInterfaceId(interfaceId); - moduleMappingResource.setModuleId(moduleId); - moduleMappingResource.setModuleResource((AppModuleResource)appModuleResource.get(moduleId)); - moduleMappingResource.setAppInterfaceResource((AppInterfaceResource)interfaceResource.get(interfaceId)); - moduleMappingResource.save(); - }catch (Exception e) { - logger.error("Error while saving application module mapping "+moduleId, e); - throw new AppCatalogException(e); - } - } - - @Override - public void updateApplicationModule(String moduleId, ApplicationModule updatedModule) throws AppCatalogException { - try { - AppModuleResource moduleResource = new AppModuleResource(); - AppModuleResource existingModule = (AppModuleResource)moduleResource.get(moduleId); - existingModule.setModuleName(updatedModule.getAppModuleName()); - existingModule.setModuleDesc(updatedModule.getAppModuleDescription()); - existingModule.setModuleVersion(updatedModule.getAppModuleVersion()); - existingModule.save(); - }catch (Exception e) { - logger.error("Error while updating application module "+moduleId, e); - throw new AppCatalogException(e); - } - } - - @Override - public void updateApplicationInterface(String interfaceId, ApplicationInterfaceDescription updatedInterface) throws AppCatalogException { - try { - AppInterfaceResource resource = new AppInterfaceResource(); - AppInterfaceResource existingInterface = (AppInterfaceResource) resource.get(interfaceId); - existingInterface.setAppName(updatedInterface.getApplicationName()); - existingInterface.setAppDescription(updatedInterface.getApplicationDescription()); - existingInterface.save(); - - // remove existing modules before adding - Map<String, String> ids = new HashMap<String, String>(); - ids.put(AbstractResource.AppModuleMappingConstants.INTERFACE_ID, interfaceId); - AppModuleMappingResource moduleMappingResource = new AppModuleMappingResource(); - moduleMappingResource.remove(ids); - List<String> applicationModules = updatedInterface.getApplicationModules(); - if (applicationModules != null && !applicationModules.isEmpty()) { - for (String moduleId : applicationModules) { - AppModuleResource appModuleResource = new AppModuleResource(); - moduleMappingResource = new AppModuleMappingResource(); - ids = new HashMap<String, String>(); - ids.put(AbstractResource.AppModuleMappingConstants.MODULE_ID, moduleId); - ids.put(AbstractResource.AppModuleMappingConstants.INTERFACE_ID, interfaceId); - AppModuleMappingResource existingMapping; - if (!moduleMappingResource.isExists(ids)) { - existingMapping = new AppModuleMappingResource(); - } else { - existingMapping = (AppModuleMappingResource) moduleMappingResource.get(ids); - } - existingMapping.setInterfaceId(interfaceId); - existingMapping.setModuleId(moduleId); - existingMapping.setModuleResource((AppModuleResource) appModuleResource.get(moduleId)); - existingMapping.setAppInterfaceResource(existingInterface); - existingMapping.save(); - } - } - - // remove existing application inputs - ApplicationInputResource inputResource = new ApplicationInputResource(); - ids = new HashMap<String, String>(); - ids.put(AbstractResource.AppInputConstants.INTERFACE_ID, interfaceId); - inputResource.remove(ids); - List<InputDataObjectType> applicationInputs = updatedInterface.getApplicationInputs(); - if (applicationInputs != null && !applicationInputs.isEmpty()) { - for (InputDataObjectType input : applicationInputs) { - inputResource = new ApplicationInputResource(); - ids = new HashMap<String, String>(); - ids.put(AbstractResource.AppInputConstants.INTERFACE_ID, interfaceId); - ids.put(AbstractResource.AppInputConstants.INPUT_KEY, input.getName()); - if (inputResource.isExists(ids)) { - inputResource = (ApplicationInputResource) inputResource.get(ids); - } - inputResource.setAppInterfaceResource(existingInterface); - inputResource.setInterfaceID(interfaceId); - inputResource.setUserFriendlyDesc(input.getUserFriendlyDescription()); - inputResource.setInputKey(input.getName()); - inputResource.setInputVal(input.getValue()); - inputResource.setDataType(input.getType().toString()); - inputResource.setMetadata(input.getMetaData()); - inputResource.setStandardInput(input.isStandardInput()); - inputResource.setAppArgument(input.getApplicationArgument()); - inputResource.setInputOrder(input.getInputOrder()); - inputResource.setRequired(input.isIsRequired()); - inputResource.setRequiredToCMD(input.isRequiredToAddedToCommandLine()); - inputResource.save(); - } - } - - // remove existing app outputs before adding - ApplicationOutputResource outputResource = new ApplicationOutputResource(); - ids = new HashMap<String, String>(); - ids.put(AbstractResource.AppOutputConstants.INTERFACE_ID, interfaceId); - outputResource.remove(ids); - List<OutputDataObjectType> applicationOutputs = updatedInterface.getApplicationOutputs(); - if (applicationOutputs != null && !applicationOutputs.isEmpty()) { - for (OutputDataObjectType output : applicationOutputs) { - outputResource = new ApplicationOutputResource(); - ids = new HashMap<String, String>(); - ids.put(AbstractResource.AppOutputConstants.INTERFACE_ID, interfaceId); - ids.put(AbstractResource.AppOutputConstants.OUTPUT_KEY, output.getName()); - if (outputResource.isExists(ids)) { - outputResource = (ApplicationOutputResource) outputResource.get(ids); - } - outputResource.setInterfaceID(interfaceId); - outputResource.setAppInterfaceResource(existingInterface); - outputResource.setOutputKey(output.getName()); - outputResource.setOutputVal(output.getValue()); - outputResource.setDataType(output.getType().toString()); - outputResource.setRequired(output.isIsRequired()); - outputResource.setRequiredToCMD(output.isRequiredToAddedToCommandLine()); - outputResource.setDataMovement(output.isDataMovement()); - outputResource.setDataNameLocation(output.getLocation()); - outputResource.setAppArgument(output.getApplicationArgument()); - outputResource.setSearchQuery(output.getSearchQuery()); - outputResource.save(); - } - } - } catch (Exception e) { - logger.error("Error while updating application interface " + interfaceId, e); - throw new AppCatalogException(e); - } - } - - @Override - public ApplicationModule getApplicationModule(String moduleId) throws AppCatalogException { - try { - AppModuleResource appModuleResource = new AppModuleResource(); - return AppCatalogThriftConversion.getApplicationModuleDesc((AppModuleResource) appModuleResource.get(moduleId)); - }catch (Exception e) { - logger.error("Error while retrieving application module "+moduleId, e); - throw new AppCatalogException(e); - } - } - - @Override - public ApplicationInterfaceDescription getApplicationInterface(String interfaceId) throws AppCatalogException { - try { - AppInterfaceResource interfaceResource = new AppInterfaceResource(); - return AppCatalogThriftConversion.getApplicationInterfaceDescription((AppInterfaceResource)interfaceResource.get(interfaceId)); - }catch (Exception e) { - logger.error("Error while retrieving application interface '"+interfaceId, e); - throw new AppCatalogException(e); - } - } - - @Override - public List<ApplicationModule> getApplicationModules(Map<String, String> filters) throws AppCatalogException { - List<ApplicationModule> modules = new ArrayList<ApplicationModule>(); - try { - AppModuleResource resource = new AppModuleResource(); - for (String fieldName : filters.keySet() ){ - if (fieldName.equals(AbstractResource.ApplicationModuleConstants.MODULE_NAME)){ - List<Resource> resources = resource.get(AbstractResource.ApplicationModuleConstants.MODULE_NAME, filters.get(fieldName)); - if (resources != null && !resources.isEmpty()){ - modules = AppCatalogThriftConversion.getAppModules(resources); - } - }else { - logger.error("Unsupported field name for app module.", new IllegalArgumentException()); - throw new IllegalArgumentException("Unsupported field name for app module."); - } - } - }catch (Exception e){ - logger.error("Error while retrieving app module list...", e); - throw new AppCatalogException(e); - } - return modules; - } - - @Override - public List<ApplicationModule> getAllApplicationModules(String gatewayId) throws AppCatalogException { - List<ApplicationModule> applicationModules = new ArrayList<ApplicationModule>(); - try { - AppModuleResource resource = new AppModuleResource(); - resource.setGatewayId(gatewayId); - List<Resource> resources = resource.getAll(); - if (resources != null && !resources.isEmpty()){ - applicationModules = AppCatalogThriftConversion.getAppModules(resources); - } - }catch (Exception e){ - logger.error("Error while retrieving compute resource list...", e); - throw new AppCatalogException(e); - } - return applicationModules; - } - - @Override - public List<ApplicationInterfaceDescription> getApplicationInterfaces(Map<String, String> filters) throws AppCatalogException { - List<ApplicationInterfaceDescription> appInterfaces = new ArrayList<ApplicationInterfaceDescription>(); - try { - AppInterfaceResource resource = new AppInterfaceResource(); - for (String fieldName : filters.keySet() ){ - if (fieldName.equals(AbstractResource.ApplicationInterfaceConstants.APPLICATION_NAME)){ - List<Resource> resources = resource.get(AbstractResource.ApplicationInterfaceConstants.APPLICATION_NAME, filters.get(fieldName)); - appInterfaces = AppCatalogThriftConversion.getAppInterfaceDescList(resources); - }else { - logger.error("Unsupported field name for app interface.", new IllegalArgumentException()); - throw new IllegalArgumentException("Unsupported field name '"+fieldName+"' for app interface."); - } - } - }catch (Exception e){ - logger.error("Error while retrieving app interface list...", e); - throw new AppCatalogException(e); - } - return appInterfaces; - } - - @Override - public List<ApplicationInterfaceDescription> getAllApplicationInterfaces(String gatewayId) throws AppCatalogException { - try { - AppInterfaceResource resource = new AppInterfaceResource(); - resource.setGatewayId(gatewayId); - List<Resource> resources = resource.getAll(); - return AppCatalogThriftConversion.getAppInterfaceDescList(resources); - }catch (Exception e){ - logger.error("Error while retrieving app interface list...", e); - throw new AppCatalogException(e); - } - } - - @Override - public List<String> getAllApplicationInterfaceIds() throws AppCatalogException { - try { - AppInterfaceResource resource = new AppInterfaceResource(); - return resource.getAllIds(); - }catch (Exception e){ - logger.error("Error while retrieving app interface list...", e); - throw new AppCatalogException(e); - } - } - - @Override - public boolean removeApplicationInterface(String interfaceId) throws AppCatalogException { - try { - AppInterfaceResource resource = new AppInterfaceResource(); - resource.remove(interfaceId); - return true; - }catch (Exception e){ - logger.error("Error while removing app interface "+interfaceId, e); - throw new AppCatalogException(e); - } - } - - @Override - public boolean removeApplicationModule(String moduleId) throws AppCatalogException { - try { - AppModuleResource resource = new AppModuleResource(); - resource.remove(moduleId); - return true; - }catch (Exception e){ - logger.error("Error while removing app module "+moduleId, e); - throw new AppCatalogException(e); - } - } - - @Override - public boolean isApplicationInterfaceExists(String interfaceId) throws AppCatalogException { - try { - AppInterfaceResource resource = new AppInterfaceResource(); - return resource.isExists(interfaceId); - }catch (Exception e){ - logger.error("Error while checking app interface existence "+interfaceId, e); - throw new AppCatalogException(e); - } - } - - @Override - public boolean isApplicationModuleExists(String moduleId) throws AppCatalogException { - try { - AppModuleResource resource = new AppModuleResource(); - return resource.isExists(moduleId); - }catch (Exception e){ - logger.error("Error while checking app module existence "+moduleId, e); - throw new AppCatalogException(e); - } - } - - @Override - public List<InputDataObjectType> getApplicationInputs(String interfaceId) throws AppCatalogException { - try { - ApplicationInputResource resource = new ApplicationInputResource(); - List<Resource> resources = resource.get(AbstractResource.AppInputConstants.INTERFACE_ID, interfaceId); - return AppCatalogThriftConversion.getAppInputs(resources); - }catch (Exception e){ - logger.error("Error while retrieving app inputs for application "+interfaceId, e); - throw new AppCatalogException(e); - } - } - - @Override - public List<OutputDataObjectType> getApplicationOutputs(String interfaceId) throws AppCatalogException { - try { - ApplicationOutputResource resource = new ApplicationOutputResource(); - List<Resource> resources = resource.get(AbstractResource.AppOutputConstants.INTERFACE_ID, interfaceId); - return AppCatalogThriftConversion.getAppOutputs(resources); - }catch (Exception e){ - logger.error("Error while retrieving app outputs for application "+interfaceId, e); - throw new AppCatalogException(e); - } - } -}
http://git-wip-us.apache.org/repos/asf/airavata/blob/ec8c6202/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/ComputeResourceImpl.java ---------------------------------------------------------------------- diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/ComputeResourceImpl.java b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/ComputeResourceImpl.java deleted file mode 100644 index 11ba727..0000000 --- a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/ComputeResourceImpl.java +++ /dev/null @@ -1,888 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -package org.apache.aiaravata.application.catalog.data.impl; - -import java.util.*; - -import org.airavata.appcatalog.cpi.AppCatalogException; -import org.airavata.appcatalog.cpi.ComputeResource; -import org.apache.aiaravata.application.catalog.data.resources.*; -import org.apache.aiaravata.application.catalog.data.util.AppCatalogThriftConversion; -import org.apache.aiaravata.application.catalog.data.util.AppCatalogUtils; -import org.apache.airavata.model.appcatalog.computeresource.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ComputeResourceImpl implements ComputeResource { - private final static Logger logger = LoggerFactory.getLogger(ComputeResourceImpl.class); - - @Override - public String addComputeResource(ComputeResourceDescription description) throws AppCatalogException { - try { - if (description.getComputeResourceId().equals("") || description.getComputeResourceId().equals(computeResourceModelConstants.DEFAULT_ID)){ - description.setComputeResourceId(AppCatalogUtils.getID(description.getHostName())); - } - return saveComputeResourceDescriptorData(description); - } catch (Exception e) { - logger.error("Error while saving compute resource...", e); - throw new AppCatalogException(e); - } - } - - protected String saveComputeResourceDescriptorData( - ComputeResourceDescription description) throws AppCatalogException { - //TODO remove existing one - ComputeResourceResource computeHostResource = saveComputeResource(description); - saveHostAliases(description, computeHostResource); - saveIpAddresses(description, computeHostResource); - saveBatchQueues(description, computeHostResource); - saveFileSystems(description, computeHostResource); - saveJobSubmissionInterfaces(description, computeHostResource); - saveDataMovementInterfaces(description, computeHostResource); - return computeHostResource.getResourceId(); - } - - protected ComputeResourceResource saveComputeResource( - ComputeResourceDescription description) throws AppCatalogException { - ComputeResourceResource computeHostResource = AppCatalogThriftConversion.getComputeHostResource(description); - computeHostResource.save(); - return computeHostResource; - } - - protected void saveDataMovementInterfaces( - ComputeResourceDescription description, - ComputeResourceResource computeHostResource) - throws AppCatalogException { - List<DataMovementInterface> dataMovemenetInterfaces = description.getDataMovementInterfaces(); - if (dataMovemenetInterfaces != null && !dataMovemenetInterfaces.isEmpty()) { - for (DataMovementInterface dataMovementInterface : dataMovemenetInterfaces) { - DataMovementInterfaceResource dmir = AppCatalogThriftConversion.getDataMovementInterface(dataMovementInterface); - dmir.setComputeHostResource(computeHostResource); - dmir.setComputeResourceId(computeHostResource.getResourceId()); - dmir.save(); - } - } - } - - protected void saveJobSubmissionInterfaces( - ComputeResourceDescription description, - ComputeResourceResource computeHostResource) - throws AppCatalogException { - List<JobSubmissionInterface> jobSubmissionInterfaces = description.getJobSubmissionInterfaces(); - if (jobSubmissionInterfaces != null && !jobSubmissionInterfaces.isEmpty()) { - for (JobSubmissionInterface jobSubmissionInterface : jobSubmissionInterfaces) { - JobSubmissionInterfaceResource jsir = AppCatalogThriftConversion.getJobSubmissionInterface(jobSubmissionInterface); - jsir.setComputeHostResource(computeHostResource); - jsir.setComputeResourceId(computeHostResource.getResourceId()); - jsir.save(); - } - } - } - - protected void saveFileSystems(ComputeResourceDescription description, - ComputeResourceResource computeHostResource) - throws AppCatalogException { - Map<FileSystems, String> fileSystems = description.getFileSystems(); - if (fileSystems != null && !fileSystems.isEmpty()) { - for (FileSystems key : fileSystems.keySet()) { - ComputeResourceFileSystemResource computeResourceFileSystemResource = new ComputeResourceFileSystemResource(); - computeResourceFileSystemResource.setComputeHostResource(computeHostResource); - computeResourceFileSystemResource.setComputeResourceId(computeHostResource.getResourceId()); - computeResourceFileSystemResource.setFileSystem(key.toString()); - computeResourceFileSystemResource.setPath(fileSystems.get(key)); - computeResourceFileSystemResource.save(); - } - } - } - - protected void saveBatchQueues(ComputeResourceDescription description, - ComputeResourceResource computeHostResource) - throws AppCatalogException { - List<BatchQueue> batchQueueList = description.getBatchQueues(); - if (batchQueueList != null && !batchQueueList.isEmpty()) { - for (BatchQueue batchQueue : batchQueueList) { - BatchQueueResource bq = AppCatalogThriftConversion.getBatchQueue(batchQueue); - bq.setComputeResourceId(computeHostResource.getResourceId()); - bq.setComputeHostResource(computeHostResource); - bq.save(); - } - } - } - - protected void saveIpAddresses(ComputeResourceDescription description, - ComputeResourceResource computeHostResource) - throws AppCatalogException { - List<String> ipAddresses = description.getIpAddresses(); - HostIPAddressResource resource = new HostIPAddressResource(); - resource.remove(description.getComputeResourceId()); - if (ipAddresses != null && !ipAddresses.isEmpty()) { - for (String ipAddress : ipAddresses) { - HostIPAddressResource ipAddressResource = new HostIPAddressResource(); - ipAddressResource.setComputeHostResource(computeHostResource); - ipAddressResource.setResourceID(computeHostResource.getResourceId()); - ipAddressResource.setIpaddress(ipAddress); - ipAddressResource.save(); - } - } - } - - protected void saveHostAliases(ComputeResourceDescription description, - ComputeResourceResource computeHostResource) - throws AppCatalogException { - List<String> hostAliases = description.getHostAliases(); - // delete previous host aliases - HostAliasResource resource = new HostAliasResource(); - resource.remove(description.getComputeResourceId()); - if (hostAliases != null && !hostAliases.isEmpty()) { - for (String alias : hostAliases) { - HostAliasResource aliasResource = new HostAliasResource(); - aliasResource.setComputeHostResource(computeHostResource); - aliasResource.setResourceID(computeHostResource.getResourceId()); - aliasResource.setAlias(alias); - aliasResource.save(); - } - } - } - - @Override - public void updateComputeResource(String computeResourceId, ComputeResourceDescription updatedComputeResource) throws AppCatalogException{ - try { - saveComputeResourceDescriptorData(updatedComputeResource); - } catch (Exception e) { - logger.error("Error while updating compute resource...", e); - throw new AppCatalogException(e); - } - } - - @Override - public String addSSHJobSubmission(SSHJobSubmission sshJobSubmission) throws AppCatalogException { - try { - String submissionId = AppCatalogUtils.getID("SSH"); - sshJobSubmission.setJobSubmissionInterfaceId(submissionId); - String resourceJobManagerId = addResourceJobManager(sshJobSubmission.getResourceJobManager()); - SshJobSubmissionResource resource = AppCatalogThriftConversion.getSSHJobSubmission(sshJobSubmission); - resource.setResourceJobManagerId(resourceJobManagerId); - resource.getResourceJobManagerResource().setResourceJobManagerId(resourceJobManagerId); - if (sshJobSubmission.getMonitorMode() != null){ - resource.setMonitorMode(sshJobSubmission.getMonitorMode().toString()); - } - resource.save(); - return submissionId; - }catch (Exception e) { - logger.error("Error while saving SSH Job Submission...", e); - throw new AppCatalogException(e); - } - } - - @Override - public String addCloudJobSubmission(CloudJobSubmission sshJobSubmission) throws AppCatalogException { - try { - sshJobSubmission.setJobSubmissionInterfaceId(AppCatalogUtils.getID("Cloud")); - CloudSubmissionResource resource = AppCatalogThriftConversion.getCloudJobSubmission(sshJobSubmission); - resource.save(); - return resource.getJobSubmissionInterfaceId(); - }catch (Exception e) { - logger.error("Error while saving SSH Job Submission...", e); - throw new AppCatalogException(e); - } - } - - @Override - public String addUNICOREJobSubmission(UnicoreJobSubmission unicoreJobSubmission) - throws AppCatalogException { - try { - unicoreJobSubmission.setJobSubmissionInterfaceId(AppCatalogUtils.getID("UNICORE")); - UnicoreJobSubmissionResource resource = AppCatalogThriftConversion.getUnicoreJobSubmission(unicoreJobSubmission); - resource.setUnicoreEndpointUrl(unicoreJobSubmission.getUnicoreEndPointURL()); - if (unicoreJobSubmission.getSecurityProtocol() != null){ - resource.setSecurityProtocol(unicoreJobSubmission.getSecurityProtocol().toString()); - } - resource.save(); - return resource.getjobSubmissionInterfaceId(); - }catch (Exception e){ - logger.error("Error while retrieving SSH Job Submission...", e); - throw new AppCatalogException(e); - } - - } - - @Override - public String addJobSubmissionProtocol(String computeResourceId, JobSubmissionInterface jobSubmissionInterface) throws AppCatalogException { - try { - JobSubmissionInterfaceResource jsi = AppCatalogThriftConversion.getJobSubmissionInterface(jobSubmissionInterface); - jsi.setComputeResourceId(computeResourceId); - ComputeResourceResource computeResourceResource = new ComputeResourceResource(); - computeResourceResource=(ComputeResourceResource)computeResourceResource.get(computeResourceId); - jsi.setComputeHostResource(computeResourceResource); - jsi.save(); - return jsi.getJobSubmissionInterfaceId(); - }catch (Exception e){ - logger.error("Error while saving "+jobSubmissionInterface.getJobSubmissionProtocol().toString()+" Job Submission Protocol...", e); - throw new AppCatalogException(e); - } - } - -// @Override -// public String addGSISSHJobSubmission(GSISSHJobSubmission gsisshJobSubmission) throws AppCatalogException { -// try { -// GSISSHSubmissionResource resource = new GSISSHSubmissionResource(); -// String hostName = "GSISSH"; -// resource.setDeploymentId(AppCatalogUtils.getID(hostName)); -// resource.setSshPort(resource.getSshPort()); -// resource.setResourceJobManager(gsisshJobSubmission.getResourceJobManager().toString()); -// resource.setInstalledPath(gsisshJobSubmission.getInstalledPath()); -// resource.setMonitorMode(gsisshJobSubmission.getMonitorMode()); -// resource.save(); -// gsisshJobSubmission.setJobSubmissionDataID(resource.getDeploymentId()); -// -// Set<String> exports = gsisshJobSubmission.getExports(); -// if (exports != null && !exports.isEmpty()){ -// for (String export : exports){ -// GSISSHExportResource exportResource = new GSISSHExportResource(); -// exportResource.setDeploymentId(resource.getDeploymentId()); -// exportResource.setExport(export); -// exportResource.setAppDeploymentResource(resource); -// exportResource.save(); -// } -// } -// -// List<String> preJobCommands = gsisshJobSubmission.getPreJobCommands(); -// if (preJobCommands != null && !preJobCommands.isEmpty()){ -// for (String command : preJobCommands){ -// GSISSHPreJobCommandResource commandResource = new GSISSHPreJobCommandResource(); -// commandResource.setDeploymentId(resource.getDeploymentId()); -// commandResource.setCommand(command); -// commandResource.setAppDeploymentResource(resource); -// commandResource.save(); -// } -// } -// -// List<String> postJobCommands = gsisshJobSubmission.getPostJobCommands(); -// if (postJobCommands != null && !postJobCommands.isEmpty()){ -// for (String command : postJobCommands){ -// GSISSHPostJobCommandResource commandResource = new GSISSHPostJobCommandResource(); -// commandResource.setDeploymentId(resource.getDeploymentId()); -// commandResource.setCommand(command); -// commandResource.setAppDeploymentResource(resource); -// commandResource.save(); -// } -// } -// return resource.getDeploymentId(); -// }catch (Exception e) { -// logger.error("Error while saving GSISSH Job Submission...", e); -// throw new AppCatalogException(e); -// } -// } -// -// @Override -// public void addGSISSHJobSubmissionProtocol(String computeResourceId, String jobSubmissionId) throws AppCatalogException { -// try { -// JobSubmissionProtocolResource resource = new JobSubmissionProtocolResource(); -// resource.setResourceID(computeResourceId); -// resource.setDeploymentId(jobSubmissionId); -// ComputeResourceDescription computeResource = getComputeResource(computeResourceId); -// resource.setComputeHostResource(AppCatalogThriftConversion.getComputeHostResource(computeResource)); -// resource.setJobType(JobSubmissionProtocol.GSISSH.toString()); -// resource.save(); -// }catch (Exception e){ -// logger.error("Error while saving GSISSH Job Submission Protocol...", e); -// throw new AppCatalogException(e); -// } -// } - - @Override - public String addGlobusJobSubmission(GlobusJobSubmission globusJobSubmission) throws AppCatalogException { -// try { -// GlobusJobSubmissionResource resource = new GlobusJobSubmissionResource(); -// String hostName = "GLOBUS"; -// resource.setDeploymentId(AppCatalogUtils.getID(hostName)); -// resource.setSecurityProtocol(globusJobSubmission.getSecurityProtocol().toString()); -// resource.setResourceJobManager(globusJobSubmission.getResourceJobManager().toString()); -// resource.save(); -// globusJobSubmission.setJobSubmissionDataID(resource.getDeploymentId()); -// List<String> globusGateKeeperEndPoint = globusJobSubmission.getGlobusGateKeeperEndPoint(); -// if (globusGateKeeperEndPoint != null && !globusGateKeeperEndPoint.isEmpty()) { -// for (String endpoint : globusGateKeeperEndPoint) { -// GlobusGKEndpointResource endpointResource = new GlobusGKEndpointResource(); -// endpointResource.setDeploymentId(resource.getDeploymentId()); -// endpointResource.setEndpoint(endpoint); -// endpointResource.setGlobusJobSubmissionResource(resource); -// endpointResource.save(); -// } -// } -// return resource.getDeploymentId(); -// } catch (Exception e) { -// logger.error("Error while saving Globus Job Submission...", e); -// throw new AppCatalogException(e); -// } - return null; - } - - @Override - public String addScpDataMovement(SCPDataMovement scpDataMovement) throws AppCatalogException { - try { - scpDataMovement.setDataMovementInterfaceId(AppCatalogUtils.getID("SCP")); - ScpDataMovementResource resource = AppCatalogThriftConversion.getSCPDataMovementDescription(scpDataMovement); - resource.save(); - return resource.getDataMovementInterfaceId(); - }catch (Exception e){ - logger.error("Error while saving SCP Data Movement...", e); - throw new AppCatalogException(e); - } - } - - @Override - public String addUnicoreDataMovement(UnicoreDataMovement unicoreDataMovement) throws AppCatalogException { - try { - unicoreDataMovement.setDataMovementInterfaceId(AppCatalogUtils.getID("UNICORE")); - UnicoreDataMovementResource resource = AppCatalogThriftConversion.getUnicoreDMResource(unicoreDataMovement); - resource.save(); - return resource.getDataMovementId(); - }catch (Exception e){ - logger.error("Error while saving UNICORE Data Movement...", e); - throw new AppCatalogException(e); - } - } - - @Override - public String addDataMovementProtocol(String computeResourceId, DataMovementInterface dataMovementInterface) throws AppCatalogException { - try { - DataMovementInterfaceResource dmi = AppCatalogThriftConversion.getDataMovementInterface(dataMovementInterface); - dmi.setComputeResourceId(computeResourceId); - ComputeResourceResource computeResourceResource = new ComputeResourceResource(); - computeResourceResource=(ComputeResourceResource)computeResourceResource.get(computeResourceId); - dmi.setComputeHostResource(computeResourceResource); - dmi.save(); - return dmi.getDataMovementInterfaceId(); - }catch (Exception e){ - logger.error("Error while saving "+dataMovementInterface.getDataMovementProtocol().toString()+" data movement Protocol...", e); - throw new AppCatalogException(e); - } - } - - @Override - public String addGridFTPDataMovement(GridFTPDataMovement gridFTPDataMovement) throws AppCatalogException { - try { - gridFTPDataMovement.setDataMovementInterfaceId(AppCatalogUtils.getID("GRIDFTP")); - GridftpDataMovementResource resource = AppCatalogThriftConversion.getGridFTPDataMovementDescription(gridFTPDataMovement); - resource.save(); - List<String> gridFTPEndPoint = gridFTPDataMovement.getGridFTPEndPoints(); - if (gridFTPEndPoint != null && !gridFTPEndPoint.isEmpty()) { - for (String endpoint : gridFTPEndPoint) { - GridftpEndpointResource endpointResource = new GridftpEndpointResource(); - endpointResource.setDataMovementInterfaceId(resource.getDataMovementInterfaceId()); - endpointResource.setEndpoint(endpoint); - endpointResource.setGridftpDataMovementResource(resource); - endpointResource.save(); - } - } - return resource.getDataMovementInterfaceId(); - }catch (Exception e){ - logger.error("Error while saving GridFTP Data Movement...", e); - throw new AppCatalogException(e); - } - } - - @Override - public ComputeResourceDescription getComputeResource(String resourceId) throws AppCatalogException { - try { - ComputeResourceResource resource = new ComputeResourceResource(); - ComputeResourceResource computeResource = (ComputeResourceResource)resource.get(resourceId); - return AppCatalogThriftConversion.getComputeHostDescription(computeResource); - }catch (Exception e){ - logger.error("Error while retrieving compute resource...", e); - throw new AppCatalogException(e); - } - } - - @Override - public List<ComputeResourceDescription> getComputeResourceList(Map<String, String> filters) throws AppCatalogException { - List<ComputeResourceDescription> computeResourceDescriptions = new ArrayList<ComputeResourceDescription>(); - try { - //TODO check if this is correct way to do this - ComputeResourceResource resource = new ComputeResourceResource(); - for (String fieldName : filters.keySet() ){ - if (fieldName.equals(AbstractResource.ComputeResourceConstants.HOST_NAME)){ - List<Resource> resources = resource.get(AbstractResource.ComputeResourceConstants.HOST_NAME, filters.get(fieldName)); - if (resources != null && !resources.isEmpty()){ - computeResourceDescriptions = AppCatalogThriftConversion.getComputeDescriptionList(resources); - } - }else { - logger.error("Unsupported field name for compute resource.", new IllegalArgumentException()); - throw new IllegalArgumentException("Unsupported field name for compute resource."); - } - } - }catch (Exception e){ - logger.error("Error while retrieving compute resource list...", e); - throw new AppCatalogException(e); - } - return computeResourceDescriptions; - } - - @Override - public List<ComputeResourceDescription> getAllComputeResourceList() throws AppCatalogException { - List<ComputeResourceDescription> computeResourceDescriptions = new ArrayList<ComputeResourceDescription>(); - try { - ComputeResourceResource resource = new ComputeResourceResource(); - List<Resource> resources = resource.getAll(); - if (resources != null && !resources.isEmpty()){ - computeResourceDescriptions = AppCatalogThriftConversion.getComputeDescriptionList(resources); - } - }catch (Exception e){ - logger.error("Error while retrieving compute resource list...", e); - throw new AppCatalogException(e); - } - return computeResourceDescriptions; - } - - @Override - public Map<String, String> getAllComputeResourceIdList() throws AppCatalogException { - try { - Map<String, String> computeResourceMap = new HashMap<String, String>(); - ComputeResourceResource resource = new ComputeResourceResource(); - List<Resource> allComputeResources = resource.getAll(); - if (allComputeResources != null && !allComputeResources.isEmpty()){ - for (Resource cm : allComputeResources){ - ComputeResourceResource cmr = (ComputeResourceResource)cm; - computeResourceMap.put(cmr.getResourceId(), cmr.getHostName()); - } - } - return computeResourceMap; - }catch (Exception e){ - logger.error("Error while retrieving compute resource list...", e); - throw new AppCatalogException(e); - } - } - -// @Override -// public GSISSHJobSubmission getGSISSHJobSubmission(String submissionId) throws AppCatalogException { -// try { -// GSISSHSubmissionResource resource = new GSISSHSubmissionResource(); -// GSISSHSubmissionResource submissionResource = (GSISSHSubmissionResource)resource.get(submissionId); -// return AppCatalogThriftConversion.getGSISSHSubmissionDescription(submissionResource); -// }catch (Exception e){ -// logger.error("Error while retrieving GSISSH Job Submission...", e); -// throw new AppCatalogException(e); -// } -// } -// -// @Override -// public List<GSISSHJobSubmission> getGSISSHJobSubmissionList(Map<String, String> filters) throws AppCatalogException { -// try { -// GSISSHSubmissionResource resource = new GSISSHSubmissionResource(); -// for (String fieldName : filters.keySet() ){ -// if (fieldName.equals(AbstractResource.GSISSHSubmissionConstants.RESOURCE_JOB_MANAGER)){ -// List<Resource> resources = resource.get(AbstractResource.GSISSHSubmissionConstants.RESOURCE_JOB_MANAGER, filters.get(fieldName)); -// if (resources != null && !resources.isEmpty()){ -// return AppCatalogThriftConversion.getGSISSHSubmissionList(resources); -// } -// }else { -// logger.error("Unsupported field name for GSISSH Submission.", new IllegalArgumentException()); -// throw new IllegalArgumentException("Unsupported field name for GSISSH Submission."); -// } -// } -// }catch (Exception e){ -// logger.error("Error while retrieving GSISSH Submission list...", e); -// throw new AppCatalogException(e); -// } -// return null; -// } -// -// @Override -// public GlobusJobSubmission getGlobusJobSubmission(String submissionId) throws AppCatalogException { -// try { -// GlobusJobSubmissionResource globusJobSubmissionResource = new GlobusJobSubmissionResource(); -// globusJobSubmissionResource=(GlobusJobSubmissionResource)globusJobSubmissionResource.get(submissionId); -// AppCatalogThriftConversion.getglo -// GlobusJobSubmissionResource resource = globusJobSubmissionResource; -// GlobusJobSubmissionResource submissionResource = (GlobusJobSubmissionResource)resource.get(submissionId); -// return AppCatalogThriftConversion.getGlobusJobSubmissionDescription(submissionResource); -// }catch (Exception e){ -// logger.error("Error while retrieving Globus Job Submission...", e); -// throw new AppCatalogException(e); -// } -// } -// -// @Override -// public List<GlobusJobSubmission> getGlobusJobSubmissionList(Map<String, String> filters) throws AppCatalogException { -// try { -// GlobusJobSubmissionResource resource = new GlobusJobSubmissionResource(); -// for (String fieldName : filters.keySet() ){ -// if (fieldName.equals(AbstractResource.GlobusJobSubmissionConstants.RESOURCE_JOB_MANAGER)){ -// List<Resource> resources = resource.get(AbstractResource.GlobusJobSubmissionConstants.RESOURCE_JOB_MANAGER, filters.get(fieldName)); -// if (resources != null && !resources.isEmpty()){ -// return AppCatalogThriftConversion.getGlobusSubmissionList(resources); -// } -// }else if (fieldName.equals(AbstractResource.GlobusJobSubmissionConstants.SECURITY_PROTOCAL)){ -// List<Resource> resources = resource.get(AbstractResource.GlobusJobSubmissionConstants.SECURITY_PROTOCAL, filters.get(fieldName)); -// if (resources != null && !resources.isEmpty()){ -// return AppCatalogThriftConversion.getGlobusSubmissionList(resources); -// } -// }else { -// logger.error("Unsupported field name for Globus Submission.", new IllegalArgumentException()); -// throw new IllegalArgumentException("Unsupported field name for Globus Submission."); -// } -// } -// }catch (Exception e){ -// logger.error("Error while retrieving Globus Submission list...", e); -// throw new AppCatalogException(e); -// } -// return null; -// } - - @Override - public SSHJobSubmission getSSHJobSubmission(String submissionId) throws AppCatalogException { - try { - SshJobSubmissionResource resource = new SshJobSubmissionResource(); - resource = (SshJobSubmissionResource)resource.get(submissionId); - return AppCatalogThriftConversion.getSSHJobSubmissionDescription(resource); - }catch (Exception e){ - logger.error("Error while retrieving SSH Job Submission...", e); - throw new AppCatalogException(e); - } - } - - // @Override - // public List<GridFTPDataMovement> getGridFTPDataMovementList(Map<String, String> filters) throws AppCatalogException { - // try { - // GridftpDataMovementResource resource = new GridftpDataMovementResource(); - // for (String fieldName : filters.keySet() ){ - // if (fieldName.equals(AbstractResource.GridFTPDataMovementConstants.SECURITY_PROTOCOL)){ - // List<Resource> resources = resource.get(AbstractResource.GridFTPDataMovementConstants.SECURITY_PROTOCOL, filters.get(fieldName)); - // if (resources != null && !resources.isEmpty()){ - // return AppCatalogThriftConversion.getGridFTPDataMovementList(resources); - // } - // }else { - // logger.error("Unsupported field name for GridFTP Data movement.", new IllegalArgumentException()); - // throw new IllegalArgumentException("Unsupported field name for GridFTP Data movement."); - // } - // } - // }catch (Exception e){ - // logger.error("Error while retrieving GridFTP Data movement list...", e); - // throw new AppCatalogException(e); - // } - // return null; - // } - - @Override - public UnicoreJobSubmission getUNICOREJobSubmission(String submissionId) - throws AppCatalogException { - try { - UnicoreJobSubmissionResource resource = new UnicoreJobSubmissionResource(); - resource = (UnicoreJobSubmissionResource)resource.get(submissionId); - return AppCatalogThriftConversion.getUnicoreJobSubmissionDescription(resource); - }catch (Exception e){ - logger.error("Error while retrieving UNICORE Job Submission model instance...", e); - throw new AppCatalogException(e); - } - } - - @Override - public UnicoreDataMovement getUNICOREDataMovement(String dataMovementId) - throws AppCatalogException { - try { - UnicoreDataMovementResource resource = new UnicoreDataMovementResource(); - resource = (UnicoreDataMovementResource)resource.get(dataMovementId); - return AppCatalogThriftConversion.getUnicoreDMDescription(resource); - }catch (Exception e){ - logger.error("Error while retrieving UNICORE data movement...", e); - throw new AppCatalogException(e); - } - } - - @Override - public CloudJobSubmission getCloudJobSubmission(String submissionId) throws AppCatalogException { - try { - CloudSubmissionResource resource = new CloudSubmissionResource(); - resource = (CloudSubmissionResource)resource.get(submissionId); - return AppCatalogThriftConversion.getCloudJobSubmissionDescription(resource); - }catch (Exception e){ - logger.error("Error while retrieving SSH Job Submission...", e); - throw new AppCatalogException(e); - } - } -// -// @Override -// public List<SSHJobSubmission> getSSHJobSubmissionList(Map<String, String> filters) throws AppCatalogException { -// try { -// SshJobSubmissionResource resource = new SshJobSubmissionResource(); -// for (String fieldName : filters.keySet() ){ -// if (fieldName.equals(AbstractResource.SSHSubmissionConstants.RESOURCE_JOB_MANAGER)){ -// List<Resource> resources = resource.get(AbstractResource.SSHSubmissionConstants.RESOURCE_JOB_MANAGER, filters.get(fieldName)); -// if (resources != null && !resources.isEmpty()){ -// return AppCatalogThriftConversion.getSSHSubmissionList(resources); -// } -// }else { -// logger.error("Unsupported field name for SSH Submission.", new IllegalArgumentException()); -// throw new IllegalArgumentException("Unsupported field name for SSH Submission."); -// } -// } -// }catch (Exception e){ -// logger.error("Error while retrieving SSH Submission list...", e); -// throw new AppCatalogException(e); -// } -// return null; -// } - - @Override - public SCPDataMovement getSCPDataMovement(String dataMoveId) throws AppCatalogException { - try { - ScpDataMovementResource resource = new ScpDataMovementResource(); - ScpDataMovementResource dataMovementResource = (ScpDataMovementResource)resource.get(dataMoveId); - return AppCatalogThriftConversion.getSCPDataMovementDescription(dataMovementResource); - }catch (Exception e){ - logger.error("Error while retrieving SCP Data Movement...", e); - throw new AppCatalogException(e); - } - } - -// @Override -// public List<SCPDataMovement> getSCPDataMovementList(Map<String, String> filters) throws AppCatalogException { -// try { -// ScpDataMovementResource resource = new ScpDataMovementResource(); -// for (String fieldName : filters.keySet() ){ -// if (fieldName.equals(AbstractResource.SCPDataMovementConstants.SECURITY_PROTOCOL)){ -// List<Resource> resources = resource.get(AbstractResource.SCPDataMovementConstants.SECURITY_PROTOCOL, filters.get(fieldName)); -// if (resources != null && !resources.isEmpty()){ -// return AppCatalogThriftConversion.getSCPDataMovementList(resources); -// } -// }else { -// logger.error("Unsupported field name for SCP Data movement.", new IllegalArgumentException()); -// throw new IllegalArgumentException("Unsupported field name for SCP Data movement."); -// } -// } -// }catch (Exception e){ -// logger.error("Error while retrieving SCP Data movement list...", e); -// throw new AppCatalogException(e); -// } -// return null; -// } - - @Override - public GridFTPDataMovement getGridFTPDataMovement(String dataMoveId) throws AppCatalogException { - try { - GridftpDataMovementResource resource = new GridftpDataMovementResource(); - GridftpDataMovementResource dataMovementResource = (GridftpDataMovementResource)resource.get(dataMoveId); - return AppCatalogThriftConversion.getGridFTPDataMovementDescription(dataMovementResource); - }catch (Exception e){ - logger.error("Error while retrieving Grid FTP Data Movement...", e); - throw new AppCatalogException(e); - } - } - -// @Override -// public List<GridFTPDataMovement> getGridFTPDataMovementList(Map<String, String> filters) throws AppCatalogException { -// try { -// GridftpDataMovementResource resource = new GridftpDataMovementResource(); -// for (String fieldName : filters.keySet() ){ -// if (fieldName.equals(AbstractResource.GridFTPDataMovementConstants.SECURITY_PROTOCOL)){ -// List<Resource> resources = resource.get(AbstractResource.GridFTPDataMovementConstants.SECURITY_PROTOCOL, filters.get(fieldName)); -// if (resources != null && !resources.isEmpty()){ -// return AppCatalogThriftConversion.getGridFTPDataMovementList(resources); -// } -// }else { -// logger.error("Unsupported field name for GridFTP Data movement.", new IllegalArgumentException()); -// throw new IllegalArgumentException("Unsupported field name for GridFTP Data movement."); -// } -// } -// }catch (Exception e){ -// logger.error("Error while retrieving GridFTP Data movement list...", e); -// throw new AppCatalogException(e); -// } -// return null; -// } - - @Override - public boolean isComputeResourceExists(String resourceId) throws AppCatalogException { - try { - ComputeResourceResource resource = new ComputeResourceResource(); - return resource.isExists(resourceId); - }catch (Exception e){ - logger.error("Error while retrieving compute resource...", e); - throw new AppCatalogException(e); - } - } - - @Override - public void removeComputeResource(String resourceId) throws AppCatalogException { - try { - ComputeResourceResource resource = new ComputeResourceResource(); - resource.remove(resourceId); - }catch (Exception e){ - logger.error("Error while removing compute resource...", e); - throw new AppCatalogException(e); - } - } - - @Override - public void removeJobSubmissionInterface(String computeResourceId, String jobSubmissionInterfaceId) throws AppCatalogException { - try { - JobSubmissionInterfaceResource resource = new JobSubmissionInterfaceResource(); - Map<String, String> ids = new HashMap<String, String>(); - ids.put(AbstractResource.JobSubmissionInterfaceConstants.COMPUTE_RESOURCE_ID, computeResourceId); - ids.put(AbstractResource.JobSubmissionInterfaceConstants.JOB_SUBMISSION_INTERFACE_ID, jobSubmissionInterfaceId); - resource.remove(ids); - }catch (Exception e){ - logger.error("Error while removing job submission interface..", e); - throw new AppCatalogException(e); - } - } - - @Override - public void removeDataMovementInterface(String computeResourceId, String dataMovementInterfaceId) throws AppCatalogException { - try { - DataMovementInterfaceResource resource = new DataMovementInterfaceResource(); - Map<String, String> ids = new HashMap<String, String>(); - ids.put(AbstractResource.DataMovementInterfaceConstants.COMPUTE_RESOURCE_ID, computeResourceId); - ids.put(AbstractResource.DataMovementInterfaceConstants.DATA_MOVEMENT_INTERFACE_ID, dataMovementInterfaceId); - resource.remove(ids); - }catch (Exception e){ - logger.error("Error while removing data movement interface..", e); - throw new AppCatalogException(e); - } - } - - @Override - public void removeBatchQueue(String computeResourceId, String queueName) throws AppCatalogException { - try { - BatchQueueResource resource = new BatchQueueResource(); - Map<String, String> ids = new HashMap<String, String>(); - ids.put(AbstractResource.BatchQueueConstants.COMPUTE_RESOURCE_ID, computeResourceId); - ids.put(AbstractResource.BatchQueueConstants.QUEUE_NAME, queueName); - resource.remove(ids); - }catch (Exception e){ - logger.error("Error while removing batch queue..", e); - throw new AppCatalogException(e); - } - } - - @Override - public String addResourceJobManager(ResourceJobManager resourceJobManager) - throws AppCatalogException { - resourceJobManager.setResourceJobManagerId(AppCatalogUtils.getID("RJM")); - ResourceJobManagerResource resource = AppCatalogThriftConversion.getResourceJobManager(resourceJobManager); - resource.save(); - Map<JobManagerCommand, String> jobManagerCommands = resourceJobManager.getJobManagerCommands(); - if (jobManagerCommands!=null && jobManagerCommands.size() != 0) { - for (JobManagerCommand commandType : jobManagerCommands.keySet()) { - JobManagerCommandResource r = new JobManagerCommandResource(); - r.setCommandType(commandType.toString()); - r.setCommand(jobManagerCommands.get(commandType)); - r.setResourceJobManagerId(resource.getResourceJobManagerId()); - r.save(); - } - } - return resource.getResourceJobManagerId(); - } - - @Override - public void updateResourceJobManager(String resourceJobManagerId, ResourceJobManager updatedResourceJobManager) throws AppCatalogException { - try { - ResourceJobManagerResource resource = AppCatalogThriftConversion.getResourceJobManager(updatedResourceJobManager); - resource.setResourceJobManagerId(resourceJobManagerId); - resource.save(); - Map<JobManagerCommand, String> jobManagerCommands = updatedResourceJobManager.getJobManagerCommands(); - if (jobManagerCommands!=null && jobManagerCommands.size() != 0) { - for (JobManagerCommand commandType : jobManagerCommands.keySet()) { - JobManagerCommandResource r = new JobManagerCommandResource(); - Map<String, String> ids = new HashMap<String, String>(); - ids.put(AbstractResource.JobManagerCommandConstants.RESOURCE_JOB_MANAGER_ID, resourceJobManagerId); - ids.put(AbstractResource.JobManagerCommandConstants.COMMAND_TYPE, commandType.toString()); - JobManagerCommandResource existingCommand; - if (r.isExists(ids)){ - existingCommand = (JobManagerCommandResource)r.get(ids); - }else { - existingCommand = new JobManagerCommandResource(); - } - existingCommand.setCommandType(commandType.toString()); - existingCommand.setCommand(jobManagerCommands.get(commandType)); - existingCommand.setResourceJobManagerId(resource.getResourceJobManagerId()); - existingCommand.save(); - } - } - }catch (Exception e){ - logger.error("Error while updating resource job manager..", e); - throw new AppCatalogException(e); - } - } - - @Override - public ResourceJobManager getResourceJobManager(String resourceJobManagerId) throws AppCatalogException { - try { - ResourceJobManagerResource resource = new ResourceJobManagerResource(); - ResourceJobManagerResource jobManagerResource = (ResourceJobManagerResource)resource.get(resourceJobManagerId); - return AppCatalogThriftConversion.getResourceJobManager(jobManagerResource); - }catch (Exception e){ - logger.error("Error while retrieving resource job manager..", e); - throw new AppCatalogException(e); - } - } - - @Override - public void deleteResourceJobManager(String resourceJobManagerId) throws AppCatalogException { - try { - ResourceJobManagerResource resource = new ResourceJobManagerResource(); - resource.remove(resourceJobManagerId); - }catch (Exception e){ - logger.error("Error while deleting resource job manager..", e); - throw new AppCatalogException(e); - } - } - - @Override - public String addLocalJobSubmission(LOCALSubmission localSubmission) - throws AppCatalogException { - localSubmission.setJobSubmissionInterfaceId(AppCatalogUtils.getID("LOCAL")); - String resourceJobManagerId = addResourceJobManager(localSubmission.getResourceJobManager()); - LocalSubmissionResource localJobSubmission = AppCatalogThriftConversion.getLocalJobSubmission(localSubmission); - localJobSubmission.setResourceJobManagerId(resourceJobManagerId); - localJobSubmission.getResourceJobManagerResource().setResourceJobManagerId(resourceJobManagerId); - localJobSubmission.save(); - return localJobSubmission.getJobSubmissionInterfaceId(); - } - - @Override - public String addLocalDataMovement(LOCALDataMovement localDataMovement) - throws AppCatalogException { - localDataMovement.setDataMovementInterfaceId(AppCatalogUtils.getID("LOCAL")); - LocalDataMovementResource ldm = AppCatalogThriftConversion.getLocalDataMovement(localDataMovement); - ldm.save(); - return ldm.getDataMovementInterfaceId(); - } - - @Override - public LOCALSubmission getLocalJobSubmission(String submissionId) - throws AppCatalogException { - LocalSubmissionResource localSubmissionResource = new LocalSubmissionResource(); - localSubmissionResource= (LocalSubmissionResource)localSubmissionResource.get(submissionId); - return AppCatalogThriftConversion.getLocalJobSubmission(localSubmissionResource); - } - - @Override - public LOCALDataMovement getLocalDataMovement(String datamovementId) - throws AppCatalogException { - LocalDataMovementResource localDataMovementResource = new LocalDataMovementResource(); - localDataMovementResource = (LocalDataMovementResource) localDataMovementResource.get(datamovementId); - return AppCatalogThriftConversion.getLocalDataMovement(localDataMovementResource); - } - -} http://git-wip-us.apache.org/repos/asf/airavata/blob/ec8c6202/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/GwyResourceProfileImpl.java ---------------------------------------------------------------------- diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/GwyResourceProfileImpl.java b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/GwyResourceProfileImpl.java deleted file mode 100644 index 4537efd..0000000 --- a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/GwyResourceProfileImpl.java +++ /dev/null @@ -1,252 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -package org.apache.aiaravata.application.catalog.data.impl; - -import org.airavata.appcatalog.cpi.AppCatalogException; -import org.airavata.appcatalog.cpi.GwyResourceProfile; -import org.apache.aiaravata.application.catalog.data.resources.*; -import org.apache.aiaravata.application.catalog.data.util.AppCatalogThriftConversion; -import org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference; -import org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile; -import org.apache.airavata.model.appcatalog.gatewayprofile.gatewayResourceProfileModelConstants; -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 GwyResourceProfileImpl implements GwyResourceProfile { - private final static Logger logger = LoggerFactory.getLogger(GwyResourceProfileImpl.class); - - @Override - public String addGatewayResourceProfile(org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile gatewayProfile) throws AppCatalogException { - try { - GatewayProfileResource profileResource = new GatewayProfileResource(); - if (!gatewayProfile.getGatewayID().equals("") && !gatewayProfile.getGatewayID().equals(gatewayResourceProfileModelConstants.DEFAULT_ID)){ - profileResource.setGatewayID(gatewayProfile.getGatewayID()); - } -// profileResource.setGatewayID(gatewayProfile.getGatewayID()); - profileResource.save(); - List<ComputeResourcePreference> computeResourcePreferences = gatewayProfile.getComputeResourcePreferences(); - if (computeResourcePreferences != null && !computeResourcePreferences.isEmpty()){ - for (ComputeResourcePreference preference : computeResourcePreferences ){ - ComputeHostPreferenceResource resource = new ComputeHostPreferenceResource(); - resource.setGatewayProfile(profileResource); - resource.setResourceId(preference.getComputeResourceId()); - ComputeResourceResource computeHostResource = new ComputeResourceResource(); - resource.setComputeHostResource((ComputeResourceResource)computeHostResource.get(preference.getComputeResourceId())); - resource.setGatewayId(profileResource.getGatewayID()); - resource.setOverrideByAiravata(preference.isOverridebyAiravata()); - resource.setLoginUserName(preference.getLoginUserName()); - if (preference.getPreferredJobSubmissionProtocol() != null){ - resource.setPreferredJobProtocol(preference.getPreferredJobSubmissionProtocol().toString()); - } - - if (preference.getPreferredDataMovementProtocol() != null){ - resource.setPreferedDMProtocol(preference.getPreferredDataMovementProtocol().toString()); - } - - resource.setBatchQueue(preference.getPreferredBatchQueue()); - resource.setProjectNumber(preference.getAllocationProjectNumber()); - resource.setScratchLocation(preference.getScratchLocation()); - resource.save(); - } - } - return profileResource.getGatewayID(); - }catch (Exception e) { - logger.error("Error while saving gateway profile...", e); - throw new AppCatalogException(e); - } - } - - @Override - public void updateGatewayResourceProfile(String gatewayId, org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile updatedProfile) throws AppCatalogException { - try { - GatewayProfileResource profileResource = new GatewayProfileResource(); - GatewayProfileResource existingGP = (GatewayProfileResource)profileResource.get(gatewayId); - existingGP.save(); - - List<ComputeResourcePreference> computeResourcePreferences = updatedProfile.getComputeResourcePreferences(); - if (computeResourcePreferences != null && !computeResourcePreferences.isEmpty()){ - for (ComputeResourcePreference preference : computeResourcePreferences ){ - ComputeHostPreferenceResource resource = new ComputeHostPreferenceResource(); - resource.setGatewayProfile(existingGP); - resource.setResourceId(preference.getComputeResourceId()); - ComputeResourceResource computeHostResource = new ComputeResourceResource(); - resource.setComputeHostResource((ComputeResourceResource)computeHostResource.get(preference.getComputeResourceId())); - resource.setGatewayId(gatewayId); - resource.setLoginUserName(preference.getLoginUserName()); - resource.setOverrideByAiravata(preference.isOverridebyAiravata()); - if (preference.getPreferredJobSubmissionProtocol() != null){ - resource.setPreferredJobProtocol(preference.getPreferredJobSubmissionProtocol().toString()); - } - - if (preference.getPreferredDataMovementProtocol() != null){ - resource.setPreferedDMProtocol(preference.getPreferredDataMovementProtocol().toString()); - } - resource.setBatchQueue(preference.getPreferredBatchQueue()); - resource.setProjectNumber(preference.getAllocationProjectNumber()); - resource.setScratchLocation(preference.getScratchLocation()); - resource.save(); - } - } - }catch (Exception e) { - logger.error("Error while updating gateway profile...", e); - throw new AppCatalogException(e); - } - } - - @Override - public GatewayResourceProfile getGatewayProfile(String gatewayId) throws AppCatalogException { - try { - GatewayProfileResource resource = new GatewayProfileResource(); - GatewayProfileResource gwresource = (GatewayProfileResource)resource.get(gatewayId); - ComputeHostPreferenceResource prefResource = new ComputeHostPreferenceResource(); - List<Resource> computePrefList = prefResource.get(AbstractResource.ComputeResourcePreferenceConstants.GATEWAY_ID, gatewayId); - List<ComputeResourcePreference> computeResourcePreferences = AppCatalogThriftConversion.getComputeResourcePreferences(computePrefList); - return AppCatalogThriftConversion.getGatewayResourceProfile(gwresource, computeResourcePreferences); - }catch (Exception e) { - logger.error("Error while retrieving gateway profile...", e); - throw new AppCatalogException(e); - } - } - - @Override - public boolean removeGatewayResourceProfile(String gatewayId) throws AppCatalogException { - try { - GatewayProfileResource resource = new GatewayProfileResource(); - resource.remove(gatewayId); - return true; - }catch (Exception e) { - logger.error("Error while deleting gateway profile...", e); - throw new AppCatalogException(e); - } - } - - @Override - public boolean removeComputeResourcePreferenceFromGateway(String gatewayId, String preferenceId) throws AppCatalogException { - try { - ComputeHostPreferenceResource resource = new ComputeHostPreferenceResource(); - Map<String, String> ids = new HashMap<String, String>(); - ids.put(AbstractResource.ComputeResourcePreferenceConstants.GATEWAY_ID, gatewayId); - ids.put(AbstractResource.ComputeResourcePreferenceConstants.RESOURCE_ID, preferenceId); - resource.remove(ids); - return true; - }catch (Exception e) { - logger.error("Error while deleting gateway profile...", e); - throw new AppCatalogException(e); - } - } - - @Override - public boolean isGatewayResourceProfileExists(String gatewayId) throws AppCatalogException { - try { - GatewayProfileResource resource = new GatewayProfileResource(); - return resource.isExists(gatewayId); - }catch (Exception e) { - logger.error("Error while retrieving gateway profile...", e); - throw new AppCatalogException(e); - } - } - - /** - * @param gatewayId - * @param hostId - * @return ComputeResourcePreference - */ - @Override - public ComputeResourcePreference getComputeResourcePreference(String gatewayId, String hostId) throws AppCatalogException { - try { - ComputeHostPreferenceResource prefResource = new ComputeHostPreferenceResource(); - List<Resource> computePrefList = prefResource.get(AbstractResource.ComputeResourcePreferenceConstants.GATEWAY_ID, gatewayId); - for (Resource resource : computePrefList){ - ComputeHostPreferenceResource cmP = (ComputeHostPreferenceResource) resource; - if (cmP.getResourceId() != null && !cmP.getResourceId().equals("")){ - if (cmP.getResourceId().equals(hostId)){ - return AppCatalogThriftConversion.getComputeResourcePreference(cmP); - } - } - } - }catch (Exception e) { - logger.error("Error while retrieving compute resource preference...", e); - throw new AppCatalogException(e); - } - return null; - } - - /** - * @param gatewayId - * @return - */ - @Override - public List<ComputeResourcePreference> getAllComputeResourcePreferences(String gatewayId) throws AppCatalogException { - try { - ComputeHostPreferenceResource prefResource = new ComputeHostPreferenceResource(); - List<Resource> computePrefList = prefResource.get(AbstractResource.ComputeResourcePreferenceConstants.GATEWAY_ID, gatewayId); - return AppCatalogThriftConversion.getComputeResourcePreferences(computePrefList); - }catch (Exception e) { - logger.error("Error while retrieving compute resource preference...", e); - throw new AppCatalogException(e); - } - } - - @Override - public List<String> getGatewayProfileIds(String gatewayName) throws AppCatalogException { - try { - GatewayProfileResource profileResource = new GatewayProfileResource(); - List<Resource> resourceList = profileResource.get(AbstractResource.GatewayProfileConstants.GATEWAY_ID, gatewayName); - List<String> gatewayIds = new ArrayList<String>(); - if (resourceList != null && !resourceList.isEmpty()){ - for (Resource resource : resourceList){ - gatewayIds.add(((GatewayProfileResource)resource).getGatewayID()); - } - } - return gatewayIds; - }catch (Exception e) { - logger.error("Error while retrieving gateway ids...", e); - throw new AppCatalogException(e); - } - } - - @Override - public List<GatewayResourceProfile> getAllGatewayProfiles() throws AppCatalogException { - try { - List<GatewayResourceProfile> gatewayResourceProfileList = new ArrayList<GatewayResourceProfile>(); - GatewayProfileResource profileResource = new GatewayProfileResource(); - List<Resource> resourceList = profileResource.getAll(); - if (resourceList != null && !resourceList.isEmpty()){ - for (Resource resource : resourceList){ - GatewayProfileResource gatewayProfileResource = (GatewayProfileResource)resource; - List<ComputeResourcePreference> computeResourcePreferences = getAllComputeResourcePreferences(gatewayProfileResource.getGatewayID()); - GatewayResourceProfile gatewayResourceProfile = AppCatalogThriftConversion.getGatewayResourceProfile(gatewayProfileResource, computeResourcePreferences); - gatewayResourceProfileList.add(gatewayResourceProfile); - } - } - return gatewayResourceProfileList; - }catch (Exception e) { - logger.error("Error while retrieving gateway ids...", e); - throw new AppCatalogException(e); - } - } -}
