use of org.glassfish.api.deployment.UndeployCommandParameters in project Payara by payara.
the class MTUnprovisionCommand method execute.
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
final Logger logger = context.getLogger();
if (app == null) {
report.setMessage("Application " + appname + " is not deployed");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (appTenant == null) {
report.setMessage("Application " + appname + " is not provisioned to tenant " + tenant);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
String internalAppName = DeploymentUtils.getInternalNameForTenant(appname, tenant);
ApplicationInfo appInfo = deployment.get(internalAppName);
ReadableArchive archive = null;
try {
if (appInfo != null) {
archive = appInfo.getSource();
} else {
URI uri = new URI(app.getLocation());
File location = new File(uri);
if (location.exists()) {
archive = archiveFactory.openArchive(location);
} else {
logger.log(Level.WARNING, localStrings.getLocalString("fnf", "File not found", location.getAbsolutePath()));
deployment.unregisterTenantWithAppInDomainXML(appname, tenant);
return;
}
}
UndeployCommandParameters commandParams = new UndeployCommandParameters();
commandParams.target = DeploymentUtils.DAS_TARGET_NAME;
commandParams.name = internalAppName;
commandParams.origin = DeployCommandParameters.Origin.mt_unprovision;
ExtendedDeploymentContext deploymentContext = deployment.getBuilder(logger, commandParams, report).source(archive).build();
deploymentContext.getAppProps().putAll(app.getDeployProperties());
deploymentContext.getAppProps().putAll(appTenant.getDeployProperties());
deploymentContext.setModulePropsMap(app.getModulePropertiesMap());
deploymentContext.setTenant(tenant, app.getName());
deployment.undeploy(internalAppName, deploymentContext);
deployment.unregisterTenantWithAppInDomainXML(appname, tenant);
// remove context from generated and tenant dir
deploymentContext.clean();
} catch (Throwable e) {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(e.getMessage());
report.setFailureCause(e);
} finally {
try {
if (archive != null) {
archive.close();
}
} catch (IOException e) {
// ignore
}
}
}
use of org.glassfish.api.deployment.UndeployCommandParameters in project Payara by payara.
the class ApplicationLoaderService method stopApplication.
private void stopApplication(Application app, ApplicationInfo appInfo) {
final ActionReport dummy = new HTMLActionReporter();
if (appInfo != null) {
UndeployCommandParameters parameters = new UndeployCommandParameters(appInfo.getName());
parameters.origin = UndeployCommandParameters.Origin.unload;
parameters.command = UndeployCommandParameters.Command.shutdown_server;
try {
deployment.disable(parameters, app, appInfo, dummy, logger);
} catch (Exception e) {
logger.log(Level.SEVERE, KernelLoggerInfo.loadingApplicationErrorDisable, e);
}
unloadApplicationForTenants(app, dummy);
appRegistry.remove(appInfo.getName());
}
}
use of org.glassfish.api.deployment.UndeployCommandParameters in project Payara by payara.
the class EmbeddedDeployerImpl method undeploy.
@Override
public void undeploy(String name, UndeployCommandParameters params) {
ActionReport report = habitat.getService(ActionReport.class, "plain");
EmbeddedDeployedInfo info = deployedApps.get(name);
ApplicationInfo appInfo = info != null ? info.appInfo : null;
if (appInfo == null) {
appInfo = deployment.get(name);
}
if (appInfo == null) {
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);
return;
}
if (params == null) {
params = new UndeployCommandParameters(name);
}
params.origin = UndeployCommandParameters.Origin.undeploy;
ExtendedDeploymentContext deploymentContext;
try {
deploymentContext = deployment.getBuilder(logger, params, report).source(source).build();
if (info != null) {
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);
}
} catch (IOException e) {
logger.log(Level.SEVERE, "Cannot create context for undeployment ", e);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
deployment.undeploy(name, deploymentContext);
if (report.getActionExitCode().equals(ActionReport.ExitCode.SUCCESS)) {
if (params.keepreposdir == null) {
params.keepreposdir = false;
}
if (!params.keepreposdir && info != null && !info.isDirectory && source.exists()) {
FileUtils.whack(new File(source.getURI()));
}
// remove context from generated
deploymentContext.clean();
}
}
use of org.glassfish.api.deployment.UndeployCommandParameters in project Payara by payara.
the class WebServicesDeployer method clean.
@Override
public void clean(DeploymentContext dc) {
super.clean(dc);
WebServicesContainer container = habitat.getService(WebServicesContainer.class);
WebServicesDeploymentMBean bean = container.getDeploymentBean();
UndeployCommandParameters params = dc.getCommandParameters(UndeployCommandParameters.class);
if (params != null) {
bean.undeploy(params.name);
}
}
Aggregations