Search in sources :

Example 41 with Module

use of com.sun.enterprise.config.serverbeans.Module 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));
    Optional<ApplicationState> appState = hotDeployService.getApplicationState(dc);
    appState.ifPresent(state -> sourceArchive.setExtraData(ApplicationState.class, state));
    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 = appState.map(state -> state.getModuleMetaData(Application.class)).orElse(holder != null ? holder.app : null);
    if (application != null) {
        application.setAppName(name);
        application.setClassLoader(cl);
        application.setRoleMapper(null);
        if (application.isVirtual()) {
            ModuleDescriptor md = application.getStandaloneBundleDescriptor().getModuleDescriptor();
            md.setModuleName(name);
            if (appState.map(ApplicationState::isActive).orElse(false)) {
                application.getStandaloneBundleDescriptor().setClassLoader(cl);
                dc.addModuleMetaData(application.getStandaloneBundleDescriptor());
                for (RootDeploymentDescriptor extension : application.getStandaloneBundleDescriptor().getExtensionsDescriptors()) {
                    extension.setClassLoader(cl);
                    dc.addModuleMetaData(extension);
                }
            }
        }
        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(FINE, "DOL Loading time{0}", System.currentTimeMillis() - start);
    return application;
}
Also used : StructuredDeploymentTracing(org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing) FileUtils(com.sun.enterprise.util.io.FileUtils) ApplicationMetaDataProvider(org.glassfish.api.deployment.ApplicationMetaDataProvider) Provider(javax.inject.Provider) Util(com.sun.enterprise.deployment.deploy.shared.Util) ClassLoaderHierarchy(org.glassfish.internal.api.ClassLoaderHierarchy) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) Level(java.util.logging.Level) ActionReport(org.glassfish.api.ActionReport) Inject(javax.inject.Inject) ArchiveFactory(com.sun.enterprise.deploy.shared.ArchiveFactory) ArchiveHandler(org.glassfish.api.deployment.archive.ArchiveHandler) DasConfig(com.sun.enterprise.config.serverbeans.DasConfig) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) ApplicationInfoProvider(org.glassfish.internal.deployment.ApplicationInfoProvider) LocalStringManagerImpl(com.sun.enterprise.util.LocalStringManagerImpl) ServerEnvironment(org.glassfish.api.admin.ServerEnvironment) DeploymentContext(org.glassfish.api.deployment.DeploymentContext) FileArchive(com.sun.enterprise.deploy.shared.FileArchive) HTMLActionReporter(com.sun.enterprise.admin.report.HTMLActionReporter) WritableArchive(org.glassfish.api.deployment.archive.WritableArchive) Sniffer(org.glassfish.api.container.Sniffer) HotDeployService(fish.payara.nucleus.hotdeploy.HotDeployService) PreDestroy(org.glassfish.hk2.api.PreDestroy) DeploymentTracing(org.glassfish.internal.deployment.DeploymentTracing) Types(org.glassfish.hk2.classmodel.reflect.Types) FINE(java.util.logging.Level.FINE) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) Module(com.sun.enterprise.config.serverbeans.Module) Collection(java.util.Collection) IOException(java.io.IOException) com.sun.enterprise.deployment.archivist(com.sun.enterprise.deployment.archivist) DeploymentSpan(org.glassfish.internal.deployment.analysis.DeploymentSpan) Logger(java.util.logging.Logger) File(java.io.File) DeploymentPlanArchive(com.sun.enterprise.deployment.deploy.shared.DeploymentPlanArchive) Parser(org.glassfish.hk2.classmodel.reflect.Parser) ApplicationState(fish.payara.nucleus.hotdeploy.ApplicationState) SAXParseException(org.xml.sax.SAXParseException) List(java.util.List) Service(org.jvnet.hk2.annotations.Service) MetaData(org.glassfish.api.deployment.MetaData) Domain(com.sun.enterprise.config.serverbeans.Domain) InputJarArchive(com.sun.enterprise.deployment.deploy.shared.InputJarArchive) org.glassfish.deployment.common(org.glassfish.deployment.common) Optional(java.util.Optional) Application(com.sun.enterprise.deployment.Application) Deployment(org.glassfish.internal.deployment.Deployment) Types(org.glassfish.hk2.classmodel.reflect.Types) ApplicationState(fish.payara.nucleus.hotdeploy.ApplicationState) 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 42 with Module

use of com.sun.enterprise.config.serverbeans.Module in project Payara by payara.

the class ListSubComponentsCommand method execute.

