Search in sources :

Example 6 with StructuredDeploymentTracing

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

the class ApplicationLifecycle method setupContainerInfos.

/**
 * set up containers and prepare the sorted ModuleInfos
 * @param handler
 * @param sniffers
 * @param context
 * @return
 * @throws java.lang.Exception
 */
@Override
public List<EngineInfo> setupContainerInfos(final ArchiveHandler handler, Collection<? extends Sniffer> sniffers, DeploymentContext context) throws Exception {
    final ActionReport report = context.getActionReport();
    StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(context);
    Map<Deployer, EngineInfo> containerInfosByDeployers = new LinkedHashMap<>();
    for (Sniffer sniffer : sniffers) {
        if (sniffer.getContainersNames() == null || sniffer.getContainersNames().length == 0) {
            report.failure(logger, "no container associated with application of type : " + sniffer.getModuleType(), null);
            throw new DeploymentException(localStrings.getLocalString("unknowncontainertype", "There is no installed container capable of handling this application {0}", context.getSource().getName()));
        }
        final String containerName = sniffer.getContainersNames()[0];
        EngineInfo engineInfo = startEngine(context, sniffer, containerName);
        Deployer deployer = startDeployer(context, containerName, engineInfo);
        containerInfosByDeployers.put(deployer, engineInfo);
    }
    // all containers that have recognized parts of the application being deployed
    // have now been successfully started. Start the deployment process.
    List<EngineInfo> sortedEngineInfos = new ArrayList<>();
    // ok everything is satisfied, just a matter of running things in order
    List<Deployer> orderedDeployers = loadDeployers(containerInfosByDeployers, context);
    // now load metadata from deployers.
    for (Deployer deployer : orderedDeployers) {
        if (logger.isLoggable(Level.FINE)) {
            logger.log(FINE, "Ordered Deployer {0}", deployer.getClass());
        }
        final MetaData metadata = deployer.getMetaData();
        EngineInfo engineInfo = containerInfosByDeployers.get(deployer);
        try (DeploymentSpan span = tracing.startSpan(TraceContext.Level.CONTAINER, engineInfo.getSniffer().getModuleType(), DeploymentTracing.AppStage.PREPARE, "MetaData")) {
            if (metadata != null) {
                if (metadata.provides() == null || metadata.provides().length == 0) {
                    deployer.loadMetaData(null, context);
                } else {
                    for (Class<?> provide : metadata.provides()) {
                        if (context.getModuleMetaData(provide) == null) {
                            context.addModuleMetaData(deployer.loadMetaData(provide, context));
                        } else {
                            deployer.loadMetaData(null, context);
                        }
                    }
                }
            } else {
                deployer.loadMetaData(null, context);
            }
        } catch (Exception e) {
            report.failure(logger, "Exception while invoking " + deployer.getClass() + " prepare method", e);
            throw e;
        }
        sortedEngineInfos.add(containerInfosByDeployers.get(deployer));
    }
    return sortedEngineInfos;
}
Also used : Sniffer(org.glassfish.api.container.Sniffer) ActionReport(org.glassfish.api.ActionReport) 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) MetaData(org.glassfish.api.deployment.MetaData) StructuredDeploymentTracing(org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing) DeploymentException(org.glassfish.deployment.common.DeploymentException) DeploymentSpan(org.glassfish.internal.deployment.analysis.DeploymentSpan) Deployer(org.glassfish.api.deployment.Deployer)

Example 7 with StructuredDeploymentTracing

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

the class ApplicationLifecycle method loadDeployers.

