Search in sources :

Example 16 with ActionReport

use of org.glassfish.api.ActionReport in project Payara by payara.

the class CreateProtocol method execute.

/**
 * Executes the command with the command parameters passed as Properties where the keys are the paramter names and
 * the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    Target targetUtil = services.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    final ActionReport report = context.getActionReport();
    // check for duplicates
    NetworkConfig networkConfig = config.getNetworkConfig();
    Protocols protocols = networkConfig.getProtocols();
    for (Protocol protocol : protocols.getProtocol()) {
        if (protocolName != null && protocolName.equalsIgnoreCase(protocol.getName())) {
            report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PROTOCOL_FAIL_DUPLICATE), protocolName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    // Add to the <network-config>
    try {
        create(protocols, protocolName, securityEnabled);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PROTOCOL_FAIL), protocolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    } catch (Exception e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PROTOCOL_FAIL), protocolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) Protocols(org.glassfish.grizzly.config.dom.Protocols) Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) ActionReport(org.glassfish.api.ActionReport) Protocol(org.glassfish.grizzly.config.dom.Protocol)

Example 17 with ActionReport

use of org.glassfish.api.ActionReport in project Payara by payara.

the class ListTimers method execute.

/**
 * Executes the command
 *
 * @param context information
 */
@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    String[] serverIds = null;
    if (targetUtil.isCluster(target) || targetUtil.isDeploymentGroup(target)) {
        List<Server> serversInCluster = targetUtil.getInstances(target);
        serverIds = new String[serversInCluster.size()];
        for (int i = 0; i < serverIds.length; i++) {
            serverIds[i] = serversInCluster.get(i).getName();
        }
    } else {
        serverIds = new String[] { target };
    }
    try {
        String[] timerCounts = listTimers(serverIds);
        ActionReport actionReport = context.getActionReport();
        Properties extraProperties = actionReport.getExtraProperties();
        if (extraProperties == null) {
            extraProperties = new Properties();
            actionReport.setExtraProperties(extraProperties);
        }
        List<Map<String, String>> property = new LinkedList<>();
        extraProperties.put("ejbTimers", property);
        for (int i = 0; i < serverIds.length; i++) {
            final ActionReport.MessagePart part = report.getTopMessagePart().addChild();
            part.setMessage(serverIds[i] + ": " + timerCounts[i]);
            HashMap<String, String> values = new HashMap<>();
            values.put("server", serverIds[i]);
            values.put("timerCount", timerCounts[i]);
            property.add(values);
        }
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    } catch (Exception e) {
        report.setMessage(localStrings.getLocalString("list.timers.failed", "List Timers command failed"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) HashMap(java.util.HashMap) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) RestEndpoint(org.glassfish.api.admin.RestEndpoint) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with ActionReport

use of org.glassfish.api.ActionReport in project Payara by payara.

the class DolProvider method validateKeepStateOption.

private void validateKeepStateOption(DeploymentContext context, DeployCommandParameters params, Application app) {
    if ((params.keepstate != null && params.keepstate) || app.getKeepState()) {
        if (!isDASTarget(context, params)) {
            // for non-DAS target, and keepstate is set to true either
            // through deployment option or deployment descriptor
            // explicitly set the deployment option to false
            params.keepstate = false;
            String warningMsg = localStrings.getLocalString("not.support.keepstate.in.cluster", "Ignoring the keepstate setting: the keepstate option is only supported in developer profile and not cluster profile.");
            ActionReport subReport = context.getActionReport().addSubActionsReport();
            subReport.setActionExitCode(ActionReport.ExitCode.WARNING);
            subReport.setMessage(warningMsg);
            context.getLogger().log(Level.WARNING, warningMsg);
        }
    }
}
Also used : ActionReport(org.glassfish.api.ActionReport)

Example 19 with ActionReport

use of org.glassfish.api.ActionReport in project Payara by payara.

the class EarHandler method getClassLoader.

public ClassLoader getClassLoader(final ClassLoader parent, DeploymentContext context) {
    final ReadableArchive archive = context.getSource();
    final ApplicationHolder holder = getApplicationHolder(archive, context, true);
    // the ear classloader hierachy will be
    // ear lib classloader <- embedded rar classloader <-
    // ear classloader <- various module classloaders
    final DelegatingClassLoader embeddedConnCl;
    final EarClassLoader cl;
    // add the libraries packaged in the application library directory
    try {
        String compatProp = context.getAppProps().getProperty(DeploymentProperties.COMPATIBILITY);
        // let's see if it's defined in glassfish-application.xml
        if (compatProp == null) {
            GFApplicationXmlParser gfApplicationXmlParser = new GFApplicationXmlParser(context.getSource());
            compatProp = gfApplicationXmlParser.getCompatibilityValue();
            if (compatProp != null) {
                context.getAppProps().put(DeploymentProperties.COMPATIBILITY, compatProp);
            }
        }
        // let's see if it's defined in sun-application.xml
        if (compatProp == null) {
            SunApplicationXmlParser sunApplicationXmlParser = new SunApplicationXmlParser(context.getSourceDir());
            compatProp = sunApplicationXmlParser.getCompatibilityValue();
            if (compatProp != null) {
                context.getAppProps().put(DeploymentProperties.COMPATIBILITY, compatProp);
            }
        }
        if (System.getSecurityManager() != null) {
            // procee declared permissions
            earDeclaredPC = PermsArchiveDelegate.getDeclaredPermissions(SMGlobalPolicyUtil.CommponentType.ear, context);
            // process ee permissions
            processEEPermissions(context);
        }
        final URL[] earLibURLs = ASClassLoaderUtil.getAppLibDirLibraries(context.getSourceDir(), holder.app.getLibraryDirectory(), compatProp);
        final EarLibClassLoader earLibCl = AccessController.doPrivileged(new PrivilegedAction<EarLibClassLoader>() {

            @Override
            public EarLibClassLoader run() {
                return new EarLibClassLoader(earLibURLs, parent);
            }
        });
        String clDelegate = holder.app.getClassLoadingDelegate();
        // default to true if null
        if (Boolean.parseBoolean(clDelegate == null ? "true" : clDelegate) == false) {
            earLibCl.enableCurrentBeforeParentUnconditional();
        } else if (clDelegate != null) {
            // otherwise clDelegate == true
            earLibCl.disableCurrentBeforeParent();
        }
        if (System.getSecurityManager() != null) {
            addEEOrDeclaredPermissions(earLibCl, earDeclaredPC, false);
            if (_logger.isLoggable(Level.FINE))
                _logger.fine("added declaredPermissions to earlib: " + earDeclaredPC);
            addEEOrDeclaredPermissions(earLibCl, eeGarntsMap.get(SMGlobalPolicyUtil.CommponentType.ear), true);
            if (_logger.isLoggable(Level.FINE))
                _logger.fine("added all ee permissions to earlib: " + eeGarntsMap.get(SMGlobalPolicyUtil.CommponentType.ear));
        }
        embeddedConnCl = AccessController.doPrivileged(new PrivilegedAction<DelegatingClassLoader>() {

            @Override
            public DelegatingClassLoader run() {
                return new DelegatingClassLoader(earLibCl);
            }
        });
        cl = AccessController.doPrivileged(new PrivilegedAction<EarClassLoader>() {

            @Override
            public EarClassLoader run() {
                return new EarClassLoader(embeddedConnCl, holder.app);
            }
        });
        // add ear lib to module classloader list so we can
        // clean it up later
        cl.addModuleClassLoader(EAR_LIB, earLibCl);
        if (System.getSecurityManager() != null) {
            // push declared permissions to ear classloader
            addEEOrDeclaredPermissions(cl, earDeclaredPC, false);
            if (_logger.isLoggable(Level.FINE))
                _logger.fine("declaredPermissions added: " + earDeclaredPC);
            // push ejb permissions to ear classloader
            addEEOrDeclaredPermissions(cl, eeGarntsMap.get(SMGlobalPolicyUtil.CommponentType.ejb), true);
            if (_logger.isLoggable(Level.FINE))
                _logger.fine("ee permissions added: " + eeGarntsMap.get(SMGlobalPolicyUtil.CommponentType.ejb));
        }
    } catch (Exception e) {
        _logger.log(Level.SEVERE, strings.get("errAddLibs"), e);
        throw new RuntimeException(e);
    }
    for (ModuleDescriptor md : holder.app.getModules()) {
        ReadableArchive sub = null;
        String moduleUri = md.getArchiveUri();
        try {
            sub = archive.getSubArchive(moduleUri);
            if (sub instanceof InputJarArchive) {
                throw new IllegalArgumentException(strings.get("wrongArchType", moduleUri));
            }
        } catch (IOException e) {
            _logger.log(Level.FINE, "Sub archive " + moduleUri + " seems unreadable", e);
        }
        if (sub != null) {
            try {
                ArchiveHandler handler = context.getModuleArchiveHandlers().get(moduleUri);
                if (handler == null) {
                    handler = getArchiveHandlerFromModuleType(md.getModuleType());
                    if (handler == null) {
                        handler = deployment.getArchiveHandler(sub);
                    }
                    context.getModuleArchiveHandlers().put(moduleUri, handler);
                }
                if (handler != null) {
                    ActionReport subReport = context.getActionReport().addSubActionsReport();
                    // todo : this is a hack, once again,
                    // the handler is assuming a file:// url
                    ExtendedDeploymentContext subContext = new DeploymentContextImpl(subReport, sub, context.getCommandParameters(DeployCommandParameters.class), env) {

                        @Override
                        public File getScratchDir(String subDirName) {
                            String modulePortion = Util.getURIName(getSource().getURI());
                            return (new File(super.getScratchDir(subDirName), modulePortion));
                        }
                    };
                    // sub context will store the root archive handler also
                    // so we can figure out the enclosing archive type
                    subContext.setArchiveHandler(context.getArchiveHandler());
                    subContext.setParentContext((ExtendedDeploymentContext) context);
                    sub.setParentArchive(context.getSource());
                    ClassLoader subCl = handler.getClassLoader(cl, subContext);
                    if ((System.getSecurityManager() != null) && (subCl instanceof DDPermissionsLoader)) {
                        addEEOrDeclaredPermissions(subCl, earDeclaredPC, false);
                        if (_logger.isLoggable(Level.FINE))
                            _logger.fine("added declared permissions to sub module of " + subCl);
                    }
                    if (md.getModuleType().equals(DOLUtils.ejbType())) {
                        // for ejb module, we just add the ejb urls
                        // to EarClassLoader and use that to load
                        // ejb module
                        URL[] moduleURLs = ((URLClassLoader) subCl).getURLs();
                        for (URL moduleURL : moduleURLs) {
                            cl.addURL(moduleURL);
                        }
                        cl.addModuleClassLoader(moduleUri, cl);
                        PreDestroy.class.cast(subCl).preDestroy();
                    } else if (md.getModuleType().equals(DOLUtils.rarType())) {
                        embeddedConnCl.addDelegate((DelegatingClassLoader.ClassFinder) subCl);
                        cl.addModuleClassLoader(moduleUri, subCl);
                    } else {
                        Boolean isTempClassLoader = context.getTransientAppMetaData(ExtendedDeploymentContext.IS_TEMP_CLASSLOADER, Boolean.class);
                        if (subCl instanceof URLClassLoader && (isTempClassLoader != null) && isTempClassLoader) {
                            // for temp classloader, we add all the module
                            // urls to the top level EarClassLoader
                            URL[] moduleURLs = ((URLClassLoader) subCl).getURLs();
                            for (URL moduleURL : moduleURLs) {
                                cl.addURL(moduleURL);
                            }
                        }
                        cl.addModuleClassLoader(moduleUri, subCl);
                    }
                }
            } catch (IOException e) {
                _logger.log(Level.SEVERE, strings.get("noClassLoader", moduleUri), e);
            }
        }
    }
    return cl;
}
Also used : AbstractArchiveHandler(com.sun.enterprise.deploy.shared.AbstractArchiveHandler) ActionReport(org.glassfish.api.ActionReport) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) URL(java.net.URL) ApplicationHolder(org.glassfish.javaee.core.deployment.ApplicationHolder) PrivilegedAction(java.security.PrivilegedAction) DDPermissionsLoader(com.sun.enterprise.security.integration.DDPermissionsLoader) URLClassLoader(java.net.URLClassLoader) DelegatingClassLoader(org.glassfish.internal.api.DelegatingClassLoader) InputJarArchive(com.sun.enterprise.deployment.deploy.shared.InputJarArchive) DelegatingClassLoader(org.glassfish.internal.api.DelegatingClassLoader) XMLStreamException(javax.xml.stream.XMLStreamException) PrivilegedActionException(java.security.PrivilegedActionException) SAXParseException(org.xml.sax.SAXParseException) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) URLClassLoader(java.net.URLClassLoader) PreDestroy(org.glassfish.hk2.api.PreDestroy)

