Search in sources :

Example 1 with BootstrapException

use of fish.payara.micro.BootstrapException in project Payara by payara.

the class PayaraMicroImpl method createLauncher.

private void createLauncher() throws BootstrapException {
    try {
        if (rootDir == null) {
            LOGGER.severe("--rootdir is required for creating a launcher");
            System.exit(-1);
        }
        unPackRuntime();
        addLibraries();
        LauncherCreator creator = new LauncherCreator(rootDir, ((URLClassLoader) getClass().getClassLoader()));
        creator.buildLauncher();
    } catch (RuntimeException | URISyntaxException | IOException e) {
        throw new BootstrapException("Unable to create launcher", e);
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) OpenURLClassLoader(fish.payara.micro.boot.loader.OpenURLClassLoader) BootstrapException(fish.payara.micro.BootstrapException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 2 with BootstrapException

use of fish.payara.micro.BootstrapException in project Payara by payara.

the class PayaraMicroImpl method bootStrap.

/**
 * Boots the Payara Micro Server. All parameters are checked at this point
 *
 * @return An instance of PayaraMicroRuntime that can be used to access the
 * running server
 * @throws BootstrapException
 */
@Override
public PayaraMicroRuntime bootStrap() throws BootstrapException {
    // First check whether we are already running
    if (isRunning()) {
        throw new IllegalStateException("Payara Micro is already running, calling bootstrap now is meaningless");
    }
    long start = System.currentTimeMillis();
    // Build the runtime directory
    try {
        unPackRuntime();
    } catch (IOException | URISyntaxException ex) {
        throw new BootstrapException("Problem unpacking the Runtime", ex);
    }
    final String loggingProperty = System.getProperty("java.util.logging.config.file");
    resetLogging(loggingProperty);
    // If it's been enabled, watch the log file for changes
    if (enableDynamicLogging) {
        PayaraFileWatcher.watch(new File(loggingProperty).toPath(), () -> {
            LOGGER.info("Logging file modified, resetting logging");
            resetLogging(loggingProperty);
        });
    }
    // Check a supported JDK version is being used
    if (!JDK.isRunningLTSJDK()) {
        LOGGER.warning("You are running the product on an unsupported JDK version and might see unexpected results or exceptions.");
    }
    runtimeDir.processDirectoryInformation();
    // build the runtime
    BootstrapProperties bprops = new BootstrapProperties();
    bprops.setInstallRoot(runtimeDir.getDirectory().getAbsolutePath());
    bprops.setProperty(Constants.PLATFORM_PROPERTY_KEY, Constants.Platform.PayaraMicro.toString());
    GlassFishRuntime gfruntime;
    try {
        gfruntime = GlassFishRuntime.bootstrap(bprops, Thread.currentThread().getContextClassLoader());
        GlassFishProperties gfproperties = new GlassFishProperties();
        gfproperties.setProperty("-type", "MICRO");
        gfproperties.setInstanceRoot(runtimeDir.getDirectory().getAbsolutePath());
        gfproperties.setConfigFileReadOnly(false);
        gfproperties.setConfigFileURI(runtimeDir.getDomainXML().toURI().toString());
        try {
            configureCommandFiles();
        } catch (IOException ex) {
            LOGGER.log(Level.SEVERE, "Unable to load command file", ex);
        }
        gf = gfruntime.newGlassFish(gfproperties);
        configurePorts();
        configureThreads();
        configureAccessLogging();
        configureHazelcast();
        configurePhoneHome();
        configureNotificationService();
        configureHealthCheck();
        configureRequestTracingService();
        configureSecrets();
        // Add additional libraries
        addLibraries();
        // boot the server
        preBootCommands.executeCommands(gf.getCommandRunner());
        callHandler(preBootHandler);
        gf.start();
        // Execute post boot commands
        postBootCommands.executeCommands(gf.getCommandRunner());
        callHandler(postBootHandler);
        this.runtime = new PayaraMicroRuntimeImpl(gf, gfruntime);
        // deploy all applications and then initialize them
        deployAll();
        // These steps are separated in case any steps need to be done in between
        gf.getCommandRunner().run("initialize-all-applications");
        postDeployCommands.executeCommands(gf.getCommandRunner());
        long end = System.currentTimeMillis();
        dumpFinalStatus(end - start);
        return runtime;
    } catch (Exception ex) {
        try {
            if (gf != null) {
                gf.dispose();
            }
        } catch (GlassFishException ex1) {
            LOGGER.log(Level.SEVERE, null, ex1);
        }
        throw new BootstrapException(ex.getMessage(), ex);
    }
}
Also used : GlassFishException(org.glassfish.embeddable.GlassFishException) GlassFishRuntime(org.glassfish.embeddable.GlassFishRuntime) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) BootstrapException(fish.payara.micro.BootstrapException) GlassFishException(org.glassfish.embeddable.GlassFishException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ValidationException(fish.payara.micro.cmd.options.ValidationException) BootstrapProperties(org.glassfish.embeddable.BootstrapProperties) BootstrapException(fish.payara.micro.BootstrapException) JarFile(java.util.jar.JarFile) File(java.io.File) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties)

Aggregations

BootstrapException (fish.payara.micro.BootstrapException)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 OpenURLClassLoader (fish.payara.micro.boot.loader.OpenURLClassLoader)1 ValidationException (fish.payara.micro.cmd.options.ValidationException)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 MalformedURLException (java.net.MalformedURLException)1 URLClassLoader (java.net.URLClassLoader)1 JarFile (java.util.jar.JarFile)1 BootstrapProperties (org.glassfish.embeddable.BootstrapProperties)1 GlassFishException (org.glassfish.embeddable.GlassFishException)1 GlassFishProperties (org.glassfish.embeddable.GlassFishProperties)1 GlassFishRuntime (org.glassfish.embeddable.GlassFishRuntime)1