Example usage for javax.persistence PersistenceException getLocalizedMessage

List of usage examples for javax.persistence PersistenceException getLocalizedMessage

Introduction

In this page you can find the example usage for javax.persistence PersistenceException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:cn.org.once.cstack.service.impl.ServerServiceImpl.java

@Override
public Server findById(Integer id) throws ServiceException {
    try {//from  w ww .j a  va  2s . c  o  m
        logger.debug("findById : Methods parameters : " + id);
        Server server = serverDAO.findOne(id);
        if (server != null) {
            logger.info("Server with id " + id + " found!");
            logger.info("" + server);
        }
        return server;
    } catch (PersistenceException e) {
        logger.error("Error ServerService : error findById Method : " + e);
        throw new ServiceException("Error database :  " + e.getLocalizedMessage(), e);

    }
}

From source file:fr.treeptik.cloudunit.service.impl.ServerServiceImpl.java

@Override
public List<Server> findByApp(Application application) throws ServiceException {
    try {/*ww  w  .  ja v  a2 s . co  m*/
        return serverDAO.findByApp(application.getId());
    } catch (PersistenceException e) {
        throw new ServiceException("Error database : " + e.getLocalizedMessage(), e);
    }
}

From source file:fr.treeptik.cloudunit.service.impl.ServerServiceImpl.java

@Override
@Transactional/*w  w  w  .j  av  a  2 s  . c om*/
public Server stopServer(Server server) throws ServiceException {
    try {
        Application application = server.getApplication();

        DockerContainer dockerContainer = new DockerContainer();
        dockerContainer.setName(server.getName());
        dockerContainer.setImage(server.getImage().getName());
        DockerContainer.stop(dockerContainer, application.getManagerIp());
        dockerContainer = DockerContainer.findOne(dockerContainer, application.getManagerIp());
        server.setDockerState(dockerContainer.getState());

        server.setStatus(Status.STOP);
        server = this.update(server);
    } catch (PersistenceException e) {
        throw new ServiceException("Error database : " + e.getLocalizedMessage(), e);
    } catch (DockerJSONException e) {
        logger.error("Fail to stop Server : " + e);
        throw new ServiceException("Error docker : " + e.getLocalizedMessage(), e);
    }
    return server;
}

From source file:org.asqatasun.service.command.AuditCommandImpl.java

/**
 * Encode Source code and persist the content list
 * /*from  w ww  .  jav  a  2s. com*/
 * @param contentSet 
 */
private void encodeSourceAndPersistContentList(Set<Content> contentSet) {
    for (Content content : contentSet) {
        if (content instanceof SSP && !((SSP) content).getDOM().isEmpty()) {
            try {
                ((SSP) content).setSource(MD5Encoder.MD5(((SSP) content).getSource()));
            } catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) {
                LOGGER.warn(ex);
            }
        }
        try {
            contentDataService.saveOrUpdate(content);
        } catch (PersistenceException pe) {
            LOGGER.warn(content.getURI() + " could not have been persisted due to " + pe.getLocalizedMessage());
            if (content instanceof SSP && !((SSP) content).getDOM().isEmpty()) {
                ((SSP) content).setDOM("");
                contentDataService.saveOrUpdate(content);
            }
        }
    }
}

From source file:fr.treeptik.cloudunit.service.impl.ServerServiceImpl.java

/**
 * Test if the user can create new server associated to this application
 *
 * @param application/*from w w w  .  ja v a 2 s.c  o  m*/
 * @throws ServiceException
 * @throws CheckException
 */
public void checkMaxNumberReach(Application application) throws ServiceException, CheckException {
    logger.info("check number of server of " + application.getName());
    if (application.getServers() != null) {
        try {
            if (application.getServers().size() >= Integer.parseInt(maxServers)) {
                throw new CheckException(
                        "You have already created your " + maxServers + " server for your application");
            }
        } catch (PersistenceException e) {
            logger.error("ServerService Error : check number of server" + e);
            throw new ServiceException(e.getLocalizedMessage(), e);
        }
    }
}

From source file:fr.treeptik.cloudunit.service.impl.ServerServiceImpl.java

@Override
@Transactional//from   w  w  w.  j a va2 s .  c o m
public Server update(Server server) throws ServiceException {

    logger.debug("update : Methods parameters : " + server.toString());
    logger.info("ServerService : Starting updating Server " + server.getName());
    try {
        server = serverDAO.save(server);

        Application application = server.getApplication();
        String dockerManagerIP = application.getManagerIp();

        hipacheRedisUtils.updateServerAddress(application, server.getContainerIP(),
                server.getServerAction().getServerPort(), server.getServerAction().getServerManagerPort());

    } catch (PersistenceException e) {
        logger.error("ServerService Error : update Server" + e);
        throw new ServiceException("Error database : " + e.getLocalizedMessage(), e);
    }

    logger.info("ServerService : Server " + server.getName() + " successfully updated.");

    return server;
}

