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());
deploymentResource.setDeploymentId(AppCatalogUtils.getID(module.getModuleName()));
deploymentResource.setAppModuleId(deploymentDescription.getAppModuleId());
deploymentResource.setModuleResource(module);
deploymentResource.setHostId(deploymentDescription.getComputeHostId());
deploymentResource.setHostResource((ComputeResourceResource)computeHostResource.get(deploymentDescription.getComputeHostId()));
deploymentResource.setAppDes(deploymentDescription.getAppDeploymentDescription());
deploymentResource.setExecutablePath(deploymentDescription.getExecutablePath());
ApplicationParallelismType parallelism = deploymentDescription.getParallelism();
if (parallelism != null){
deploymentResource.setParallelism(parallelism.toString());
}
deploymentResource.save();
deploymentDescription.setAppDeploymentId(deploymentResource.getDeploymentId());
List<String> moduleLoadCmds = deploymentDescription.getModuleLoadCmds();
if (moduleLoadCmds != null && !moduleLoadCmds.isEmpty()){
for (String cmd : moduleLoadCmds){
ModuleLoadCmdResource cmdResource = new ModuleLoadCmdResource();
cmdResource.setAppDeploymentId(deploymentDescription.getAppDeploymentId());
cmdResource.setCmd(cmd);
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.save();
}
}
return deploymentResource.getDeploymentId();
}catch (Exception e) {
logger.error("Error while saving application deployment...", e);
throw new AppCatalogException(e);
}
}