Search in sources :

Example 1 with HTMLActionReporter

use of com.sun.enterprise.v3.common.HTMLActionReporter in project Payara by payara.

the class ApplicationConfigListener method disableApplication.

private void disableApplication(String appName) {
    Application app = applications.getApplication(appName);
    ApplicationRef appRef = domain.getApplicationRefInServer(server.getName(), appName);
    // by the current server instance, do not unload
    if (app == null || appRef == null) {
        return;
    }
    ApplicationInfo appInfo = appRegistry.get(appName);
    if (appInfo == null || !appInfo.isLoaded()) {
        return;
    }
    try {
        ActionReport report = new HTMLActionReporter();
        UndeployCommandParameters commandParams = new UndeployCommandParameters();
        commandParams.name = appName;
        commandParams.target = server.getName();
        commandParams.origin = UndeployCommandParameters.Origin.unload;
        commandParams.command = UndeployCommandParameters.Command.disable;
        deployment.disable(commandParams, app, appInfo, report, logger);
        if (report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
            throw new Exception(report.getMessage());
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE, KernelLoggerInfo.loadingApplicationErrorDisable, e);
        throw new RuntimeException(e);
    }
}
Also used : UndeployCommandParameters(org.glassfish.api.deployment.UndeployCommandParameters) HTMLActionReporter(com.sun.enterprise.v3.common.HTMLActionReporter) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) ActionReport(org.glassfish.api.ActionReport) Application(com.sun.enterprise.config.serverbeans.Application) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef)

Example 2 with HTMLActionReporter

use of com.sun.enterprise.v3.common.HTMLActionReporter in project Payara by payara.

the class ApplicationLoaderService method postConstruct.

/**
 * Starts the application loader service.
 *
 * Look at the list of applications installed in our local repository
 * Get a Deployer capable for each application found
 * Invoke the deployer load() method for each application.
 */
