Search in sources :

Example 1 with ProgressTracker

use of org.glassfish.internal.data.ProgressTracker in project Payara by payara.

the class ApplicationLifecycle method prepare.

@Override
public ApplicationDeployment prepare(Collection<? extends Sniffer> sniffers, final ExtendedDeploymentContext context) {
    StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(context);
    DeploymentSpan eventSpan = tracing.startSpan(DeploymentTracing.AppStage.PROCESS_EVENTS, Deployment.DEPLOYMENT_START.type());
    events.send(new Event<>(Deployment.DEPLOYMENT_START, context), false);
    eventSpan.close();
    currentDeploymentContext.get().push(context);
    final ActionReport report = context.getActionReport();
    final DeployCommandParameters commandParams = context.getCommandParameters(DeployCommandParameters.class);
    final String appName = commandParams.name();
    ApplicationInfo appInfo;
    Optional<ApplicationState> appState = hotDeployService.getApplicationState(context);
    final ClassLoader currentCL = Thread.currentThread().getContextClassLoader();
    ProgressTracker tracker = new ProgressTracker() {

        @Override
        public void actOn(Logger logger) {
            // loaded but may not be started. Issue 18263
            for (EngineRef module : get("loaded", EngineRef.class)) {
                try {
                    module.stop(context);
                } catch (Exception e) {
                // ignore
                }
            }
            try {
                PreDestroy.class.cast(context).preDestroy();
            } catch (Exception e) {
            // ignore
            }
            for (EngineRef module : get("loaded", EngineRef.class)) {
                try {
                    module.unload(context);
                } catch (Exception e) {
                // ignore
                }
            }
            try {
                ApplicationInfo appInfo = appRegistry.get(appName);
                if (appInfo != null) {
                    // send the event to close necessary resources
                    events.send(new Event<>(Deployment.APPLICATION_DISABLED, appInfo));
                }
            } catch (Exception e) {
            // ignore
            }
            for (EngineRef module : get("prepared", EngineRef.class)) {
                try {
                    module.clean(context);
                } catch (Exception e) {
                // ignore
                }
            }
            if (!commandParams.keepfailedstubs) {
                try {
                    context.clean();
                } catch (Exception e) {
                // ignore
                }
            }
            appRegistry.remove(appName);
        }
    };
    try (DeploymentSpan topSpan = tracing.startSpan(DeploymentTracing.AppStage.PREPARE);
        SpanSequence span = tracing.startSequence(DeploymentTracing.AppStage.PREPARE, "ArchiveMetadata")) {
        if (commandParams.origin == OpsParams.Origin.deploy && appRegistry.get(appName) != null && !commandParams.hotDeploy) {
            report.setMessage(localStrings.getLocalString("appnamenotunique", "Application name {0} is already in use. Please pick a different name.", appName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return null;
        }
        // defined virtual servers minus __asadmin on that target
        if (commandParams.virtualservers == null) {
            commandParams.virtualservers = DeploymentUtils.getVirtualServers(commandParams.target, env, domain);
        }
        if (commandParams.enabled == null) {
            commandParams.enabled = Boolean.TRUE;
        }
        if (commandParams.altdd != null) {
            context.getSource().addArchiveMetaData(DeploymentProperties.ALT_DD, commandParams.altdd);
        }
        if (commandParams.runtimealtdd != null) {
            context.getSource().addArchiveMetaData(DeploymentProperties.RUNTIME_ALT_DD, commandParams.runtimealtdd);
        }
        context.addTransientAppMetaData(ExtendedDeploymentContext.TRACKER, tracker);
        context.setPhase(DeploymentContextImpl.Phase.PREPARE);
        span.start("ArchiveHandler");
        ArchiveHandler handler = context.getArchiveHandler();
        if (handler == null) {
            handler = getArchiveHandler(context.getSource(), commandParams.type);
            context.setArchiveHandler(handler);
        }
        if (handler == null) {
            report.setMessage(localStrings.getLocalString("unknownarchivetype", "Archive type of {0} was not recognized", context.getSourceDir()));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return null;
        }
        span.start(DeploymentTracing.AppStage.CLASS_SCANNING);
        if (handler.requiresAnnotationScanning(context.getSource())) {
            getDeployableTypes(context);
        }
        span.finish();
        // is that some container do not support to be restarted.
        if (sniffers != null && logger.isLoggable(Level.FINE)) {
            for (Sniffer sniffer : sniffers) {
                logger.log(FINE, "Before Sorting{0}", sniffer.getModuleType());
            }
        }
        span.start(DeploymentTracing.AppStage.PREPARE, "Sniffer");
        sniffers = getSniffers(handler, sniffers, context);
        final Collection<? extends Sniffer> selectedSniffers = sniffers;
        appState.ifPresent(s -> s.setSniffers(selectedSniffers));
        span.start(DeploymentTracing.AppStage.PREPARE, "ClassLoaderHierarchy");
        ClassLoaderHierarchy clh = habitat.getService(ClassLoaderHierarchy.class);
        span.start(DeploymentTracing.AppStage.PREPARE, "ClassLoader");
        context.createDeploymentClassLoader(clh, handler);
        events.send(new Event<>(Deployment.AFTER_DEPLOYMENT_CLASSLOADER_CREATION, context), false);
        Thread.currentThread().setContextClassLoader(context.getClassLoader());
        span.start(DeploymentTracing.AppStage.PREPARE, "Container");
        final List<EngineInfo> sortedEngineInfos;
        if (appState.map(ApplicationState::getEngineInfos).isPresent()) {
            sortedEngineInfos = appState.get().getEngineInfos();
            loadDeployers(sortedEngineInfos.stream().collect(toMap(EngineInfo::getDeployer, Function.identity())), context);
        } else {
            sortedEngineInfos = setupContainerInfos(handler, sniffers, context);
            appState.ifPresent(s -> s.setEngineInfos(sortedEngineInfos));
        }
        // a bit more is happening here, but I cannot quite describe it yet
        span.start(DeploymentTracing.AppStage.CREATE_CLASSLOADER);
        if (sortedEngineInfos.isEmpty()) {
            throw new DeploymentException(localStrings.getLocalString("unknowncontainertype", "There is no installed container capable of handling this application {0}", context.getSource().getName()));
        }
        if (logger.isLoggable(Level.FINE)) {
            for (EngineInfo info : sortedEngineInfos) {
                logger.log(FINE, "After Sorting {0}", info.getSniffer().getModuleType());
            }
        }
        // create a temporary application info to hold metadata
        // so the metadata could be accessed at classloader
        // construction time through ApplicationInfo
        ApplicationInfo tempAppInfo = new ApplicationInfo(events, context.getSource(), appName);
        for (Object m : context.getModuleMetadata()) {
            tempAppInfo.addMetaData(m);
        }
        tempAppInfo.setIsJavaEEApp(sortedEngineInfos);
        // set the flag on the archive to indicate whether it's
        // a JavaEE archive or not
        context.getSource().setExtraData(Boolean.class, tempAppInfo.isJavaEEApp());
        appRegistry.add(appName, tempAppInfo);
        try {
            notifyLifecycleInterceptorsBefore(ExtendedDeploymentContext.Phase.PREPARE, context);
        } catch (Throwable interceptorException) {
            report.failure(logger, "Exception while invoking the lifecycle interceptor", null);
            report.setFailureCause(interceptorException);
            logger.log(SEVERE, KernelLoggerInfo.lifecycleException, interceptorException);
            tracker.actOn(logger);
            return null;
        }
        events.send(new Event<>(Deployment.DEPLOYMENT_BEFORE_CLASSLOADER_CREATION, context), false);
        context.createApplicationClassLoader(clh, handler);
        tempAppInfo.setAppClassLoader(context.getFinalClassLoader());
        events.send(new Event<>(Deployment.AFTER_APPLICATION_CLASSLOADER_CREATION, context), false);
        // this is a first time deployment as opposed as load following an unload event,
        // we need to create the application info
        // todo : we should come up with a general Composite API solution
        final ModuleInfo moduleInfo;
        try (SpanSequence innerSpan = span.start(DeploymentTracing.AppStage.PREPARE, "Module")) {
            if (appState.map(ApplicationState::getModuleInfo).isPresent()) {
                moduleInfo = appState.get().getModuleInfo();
                moduleInfo.reset();
            } else {
                moduleInfo = prepareModule(sortedEngineInfos, appName, context, tracker);
                appState.ifPresent(s -> s.setModuleInfo(moduleInfo));
            }
            // Now that the prepare phase is done, any artifacts
            // should be available.  Go ahead and create the
            // downloadable client JAR.  We want to do this now, or
            // at least before the load and start phases, because
            // (for example) the app client deployer start phase
            // needs to find all generated files when it runs.
            final ClientJarWriter cjw = new ClientJarWriter(context);
            cjw.run();
        } catch (Throwable prepareException) {
            report.failure(logger, "Exception while preparing the app", null);
            report.setFailureCause(prepareException);
            logger.log(SEVERE, KernelLoggerInfo.lifecycleException, prepareException);
            tracker.actOn(logger);
            return null;
        }
        span.start(DeploymentTracing.AppStage.PROCESS_EVENTS, Deployment.APPLICATION_PREPARED.type());
        // is not a composite module.
        if (appState.map(ApplicationState::getApplicationInfo).isPresent()) {
            appInfo = appState.get().getApplicationInfo();
            appInfo.reset(context.getSource());
            for (Object metadata : context.getModuleMetadata()) {
                moduleInfo.addMetaData(metadata);
                appInfo.addMetaData(metadata);
            }
        } else if ((appInfo = context.getModuleMetaData(ApplicationInfo.class)) == null) {
            ApplicationInfo applicationInfo = new ApplicationInfo(events, context.getSource(), appName);
            appInfo = applicationInfo;
            appInfo.addModule(moduleInfo);
            appState.ifPresent(s -> s.setApplicationInfo(applicationInfo));
            for (Object metadata : context.getModuleMetadata()) {
                moduleInfo.addMetaData(metadata);
                appInfo.addMetaData(metadata);
            }
        } else {
            for (EngineRef ref : moduleInfo.getEngineRefs()) {
                appInfo.add(ref);
            }
        }
        // remove the temp application info from the registry
        // first, then register the real one
        appRegistry.remove(appName);
        appInfo.setIsJavaEEApp(sortedEngineInfos);
        appRegistry.add(appName, appInfo);
        notifyLifecycleInterceptorsAfter(ExtendedDeploymentContext.Phase.PREPARE, context);
        // send the APPLICATION_PREPARED event
        // set the phase and thread context classloader properly
        // before sending the event
        context.setPhase(DeploymentContextImpl.Phase.PREPARED);
        Thread.currentThread().setContextClassLoader(context.getClassLoader());
        appInfo.setAppClassLoader(context.getClassLoader());
        appState.ifPresent(s -> s.setApplicationClassLoader(context.getClassLoader()));
        events.send(new Event<>(Deployment.APPLICATION_PREPARED, context), false);
        if (loadOnCurrentInstance(context)) {
            appInfo.setLibraries(commandParams.libraries());
            try (SpanSequence innerSpan = span.start(DeploymentTracing.AppStage.LOAD)) {
                notifyLifecycleInterceptorsBefore(ExtendedDeploymentContext.Phase.LOAD, context);
                appInfo.load(context, tracker);
                notifyLifecycleInterceptorsAfter(ExtendedDeploymentContext.Phase.LOAD, 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);
                return null;
            }
        }
    } catch (DeploymentException de) {
        report.failure(logger, de.getMessage());
        tracker.actOn(logger);
        return null;
    } catch (Exception e) {
        report.failure(logger, localStrings.getLocalString("error.deploying.app", "Exception while deploying the app [{0}]", appName), null);
        report.setFailureCause(e);
        logger.log(SEVERE, KernelLoggerInfo.lifecycleException, e);
        tracker.actOn(logger);
        return null;
    } finally {
        Thread.currentThread().setContextClassLoader(currentCL);
        if (report.getActionExitCode() != ActionReport.ExitCode.SUCCESS) {
            context.postDeployClean(false);
            events.send(new Event<>(Deployment.DEPLOYMENT_FAILURE, context));
        }
    }
    ApplicationDeployment depl = new ApplicationDeployment(appInfo, context);
    appRegistry.addTransient(depl);
    return depl;
}
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) ArchiveHandler(org.glassfish.api.deployment.archive.ArchiveHandler) ProgressTracker(org.glassfish.internal.data.ProgressTracker) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) ClassLoaderHierarchy(org.glassfish.internal.api.ClassLoaderHierarchy) EngineInfo(org.glassfish.internal.data.EngineInfo) StructuredDeploymentTracing(org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing) SpanSequence(org.glassfish.internal.deployment.analysis.SpanSequence) ApplicationState(fish.payara.nucleus.hotdeploy.ApplicationState) ClientJarWriter(org.glassfish.deployment.common.ClientJarWriter) Sniffer(org.glassfish.api.container.Sniffer) 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) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) ModuleInfo(org.glassfish.internal.data.ModuleInfo) PreDestroy(org.glassfish.hk2.api.PreDestroy) DeploymentException(org.glassfish.deployment.common.DeploymentException) DeploymentSpan(org.glassfish.internal.deployment.analysis.DeploymentSpan)

