Search in sources :

Example 31 with ExtendedDeploymentContext

use of org.glassfish.internal.deployment.ExtendedDeploymentContext in project Payara by payara.

the class InstanceDeployCommand method execute.

@Override
public void execute(AdminCommandContext ctxt) {
    long operationStartTime = Calendar.getInstance().getTimeInMillis();
    final ActionReport report = ctxt.getActionReport();
    final Logger logger = ctxt.getLogger();
    ReadableArchive archive = null;
    this.origin = Origin.deploy_instance;
    this.command = Command._deploy;
    this.previousContextRoot = preservedcontextroot;
    if (previousVirtualServers != null) {
        String vs = previousVirtualServers.getProperty(target);
        if (vs != null) {
            this.virtualservers = vs;
        }
    }
    if (previousEnabledAttributes != null) {
        String enabledAttr = previousEnabledAttributes.getProperty(target);
        if (enabledAttr != null) {
            String enabledAttrForApp = previousEnabledAttributes.getProperty(DeploymentUtils.DOMAIN_TARGET_NAME);
            this.enabled = Boolean.valueOf(enabledAttr) && Boolean.valueOf(enabledAttrForApp);
        }
    }
    try {
        if (!path.exists()) {
            report.setMessage(localStrings.getLocalString("fnf", "File not found", path.getAbsolutePath()));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        if (snifferManager.hasNoSniffers()) {
            String msg = localStrings.getLocalString("nocontainer", "No container services registered, done...");
            report.failure(logger, msg);
            return;
        }
        archive = archiveFactory.openArchive(path, this);
        ArchiveHandler archiveHandler = deployment.getArchiveHandler(archive, type);
        if (archiveHandler == null) {
            report.failure(logger, localStrings.getLocalString("deploy.unknownarchivetype", "Archive type of {0} was not recognized", path.getName()));
            return;
        }
        // wait until all applications are loaded as we may have dependency on these, or the previous app is still
        // starting
        startupProvider.get();
        // clean up any left over repository files
        if (!keepreposdir.booleanValue()) {
            FileUtils.whack(new File(env.getApplicationRepositoryPath(), VersioningUtils.getRepositoryName(name)));
        }
        ExtendedDeploymentContext deploymentContext = deployment.getBuilder(logger, this, report).source(archive).build();
        // clean up any remaining generated files
        deploymentContext.clean();
        deploymentContext.getAppProps().putAll(appprops);
        processGeneratedContent(generatedcontent, deploymentContext, logger);
        Transaction t = null;
        Application application = applications.getApplication(name);
        if (application != null) {
            // application element already been synchronized over
            t = new Transaction();
        } else {
            t = deployment.prepareAppConfigChanges(deploymentContext);
        }
        ApplicationInfo appInfo;
        appInfo = deployment.deploy(deploymentContext);
        if (report.getActionExitCode() == ActionReport.ExitCode.SUCCESS) {
            try {
                moveAltDDFilesToPermanentLocation(deploymentContext, logger);
                // register application information in domain.xml
                if (application != null) {
                    // application element already synchronized over
                    // just write application-ref
                    deployment.registerAppInDomainXML(appInfo, deploymentContext, t, true);
                } else {
                    // write both application and application-ref
                    deployment.registerAppInDomainXML(appInfo, deploymentContext, t);
                }
            } catch (Exception e) {
                // roll back the deployment and re-throw the exception
                deployment.undeploy(name, deploymentContext);
                deploymentContext.clean();
                throw e;
            }
        }
    } 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) {
            logger.log(Level.INFO, localStrings.getLocalString("errClosingArtifact", "Error while closing deployable artifact : ", path.getAbsolutePath()), e);
        }
        if (report.getActionExitCode().equals(ActionReport.ExitCode.SUCCESS)) {
            logger.info(localStrings.getLocalString("deploy.done", "Deployment of {0} done is {1} ms", name, (Calendar.getInstance().getTimeInMillis() - operationStartTime)));
        } else if (report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
            String errorMessage = report.getMessage();
            Throwable cause = report.getFailureCause();
            if (cause != null) {
                String causeMessage = cause.getMessage();
                if (causeMessage != null && !causeMessage.equals(errorMessage)) {
                    errorMessage = errorMessage + " : " + cause.getMessage();
                }
                logger.log(Level.SEVERE, errorMessage, cause.getCause());
            }
            report.setMessage(localStrings.getLocalString("failToLoadOnInstance", "Failed to load the application on instance {0} : {1}", server.getName(), errorMessage));
            // reset the failure cause so command framework will not try
            // to print the same message again
            report.setFailureCause(null);
        }
    }
}
Also used : ArchiveHandler(org.glassfish.api.deployment.archive.ArchiveHandler) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) IOException(java.io.IOException) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) IOException(java.io.IOException) Transaction(org.jvnet.hk2.config.Transaction) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) ZipFile(java.util.zip.ZipFile) File(java.io.File) Application(com.sun.enterprise.config.serverbeans.Application)

Example 32 with ExtendedDeploymentContext

use of org.glassfish.internal.deployment.ExtendedDeploymentContext in project Payara by payara.

the class InstanceLifecycleModuleCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    final Logger logger = context.getLogger();
    try {
        Application application = applications.getApplication(name);
        Transaction t = new Transaction();
        // create a dummy context to hold params and props
        DeployCommandParameters commandParams = new DeployCommandParameters();
        commandParams.name = name;
        commandParams.target = target;
        commandParams.enabled = enabled;
        commandParams.virtualservers = virtualservers;
        ExtendedDeploymentContext lifecycleContext = new DeploymentContextImpl(report, null, commandParams, null);
        lifecycleContext.getAppProps().putAll(appprops);
        if (application != null) {
            // application element already been synchronized over
            // just write application-ref
            deployment.registerAppInDomainXML(null, lifecycleContext, t, true);
        } else {
            // write both
            t = deployment.prepareAppConfigChanges(lifecycleContext);
            deployment.registerAppInDomainXML(null, lifecycleContext, t);
        }
    } catch (Exception e) {
        report.failure(logger, e.getMessage());
    }
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) Transaction(org.jvnet.hk2.config.Transaction) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) Application(com.sun.enterprise.config.serverbeans.Application) DeploymentContextImpl(org.glassfish.deployment.common.DeploymentContextImpl)

Example 33 with ExtendedDeploymentContext

use of org.glassfish.internal.deployment.ExtendedDeploymentContext 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 34 with ExtendedDeploymentContext

use of org.glassfish.internal.deployment.ExtendedDeploymentContext 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)

Example 35 with ExtendedDeploymentContext

use of org.glassfish.internal.deployment.ExtendedDeploymentContext 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)

Aggregations

ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)39 ActionReport (org.glassfish.api.ActionReport)23 IOException (java.io.IOException)17 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)17 File (java.io.File)16 Logger (java.util.logging.Logger)11 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)11 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)10 Properties (java.util.Properties)9 URI (java.net.URI)7 Deployment (org.glassfish.internal.deployment.Deployment)7 DeploymentContext (org.glassfish.api.deployment.DeploymentContext)6 UndeployCommandParameters (org.glassfish.api.deployment.UndeployCommandParameters)6 ArchiveHandler (org.glassfish.api.deployment.archive.ArchiveHandler)6 DeploymentContextImpl (org.glassfish.deployment.common.DeploymentContextImpl)6 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)6 Application (com.sun.enterprise.deployment.Application)5 ArrayList (java.util.ArrayList)5 DeploymentProperties (org.glassfish.deployment.common.DeploymentProperties)5 VersioningException (org.glassfish.deployment.versioning.VersioningException)5