private List<Deployer> loadDeployers(Map<Deployer, EngineInfo> containerInfosByDeployers, DeploymentContext context) throws IOException {
    final ActionReport report = context.getActionReport();
    final Map<Class, ApplicationMetaDataProvider> typeByProvider = getTypeByProvider();
    final Map<Class, Deployer> typeByDeployer = getTypeByDeployer(containerInfosByDeployers);
    final StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(context);
    for (Deployer deployer : containerInfosByDeployers.keySet()) {
        if (deployer.getMetaData() != null) {
            for (Class dependency : deployer.getMetaData().requires()) {
                if (!typeByDeployer.containsKey(dependency) && !typeByProvider.containsKey(dependency)) {
                    Service s = deployer.getClass().getAnnotation(Service.class);
                    String serviceName;
                    if (s != null && s.name() != null && s.name().length() > 0) {
                        serviceName = s.name();
                    } else {
                        serviceName = deployer.getClass().getSimpleName();
                    }
                    report.failure(logger, serviceName + " deployer requires " + dependency + " but no other deployer provides it", null);
                    return null;
                }
            }
        }
    }
    List<Deployer> orderedDeployers = new ArrayList<>();
    for (Map.Entry<Deployer, EngineInfo> entry : containerInfosByDeployers.entrySet()) {
        Deployer deployer = entry.getKey();
        if (logger.isLoggable(Level.FINE)) {
            logger.log(FINE, "Keyed Deployer {0}", deployer.getClass());
        }
        DeploymentSpan span = tracing.startSpan(TraceContext.Level.CONTAINER, entry.getValue().getSniffer().getModuleType(), DeploymentTracing.AppStage.PREPARE);
        loadDeployer(orderedDeployers, deployer, typeByDeployer, typeByProvider, context);
        span.close();
    }
    return orderedDeployers;
}
Also used : HotDeployService(fish.payara.nucleus.hotdeploy.HotDeployService) Service(org.jvnet.hk2.annotations.Service) PayaraExecutorService(fish.payara.nucleus.executorservice.PayaraExecutorService) ExecutorService(java.util.concurrent.ExecutorService) ActionReport(org.glassfish.api.ActionReport) EngineInfo(org.glassfish.internal.data.EngineInfo) StructuredDeploymentTracing(org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing) DeploymentSpan(org.glassfish.internal.deployment.analysis.DeploymentSpan) Collectors.toMap(java.util.stream.Collectors.toMap) ParameterMap(org.glassfish.api.admin.ParameterMap) ApplicationMetaDataProvider(org.glassfish.api.deployment.ApplicationMetaDataProvider) Deployer(org.glassfish.api.deployment.Deployer)

Example 8 with StructuredDeploymentTracing

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

the class DolProvider method getNameFor.

/**
 * return the name for the given application
 *
 * @param archive
 * @param context
 * @return
 */
@Override
public String getNameFor(ReadableArchive archive, DeploymentContext context) {
    if (context == null) {
        return null;
    }
    DeployCommandParameters params = context.getCommandParameters(DeployCommandParameters.class);
    Application application;
    StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(context);
    try (DeploymentSpan span = tracing.startSpan(DeploymentTracing.AppStage.DETERMINE_APP_NAME, "DeploymentDescriptors")) {
        // name for ear and module name for standalone module
        if (params.altdd != null || archive.exists("META-INF/application.xml") || archive.exists("WEB-INF/web.xml") || archive.exists("META-INF/ejb-jar.xml") || archive.exists("META-INF/application-client.xml") || archive.exists("META-INF/ra.xml")) {
            String archiveType = context.getArchiveHandler().getArchiveType();
            application = applicationFactory.createApplicationFromStandardDD(archive, archiveType);
            ApplicationHolder holder = new ApplicationHolder(application);
            context.addModuleMetaData(holder);
            return application.getAppName();
        }
    } catch (Exception e) {
        Logger.getAnonymousLogger().log(Level.WARNING, "Error occurred", e);
    }
    return null;
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) StructuredDeploymentTracing(org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing) DeploymentSpan(org.glassfish.internal.deployment.analysis.DeploymentSpan) Application(com.sun.enterprise.deployment.Application) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException)

Example 9 with StructuredDeploymentTracing

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

the class ApplicationInfo method load.

@Override
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);
    StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(context);
    DeploymentSpan span = tracing.startSpan(TraceContext.Level.APPLICATION, name, DeploymentTracing.AppStage.LOAD);
    super.load(context, tracker);
    appClassLoader = context.getClassLoader();
    for (ModuleInfo module : modules) {
        module.load(getSubContext(module, context), tracker);
    }
    populateApplicationServiceLocator();
    isLoaded = true;
    span.close();
    if (events != null) {
        span = tracing.startSpan(TraceContext.Level.APPLICATION, name, DeploymentTracing.AppStage.PROCESS_EVENTS, Deployment.APPLICATION_LOADED.type());
        events.send(new Event<ApplicationInfo>(Deployment.APPLICATION_LOADED, this), false);
        span.close();
    }
}
Also used : StructuredDeploymentTracing(org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing) DeploymentSpan(org.glassfish.internal.deployment.analysis.DeploymentSpan) Logger(java.util.logging.Logger)

Example 10 with StructuredDeploymentTracing

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

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