Search in sources :

Example 6 with GlassFishException

use of org.glassfish.embeddable.GlassFishException in project Payara by payara.

the class PayaraMicroImpl method getGAVURLs.

/**
 * Converts the GAVs provided to a URLs, and stores them in the
 * deploymentURLsMap.
 */
private void getGAVURLs() throws GlassFishException {
    GAVConvertor gavConvertor = new GAVConvertor();
    for (String gav : GAVs) {
        try {
            Map.Entry<String, URL> artefactMapEntry = gavConvertor.getArtefactMapEntry(gav, repositoryURLs);
            if (deploymentURLsMap == null) {
                deploymentURLsMap = new LinkedHashMap<>();
            }
            String contextRoot = artefactMapEntry.getKey();
            if ("ROOT".equals(contextRoot)) {
                contextRoot = "/";
            }
            deploymentURLsMap.put(contextRoot, artefactMapEntry.getValue());
        } catch (MalformedURLException ex) {
            throw new GlassFishException(ex.getMessage());
        }
    }
}
Also used : GlassFishException(org.glassfish.embeddable.GlassFishException) GAVConvertor(fish.payara.deployment.util.GAVConvertor) MalformedURLException(java.net.MalformedURLException) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) URL(java.net.URL)

Example 7 with GlassFishException

