Search in sources :

Example 46 with DeployCommandParameters

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

the class DolProvider method processDOL.

private Application processDOL(DeploymentContext dc) throws IOException {
    ReadableArchive sourceArchive = dc.getSource();
    sourceArchive.setExtraData(Types.class, dc.getTransientAppMetaData(Types.class.getName(), Types.class));
    sourceArchive.setExtraData(Parser.class, dc.getTransientAppMetaData(Parser.class.getName(), Parser.class));
    ClassLoader cl = dc.getClassLoader();
    DeployCommandParameters params = dc.getCommandParameters(DeployCommandParameters.class);
    sourceArchive.addArchiveMetaData(DeploymentProperties.APP_PROPS, dc.getAppProps());
    sourceArchive.addArchiveMetaData(DeploymentProperties.COMMAND_PARAMS, params);
    String name = params.name();
    String archiveType = dc.getArchiveHandler().getArchiveType();
    Archivist archivist = archivistFactory.getArchivist(archiveType, cl);
    if (archivist == null) {
        // an empty Application object
        return Application.createApplication();
    }
    archivist.setAnnotationProcessingRequested(true);
    String xmlValidationLevel = dasConfig.getDeployXmlValidation();
    archivist.setXMLValidationLevel(xmlValidationLevel);
    if (xmlValidationLevel.equals("none")) {
        archivist.setXMLValidation(false);
    }
    archivist.setRuntimeXMLValidationLevel(xmlValidationLevel);
    if (xmlValidationLevel.equals("none")) {
        archivist.setRuntimeXMLValidation(false);
    }
    Collection<Sniffer> sniffers = dc.getTransientAppMetaData(DeploymentProperties.SNIFFERS, Collection.class);
    archivist.setExtensionArchivists(archivistFactory.getExtensionsArchivists(sniffers, archivist.getModuleType()));
    ApplicationHolder holder = dc.getModuleMetaData(ApplicationHolder.class);
    File deploymentPlan = params.deploymentplan;
    handleDeploymentPlan(deploymentPlan, archivist, sourceArchive, holder);
    long start = System.currentTimeMillis();
    Application application = null;
    if (holder != null) {
        application = holder.app;
        application.setAppName(name);
        application.setClassLoader(cl);
        application.setRoleMapper(null);
        if (application.isVirtual()) {
            ModuleDescriptor md = application.getStandaloneBundleDescriptor().getModuleDescriptor();
            md.setModuleName(name);
        }
        try {
            applicationFactory.openWith(application, sourceArchive, archivist);
        } catch (SAXParseException e) {
            throw new IOException(e);
        }
    } else {
        // and it's a standalone module
        try {
            application = applicationFactory.openArchive(name, archivist, sourceArchive, true);
            application.setAppName(name);
            ModuleDescriptor md = application.getStandaloneBundleDescriptor().getModuleDescriptor();
            md.setModuleName(name);
        } catch (SAXParseException e) {
            throw new IOException(e);
        }
    }
    application.setRegistrationName(name);
    sourceArchive.removeExtraData(Types.class);
    sourceArchive.removeExtraData(Parser.class);
    Logger.getAnonymousLogger().log(Level.FINE, "DOL Loading time" + (System.currentTimeMillis() - start));
    return application;
}
Also used : Types(org.glassfish.hk2.classmodel.reflect.Types) Sniffer(org.glassfish.api.container.Sniffer) IOException(java.io.IOException) Parser(org.glassfish.hk2.classmodel.reflect.Parser) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) SAXParseException(org.xml.sax.SAXParseException) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) File(java.io.File) Application(com.sun.enterprise.deployment.Application)

Example 47 with DeployCommandParameters

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

the class EarHandler method getApplicationHolder.

private ApplicationHolder getApplicationHolder(ReadableArchive source, DeploymentContext context, boolean isDirectory) {
    ApplicationHolder holder = context.getModuleMetaData(ApplicationHolder.class);
    if (holder == null || holder.app == null) {
        try {
            DeployCommandParameters params = context.getCommandParameters(DeployCommandParameters.class);
            if (params != null && params.altdd != null) {
                source.addArchiveMetaData(DeploymentProperties.ALT_DD, params.altdd);
            }
            long start = System.currentTimeMillis();
            ApplicationArchivist archivist = habitat.getService(ApplicationArchivist.class);
            archivist.setAnnotationProcessingRequested(true);
            String xmlValidationLevel = dasConfig.getDeployXmlValidation();
            archivist.setXMLValidationLevel(xmlValidationLevel);
            if (xmlValidationLevel.equals("none")) {
                archivist.setXMLValidation(false);
            }
            holder = new ApplicationHolder(archivist.createApplication(source, isDirectory));
            Boolean cdiEnabled = new GFApplicationXmlParser(source).isEnableImplicitCDI();
            if (cdiEnabled != null) {
                context.getAppProps().put(RuntimeTagNames.PAYARA_ENABLE_IMPLICIT_CDI, cdiEnabled.toString().toLowerCase());
            }
            _logger.fine("time to read application.xml " + (System.currentTimeMillis() - start));
        } catch (IOException | XMLStreamException | SAXParseException e) {
            throw new RuntimeException(e);
        }
        context.addModuleMetaData(holder);
    }
    if (holder.app == null) {
        throw new RuntimeException(strings.get("errReadMetadata"));
    }
    return holder;
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) ApplicationHolder(org.glassfish.javaee.core.deployment.ApplicationHolder) XMLStreamException(javax.xml.stream.XMLStreamException) SAXParseException(org.xml.sax.SAXParseException) ApplicationArchivist(com.sun.enterprise.deployment.archivist.ApplicationArchivist)

Example 48 with DeployCommandParameters

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

the class CreateLifecycleModuleCommand method execute.

public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    try {
        validateTarget(target, name);
    } catch (IllegalArgumentException ie) {
        report.setMessage(ie.getMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    DeployCommandParameters commandParams = new DeployCommandParameters();
    commandParams.name = name;
    commandParams.enabled = enabled;
    commandParams.description = description;
    commandParams.target = target;
    // create a dummy context to hold params and props
    ExtendedDeploymentContext deploymentContext = new DeploymentContextImpl(report, null, commandParams, null);
    Properties appProps = deploymentContext.getAppProps();
    if (property != null) {
        appProps.putAll(property);
    }
    // set to default "user", deployers can override it
    appProps.setProperty(ServerTags.OBJECT_TYPE, "user");
    appProps.setProperty(ServerTags.CLASS_NAME, classname);
    if (classpath != null) {
        appProps.setProperty(ServerTags.CLASSPATH, classpath);
    }
    if (loadorder != null) {
        appProps.setProperty(ServerTags.LOAD_ORDER, loadorder);
    }
    appProps.setProperty(ServerTags.IS_FAILURE_FATAL, failurefatal.toString());
    appProps.setProperty(ServerTags.IS_LIFECYCLE, "true");
    try {
        Transaction t = deployment.prepareAppConfigChanges(deploymentContext);
        deployment.registerAppInDomainXML(null, deploymentContext, t);
    } catch (Exception e) {
        report.setMessage("Failed to create lifecycle module: " + e);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) Transaction(org.jvnet.hk2.config.Transaction) ActionReport(org.glassfish.api.ActionReport) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) Properties(java.util.Properties) DeploymentContextImpl(org.glassfish.deployment.common.DeploymentContextImpl)

Example 49 with DeployCommandParameters

use of org.glassfish.api.deployment.DeployCommandParameters 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 50 with DeployCommandParameters

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

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