Search in sources :

Example 6 with UndeployCommandParameters

use of org.glassfish.api.deployment.UndeployCommandParameters in project Payara by payara.

the class EjbApplication method resolveKeepStateOptions.

/**
 * Returns a consolidated keepstate value.  keepstate only takes effect for
 * redeploy operations where the app is already registered.  If the app is
 * not already registered, keepstate always resolves to false even if
 * keepstate is true in CLI or descriptors.  For redeploy operations, CLI
 * --keepstate option has precedence over descriptor keep-state element.
 * @param deployContext
 * @param isDeploy
 * @param bundleDesc
 * @return true if keepstate is true after consolidating --keepstate CLI option
 * and keep-state element in descriptors; false otherwise.
 */
private boolean resolveKeepStateOptions(DeploymentContext deployContext, boolean isDeploy, EjbBundleDescriptorImpl bundleDesc) {
    Boolean isredeploy = Boolean.FALSE;
    Boolean keepState = null;
    if (isDeploy) {
        DeployCommandParameters dcp = deployContext.getCommandParameters(DeployCommandParameters.class);
        if (dcp != null) {
            isredeploy = dcp.isredeploy;
            keepState = dcp.keepstate;
        }
    } else {
        UndeployCommandParameters ucp = deployContext.getCommandParameters(UndeployCommandParameters.class);
        if (ucp != null) {
            isredeploy = ucp.isredeploy;
            keepState = ucp.keepstate;
        }
    }
    if (!isredeploy) {
        return false;
    }
    if (keepState == null) {
        Application app = bundleDesc.getApplication();
        keepState = app.getKeepState();
    }
    return keepState;
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) UndeployCommandParameters(org.glassfish.api.deployment.UndeployCommandParameters) Application(com.sun.enterprise.deployment.Application)

Example 7 with UndeployCommandParameters

use of org.glassfish.api.deployment.UndeployCommandParameters in project Payara by payara.

the class ApplicationConfigListener method disableApplication.

private void disableApplication(String appName) {
    Application app = applications.getApplication(appName);
    ApplicationRef appRef = domain.getApplicationRefInServer(server.getName(), appName);
    // by the current server instance, do not unload
    if (app == null || appRef == null) {
        return;
    }
    ApplicationInfo appInfo = appRegistry.get(appName);
    if (appInfo == null || !appInfo.isLoaded()) {
        return;
    }
    try {
        ActionReport report = new HTMLActionReporter();
        UndeployCommandParameters commandParams = new UndeployCommandParameters();
        commandParams.name = appName;
        commandParams.target = server.getName();
        commandParams.origin = UndeployCommandParameters.Origin.unload;
        commandParams.command = UndeployCommandParameters.Command.disable;
        deployment.disable(commandParams, app, appInfo, report, logger);
        if (report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
            throw new Exception(report.getMessage());
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE, KernelLoggerInfo.loadingApplicationErrorDisable, e);
        throw new RuntimeException(e);
    }
}
Also used : UndeployCommandParameters(org.glassfish.api.deployment.UndeployCommandParameters) HTMLActionReporter(com.sun.enterprise.v3.common.HTMLActionReporter) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) ActionReport(org.glassfish.api.ActionReport) Application(com.sun.enterprise.config.serverbeans.Application) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef)

Example 8 with UndeployCommandParameters

use of org.glassfish.api.deployment.UndeployCommandParameters in project Payara by payara.

the class ApplicationLoaderService method unloadApplicationForTenants.