use of org.glassfish.embeddable.GlassFishException 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);
    }
    resetLogging();
    // 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());
        HazelcastCore.setThreadLocalDisabled(true);
        try {
            gf.start();
            // Attempt paranoid unbinding of all reserved ports.
            MicroNetworkListener.clearReservedSockets();
            // Execute post boot commands
            postBootCommands.executeCommands(gf.getCommandRunner());
            this.runtime = new PayaraMicroRuntimeImpl(gf, gfruntime);
            // load all applications, but do not start them until Hazelcast gets a chance to initialize
            deployAll();
        } catch (IOException ex) {
            LOGGER.log(Level.SEVERE, "Error unbinding reserved port.", ex);
        } finally {
            HazelcastCore.setThreadLocalDisabled(false);
        }
        if (!noCluster) {
            gf.getCommandRunner().run("set-hazelcast-configuration", "--enabled", "true", "--dynamic", "true", "--target", "server-config", "--hostawarepartitioning", Boolean.toString(hostAware), "--lite", Boolean.toString(liteMember));
        }
        gf.getCommandRunner().run("initialize-all-applications");
        postDeployCommands.executeCommands(gf.getCommandRunner());
        long end = System.currentTimeMillis();
        dumpFinalStatus(end - start);
        return runtime;
    } catch (Exception ex) {
        try {
            gf.dispose();
        } catch (GlassFishException ex1) {
            LOGGER.log(Level.SEVERE, null, ex1);
        }
        throw new BootstrapException(ex.getMessage(), ex);
    }
}
Also used : GlassFishException(org.glassfish.embeddable.GlassFishException) BootstrapProperties(org.glassfish.embeddable.BootstrapProperties) GlassFishRuntime(org.glassfish.embeddable.GlassFishRuntime) BootstrapException(fish.payara.micro.BootstrapException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) BootstrapException(fish.payara.micro.BootstrapException) BindException(java.net.BindException) GlassFishException(org.glassfish.embeddable.GlassFishException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ValidationException(fish.payara.micro.cmd.options.ValidationException)

Example 8 with GlassFishException

use of org.glassfish.embeddable.GlassFishException in project Payara by payara.

the class PayaraMicroImpl method configurePorts.

private void configurePorts() throws GlassFishException {
    PortBinder portBinder = new PortBinder();
    if (httpPort != Integer.MIN_VALUE) {
        if (autoBindHttp == true) {
            // Log warnings if overriding other options
            logPortPrecedenceWarnings(false);
            // Search for an available port from the specified port
            try {
                int port = portBinder.findAvailablePort(httpPort, autoBindRange);
                preBootCommands.add(new BootCommand("set", "configs.config.server-config.network-config.network-listeners.network-listener.http-listener.port=" + port));
                preBootCommands.add(new BootCommand("set", "configs.config.server-config.network-config.network-listeners.network-listener.http-listener.enabled=true"));
            } catch (BindException ex) {
                LOGGER.log(Level.SEVERE, "No available port found in range: " + httpPort + " - " + (httpPort + autoBindRange), ex);
                throw new GlassFishException("Could not bind HTTP port");
            }
        } else {
            // Log warnings if overriding other options
            logPortPrecedenceWarnings(false);
            preBootCommands.add(new BootCommand("set", "configs.config.server-config.network-config.network-listeners.network-listener.http-listener.port=" + httpPort));
        }
    } else if (autoBindHttp == true) {
        // Log warnings if overriding other options
        logPortPrecedenceWarnings(false);
        // Search for an available port from the default HTTP port
        try {
            int port = portBinder.findAvailablePort(defaultHttpPort, autoBindRange);
            preBootCommands.add(new BootCommand("set", "configs.config.server-config.network-config.network-listeners.network-listener.http-listener.port=" + port));
            preBootCommands.add(new BootCommand("set", "configs.config.server-config.network-config.network-listeners.network-listener.http-listener.enabled=true"));
        } catch (BindException ex) {
            LOGGER.log(Level.SEVERE, "No available port found in range: " + defaultHttpPort + " - " + (defaultHttpPort + autoBindRange), ex);
            throw new GlassFishException("Could not bind HTTP port");
        }
    }
    if (sslPort != Integer.MIN_VALUE) {
        if (autoBindSsl == true) {
            // Log warnings if overriding other options
            logPortPrecedenceWarnings(true);
            // Search for an available port from the specified port
            try {
                int port = portBinder.findAvailablePort(sslPort, autoBindRange);
                preBootCommands.add(new BootCommand("set", "configs.config.server-config.network-config.network-listeners.network-listener.https-listener.port=" + port));
                preBootCommands.add(new BootCommand("set", "configs.config.server-config.network-config.network-listeners.network-listener.https-listener.enabled=true"));
            } catch (BindException ex) {
                LOGGER.log(Level.SEVERE, "No available port found in range: " + sslPort + " - " + (sslPort + autoBindRange), ex);
                throw new GlassFishException("Could not bind SSL port");
            }
        } else {
            // Log warnings if overriding other options
            logPortPrecedenceWarnings(true);
            // Set the port as normal
            preBootCommands.add(new BootCommand("set", "configs.config.server-config.network-config.network-listeners.network-listener.https-listener.port=" + sslPort));
            preBootCommands.add(new BootCommand("set", "configs.config.server-config.network-config.network-listeners.network-listener.https-listener.enabled=true"));
        }
    } else if (autoBindSsl == true) {
        // Log warnings if overriding other options
        logPortPrecedenceWarnings(true);
        // Search for an available port from the default HTTPS port
        try {
            int port = portBinder.findAvailablePort(defaultHttpsPort, autoBindRange);
            preBootCommands.add(new BootCommand("set", "configs.config.server-config.network-config.network-listeners.network-listener.https-listener.port=" + port));
            preBootCommands.add(new BootCommand("set", "configs.config.server-config.network-config.network-listeners.network-listener.https-listener.enabled=true"));
        } catch (BindException ex) {
            LOGGER.log(Level.SEVERE, "No available port found in range: " + defaultHttpsPort + " - " + (defaultHttpsPort + autoBindRange), ex);
            throw new GlassFishException("Could not bind SSL port");
        }
    }
    if (sslCert != null) {
        preBootCommands.add(new BootCommand("set", "configs.config.server-config.network-config.protocols.protocol.https-listener.ssl.cert-nickname=" + sslCert));
    }
}
Also used : GlassFishException(org.glassfish.embeddable.GlassFishException) BootCommand(fish.payara.micro.boot.runtime.BootCommand) BindException(java.net.BindException)

Example 9 with GlassFishException

use of org.glassfish.embeddable.GlassFishException in project Payara by payara.

the class PayaraMicroImpl method dumpFinalStatus.

private void dumpFinalStatus(long bootTime) {
    // Print instance descriptor
    InstanceDescriptor id = getRuntime().getLocalDescriptor();
    LOGGER.log(Level.INFO, id.toJsonString(showServletMappings));
    // Get Payara Micro endpoints
    StringBuilder sb = new StringBuilder();
    sb.append("\nPayara Micro URLs:\n");
    List<URL> urls = id.getApplicationURLS();
    for (URL url : urls) {
        sb.append(url.toString()).append('\n');
    }
    // Count through applications and add their REST endpoints
    try {
        ListRestEndpointsCommand cmd = gf.getService(ListRestEndpointsCommand.class);
        id.getDeployedApplications().forEach(app -> {
            Map<String, Set<String>> endpoints = null;
            try {
                endpoints = cmd.getEndpointMap(app.getName());
            } catch (IllegalArgumentException ex) {
                // The application has no endpoints
                endpoints = null;
            }
            if (endpoints != null) {
                sb.append("\n'" + app.getName() + "' REST Endpoints:\n");
                endpoints.forEach((path, methods) -> {
                    methods.forEach(method -> {
                        sb.append(method + "\t" + path + "\n");
                    });
                });
            }
        });
    } catch (GlassFishException ex) {
        // Really shouldn't happen, the command catches it's own errors most of the time
        LOGGER.log(Level.SEVERE, "Failed to get REST endpoints for application", ex);
    }
    sb.append("\n");
    // Print out all endpoints
    LOGGER.log(Level.INFO, sb.toString());
    // Print the logo if it's enabled
    if (generateLogo) {
        generateLogo();
    }
    // Print final ready message
    LOGGER.log(Level.INFO, "{0} ready in {1} (ms)", new Object[] { Version.getFullVersion(), bootTime });
}
Also used : InstanceDescriptor(fish.payara.micro.data.InstanceDescriptor) GlassFishException(org.glassfish.embeddable.GlassFishException) Set(java.util.Set) ListRestEndpointsCommand(fish.payara.appserver.rest.endpoints.config.admin.ListRestEndpointsCommand) URL(java.net.URL)

Example 10 with GlassFishException

use of org.glassfish.embeddable.GlassFishException in project Payara by payara.

the class DeployerImpl method undeploy.

@Override
public void undeploy(String appName, String... params) throws GlassFishException {
    String[] newParams = new String[params.length + 1];
    System.arraycopy(params, 0, newParams, 0, params.length);
    newParams[params.length] = appName;
    CommandExecutorImpl executer = habitat.getService(CommandExecutorImpl.class);
    try {
        ActionReport actionReport = executer.executeCommand("undeploy", newParams);
        if (actionReport.hasSuccesses()) {
            logger.log(Level.INFO, "{0} was successfully undeployed", appName);
        }
    } catch (CommandException e) {
        throw new GlassFishException(e);
    }
}
Also used : GlassFishException(org.glassfish.embeddable.GlassFishException) CommandException(org.glassfish.api.admin.CommandException) ActionReport(org.glassfish.api.ActionReport)

Aggregations

GlassFishException (org.glassfish.embeddable.GlassFishException)25 File (java.io.File)7 IOException (java.io.IOException)5 URL (java.net.URL)5 GlassFishProperties (org.glassfish.embeddable.GlassFishProperties)5 Properties (java.util.Properties)4 NamingException (javax.naming.NamingException)4 ActionReport (org.glassfish.api.ActionReport)3 BootstrapProperties (org.glassfish.embeddable.BootstrapProperties)3 BundleException (org.osgi.framework.BundleException)3 ModulesRegistry (com.sun.enterprise.module.ModulesRegistry)2 ModuleStartup (com.sun.enterprise.module.bootstrap.ModuleStartup)2 StartupContext (com.sun.enterprise.module.bootstrap.StartupContext)2 BindException (java.net.BindException)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 CommandException (org.glassfish.api.admin.CommandException)2