Search in sources :

Example 51 with DeployCommandParameters

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

the class PostDeployCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    final Logger logger = context.getLogger();
    final DeployCommandSupplementalInfo suppInfo = context.getActionReport().getResultType(DeployCommandSupplementalInfo.class);
    final DeploymentContext dc = suppInfo.deploymentContext();
    final DeployCommandParameters params = dc.getCommandParameters(DeployCommandParameters.class);
    final InterceptorNotifier notifier = new InterceptorNotifier(habitat, dc);
    // if the target is DAS, we do not need to do anything more
    if (DeploymentUtils.isDASTarget(params.target)) {
        return;
    }
    try {
        final ParameterMap paramMap = deployment.prepareInstanceDeployParamMap(dc);
        List<String> targets = new ArrayList<String>();
        if (!DeploymentUtils.isDomainTarget(params.target)) {
            targets.add(params.target);
        } else {
            targets = suppInfo.previousTargets();
        }
        ClusterOperationUtil.replicateCommand("_deploy", FailurePolicy.Warn, FailurePolicy.Warn, FailurePolicy.Ignore, targets, context, paramMap, habitat);
        notifier.ensureAfterReported(Phase.REPLICATION);
    } catch (Exception e) {
        report.failure(logger, e.getMessage());
    }
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) DeploymentContext(org.glassfish.api.deployment.DeploymentContext) ArrayList(java.util.ArrayList) ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger)

Example 52 with DeployCommandParameters

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

the class ApplicationLoaderService method processApplication.

public List<Deployment.ApplicationDeployment> processApplication(Application app, ApplicationRef appRef) {
    long operationStartTime = Calendar.getInstance().getTimeInMillis();
    initializeRuntimeDependencies();
    String source = app.getLocation();
    final String appName = app.getName();
    // lifecycle modules are loaded separately
    if (Boolean.valueOf(app.getDeployProperties().getProperty(ServerTags.IS_LIFECYCLE))) {
        return ImmutableList.of();
    }
    URI uri;
    try {
        uri = new URI(source);
    } catch (URISyntaxException e) {
        logger.log(Level.SEVERE, KernelLoggerInfo.cantDetermineLocation, e.getLocalizedMessage());
        return ImmutableList.of();
    }
    List<Deployment.ApplicationDeployment> appDeployments = new ArrayList<>();
    File sourceFile = new File(uri);
    if (sourceFile.exists()) {
        try {
            ReadableArchive archive = null;
            try {
                DeploymentTracing tracing = null;
                if (deploymentTracingEnabled != null) {
                    tracing = new DeploymentTracing();
                }
                DeployCommandParameters deploymentParams = app.getDeployParameters(appRef);
                deploymentParams.target = server.getName();
                deploymentParams.origin = DeployCommandParameters.Origin.load;
                deploymentParams.command = DeployCommandParameters.Command.startup_server;
                if (domain.isAppReferencedByPaaSTarget(appName)) {
                    if (server.isDas()) {
                        // for loading PaaS application on DAS
                        // we set it to the real PaaS target
                        deploymentParams.target = deployment.getDefaultTarget(appName, deploymentParams.origin, deploymentParams._classicstyle);
                    }
                }
                archive = archiveFactoryProvider.get().openArchive(sourceFile, deploymentParams);
                ActionReport report = new HTMLActionReporter();
                ExtendedDeploymentContext depContext = deployment.getBuilder(logger, deploymentParams, report).source(archive).build();
                if (tracing != null) {
                    depContext.addModuleMetaData(tracing);
                }
                depContext.getAppProps().putAll(app.getDeployProperties());
                depContext.setModulePropsMap(app.getModulePropertiesMap());
                new ApplicationConfigInfo(app).store(depContext.getAppProps());
                appDeployments.add(deployment.prepare(deployment.getSniffersFromApp(app), depContext));
                appDeployments.addAll(loadApplicationForTenants(app, appRef, report));
                if (report.getActionExitCode().equals(ActionReport.ExitCode.SUCCESS)) {
                    if (tracing != null) {
                        tracing.print(System.out);
                    }
                    logger.log(Level.INFO, KernelLoggerInfo.loadingApplicationTime, new Object[] { appName, (Calendar.getInstance().getTimeInMillis() - operationStartTime) });
                } else {
                    logger.log(Level.SEVERE, KernelLoggerInfo.deployFail, report.getMessage());
                }
            } finally {
                if (archive != null) {
                    try {
                        archive.close();
                    } catch (IOException e) {
                        logger.log(Level.FINE, KernelLoggerInfo.deployException, e);
                    }
                }
            }
        } catch (IOException e) {
            logger.log(Level.SEVERE, KernelLoggerInfo.exceptionOpenArtifact, e);
        }
    } else {
        logger.log(Level.SEVERE, KernelLoggerInfo.notFoundInOriginalLocation, source);
    }
    return FluentIterable.from(appDeployments).filter(Predicates.notNull()).toList();
}
Also used : URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ActionReport(org.glassfish.api.ActionReport) URI(java.net.URI) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) HTMLActionReporter(com.sun.enterprise.v3.common.HTMLActionReporter) ApplicationConfigInfo(org.glassfish.deployment.common.ApplicationConfigInfo) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) File(java.io.File)