Example 2 with ProgressTracker

use of org.glassfish.internal.data.ProgressTracker in project Payara by payara.

the class EjbDeployer method clean.

/**
 * Clean any files and artifacts that were created during the execution of the prepare method.
 *
 * @param dc deployment context
 */
public void clean(DeploymentContext dc) {
    // Both undeploy and shutdown scenarios are
    // handled directly in EjbApplication.shutdown.
    // But CMP drop tables should be handled here.
    OpsParams params = dc.getCommandParameters(OpsParams.class);
    if ((params.origin.isUndeploy() || params.origin.isDeploy()) && isDas()) {
        // If CMP beans are present, cmpDeployer should've been initialized in unload()
        if (cmpDeployer != null) {
            cmpDeployer.clean(dc);
        }
        long uniqueAppId = getApplicationFromApplicationInfo(params.name()).getUniqueId();
        try {
            if (getTimeoutStatusFromApplicationInfo(params.name())) {
                EJBTimerService persistentTimerService = null;
                EJBTimerService nonPersistentTimerService = null;
                boolean tsInitialized = false;
                ProgressTracker tracker = dc.getTransientAppMetaData(ExtendedDeploymentContext.TRACKER, ProgressTracker.class);
                if (tracker == null || !tracker.get("initialized", EngineRef.class).isEmpty()) {
                    if (EJBTimerService.isPersistentTimerServiceLoaded()) {
                        persistentTimerService = EJBTimerService.getPersistentTimerService();
                    }
                    if (EJBTimerService.isNonPersistentTimerServiceLoaded()) {
                        nonPersistentTimerService = EJBTimerService.getNonPersistentTimerService();
                    }
                    tsInitialized = true;
                }
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "EjbDeployer APP ID of a Timeout App? {0}", uniqueAppId);
                    _logger.log(Level.FINE, "EjbDeployer Persistent TimerService: {0}", persistentTimerService);
                    _logger.log(Level.FINE, "EjbDeployer Non-Persistent TimerService: {0}", nonPersistentTimerService);
                }
                if (tsInitialized) {
                    if (persistentTimerService == null) {
                        _logger.log(Level.FINE, "EJB Persistent Timer Service is not available. Persistent Timers for application with id {0} will not be deleted", uniqueAppId);
                    } else {
                        if (getKeepStateFromApplicationInfo(params.name())) {
                            _logger.log(Level.INFO, "Persistent Timers will not be destroyed since keepstate is true for application {0}", params.name());
                        } else {
                            persistentTimerService.destroyAllTimers(uniqueAppId);
                        }
                    }
                    if (nonPersistentTimerService == null) {
                        _logger.log(Level.FINE, "EJB Non-Persistent Timer Service is not available. Non-Persistent Timers for application with id {0} will not be deleted", uniqueAppId);
                    } else {
                        nonPersistentTimerService.destroyAllTimers(uniqueAppId);
                    }
                }
            }
        } catch (Exception e) {
            _logger.log(Level.WARNING, "Failed to delete timers for application with id " + uniqueAppId, e);
        }
    }
    // Security related cleanup is to be done for the undeploy event
    if (params.origin.isUndeploy() || params.origin.isDeploy() || params.origin.isLoad()) {
        // Removing EjbSecurityManager for undeploy case
        String appName = params.name();
        String[] contextIds = ejbSecManagerFactory.getContextsForApp(appName, false);
        if (contextIds != null) {
            for (String contextId : contextIds) {
                try {
                    // TODO:appName is not correct, we need the module name
                    // from the descriptor.
                    probeProvider.policyDestructionStartedEvent(contextId);
                    SecurityUtil.removePolicy(contextId);
                    probeProvider.policyDestructionEndedEvent(contextId);
                    probeProvider.policyDestructionEvent(contextId);
                } catch (IASSecurityException ex) {
                    _logger.log(Level.WARNING, "Error removing the policy file " + "for application " + appName + " " + ex);
                }
                List<EJBSecurityManager> managers = ejbSecManagerFactory.getManagers(contextId, false);
                if (managers != null) {
                    for (EJBSecurityManager manager : managers) {
                        manager.destroy();
                    }
                }
            }
        }
        // Removing the RoleMapper
        SecurityUtil.removeRoleMapper(dc);
    }
}
Also used : EJBSecurityManager(org.glassfish.ejb.security.application.EJBSecurityManager) ProgressTracker(org.glassfish.internal.data.ProgressTracker) OpsParams(org.glassfish.api.deployment.OpsParams) EJBTimerService(com.sun.ejb.containers.EJBTimerService) EngineRef(org.glassfish.internal.data.EngineRef) DeploymentException(org.glassfish.deployment.common.DeploymentException) IASSecurityException(com.sun.enterprise.security.util.IASSecurityException) IASSecurityException(com.sun.enterprise.security.util.IASSecurityException)

