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:fr.treeptik.cloudunit.service.impl.ModuleServiceImpl.java

@Override
public List<Module> findByApp(Application application) throws ServiceException {
    try {//from  w ww  .  j  a  v  a2 s .co m
        return moduleDAO.findByApp(application.getName());
    } catch (PersistenceException e) {
        logger.error("Error ModuleService : error findByApp Method : " + e);
        throw new ServiceException(e.getLocalizedMessage(), e);
    }
}

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

@Override
public Module findByName(String moduleName) throws ServiceException {
    try {/*from   ww  w .java 2 s  .  co m*/
        logger.debug("findByName : " + moduleName);
        Module module = moduleDAO.findByName(moduleName);
        logger.debug("findByName : " + module);
        return module;
    } catch (PersistenceException e) {
        logger.error("Error ModuleService : error findName Method : " + e);
        throw new ServiceException(e.getLocalizedMessage(), e);
    }
}

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

@Override
public List<Module> findByAppAndUser(User user, String applicationName) throws ServiceException {
    try {//  w  w  w .  j  ava2 s .co  m
        List<Module> modules = moduleDAO.findByAppAndUser(user.getId(), applicationName);
        return modules;
    } catch (PersistenceException e) {
        logger.error("Error ModuleService : error findByAppAndUser Method : " + e);
        throw new ServiceException(e.getLocalizedMessage(), e);
    }

}

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

@Override
public Module findGitModule(String login, Application application) throws ServiceException {
    try {/*from   w  ww.  j a v  a 2 s.co  m*/
        return moduleDAO.findGitModule(login, application.getName());
    } catch (PersistenceException e) {
        logger.error("Error ModuleService : error find git container Method : " + e);
        throw new ServiceException(e.getLocalizedMessage(), e);
    }
}

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

@Override
@Transactional//from  w  ww .ja v a2s.  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 = 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// www. j a va  2 s  .  c o  m
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.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/*from  w  w  w.  ja v a2s  .co  m*/
 * @param tagName
 * @return
 * @throws ServiceException
 * @throws CheckException
 */
@Override
@Transactional
public Server create(Server server, String tagName) throws ServiceException, CheckException {

    String registryPrefix = "";

    if (tagName != null) {
        registryPrefix = "localhost:5000/";
    } else {
        tagName = "";
    }

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

    // Initialize container informations :
    DockerContainer dockerContainer = new DockerContainer();
    Map<String, String> ports = new HashMap<String, String>();

    // General informations
    String dockerManagerIP = server.getApplication().getManagerIp();
    server.setStatus(Status.PENDING);
    server.setJvmOptions("");
    server.setStartDate(new Date());

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

    // Build a custom container
    String containerName = "";
    try {
        containerName = AlphaNumericsCharactersCheckUtils.convertToAlphaNumerics(user.getLogin()) + "-"
                + AlphaNumericsCharactersCheckUtils.convertToAlphaNumerics(server.getApplication().getName())
                + "-" + server.getName();
    } catch (UnsupportedEncodingException e2) {
        throw new ServiceException("Error rename Serveur", e2);
    }

    String imagePath = registryPrefix + server.getImage().getPath() + tagName.replace(":", "") + tagName;

    logger.debug("imagePath:" + imagePath);

    List<String> volumesFrom = new ArrayList<>();
    volumesFrom.add(server.getImage().getName());
    volumesFrom.add("java");
    dockerContainer = new DockerContainerBuilder().withName(containerName).withImage(imagePath).withMemory(0L)
            .withMemorySwap(0L).withPorts(ports).withVolumesFrom(volumesFrom)
            .withCmd(Arrays.asList(user.getLogin(), user.getPassword(), server.getApplication().getRestHost(),
                    server.getApplication().getName(), "jdk1.7.0_55", databasePassword, envExec))
            .build();

    try {
        // create a container and get informations
        DockerContainer.create(dockerContainer, application.getManagerIp());

        logger.debug("container : " + dockerContainer);

        dockerContainer = DockerContainer.findOne(dockerContainer, application.getManagerIp());

        String subdomain = System.getenv("CU_SUB_DOMAIN");
        if (subdomain == null) {
            subdomain = "";
        }
        logger.info("env.CU_SUB_DOMAIN=" + subdomain);

        server.getApplication().setSuffixCloudUnitIO(subdomain + suffixCloudUnitIO);
        DockerContainer.start(dockerContainer, application.getManagerIp());
        dockerContainer = DockerContainer.findOne(dockerContainer, application.getManagerIp());

        server = containerMapper.mapDockerContainerToServer(dockerContainer, server);
        server = serverDAO.saveAndFlush(server);
        server = ServerFactory.updateServer(server);

        logger.info(server.getServerAction().getServerManagerPath());
        logger.info("" + server.getListPorts());
        logger.info(server.getServerAction().getServerManagerPort());
        logger.info(application.getLocation());

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

        // Update server with all its informations
        server.setManagerLocation("http://manager-" + application.getLocation().substring(7)
                + server.getServerAction().getServerManagerPath());
        server.setStatus(Status.START);
        server.setJvmMemory(512L);
        server.setJvmRelease("jdk1.7.0_55");

        server = this.update(server);

        Thread.sleep(3000);

    } catch (PersistenceException e) {
        logger.error("ServerService Error : Create Server " + e);
        try {
            // Removing a creating container if an error has occurred with
            // the database
            DockerContainer.remove(dockerContainer, application.getManagerIp());
        } catch (DockerJSONException e1) {
            logger.error("ServerService Error : Create Server " + e1);
            throw new ServiceException(e.getLocalizedMessage(), e1);
        }
        throw new ServiceException(e.getLocalizedMessage(), e);
    } catch (DockerJSONException e) {
        StringBuilder msgError = new StringBuilder(512);
        msgError.append("server=").append(server);
        msgError.append(", tagName=[").append(tagName).append("]");
        logger.error("" + msgError, e);
        throw new ServiceException(msgError.toString(), e);
    } catch (InterruptedException e) {
        StringBuilder msgError = new StringBuilder(512);
        msgError.append("server=").append(server);
        msgError.append(", tagName=[").append(tagName).append("]");
        logger.error("" + msgError, e);
    }
    logger.info("ServerService : Server " + server.getName() + " successfully created.");
    return server;
}

