Search in sources :

Example 11 with StructuredDeploymentTracing

use of org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing 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 12 with StructuredDeploymentTracing

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

the class ApplicationLifecycle method initialize.

@Override
public void initialize(ApplicationInfo appInfo, Collection<? extends Sniffer> sniffers, ExtendedDeploymentContext context) {
    if (appInfo == null) {
        return;
    }
    appRegistry.removeTransient(appInfo.getName());
    final ActionReport report = context.getActionReport();
    ProgressTracker tracker = context.getTransientAppMetaData(ExtendedDeploymentContext.TRACKER, ProgressTracker.class);
    StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(context);
    // associated engines and the application info is created and registered
    if (loadOnCurrentInstance(context)) {
        try (SpanSequence span = tracing.startSequence(DeploymentTracing.AppStage.INITIALIZE)) {
            notifyLifecycleInterceptorsBefore(ExtendedDeploymentContext.Phase.START, context);
            appInfo.initialize();
            appInfo.getModuleInfos().forEach(moduleInfo -> moduleInfo.getEngineRefs().forEach(engineRef -> tracker.add("initialized", EngineRef.class, engineRef)));
            span.start(DeploymentTracing.AppStage.START);
            appInfo.start(context, tracker);
            notifyLifecycleInterceptorsAfter(ExtendedDeploymentContext.Phase.START, context);
        } catch (Throwable loadException) {
            logger.log(SEVERE, KernelLoggerInfo.lifecycleException, loadException);
            report.failure(logger, "Exception while loading the app", null);
            report.setFailureCause(loadException);
            tracker.actOn(logger);
        } finally {
            context.postDeployClean(false);
            if (report.getActionExitCode() == ActionReport.ExitCode.FAILURE) {
                // warning status code is not a failure
                events.send(new Event<>(Deployment.DEPLOYMENT_FAILURE, context));
            } else {
                events.send(new Event<>(Deployment.DEPLOYMENT_SUCCESS, appInfo));
            }
        }
        currentDeploymentContext.get().pop();
    }
}
Also used : StructuredDeploymentTracing(org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing) ApplicationMetaDataProvider(org.glassfish.api.deployment.ApplicationMetaDataProvider) BufferedInputStream(java.io.BufferedInputStream) Event(org.glassfish.api.event.EventListener.Event) KernelLoggerInfo(org.glassfish.kernel.KernelLoggerInfo) ParsingConfig(org.glassfish.hk2.classmodel.reflect.util.ParsingConfig) TraceContext(org.glassfish.internal.deployment.analysis.TraceContext) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) ServerEnvironment(org.glassfish.api.admin.ServerEnvironment) FileArchive(com.sun.enterprise.deploy.shared.FileArchive) Property(org.jvnet.hk2.config.types.Property) HotDeployService(fish.payara.nucleus.hotdeploy.HotDeployService) DeploymentTracing(org.glassfish.internal.deployment.DeploymentTracing) ParameterMapExtractor(org.glassfish.common.util.admin.ParameterMapExtractor) WARNING(java.util.logging.Level.WARNING) CommonModelRegistry(org.glassfish.hk2.classmodel.reflect.util.CommonModelRegistry) com.sun.enterprise.config.serverbeans(com.sun.enterprise.config.serverbeans) MultiException(org.glassfish.hk2.api.MultiException) Service(org.jvnet.hk2.annotations.Service) Container(org.glassfish.api.container.Container) DeploymentException(org.glassfish.deployment.common.DeploymentException) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ZipOutputStream(java.util.zip.ZipOutputStream) DeploymentContextImpl(org.glassfish.deployment.common.DeploymentContextImpl) ProgressTracker(org.glassfish.internal.data.ProgressTracker) java.util(java.util) Dom(org.jvnet.hk2.config.Dom) OpsParams(org.glassfish.api.deployment.OpsParams) ClassLoaderHierarchy(org.glassfish.internal.api.ClassLoaderHierarchy) EngineRef(org.glassfish.internal.data.EngineRef) BufferedOutputStream(java.io.BufferedOutputStream) ArchiveFactory(com.sun.enterprise.deploy.shared.ArchiveFactory) ArchiveDetector(org.glassfish.api.deployment.archive.ArchiveDetector) LocalStringManagerImpl(com.sun.enterprise.util.LocalStringManagerImpl) DeploymentContext(org.glassfish.api.deployment.DeploymentContext) VersioningUtils(org.glassfish.deployment.versioning.VersioningUtils) ApplicationLifecycleInterceptor(org.glassfish.internal.deployment.ApplicationLifecycleInterceptor) Sniffer(org.glassfish.api.container.Sniffer) WritableArchive(org.glassfish.api.deployment.archive.WritableArchive) ApplicationName(org.glassfish.api.admin.config.ApplicationName) Named(javax.inject.Named) PreDestroy(org.glassfish.hk2.api.PreDestroy) DeploymentProperties(org.glassfish.deployment.common.DeploymentProperties) ApplicationConfigInfo(org.glassfish.deployment.common.ApplicationConfigInfo) ServerEnvironmentImpl(org.glassfish.server.ServerEnvironmentImpl) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ConfigSupport(org.jvnet.hk2.config.ConfigSupport) DeploymentSpan(org.glassfish.internal.deployment.analysis.DeploymentSpan) File(java.io.File) PostConstruct(org.glassfish.hk2.api.PostConstruct) Parser(org.glassfish.hk2.classmodel.reflect.Parser) MetaData(org.glassfish.api.deployment.MetaData) EngineInfo(org.glassfish.internal.data.EngineInfo) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) ApplicationRegistry(org.glassfish.internal.data.ApplicationRegistry) FileUtils(com.sun.enterprise.util.io.FileUtils) ResourceLocator(org.glassfish.hk2.classmodel.reflect.util.ResourceLocator) SpanSequence(org.glassfish.internal.deployment.analysis.SpanSequence) Events(org.glassfish.api.event.Events) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) PropertyVetoException(java.beans.PropertyVetoException) ArchiveHandler(org.glassfish.api.deployment.archive.ArchiveHandler) Collectors.toMap(java.util.stream.Collectors.toMap) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) URI(java.net.URI) ThreadFactory(java.util.concurrent.ThreadFactory) ZipEntry(java.util.zip.ZipEntry) ContainerRegistry(org.glassfish.internal.data.ContainerRegistry) RetryableException(org.jvnet.hk2.config.RetryableException) ClientJarWriter(org.glassfish.deployment.common.ClientJarWriter) ParameterMap(org.glassfish.api.admin.ParameterMap) Logger(java.util.logging.Logger) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) ApplicationState(fish.payara.nucleus.hotdeploy.ApplicationState) DeploymentLifecycleProbeProvider(org.glassfish.deployment.monitor.DeploymentLifecycleProbeProvider) UndeployCommandParameters(org.glassfish.api.deployment.UndeployCommandParameters) DeploymentGroup(fish.payara.enterprise.config.serverbeans.DeploymentGroup) Deployment(org.glassfish.internal.deployment.Deployment) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) INFO(java.util.logging.Level.INFO) Singleton(javax.inject.Singleton) Function(java.util.function.Function) Level(java.util.logging.Level) SEVERE(java.util.logging.Level.SEVERE) ActionReport(org.glassfish.api.ActionReport) Inject(javax.inject.Inject) PayaraExecutorService(fish.payara.nucleus.executorservice.PayaraExecutorService) ExecutorService(java.util.concurrent.ExecutorService) Types(org.glassfish.hk2.classmodel.reflect.Types) FINE(java.util.logging.Level.FINE) Deployer(org.glassfish.api.deployment.Deployer) VersioningSyntaxException(org.glassfish.deployment.versioning.VersioningSyntaxException) DeploymentUtils(org.glassfish.deployment.common.DeploymentUtils) FileInputStream(java.io.FileInputStream) ModuleInfo(org.glassfish.internal.data.ModuleInfo) TimeUnit(java.util.concurrent.TimeUnit) VirtualizationEnv(org.glassfish.api.virtualization.VirtualizationEnv) ConfigBean(org.jvnet.hk2.config.ConfigBean) Transaction(org.jvnet.hk2.config.Transaction) CompositeHandler(org.glassfish.api.deployment.archive.CompositeHandler) ParsingContext(org.glassfish.hk2.classmodel.reflect.ParsingContext) InputStream(java.io.InputStream) ProgressTracker(org.glassfish.internal.data.ProgressTracker) SpanSequence(org.glassfish.internal.deployment.analysis.SpanSequence) StructuredDeploymentTracing(org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing) ActionReport(org.glassfish.api.ActionReport)