Example 3 with ProgressTracker

use of org.glassfish.internal.data.ProgressTracker in project Payara by payara.

the class EarDeployer method prepareBundle.

private ModuleInfo prepareBundle(final ModuleDescriptor md, Application application, final ExtendedDeploymentContext bundleContext) throws Exception {
    List<EngineInfo> orderedContainers;
    ProgressTracker tracker = bundleContext.getTransientAppMetaData(ExtendedDeploymentContext.TRACKER, ProgressTracker.class);
    try {
        // let's get the previously stored list of sniffers
        Hashtable<String, Collection<Sniffer>> sniffersTable = bundleContext.getSource().getParentArchive().getExtraData(Hashtable.class);
        Collection<Sniffer> sniffers = sniffersTable.get(md.getArchiveUri());
        // let's get the list of containers interested in this module
        orderedContainers = deployment.setupContainerInfos(null, sniffers, bundleContext);
        if (orderedContainers == null) {
            return null;
        }
    } catch (Exception e) {
        deplLogger.log(Level.WARNING, ERROR_OCCURRED, e);
        throw e;
    }
    return deployment.prepareModule(orderedContainers, md.getArchiveUri(), bundleContext, tracker);
}
Also used : EngineInfo(org.glassfish.internal.data.EngineInfo) ProgressTracker(org.glassfish.internal.data.ProgressTracker) Collection(java.util.Collection) Sniffer(org.glassfish.api.container.Sniffer) IOException(java.io.IOException) DeploymentException(org.glassfish.deployment.common.DeploymentException)