private void unloadApplicationForTenants(Application app, ActionReport report) {
    if (app == null || app.getAppTenants() == null) {
        return;
    }
    for (AppTenant tenant : app.getAppTenants().getAppTenant()) {
        UndeployCommandParameters parameters = new UndeployCommandParameters();
        parameters.name = DeploymentUtils.getInternalNameForTenant(app.getName(), tenant.getTenant());
        parameters.origin = UndeployCommandParameters.Origin.unload;
        parameters.target = server.getName();
        ApplicationInfo appInfo = deployment.get(parameters.name);
        if (appInfo == null) {
            continue;
        }
        ActionReport subReport = report.addSubActionsReport();
        try {
            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());
            deployment.unload(appInfo, deploymentContext);
        } catch (Throwable e) {
            subReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
            subReport.setMessage(e.getMessage());
            subReport.setFailureCause(e);
        }
        appRegistry.remove(appInfo.getName());
    }
}
Also used : UndeployCommandParameters(org.glassfish.api.deployment.UndeployCommandParameters) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) ActionReport(org.glassfish.api.ActionReport)

Example 9 with UndeployCommandParameters

use of org.glassfish.api.deployment.UndeployCommandParameters in project Payara by payara.

the class ResourcesDeployer method preserveResources.

/**
 * preserve the old application's resources so that they can be registered during deploy.
 * @param dc DeploymentContext
 * @param undeployCommandParameters undeploy command parameters
 */
private void preserveResources(DeploymentContext dc, UndeployCommandParameters undeployCommandParameters) {
    try {
        if (undeployCommandParameters.origin == OpsParams.Origin.undeploy) {
            Properties properties = undeployCommandParameters.properties;
            if (properties != null) {
                String preserve = properties.getProperty(DeploymentProperties.PRESERVE_APP_SCOPED_RESOURCES);
                if (preserve != null && Boolean.valueOf(preserve)) {
                    debug("Preserve app scoped resources enabled");
                    final UndeployCommandParameters commandParams = dc.getCommandParameters(UndeployCommandParameters.class);
                    String appName = commandParams.name();
                    Application app = applications.getApplication(appName);
                    preserveResources(app);
                    // store application info (for module information ie., sniffer type)
                    preservedApps.put(appName, app);
                }
            }
        }
    } catch (Exception e) {
        // in the event notification infrastructure
        throw new DeploymentException(e.getMessage(), e);
    }
}
Also used : UndeployCommandParameters(org.glassfish.api.deployment.UndeployCommandParameters) DeploymentException(org.glassfish.deployment.common.DeploymentException) DeploymentProperties(org.glassfish.deployment.common.DeploymentProperties) ResourceException(javax.resource.ResourceException) IOException(java.io.IOException) DeploymentException(org.glassfish.deployment.common.DeploymentException) ResourceConflictException(org.glassfish.resourcebase.resources.api.ResourceConflictException)

Example 10 with UndeployCommandParameters

use of org.glassfish.api.deployment.UndeployCommandParameters in project Payara by payara.

the class ResourcesDeployer method cleanupPreservedResources.

private void cleanupPreservedResources(DeploymentContext dc, Event event) {
    if (Deployment.DEPLOYMENT_FAILURE.equals(event.type())) {
        final DeployCommandParameters deployCommandParameters = dc.getCommandParameters(DeployCommandParameters.class);
        if (deployCommandParameters.origin == OpsParams.Origin.deploy || deployCommandParameters.origin == OpsParams.Origin.deploy_instance || deployCommandParameters.origin == OpsParams.Origin.create_application_ref) {
            Properties properties = deployCommandParameters.properties;
            String appName = deployCommandParameters.name();
            cleanupPreservedResources(appName, properties);
        }
    } else if (Deployment.UNDEPLOYMENT_FAILURE.equals(event.type())) {
        final UndeployCommandParameters undeployCommandParameters = dc.getCommandParameters(UndeployCommandParameters.class);
        if (undeployCommandParameters.origin == OpsParams.Origin.undeploy) {
            Properties properties = undeployCommandParameters.properties;
            String appName = undeployCommandParameters.name();
            cleanupPreservedResources(appName, properties);
        }
    }
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) UndeployCommandParameters(org.glassfish.api.deployment.UndeployCommandParameters) DeploymentProperties(org.glassfish.deployment.common.DeploymentProperties)

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