List of usage examples for java.lang Module getName
public String getName()
From source file:fr.treeptik.cloudunit.service.impl.ApplicationServiceImpl.java
/** * Remove an application/*from www . j a v a2s .c o m*/ * * @param application * @param user * @return * @throws ServiceException */ @Override @Transactional public Application remove(Application application, User user) throws ServiceException, CheckException { try { logger.info("Starting removing application " + application.getName()); // Delete all modules List<Module> listModules = application.getModules(); for (Module module : listModules) { try { moduleService.remove(application, user, module, false, application.getStatus()); } catch (ServiceException | CheckException e) { application.setStatus(Status.FAIL); logger.error("ApplicationService Error : failed to remove module " + module.getName() + " for application " + application.getName() + " : " + e); e.printStackTrace(); } } // Delete all alias List<String> aliases = new ArrayList<>(); aliases.addAll(application.getAliases()); for (String alias : aliases) { removeAlias(application, alias); } // Delete all servers List<Server> listServers = application.getServers(); for (Server server : listServers) { serverService.remove(server.getName()); if (listServers.indexOf(server) == listServers.size() - 1) { hipacheRedisUtils.removeRedisAppKey(application); applicationDAO.delete(server.getApplication()); portUtils.releaseProxyPorts(application); } } logger.info("ApplicationService : Application successfully removed "); } catch (PersistenceException e) { setStatus(application, Status.FAIL); logger.error("ApplicationService Error : failed to remove " + application.getName() + " : " + e); throw new ServiceException(e.getLocalizedMessage(), e); } catch (ServiceException e) { setStatus(application, Status.FAIL); logger.error( "ApplicationService Error : failed to remove application " + application.getName() + " : " + e); } return application; }
From source file:fr.treeptik.cloudunit.service.impl.ModuleServiceImpl.java
private void restoreDataModule(Module module) { Application application;// w w w .j av a2 s . co m try { Thread.sleep(5000); application = applicationService.findByNameAndUser(module.getApplication().getUser(), module.getApplication().getName()); DockerContainer dockerContainer = new DockerContainer(); dockerContainer.setName(module.getName() + "-data"); dockerContainer = DockerContainer.findOne(dockerContainer, application.getManagerIp()); Map<String, String> configShell = new HashMap<>(); configShell.put("port", dockerContainer.getPorts().get("22/tcp")); configShell.put("dockerManagerAddress", application.getManagerIp()); String rootPassword = module.getApplication().getUser().getPassword(); configShell.put("password", rootPassword); int code = shellUtils.executeShell("/cloudunit/scripts/restore-data.sh", configShell); logger.info("The backup script return : " + code); } catch (ServiceException | CheckException | DockerJSONException | InterruptedException e) { logger.error("" + module, e); } }
From source file:fr.treeptik.cloudunit.service.impl.ApplicationServiceImpl.java
public List<ContainerUnit> listContainers(String applicationName, boolean withModules) throws ServiceException { List<ContainerUnit> containers = new ArrayList<>(); try {//from w w w.j a v a2 s . c o m Application application = findByNameAndUser(authentificationUtils.getAuthentificatedUser(), applicationName); if (application != null) { try { // Serveurs List<Server> servers = application.getServers(); // Ajout des containers de type server for (Server server : servers) { DockerContainer dockerContainer = new DockerContainer(); dockerContainer.setName(server.getName()); dockerContainer = DockerContainer.findOne(dockerContainer, application.getManagerIp()); server = containerMapper.mapDockerContainerToServer(dockerContainer, server); ContainerUnit containerUnit = new ContainerUnit(server.getName(), server.getContainerID(), "server"); containers.add(containerUnit); } if (withModules) { // Ajout des containers de type module List<Module> modules = application.getModules(); for (Module module : modules) { // on evite de remonter les modules de type toolkit // (git, maven...) if (module.isTool()) { continue; } DockerContainer dockerContainer = new DockerContainer(); dockerContainer.setName(module.getName()); dockerContainer = DockerContainer.findOne(dockerContainer, application.getManagerIp()); module = containerMapper.mapDockerContainerToModule(dockerContainer, module); ContainerUnit containerUnit = new ContainerUnit(module.getName(), module.getContainerID(), "module"); containers.add(containerUnit); } } } catch (Exception ex) { // Si une application sort en erreur, il ne faut pas // arrter la suite des traitements logger.error(application.toString(), ex); } } } catch (Exception e) { throw new ServiceException(e.getLocalizedMessage(), e); } return containers; }
From source file:com.powermonitor.epitech.ConfigModules.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstance) { View v = inflater.inflate(R.layout.configmodules, container, false); getActivity().setTitle("Modules"); // Create list view this.consult = (Button) v.findViewById(R.id.consulter); this.listView = (ListView) v.findViewById(R.id.ConfigModules_modulesListView); this.adapter = new ModuleListAdapter(v.getContext(), R.layout.modulerow, dataList); this.adapter.setToggleVisibility(true); this.listView.setAdapter(adapter); registerForContextMenu(this.listView); try {// www . j a v a2 s. c o m JSONArray list = modulesList.getJSONArray("modules"); for (int i = 0; i < list.length(); i++) { JSONObject o = list.getJSONObject(i); JSONObject defaultProfile = o.optJSONObject("defaultProfile"); int internalProfileID = o.getInt("internalProfileId"); Profile.Small defProfile; if (defaultProfile == null) { defProfile = new Profile.Small(0, ""); } else { defProfile = new Profile.Small(defaultProfile.getInt("id"), defaultProfile.getString("name")); } Module m = new Module(o.getInt("id"), o.getString("name"), defProfile, o.getBoolean("status")); m.setInternalProfileId(internalProfileID); dataList.add(m); } } catch (JSONException ex) { Logger.getLogger(Communication.class.getName()).log(Level.SEVERE, null, ex); } this.adapter.setOnItemCheckedListener(new ModuleListAdapter.OnItemCheckedListener() { @Override public void onItemsChecked(List<Module> list) { checkedItems = list; if (list.size() > 0) consult.setVisibility(View.VISIBLE); else consult.setVisibility(View.GONE); } }); this.consult.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { JSONArray arr = new JSONArray(); if (checkedItems != null) { for (Module m : checkedItems) { JSONObject obj = new JSONObject(); try { obj.put("name", m.getName()); obj.put("id", m.id); arr.put(obj); } catch (JSONException e) { e.printStackTrace(); } } } Intent i = new Intent(ConfigModules.this.getActivity(), ViewModules.class); i.putExtra("ModulesID", arr.toString()); startActivity(i); } }); return v; }
From source file:fr.treeptik.cloudunit.service.impl.ModuleServiceImpl.java
@Transactional private Module createAndAffectModuleValues(Application application, Module module, String tagName) throws ServiceException, CheckException { try {/*ww w .java2 s .c om*/ // user = userService.findById(user.getId()); module.setImage(imageService.findByName(module.getImage().getName())); // Create container module in docker module = this.create(application, module, tagName); Long instanceNumber = module.getInstanceNumber(); // Add extra properties module.setStartDate(new Date()); module.setInternalDNSName(module.getName() + "." + module.getImage().getName() + ".cloud.unit"); this.addModuleManager(module, instanceNumber); // save module in DB module = this.update(module); } catch (ServiceException e) { module.setStatus(Status.FAIL); logger.error(application.toString() + module.toString(), e); throw new ServiceException(e.getLocalizedMessage(), e); } return module; }
From source file:org.openmrs.module.ModuleFactory.java
/** * Try to start all of the loaded modules that have the global property <i>moduleId</i>.started * is set to "true" or the property does not exist. Otherwise, leave it as only "loaded"<br> * <br>//from ww w .ja v a2 s . c o m * Modules that are already started will be skipped. */ public static void startModules() { // loop over and try starting each of the loaded modules if (getLoadedModules().size() > 0) { try { List<Module> modules = getModulesThatShouldStart(); modules = getModulesInStartupOrder(modules); // try and start the modules that should be started for (Module mod : modules) { if (mod.isStarted()) { continue; // skip over modules that are already started } // Skip module if required ones are not started if (!requiredModulesStarted(mod)) { String message = getFailedToStartModuleMessage(mod); log.error(message); mod.setStartupErrorMessage(message); notifySuperUsersAboutModuleFailure(mod); continue; } try { if (log.isDebugEnabled()) { log.debug("starting module: " + mod.getModuleId()); } startModule(mod); } catch (Exception e) { log.error("Error while starting module: " + mod.getName(), e); mod.setStartupErrorMessage("Error while starting module", e); notifySuperUsersAboutModuleFailure(mod); } } } catch (CycleException e) { String message = getCyclicDependenciesMessage(); log.error(message); notifySuperUsersAboutCyclicDependencies(); } } }
From source file:de.juwimm.cms.content.modules.ModuleFactoryStandardImpl.java
/** * Parses the specified {@code propertyNodes} and prepares the information, * calls {@see Module#setCustomProperties(String, Properties)} * /*w w w .ja v a 2s. c om*/ * @see ModuleFactory#setCustomProperties(Module, java.util.Iterator) */ public void setCustomProperties(Module module, Iterator propertyNodes) { try { Element property; while (propertyNodes.hasNext()) { property = (Element) propertyNodes.next(); String propertyname = property.getAttribute("name"); Properties prop = new Properties(); Iterator pi = XercesHelper.findNodes(property, "./*"); Node propParameter; while (pi.hasNext()) { propParameter = (Element) pi.next(); String propVal = ""; if (propParameter.getNodeName().equalsIgnoreCase("properties")) { propVal = XercesHelper.node2string(propParameter); } else { propVal = XercesHelper.getNodeValue(propParameter); } prop.setProperty(propParameter.getNodeName(), propVal); } module.setCustomProperties(propertyname, prop); } module.setCustomProperties("CustomConfigurationReady", new Properties()); } catch (Exception exe) { log.error("Error setting custom properties", exe); } if (log.isDebugEnabled()) log.debug("SetModuleParameters end " + module.getName()); }
From source file:fr.treeptik.cloudunit.service.impl.ModuleServiceImpl.java
/** * Creation d'un container contenant uniquement les donnes lies au * container mysql//from w ww . j av a 2 s .c om * * @param module * @param containerName * @param tagName * @return * @throws ServiceException * @throws CheckException */ @Transactional private DockerContainer createAndStartDataContainer(Module module, String containerName, String tagName) throws ServiceException, CheckException { String imagePath = module.getImage().getPath() + "-data"; if (tagName != null) { imagePath = "localhost:5000/" + imagePath.replaceAll("-data", "-" + module.getInstanceNumber() + "-data") + tagName + ":" + tagName; } Application application = module.getApplication(); String dataContainerName = containerName + "-data"; logger.debug("create : Methods parameters : " + module + " -- " + application + " -- containerName = " + containerName); logger.info("logger.ModuleService : Starting creating data container for " + module.getName()); Map<String, String> ports = new HashMap<String, String>(); logger.debug("imagePath:" + imagePath); DockerContainer dataContainer = DockerContainerBuilder.dockerContainer().withName(dataContainerName) .withImage(imagePath).withMemory(0L).withMemorySwap(0L).withPorts(ports) .withCmd(Arrays.asList("/bin/sh", "/cloudunit/scripts/start-service.sh", module.getApplication().getUser().getLogin(), module.getApplication().getUser().getPassword())) .build(); try { DockerContainer.create(dataContainer, application.getManagerIp()); dataContainer = DockerContainer.findOne(dataContainer, application.getManagerIp()); /** * Cration du volume entre l'hte et le dossier de destination du * tar de /cloudunit/database un crontab fera un tar toutes les * heures de /cloudunit/database vers /cloudunit/backup ce tar sera * accessible directement sur l'hte mme si le container est * supprim. */ DockerContainer.start(dataContainer, application.getManagerIp()); dataContainer = DockerContainer.findOne(dataContainer, application.getManagerIp()); if (tagName != null) { this.restoreDataModule(module); } } catch (DockerJSONException e) { module.setStatus(Status.FAIL); module = this.saveInDB(module); logger.error("ModuleService Error : Create data container" + e); throw new ServiceException("Error docker : " + e.getLocalizedMessage(), e); } return dataContainer; }
From source file:org.cruxframework.crux.core.rebind.module.Modules.java
/** * /*from ww w. ja va 2 s . c o m*/ * @param templateId * @param template */ protected Module registerModule(URL moduleDescriptor, String moduleFullName, Document moduleDocument) { Module module; ; if (moduleAliases.containsKey(moduleFullName)) { module = getModuleEager(moduleFullName); try { if (!URLUtils.isIdenticResource(moduleDescriptor, module.getDescriptorURL(), moduleFullName + ".gwt.xml")) { throw new ModuleException( "Duplicated module descriptor. Module [" + moduleFullName + "] is already registered."); } } catch (Exception e) { logger.error("Erro : moduleName[" + moduleFullName + "], module=" + module, e); } } else { module = new Module(); Element element = moduleDocument.getDocumentElement(); module.setFullName(moduleFullName); module.setName(getModuleName(moduleFullName, element)); module.setSources(getModuleSources(element)); module.setPublicPaths(getModulePublicPaths(element)); module.setRootPath(getModuleRootPath(moduleFullName)); module.setInherits(getModuleInherits(element)); module.setDescriptorURL(moduleDescriptor); URL location = module.getDescriptorURL(); location = URLResourceHandlersRegistry.getURLResourceHandler(location.getProtocol()) .getParentDir(location); module.setLocation(location); modules.put(module.getName(), module); moduleAliases.put(moduleFullName, module.getName()); } return module; }
From source file:fr.treeptik.cloudunit.service.impl.SnapshotServiceImpl.java
@Override @Transactional//from ww w . j a va 2 s . c om public Snapshot create(String applicationName, User user, String tag, String description, Status previousStatus) throws ServiceException, CheckException { Snapshot snapshot = new Snapshot(); ObjectMapper objectMapper = new ObjectMapper(); Application application = applicationService.findByNameAndUser(user, applicationName); if (tagExists(tag, user.getLogin())) { applicationService.setStatus(application, previousStatus); authentificationUtils.allowUser(user); throw new CheckException("this tag already exists"); } if (tag.equalsIgnoreCase("") || tag == null || tag.equalsIgnoreCase(" ")) { applicationService.setStatus(application, previousStatus); authentificationUtils.allowUser(user); throw new CheckException("You must put a tag name"); } try { snapshot.setApplicationName(application.getName()); snapshot.setDate(new Date()); snapshot.setTag(tag); snapshot.setDescription(description); snapshot.setUser(application.getUser()); snapshot.setDeploymentStatus(application.getDeploymentStatus()); Map<String, ModuleConfiguration> config = new HashMap<>(); for (Server server : application.getServers()) { snapshot = server.getServerAction().cloneProperties(snapshot); } for (Module module : application.getModules()) { if (!module.getImage().getPath().contains("git")) { ModuleConfiguration moduleConfiguration = moduleConfigurationDAO .saveAndFlush(module.getModuleAction().cloneProperties()); config.put(moduleConfiguration.getPath(), moduleConfiguration); } } snapshot.setAppConfig(config); // Export des containers : commit + push Thread.sleep(5000); List<String> images = new ArrayList<>(); for (Server server : application.getServers()) { images.add(server.getImage().getPath()); DockerContainer dockerContainer = new DockerContainer(); dockerContainer.setName(server.getName()); dockerContainer.setImage(server.getImage().getName()); String id = (String) (objectMapper.readValue(DockerContainer.commit(dockerContainer, snapshot.getUniqueTagName(), application.getManagerIp(), server.getImage().getPath()), HashMap.class)).get("Id"); DockerContainer.push(server.getImage().getPath(), snapshot.getUniqueTagName(), application.getManagerIp()); DockerContainer.deleteImage(id, application.getManagerIp()); } for (Module module : application.getModules()) { // commentaire de git // if (module.getImage().getPath().contains("git")) { // continue; // } String imageName = ""; String moduleName = ""; if (module.getImage().getPath().contains("git")) { moduleName = module.getName(); imageName = module.getImage().getPath(); } else { moduleName = module.getName() + "-data"; imageName = module.getImage().getPath() + "-" + module.getInstanceNumber() + "-data"; this.backupModule(module); } images.add(imageName); DockerContainer dockerContainer = new DockerContainer(); dockerContainer.setName(moduleName); dockerContainer.setImage(module.getImage().getName()); String id = (String) (objectMapper.readValue(DockerContainer.commit(dockerContainer, snapshot.getUniqueTagName(), application.getManagerIp(), imageName), HashMap.class)) .get("Id"); DockerContainer.push(imageName, snapshot.getUniqueTagName(), application.getManagerIp()); DockerContainer.deleteImage(id, application.getManagerIp()); } snapshot.setImages(images); snapshot = snapshotDAO.save(snapshot); } catch (DockerJSONException | InterruptedException | IOException e) { throw new ServiceException(e.getLocalizedMessage(), e); } return snapshot; }