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());
if (updatedDeployment.getParallelism() != null){
deploymentResource.setParallelism(updatedDeployment.getParallelism().toString());
}
existingDep.save();
List<String> moduleLoadCmds = updatedDeployment.getModuleLoadCmds();
if (moduleLoadCmds != null && !moduleLoadCmds.isEmpty()){
for (String cmd : moduleLoadCmds){
ModuleLoadCmdResource cmdResource = new ModuleLoadCmdResource();
Map<String, String> ids = new HashMap<String, String>();
ids.put(AbstractResource.ModuleLoadCmdConstants.APP_DEPLOYMENT_ID, deploymentId);
ids.put(AbstractResource.ModuleLoadCmdConstants.CMD, cmd);
if (cmdResource.isExists(ids)){
cmdResource = (ModuleLoadCmdResource)cmdResource.get(ids);
}
cmdResource.setCmd(cmd);
cmdResource.setAppDeploymentResource(existingDep);
cmdResource.save();
}
}
List<SetEnvPaths> libPrependPaths = updatedDeployment.getLibPrependPaths();
if (libPrependPaths != null && !libPrependPaths.isEmpty()){
for (SetEnvPaths path : libPrependPaths){
LibraryPrepandPathResource prepandPathResource = new LibraryPrepandPathResource();
Map<String, String> ids = new HashMap<String, String>();
ids.put(AbstractResource.LibraryPrepandPathConstants.DEPLOYMENT_ID, deploymentId);
ids.put(AbstractResource.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();
if (libApendPaths != null && !libApendPaths.isEmpty()){
for (SetEnvPaths path : libApendPaths){
LibraryApendPathResource apendPathResource = new LibraryApendPathResource();
Map<String, String> ids = new HashMap<String, String>();
ids.put(AbstractResource.LibraryApendPathConstants.DEPLOYMENT_ID, deploymentId);
ids.put(AbstractResource.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();
if (setEnvironment != null && !setEnvironment.isEmpty()){
for (SetEnvPaths path : setEnvironment){
AppEnvironmentResource environmentResource = new AppEnvironmentResource();
Map<String, String> ids = new HashMap<String, String>();
ids.put(AbstractResource.AppEnvironmentConstants.DEPLOYMENT_ID, deploymentId);
ids.put(AbstractResource.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.save();
}
}
}catch (Exception e) {
logger.error("Error while updating application deployment...", e);
throw new AppCatalogException(e);
}
}