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