Search in sources :

Example 16 with UndeployCommandParameters

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
        }
    }
}
Also used : UndeployCommandParameters(org.glassfish.api.deployment.UndeployCommandParameters) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) IOException(java.io.IOException) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) URI(java.net.URI) File(java.io.File)

Example 17 with UndeployCommandParameters

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());
    }
}
Also used : UndeployCommandParameters(org.glassfish.api.deployment.UndeployCommandParameters) HTMLActionReporter(com.sun.enterprise.v3.common.HTMLActionReporter) ActionReport(org.glassfish.api.ActionReport) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 18 with UndeployCommandParameters

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();
    }
}
Also used : UndeployCommandParameters(org.glassfish.api.deployment.UndeployCommandParameters) IOException(java.io.IOException) ActionReport(org.glassfish.api.ActionReport) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) File(java.io.File)

Example 19 with UndeployCommandParameters

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

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