use of org.glassfish.api.deployment.UndeployCommandParameters in project Payara by payara.
the class VirtualServer method removeContext.
/**
* Stops the given <tt>context</tt> and removes it from this
* <tt>VirtualServer</tt>.
* @throws org.glassfish.embeddable.GlassFishException
*/
@Override
public void removeContext(Context context) throws GlassFishException {
ActionReport report = services.getService(ActionReport.class, "plain");
Deployment deployment = services.getService(Deployment.class);
String name;
if (context instanceof ContextFacade) {
name = ((ContextFacade) context).getAppName();
} else {
name = context.getPath();
}
ApplicationInfo appInfo = deployment.get(name);
if (appInfo == null) {
report.setMessage("Cannot find deployed application of name " + name);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
throw new GlassFishException("Cannot find deployed application of name " + name);
}
ReadableArchive source = appInfo.getSource();
if (source == null) {
report.setMessage("Cannot get source archive for undeployment");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
throw new GlassFishException("Cannot get source archive for undeployment");
}
UndeployCommandParameters params = new UndeployCommandParameters(name);
params.origin = UndeployCommandParameters.Origin.undeploy;
params.target = "server";
ExtendedDeploymentContext deploymentContext = null;
try {
deploymentContext = deployment.getBuilder(_logger, params, report).source(source).build();
deployment.undeploy(name, deploymentContext);
deployment.unregisterAppFromDomainXML(name, "server");
} catch (IOException e) {
_logger.log(Level.SEVERE, LogFacade.REMOVE_CONTEXT_ERROR, e);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
throw new GlassFishException("Cannot create context for undeployment ", e);
} catch (TransactionFailure e) {
throw new GlassFishException(e);
} finally {
if (deploymentContext != null) {
deploymentContext.clean();
}
}
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, LogFacade.REMOVED_CONTEXT, name);
}
}
use of org.glassfish.api.deployment.UndeployCommandParameters in project Payara by payara.
the class AppClientDeployer method clean.
/**
* Clean any files and artifacts that were created during the execution
* of the prepare method.
*
* @param dc deployment context
*/
@Override
public void clean(DeploymentContext dc) {
super.clean(dc);
UndeployCommandParameters params = dc.getCommandParameters(UndeployCommandParameters.class);
if (params != null) {
final com.sun.enterprise.config.serverbeans.Application app = applications.getApplication(params.name);
DeploymentUtils.downloadableArtifacts(app).clearArtifacts();
}
}
use of org.glassfish.api.deployment.UndeployCommandParameters in project Payara by payara.
the class DeleteApplicationRefCommand method execute.
/**
* Entry point from the framework into the command execution
* @param context context for the command.
*/
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
final Logger logger = context.getLogger();
UndeployCommandParameters commandParams = new UndeployCommandParameters();
if (server.isDas()) {
commandParams.origin = Origin.unload;
} else {
// delete application ref on instance
// is essentially an undeploy
commandParams.origin = Origin.undeploy;
}
commandParams.command = Command.delete_application_ref;
// for each matched version
Iterator it = matchedVersions.iterator();
while (it.hasNext()) {
String appName = (String) it.next();
Application application = applications.getApplication(appName);
if (application == null) {
if (env.isDas()) {
// let's only do this check for DAS to be more
// tolerable of the partial deployment case
report.setMessage(localStrings.getLocalString("application.notreg", "Application {0} not registered", appName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
return;
}
ApplicationRef applicationRef = domain.getApplicationRefInTarget(appName, target);
if (applicationRef == null) {
if (env.isDas()) {
// let's only do this check for DAS to be more
// tolerable of the partial deployment case
report.setMessage(localStrings.getLocalString("appref.not.exists", "Target {1} does not have a reference to application {0}.", appName, target));
report.setActionExitCode(ActionReport.ExitCode.WARNING);
}
return;
}
if (application.isLifecycleModule()) {
try {
deployment.unregisterAppFromDomainXML(appName, target, true);
} catch (Exception e) {
report.failure(logger, e.getMessage());
}
return;
}
try {
ReadableArchive source = null;
ApplicationInfo appInfo = deployment.get(appName);
if (appInfo != null) {
source = appInfo.getSource();
} else {
File location = new File(new URI(application.getLocation()));
source = archiveFactory.openArchive(location);
}
commandParams.name = appName;
commandParams.cascade = cascade;
final ExtendedDeploymentContext deploymentContext = deployment.getBuilder(logger, commandParams, report).source(source).build();
deploymentContext.getAppProps().putAll(application.getDeployProperties());
deploymentContext.setModulePropsMap(application.getModulePropertiesMap());
if (domain.isCurrentInstanceMatchingTarget(target, appName, server.getName(), null) && appInfo != null) {
// stop and unload application if it's the target and the
// the application is in enabled state
deployment.unload(appInfo, deploymentContext);
}
if (report.getActionExitCode().equals(ActionReport.ExitCode.SUCCESS)) {
try {
if (server.isInstance()) {
// if it's on instance, we should clean up
// the bits
deployment.undeploy(appName, deploymentContext);
deploymentContext.clean();
if (!Boolean.valueOf(application.getDirectoryDeployed()) && source.exists()) {
FileUtils.whack(new File(source.getURI()));
}
deployment.unregisterAppFromDomainXML(appName, target);
} else {
deployment.unregisterAppFromDomainXML(appName, target, true);
}
} catch (TransactionFailure e) {
logger.warning("failed to delete application ref for " + appName);
}
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Error during deleteing application ref ", e);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(e.getMessage());
}
}
}
use of org.glassfish.api.deployment.UndeployCommandParameters in project Payara by payara.
the class EventsTest method badUndeployTest.
@Test
public void badUndeployTest() throws Exception {
Deployment deployment = habitat.getService(Deployment.class);
UndeployCommandParameters params = new UndeployCommandParameters("notavalidname");
params.target = "server";
ActionReport report = habitat.getService(ActionReport.class, "hk2-agent");
ExtendedDeploymentContext dc = deployment.getBuilder(Logger.getAnonymousLogger(), params, report).source(application).build();
deployment.undeploy("notavalidname", dc);
Assert.assertEquals(report.getActionExitCode(), ActionReport.ExitCode.FAILURE);
}
use of org.glassfish.api.deployment.UndeployCommandParameters in project Payara by payara.
the class EventsTest method deployUndeployTest.
@Test
public void deployUndeployTest() throws Exception {
final List<EventTypes> myTestEvents = getSingletonModuleSuccessfullDeploymentEvents();
Events events = habitat.getService(Events.class);
EventListener listener = new EventListener() {
public void event(Event event) {
if (myTestEvents.contains(event.type())) {
myTestEvents.remove(event.type());
}
}
};
events.register(listener);
Deployment deployment = habitat.getService(Deployment.class);
DeployCommandParameters params = new DeployCommandParameters(application);
params.name = "fakeApplication";
params.target = "server";
ActionReport report = habitat.getService(ActionReport.class, "hk2-agent");
ExtendedDeploymentContext dc = deployment.getBuilder(Logger.getAnonymousLogger(), params, report).source(application).build();
deployment.deploy(dc);
events.unregister(listener);
for (EventTypes et : myTestEvents) {
System.out.println("An expected event of type " + et.type() + " was not received");
}
try {
final List<EventTypes> myTestEvents2 = getSingletonModuleSuccessfullUndeploymentEvents();
EventListener listener2 = new EventListener() {
public void event(Event event) {
if (myTestEvents2.contains(event.type())) {
myTestEvents2.remove(event.type());
}
}
};
events.register(listener2);
UndeployCommandParameters params2 = new UndeployCommandParameters("fakeApplication");
params2.target = "server";
ActionReport report2 = habitat.getService(ActionReport.class, "hk2-agent");
ExtendedDeploymentContext dc2 = deployment.getBuilder(Logger.getAnonymousLogger(), params2, report2).source(application).build();
deployment.undeploy("fakeApplication", dc2);
events.unregister(listener2);
for (EventTypes et : myTestEvents2) {
System.out.println("An expected event of type " + et.type() + " was not received");
}
} catch (Throwable t) {
t.printStackTrace();
}
}
Aggregations