Search in sources :

Example 21 with ExtendedDeploymentContext

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

the class PostStateCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    final Logger logger = context.getLogger();
    try {
        logger.log(Level.INFO, "PostState starting: " + this.getClass().getName());
        final ExtendedDeploymentContext dc;
        if (suppInfo == null) {
            throw new IllegalStateException("Internal Error: suppInfo was not set. Insure that it is set properly.");
        } else {
            dc = suppInfo.deploymentContext();
        }
        if (dc == null) {
            return;
        }
        final InterceptorNotifier notifier = new InterceptorNotifier(habitat, dc);
        try {
            notifier.ensureAfterReported(ExtendedDeploymentContext.Phase.REPLICATION);
            logger.log(Level.INFO, "PostStateCommand: " + this.getClass().getName() + " finished successfully");
        } catch (Exception e) {
            report.failure(logger, e.getMessage());
            logger.log(Level.SEVERE, "Error during inner PostState: " + this.getClass().getName(), e);
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Error duirng outer PostState: " + this.getClass().getName(), e);
    } finally {
        // null out to prevent class loader leaks as the suppInfo holds a reference to the Deployment Context
        // which holds a reference to the WebAppClassloader and this instance can be cached
        suppInfo = null;
        accessChecks = null;
    }
}
Also used : ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext)

Example 22 with ExtendedDeploymentContext

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

the class PostUndeployCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    final Logger logger = context.getLogger();
    logger.log(Level.INFO, "PostUndeployCommand starting");
    try {
        ActionReport report = context.getActionReport();
        final DeployCommandSupplementalInfo suppInfo = context.getActionReport().getResultType(DeployCommandSupplementalInfo.class);
        /*
         * If the user undeployed by specifying the target as "domain" then
         * the undeploy command has already explicitly sent the undeploy command
         * to the instances and has notified the after(replication) listeners.
         * In that case, the suppInfo won't have been set in the deployment
         * context.
         */
        if (suppInfo == null) {
            return;
        }
        final ExtendedDeploymentContext dc = suppInfo.deploymentContext();
        final InterceptorNotifier notifier = new InterceptorNotifier(habitat, dc);
        try {
            notifier.ensureAfterReported(ExtendedDeploymentContext.Phase.REPLICATION);
            logger.log(Level.INFO, "PostUndeployCommand done successfully");
        } catch (Exception e) {
            report.failure(logger, e.getMessage());
            logger.log(Level.SEVERE, "Error in inner PostUndeployCommand", e);
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Error in outer PostUndeployCommand", e);
    }
}
Also used : Logger(java.util.logging.Logger) ActionReport(org.glassfish.api.ActionReport) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext)

Example 23 with ExtendedDeploymentContext

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

the class PermsArchiveDelegate method processModuleDeclaredAndEEPemirssions.

/**
 * Get the declared permissions and EE permissions, then add them to the classloader
 *
 * @param type module type
 * @param context deployment context
 * @param classloader throws AccessControlException if caller has no privilege
 */
public static void processModuleDeclaredAndEEPemirssions(SMGlobalPolicyUtil.CommponentType type, DeploymentContext context, ClassLoader classloader) throws SecurityException {
    if (System.getSecurityManager() != null) {
        if (!(classloader instanceof DDPermissionsLoader))
            return;
        if (!(context instanceof ExtendedDeploymentContext))
            return;
        DDPermissionsLoader ddcl = (DDPermissionsLoader) classloader;
        if (((ExtendedDeploymentContext) context).getParentContext() == null) {
            PermissionCollection declPc = getDeclaredPermissions(type, context);
            ddcl.addDeclaredPermissions(declPc);
        }
        PermissionCollection eePc = processEEPermissions(type, context);
        ddcl.addEEPermissions(eePc);
    }
}
Also used : PermissionCollection(java.security.PermissionCollection) DDPermissionsLoader(com.sun.enterprise.security.integration.DDPermissionsLoader) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext)

