Search in sources :

Example 1 with DoNothingActionReporter

use of com.sun.enterprise.admin.report.DoNothingActionReporter in project Payara by payara.

the class UpgradeStartup method start.

// do nothing, just return, at the time the upgrade service has
// run correctly.
public void start() {
    // we need to disable all the applications before starting server
    // so the applications will not get loaded before redeployment
    // store the list of previous enabled applications
    // so we can reset these applications back to enabled after
    // redeployment
    List<Application> enabledApps = new ArrayList<Application>();
    List<String> enabledAppNames = new ArrayList<String>();
    for (Application app : domain.getApplications().getApplications()) {
        logger.log(Level.INFO, "app " + app.getName() + " is " + app.getEnabled() + " resulting in " + Boolean.parseBoolean(app.getEnabled()));
        if (Boolean.parseBoolean(app.getEnabled())) {
            logger.log(Level.INFO, "Disabling application " + app.getName());
            enabledApps.add(app);
            enabledAppNames.add(app.getName());
        }
    }
    if (enabledApps.size() > 0) {
        try {
            ConfigSupport.apply(new ConfigCode() {

                public Object run(ConfigBeanProxy... configBeanProxies) throws PropertyVetoException, TransactionFailure {
                    for (ConfigBeanProxy proxy : configBeanProxies) {
                        Application app = (Application) proxy;
                        app.setEnabled(Boolean.FALSE.toString());
                    }
                    return null;
                }
            }, enabledApps.toArray(new Application[enabledApps.size()]));
        } catch (TransactionFailure tf) {
            logger.log(Level.SEVERE, "Exception while disabling applications", tf);
            return;
        }
    }
    // start the application server
    appservStartup.start();
    initializeSigTypeList();
    // redeploy all existing applications
    for (Application app : applications.getApplications()) {
        // we don't need to redeploy lifecycle modules
        if (Boolean.valueOf(app.getDeployProperties().getProperty(ServerTags.IS_LIFECYCLE))) {
            continue;
        }
        logger.log(Level.INFO, "Redeploy application " + app.getName() + " located at " + app.getLocation());
        // we let upgrade proceed even if one application
        // failed to redeploy
        redeployApp(app);
    }
    // after redeployment
    if (enabledAppNames.size() > 0) {
        for (Application app : domain.getApplications().getApplications()) {
            if (enabledAppNames.contains(app.getName())) {
                logger.log(Level.INFO, "Enabling application " + app.getName());
                try {
                    ConfigSupport.apply(new SingleConfigCode<Application>() {

                        public Object run(Application param) throws PropertyVetoException, TransactionFailure {
                            if (!Boolean.parseBoolean(param.getEnabled())) {
                                param.setEnabled(Boolean.TRUE.toString());
                            }
                            return null;
                        }
                    }, app);
                } catch (TransactionFailure tf) {
                    logger.log(Level.SEVERE, "Exception while disabling applications", tf);
                    return;
                }
            }
        }
    }
    // clean up leftover directories
    cleanupLeftOverDirectories();
    // stop-the server.
    KernelLoggerInfo.getLogger().info(KernelLoggerInfo.exitUpgrade);
    try {
        Thread.sleep(3000);
        if (runner != null) {
            runner.getCommandInvocation("stop-domain", new DoNothingActionReporter(), kernelIdentity.getSubject()).execute();
        }
    } catch (InterruptedException e) {
        KernelLoggerInfo.getLogger().log(Level.SEVERE, KernelLoggerInfo.exceptionUpgrade, e);
    }
}
Also used : DoNothingActionReporter(com.sun.enterprise.admin.report.DoNothingActionReporter) PropertyVetoException(java.beans.PropertyVetoException) Application(com.sun.enterprise.config.serverbeans.Application)

Example 2 with DoNothingActionReporter

use of com.sun.enterprise.admin.report.DoNothingActionReporter in project Payara by payara.

