Search in sources :

Example 11 with DeploymentSpan

use of org.glassfish.internal.deployment.analysis.DeploymentSpan 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);
    StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(context);
    moduleClassLoader = context.getClassLoader();
    Set<EngineRef> filteredEngines = new LinkedHashSet<>();
    LinkedList<EngineRef> filteredReversedEngines = new LinkedList<>();
    ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
    try (DeploymentSpan span = tracing.startSpan(TraceContext.Level.MODULE, name, DeploymentTracing.AppStage.LOAD)) {
        Thread.currentThread().setContextClassLoader(context.getClassLoader());
        for (EngineRef engine : _getEngineRefs()) {
            final EngineInfo engineInfo = engine.getContainerInfo();
            // get the container.
            Deployer deployer = engineInfo.getDeployer();
            try (DeploymentSpan containerSpan = tracing.startSpan(TraceContext.Level.CONTAINER, engineInfo.getSniffer().getModuleType(), DeploymentTracing.AppStage.LOAD)) {
                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(SEVERE, "Exception while invoking " + deployer.getClass() + " load method", e);
                throw e;
            }
        }
        engines = filteredEngines;
        reversedEngines = filteredReversedEngines;
        if (events != null) {
            try (DeploymentSpan innerSpan = tracing.startSpan(TraceContext.Level.MODULE, name, DeploymentTracing.AppStage.PROCESS_EVENTS, Deployment.MODULE_LOADED.type())) {
                events.send(new Event<ModuleInfo>(Deployment.MODULE_LOADED, this), false);
            }
        }
    } 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) StructuredDeploymentTracing(org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing) DeploymentSpan(org.glassfish.internal.deployment.analysis.DeploymentSpan) Deployer(org.glassfish.api.deployment.Deployer)

Example 12 with DeploymentSpan

use of org.glassfish.internal.deployment.analysis.DeploymentSpan 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 {
    List<EngineRef> addedEngines = new ArrayList<>();
    StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(context);
    tracing.switchToContext(TraceContext.Level.MODULE, moduleName);
    for (EngineInfo engineInfo : sortedEngineInfos) {
        // get the deployer
        Deployer deployer = engineInfo.getDeployer();
        try (DeploymentSpan span = tracing.startSpan(TraceContext.Level.CONTAINER, engineInfo.getSniffer().getModuleType(), DeploymentTracing.AppStage.PREPARE)) {
            deployer.prepare(context);
            // 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) {
            final ActionReport report = context.getActionReport();
            report.failure(logger, "Exception while invoking " + deployer.getClass() + " prepare method", e);
            throw e;
        }
    }
    if (events != null) {
        DeploymentSpan span = tracing.startSpan(TraceContext.Level.MODULE, moduleName, DeploymentTracing.AppStage.PROCESS_EVENTS, Deployment.MODULE_PREPARED.type());
        events.send(new Event<>(Deployment.MODULE_PREPARED, context), false);
        span.close();
    }
    // 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 : ActionReport(org.glassfish.api.ActionReport) EngineRef(org.glassfish.internal.data.EngineRef) MultiException(org.glassfish.hk2.api.MultiException) DeploymentException(org.glassfish.deployment.common.DeploymentException) IOException(java.io.IOException) PropertyVetoException(java.beans.PropertyVetoException) RetryableException(org.jvnet.hk2.config.RetryableException) VersioningSyntaxException(org.glassfish.deployment.versioning.VersioningSyntaxException) EngineInfo(org.glassfish.internal.data.EngineInfo) ModuleInfo(org.glassfish.internal.data.ModuleInfo) ApplicationConfigInfo(org.glassfish.deployment.common.ApplicationConfigInfo) StructuredDeploymentTracing(org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing) DeploymentSpan(org.glassfish.internal.deployment.analysis.DeploymentSpan) Deployer(org.glassfish.api.deployment.Deployer)

Example 13 with DeploymentSpan

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

the class ApplicationLifecycle method startDeployer.

private Deployer startDeployer(DeploymentContext context, String containerName, EngineInfo engineInfo) throws Exception {
    final ActionReport report = context.getActionReport();
    StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(context);
    try (DeploymentSpan span = tracing.startSpan(TraceContext.Level.CONTAINER, engineInfo.getSniffer().getModuleType(), DeploymentTracing.AppStage.PREPARE, "Deployer")) {
        Deployer deployer = engineInfo.getDeployer();
        if (deployer == null) {
            if (!startContainers(Collections.singleton(engineInfo), logger, context)) {
                final String msg = "Aborting, Failed to start container " + containerName;
                report.failure(logger, msg, null);
                throw new Exception(msg);
            }
            deployer = engineInfo.getDeployer();
            if (deployer == null) {
                report.failure(logger, "Got a null deployer out of the " + engineInfo.getContainer().getClass() + " container, is it annotated with @Service ?");
                throw new DeploymentException("Deployer not found for container " + containerName);
            }
        }
        return deployer;
    }
}
Also used : StructuredDeploymentTracing(org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing) DeploymentException(org.glassfish.deployment.common.DeploymentException) DeploymentSpan(org.glassfish.internal.deployment.analysis.DeploymentSpan) ActionReport(org.glassfish.api.ActionReport) Deployer(org.glassfish.api.deployment.Deployer) MultiException(org.glassfish.hk2.api.MultiException) DeploymentException(org.glassfish.deployment.common.DeploymentException) IOException(java.io.IOException) PropertyVetoException(java.beans.PropertyVetoException) RetryableException(org.jvnet.hk2.config.RetryableException) VersioningSyntaxException(org.glassfish.deployment.versioning.VersioningSyntaxException)

Example 14 with DeploymentSpan

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

the class ApplicationLifecycle method getDeployableParser.

public Parser getDeployableParser(ReadableArchive source, boolean skipScanExternalLibProp, boolean modelUnAnnotatedMembers, StructuredDeploymentTracing tracing, Logger logger) throws IOException {
    try {
        ResourceLocator locator = determineLocator();
        // scan the jar and store the result in the deployment context.
        ParsingContext.Builder parsingContextBuilder = new ParsingContext.Builder().logger(logger).executorService(executorService.getUnderlyingExecutorService()).config(new ParsingConfig() {

            @Override
            public Set<String> getAnnotationsOfInterest() {
                return Collections.emptySet();
            }

            @Override
            public Set<String> getTypesOfInterest() {
                return Collections.emptySet();
            }

            @Override
            public boolean modelUnAnnotatedMembers() {
                return modelUnAnnotatedMembers;
            }
        });
        // workaround bug in Builder
        parsingContextBuilder.locator(locator);
        ParsingContext parsingContext = parsingContextBuilder.build();
        Parser parser = new Parser(parsingContext);
        ReadableArchiveScannerAdapter scannerAdapter = new ReadableArchiveScannerAdapter(parser, source);
        DeploymentSpan mainScanSpan = tracing.startSpan(DeploymentTracing.AppStage.CLASS_SCANNING, source.getName());
        parser.parse(scannerAdapter, () -> mainScanSpan.close());
        for (ReadableArchive externalLibArchive : getExternalLibraries(source, skipScanExternalLibProp)) {
            ReadableArchiveScannerAdapter libAdapter = null;
            try {
                DeploymentSpan span = tracing.startSpan(DeploymentTracing.AppStage.CLASS_SCANNING, externalLibArchive.getName());
                libAdapter = new ReadableArchiveScannerAdapter(parser, externalLibArchive);
                parser.parse(libAdapter, () -> span.close());
            } finally {
                if (libAdapter != null) {
                    libAdapter.close();
                }
            }
        }
        parser.awaitTermination();
        scannerAdapter.close();
        return parser;
    } catch (InterruptedException e) {
        throw new IOException(e);
    }
}
Also used : ParsingConfig(org.glassfish.hk2.classmodel.reflect.util.ParsingConfig) ParsingContext(org.glassfish.hk2.classmodel.reflect.ParsingContext) DeploymentSpan(org.glassfish.internal.deployment.analysis.DeploymentSpan) IOException(java.io.IOException) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) ResourceLocator(org.glassfish.hk2.classmodel.reflect.util.ResourceLocator) Parser(org.glassfish.hk2.classmodel.reflect.Parser)

