Search in sources :

Example 1 with HTMLActionReporter

use of com.sun.enterprise.admin.report.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.admin.report.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.admin.report.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());
        if (appRef != null) {
            // Does the application need to be run on this instance?
            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);
                    FileUtils.deleteOnExit(tmpDir);
                    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.admin.report.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.admin.report.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);
            FileUtils.deleteOnExit(tmpDir);
            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.admin.report.HTMLActionReporter) PreDestroy(org.glassfish.hk2.api.PreDestroy) FileArchive(com.sun.enterprise.deploy.shared.FileArchive) File(java.io.File)

Example 4 with HTMLActionReporter

use of com.sun.enterprise.admin.report.HTMLActionReporter in project Payara by payara.

the class ApplicationConfigListener method enableApplication.

private void enableApplication(String appName) {
    Application app = applications.getApplication(appName);
    ApplicationRef appRef = domain.getApplicationRefInServer(server.getName(), appName);
    // by the current server instance, do not load
    if (app == null || appRef == null) {
        return;
    }
    // if the application is not in enable state, do not load
    if (!deployment.isAppEnabled(app)) {
        return;
    }
    ApplicationInfo appInfo = appRegistry.get(appName);
    if (appInfo == null || appInfo.isLoaded()) {
        return;
    }
    long operationStartTime = Calendar.getInstance().getTimeInMillis();
    try {
        ActionReport report = new HTMLActionReporter();
        deployment.enable(server.getName(), app, appRef, report, logger);
        if (report.getActionExitCode().equals(ActionReport.ExitCode.SUCCESS)) {
            logger.log(Level.INFO, KernelLoggerInfo.loadingApplicationTime, new Object[] { appName, (Calendar.getInstance().getTimeInMillis() - operationStartTime) });
        } else if (report.getActionExitCode().equals(ActionReport.ExitCode.WARNING)) {
            logger.log(Level.WARNING, KernelLoggerInfo.loadingApplicationWarning, new Object[] { appName, report.getMessage() });
        } else if (report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
            throw new Exception(report.getMessage());
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE, KernelLoggerInfo.loadingApplicationErrorEnable, e);
        throw new RuntimeException(e);
    }
}
Also used : HTMLActionReporter(com.sun.enterprise.admin.report.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 5 with HTMLActionReporter

use of com.sun.enterprise.admin.report.HTMLActionReporter in project Payara by payara.

the class ApplicationLoaderService method processApplication.

public List<Deployment.ApplicationDeployment> processApplication(Application app, ApplicationRef appRef) {
    long operationStartTime = Calendar.getInstance().getTimeInMillis();
    initializeRuntimeDependencies();
    String source = app.getLocation();
    final String appName = app.getName();
    // lifecycle modules are loaded separately
    if (Boolean.valueOf(app.getDeployProperties().getProperty(ServerTags.IS_LIFECYCLE))) {
        return Collections.emptyList();
    }
    URI uri;
    try {
        uri = new URI(source);
    } catch (URISyntaxException e) {
        logger.log(Level.SEVERE, KernelLoggerInfo.cantDetermineLocation, e.getLocalizedMessage());
        return Collections.emptyList();
    }
    List<Deployment.ApplicationDeployment> appDeployments = new ArrayList<>();
    File sourceFile = new File(uri);
    if (sourceFile.exists()) {
        try {
            ReadableArchive archive = null;
            try {
                StructuredDeploymentTracing structuredTracing = deploymentTracingEnabled != null ? StructuredDeploymentTracing.create(app.getName()) : StructuredDeploymentTracing.createDisabled(app.getName());
                DeploymentTracing tracing = null;
                DeployCommandParameters deploymentParams = app.getDeployParameters(appRef);
                deploymentParams.target = server.getName();
                deploymentParams.origin = DeployCommandParameters.Origin.load;
                deploymentParams.command = DeployCommandParameters.Command.startup_server;
                if (domain.isAppReferencedByPaaSTarget(appName)) {
                    if (server.isDas()) {
                        // for loading PaaS application on DAS
                        // we set it to the real PaaS target
                        deploymentParams.target = deployment.getDefaultTarget(appName, deploymentParams.origin, deploymentParams._classicstyle);
                    }
                }
                archive = archiveFactoryProvider.get().openArchive(sourceFile, deploymentParams);
                ActionReport report = new HTMLActionReporter();
                ExtendedDeploymentContext depContext = deployment.getBuilder(logger, deploymentParams, report).source(archive).build();
                tracing = structuredTracing.register(depContext);
                depContext.getAppProps().putAll(app.getDeployProperties());
                depContext.setModulePropsMap(app.getModulePropertiesMap());
                new ApplicationConfigInfo(app).store(depContext.getAppProps());
                appDeployments.add(deployment.prepare(deployment.getSniffersFromApp(app), depContext));
                appDeployments.addAll(loadApplicationForTenants(app, appRef, report));
                if (report.getActionExitCode().equals(ActionReport.ExitCode.SUCCESS)) {
                    if (tracing != null) {
                        tracing.print(System.out);
                    }
                    logger.log(Level.INFO, KernelLoggerInfo.loadingApplicationTime, new Object[] { appName, (Calendar.getInstance().getTimeInMillis() - operationStartTime) });
                } else {
                    logger.log(Level.SEVERE, KernelLoggerInfo.deployFail, report.getMessage());
                }
            } finally {
                if (archive != null) {
                    try {
                        archive.close();
                    } catch (IOException e) {
                        logger.log(Level.FINE, KernelLoggerInfo.deployException, e);
                    }
                }
            }
        } catch (IOException e) {
            logger.log(Level.SEVERE, KernelLoggerInfo.exceptionOpenArtifact, e);
        }
    } else {
        logger.log(Level.SEVERE, KernelLoggerInfo.notFoundInOriginalLocation, source);
    }
    appDeployments.removeIf(t -> t == null);
    return appDeployments;
}
Also used : URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ActionReport(org.glassfish.api.ActionReport) URI(java.net.URI) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) HTMLActionReporter(com.sun.enterprise.admin.report.HTMLActionReporter) ApplicationConfigInfo(org.glassfish.deployment.common.ApplicationConfigInfo) StructuredDeploymentTracing(org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing) StructuredDeploymentTracing(org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) File(java.io.File)

Aggregations

HTMLActionReporter (com.sun.enterprise.admin.report.HTMLActionReporter)7 ActionReport (org.glassfish.api.ActionReport)6 IOException (java.io.IOException)4 File (java.io.File)3 URISyntaxException (java.net.URISyntaxException)3 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)3 Application (com.sun.enterprise.config.serverbeans.Application)2 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)2 UndeployCommandParameters (org.glassfish.api.deployment.UndeployCommandParameters)2 ArchiveHandler (org.glassfish.api.deployment.archive.ArchiveHandler)2 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)2 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)2 FileArchive (com.sun.enterprise.deploy.shared.FileArchive)1 InputJarArchive (com.sun.enterprise.deployment.deploy.shared.InputJarArchive)1 URI (java.net.URI)1 Logger (java.util.logging.Logger)1 Event (org.glassfish.api.event.EventListener.Event)1 ApplicationConfigInfo (org.glassfish.deployment.common.ApplicationConfigInfo)1 DeploymentContextImpl (org.glassfish.deployment.common.DeploymentContextImpl)1 DeploymentLifecycleStatsProvider (org.glassfish.deployment.monitor.DeploymentLifecycleStatsProvider)1