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.ApplicationServiceImpl.java

/**
* Test if the user can create new applications because we limit the number
* per user// www. j  av  a 2  s . c  o  m
*
* @param application
* @throws CheckException
* @throws ServiceException
*/
public void checkCreate(User user, String application) throws CheckException, ServiceException {
    try {
        if (checkAppExist(user, application)) {
            throw new CheckException(application + " already exists !");
        }
        if (checkNameLength(application)) {
            throw new CheckException("This name has length equal to zero : " + application);
        }
    } catch (PersistenceException e) {
        logger.error("ApplicationService Error : Create Application" + e);
        throw new ServiceException(e.getLocalizedMessage(), e);
    }
}

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

@Override
@Transactional// w w  w. j ava 2 s.  c om
public Module startModule(String moduleName) throws ServiceException {
    logger.info("Module : Starting module " + moduleName);
    Module module = null;
    try {
        module = findByName(moduleName);
        module = dockerService.startModule(moduleName, module);
        applicationEventPublisher.publishEvent(new ModuleStartEvent(module));
        if (!module.isInitialized()) {
            module.setInitialized(true);
            module = moduleDAO.save(module);
            applicationEventPublisher
                    .publishEvent(new HookEvent(new Hook(moduleName, RemoteExecAction.MODULE_POST_START_ONCE)));
        }
        applicationEventPublisher
                .publishEvent(new HookEvent(new Hook(moduleName, RemoteExecAction.MODULE_POST_START)));
    } catch (PersistenceException e) {
        logger.error("ModuleService Error : fail to start Module" + moduleName);
        throw new ServiceException(e.getLocalizedMessage(), e);
    }
    return module;
}

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

@Override
public Server findByName(String serverName) throws ServiceException {
    try {//  w  w  w .j a  v  a 2s. c  om
        return serverDAO.findByName(serverName);
    } catch (PersistenceException e) {
        throw new ServiceException("Error database : " + e.getLocalizedMessage(), e);
    }
}

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

@Override
public Server findByApp(Application application) throws ServiceException {
    try {/*from ww w  . ja va  2  s .c o m*/
        return serverDAO.findByApp(application.getId());
    } catch (PersistenceException e) {
        throw new ServiceException("Error database : " + e.getLocalizedMessage(), e);
    }
}

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

@Override
public Server findByContainerID(String id) throws ServiceException {
    try {/*from www .  j a v  a2  s .  co m*/
        return serverDAO.findByContainerID(id);
    } catch (PersistenceException e) {
        throw new ServiceException("Error database : " + e.getLocalizedMessage(), e);
    }
}

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

@Override
@Transactional/*from w w w  . j  a  v a2 s  .  c  o m*/
@CacheEvict("env")
public Module create(String imageName, Application application, User user)
        throws ServiceException, CheckException {

    // General informations
    checkImageExist(imageName);
    Image image = imageService.findByName(imageName);
    checkModuleAlreadyPresent(image.getPrefixEnv(), application.getId());
    Module module = application.addModule(image);

    // Build a custom container
    String containerName = NamingUtils.getContainerName(module.getApplication().getName(),
            module.getImage().getPrefixEnv(), user.getLogin());
    String imagePath = module.getImage().getPath();
    logger.debug("imagePath:" + imagePath);

    try {
        Map<ModuleEnvironmentRole, ModuleEnvironmentVariable> moduleEnvs = getModuleEnvironmentVariables(image,
                application.getName());
        List<String> internalEnvironment = getInternalEnvironment(moduleEnvs);
        List<EnvironmentVariable> exportedEnvironment = getExportedEnvironment(module, image, moduleEnvs);
        environmentService.save(user, exportedEnvironment, application.getName(),
                application.getServer().getName());
        dockerService.createModule(containerName, module, imagePath, user, internalEnvironment, true,
                new ArrayList<>());
        module = dockerService.startModule(containerName, module);
        module = moduleDAO.save(module);
        environmentService.createInDatabase(getInternalEnvironment(module, image, moduleEnvs), containerName,
                application);
        applicationEventPublisher.publishEvent(new ModuleStartEvent(module));
        applicationEventPublisher
                .publishEvent(new HookEvent(new Hook(containerName, RemoteExecAction.MODULE_POST_CREATION)));
    } catch (PersistenceException e) {
        logger.error("ServerService Error : Create Server " + e);
        throw new ServiceException(e.getLocalizedMessage(), e);
    } catch (DockerJSONException e) {
        logger.error("module = {}", module);
        logger.error("Error detail", e);
        throw new ServiceException("Error while creating a module", e);
    }
    return module;
}

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

/**
 * Method useful for Logs and Monitoring Management
 *
 * @return//from  w ww  .j  a  va2  s.  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.setServer(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:cn.org.once.cstack.service.impl.ModuleServiceImpl.java

@Override
@Transactional//  w  w w. j  ava 2  s  . c  o  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 = moduleDAO.save(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:cn.org.once.cstack.service.impl.ServerServiceImpl.java

/**
 * Create a server with or without a tag. Tag parameter is needed for
 * restore processus after cloning The idea is to use the same logic for a
 * new server or another one coming from registry.
 *
 * @param server//ww  w  .  j  a va 2  s .  com
 * @return
 * @throws ServiceException
 * @throws CheckException
 */
@Override
@Transactional
public Server create(Server server) throws ServiceException, CheckException {

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

    // General information
    Application application = server.getApplication();
    User user = server.getApplication().getUser();

    // Build a custom container
    String containerName = NamingUtils.getContainerName(server.getApplication().getName(), null,
            server.getApplication().getUser().getLogin());

    String imagePath = server.getImage().getPath();
    String imageSubType = server.getImage().getImageSubType().toString();
    try {
        dockerService.createServer(containerName, server, imagePath, imageSubType, user, null, true, null);
        server = dockerService.startServer(containerName, server);
        server = serverDAO.saveAndFlush(server);
        // Update server with all its information
        server.setManagerLocation(String.format("http://%s/%s", containerName + domain,
                dockerService.getEnv(server.getName(), "CU_SERVER_MANAGER_PATH")));
        server.setStatus(Status.START);
        server = this.update(server);
    } catch (PersistenceException e) {
        logger.error("ServerService Error : Create Server " + e);
        throw new ServiceException(e.getLocalizedMessage(), e);
    } catch (DockerJSONException e) {
        StringBuilder msgError = new StringBuilder(512);
        msgError.append("server=").append(server);
        logger.error("" + msgError, e);
        throw new ServiceException(msgError.toString(), e);
    }
    logger.info("ServerService : Server " + server.getName() + " successfully created.");
    return server;
}

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

@Override
public List<Server> findAll() throws ServiceException {
    try {/*from   ww w  .  jav  a  2s .c o  m*/
        logger.debug("start findAll");
        List<Server> servers = serverDAO.findAll();
        logger.info("ServerService : All Servers found ");
        return servers;
    } catch (PersistenceException e) {
        logger.error("Error ServerService : error findAll Method : " + e);
        throw new ServiceException("Error database :  " + e.getLocalizedMessage(), e);

    }
}