Example 24 with ExtendedDeploymentContext

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

the class EjbApplication method stop.

public boolean stop(ApplicationContext stopContext) {
    DeploymentContext depc = (DeploymentContext) stopContext;
    OpsParams params = depc.getCommandParameters(OpsParams.class);
    boolean keepState = false;
    // keepstate remains the default value (false).
    if (params.origin.isUndeploy()) {
        keepState = resolveKeepStateOptions(depc, false, ejbBundle);
        if (keepState) {
            Properties appProps = depc.getAppProps();
            Object appId = appProps.get(EjbDeployer.APP_UNIQUE_ID_PROP);
            Properties actionReportProps = null;
            if (ejbBundle.getApplication().isVirtual()) {
                actionReportProps = depc.getActionReport().getExtraProperties();
            } else {
                // the application is EAR
                ExtendedDeploymentContext exdc = (ExtendedDeploymentContext) depc;
                actionReportProps = exdc.getParentContext().getActionReport().getExtraProperties();
            }
            actionReportProps.put(EjbDeployer.APP_UNIQUE_ID_PROP, appId);
            actionReportProps.put(EjbApplication.KEEP_STATE, String.valueOf(true));
            _logger.log(Level.INFO, "keepstate options resolved to true, saving appId {0} for application {1}.", new Object[] { appId, params.name() });
        }
    }
    // If true we're shutting down b/c of an undeploy or a fatal error during
    // deployment.  If false, it's a shutdown where the application will remain
    // deployed.
    boolean undeploy = (params.origin.isUndeploy() || params.origin.isDeploy());
    // and Application.  For failed deploy, keepstate is the default value (false).
    if (undeploy) {
        // store keepstate in ApplicationInfo to make it available to
        // EjbDeployer.clean().  A different instance of DeploymentContext
        // is passed to EjbDeployer.clean so we cannot use anything in DC (e.g.
        // appProps, transientData) to store keepstate.
        ApplicationRegistry appRegistry = services.getService(ApplicationRegistry.class);
        ApplicationInfo appInfo = appRegistry.get(params.name());
        appInfo.addTransientAppMetaData(KEEP_STATE, keepState);
        // store keepState in Application to make it available to subsequent
        // undeploy-related methods.
        ejbBundle.getApplication().setKeepStateResolved(String.valueOf(keepState));
    }
    // First, shutdown any singletons that were initialized based
    // on a particular ordering dependency.
    // TODO Make sure this covers both eagerly and lazily initialized
    // Singletons.
    singletonLCM.doShutdown();
    for (Container container : containers) {
        if (undeploy) {
            container.undeploy();
        } else {
            container.onShutdown();
        }
        if (container.getSecurityManager() != null) {
            container.getSecurityManager().destroy();
        }
    }
    containers.clear();
    return true;
}
Also used : DeploymentContext(org.glassfish.api.deployment.DeploymentContext) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) ApplicationRegistry(org.glassfish.internal.data.ApplicationRegistry) Container(com.sun.ejb.Container) AbstractSingletonContainer(com.sun.ejb.containers.AbstractSingletonContainer) ApplicationContainer(org.glassfish.api.deployment.ApplicationContainer) OpsParams(org.glassfish.api.deployment.OpsParams) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) Properties(java.util.Properties) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext)

Example 25 with ExtendedDeploymentContext

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

the class DescriptorFactory method createApplicationDescriptor.

/**
 * Returns the parsed DOL object from archive
 *
 * @param archiveFile original archive file
 * @param destRootDir root destination directory where the application
 *        should be expanded under in case of archive deployment
 * @param parentCl parent classloader
 *
 * @return the parsed DOL object
 */