Example 15 with DeploymentSpan

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

the class ApplicationLifecycle method loadDeployer.

private void loadDeployer(List<Deployer> results, Deployer deployer, Map<Class, Deployer> typeByDeployer, Map<Class, ApplicationMetaDataProvider> typeByProvider, DeploymentContext dc) throws IOException {
    StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(dc);
    if (results.contains(deployer)) {
        return;
    }
    results.add(deployer);
    if (deployer.getMetaData() != null) {
        for (Class required : deployer.getMetaData().requires()) {
            if (dc.getModuleMetaData(required) != null) {
                continue;
            }
            if (typeByDeployer.containsKey(required)) {
                loadDeployer(results, typeByDeployer.get(required), typeByDeployer, typeByProvider, dc);
            } else {
                ApplicationMetaDataProvider provider = typeByProvider.get(required);
                if (provider == null) {
                    logger.log(SEVERE, KernelLoggerInfo.inconsistentLifecycleState, required);
                } else {
                    LinkedList<ApplicationMetaDataProvider> providers = new LinkedList<>();
                    addRecursively(providers, typeByProvider, provider);
                    for (ApplicationMetaDataProvider p : providers) {
                        // this actually loads all descriptors of the app.
                        try (DeploymentSpan span = tracing.startSpan(TraceContext.Level.APPLICATION, null, DeploymentTracing.AppStage.LOAD, "DeploymentDescriptor")) {
                            dc.addModuleMetaData(p.load(dc));
                        }
                    }
                }
            }
        }
    }
}
Also used : StructuredDeploymentTracing(org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing) DeploymentSpan(org.glassfish.internal.deployment.analysis.DeploymentSpan) ApplicationMetaDataProvider(org.glassfish.api.deployment.ApplicationMetaDataProvider)

Aggregations

DeploymentSpan (org.glassfish.internal.deployment.analysis.DeploymentSpan)15 StructuredDeploymentTracing (org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing)14 PropertyVetoException (java.beans.PropertyVetoException)8 IOException (java.io.IOException)8 ActionReport (org.glassfish.api.ActionReport)7 Deployer (org.glassfish.api.deployment.Deployer)6 VersioningSyntaxException (org.glassfish.deployment.versioning.VersioningSyntaxException)6 Logger (java.util.logging.Logger)5 DeploymentException (org.glassfish.deployment.common.DeploymentException)5 MultiException (org.glassfish.hk2.api.MultiException)5 EngineInfo (org.glassfish.internal.data.EngineInfo)5 RetryableException (org.jvnet.hk2.config.RetryableException)5 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)4 ApplicationMetaDataProvider (org.glassfish.api.deployment.ApplicationMetaDataProvider)3 PayaraExecutorService (fish.payara.nucleus.executorservice.PayaraExecutorService)2 ApplicationState (fish.payara.nucleus.hotdeploy.ApplicationState)2 HotDeployService (fish.payara.nucleus.hotdeploy.HotDeployService)2 ExecutorService (java.util.concurrent.ExecutorService)2 Collectors.toMap (java.util.stream.Collectors.toMap)2 ParameterMap (org.glassfish.api.admin.ParameterMap)2