Search in sources :

Example 21 with GlassFishException

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

the class DeployerImpl method getDeployedApplications.

@Override
public Collection<String> getDeployedApplications() throws GlassFishException {
    try {
        CommandExecutorImpl executer = habitat.getService(CommandExecutorImpl.class);
        ActionReport report = executer.executeCommand("list-components");
        Properties props = report.getTopMessagePart().getProps();
        return new ArrayList<String>(props.stringPropertyNames());
    } catch (Exception e) {
        throw new GlassFishException(e);
    }
}
Also used : GlassFishException(org.glassfish.embeddable.GlassFishException) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) CommandException(org.glassfish.api.admin.CommandException) GlassFishException(org.glassfish.embeddable.GlassFishException) IOException(java.io.IOException)

Example 22 with GlassFishException

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

the class DeployerImpl method deploy.

@Override
public String deploy(File file, String... params) throws GlassFishException {
    String[] newParams = new String[params.length + 1];
    System.arraycopy(params, 0, newParams, 0, params.length);
    newParams[params.length] = file.getAbsolutePath();
    CommandExecutorImpl executer = habitat.getService(CommandExecutorImpl.class);
    try {
        String command = "deploy";
        ActionReport actionReport = executer.createActionReport();
        ParameterMap commandParams = executer.getParameters(command, newParams);
        org.glassfish.api.admin.CommandRunner.CommandInvocation inv = executer.getCommandRunner().getCommandInvocation(command, actionReport, kernelIdentity.getSubject());
        inv.parameters(commandParams);
        // set outputbound payload if --retrieve option is specified.
        Payload.Outbound outboundPayload = null;
        String retrieveOpt = commandParams.getOne("retrieve");
        File retrieve = retrieveOpt != null ? new File(retrieveOpt) : null;
        if (retrieve != null && retrieve.exists()) {
            outboundPayload = PayloadImpl.Outbound.newInstance();
            inv.outbound(outboundPayload);
        }
        inv.execute();
        // extract the outbound payload.
        if (outboundPayload != null) {
            extractPayload(outboundPayload, actionReport, retrieve);
        }
        return actionReport.getResultType(String.class);
    } catch (CommandException e) {
        throw new GlassFishException(e);
    }
}
Also used : GlassFishException(org.glassfish.embeddable.GlassFishException) ParameterMap(org.glassfish.api.admin.ParameterMap) CommandException(org.glassfish.api.admin.CommandException) ActionReport(org.glassfish.api.ActionReport) Payload(org.glassfish.api.admin.Payload) File(java.io.File)

Example 23 with GlassFishException

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

the class EmbeddedOSGiGlassFishRuntime method shutdown.

public synchronized void shutdown() throws GlassFishException {
    // make a copy to avoid ConcurrentModificationException
    for (GlassFish gf : new ArrayList<GlassFish>(gfs)) {
        if (gf.getStatus() != GlassFish.Status.DISPOSED) {
            try {
                gf.dispose();
            } catch (GlassFishException e) {
                e.printStackTrace();
            }
        }
    }
    gfs.clear();
    shutdownInternal();
    System.out.println("Completed shutdown of GlassFish runtime");
}
Also used : GlassFishException(org.glassfish.embeddable.GlassFishException) ArrayList(java.util.ArrayList) GlassFish(org.glassfish.embeddable.GlassFish)

Example 24 with GlassFishException

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

the class OSGiGlassFishRuntime method shutdown.

@Override
public void shutdown() throws GlassFishException {
    if (framework == null) {
        // already shutdown
        return;
    }
    try {
        super.shutdown();
        framework.stop();
        framework.waitForStop(0);
    } catch (InterruptedException ex) {
        throw new GlassFishException(ex);
    } catch (BundleException ex) {
        throw new GlassFishException(ex);
    } finally {
        // guard against repeated calls.
        framework = null;
    }
}
Also used : GlassFishException(org.glassfish.embeddable.GlassFishException) BundleException(org.osgi.framework.BundleException)

Example 25 with GlassFishException

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

the class OSGiGlassFishRuntimeBuilder method build.

public GlassFishRuntime build(BootstrapProperties bsProps) throws GlassFishException {
    try {
        MainHelper.buildStartupContext(bsProps.getProperties());
        Properties properties = bsProps.getProperties();
        // Set the builder name so that when we check for nonEmbedded() inside GlassFishMainActivator,
        // we can identify the environment.
        properties.setProperty(Constants.BUILDER_NAME_PROPERTY, getClass().getName());
        // Step 0: Locate and launch a framework
        long t0 = System.currentTimeMillis();
        fwLauncher = new OSGiFrameworkLauncher(properties);
        framework = fwLauncher.launchOSGiFrameWork();
        long t1 = System.currentTimeMillis();
        logger.logp(Level.FINE, "OSGiGlassFishRuntimeBuilder", "build", "Launched {0}", new Object[] { framework });
        // Step 1: install/update/delete bundles
        if (newFramework()) {
            storeProvisioningOptions(properties);
        } else {
            // this will reconfigure if any provisioning options have changed.
            reconfigure(properties);
        }
        BundleProvisioner bundleProvisioner = BundleProvisioner.createBundleProvisioner(framework.getBundleContext(), properties);
        List<Long> bundleIds = bundleProvisioner.installBundles();
        if (bundleProvisioner.hasAnyThingChanged()) {
            bundleProvisioner.refresh();
            // clean hk2 cache so that updated bundle details will go in there.
            deleteHK2Cache(properties);
            // Save the bundle ids for use during restart.
            storeBundleIds(bundleIds.toArray(new Long[bundleIds.size()]));
        }
        if (bundleProvisioner.isSystemBundleUpdationRequired()) {
            logger.log(Level.INFO, LogFacade.UPDATING_SYSTEM_BUNDLE);
            framework.update();
            framework.waitForStop(0);
            framework.init();
            bundleProvisioner.setBundleContext(framework.getBundleContext());
        }
        // Step 2: Start bundles
        bundleProvisioner.startBundles();
        long t2 = System.currentTimeMillis();
        // Step 3: Start the framework, so bundles will get activated as per their start levels
        framework.start();
        long t3 = System.currentTimeMillis();
        printStats(bundleProvisioner, t0, t1, t2, t3);
        // Step 4: Obtain reference to GlassFishRuntime and return the same
        return getGlassFishRuntime();
    } catch (Exception e) {
        throw new GlassFishException(e);
    }
}
Also used : GlassFishException(org.glassfish.embeddable.GlassFishException) Properties(java.util.Properties) BootstrapProperties(org.glassfish.embeddable.BootstrapProperties) GlassFishException(org.glassfish.embeddable.GlassFishException) BundleException(org.osgi.framework.BundleException)

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