public void postConstruct() {
    assert env != null;
    try {
        logger.fine("Satisfying Optional Packages dependencies...");
        InstalledLibrariesResolver.initializeInstalledLibRegistry(env.getLibPath().getAbsolutePath());
    } catch (Exception e) {
        logger.log(Level.WARNING, KernelLoggerInfo.exceptionOptionalDepend, e);
    }
    DeploymentLifecycleStatsProvider dlsp = new DeploymentLifecycleStatsProvider();
    StatsProviderManager.register("deployment", PluginPoint.SERVER, "deployment/lifecycle", dlsp);
    deploymentTracingEnabled = System.getProperty("org.glassfish.deployment.trace");
    domain = habitat.getService(Domain.class);
    /*
         * Build a map that associates an application with its
         * order in domain.xml.  If the deployment-order attribute
         * is not used for any application, then the applications
         * are loaded in the order they occur in domain.xml.  Also, for
         * applications with the same deployment-order attribute,
         * the applications are loaded in the order they occur in domain.xml.
         * Otherwise, applications are loaded according to the
         * deploynment-order attribute.
         */
    systemApplications = domain.getSystemApplications();
    for (Application systemApp : systemApplications.getApplications()) {
        appOrderInfoMap.put(systemApp.getName(), Integer.valueOf(appOrder++));
    }
    List<Application> standaloneAdapters = applications.getApplicationsWithSnifferType(ServerTags.CONNECTOR, true);
    for (Application standaloneAdapter : standaloneAdapters) {
        appOrderInfoMap.put(standaloneAdapter.getName(), Integer.valueOf(appOrder++));
    }
    List<Application> allApplications = applications.getApplications();
    for (Application app : allApplications) {
        appOrderInfoMap.put(app.getName(), Integer.valueOf(appOrder++));
    }
    for (Application systemApp : systemApplications.getApplications()) {
        // check to see if we need to load up this system application
        if (Boolean.valueOf(systemApp.getDeployProperties().getProperty(ServerTags.LOAD_SYSTEM_APP_ON_STARTUP))) {
            if (deployment.isAppEnabled(systemApp) || loadAppOnDAS(systemApp.getName())) {
                Integer order = appOrderInfoMap.get(systemApp.getName());
                ApplicationOrderInfo info = new ApplicationOrderInfo(systemApp, order);
                DeploymentOrder.addApplicationDeployment(info);
            }
        }
    }
    // load standalone resource adapters first
    for (Application standaloneAdapter : standaloneAdapters) {
        // information is available on DAS
        if (deployment.isAppEnabled(standaloneAdapter) || loadAppOnDAS(standaloneAdapter.getName())) {
            DeploymentOrder.addApplicationDeployment(new ApplicationOrderInfo(standaloneAdapter, appOrderInfoMap.get(standaloneAdapter.getName()).intValue()));
        }
    }
    // then the rest of the applications
    for (Application app : allApplications) {
        if (app.isStandaloneModule() && app.containsSnifferType(ServerTags.CONNECTOR)) {
            continue;
        }
        // information is available on DAS
        if (Boolean.valueOf(app.getEnabled()) || loadAppOnDAS(app.getName())) {
            DeploymentOrder.addApplicationDeployment(new ApplicationOrderInfo(app, appOrderInfoMap.get(app.getName()).intValue()));
        }
    }
    List<Deployment.ApplicationDeployment> appDeployments = new ArrayList<>();
    // process the deployed applications
    Iterator iter = DeploymentOrder.getApplicationDeployments();
    while (iter.hasNext()) {
        Application app = (Application) iter.next();
        ApplicationRef appRef = server.getApplicationRef(app.getName());
        appDeployments.addAll(processApplication(app, appRef));
    }
    // does the user want us to run a particular application
    String defaultParam = env.getStartupContext().getArguments().getProperty("default");
    if (defaultParam != null) {
        initializeRuntimeDependencies();
        File sourceFile;
        if (defaultParam.equals(".")) {
            sourceFile = new File(System.getProperty("user.dir"));
        } else {
            sourceFile = new File(defaultParam);
        }
        if (sourceFile.exists()) {
            sourceFile = sourceFile.getAbsoluteFile();
            ReadableArchive sourceArchive = null;
            try {
                sourceArchive = archiveFactoryProvider.get().openArchive(sourceFile);
                DeployCommandParameters parameters = new DeployCommandParameters(sourceFile);
                parameters.name = sourceFile.getName();
                parameters.enabled = Boolean.TRUE;
                parameters.origin = DeployCommandParameters.Origin.deploy;
                ActionReport report = new HTMLActionReporter();
                if (!sourceFile.isDirectory()) {
                    // ok we need to explode the directory somwhere and remember to delete it on shutdown
                    final File tmpFile = File.createTempFile(sourceFile.getName(), "");
                    final String path = tmpFile.getAbsolutePath();
                    if (!tmpFile.delete()) {
                        logger.log(Level.WARNING, KernelLoggerInfo.cantDeleteTempFile, path);
                    }
                    File tmpDir = new File(path);
                    tmpDir.deleteOnExit();
                    events.register(new org.glassfish.api.event.EventListener() {

                        public void event(Event event) {
                            if (event.is(EventTypes.SERVER_SHUTDOWN)) {
                                if (tmpFile.exists()) {
                                    FileUtils.whack(tmpFile);
                                }
                            }
                        }
                    });
                    if (tmpDir.mkdirs()) {
                        ArchiveHandler handler = deployment.getArchiveHandler(sourceArchive);
                        final String appName = handler.getDefaultApplicationName(sourceArchive);
                        DeploymentContextImpl dummyContext = new DeploymentContextImpl(report, logger, sourceArchive, parameters, env);
                        handler.expand(sourceArchive, archiveFactoryProvider.get().createArchive(tmpDir), dummyContext);
                        sourceArchive = archiveFactoryProvider.get().openArchive(tmpDir);
                        logger.log(Level.INFO, KernelLoggerInfo.sourceNotDirectory, tmpDir.getAbsolutePath());
                        parameters.name = appName;
                    }
                }
                ExtendedDeploymentContext depContext = deployment.getBuilder(logger, parameters, report).source(sourceArchive).build();
                Deployment.ApplicationDeployment appDeployment = deployment.prepare(null, depContext);
                if (appDeployment == null) {
                    logger.log(Level.SEVERE, KernelLoggerInfo.cantFindApplicationInfo, sourceFile.getAbsolutePath());
                } else {
                    appDeployments.add(appDeployment);
                }
            } catch (RuntimeException | IOException e) {
                logger.log(Level.SEVERE, KernelLoggerInfo.deployException, e);
            } finally {
                if (sourceArchive != null) {
                    try {
                        sourceArchive.close();
                    } catch (IOException ioe) {
                    // ignore
                    }
                }
            }
        }
    }
    events.send(new Event<>(Deployment.ALL_APPLICATIONS_LOADED, null), false);
    for (Deployment.ApplicationDeployment depl : appDeployments) {
        deployment.initialize(depl.appInfo, depl.appInfo.getSniffers(), depl.context);
    }
    events.send(new Event<>(Deployment.ALL_APPLICATIONS_PROCESSED, null));
}
Also used : ArchiveHandler(org.glassfish.api.deployment.archive.ArchiveHandler) ActionReport(org.glassfish.api.ActionReport) DeploymentLifecycleStatsProvider(org.glassfish.deployment.monitor.DeploymentLifecycleStatsProvider) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) DeploymentContextImpl(org.glassfish.deployment.common.DeploymentContextImpl) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) HTMLActionReporter(com.sun.enterprise.v3.common.HTMLActionReporter) Event(org.glassfish.api.event.EventListener.Event) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) File(java.io.File)

