Search in sources :

Example 6 with ApplicationParallelismType

use of org.apache.airavata.model.parallelism.ApplicationParallelismType in project airavata by apache.

the class ApplicationDeploymentImpl method addApplicationDeployment.

@Override
public String addApplicationDeployment(ApplicationDeploymentDescription deploymentDescription, String gatewayId) throws AppCatalogException {
    try {
        AppDeploymentResource deploymentResource = new AppDeploymentResource();
        ComputeResourceResource computeHostResource = new ComputeResourceResource();
        AppModuleResource moduleResource = new AppModuleResource();
        if (!computeHostResource.isExists(deploymentDescription.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(deploymentDescription.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(deploymentDescription.getAppModuleId());
        ComputeResourceResource hostResource = (ComputeResourceResource) computeHostResource.get(deploymentDescription.getComputeHostId());
        deploymentResource.setDeploymentId(hostResource.getHostName() + "_" + deploymentDescription.getAppModuleId());
        deploymentResource.setAppModuleId(deploymentDescription.getAppModuleId());
        deploymentResource.setModuleResource(module);
        deploymentResource.setHostId(deploymentDescription.getComputeHostId());
        deploymentResource.setHostResource(hostResource);
        deploymentResource.setAppDes(deploymentDescription.getAppDeploymentDescription());
        deploymentResource.setExecutablePath(deploymentDescription.getExecutablePath());
        deploymentResource.setGatewayId(gatewayId);
        deploymentResource.setDefaultQueueName(deploymentDescription.getDefaultQueueName());
        deploymentResource.setDefaultCPUCount(deploymentDescription.getDefaultCPUCount());
        deploymentResource.setDefaultNodeCount(deploymentDescription.getDefaultNodeCount());
        deploymentResource.setDefaultWalltime(deploymentDescription.getDefaultWalltime());
        deploymentResource.setEditableByUser(deploymentDescription.isEditableByUser());
        ApplicationParallelismType parallelism = deploymentDescription.getParallelism();
        if (parallelism != null) {
            deploymentResource.setParallelism(parallelism.toString());
        }
        deploymentResource.save();
        deploymentDescription.setAppDeploymentId(deploymentResource.getDeploymentId());
        List<CommandObject> moduleLoadCmds = deploymentDescription.getModuleLoadCmds();
        if (moduleLoadCmds != null && !moduleLoadCmds.isEmpty()) {
            for (CommandObject cmd : moduleLoadCmds) {
                ModuleLoadCmdResource cmdResource = new ModuleLoadCmdResource();
                cmdResource.setAppDeploymentId(deploymentDescription.getAppDeploymentId());
                cmdResource.setOrder(cmd.getCommandOrder());
                cmdResource.setCmd(cmd.getCommand());
                cmdResource.save();
            }
        }
        List<CommandObject> preJobCommands = deploymentDescription.getPreJobCommands();
        if (preJobCommands != null && !preJobCommands.isEmpty()) {
            for (CommandObject cmd : preJobCommands) {
                PreJobCommandResource cmdResource = new PreJobCommandResource();
                cmdResource.setAppDeploymentId(deploymentDescription.getAppDeploymentId());
                cmdResource.setCommand(cmd.getCommand());
                cmdResource.setOrder(cmd.getCommandOrder());
                cmdResource.save();
            }
        }
        List<CommandObject> postJobCommands = deploymentDescription.getPostJobCommands();
        if (postJobCommands != null && !postJobCommands.isEmpty()) {
            for (CommandObject cmd : postJobCommands) {
                PostJobCommandResource cmdResource = new PostJobCommandResource();
                cmdResource.setAppDeploymentId(deploymentDescription.getAppDeploymentId());
                cmdResource.setCommand(cmd.getCommand());
                cmdResource.setOrder(cmd.getCommandOrder());
                cmdResource.save();
            }
        }
        List<SetEnvPaths> libPrependPaths = deploymentDescription.getLibPrependPaths();
        if (libPrependPaths != null && !libPrependPaths.isEmpty()) {
            for (SetEnvPaths path : libPrependPaths) {
                LibraryPrepandPathResource prepandPathResource = new LibraryPrepandPathResource();
                prepandPathResource.setAppDeploymentResource(deploymentResource);
                prepandPathResource.setName(path.getName());
                prepandPathResource.setValue(path.getValue());
                prepandPathResource.setDeploymentId(deploymentResource.getDeploymentId());
                prepandPathResource.save();
            }
        }
        List<SetEnvPaths> libApendPaths = deploymentDescription.getLibAppendPaths();
        if (libApendPaths != null && !libApendPaths.isEmpty()) {
            for (SetEnvPaths path : libApendPaths) {
                LibraryApendPathResource apendPathResource = new LibraryApendPathResource();
                apendPathResource.setAppDeploymentResource(deploymentResource);
                apendPathResource.setName(path.getName());
                apendPathResource.setValue(path.getValue());
                apendPathResource.setDeploymentId(deploymentResource.getDeploymentId());
                apendPathResource.save();
            }
        }
        List<SetEnvPaths> setEnvironment = deploymentDescription.getSetEnvironment();
        if (setEnvironment != null && !setEnvironment.isEmpty()) {
            for (SetEnvPaths path : setEnvironment) {
                AppEnvironmentResource environmentResource = new AppEnvironmentResource();
                environmentResource.setAppDeploymentResource(deploymentResource);
                environmentResource.setName(path.getName());
                environmentResource.setValue(path.getValue());
                environmentResource.setDeploymentId(deploymentResource.getDeploymentId());
                environmentResource.setOrder(path.getEnvPathOrder());
                environmentResource.save();
            }
        }
        return deploymentResource.getDeploymentId();
    } catch (Exception e) {
        logger.error("Error while saving application deployment...", e);
        throw new AppCatalogException(e);
    }
}
Also used : ApplicationParallelismType(org.apache.airavata.model.parallelism.ApplicationParallelismType) 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)

Aggregations

ApplicationParallelismType (org.apache.airavata.model.parallelism.ApplicationParallelismType)6 ApplicationDeploymentDescription (org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription)3 CommandObject (org.apache.airavata.model.appcatalog.appdeployment.CommandObject)2 Writable (groovy.lang.Writable)1 GStringTemplateEngine (groovy.text.GStringTemplateEngine)1 TemplateEngine (groovy.text.TemplateEngine)1 java.io (java.io)1 InetAddress (java.net.InetAddress)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 UnknownHostException (java.net.UnknownHostException)1 ByteBuffer (java.nio.ByteBuffer)1 SecureRandom (java.security.SecureRandom)1 java.util (java.util)1 HashMap (java.util.HashMap)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 javax.xml.xpath (javax.xml.xpath)1 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)1