Search in sources :

Example 51 with AppCatalogException

use of org.apache.airavata.registry.cpi.AppCatalogException in project airavata by apache.

the class ApplicationDeploymentImpl method updateApplicationDeployment.

@Override
public void updateApplicationDeployment(String deploymentId, ApplicationDeploymentDescription updatedDeployment) throws AppCatalogException {
    try {
        AppDeploymentResource deploymentResource = new AppDeploymentResource();
        AppDeploymentResource existingDep = (AppDeploymentResource) deploymentResource.get(deploymentId);
        ComputeResourceResource computeHostResource = new ComputeResourceResource();
        AppModuleResource moduleResource = new AppModuleResource();
        if (!computeHostResource.isExists(updatedDeployment.getComputeHostId())) {
            logger.error("Compute host does not exist in the system. Please create a Compute host first...");
            throw new AppCatalogException("Compute host does not exist in the system. Please create a Compute host first...");
        }
        if (!moduleResource.isExists(updatedDeployment.getAppModuleId())) {
            logger.error("Application module does not exist in the system. Please create an application module first...");
            throw new AppCatalogException("Application module does not exist in the system. Please create an application module first...");
        }
        AppModuleResource module = (AppModuleResource) moduleResource.get(updatedDeployment.getAppModuleId());
        existingDep.setAppModuleId(updatedDeployment.getAppModuleId());
        existingDep.setModuleResource(module);
        existingDep.setHostId(updatedDeployment.getComputeHostId());
        existingDep.setHostResource((ComputeResourceResource) computeHostResource.get(updatedDeployment.getComputeHostId()));
        existingDep.setAppDes(updatedDeployment.getAppDeploymentDescription());
        existingDep.setExecutablePath(updatedDeployment.getExecutablePath());
        existingDep.setDefaultQueueName(updatedDeployment.getDefaultQueueName());
        existingDep.setDefaultCPUCount(updatedDeployment.getDefaultCPUCount());
        existingDep.setDefaultNodeCount(updatedDeployment.getDefaultNodeCount());
        existingDep.setDefaultWalltime(updatedDeployment.getDefaultWalltime());
        existingDep.setEditableByUser(updatedDeployment.isEditableByUser());
        if (updatedDeployment.getParallelism() != null) {
            existingDep.setParallelism(updatedDeployment.getParallelism().toString());
        }
        existingDep.save();
        // remove existing module load commands
        ModuleLoadCmdResource cmdResource = new ModuleLoadCmdResource();
        Map<String, String> ids = new HashMap<String, String>();
        ids.put(AppCatAbstractResource.ModuleLoadCmdConstants.APP_DEPLOYMENT_ID, deploymentId);
        cmdResource.remove(ids);
        List<CommandObject> moduleLoadCmds = updatedDeployment.getModuleLoadCmds();
        if (moduleLoadCmds != null && !moduleLoadCmds.isEmpty()) {
            for (CommandObject cmd : moduleLoadCmds) {
                ids = new HashMap<String, String>();
                ids.put(AppCatAbstractResource.ModuleLoadCmdConstants.APP_DEPLOYMENT_ID, deploymentId);
                ids.put(AppCatAbstractResource.ModuleLoadCmdConstants.CMD, cmd.getCommand());
                if (cmdResource.isExists(ids)) {
                    cmdResource = (ModuleLoadCmdResource) cmdResource.get(ids);
                }
                cmdResource.setCmd(cmd.getCommand());
                cmdResource.setAppDeploymentResource(existingDep);
                cmdResource.setAppDeploymentId(deploymentId);
                cmdResource.setOrder(cmd.getCommandOrder());
                cmdResource.save();
            }
        }
        PreJobCommandResource preJobCommandResource = new PreJobCommandResource();
        ids = new HashMap<String, String>();
        ids.put(AppCatAbstractResource.PreJobCommandConstants.DEPLOYMENT_ID, deploymentId);
        preJobCommandResource.remove(ids);
        List<CommandObject> preJobCommands = updatedDeployment.getPreJobCommands();
        if (preJobCommands != null && !preJobCommands.isEmpty()) {
            for (CommandObject cmd : preJobCommands) {
                ids = new HashMap<String, String>();
                ids.put(AppCatAbstractResource.PreJobCommandConstants.DEPLOYMENT_ID, deploymentId);
                ids.put(AppCatAbstractResource.PreJobCommandConstants.COMMAND, cmd.getCommand());
                if (preJobCommandResource.isExists(ids)) {
                    preJobCommandResource = (PreJobCommandResource) preJobCommandResource.get(ids);
                }
                preJobCommandResource.setCommand(cmd.getCommand());
                preJobCommandResource.setAppDeploymentResource(existingDep);
                preJobCommandResource.setAppDeploymentId(deploymentId);
                preJobCommandResource.setOrder(cmd.getCommandOrder());
                preJobCommandResource.save();
            }
        }
        PostJobCommandResource postJobCommandResource = new PostJobCommandResource();
        ids = new HashMap<String, String>();
        ids.put(AppCatAbstractResource.PostJobCommandConstants.DEPLOYMENT_ID, deploymentId);
        postJobCommandResource.remove(ids);
        List<CommandObject> postJobCommands = updatedDeployment.getPostJobCommands();
        if (postJobCommands != null && !postJobCommands.isEmpty()) {
            for (CommandObject cmd : postJobCommands) {
                ids = new HashMap<String, String>();
                ids.put(AppCatAbstractResource.PostJobCommandConstants.DEPLOYMENT_ID, deploymentId);
                ids.put(AppCatAbstractResource.PostJobCommandConstants.COMMAND, cmd.getCommand());
                if (postJobCommandResource.isExists(ids)) {
                    postJobCommandResource = (PostJobCommandResource) postJobCommandResource.get(ids);
                }
                postJobCommandResource.setCommand(cmd.getCommand());
                postJobCommandResource.setOrder(cmd.getCommandOrder());
                postJobCommandResource.setAppDeploymentResource(existingDep);
                postJobCommandResource.setAppDeploymentId(deploymentId);
                postJobCommandResource.save();
            }
        }
        // remove existing lib prepand paths
        LibraryPrepandPathResource prepandPathResource = new LibraryPrepandPathResource();
        ids = new HashMap<String, String>();
        ids.put(AppCatAbstractResource.LibraryPrepandPathConstants.DEPLOYMENT_ID, deploymentId);
        prepandPathResource.remove(ids);
        List<SetEnvPaths> libPrependPaths = updatedDeployment.getLibPrependPaths();
        if (libPrependPaths != null && !libPrependPaths.isEmpty()) {
            for (SetEnvPaths path : libPrependPaths) {
                ids = new HashMap<String, String>();
                ids.put(AppCatAbstractResource.LibraryPrepandPathConstants.DEPLOYMENT_ID, deploymentId);
                ids.put(AppCatAbstractResource.LibraryPrepandPathConstants.NAME, path.getName());
                if (prepandPathResource.isExists(ids)) {
                    prepandPathResource = (LibraryPrepandPathResource) prepandPathResource.get(ids);
                }
                prepandPathResource.setAppDeploymentResource(existingDep);
                prepandPathResource.setName(path.getName());
                prepandPathResource.setValue(path.getValue());
                prepandPathResource.setDeploymentId(deploymentId);
                prepandPathResource.save();
            }
        }
        List<SetEnvPaths> libApendPaths = updatedDeployment.getLibAppendPaths();
        // remove lib append paths
        LibraryApendPathResource apendPathResource = new LibraryApendPathResource();
        ids = new HashMap<String, String>();
        ids.put(AppCatAbstractResource.LibraryApendPathConstants.DEPLOYMENT_ID, deploymentId);
        apendPathResource.remove(ids);
        if (libApendPaths != null && !libApendPaths.isEmpty()) {
            for (SetEnvPaths path : libApendPaths) {
                ids = new HashMap<String, String>();
                ids.put(AppCatAbstractResource.LibraryApendPathConstants.DEPLOYMENT_ID, deploymentId);
                ids.put(AppCatAbstractResource.LibraryApendPathConstants.NAME, path.getName());
                if (apendPathResource.isExists(ids)) {
                    apendPathResource = (LibraryApendPathResource) apendPathResource.get(ids);
                }
                apendPathResource.setAppDeploymentResource(existingDep);
                apendPathResource.setName(path.getName());
                apendPathResource.setValue(path.getValue());
                apendPathResource.setDeploymentId(deploymentId);
                apendPathResource.save();
            }
        }
        List<SetEnvPaths> setEnvironment = updatedDeployment.getSetEnvironment();
        // remove existing setEnvPaths
        AppEnvironmentResource environmentResource = new AppEnvironmentResource();
        ids = new HashMap<String, String>();
        ids.put(AppCatAbstractResource.AppEnvironmentConstants.DEPLOYMENT_ID, deploymentId);
        environmentResource.remove(ids);
        if (setEnvironment != null && !setEnvironment.isEmpty()) {
            for (SetEnvPaths path : setEnvironment) {
                ids = new HashMap<String, String>();
                ids.put(AppCatAbstractResource.AppEnvironmentConstants.DEPLOYMENT_ID, deploymentId);
                ids.put(AppCatAbstractResource.AppEnvironmentConstants.NAME, path.getName());
                if (environmentResource.isExists(ids)) {
                    environmentResource = (AppEnvironmentResource) environmentResource.get(ids);
                }
                environmentResource.setAppDeploymentResource(existingDep);
                environmentResource.setName(path.getName());
                environmentResource.setValue(path.getValue());
                environmentResource.setDeploymentId(deploymentId);
                environmentResource.setOrder(path.getEnvPathOrder());
                environmentResource.save();
            }
        }
    } catch (Exception e) {
        logger.error("Error while updating application deployment...", e);
        throw new AppCatalogException(e);
    }
}
Also used : HashMap(java.util.HashMap) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) CommandObject(org.apache.airavata.model.appcatalog.appdeployment.CommandObject) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) SetEnvPaths(org.apache.airavata.model.appcatalog.appdeployment.SetEnvPaths)

