Search in sources :

Example 6 with DeploymentTracing

use of org.glassfish.internal.deployment.DeploymentTracing in project Payara by payara.

the class ApplicationLifecycle method prepareModule.

@Override
public ModuleInfo prepareModule(List<EngineInfo> sortedEngineInfos, String moduleName, DeploymentContext context, ProgressTracker tracker) throws Exception {
    ActionReport report = context.getActionReport();
    List<EngineRef> addedEngines = new ArrayList<EngineRef>();
    DeploymentTracing tracing = context.getModuleMetaData(DeploymentTracing.class);
    if (tracing != null) {
        tracing.addModuleMark(DeploymentTracing.ModuleMark.PREPARE, moduleName);
    }
    for (EngineInfo engineInfo : sortedEngineInfos) {
        // get the deployer
        Deployer deployer = engineInfo.getDeployer();
        try {
            if (tracing != null) {
                tracing.addContainerMark(DeploymentTracing.ContainerMark.PREPARE, engineInfo.getSniffer().getModuleType());
            }
            deployer.prepare(context);
            if (tracing != null) {
                tracing.addContainerMark(DeploymentTracing.ContainerMark.PREPARED, engineInfo.getSniffer().getModuleType());
            }
            // construct an incomplete EngineRef which will be later
            // filled in at loading time
            EngineRef engineRef = new EngineRef(engineInfo, null);
            addedEngines.add(engineRef);
            tracker.add("prepared", EngineRef.class, engineRef);
            tracker.add(Deployer.class, deployer);
        } catch (Exception e) {
            report.failure(logger, "Exception while invoking " + deployer.getClass() + " prepare method", e);
            throw e;
        }
    }
    if (tracing != null) {
        tracing.addModuleMark(DeploymentTracing.ModuleMark.PREPARE_EVENTS, moduleName);
    }
    if (events != null) {
        events.send(new Event<DeploymentContext>(Deployment.MODULE_PREPARED, context), false);
    }
    if (tracing != null) {
        tracing.addModuleMark(DeploymentTracing.ModuleMark.PREPARED, moduleName);
    }
    // I need to create the application info here from the context, or something like this.
    // and return the application info from this method for automatic registration in the caller.
    // set isComposite property on module props so we know whether to persist
    // module level properties inside ModuleInfo
    String isComposite = context.getAppProps().getProperty(ServerTags.IS_COMPOSITE);
    if (isComposite != null) {
        context.getModuleProps().setProperty(ServerTags.IS_COMPOSITE, isComposite);
    }
    ModuleInfo mi = new ModuleInfo(events, moduleName, addedEngines, context.getModuleProps());
    /*
         * Save the application config that is potentially attached to each
         * engine in the corresponding EngineRefs that have already created.
         * 
         * Later, in registerAppInDomainXML, the appInfo is saved, which in
         * turn saves the moduleInfo children and their engineRef children.
         * Saving the engineRef assigns the application config to the Engine
         * which corresponds directly to the <engine> element in the XML.
         * A long way to get this done.
         */
    // Application existingApp = applications.getModule(Application.class, moduleName);
    // if (existingApp != null) {
    ApplicationConfigInfo savedAppConfig = new ApplicationConfigInfo(context.getAppProps());
    for (EngineRef er : mi.getEngineRefs()) {
        ApplicationConfig c = savedAppConfig.get(mi.getName(), er.getContainerInfo().getSniffer().getModuleType());
        if (c != null) {
            er.setApplicationConfig(c);
        }
    }
    // }
    return mi;
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) RetryableException(org.jvnet.hk2.config.RetryableException) MultiException(org.glassfish.hk2.api.MultiException) VersioningSyntaxException(org.glassfish.deployment.versioning.VersioningSyntaxException) IOException(java.io.IOException) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) DeploymentTracing(org.glassfish.internal.deployment.DeploymentTracing)

Example 7 with DeploymentTracing

use of org.glassfish.internal.deployment.DeploymentTracing in project Payara by payara.

the class ApplicationInfo method load.

