Search in sources :

Example 1 with OpsParams

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

the class SecurityDeployer method unload.

@Override
public void unload(DummyApplication container, DeploymentContext context) {
    OpsParams params = context.getCommandParameters(OpsParams.class);
    cleanSecurityContext(params.name());
}
Also used : OpsParams(org.glassfish.api.deployment.OpsParams)

Example 2 with OpsParams

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

the class JPADeployer method cleanArtifacts.

protected void cleanArtifacts(DeploymentContext dc) throws DeploymentException {
    // Drop tables if needed on undeploy.
    OpsParams params = dc.getCommandParameters(OpsParams.class);
    if (params.origin.isUndeploy() && isDas()) {
        boolean hasScopedResource = false;
        String appName = params.name();
        ApplicationInfo appInfo = applicationRegistry.get(appName);
        Application application = appInfo.getMetaData(Application.class);
        Set<BundleDescriptor> bundles = application.getBundleDescriptors();
        // Iterate through all the bundles of the app and collect pu references in referencedPus
        for (BundleDescriptor bundle : bundles) {
            Collection<? extends PersistenceUnitDescriptor> pusReferencedFromBundle = bundle.findReferencedPUs();
            for (PersistenceUnitDescriptor pud : pusReferencedFromBundle) {
                hasScopedResource = hasScopedResource(pud);
                if (hasScopedResource) {
                    break;
                }
            }
        }
        // delete tables.
        if (hasScopedResource) {
            connectorRuntime.registerDataSourceDefinitions(application);
        }
        Java2DBProcessorHelper helper = new Java2DBProcessorHelper(dc);
        helper.init();
        // NOI18N
        helper.createOrDropTablesInDB(false, "JPA");
        // if there are scoped resources, undeploy them.
        if (hasScopedResource) {
            connectorRuntime.unRegisterDataSourceDefinitions(application);
        }
    }
}
Also used : Java2DBProcessorHelper(org.glassfish.persistence.common.Java2DBProcessorHelper) OpsParams(org.glassfish.api.deployment.OpsParams) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo)

Example 3 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 4 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);
        }
        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 5 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;
        // target could be null for internal apps such as wstx-services or admin console
        boolean isDeploymentGroup = dcp.target == null ? false : domain.getDeploymentGroupNamed(dcp.target) != null;
        boolean isDeployment = opsparams.origin.isDeploy() || opsparams.origin.isCreateAppRef();
        boolean isDirectTarget = env.getInstanceName().equals(dcp.target);
        // Create timers on DAS only if this condition is not met
        if (!isDeployment || isDirectTarget) {
            // Otherwise, 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;
        }
        if (isDeploymentGroup) {
            _logger.log(Level.WARNING, "Deployment targets deployment group {0}, it is assumed that timer " + "service configuration is consistent accross all members of the group", dcp.target);
        }
        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) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) Application(com.sun.enterprise.deployment.Application) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Aggregations

OpsParams (org.glassfish.api.deployment.OpsParams)14 IASSecurityException (com.sun.enterprise.security.util.IASSecurityException)4 DeploymentException (org.glassfish.deployment.common.DeploymentException)4 Application (com.sun.enterprise.deployment.Application)3 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)3 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)3 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)3 File (java.io.File)2 Properties (java.util.Properties)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 IOException (java.io.IOException)1 List (java.util.List)1 ActionReport (org.glassfish.api.ActionReport)1 ApplicationContainer (org.glassfish.api.deployment.ApplicationContainer)1 DeploymentContext (org.glassfish.api.deployment.DeploymentContext)1