Search in sources :

Example 6 with OpsParams

use of org.glassfish.api.deployment.OpsParams 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);
        }
        Properties appProps = dc.getAppProps();
        String uniqueAppId = appProps.getProperty(APP_UNIQUE_ID_PROP);
        try {
            if (getTimeoutStatusFromApplicationInfo(params.name()) && uniqueAppId != null) {
                String target = ((params.origin.isDeploy()) ? dc.getCommandParameters(DeployCommandParameters.class).target : dc.getCommandParameters(UndeployCommandParameters.class).target);
                if (DeploymentUtils.isDomainTarget(target)) {
                    List<String> targets = (List<String>) dc.getTransientAppMetaData(DeploymentProperties.PREVIOUS_TARGETS, List.class);
                    if (targets == null) {
                        targets = domain.getAllReferencedTargetsForApplication(params.name());
                    }
                    if (targets != null && targets.size() > 0) {
                        target = targets.get(0);
                    }
                }
                EJBTimerService timerService = null;
                boolean tsInitialized = false;
                ProgressTracker tracker = dc.getTransientAppMetaData(ExtendedDeploymentContext.TRACKER, ProgressTracker.class);
                if (tracker == null || !tracker.get("initialized", EngineRef.class).isEmpty()) {
                    timerService = EJBTimerService.getEJBTimerService(target, false);
                    tsInitialized = true;
                }
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "EjbDeployer APP ID of a Timeout App? " + uniqueAppId);
                    _logger.log(Level.FINE, "EjbDeployer TimerService: " + timerService);
                }
                if (tsInitialized) {
                    if (timerService == null) {
                        _logger.log(Level.WARNING, "EJB Timer Service is not available. Timers for application with id " + uniqueAppId + " will not be deleted");
                    } else {
                        if (getKeepStateFromApplicationInfo(params.name())) {
                            _logger.log(Level.INFO, "Timers will not be destroyed since keepstate is true for application {0}", params.name());
                        } else {
                            timerService.destroyAllTimers(Long.parseLong(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);
                }
                ArrayList<EJBSecurityManager> managers = ejbSecManagerFactory.getManagers(contextId, false);
                if (managers != null) {
                    for (EJBSecurityManager m : managers) {
                        m.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) DeploymentProperties(org.glassfish.deployment.common.DeploymentProperties) Properties(java.util.Properties) 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) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) UndeployCommandParameters(org.glassfish.api.deployment.UndeployCommandParameters) List(java.util.List) ArrayList(java.util.ArrayList)

Example 7 with OpsParams

use of org.glassfish.api.deployment.OpsParams in project Payara by payara.

the class EjbDeployer method event.

@Override
public void event(Event event) {
    if (event.is(Deployment.APPLICATION_PREPARED) && isDas()) {
        ExtendedDeploymentContext context = (ExtendedDeploymentContext) event.hook();
        OpsParams opsparams = context.getCommandParameters(OpsParams.class);
        DeployCommandParameters dcp = context.getCommandParameters(DeployCommandParameters.class);
        ApplicationInfo appInfo = appRegistry.get(opsparams.name());
        Application app = appInfo.getMetaData(Application.class);
        if (app == null) {
            // Not a Java EE application
            return;
        }
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "EjbDeployer in APPLICATION_PREPARED for origin: " + opsparams.origin + ", target: " + dcp.target + ", name: " + opsparams.name());
        }
        boolean createTimers = true;
        if (!(opsparams.origin.isDeploy() || opsparams.origin.isCreateAppRef()) || env.getInstanceName().equals(dcp.target)) {
            // Timers will be created by the BaseContainer if it's a single instance deploy
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "EjbDeployer ... will only set the timeout application flag if any");
            }
            // But is-timed-app needs to be set in AppInfo in any case
            createTimers = false;
        }
        String target = dcp.target;
        if (createTimers && dcp.isredeploy != null && dcp.isredeploy && DeploymentUtils.isDomainTarget(target)) {
            List<String> targets = (List<String>) context.getTransientAppMetaData(DeploymentProperties.PREVIOUS_TARGETS, List.class);
            for (String ref : targets) {
                target = ref;
                if (domain.getClusterNamed(target) != null || domain.getDeploymentGroupNamed(target) != null) {
                    // prefer cluster target
                    break;
                }
            }
        }
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "EjbDeployer using target for event as " + target);
        }
        boolean isTimedApp = false;
        for (EjbBundleDescriptorImpl ejbBundle : app.getBundleDescriptors(EjbBundleDescriptorImpl.class)) {
            if (checkEjbBundleForTimers(ejbBundle, createTimers, target)) {
                isTimedApp = true;
            }
        }
        if (isTimedApp && (opsparams.origin.isDeploy() || opsparams.origin.isLoad())) {
            // Mark application as a timeout application, so that the clean() call removes the timers.
            appInfo.addTransientAppMetaData(IS_TIMEOUT_APP_PROP, Boolean.TRUE);
        }
    }
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) OpsParams(org.glassfish.api.deployment.OpsParams) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) List(java.util.List) ArrayList(java.util.ArrayList) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) Application(com.sun.enterprise.deployment.Application) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Example 8 with OpsParams