Example 53 with DeployCommandParameters

use of org.glassfish.api.deployment.DeployCommandParameters 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.v3.common.DoNothingActionReporter)

Example 54 with DeployCommandParameters

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

the class EmbeddedDeployerImpl method deploy.

@Override
public String deploy(ReadableArchive archive, DeployCommandParameters params) {
    // ensure server is started. start it if not started.
    try {
        server.start();
    } catch (LifecycleException e) {
        throw new RuntimeException(e);
    }
    ActionReport report = new PlainTextActionReporter();
    if (params == null) {
        params = new DeployCommandParameters();
    }
    ExtendedDeploymentContext initialContext = new DeploymentContextImpl(report, archive, params, env);
    ArchiveHandler archiveHandler = null;
    try {
        archiveHandler = deployment.getArchiveHandler(archive);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    if (archiveHandler == null) {
        throw new RuntimeException("Cannot find archive handler for source archive");
    }
    if (params.name == null) {
        params.name = archiveHandler.getDefaultApplicationName(archive, initialContext);
    }
    ExtendedDeploymentContext context = null;
    try {
        context = deployment.getBuilder(logger, params, report).source(archive).archiveHandler(archiveHandler).build(initialContext);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    if (params.property != null) {
        context.getAppProps().putAll(params.property);
    }
    if (params.properties != null) {
        context.getAppProps().putAll(params.properties);
    }
    ApplicationInfo appInfo = null;
    try {
        appInfo = deployment.deploy(context);
    } catch (Exception e) {
        logger.log(Level.SEVERE, KernelLoggerInfo.deployException, e);
    }
    if (appInfo != null) {
        boolean isDirectory = new File(archive.getURI().getPath()).isDirectory();
        EmbeddedDeployedInfo info = new EmbeddedDeployedInfo(appInfo, context.getModulePropsMap(), context.getAppProps(), isDirectory);
        deployedApps.put(appInfo.getName(), info);
        return appInfo.getName();
    }
    return null;
}
Also used : IOException(java.io.IOException) ActionReport(org.glassfish.api.ActionReport) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) PropertyVetoException(java.beans.PropertyVetoException) IOException(java.io.IOException) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) PlainTextActionReporter(com.sun.enterprise.v3.common.PlainTextActionReporter) File(java.io.File)

Aggregations

DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)54 ActionReport (org.glassfish.api.ActionReport)18 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)18 File (java.io.File)17 IOException (java.io.IOException)16 Application (com.sun.enterprise.deployment.Application)11 DeploymentContext (org.glassfish.api.deployment.DeploymentContext)10 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)9 Properties (java.util.Properties)8 Logger (java.util.logging.Logger)7 DeploymentContextImpl (org.glassfish.deployment.common.DeploymentContextImpl)7 ArrayList (java.util.ArrayList)6 UndeployCommandParameters (org.glassfish.api.deployment.UndeployCommandParameters)6 DeploymentProperties (org.glassfish.deployment.common.DeploymentProperties)6 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)6 SAXParseException (org.xml.sax.SAXParseException)6 ArchiveHandler (org.glassfish.api.deployment.archive.ArchiveHandler)5 URI (java.net.URI)4 VersioningSyntaxException (org.glassfish.deployment.versioning.VersioningSyntaxException)4 Test (org.junit.Test)4