Example 4 with ProgressTracker

use of org.glassfish.internal.data.ProgressTracker in project Payara by payara.

the class ApplicationState method start.

/**
 * Starts the Application state for new deployment by copying the cached
 * metadata and properties to the new {@code DeploymentContext} instance.
 *
 * @param commandParams
 * @param newContext
 * @param events
 * @return
 */
public boolean start(DeployCommandParameters commandParams, ExtendedDeploymentContext newContext, Events events) {
    validateInactiveState();
    this.active = true;
    if (commandParams.sourcesChanged != null) {
        this.classesChanged = new HashMap<>();
        for (String sourcePath : commandParams.sourcesChanged) {
            String className = getClassName(sourcePath);
            if (className != null) {
                this.classesChanged.put(className, sourcePath);
            }
        }
    }
    if (hotswap) {
        final Map<Class<?>, byte[]> reloadMap = new HashMap<>();
        ResourceClassLoader previousResourceClassLoader = ResourceClassLoader.class.cast(applicationClassLoader);
        ConcurrentHashMap<String, ResourceEntry> previousResourceEntries = previousResourceClassLoader.getResourceEntries();
        previousResourceEntries.entrySet().stream().filter(e -> classesChanged.containsKey(e.getKey())).forEach(e -> {
            Class clazz = previousResourceClassLoader.reloadResourceEntry(e.getKey(), classesChanged.get(e.getKey()), e.getValue());
            reloadMap.put(clazz, e.getValue().binaryContent);
        });
        // Update application classloader
        HotSwapHelper.hotswap(reloadMap);
        newContext.setClassLoader(applicationClassLoader);
        ProgressTracker tracker = newContext.getTransientAppMetaData(ExtendedDeploymentContext.TRACKER, ProgressTracker.class);
        try {
            // Reload application metadata
            reloadApplicationMetaData(newContext);
            // Reload application engines
            applicationInfo.reload(newContext, tracker);
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
        return false;
    } else {
        if (this.applicationInfo != null) {
            this.previousClassLoaders = getClassLoaders(this.applicationInfo);
        }
        newContext.getAppProps().putAll(this.deploymentContext.getAppProps());
        newContext.getModulePropsMap().putAll(this.deploymentContext.getModulePropsMap());
        this.deploymentContext = newContext;
        Set<Class> requiredMetaDataClasses = requiredMetaDataClasses();
        this.modulesMetaData.values().stream().filter(md -> !requiredMetaDataClasses.contains(md.getClass())).forEach(newContext::addModuleMetaData);
        this.getDescriptorMetadata().entrySet().forEach(e -> newContext.addTransientAppMetaData(e.getKey(), e.getValue()));
        if (applicationClassLoader != null && applicationClassLoader instanceof ResourceClassLoader) {
            ClassLoader newClassLoader = newContext.getArchiveHandler().getClassLoader(applicationClassLoader.getParent(), newContext);
            ResourceClassLoader newResourceClassLoader = ResourceClassLoader.class.cast(newClassLoader);
            ResourceClassLoader previousResourceClassLoader = ResourceClassLoader.class.cast(applicationClassLoader);
            ConcurrentHashMap<String, ResourceEntry> previousResourceEntries = previousResourceClassLoader.getResourceEntries();
            previousResourceEntries.entrySet().stream().filter(e -> !classesChanged.containsKey(e.getKey())).forEach(e -> newResourceClassLoader.addResourceEntry(e.getKey(), classesChanged.get(e.getKey()), e.getValue()));
            newContext.setClassLoader(newClassLoader);
            if (this.applicationInfo != null) {
                // unload previous app
                events.send(new EventListener.Event<>(Deployment.APPLICATION_UNLOADED, this.applicationInfo), false);
            }
        }
    }
    return true;
}
Also used : Arrays(java.util.Arrays) ApplicationMetaDataProvider(org.glassfish.api.deployment.ApplicationMetaDataProvider) ProgressTracker(org.glassfish.internal.data.ProgressTracker) Globals(org.glassfish.internal.api.Globals) Events(org.glassfish.api.event.Events) HashMap(java.util.HashMap) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) Function(java.util.function.Function) HashSet(java.util.HashSet) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) DeploymentContext(org.glassfish.api.deployment.DeploymentContext) Sniffer(org.glassfish.api.container.Sniffer) EventListener(org.glassfish.api.event.EventListener) PreDestroy(org.glassfish.hk2.api.PreDestroy) ResourceEntry(org.glassfish.api.deployment.ResourceEntry) Collectors.toSet(java.util.stream.Collectors.toSet) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) IOException(java.io.IOException) Logger(java.util.logging.Logger) File(java.io.File) ModuleInfo(org.glassfish.internal.data.ModuleInfo) ResourceClassLoader(org.glassfish.api.deployment.ResourceClassLoader) List(java.util.List) EngineInfo(org.glassfish.internal.data.EngineInfo) Entry(java.util.Map.Entry) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) Optional(java.util.Optional) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) HotSwapHelper(com.sun.enterprise.glassfish.bootstrap.MainHelper.HotSwapHelper) Collections(java.util.Collections) Deployment(org.glassfish.internal.deployment.Deployment) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ProgressTracker(org.glassfish.internal.data.ProgressTracker) IOException(java.io.IOException) ResourceClassLoader(org.glassfish.api.deployment.ResourceClassLoader) ResourceEntry(org.glassfish.api.deployment.ResourceEntry) ResourceClassLoader(org.glassfish.api.deployment.ResourceClassLoader) EventListener(org.glassfish.api.event.EventListener)

