List of usage examples for org.springframework.dao DataAccessException getLocalizedMessage
public String getLocalizedMessage()
From source file:fr.treeptik.cloudunit.service.impl.SnapshotServiceImpl.java
@Override public List<Snapshot> listAll(String login) throws ServiceException { try {/*from w w w . j a v a 2 s .com*/ return snapshotDAO.listAll(login); } catch (DataAccessException e) { throw new ServiceException("Error : " + e.getLocalizedMessage(), e); } }
From source file:cn.org.once.cstack.service.impl.ModuleServiceImpl.java
@Override @Transactional/*from ww w . j av a2 s. c om*/ public Module stopModule(String moduleName) throws ServiceException { Module module = null; try { module = findByName(moduleName); dockerService.stopContainer(moduleName); applicationEventPublisher.publishEvent(new ModuleStopEvent(module)); } catch (DataAccessException e) { logger.error("[" + moduleName + "] Fail to stop Module : " + moduleName); throw new ServiceException(e.getLocalizedMessage(), e); } return module; }
From source file:fr.treeptik.cloudunit.service.impl.ApplicationServiceImpl.java
@Override public List<String> getListAliases(Application application) throws ServiceException { try {/*from www.ja v a 2s . c o m*/ return applicationDAO.findAllAliases(application.getName()); } catch (DataAccessException e) { throw new ServiceException(e.getLocalizedMessage(), e); } }
From source file:fr.treeptik.cloudunit.service.impl.ApplicationServiceImpl.java
@Override @Transactional//w w w. j a v a 2 s . co m 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); } }
From source file:fr.treeptik.cloudunit.service.impl.ApplicationServiceImpl.java
@Override @Transactional/* ww w .j a v a2s.c o m*/ public void removeAlias(Application application, String alias) throws ServiceException, CheckException { try { hipacheRedisUtils.removeAlias(alias); boolean removed = application.getAliases().remove(alias); if (!removed) { throw new CheckException("Alias [" + alias + "] doesn't exist"); } application = applicationDAO.save(application); } catch (DataAccessException e) { throw new ServiceException(e.getLocalizedMessage(), e); } }
From source file:fr.treeptik.cloudunit.service.impl.ApplicationServiceImpl.java
@Override @Transactional//from w ww . java 2 s . c o m 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); } }
From source file:fr.treeptik.cloudunit.service.impl.ApplicationServiceImpl.java
@Override @Transactional(rollbackFor = ServiceException.class) public Application create(String applicationName, String login, String serverName, String tagName) throws ServiceException, CheckException { // if tagname is null, we prefix with a ":" if (tagName != null) { tagName = ":" + tagName; }//from ww w . j a va2 s. com if (applicationName != null) { applicationName = applicationName.toLowerCase(); } logger.info("--CALL CREATE NEW APP--"); Application application = new Application(); logger.info("applicationName = " + applicationName + ", serverName = " + serverName); User user = authentificationUtils.getAuthentificatedUser(); // For cloning management if (tagName != null) { application.setAClone(true); } application.setName(applicationName); application.setUser(user); application.setModules(new ArrayList<>()); // verify if application exists already this.checkCreate(application, serverName); // todo : use a session flag application.setStatus(Status.PENDING); application = this.saveInDB(application); serverService.checkMaxNumberReach(application); String subdomain = System.getenv("CU_SUB_DOMAIN") == null ? "" : System.getenv("CU_SUB_DOMAIN"); List<Image> imagesEnabled = imageService.findEnabledImages(); List<String> imageNames = new ArrayList<>(); for (Image image : imagesEnabled) { imageNames.add(image.getName()); } if (!imageNames.contains(serverName)) { throw new CheckException(messageSource.getMessage("server.not.found", null, locale)); } try { // BLOC APPLICATION application.setDomainName(subdomain + suffixCloudUnitIO); application = applicationDAO.save(application); application.setManagerIp(dockerManagerIp); application.setJvmRelease(javaVersionDefault); application.setRestHost(restHost); logger.info(application.getManagerIp()); // BLOC SERVER Server server = ServerFactory.getServer(serverName); // We get image associated to server Image image = imageService.findByName(serverName); server.setImage(image); server.setApplication(application); server.setName(serverName); server = serverService.create(server, tagName); List<Server> servers = new ArrayList<>(); servers.add(server); application.setServers(servers); // BLOC MODULE Module moduleGit = this.addGitContainer(application, tagName); application.getModules().add(moduleGit); application.setGitContainerIP(moduleGit.getContainerIP()); // Persistence for Application model application = applicationDAO.save(application); // Copy the ssh key from the server to git container to be able to deploy war with gitpush // During clone processus, env variables are not updated. We must wait for a restart before // to copy the ssh keys for git push if (tagName == null) { this.sshCopyIDToServer(application, user); } } catch (DataAccessException e) { throw new ServiceException(e.getLocalizedMessage(), e); } logger.info("" + application); logger.info("ApplicationService : Application " + application.getName() + " successfully created."); return application; }
From source file:fr.treeptik.cloudunit.service.impl.ModuleServiceImpl.java
@Override @Transactional// w ww . j a v a 2 s . c om 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:com.qut.middleware.deployer.logic.RegisterESOELogic.java
private void configureDataLayer(DeploymentBean bean) throws RegisterESOEException { switch (bean.getDatabaseDriver()) { case mysql://from ww w . j a va2s . c om dataSource.setDriverClassName(Constants.MYSQL_DRIVER); break; case oracle: dataSource.setDriverClassName(Constants.ORACLE_DRIVER); break; /* Attempt to connect to mysql source if not submitted */ default: dataSource.setDriverClassName(Constants.MYSQL_DRIVER); } try { dataSource.setUrl(bean.getDatabaseURL()); dataSource.setUsername(bean.getDatabaseUsername()); dataSource.setPassword(bean.getDatabasePassword()); } catch (DataAccessException e) { this.logger.error("Unable to connect with database " + e.getLocalizedMessage()); this.logger.debug(e.toString()); throw new RegisterESOEException(e.getLocalizedMessage(), e); } }
From source file:edu.mit.isda.permitservice.dataobjects.HibernateAuthorizationMgr.java
/** * retrieves all the Categories in the database * * @return all the {@link Category} in the database * @throws ObjectNotFoundException If no category is found * @throws AuthorizationException in case of hibernate error */// w ww . j av a 2 s . co m @SuppressWarnings("unchecked") public Set<Category> listCategories() throws ObjectNotFoundException, AuthorizationException { List l = null; HibernateTemplate t = getHibernateTemplate(); try { l = t.find("from Category c"); } catch (DataAccessException e) { Exception re = (Exception) e.getCause(); SQLException se = null; if (re instanceof org.hibernate.exception.SQLGrammarException) { se = ((org.hibernate.exception.SQLGrammarException) re).getSQLException(); } else if (e.getCause() instanceof SQLException) { se = (SQLException) e.getCause(); } if (null != se) { int i = se.getErrorCode(); String msg = se.getMessage(); String errorMessage = se.getMessage() + " Error Code: " + se.getErrorCode(); int index = msg.indexOf("\n"); if (index > 0) msg = msg.substring(0, index); throw new AuthorizationException(errorMessage); } else throw new AuthorizationException(e.getLocalizedMessage()); } if (l == null) throw new ObjectNotFoundException("No Categories found in database"); Set<Category> catSet = new HashSet<Category>(l); return catSet; }