/** * Lancer par signal de NoPublicController quand le processus sshd est démarré dans les containers * serveur et git */ public Application updateEnv(Application application, User user) throws ServiceException { logger.info("--update Env of Server--"); String command = null; Map<String, String> configShellModule = new HashMap<>(); Map<String, String> configShellServer = new HashMap<>(); Module moduleGit = moduleService.findGitModule(user.getLogin(), application); Server server = application.getServers().get(0); String rootPassword = application.getUser().getPassword(); configShellModule.put("port", moduleGit.getSshPort()); configShellModule.put("dockerManagerAddress", moduleGit.getApplication().getManagerIp()); configShellModule.put("password", rootPassword); configShellModule.put("dockerManagerAddress", application.getManagerIp()); logger.info("new server ip : " + server.getContainerIP()); try { int counter = 0; while (!server.getStatus().equals(Status.START) || !moduleGit.getStatus().equals(Status.START)) { if (counter == 100) { break; } Thread.sleep(1000); logger.info(" wait git and server sshd processus start"); logger.info( "SSHDSTATUS = server : " + server.getStatus() + " - module : " + moduleGit.getStatus()); moduleGit = moduleService.findById(moduleGit.getId()); server = serverService.findById(server.getId()); counter++; } command = ". /cloudunit/scripts/update-env.sh " + server.getContainerIP(); logger.info("command shell to execute [" + command + "]"); shellUtils.executeShell(command, configShellModule); configShellServer.put("port", server.getSshPort()); configShellServer.put("dockerManagerAddress", server.getApplication().getManagerIp()); configShellServer.put("password", rootPassword); command = ". /cloudunit/scripts/rm-auth-keys.sh "; logger.info("command shell to execute [" + command + "]"); shellUtils.executeShell(command, configShellServer); String cleanCommand = server.getServerAction().cleanCommand(); if (cleanCommand != null) { shellUtils.executeShell(server.getServerAction().cleanCommand(), configShellServer); } } catch (Exception e) { moduleGit.setStatus(Status.FAIL); moduleGit = moduleService.saveInDB(moduleGit); server.setStatus(Status.FAIL); server = serverService.saveInDB(server); logger.error("Error : Error during update Env var of GIT " + e); throw new ServiceException(e.getLocalizedMessage(), e); } return application; }
@Override @Transactional public void addNewAlias(Application application, String alias) throws ServiceException, CheckException { logger.info("ALIAS VALUE IN addNewAlias : " + alias); if (checkAliasIfExists(alias)) { throw new CheckException( "This alias is already used by another application on this CloudUnit instance"); } alias = alias.toLowerCase(); if (alias.startsWith("https://") || alias.startsWith("http://") || alias.startsWith("ftp://")) { alias = alias.substring(alias.lastIndexOf("//") + 2, alias.length()); } if (!StringUtils.isAlphanumeric(alias)) { throw new CheckException( "This alias must be alphanumeric. Please remove all other characters"); } try { Server server = application.getServers().get(0); application.getAliases().add(alias); hipacheRedisUtils.writeNewAlias(alias, application, server.getServerAction().getServerPort()); applicationDAO.save(application); } catch (DataAccessException e) { throw new ServiceException(e.getLocalizedMessage(), e); } }
@Override @Transactional public void updateAliases(Application application) throws ServiceException { try { Server server = application.getServers().get(0); List<String> aliases = applicationDAO.findAllAliases(application.getName()); for (String alias : aliases) { hipacheRedisUtils.updateAlias(alias, application, server.getServerAction().getServerPort()); } } catch (DataAccessException e) { throw new ServiceException(e.getLocalizedMessage(), e); } }