public ResultHolder createApplicationDescriptor(File archiveFile, File destRootDir, ClassLoader parentCl) throws IOException {
    ReadableArchive archive = null;
    Application application = null;
    try {
        Descriptor.setBoundsChecking(false);
        archive = archiveFactory.openArchive(archiveFile);
        ArchiveHandler archiveHandler = deployment.getArchiveHandler(archive);
        ActionReport dummyReport = new HTMLActionReporter();
        String appName = DeploymentUtils.getDefaultEEName(archiveFile.getName());
        DeployCommandParameters params = new DeployCommandParameters();
        params.name = appName;
        ExtendedDeploymentContext context = new DeploymentContextImpl(dummyReport, archive, params, env);
        context.setArchiveHandler(archiveHandler);
        if (!archiveFile.isDirectory()) {
            // expand archive
            File destDir = new File(destRootDir, appName);
            if (destDir.exists()) {
                FileUtils.whack(destDir);
            }
            destDir.mkdirs();
            archiveHandler.expand(archive, archiveFactory.createArchive(destDir), context);
            archive.close();
            archive = archiveFactory.openArchive(destDir);
            context.setSource(archive);
        }
        // issue 14564
        context.addTransientAppMetaData(ExtendedDeploymentContext.IS_TEMP_CLASSLOADER, Boolean.TRUE);
        String archiveType = context.getArchiveHandler().getArchiveType();
        ClassLoader cl = archiveHandler.getClassLoader(parentCl, context);
        Archivist archivist = archivistFactory.getArchivist(archiveType, cl);
        if (archivist == null) {
            throw new IOException("Cannot determine the Java EE module type for " + archive.getURI());
        }
        archivist.setAnnotationProcessingRequested(true);
        String xmlValidationLevel = dasConfig.getDeployXmlValidation();
        archivist.setXMLValidationLevel(xmlValidationLevel);
        if (xmlValidationLevel.equals("none")) {
            archivist.setXMLValidation(false);
        }
        archivist.setRuntimeXMLValidation(false);
        try {
            application = applicationFactory.openArchive(appName, archivist, archive, true);
        } catch (SAXParseException e) {
            throw new IOException(e);
        }
        if (application != null) {
            application.setClassLoader(cl);
            application.visit((ApplicationVisitor) new ApplicationValidator());
        }
    } finally {
        if (archive != null) {
            archive.close();
        }
        // We need to reset it after descriptor building
        Descriptor.setBoundsChecking(true);
    }
    ResultHolder result = new ResultHolder();
    result.application = application;
    result.archive = archive;
    return result;
}
Also used : ArchiveHandler(org.glassfish.api.deployment.archive.ArchiveHandler) Archivist(com.sun.enterprise.deployment.archivist.Archivist) IOException(java.io.IOException) ActionReport(org.glassfish.api.ActionReport) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) DeploymentContextImpl(org.glassfish.deployment.common.DeploymentContextImpl) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) ApplicationValidator(com.sun.enterprise.deployment.util.ApplicationValidator) SAXParseException(org.xml.sax.SAXParseException) HTMLActionReporter(com.sun.enterprise.v3.common.HTMLActionReporter) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) Application(com.sun.enterprise.deployment.Application) File(java.io.File)

Aggregations

ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)39 ActionReport (org.glassfish.api.ActionReport)23 IOException (java.io.IOException)17 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)17 File (java.io.File)16 Logger (java.util.logging.Logger)11 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)11 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)10 Properties (java.util.Properties)9 URI (java.net.URI)7 Deployment (org.glassfish.internal.deployment.Deployment)7 DeploymentContext (org.glassfish.api.deployment.DeploymentContext)6 UndeployCommandParameters (org.glassfish.api.deployment.UndeployCommandParameters)6 ArchiveHandler (org.glassfish.api.deployment.archive.ArchiveHandler)6 DeploymentContextImpl (org.glassfish.deployment.common.DeploymentContextImpl)6 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)6 Application (com.sun.enterprise.deployment.Application)5 ArrayList (java.util.ArrayList)5 DeploymentProperties (org.glassfish.deployment.common.DeploymentProperties)5 VersioningException (org.glassfish.deployment.versioning.VersioningException)5