Example 13 with StructuredDeploymentTracing

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

the class ApplicationLifecycle method getDeployableTypes.

@Override
@SuppressWarnings("squid:S2095")
public Types getDeployableTypes(DeploymentContext context) throws IOException {
    synchronized (context) {
        Types types = context.getTransientAppMetaData(Types.class.getName(), Types.class);
        if (types != null) {
            return types;
        }
        StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(context);
        Boolean skipScanExternalLibProp = Boolean.valueOf(context.getAppProps().getProperty(DeploymentProperties.SKIP_SCAN_EXTERNAL_LIB));
        Parser parser = getDeployableParser(context.getSource(), skipScanExternalLibProp, false, tracing, context.getLogger());
        ParsingContext parsingContext = parser.getContext();
        context.addTransientAppMetaData(Types.class.getName(), parsingContext.getTypes());
        context.addTransientAppMetaData(Parser.class.getName(), parser);
        return parsingContext.getTypes();
    }
}
Also used : Types(org.glassfish.hk2.classmodel.reflect.Types) ParsingContext(org.glassfish.hk2.classmodel.reflect.ParsingContext) StructuredDeploymentTracing(org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing) Parser(org.glassfish.hk2.classmodel.reflect.Parser)

Example 14 with StructuredDeploymentTracing

use of org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing 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 15 with StructuredDeploymentTracing

use of org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing 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

StructuredDeploymentTracing (org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing)16 DeploymentSpan (org.glassfish.internal.deployment.analysis.DeploymentSpan)14 PropertyVetoException (java.beans.PropertyVetoException)9 IOException (java.io.IOException)8 ActionReport (org.glassfish.api.ActionReport)8 Deployer (org.glassfish.api.deployment.Deployer)7 Logger (java.util.logging.Logger)6 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)6 DeploymentException (org.glassfish.deployment.common.DeploymentException)6 VersioningSyntaxException (org.glassfish.deployment.versioning.VersioningSyntaxException)6 MultiException (org.glassfish.hk2.api.MultiException)6 EngineInfo (org.glassfish.internal.data.EngineInfo)6 RetryableException (org.jvnet.hk2.config.RetryableException)6 ApplicationMetaDataProvider (org.glassfish.api.deployment.ApplicationMetaDataProvider)4 PayaraExecutorService (fish.payara.nucleus.executorservice.PayaraExecutorService)3 HotDeployService (fish.payara.nucleus.hotdeploy.HotDeployService)3 File (java.io.File)3 URI (java.net.URI)3 ApplicationConfigInfo (org.glassfish.deployment.common.ApplicationConfigInfo)3 com.sun.enterprise.config.serverbeans (com.sun.enterprise.config.serverbeans)2