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());
}
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);
}
}
}
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);
}
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);
}
}
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);
}
}
}
Aggregations