Search in sources :

Example 1 with JahiaInitializationException

use of org.jahia.exceptions.JahiaInitializationException in project jahia by Jahia.

the class SchedulerService method switchReadOnlyMode.

@Override
@SuppressWarnings("java:S2276")
public synchronized void switchReadOnlyMode(boolean enable) {
    // Suppressing warning about the usage of Thread.sleep as it is exactly the behaviour we desire here.
    // We need to keep the lock on the 'this' monitor to ensure this is the only method running.
    // switch db persisted scheduler read only mode flag
    scheduler.setReadOnly(enable);
    if (enable) {
        logger.info("Entering read-only mode...");
        try {
            logger.info("Putting schedulers to standby...");
            standbySchedulers();
            logger.info("Done putting schedulers to standby");
            logger.info("Waiting for running jobs to complete...");
            long start = System.currentTimeMillis();
            int count = getRunningJobsCount();
            while (count > 0) {
                logger.info("{} job(s) are still running...", count);
                if (System.currentTimeMillis() - start > timeoutSwitchingToReadOnlyMode) {
                    logger.error("Timed out waiting for running jobs to complete.");
                    throw new JahiaRuntimeException("Wait timeout elapsed, jobs are still running");
                }
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    throw new JahiaRuntimeException(e);
                }
                count = getRunningJobsCount();
            }
            logger.info("All running jobs have completed.");
        } catch (SchedulerException e) {
            throw new JahiaRuntimeException(e);
        }
    } else {
        logger.info("Exiting read-only mode...");
        try {
            logger.info("Starting schedulers...");
            startSchedulers();
            logger.info("Done starting schedulers");
        } catch (JahiaInitializationException e) {
            throw new JahiaRuntimeException(e);
        }
    }
}
Also used : JahiaInitializationException(org.jahia.exceptions.JahiaInitializationException) JahiaRuntimeException(org.jahia.exceptions.JahiaRuntimeException)

Example 2 with JahiaInitializationException

use of org.jahia.exceptions.JahiaInitializationException in project jahia by Jahia.

the class JCRStoreProvider method start.

/**
 * Starts this provider if possible, checking its availability before attempting the starting procedure if so requested.
 *
 * @param checkAvailability whether or not to check the availability before attempting the starting procedure
 * @return <code>true</code> if this provider is available or availability checking was not requested, <code>false</code> otherwise.
 * @throws JahiaInitializationException
 */
public boolean start(boolean checkAvailability) throws JahiaInitializationException {
    String tmpAuthenticationType = authenticationType;
    try {
        authenticationType = "shared";
        final boolean available = !checkAvailability || isAvailable();
        if (available && !initialized) {
            getSessionFactory().addProvider(this);
            boolean isProcessingServer = SettingsBean.getInstance().isProcessingServer();
            if (isProcessingServer) {
                initNodeTypes();
            }
            initObservers();
            initialized = true;
            initContent();
            initDynamicMountPoints();
            if (patcher != null && isProcessingServer) {
                patcher.executeScripts("jcrStoreProviderStarted");
            }
        }
        return available;
    } catch (Exception e) {
        logger.error("Couldn't mount provider " + getUrl(), e);
        stop();
        throw new JahiaInitializationException("Couldn't mount provider " + getUrl(), e);
    } finally {
        authenticationType = tmpAuthenticationType;
    }
}
Also used : JahiaInitializationException(org.jahia.exceptions.JahiaInitializationException) NamingException(javax.naming.NamingException) IOException(java.io.IOException) JahiaInitializationException(org.jahia.exceptions.JahiaInitializationException) StaleItemStateException(org.apache.jackrabbit.core.state.StaleItemStateException)

Example 3 with JahiaInitializationException

use of org.jahia.exceptions.JahiaInitializationException in project jahia by Jahia.

the class JahiaContextLoaderListener method contextInitialized.