use of org.glassfish.api.deployment.OpsParams in project Payara by payara.

the class EjbDeployer method prepare.

@Override
public boolean prepare(DeploymentContext dc) {
    EjbBundleDescriptorImpl ejbBundle = dc.getModuleMetaData(EjbBundleDescriptorImpl.class);
    if (ejbBundle == null) {
        String errMsg = localStrings.getLocalString("context.contains.no.ejb", "DeploymentContext does not contain any EJB", dc.getSourceDir());
        throw new RuntimeException(errMsg);
    }
    // Get application-level properties (*not* module-level)
    Properties appProps = dc.getAppProps();
    long uniqueAppId;
    if (!appProps.containsKey(APP_UNIQUE_ID_PROP)) {
        // This is the first time load is being called for any ejb module in an
        // application, so generate the unique id.
        uniqueAppId = getNextEjbAppUniqueId();
        appProps.setProperty(APP_UNIQUE_ID_PROP, uniqueAppId + "");
    } else {
        uniqueAppId = Long.parseLong(appProps.getProperty(APP_UNIQUE_ID_PROP));
    }
    OpsParams params = dc.getCommandParameters(OpsParams.class);
    if (params.origin.isDeploy()) {
        // KEEP_STATE is saved to AppProps in EjbApplication.stop
        String keepStateVal = (String) dc.getAppProps().get(EjbApplication.KEEP_STATE);
        if (keepStateVal != null) {
            // save KEEP_STATE to Application so subsequent to make it available
            // to subsequent deploy-related methods.
            ejbBundle.getApplication().setKeepStateResolved(keepStateVal);
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "EjbDeployer.prepare set keepstate to {0} for application.", ejbBundle.getApplication().getKeepStateResolved());
            }
        }
    }
    Application app = ejbBundle.getApplication();
    if (!app.isUniqueIdSet()) {
        // This will set the unique id for all EJB components in the application.
        // If there are multiple ejb modules in the app, we'll only call it once
        // for the first ejb module load().  All the old
        // .xml processing for unique-id in the sun-* descriptors is removed so
        // this is the only place where Application.setUniqueId() should be called.
        app.setUniqueId(uniqueAppId);
    }
    return super.prepare(dc);
}
Also used : OpsParams(org.glassfish.api.deployment.OpsParams) DeploymentProperties(org.glassfish.deployment.common.DeploymentProperties) Properties(java.util.Properties) Application(com.sun.enterprise.deployment.Application) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Example 9 with OpsParams

use of org.glassfish.api.deployment.OpsParams in project Payara by payara.

the class SecurityUtil method removeRoleMapper.

public static void removeRoleMapper(DeploymentContext dc) {
    OpsParams params = dc.getCommandParameters(OpsParams.class);
    if (params.origin != OpsParams.Origin.undeploy) {
        return;
    }
    String appName = params.name();
    SecurityRoleMapperFactory factory = getRoleMapperFactory();
    factory.removeRoleMapper(appName);
}
Also used : OpsParams(org.glassfish.api.deployment.OpsParams) SecurityRoleMapperFactory(org.glassfish.deployment.common.SecurityRoleMapperFactory)

Example 10 with OpsParams

use of org.glassfish.api.deployment.OpsParams 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)

Aggregations

OpsParams (org.glassfish.api.deployment.OpsParams)13 IASSecurityException (com.sun.enterprise.security.util.IASSecurityException)4 DeploymentException (org.glassfish.deployment.common.DeploymentException)4 Application (com.sun.enterprise.deployment.Application)3 Properties (java.util.Properties)3 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)3 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)3 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 DeploymentProperties (org.glassfish.deployment.common.DeploymentProperties)2 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)2 Container (com.sun.ejb.Container)1 StaticRmiStubGenerator (com.sun.ejb.codegen.StaticRmiStubGenerator)1 AbstractSingletonContainer (com.sun.ejb.containers.AbstractSingletonContainer)1 EJBTimerService (com.sun.ejb.containers.EJBTimerService)1 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)1 File (java.io.File)1 ApplicationContainer (org.glassfish.api.deployment.ApplicationContainer)1 DeploymentContext (org.glassfish.api.deployment.DeploymentContext)1