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);
}
}
Aggregations