Example 20 with ActionReport

use of org.glassfish.api.ActionReport in project Payara by payara.

the class CreateJMSDestination method createJMSDestination.

// create-jmsdest
private void createJMSDestination(ActionReport report, final Subject subject) throws Exception {
    MQJMXConnectorInfo mqInfo = getMQJMXConnectorInfo(target, config, serverContext, domain, connectorRuntime);
    // MBeanServerConnection  mbsc = getMBeanServerConnection(tgtName);
    try {
        MBeanServerConnection mbsc = mqInfo.getMQMBeanServerConnection();
        ObjectName on = new ObjectName(DESTINATION_MANAGER_CONFIG_MBEAN_NAME);
        String[] signature = null;
        AttributeList destAttrs = null;
        Object[] params = null;
        if (force) {
            signature = new String[] {};
            params = new Object[] {};
            ObjectName[] dests = (ObjectName[]) mbsc.invoke(on, "getDestinations", params, signature);
            boolean destExists = false;
            if (dests != null) {
                String type = destType.equalsIgnoreCase(JMS_DEST_TYPE_TOPIC) ? "t" : "q";
                for (ObjectName dest : dests) {
                    if (dest.toString().indexOf("desttype=" + type + ",name=" + ObjectName.quote(destName)) != -1) {
                        destExists = true;
                        break;
                    }
                }
            }
            if (destExists) {
                ActionReport deleteReport = report.addSubActionsReport();
                ParameterMap parameters = new ParameterMap();
                parameters.set("DEFAULT", destName);
                parameters.set("destType", destType);
                parameters.set("target", target);
                commandRunner.getCommandInvocation("delete-jmsdest", deleteReport, subject).parameters(parameters).execute();
                if (ActionReport.ExitCode.FAILURE.equals(deleteReport.getActionExitCode())) {
                    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                    return;
                }
            }
        }
        if (props != null) {
            destAttrs = convertProp2Attrs(props);
        }
        if (destType.equalsIgnoreCase(JMS_DEST_TYPE_TOPIC)) {
            destType = DESTINATION_TYPE_TOPIC;
        } else if (destType.equalsIgnoreCase(JMS_DEST_TYPE_QUEUE)) {
            destType = DESTINATION_TYPE_QUEUE;
        }
        if ((destAttrs == null) || (destAttrs.isEmpty())) {
            signature = new String[] { "java.lang.String", "java.lang.String" };
            params = new Object[] { destType, destName };
        } else {
            signature = new String[] { "java.lang.String", "java.lang.String", "javax.management.AttributeList" };
            params = new Object[] { destType, destName, destAttrs };
        }
        mbsc.invoke(on, "create", params, signature);
        report.setMessage(localStrings.getLocalString("create.jms.destination.success", "JMS Destination {0} created.", destName));
    } catch (Exception e) {
        logAndHandleException(e, "admin.mbeans.rmb.error_creating_jms_dest");
    } finally {
        try {
            if (mqInfo != null) {
                mqInfo.closeMQMBeanServerConnection();
            }
        } catch (Exception e) {
            handleException(e);
        }
    }
}
Also used : AttributeList(javax.management.AttributeList) ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) ObjectName(javax.management.ObjectName) MBeanServerConnection(javax.management.MBeanServerConnection)

Aggregations

ActionReport (org.glassfish.api.ActionReport)508 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)86 Properties (java.util.Properties)83 Config (com.sun.enterprise.config.serverbeans.Config)73 PropertyVetoException (java.beans.PropertyVetoException)72 ParameterMap (org.glassfish.api.admin.ParameterMap)66 Logger (java.util.logging.Logger)56 IOException (java.io.IOException)47 ArrayList (java.util.ArrayList)47 HashMap (java.util.HashMap)43 File (java.io.File)41 CommandTarget (org.glassfish.config.support.CommandTarget)30 Target (org.glassfish.internal.api.Target)30 Map (java.util.Map)27 Server (com.sun.enterprise.config.serverbeans.Server)25 List (java.util.List)25 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)24 CommandRunner (org.glassfish.api.admin.CommandRunner)23 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)23 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)19