Example 52 with AppCatalogException

use of org.apache.airavata.registry.cpi.AppCatalogException in project airavata by apache.

the class ApplicationDeploymentImpl method getAllApplicationDeployements.

@Override
public List<ApplicationDeploymentDescription> getAllApplicationDeployements(String gatewayId) throws AppCatalogException {
    List<ApplicationDeploymentDescription> deploymentDescriptions = new ArrayList<ApplicationDeploymentDescription>();
    try {
        AppDeploymentResource resource = new AppDeploymentResource();
        resource.setGatewayId(gatewayId);
        List<AppCatalogResource> resources = resource.getAll();
        if (resources != null && !resources.isEmpty()) {
            deploymentDescriptions = AppCatalogThriftConversion.getAppDepDescList(resources);
        }
    } catch (Exception e) {
        logger.error("Error while retrieving app deployment list...", e);
        throw new AppCatalogException(e);
    }
    return deploymentDescriptions;
}
Also used : ApplicationDeploymentDescription(org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ArrayList(java.util.ArrayList) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException)

Example 53 with AppCatalogException

use of org.apache.airavata.registry.cpi.AppCatalogException in project airavata by apache.

the class ComputeResourceImpl method addCloudJobSubmission.

@Override
public String addCloudJobSubmission(CloudJobSubmission cloudJobSubmission) throws AppCatalogException {
    try {
        cloudJobSubmission.setJobSubmissionInterfaceId(AppCatalogUtils.getID("Cloud"));
        CloudSubmissionResource resource = AppCatalogThriftConversion.getCloudJobSubmission(cloudJobSubmission);
        resource.save();
        return resource.getJobSubmissionInterfaceId();
    } catch (Exception e) {
        logger.error("Error while saving SSH Job Submission...", e);
        throw new AppCatalogException(e);
    }
}
Also used : AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException)