the class PayaraServerNameGenerator method getAllNamesInUse.

private static List<String> getAllNamesInUse(AdminCommandContext context) {
    List<String> namesInUse = new ArrayList<>();
    CommandRunner commandRunner = Globals.getDefaultBaseServiceLocator().getService(CommandRunner.class);
    namesInUse.addAll(getInstanceNames(new DoNothingActionReporter(), context, commandRunner));
    namesInUse.addAll(getNodeNames(new DoNothingActionReporter(), context, commandRunner));
    namesInUse.addAll(getClusterNames(new DoNothingActionReporter(), context, commandRunner));
    namesInUse.addAll(getDeploymentGroupNames(new DoNothingActionReporter(), context, commandRunner));
    namesInUse.addAll(getConfigNames(new DoNothingActionReporter(), context, commandRunner));
    return namesInUse;
}
Also used : ArrayList(java.util.ArrayList) CommandRunner(org.glassfish.api.admin.CommandRunner) DoNothingActionReporter(com.sun.enterprise.admin.report.DoNothingActionReporter)

Example 3 with DoNothingActionReporter

use of com.sun.enterprise.admin.report.DoNothingActionReporter in project Payara by payara.

the class UpgradeStartup method redeployApp.

private boolean redeployApp(Application app) {
    // we don't need to redeploy any v3 type application
    if (app.getModule().size() > 0) {
        logger.log(Level.INFO, "Skip redeploying v3 type application " + app.getName());
        return true;
    }
    // populate the params and properties from application element first
    DeployCommandParameters deployParams = app.getDeployParameters(null);
    // we should not have to repackage for any upgrade from v3
    if (!Boolean.valueOf(app.getDirectoryDeployed())) {
        File repackagedFile = null;
        try {
            repackagedFile = repackageArchive(app);
        } catch (IOException ioe) {
            logger.log(Level.SEVERE, "Repackaging of application " + app.getName() + " failed: " + ioe.getMessage(), ioe);
            return false;
        }
        if (repackagedFile == null) {
            logger.log(Level.SEVERE, "Repackaging of application " + app.getName() + " failed.");
            return false;
        }
        logger.log(Level.INFO, "Repackaged application " + app.getName() + " at " + repackagedFile.getPath());
        deployParams.path = repackagedFile;
    }
    deployParams.properties = app.getDeployProperties();
    // remove the marker properties so they don't get carried over
    // through redeployment
    deployParams.properties.remove(MODULE_TYPE);
    // add the compatibility property so the applications are
    // upgraded/redeployed in a backward compatible way
    deployParams.properties.setProperty(DeploymentProperties.COMPATIBILITY, "v2");
    // now override the ones needed for the upgrade
    deployParams.enabled = null;
    deployParams.force = true;
    deployParams.dropandcreatetables = false;
    deployParams.createtables = false;
    deployParams.target = DOMAIN_TARGET;
    ActionReport report = new DoNothingActionReporter();
    commandRunner.getCommandInvocation("deploy", report, kernelIdentity.getSubject()).parameters(deployParams).execute();
    if (report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
        logger.log(Level.SEVERE, "Redeployment of application " + app.getName() + " failed: " + report.getMessage() + "\nPlease redeploy " + app.getName() + " manually.", report.getFailureCause());
        return false;
    }
    return true;
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) ActionReport(org.glassfish.api.ActionReport) DoNothingActionReporter(com.sun.enterprise.admin.report.DoNothingActionReporter)

Aggregations

DoNothingActionReporter (com.sun.enterprise.admin.report.DoNothingActionReporter)3 Application (com.sun.enterprise.config.serverbeans.Application)1 PropertyVetoException (java.beans.PropertyVetoException)1 ArrayList (java.util.ArrayList)1 ActionReport (org.glassfish.api.ActionReport)1 CommandRunner (org.glassfish.api.admin.CommandRunner)1 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)1