@Override
public void contextInitialized(ServletContextEvent event) {
    startupTime = System.currentTimeMillis();
    startupWithTrust(Jahia.getBuildNumber());
    logger.info("Starting up Jahia, please wait...");
    servletContext = event.getServletContext();
    Jahia.setContextPath(servletContext.getContextPath());
    initWebAppRoot();
    if (System.getProperty("jahia.config") == null) {
        setSystemProperty("jahia.config", "");
    }
    if (System.getProperty("jahia.license") == null) {
        setSystemProperty("jahia.license", "");
    }
    try {
        // verify supported Java version
        Jahia.verifyJavaVersion(servletContext.getInitParameter("supported_jdk_versions"));
    } catch (JahiaInitializationException e) {
        throw new JahiaRuntimeException(e);
    }
    detectPID(servletContext);
    initializeTemporarySettingsBean();
    Patcher.getInstance().setServletContext(servletContext);
    Patcher.getInstance().executeScripts("beforeContextInitializing");
    // initialize VFS file system (solves classloader issue: https://issues.apache.org/jira/browse/VFS-228 )
    try {
        VFS.getManager();
    } catch (FileSystemException e) {
        throw new JahiaRuntimeException(e);
    }
    try {
        long timer = System.currentTimeMillis();
        logger.info("Start initializing Spring root application context");
        running = true;
        super.contextInitialized(event);
        logger.info("Spring Root application context initialized in {} ms", (System.currentTimeMillis() - timer));
        // initialize services registry
        ServicesRegistry.getInstance().init();
        // fire Spring event that the root context is initialized
        WebApplicationContext rootCtx = ContextLoader.getCurrentWebApplicationContext();
        rootCtx.publishEvent(new RootContextInitializedEvent(rootCtx));
        boolean isProcessingServer = SettingsBean.getInstance().isProcessingServer();
        // execute patches after root context initialization
        if (isProcessingServer) {
            Patcher.getInstance().executeScripts("rootContextInitialized");
        }
        // start OSGi container
        FrameworkService.getInstance().start();
    } catch (JahiaException e) {
        running = false;
        logger.error(e.getMessage(), e);
        throw new JahiaRuntimeException(e);
    } catch (RuntimeException e) {
        running = false;
        logger.error(e.getMessage(), e);
        throw e;
    } finally {
        JCRSessionFactory.getInstance().closeAllSessions();
    }
}
Also used : JahiaInitializationException(org.jahia.exceptions.JahiaInitializationException) FileSystemException(org.apache.commons.vfs2.FileSystemException) JahiaRuntimeException(org.jahia.exceptions.JahiaRuntimeException) JahiaException(org.jahia.exceptions.JahiaException) JahiaRuntimeException(org.jahia.exceptions.JahiaRuntimeException) WebApplicationContext(org.springframework.web.context.WebApplicationContext) XmlWebApplicationContext(org.springframework.web.context.support.XmlWebApplicationContext)

Example 4 with JahiaInitializationException

use of org.jahia.exceptions.JahiaInitializationException in project jahia by Jahia.

the class Jahia method verifyJavaVersion.

/**
 * This method check if the Java version used to run the application is supported
 *
 * @param supportedJDKVersions list as a string of the supported JDK versions
 * @throws JahiaInitializationException if the version used is not supported
 */
public static void verifyJavaVersion(String supportedJDKVersions) throws JahiaInitializationException {
    if (supportedJDKVersions != null) {
        Version currentJDKVersion;
        try {
            currentJDKVersion = new Version(System.getProperty("java.version"));
            if (Arrays.stream(StringUtils.split(supportedJDKVersions, ',')).noneMatch(v -> isSupportedJDKVersion(currentJDKVersion, v.trim()))) {
                String jemsg = "WARNING\n\n" + "You are using an unsupported JDK version\n" + "or have an invalid " + INIT_PARAM_SUPPORTED_JDK_VERSIONS + " parameter string in \n" + "the deployment descriptor file web.xml.\n" + "\n\nHere is the range specified in the web.xml file : " + supportedJDKVersions + ".\n" + "\nIf you want to disable this warning, remove the " + INIT_PARAM_SUPPORTED_JDK_VERSIONS + "\n" + "\ninitialization parameter in the WEB-INF/web.xml\n\n" + "\n\nPlease note that if you deactivate this check or use unsupported versions\n\n" + "\nYou might run into serious problems and we cannot offer support for these.\n\n" + "\nYou may download a supported JDK from Oracle site: http://www.oracle.com/technetwork/java/javase/downloads/index.html" + "\n\n&nbsp;\n";
                JahiaInitializationException e = new JahiaInitializationException(jemsg);
                logger.error("Invalid JDK version", e);
                throw e;
            }
        } catch (NumberFormatException nfe) {
            logger.warn("Couldn't convert JDK version to internal version testing system, ignoring JDK version test...", nfe);
        }
    }
}
Also used : JahiaInitializationException(org.jahia.exceptions.JahiaInitializationException) Version(org.jahia.commons.Version)

Example 5 with JahiaInitializationException

use of org.jahia.exceptions.JahiaInitializationException in project jahia by Jahia.

the class TaggingService method initAfterAllServicesAreStarted.

@Override
public void initAfterAllServicesAreStarted() throws JahiaInitializationException {
    try {
        Map<String, String> tagPropSelectorOptions = NodeTypeRegistry.getInstance().getNodeType(TaggingService.JMIX_TAGGED).getPropertyDefinition(TaggingService.J_TAG_LIST).getSelectorOptions();
        tagSeparator = tagPropSelectorOptions.get("separator");
    } catch (NoSuchNodeTypeException e) {
        throw new JahiaInitializationException("Cannot initialize tag service", e);
    }
}
Also used : JahiaInitializationException(org.jahia.exceptions.JahiaInitializationException) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Aggregations

JahiaInitializationException (org.jahia.exceptions.JahiaInitializationException)7 JahiaRuntimeException (org.jahia.exceptions.JahiaRuntimeException)2 IOException (java.io.IOException)1 NoSuchNodeTypeException (javax.jcr.nodetype.NoSuchNodeTypeException)1 NamingException (javax.naming.NamingException)1 FileSystemException (org.apache.commons.vfs2.FileSystemException)1 StaleItemStateException (org.apache.jackrabbit.core.state.StaleItemStateException)1 Version (org.jahia.commons.Version)1 JahiaException (org.jahia.exceptions.JahiaException)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1 XmlWebApplicationContext (org.springframework.web.context.support.XmlWebApplicationContext)1