Example 3 with HTMLActionReporter

use of com.sun.enterprise.v3.common.HTMLActionReporter in project Payara by payara.

the class DescriptorFactory method createApplicationDescriptor.

/**
 * Returns the parsed DOL object from archive
 *
 * @param archiveFile original archive file
 * @param destRootDir root destination directory where the application
 *        should be expanded under in case of archive deployment
 * @param parentCl parent classloader
 *
 * @return the parsed DOL object
 */
public ResultHolder createApplicationDescriptor(File archiveFile, File destRootDir, ClassLoader parentCl) throws IOException {
    ReadableArchive archive = null;
    Application application = null;
    try {
        Descriptor.setBoundsChecking(false);
        archive = archiveFactory.openArchive(archiveFile);
        ArchiveHandler archiveHandler = deployment.getArchiveHandler(archive);
        ActionReport dummyReport = new HTMLActionReporter();
        String appName = DeploymentUtils.getDefaultEEName(archiveFile.getName());
        DeployCommandParameters params = new DeployCommandParameters();
        params.name = appName;
        ExtendedDeploymentContext context = new DeploymentContextImpl(dummyReport, archive, params, env);
        context.setArchiveHandler(archiveHandler);
        if (!archiveFile.isDirectory()) {
            // expand archive
            File destDir = new File(destRootDir, appName);
            if (destDir.exists()) {
                FileUtils.whack(destDir);
            }
            destDir.mkdirs();
            archiveHandler.expand(archive, archiveFactory.createArchive(destDir), context);
            archive.close();
            archive = archiveFactory.openArchive(destDir);
            context.setSource(archive);
        }
        // issue 14564
        context.addTransientAppMetaData(ExtendedDeploymentContext.IS_TEMP_CLASSLOADER, Boolean.TRUE);
        String archiveType = context.getArchiveHandler().getArchiveType();
        ClassLoader cl = archiveHandler.getClassLoader(parentCl, context);
        Archivist archivist = archivistFactory.getArchivist(archiveType, cl);
        if (archivist == null) {
            throw new IOException("Cannot determine the Java EE module type for " + archive.getURI());
        }
        archivist.setAnnotationProcessingRequested(true);
        String xmlValidationLevel = dasConfig.getDeployXmlValidation();
        archivist.setXMLValidationLevel(xmlValidationLevel);
        if (xmlValidationLevel.equals("none")) {
            archivist.setXMLValidation(false);
        }
        archivist.setRuntimeXMLValidation(false);
        try {
            application = applicationFactory.openArchive(appName, archivist, archive, true);
        } catch (SAXParseException e) {
            throw new IOException(e);
        }
        if (application != null) {
            application.setClassLoader(cl);
            application.visit((ApplicationVisitor) new ApplicationValidator());
        }
    } finally {
        if (archive != null) {
            archive.close();
        }
        // We need to reset it after descriptor building
        Descriptor.setBoundsChecking(true);
    }
    ResultHolder result = new ResultHolder();
    result.application = application;
    result.archive = archive;
    return result;
}
Also used : ArchiveHandler(org.glassfish.api.deployment.archive.ArchiveHandler) Archivist(com.sun.enterprise.deployment.archivist.Archivist) IOException(java.io.IOException) ActionReport(org.glassfish.api.ActionReport) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) DeploymentContextImpl(org.glassfish.deployment.common.DeploymentContextImpl) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) ApplicationValidator(com.sun.enterprise.deployment.util.ApplicationValidator) SAXParseException(org.xml.sax.SAXParseException) HTMLActionReporter(com.sun.enterprise.v3.common.HTMLActionReporter) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) Application(com.sun.enterprise.deployment.Application) File(java.io.File)