From source file:fr.treeptik.cloudunit.service.impl.ServerServiceImpl.java

@Override
@Transactional/*from  w  w  w .  j  a  va 2s .  c  o m*/
public Server startServer(Server server) throws ServiceException {

    logger.debug("start : Methods parameters : " + server);
    logger.info("ServerService : Starting Server " + server.getName());

    try {
        Application application = server.getApplication();

        DockerContainer dockerContainer = new DockerContainer();
        dockerContainer.setName(server.getName());
        dockerContainer.setImage(server.getImage().getName());
        if (server.getPortsToOpen() != null) {
            dockerContainer.setPortsToOpen(server.getPortsToOpen().stream()
                    .map(t -> Integer.parseInt(t.getPort())).collect(Collectors.toList()));
        }
        DockerContainer.start(dockerContainer, application.getManagerIp());
        dockerContainer = DockerContainer.findOne(dockerContainer, application.getManagerIp());
        server = containerMapper.mapDockerContainerToServer(dockerContainer, server);

        String dockerManagerIP = server.getApplication().getManagerIp();
        server.setStartDate(new Date());
        application = applicationDAO.saveAndFlush(application);

        server = this.update(server);

        hipacheRedisUtils.updateServerAddress(server.getApplication(), server.getContainerIP(),
                server.getServerAction().getServerPort(), server.getServerAction().getServerManagerPort());

        // ajout des alias des ports forwards
        final Application effectiveApplication = application;
        final Server effectiveServer = server;
        server.getPortsToOpen().stream().filter(t -> t.getAlias() != null)
                .forEach(t -> hipacheRedisUtils.writeNewAlias(t.getPort(), effectiveApplication,
                        effectiveServer.getListPorts().get(t + "/tcp")));

    } catch (PersistenceException e) {
        logger.error("ServerService Error : fail to start Server" + e);
        throw new ServiceException("Error database :  " + e.getLocalizedMessage(), e);
    } catch (DockerJSONException e) {
        logger.error("ServerService Error : fail to start Server" + e);
        throw new ServiceException("Error docker :  " + e.getLocalizedMessage(), e);
    }
    return server;
}

From source file:fr.treeptik.cloudunit.service.impl.ApplicationServiceImpl.java

@Override
public Long countApp(User user) throws ServiceException {
    try {// ww  w.ja  va2s.  c o  m
        return applicationDAO.countApp(user.getId());
    } catch (PersistenceException e) {
        throw new ServiceException(e.getLocalizedMessage(), e);
    }
}

From source file:fr.treeptik.cloudunit.service.impl.ApplicationServiceImpl.java

/**
 * Method useful for Logs and Monitoring Management
 *
 * @return//from   w  w w  .j  ava  2s.c om
 * @throws ServiceException
 */
@Override
public List<Application> findAll() throws ServiceException {
    try {
        logger.debug("start findAll");
        List<Application> listApplications = applicationDAO.findAll();
        for (Application application : listApplications) {
            application.setServers(serverService.findByApp(application));
            application
                    .setModules(moduleService.findByAppAndUser(application.getUser(), application.getName()));
        }
        logger.debug("ApplicationService : All Applications found ");
        return listApplications;
    } catch (PersistenceException e) {
        logger.error("Error ApplicationService : error findAll Method : " + e);
        throw new ServiceException(e.getLocalizedMessage(), e);
    }
}

From source file:fr.treeptik.cloudunit.service.impl.ApplicationServiceImpl.java

/**
 * Test if the user can create new applications because we limit the number per user
 *
 * @param application//w ww.j ava2  s.co  m
 * @param serverName
 * @throws CheckException
 * @throws ServiceException
 */
@Override
public void checkCreate(Application application, String serverName) throws CheckException, ServiceException {

    logger.debug("--CHECK APP COUNT--");

    if (this.countApp(application.getUser()) >= Integer.parseInt(numberMaxApplications)) {
        throw new ServiceException(
                "You have already created your " + numberMaxApplications + " apps into the Cloud");
    }

    try {
        if (checkAppExist(application.getUser(), application.getName())) {
            throw new CheckException(messageSource.getMessage("app.exists", null, locale));
        }
        if (imageService.findByName(serverName) == null)
            throw new CheckException(messageSource.getMessage("image.not.found", null, locale));
        imageService.findByName(serverName);

    } catch (PersistenceException e) {
        logger.error("ApplicationService Error : Create Application" + e);
        throw new ServiceException(e.getLocalizedMessage(), e);
    }

}