public void load(ExtendedDeploymentContext context, ProgressTracker tracker) throws Exception {
    Logger logger = context.getLogger();
    if (isLoaded) {
        logger.fine("Application is already loaded.");
        return;
    }
    context.setPhase(ExtendedDeploymentContext.Phase.LOAD);
    DeploymentTracing tracing = context.getModuleMetaData(DeploymentTracing.class);
    if (tracing != null) {
        tracing.addMark(DeploymentTracing.Mark.LOAD);
    }
    super.load(context, tracker);
    appClassLoader = context.getClassLoader();
    for (ModuleInfo module : modules) {
        if (tracing != null) {
            tracing.addModuleMark(DeploymentTracing.ModuleMark.LOAD, module.getName());
        }
        module.load(getSubContext(module, context), tracker);
        if (tracing != null) {
            tracing.addModuleMark(DeploymentTracing.ModuleMark.LOADED, module.getName());
        }
    }
    populateApplicationServiceLocator();
    isLoaded = true;
    if (tracing != null) {
        tracing.addMark(DeploymentTracing.Mark.LOAD_EVENTS);
    }
    if (events != null) {
        events.send(new Event<ApplicationInfo>(Deployment.APPLICATION_LOADED, this), false);
    }
    if (tracing != null) {
        tracing.addMark(DeploymentTracing.Mark.LOADED);
    }
}
Also used : DeploymentTracing(org.glassfish.internal.deployment.DeploymentTracing) Logger(java.util.logging.Logger)

Example 8 with DeploymentTracing

use of org.glassfish.internal.deployment.DeploymentTracing in project Payara by payara.

the class ModuleInfo method load.

public void load(ExtendedDeploymentContext context, ProgressTracker tracker) throws Exception {
    Logger logger = context.getLogger();
    context.setPhase(ExtendedDeploymentContext.Phase.LOAD);
    DeploymentTracing tracing = context.getModuleMetaData(DeploymentTracing.class);
    if (tracing != null) {
        tracing.addMark(DeploymentTracing.Mark.LOAD);
    }
    moduleClassLoader = context.getClassLoader();
    Set<EngineRef> filteredEngines = new LinkedHashSet<EngineRef>();
    LinkedList<EngineRef> filteredReversedEngines = new LinkedList<EngineRef>();
    ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(context.getClassLoader());
        for (EngineRef engine : _getEngineRefs()) {
            final EngineInfo engineInfo = engine.getContainerInfo();
            if (tracing != null) {
                tracing.addContainerMark(DeploymentTracing.ContainerMark.LOAD, engineInfo.getSniffer().getModuleType());
            }
            // get the container.
            Deployer deployer = engineInfo.getDeployer();
            try {
                ApplicationContainer appCtr = deployer.load(engineInfo.getContainer(), context);
                if (appCtr == null) {
                    String msg = "Cannot load application in " + engineInfo.getContainer().getName() + " container";
                    logger.fine(msg);
                    continue;
                }
                engine.load(context, tracker);
                engine.setApplicationContainer(appCtr);
                filteredEngines.add(engine);
                filteredReversedEngines.addFirst(engine);
            } catch (Exception e) {
                logger.log(Level.SEVERE, "Exception while invoking " + deployer.getClass() + " load method", e);
                throw e;
            }
            if (tracing != null) {
                tracing.addContainerMark(DeploymentTracing.ContainerMark.LOADED, engineInfo.getSniffer().getModuleType());
            }
        }
        engines = filteredEngines;
        reversedEngines = filteredReversedEngines;
        if (tracing != null) {
            tracing.addMark(DeploymentTracing.Mark.LOAD_EVENTS);
        }
        if (events != null) {
            events.send(new Event<ModuleInfo>(Deployment.MODULE_LOADED, this), false);
        }
        if (tracing != null) {
            tracing.addMark(DeploymentTracing.Mark.LOADED);
        }
    } finally {
        Thread.currentThread().setContextClassLoader(currentClassLoader);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Logger(java.util.logging.Logger) ApplicationContainer(org.glassfish.api.deployment.ApplicationContainer) LinkedList(java.util.LinkedList) PropertyVetoException(java.beans.PropertyVetoException) DeploymentTracing(org.glassfish.internal.deployment.DeploymentTracing) Deployer(org.glassfish.api.deployment.Deployer)

Aggregations

DeploymentTracing (org.glassfish.internal.deployment.DeploymentTracing)8 PropertyVetoException (java.beans.PropertyVetoException)5 IOException (java.io.IOException)4 Logger (java.util.logging.Logger)4 VersioningSyntaxException (org.glassfish.deployment.versioning.VersioningSyntaxException)3 MultiException (org.glassfish.hk2.api.MultiException)3 RetryableException (org.jvnet.hk2.config.RetryableException)3 Sniffer (org.glassfish.api.container.Sniffer)2 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)2 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)2 Application (com.sun.enterprise.deployment.Application)1 LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1 ApplicationContainer (org.glassfish.api.deployment.ApplicationContainer)1 Deployer (org.glassfish.api.deployment.Deployer)1 PreDestroy (org.glassfish.hk2.api.PreDestroy)1 Service (org.jvnet.hk2.annotations.Service)1 SAXParseException (org.xml.sax.SAXParseException)1