Example 4 with HTMLActionReporter

use of com.sun.enterprise.v3.common.HTMLActionReporter in project Payara by payara.

the class DolProvider method processDeploymentMetaData.

/**
 * This method populates the Application object from a ReadableArchive
 * @param archive the archive for the application
 */
public Application processDeploymentMetaData(ReadableArchive archive) throws Exception {
    FileArchive expandedArchive = null;
    File tmpFile = null;
    ExtendedDeploymentContext context = null;
    Logger logger = Logger.getAnonymousLogger();
    ClassLoader cl = null;
    try {
        String archiveName = Util.getURIName(archive.getURI());
        ArchiveHandler archiveHandler = deployment.getArchiveHandler(archive);
        if (archiveHandler == null) {
            throw new IllegalArgumentException(localStrings.getLocalString("deploy.unknownarchivetype", "Archive type of {0} was not recognized", archiveName));
        }
        DeployCommandParameters parameters = new DeployCommandParameters(new File(archive.getURI()));
        ActionReport report = new HTMLActionReporter();
        context = new DeploymentContextImpl(report, archive, parameters, env);
        context.setArchiveHandler(archiveHandler);
        String appName = archiveHandler.getDefaultApplicationName(archive, context);
        parameters.name = appName;
        if (archive instanceof InputJarArchive) {
            // we need to expand the archive first in this case
            tmpFile = File.createTempFile(archiveName, "");
            String path = tmpFile.getAbsolutePath();
            if (!tmpFile.delete()) {
                logger.log(Level.WARNING, "cannot.delete.temp.file", new Object[] { path });
            }
            File tmpDir = new File(path);
            tmpDir.deleteOnExit();
            if (!tmpDir.exists() && !tmpDir.mkdirs()) {
                throw new IOException("Unable to create directory " + tmpDir.getAbsolutePath());
            }
            expandedArchive = (FileArchive) archiveFactory.createArchive(tmpDir);
            archiveHandler.expand(archive, expandedArchive, context);
            context.setSource(expandedArchive);
        }
        context.setPhase(DeploymentContextImpl.Phase.PREPARE);
        ClassLoaderHierarchy clh = clhProvider.get();
        context.createDeploymentClassLoader(clh, archiveHandler);
        cl = context.getClassLoader();
        deployment.getDeployableTypes(context);
        deployment.getSniffers(archiveHandler, null, context);
        return processDOL(context);
    } finally {
        if (cl != null && cl instanceof PreDestroy) {
            try {
                PreDestroy.class.cast(cl).preDestroy();
            } catch (Exception e) {
            // ignore
            }
        }
        if (context != null) {
            context.postDeployClean(true);
        }
        if (expandedArchive != null) {
            try {
                expandedArchive.close();
            } catch (Exception e) {
            // ignore
            }
        }
        if (tmpFile != null && tmpFile.exists()) {
            try {
                FileUtils.whack(tmpFile);
            } catch (Exception e) {
            // ignore
            }
        }
    }
}
Also used : ArchiveHandler(org.glassfish.api.deployment.archive.ArchiveHandler) InputJarArchive(com.sun.enterprise.deployment.deploy.shared.InputJarArchive) IOException(java.io.IOException) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) Logger(java.util.logging.Logger) ActionReport(org.glassfish.api.ActionReport) ClassLoaderHierarchy(org.glassfish.internal.api.ClassLoaderHierarchy) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) HTMLActionReporter(com.sun.enterprise.v3.common.HTMLActionReporter) PreDestroy(org.glassfish.hk2.api.PreDestroy) FileArchive(com.sun.enterprise.deploy.shared.FileArchive) File(java.io.File)

