Search in sources :

Example 11 with UndeployCommandParameters

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);
    }
}
Also used : GlassFishException(org.glassfish.embeddable.GlassFishException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) UndeployCommandParameters(org.glassfish.api.deployment.UndeployCommandParameters) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) Deployment(org.glassfish.internal.deployment.Deployment) IOException(java.io.IOException) ActionReport(org.glassfish.api.ActionReport) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext)

Example 12 with UndeployCommandParameters

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();
    }
}
Also used : UndeployCommandParameters(org.glassfish.api.deployment.UndeployCommandParameters)

Example 13 with UndeployCommandParameters

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());
        }
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef) URI(java.net.URI) VersioningException(org.glassfish.deployment.versioning.VersioningException) UndeployCommandParameters(org.glassfish.api.deployment.UndeployCommandParameters) Iterator(java.util.Iterator) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) Application(com.sun.enterprise.config.serverbeans.Application) File(java.io.File)

Example 14 with UndeployCommandParameters

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);
}
Also used : UndeployCommandParameters(org.glassfish.api.deployment.UndeployCommandParameters) Deployment(org.glassfish.internal.deployment.Deployment) ActionReport(org.glassfish.api.ActionReport) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 15 with UndeployCommandParameters

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();
    }
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) UndeployCommandParameters(org.glassfish.api.deployment.UndeployCommandParameters) Events(org.glassfish.api.event.Events) Deployment(org.glassfish.internal.deployment.Deployment) EventTypes(org.glassfish.api.event.EventTypes) EventListener(org.glassfish.api.event.EventListener) ActionReport(org.glassfish.api.ActionReport) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Aggregations

UndeployCommandParameters (org.glassfish.api.deployment.UndeployCommandParameters)19 ActionReport (org.glassfish.api.ActionReport)10 IOException (java.io.IOException)7 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)7 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)7 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)6 File (java.io.File)4 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)4 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)3 Application (com.sun.enterprise.deployment.Application)3 Deployment (org.glassfish.internal.deployment.Deployment)3 Application (com.sun.enterprise.config.serverbeans.Application)2 HTMLActionReporter (com.sun.enterprise.v3.common.HTMLActionReporter)2 URI (java.net.URI)2 Logger (java.util.logging.Logger)2 DeploymentContext (org.glassfish.api.deployment.DeploymentContext)2 DeploymentProperties (org.glassfish.deployment.common.DeploymentProperties)2 GlassFishException (org.glassfish.embeddable.GlassFishException)2 ConfigApiTest (org.glassfish.tests.utils.ConfigApiTest)2 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)2