public void undeploy(String appName, ExtendedDeploymentContext context) { ActionReport report = context.getActionReport(); UndeployCommandParameters params = context.getCommandParameters(UndeployCommandParameters.class); ApplicationInfo info = appRegistry.get(appName); if (info==null) { report.failure(context.getLogger(), "Application " + appName + " not registered", null); events.send(new Event(Deployment.UNDEPLOYMENT_FAILURE, context)); return; } events.send(new Event(Deployment.UNDEPLOYMENT_START, info)); // for DAS target, the undeploy should unload the application // as well if (DeploymentUtils.isDASTarget(params.target)) { unload(info, context); } if (report.getActionExitCode().equals(ActionReport.ExitCode.SUCCESS)) { events.send(new Event(Deployment.UNDEPLOYMENT_SUCCESS, context)); deploymentLifecycleProbeProvider.applicationUndeployedEvent(appName, getApplicationType(info)); } else { events.send(new Event(Deployment.UNDEPLOYMENT_FAILURE, context)); } appRegistry.remove(appName); }
List<URI> classPathURIs = handler.getClassPathURIs(archive); classPathURIs.addAll(getLibraryJarURIs(app, archive)); Types types = archive.getParentArchive().getExtraData(Types.class); DeployCommandParameters parameters = archive.getParentArchive().getArchiveMetaData(DeploymentProperties.COMMAND_PARAMS, DeployCommandParameters.class); Properties appProps = archive.getParentArchive().getArchiveMetaData(DeploymentProperties.APP_PROPS, Properties.class); ExtendedDeploymentContext context = new DeploymentContextImpl(null, archive, parameters, habitat.<ServerEnvironment>getService(ServerEnvironment.class)); if (appProps != null) { context.getAppProps().putAll(appProps); context.setArchiveHandler(handler); context.addTransientAppMetaData(Types.class.getName(), types); Collection<Sniffer> sniffers = snifferManager.getSniffers(context, classPathURIs, types); context.postDeployClean(true); String type = getTypeFromModuleType(md.getModuleType()); Sniffer mainSniffer = null;
@SuppressWarnings("unchecked") private Properties getActionReportProperties(DeploymentContext deployContext) { if (!wmInfo.getDescriptor().getApplication().isVirtual()) { deployContext = ((ExtendedDeploymentContext)deployContext).getParentContext(); } return deployContext.getActionReport().getExtraProperties(); }
public void unload(ExtendedDeploymentContext context) { Logger logger = context.getLogger(); if (!isLoaded) { logger.fine("Application is already unloaded."); return; } ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(appClassLoader); context.setClassLoader(appClassLoader); super.unload(context); for (ModuleInfo module : reversedModules) { module.unload(getSubContext(module, context)); } isLoaded = false; if (events!=null) { events.send(new Event<ApplicationInfo>(Deployment.APPLICATION_UNLOADED, this), false); } } finally { Thread.currentThread().setContextClassLoader(currentClassLoader); context.setClassLoader(null); } }
/** * unloads the module from its container. * * @param context unloading context * @return */ public boolean unload(ExtendedDeploymentContext context) { ActionReport report = context.getActionReport(); // then remove the application from the container Deployer deployer = ctrInfo.getDeployer(); try { deployer.unload(appCtr, context); ctrInfo.unload(context); } catch(Exception e) { report.failure(context.getLogger(), "Exception while shutting down application container", e); return false; } appCtr=null; return true; }
public ApplicationInfo unload(ApplicationInfo info, ExtendedDeploymentContext context) { ActionReport report = context.getActionReport(); if (info==null) { report.failure(context.getLogger(), "Application not registered", null); return null; } notifyLifecycleInterceptorsBefore(ExtendedDeploymentContext.Phase.STOP, context); if (info.isLoaded()) { info.stop(context, context.getLogger()); notifyLifecycleInterceptorsAfter(ExtendedDeploymentContext.Phase.STOP, context); notifyLifecycleInterceptorsBefore(ExtendedDeploymentContext.Phase.UNLOAD, context); info.unload(context); notifyLifecycleInterceptorsAfter(ExtendedDeploymentContext.Phase.UNLOAD, context); } events.send(new Event<ApplicationInfo>(Deployment.APPLICATION_DISABLED, info), false); try { notifyLifecycleInterceptorsBefore(ExtendedDeploymentContext.Phase.CLEAN, context); info.clean(context); notifyLifecycleInterceptorsAfter(ExtendedDeploymentContext.Phase.CLEAN, context); } catch(Exception e) { report.failure(context.getLogger(), "Exception while cleaning", e); return info; } return info; }
} catch (VersioningWildcardException ex) { File file = null; DeployCommandParameters commandParams=null; Properties contextProps = new Properties(); Map<String, Properties> modulePropsMap = null; ApplicationConfigInfo savedAppConfig = null; deployment.getBuilder(logger, commandParams, report).source(archive).build(); Properties appProps = deploymentContext.getAppProps(); appProps.putAll(contextProps); appProps.setProperty(ServerTags.LOCATION, location); deploymentContext.setModulePropsMap(modulePropsMap); versioningService.handleDisable(appName, target, deploymentContext.getActionReport()); } else { events.send(new Event<DeploymentContext>(Deployment.APPLICATION_PREPARED, deploymentContext), false); } finally { try { archive.close(); } catch(IOException e) { logger.log(Level.INFO, "Error while closing deployable artifact : " + file.getAbsolutePath(), e);
source(initialContext.getSource()).archiveHandler(archiveHandler).build(initialContext); if (tracing!=null) { tracing.addMark(DeploymentTracing.Mark.CONTEXT_CREATED); deploymentContext.addModuleMetaData(tracing); deploymentContext.getAppProps().putAll(undeployProps); properties = new Properties(); properties.putAll(property); deploymentContext.getAppProps().putAll(properties); validateDeploymentProperties(properties, deploymentContext); deploymentContext.clean(); Properties appProps = deploymentContext.getAppProps(); String appLocation = DeploymentUtils.relativizeWithinDomainIfPossible( deploymentContext.getSource().getURI()); deploymentContext.addTransientAppMetaData(DeploymentProperties.PREVIOUS_TARGETS, previousTargets); deploymentContext.addTransientAppMetaData(DeploymentProperties.PREVIOUS_VIRTUAL_SERVERS, previousVirtualServers); deploymentContext.addTransientAppMetaData(DeploymentProperties.PREVIOUS_ENABLED_ATTRIBUTES, previousEnabledAttributes); deploymentContext.clean(); throw e; deploymentContext.postDeployClean(true);
String compatProp = context.getAppProps().getProperty( DeploymentProperties.COMPATIBILITY); compatProp = gfApplicationXmlParser.getCompatibilityValue(); if (compatProp != null) { context.getAppProps().put( DeploymentProperties.COMPATIBILITY, compatProp); compatProp = sunApplicationXmlParser.getCompatibilityValue(); if (compatProp != null) { context.getAppProps().put( DeploymentProperties.COMPATIBILITY, compatProp); String moduleUri = md.getArchiveUri(); try { sub = archive.getSubArchive(moduleUri); if (sub instanceof InputJarArchive) { throw new IllegalArgumentException(strings.get("wrongArchType", moduleUri)); context.getActionReport().addSubActionsReport(); subContext.setArchiveHandler (context.getArchiveHandler()); subContext.setParentContext((ExtendedDeploymentContext)context); sub.setParentArchive(context.getSource());
String vs = previousVirtualServers.getProperty(target); if (vs != null) { this.virtualservers = vs; String enabledAttr = previousEnabledAttributes.getProperty(target); if (enabledAttr != null) { String enabledAttrForApp = previousEnabledAttributes.getProperty(DeploymentUtils.DOMAIN_TARGET_NAME); this.enabled = Boolean.valueOf(enabledAttr) && Boolean.valueOf(enabledAttrForApp); report.setMessage(localStrings.getLocalString("fnf","File not found", path.getAbsolutePath())); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; report.failure(logger,msg); return; deploymentContext.clean(); deploymentContext.getAppProps().putAll(appprops); deploymentContext.clean(); throw e; try { if (archive != null) { archive.close();
if (Boolean.valueOf(app.getDeployProperties().getProperty (ServerTags.IS_LIFECYCLE))) { return; ExtendedDeploymentContext depContext = deployment.getBuilder(logger, deploymentParams, report).source(archive).build(); if (tracing!=null) { depContext.addModuleMetaData(tracing); depContext.getAppProps().putAll(app.getDeployProperties()); depContext.setModulePropsMap(app.getModulePropertiesMap()); new ApplicationConfigInfo(app).store(depContext.getAppProps()); if (report.getActionExitCode().equals(ActionReport.ExitCode.SUCCESS)) { if (tracing!=null) { tracing.print(System.out); appName, (Calendar.getInstance().getTimeInMillis() - operationStartTime)}); } else { logger.log(Level.SEVERE, KernelLoggerInfo.deployFail, report.getMessage()); archive.close(); } catch(IOException e) { logger.log(Level.FINE, KernelLoggerInfo.deployException, e);
public void registerTenantWithAppInDomainXML( final String appName, final ExtendedDeploymentContext context) throws TransactionFailure { final Transaction t = new Transaction(); try { final AppTenant appTenant_w = writeableTenantForApp( appName, t); appTenant_w.setContextRoot(context.getAppProps().getProperty(ServerTags.CONTEXT_ROOT)); appTenant_w.setTenant(context.getTenant()); t.commit(); } catch (TransactionFailure ex) { t.rollback(); throw ex; } catch (Throwable ex) { t.rollback(); throw new TransactionFailure(ex.getLocalizedMessage(), ex); } }
validateTarget(target, name); } catch (IllegalArgumentException ie) { report.setMessage(ie.getMessage()); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; Properties appProps = deploymentContext.getAppProps(); appProps.putAll(property); appProps.setProperty(ServerTags.OBJECT_TYPE, "user"); appProps.setProperty(ServerTags.CLASS_NAME, classname); if (classpath != null) { appProps.setProperty(ServerTags.CLASSPATH, classpath); deployment.registerAppInDomainXML(null, deploymentContext, t); } catch(Exception e) { report.setMessage("Failed to create lifecycle module: " + e); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return;
if (keepState) { Properties appProps = depc.getAppProps(); Object appId = appProps.get(EjbDeployer.APP_UNIQUE_ID_PROP); Properties actionReportProps = null; 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()}); appInfo.addTransientAppMetaData(KEEP_STATE, keepState);
ExtendedDeploymentContext dc = deployment.getBuilder( logger, params, report).source(app).build(); dc.addTransientAppMetaData(DatabaseConstants.JTA_DATASOURCE_JNDI_NAME_OVERRIDE, resourceName); Properties appProps = dc.getAppProps(); appProps.setProperty(ServerTags.OBJECT_TYPE, DeploymentProperties.SYSTEM_ALL); if (report.getActionExitCode() != ActionReport.ExitCode.SUCCESS) { logger.log (Level.WARNING, "Cannot deploy or load EJBTimerService: ", report.getFailureCause()); } else { deployed = true;
File sourceFile = new File(archive.getURI().getSchemeSpecificPart()); initial.getAppProps().put(ServerTags.DEFAULT_APP_NAME, DeploymentUtils.getDefaultEEName(sourceFile.getName())); } catch (VersioningSyntaxException e) { ActionReport report = copy.report(); report.setMessage(e.getMessage()); report.setActionExitCode(ActionReport.ExitCode.FAILURE); archive.close(); } catch(IOException e) { logger.log(Level.SEVERE, KernelLoggerInfo.errorClosingArtifact, new Object[] { archive.getURI().getSchemeSpecificPart(), e}); throw e; initial.setSource(archive); } catch(IOException e) { logger.log(Level.SEVERE, KernelLoggerInfo.errorExpandingFile, e); initial.setArchiveHandler(archiveHandler); return initial;
matchedVersions = versioningService.getMatchedVersions(name, target); } catch (VersioningException e) { report.failure(logger, e.getMessage()); return; report.setMessage(localStrings.getLocalString("ref.not.referenced.target","Application {0} is not referenced by target {1}", name, target)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); ApplicationInfo appInfo = deployment.get(appName); if (appInfo != null) { source = appInfo.getSource(); } else { File location = new File(new URI(application.getLocation())); deploymentContext.getAppProps().putAll( application.getDeployProperties()); deploymentContext.setModulePropsMap( application.getModulePropertiesMap()); deploymentContext.clean(); if (!Boolean.valueOf(application.getDirectoryDeployed()) && source.exists()) { FileUtils.whack(new File(source.getURI()));
report.setMessage( "Cannot find deployed application of name " + name); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; ReadableArchive source = appInfo.getSource(); if (source == null) { report.setMessage( "Cannot get source archive for undeployment"); report.setActionExitCode(ActionReport.ExitCode.FAILURE); for (ModuleInfo module : appInfo.getModuleInfos()) { info.map.put(module.getName(), module.getModuleProps()); deploymentContext.getModuleProps().putAll(module.getModuleProps()); deploymentContext.setModulePropsMap(info.map); deploymentContext.getAppProps().putAll(info.appProps); params.keepreposdir = false; if ( !params.keepreposdir && info != null && !info.isDirectory && source.exists()) { FileUtils.whack(new File(source.getURI())); deploymentContext.clean();
public ExtendedDeploymentContext disable(UndeployCommandParameters commandParams, Application app, ApplicationInfo appInfo, ActionReport report, Logger logger) throws Exception { if (appInfo == null) { report.failure(logger, "Application not registered", null); return null; } // if it's not on DAS and the application is not loaded, do not unload // when it's on DAS, there is some necessary clean up we need to do if (!env.isDas() && !appInfo.isLoaded()) { return null; } if (app != null) { commandParams._type = app.archiveType(); } final ExtendedDeploymentContext deploymentContext = getBuilder(logger, commandParams, report).source(appInfo.getSource()).build(); if (app != null) { deploymentContext.getAppProps().putAll( app.getDeployProperties()); deploymentContext.setModulePropsMap( app.getModulePropertiesMap()); } if (commandParams.properties != null) { deploymentContext.getAppProps().putAll(commandParams.properties); } unload(appInfo, deploymentContext); return deploymentContext; }
ActionReport subReport = report.addSubActionsReport(); ExtendedDeploymentContext deploymentContext = deployment.getBuilder(KernelLoggerInfo.getLogger(), parameters, subReport).source(appInfo.getSource()).build(); deploymentContext.getAppProps().putAll( app.getDeployProperties()); deploymentContext.getAppProps().putAll( tenant.getDeployProperties()); deploymentContext.setModulePropsMap( app.getModulePropertiesMap()); deploymentContext.setTenant(tenant.getTenant(), app.getName()); subReport.setActionExitCode(ActionReport.ExitCode.FAILURE); subReport.setMessage(e.getMessage()); subReport.setFailureCause(e); appRegistry.remove(appInfo.getName());