Example 5 with HTMLActionReporter

use of com.sun.enterprise.v3.common.HTMLActionReporter in project Payara by payara.

the class ConfigAttributeSetTest method simpleAttributeSetTest.

@Test
public void simpleAttributeSetTest() {
    CommandRunnerImpl runner = habitat.getService(CommandRunnerImpl.class);
    assertNotNull(runner);
    // let's find our target
    NetworkListener listener = null;
    NetworkListeners service = habitat.getService(NetworkListeners.class);
    for (NetworkListener l : service.getNetworkListener()) {
        if ("http-listener-1".equals(l.getName())) {
            listener = l;
            break;
        }
    }
    assertNotNull(listener);
    // Let's register a listener
    ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(listener);
    bean.addListener(this);
    // parameters to the command
    ParameterMap parameters = new ParameterMap();
    parameters.set("value", "8090");
    parameters.set("DEFAULT", "configs.config.server-config.http-service.http-listener.http-listener-1.port");
    // execute the set command.
    runner.getCommandInvocation("set", new HTMLActionReporter(), adminSubject()).parameters(parameters).execute();
    // check the result.
    String port = listener.getPort();
    assertEquals(port, "8090");
    // ensure events are delivered.
    habitat.<Transactions>getService(Transactions.class).waitForDrain();
    // finally
    bean.removeListener(this);
    // check we recevied the event
    assertNotNull(event);
    assertEquals("8080", event.getOldValue());
    assertEquals("8090", event.getNewValue());
    assertEquals("port", event.getPropertyName());
}
Also used : Transactions(org.jvnet.hk2.config.Transactions) HTMLActionReporter(com.sun.enterprise.v3.common.HTMLActionReporter) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) ObservableBean(org.jvnet.hk2.config.ObservableBean) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Aggregations

HTMLActionReporter (com.sun.enterprise.v3.common.HTMLActionReporter)8 ActionReport (org.glassfish.api.ActionReport)7 IOException (java.io.IOException)5 File (java.io.File)4 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)4 URISyntaxException (java.net.URISyntaxException)3 ArchiveHandler (org.glassfish.api.deployment.archive.ArchiveHandler)3 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)3 Application (com.sun.enterprise.config.serverbeans.Application)2 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)2 UndeployCommandParameters (org.glassfish.api.deployment.UndeployCommandParameters)2 DeploymentContextImpl (org.glassfish.deployment.common.DeploymentContextImpl)2 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)2 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)2 SAXParseException (org.xml.sax.SAXParseException)2 FileArchive (com.sun.enterprise.deploy.shared.FileArchive)1 Application (com.sun.enterprise.deployment.Application)1 Archivist (com.sun.enterprise.deployment.archivist.Archivist)1 InputJarArchive (com.sun.enterprise.deployment.deploy.shared.InputJarArchive)1 ApplicationValidator (com.sun.enterprise.deployment.util.ApplicationValidator)1