List of usage examples for java.lang Module getName
public String getName()
From source file:fr.treeptik.cloudunit.service.impl.ModuleServiceImpl.java
/** * Affecte un nom disponible pour le module que l'on souhaite crer * * @param module// www. ja va 2 s . c om * @param applicationName * @param counter * @return module * @throws ServiceException */ private Module initNewModule(Module module, String applicationName, int counter) throws ServiceException { try { Long nbInstance = imageService.countNumberOfInstances(module.getName(), applicationName, module.getApplication().getUser().getLogin()); Long counterGlobal = (nbInstance.longValue() == 0 ? 1L : (nbInstance + counter)); try { String containerName = AlphaNumericsCharactersCheckUtils .convertToAlphaNumerics(module.getApplication().getUser().getLogin()) + "-" + AlphaNumericsCharactersCheckUtils.convertToAlphaNumerics( module.getApplication().getName()) + "-" + module.getName() + "-" + counterGlobal; logger.info("containerName generated : " + containerName); Module moduleTemp = moduleDAO.findByName(containerName); if (moduleTemp == null) { module.setName(containerName); } else { initNewModule(module, applicationName, counter + 1); } } catch (UnsupportedEncodingException e1) { throw new ServiceException("Error renaming container", e1); } } catch (ServiceException e) { throw new ServiceException(e.getLocalizedMessage(), e); } return module; }
From source file:fr.treeptik.cloudunit.service.impl.ModuleServiceImpl.java
@Override @Transactional// w w w .ja v a2 s .co m public Module update(Module module) throws ServiceException { logger.debug("update : Methods parameters : " + module.toString()); logger.info("ModuleService : Starting updating Module " + module.getName()); try { module = moduleDAO.save(module); } catch (PersistenceException e) { module.setStatus(Status.FAIL); module = this.saveInDB(module); logger.error("ModuleService Error : update Module" + e); throw new ServiceException(e.getLocalizedMessage(), e); } logger.info("ModuleService : Module " + module.getName() + " successfully updated."); return module; }
From source file:fr.treeptik.cloudunit.service.impl.ModuleServiceImpl.java
@Override @Transactional//from ww w .j a v a2 s.com public Module startModule(Module module) throws ServiceException { logger.debug("start : Methods parameters : " + module); logger.info("Module : Starting module " + module.getName()); Map<String, String> forwardedPorts = new HashMap<>(); Application application = module.getApplication(); try { DockerContainer dockerContainer = new DockerContainer(); DockerContainer dataDockerContainer = new DockerContainer(); dockerContainer.setName(module.getName()); dockerContainer.setPorts(forwardedPorts); dockerContainer.setImage(module.getImage().getName()); if (module.getImage().getImageType().equals("module")) { dockerContainer.setVolumesFrom(module.getVolumesFrom()); } if (module.getImage().getName().contains("git")) { dockerContainer.setPortBindings("22/tcp", "0.0.0.0", module.getSshPort()); } DockerContainer.start(dockerContainer, application.getManagerIp()); dockerContainer = DockerContainer.findOne(dockerContainer, application.getManagerIp()); if (module.getImage().getImageType().equals("module")) { dataDockerContainer.setName(module.getName() + "-data"); DockerContainer.start(dataDockerContainer, application.getManagerIp()); } module = containerMapper.mapDockerContainerToModule(dockerContainer, module); // Unsubscribe module manager module.getModuleAction().updateModuleManager(hipacheRedisUtils); } catch (PersistenceException e) { module.setStatus(Status.FAIL); module = this.saveInDB(module); logger.error("ModuleService Error : fail to start Module" + e); throw new ServiceException(e.getLocalizedMessage(), e); } catch (DockerJSONException e) { module.setStatus(Status.FAIL); module = this.saveInDB(module); logger.error("ModuleService Error : fail to start Module " + e); throw new ServiceException(e.getLocalizedMessage(), e); } return module; }
From source file:fr.treeptik.cloudunit.service.impl.ModuleServiceImpl.java
@Override @Transactional/*from w ww . j a v a 2s. com*/ public Module stopModule(Module module) throws ServiceException { try { Application application = module.getApplication(); DockerContainer dockerContainer = new DockerContainer(); dockerContainer.setName(module.getName()); dockerContainer.setImage(module.getImage().getName()); DockerContainer.stop(dockerContainer, application.getManagerIp()); dockerContainer = DockerContainer.findOne(dockerContainer, application.getManagerIp()); module.setDockerState(dockerContainer.getState()); module.setStatus(Status.STOP); module = this.update(module); } catch (DataAccessException e) { module.setStatus(Status.FAIL); module = this.saveInDB(module); throw new ServiceException(e.getLocalizedMessage(), e); } catch (DockerJSONException e) { module.setStatus(Status.FAIL); module = this.saveInDB(module); logger.error("Fail to stop Module" + e); throw new ServiceException(e.getLocalizedMessage(), e); } return module; }
From source file:org.cruxframework.crux.core.rebind.module.Modules.java
/** * @param module/*from ww w. ja va 2s. c o m*/ * @param screenID * @param moduleRootLocation * @return */ private String getRelativeScreenId(Module module, String screenID, URL moduleRootLocation) { String locationStr = moduleRootLocation.toString(); if (screenID.startsWith(locationStr)) { screenID = screenID.substring(locationStr.length()); } else { URL webDir = ClassPathResolverInitializer.getClassPathResolver().findWebBaseDir(); String webDirStr = webDir.toString(); if (screenID.startsWith(webDirStr)) { screenID = screenID.substring(webDirStr.length()); } int index = screenID.indexOf("/"); if (index > 0) { String possibleModule = screenID.substring(0, index); if (possibleModule.equals(module.getName())) { screenID = screenID.substring(index + 1); } } } if (screenID.startsWith("/")) { screenID = screenID.substring(1); } for (String publicPath : module.getPublicPaths()) { if (screenID.startsWith(publicPath)) { screenID = screenID.substring(publicPath.length()); break; } } if (screenID.startsWith("/")) { screenID = screenID.substring(1); } if (screenID.endsWith(".crux.xml")) { screenID = screenID.substring(0, screenID.length() - 9) + ".html"; } return screenID; }
From source file:fr.treeptik.cloudunit.service.impl.ModuleServiceImpl.java
public Module restoreBackup(String moduleName) throws ServiceException { Module module = this.findByName(moduleName); logger.debug("restoreBackup of module : : " + module); String scriptHostPath = "/vagrant_cloudunit/cu-services/scriptHost/"; String dataContainerName = module.getName() + "-data"; logger.info("logger.ModuleService : Starting finding data container for " + dataContainerName); Application application = module.getApplication(); DockerContainer dataContainer = new DockerContainer(); dataContainer.setName(dataContainerName); try {/* w ww. j ava2 s . co m*/ dataContainer = DockerContainer.findOne(dataContainer, application.getManagerIp()); } catch (DockerJSONException e) { module.setStatus(Status.FAIL); this.saveInDB(module); logger.error("ModuleService Error : Create Module" + e); throw new ServiceException("Error docker : " + e.getLocalizedMessage(), e); } Map<String, String> configShell = new HashMap<>(); configShell.put("port", "22"); configShell.put("dockerManagerAddress", application.getManagerIp()); String command; try { command = "expect " + scriptHostPath + "restoreBackupExpect.sh " + module.getName() + " " + module.getModuleInfos().get("username") + " " + module.getModuleInfos().get("password") + " " + module.getApplication().getName() + " " + module.getApplication().getUser().getPassword(); shellUtils.executeShell(command, configShell); logger.info(command); DockerContainer dockerContainer = new DockerContainer(); dockerContainer.setName(module.getName()); dockerContainer.setImage(module.getImage().getName()); dockerContainer = DockerContainer.findOne(dockerContainer, application.getManagerIp()); module = containerMapper.mapDockerContainerToModule(dockerContainer, module); this.update(module); hipacheRedisUtils.updatedAdminAddress(application, application.getManagerIp(), module.getListPorts().get("80/tcp"), module.getImage().getManagerName(), Long.parseLong(module.getName().substring(module.getName().lastIndexOf("-") + 1))); } catch (DockerJSONException e) { application.setStatus(Status.FAIL); logger.error("ServerService Error : fail to start server" + e); throw new ServiceException(e.getLocalizedMessage(), e); } return module; }
From source file:fr.treeptik.cloudunit.service.impl.ModuleServiceImpl.java
@Override @Transactional//from w w w .j av a 2s.c o m public Module remove(Application application, User user, Module module, Boolean isModuleRemoving, Status previousApplicationStatus) throws ServiceException, CheckException { logger.debug( "remove : Methods parameters : " + module.getName() + " applicationName " + application.getName()); try { logger.info("Module to remove : " + module); logger.info("From application : " + application); // Unsubscribe module manager module.getModuleAction().unsubscribeModuleManager(hipacheRedisUtils); // Delete container in docker DockerContainer dockerContainer = new DockerContainer(); dockerContainer.setName(module.getName()); dockerContainer.setImage(module.getImage().getName()); String imageId = ""; if (module.getName().contains("git")) { imageId = DockerContainer.findOneWithImageID(dockerContainer, application.getManagerIp()) .getImageID(); } else { DockerContainer dataContainer = new DockerContainer(); dataContainer.setName(dockerContainer.getName() + "-data"); imageId = DockerContainer.findOneWithImageID(dataContainer, application.getManagerIp()) .getImageID(); } if (module.getStatus().equals(Status.START)) { DockerContainer.stop(dockerContainer, application.getManagerIp()); } DockerContainer.remove(dockerContainer, application.getManagerIp()); try { if (application.isAClone()) { DockerContainer.deleteImage(imageId, application.getManagerIp()); } } catch (DockerJSONException e) { logger.info("Others apps use this docker images"); } // Delete in database if (isModuleRemoving) { for (Server server : application.getServers()) { Map<String, String> configShell = new HashMap<>(); // On redmarre temporairement les containers Server et // Module pour lancer les scripts via SSH if (previousApplicationStatus.equals(Status.STOP)) { serverService.startServer(server); application.setStatus(Status.STOP); application = applicationDAO.save(application); } configShell.put("port", server.getSshPort()); configShell.put("dockerManagerAddress", application.getManagerIp()); configShell.put("password", server.getApplication().getUser().getPassword()); String command; Integer exitCode1; command = "sh /cloudunit/scripts/rmDBEnvVar.sh " + module.getInstanceNumber(); int counter = 0; while (!server.getStatus().equals(Status.START)) { if (counter == 100) { break; } Thread.sleep(1000); logger.info(" wait server sshd processus start"); logger.info("SSHDSTATUS = server : " + server.getStatus()); server = serverService.findById(server.getId()); counter++; } logger.info("command shell to execute [" + command + "]"); exitCode1 = shellUtils.executeShell(command, configShell); if (exitCode1 != 0) { server.setStatus(Status.FAIL); serverService.saveInDB(server); logger.error("Error : Error during reset module's parameters of server - exitCode1 = " + exitCode1); throw new ServiceException( "Error : Error during reset module's parameters of server - exitCode1 = " + exitCode1, null); } if (previousApplicationStatus.equals(Status.STOP)) { serverService.stopServer(server); application.setStatus(Status.STOP); } } } moduleDAO.delete(module); logger.info("ModuleService : Module successfully removed "); } catch (PersistenceException e) { module.setStatus(Status.FAIL); throw new ServiceException("Error database : failed to remove " + module.getName(), e); } catch (DockerJSONException e) { throw new ServiceException("Error docker : " + e.getLocalizedMessage(), e); } catch (InterruptedException e) { //todo logger.error(e.getMessage()); } return module; }
From source file:fr.treeptik.cloudunit.service.impl.ModuleServiceImpl.java
/** * check if the status passed in parameter is the as in db if it's case a * checkException is throws//from w w w . jav a 2 s .co m * * @throws ServiceException CheckException */ @Override public void checkStatus(Module module, String status) throws CheckException, ServiceException { logger.info("--CHECK APP STATUS--"); if (module.getStatus().name().equalsIgnoreCase(status)) { if (module.getStatus().name().equalsIgnoreCase(status)) { throw new CheckException("Error : Module " + module.getName() + " is already " + status + "ED"); } } }
From source file:org.pentaho.reporting.libraries.base.boot.PackageManager.java
/** * Tries to load a given module and all dependent modules. If the dependency check fails for that module (or for one * of the dependent modules), the loaded modules are discarded and no action is taken. * * @param moduleInfo the module info of the module that should be loaded. * @param incompleteModules a list of incompletly loaded modules. This are module specifications which depend on the * current module and wait for the module to be completly loaded. * @param modules the list of previously loaded modules for this module. * @param fatal a flag that states, whether the failure of loading a module should be considered an error. * Root-modules load errors are never fatal, as we try to load all known modules, regardless * whether they are active or not. * @return true, if the module was loaded successfully, false otherwise. *//*ww w . j av a2s .c o m*/ private boolean loadModule(final ModuleInfo moduleInfo, final ArrayList<Module> incompleteModules, final ArrayList<Module> modules, final boolean fatal) { try { final Module module = ObjectUtilities.loadAndInstantiate(moduleInfo.getModuleClass(), booter.getClass(), Module.class); if (module == null) { if (fatal) { LOGGER.warn("Unresolved dependency for package: " + moduleInfo.getModuleClass()); } LOGGER.debug("Module class referenced, but not in classpath: " + moduleInfo.getModuleClass()); return false; } if (acceptVersion(moduleInfo, module) == false) { // module conflict! LOGGER.warn("Module " + module.getName() + ": required version: " + moduleInfo + ", but found Version: \n" + module); final PackageState state = new PackageState(module, PackageState.STATE_ERROR); dropFailedModule(state); return false; } final int moduleContained = containsModule(modules, module); if (moduleContained == RETURN_MODULE_ERROR) { // the module caused harm before ... LOGGER.debug("Indicated failure for module: " + module.getModuleClass()); final PackageState state = new PackageState(module, PackageState.STATE_ERROR); dropFailedModule(state); return false; } else if (moduleContained == RETURN_MODULE_UNKNOWN) { if (incompleteModules.contains(module)) { // we assume that loading will continue ... LOGGER.error( "Circular module reference: This module definition is invalid: " + module.getClass()); final PackageState state = new PackageState(module, PackageState.STATE_ERROR); dropFailedModule(state); return false; } incompleteModules.add(module); final ModuleInfo[] required = module.getRequiredModules(); for (int i = 0; i < required.length; i++) { if (loadModule(required[i], incompleteModules, modules, true) == false) { LOGGER.debug("Indicated failure for module: " + module.getModuleClass()); final PackageState state = new PackageState(module, PackageState.STATE_ERROR); dropFailedModule(state); return false; } } final ModuleInfo[] optional = module.getOptionalModules(); for (int i = 0; i < optional.length; i++) { if (loadModule(optional[i], incompleteModules, modules, true) == false) { LOGGER.debug("Optional module: " + optional[i].getModuleClass() + " was not loaded."); } } // maybe a dependent module defined the same base module ... if (containsModule(modules, module) == RETURN_MODULE_UNKNOWN) { modules.add(module); } incompleteModules.remove(module); } return true; } catch (Exception e) { LOGGER.warn("Exception while loading module: " + moduleInfo, e); return false; } }
From source file:fr.treeptik.cloudunit.service.impl.ModuleServiceImpl.java
/** * Create module in docker (Not in DB)/*from w w w . j a v a2 s . co m*/ * * @param module * @return * @throws ServiceException * @throws CheckException */ @Transactional private Module create(Application application, Module module, String tagName) throws ServiceException, CheckException { logger.debug("create : Methods parameters : " + module); logger.info("logger.ModuleService : Starting creating Module " + module.getName()); // Nommage du module - Mthode recursive, on part de 1 module = initNewModule(module, application.getName(), 1); DockerContainer dataDockerContainer = new DockerContainer(); if (module.getImage().getImageType().equals("module") & !module.getName().contains("git")) { dataDockerContainer = this.createAndStartDataContainer(module, module.getName(), tagName); } String imagePath = module.getImage().getPath(); if (logger.isDebugEnabled()) { logger.info("imagePath:" + imagePath); } // si le tag n'est pas nul on rcupre la bonne image pour git if (tagName != null & module.getImage().getName().contains("git")) { imagePath = "localhost:5000/cloudunit/git" + tagName.replace(":", "") + tagName; } DockerContainer dockerContainer = new DockerContainer(); // Dfinition des paramtres Docker du container dockerContainer = DockerContainerBuilder.dockerContainer().withName(module.getName()).withImage(imagePath) .withMemory(0L).withMemorySwap(0L).build(); module.getModuleAction().initModuleInfos(); if (tagName != null & !module.getImage().getName().contains("git")) { List<String> commandesSpe = new ArrayList<>(); Snapshot snapshot = snapshotService.findOne(tagName.split("-")[1], application.getUser().getLogin()); Map<String, String> map = new HashMap<>(); for (String key : snapshot.getAppConfig().keySet()) { if (key.equalsIgnoreCase( module.getImage().getPath() + "-" + module.getInstanceNumber() + "-data")) { if (logger.isDebugEnabled()) { logger.debug("KEY : " + key); logger.debug("MODULE : " + module.getImage().getPath() + "-" + module.getInstanceNumber() + "-data"); } map.put("username", snapshot.getAppConfig().get(key).getProperties() .get("username-" + module.getImage().getName())); map.put("password", snapshot.getAppConfig().get(key).getProperties() .get("password-" + module.getImage().getName())); } } commandesSpe.addAll(module.getModuleAction().createDockerCmdForClone(map, databasePassword, envExec)); dockerContainer.setCmd(commandesSpe); } else { dockerContainer.setCmd(module.getModuleAction().createDockerCmd(databasePassword, envExec)); } try { DockerContainer.create(dockerContainer, application.getManagerIp()); dockerContainer = DockerContainer.findOne(dockerContainer, application.getManagerIp()); if (module.getImage().getImageType().equals("module")) { List<String> volumesFrom = new ArrayList<>(); volumesFrom.add(dataDockerContainer.getName()); volumesFrom.add("java"); dockerContainer.setVolumesFrom(volumesFrom); } if (module.getImage().getName().contains("git")) { dockerContainer.setPortBindings("22/tcp", "0.0.0.0", module.getSshPort()); dockerContainer.setVolumesFrom(Arrays.asList("java")); } dockerContainer = DockerContainer.start(dockerContainer, application.getManagerIp()); dockerContainer = DockerContainer.findOne(dockerContainer, application.getManagerIp()); module = containerMapper.mapDockerContainerToModule(dockerContainer, module); if (module.getApplication().getStatus().equals(Status.STOP)) { DockerContainer.stop(dockerContainer, application.getManagerIp()); module.setStatus(Status.STOP); } if (module.getApplication().getStatus().equals(Status.START) || module.getApplication().getStatus().equals(Status.PENDING)) { module.setStatus(Status.START); } module = this.update(module); } catch (DockerJSONException e) { module.setStatus(Status.FAIL); this.saveInDB(module); logger.error("ModuleService Error : Create Module " + e); throw new ServiceException("Error docker : " + e.getLocalizedMessage(), e); } logger.info("ModuleService : Module " + module.getName() + " successfully created."); return module; }