Example 54 with AppCatalogException

use of org.apache.airavata.registry.cpi.AppCatalogException in project airavata by apache.

the class ComputeResourceImpl method removeComputeResource.

@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);
    }
}
Also used : AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException)

Example 55 with AppCatalogException

use of org.apache.airavata.registry.cpi.AppCatalogException in project airavata by apache.

the class ComputeResourceImpl method getCloudJobSubmission.

@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);
    }
}
Also used : AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException)

Aggregations

AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)353 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)268 EntityManager (javax.persistence.EntityManager)261 Query (javax.persistence.Query)176 AppCatalogQueryGenerator (org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)176 ArrayList (java.util.ArrayList)94 HashMap (java.util.HashMap)70 Map (java.util.Map)54 List (java.util.List)42 CompositeIdentifier (org.apache.airavata.registry.cpi.CompositeIdentifier)22 ComputeResource (org.apache.airavata.registry.core.app.catalog.model.ComputeResource)14 ApplicationDeployment (org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment)13 ApplicationInterface (org.apache.airavata.registry.core.app.catalog.model.ApplicationInterface)10 ApplicationModule (org.apache.airavata.registry.core.app.catalog.model.ApplicationModule)8 GatewayProfile (org.apache.airavata.registry.core.app.catalog.model.GatewayProfile)6 ResourceJobManager (org.apache.airavata.registry.core.app.catalog.model.ResourceJobManager)6 StorageResource (org.apache.airavata.registry.core.app.catalog.model.StorageResource)6 Initialize (org.apache.airavata.app.catalog.util.Initialize)5 ProcessContext (org.apache.airavata.gfac.core.context.ProcessContext)5 GSISSHSubmission (org.apache.airavata.registry.core.app.catalog.model.GSISSHSubmission)5