From source file:org.opencms.db.jpa.CmsProjectDriver.java

/**
 * @see org.opencms.db.I_CmsProjectDriver#getUsersPubList(org.opencms.db.CmsDbContext, org.opencms.util.CmsUUID)
 *//*from   w w  w  . java2  s  .  com*/
public List<CmsResource> getUsersPubList(CmsDbContext dbc, CmsUUID userId) throws CmsDataAccessException {

    List<CmsResource> result = null;
    try {
        Query q = m_sqlManager.createNativeQuery(dbc, dbc.currentProject().getUuid(),
                C_LOG_READ_PUBLISH_LIST_2);
        q.setParameter(1, userId.toString());
        q.setParameter(2, userId.toString());
        @SuppressWarnings("unchecked")
        List<Object[]> res = q.getResultList();

        result = new ArrayList<CmsResource>();

        Class<?> structureClass;
        Class<?> resourcesClass;
        Object[] obj = new Object[3];

        if (CmsProject.ONLINE_PROJECT_ID.equals(dbc.currentProject().getUuid())) {
            structureClass = CmsDAOOnlineStructure.class;
            resourcesClass = CmsDAOOnlineResources.class;
        } else {
            structureClass = CmsDAOOfflineStructure.class;
            resourcesClass = CmsDAOOfflineResources.class;
        }

        for (Object[] objArray : res) {
            // there are building obj array which should normally 
            // returned by JPQL query
            obj[0] = m_sqlManager.find(dbc, resourcesClass, objArray[0]);
            obj[1] = m_sqlManager.find(dbc, structureClass, objArray[1]);
            obj[2] = ((I_CmsDAOResources) obj[0]).getProjectLastModified();

            CmsResource resource = ((CmsVfsDriver) m_driverManager.getVfsDriver(dbc)).createResource(obj,
                    dbc.currentProject().getUuid());
            long date = ((Number) objArray[2]).longValue();
            resource.setDateLastModified(date);
            result.add(resource);
        }
    } catch (PersistenceException e) {
        throw new CmsDataAccessException(Messages.get().container(Messages.ERR_JPA_PERSITENCE, e), e);
    } catch (Exception e) {
        LOG.error(e.getLocalizedMessage(), e);
    }

    return result;
}

From source file:org.opens.tanaguru.service.command.AuditCommandImpl.java

/**
 * Encode Source code and persist the content list
 * /*  ww w  .  j ava 2  s  .  co m*/
 * @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 ex) {
                LOGGER.warn(ex);
            } catch (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);
            }
        }
    }
}