public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    ActionReport.MessagePart part = report.getTopMessagePart();
    String applicationName = modulename;
    if (appname != null) {
        applicationName = appname;
    }
    try {
        VersioningUtils.checkIdentifier(applicationName);
    } catch (VersioningSyntaxException ex) {
        report.setMessage(ex.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (!deployment.isRegistered(applicationName)) {
        report.setMessage(localStrings.getLocalString("application.notreg", "Application {0} not registered", applicationName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    Application application = applications.getApplication(applicationName);
    if (application.isLifecycleModule()) {
        if (!terse) {
            part.setMessage(localStrings.getLocalString("listsubcomponents.no.elements.to.list", "Nothing to List."));
        }
        return;
    }
    ApplicationInfo appInfo = appRegistry.get(applicationName);
    if (appInfo == null) {
        report.setMessage(localStrings.getLocalString("application.not.enabled", "Application {0} is not in an enabled state", applicationName));
        return;
    }
    com.sun.enterprise.deployment.Application app = appInfo.getMetaData(com.sun.enterprise.deployment.Application.class);
    if (app == null) {
        if (!terse) {
            part.setMessage(localStrings.getLocalString("listsubcomponents.no.elements.to.list", "Nothing to List."));
        }
        return;
    }
    Map<String, String> subComponents;
    Map<String, String> subComponentsMap = new HashMap<String, String>();
    if (appname == null) {
        subComponents = getAppLevelComponents(app, type, subComponentsMap);
    } else {
        // strip the version suffix (delimited by colon), if present
        int versionSuffix = modulename.indexOf(':');
        String versionLessModuleName = versionSuffix > 0 ? modulename.substring(0, versionSuffix) : modulename;
        BundleDescriptor bundleDesc = app.getModuleByUri(versionLessModuleName);
        if (bundleDesc == null) {
            report.setMessage(localStrings.getLocalString("listsubcomponents.invalidmodulename", "Invalid module name", appname, modulename));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        subComponents = getModuleLevelComponents(bundleDesc, type, subComponentsMap);
    }
    // the type param can only have values "ejbs" and "servlets"
    if (type != null) {
        if (!type.equals("servlets") && !type.equals("ejbs")) {
            report.setMessage(localStrings.getLocalString("listsubcomponents.invalidtype", "The type option has invalid value {0}. It should have a value of servlets or ejbs.", type));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    List<String> subModuleInfos = new ArrayList<String>();
    if (!app.isVirtual()) {
        subModuleInfos = getSubModulesForEar(app, type);
    }
    int[] longestValue = new int[2];
    for (Map.Entry<String, String> entry : subComponents.entrySet()) {
        String key = entry.getKey();
        if (key.length() > longestValue[0]) {
            longestValue[0] = key.length();
        }
        String value = entry.getValue();
        if (value.length() > longestValue[1]) {
            longestValue[1] = value.length();
        }
    }
    StringBuilder formattedLineBuf = new StringBuilder();
    for (int j = 0; j < 2; j++) {
        longestValue[j] += 2;
        formattedLineBuf.append("%-").append(longestValue[j]).append("s");
    }
    String formattedLine = formattedLineBuf.toString();
    if (!terse && subComponents.isEmpty()) {
        part.setMessage(localStrings.getLocalString("listsubcomponents.no.elements.to.list", "Nothing to List."));
    }
    int i = 0;
    for (Map.Entry<String, String> entry : subComponents.entrySet()) {
        ActionReport.MessagePart childPart = part.addChild();
        childPart.setMessage(String.format(formattedLine, new Object[] { entry.getKey(), entry.getValue() }));
        if (appname == null && !app.isVirtual()) {
            // support for JSR88 client
            if (subModuleInfos.get(i) != null) {
                childPart.addProperty("moduleInfo", subModuleInfos.get(i));
            }
        }
        if (resources) {
            Module module = application.getModule(entry.getKey());
            if (module != null) {
                ActionReport subReport = report.addSubActionsReport();
                CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation("_list-resources", subReport, context.getSubject());
                final ParameterMap parameters = new ParameterMap();
                parameters.add("appname", application.getName());
                parameters.add("modulename", module.getName());
                inv.parameters(parameters).execute();
                ActionReport.MessagePart subPart = subReport.getTopMessagePart();
                for (ActionReport.MessagePart cp : subPart.getChildren()) {
                    ActionReport.MessagePart resourcesChildPart = childPart.addChild();
                    resourcesChildPart.setMessage("  " + cp.getMessage());
                }
            }
        }
        i++;
    }
    // add the properties for GUI to display
    Set<String> keys = subComponentsMap.keySet();
    for (String key : keys) {
        part.addProperty(key, subComponentsMap.get(key));
    }
    // now this is the normal output for the list-sub-components command
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) ActionReport(org.glassfish.api.ActionReport) VersioningSyntaxException(org.glassfish.deployment.versioning.VersioningSyntaxException) com.sun.enterprise.deployment(com.sun.enterprise.deployment) Module(com.sun.enterprise.config.serverbeans.Module) Application(com.sun.enterprise.config.serverbeans.Application)

Aggregations

Module (com.sun.enterprise.config.serverbeans.Module)42 Application (com.sun.enterprise.config.serverbeans.Application)11 ActionReport (org.glassfish.api.ActionReport)9 PropertyVetoException (java.beans.PropertyVetoException)5 Engine (com.sun.enterprise.config.serverbeans.Engine)3 Resource (com.sun.enterprise.config.serverbeans.Resource)3 Resources (com.sun.enterprise.config.serverbeans.Resources)3 ArrayList (java.util.ArrayList)3 Property (org.jvnet.hk2.config.types.Property)3 Server (com.sun.enterprise.config.serverbeans.Server)2 ConnectorApplication (com.sun.enterprise.connectors.module.ConnectorApplication)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 ConnectorResource (org.glassfish.connectors.config.ConnectorResource)2 WorkSecurityMap (org.glassfish.connectors.config.WorkSecurityMap)2 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)2 Resource (org.glassfish.resources.api.Resource)2 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)1 RemoteRestAdminCommand (com.sun.enterprise.admin.remote.RemoteRestAdminCommand)1 ServerRemoteRestAdminCommand (com.sun.enterprise.admin.remote.ServerRemoteRestAdminCommand)1