Example 5 with ProgressTracker

use of org.glassfish.internal.data.ProgressTracker 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)

Aggregations

ProgressTracker (org.glassfish.internal.data.ProgressTracker)5 IOException (java.io.IOException)4 DeploymentException (org.glassfish.deployment.common.DeploymentException)4 File (java.io.File)3 Function (java.util.function.Function)3 Logger (java.util.logging.Logger)3 Collectors.toMap (java.util.stream.Collectors.toMap)3 Sniffer (org.glassfish.api.container.Sniffer)3 EngineInfo (org.glassfish.internal.data.EngineInfo)3 com.sun.enterprise.config.serverbeans (com.sun.enterprise.config.serverbeans)2 ArchiveFactory (com.sun.enterprise.deploy.shared.ArchiveFactory)2 FileArchive (com.sun.enterprise.deploy.shared.FileArchive)2 LocalStringManagerImpl (com.sun.enterprise.util.LocalStringManagerImpl)2 FileUtils (com.sun.enterprise.util.io.FileUtils)2 DeploymentGroup (fish.payara.enterprise.config.serverbeans.DeploymentGroup)2 PayaraExecutorService (fish.payara.nucleus.executorservice.PayaraExecutorService)2 ApplicationState (fish.payara.nucleus.hotdeploy.ApplicationState)2 HotDeployService (fish.payara.nucleus.hotdeploy.HotDeployService)2 PropertyVetoException (java.beans.PropertyVetoException)2 BufferedInputStream (java.io.BufferedInputStream)2