Package org.glassfish.api

Examples of org.glassfish.api.ActionReport$MessagePart


        ServerContext serverContext;


    public void execute(AdminCommandContext context) {

        final ActionReport report = context.getActionReport();

        if (destType != null && !destType.equals(JMS_DEST_TYPE_QUEUE)
                && !destType.equals(JMS_DEST_TYPE_TOPIC)) {
            report.setMessage(localStrings.getLocalString("admin.mbeans.rmb.invalid_jms_desttype", destType));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }

        report.setExtraProperties(new Properties());
        List<Map> jmsDestList = new ArrayList<Map>();

        try {
            List<JMSDestinationInfo> list = listJMSDestinations(target, destType);

            for (JMSDestinationInfo destInfo : list) {
                final ActionReport.MessagePart part = report.getTopMessagePart().addChild();
                part.setMessage(destInfo.getDestinationName());
                Map<String, String> destMap = new HashMap<String, String>();
                destMap.put("name", destInfo.getDestinationName());
                destMap.put("type", destInfo.getDestinationType());
                jmsDestList.add(destMap);
            }

            report.getExtraProperties().put("destinations", jmsDestList);

        } catch (Exception e) {
            logger.throwing(getClass().getName(), "ListJMSDestination", e);
            e.printStackTrace();//handleException(e);
            report.setMessage(localStrings.getLocalString("list.jms.dest.fail",
                    "Unable to list JMS Destinations. Please ensure that the Message Queue Brokers are running"));// + " " + e.getLocalizedMessage());
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setFailureCause(e);
            return;
        }
    }
View Full Code Here


    final private static LocalStringManagerImpl localStrings = new LocalStringManagerImpl(ListLoggerLevels.class);

    public void execute(AdminCommandContext context) {

        final ActionReport report = context.getActionReport();
        boolean isCluster = false;
        boolean isDas = false;
        boolean isInstance = false;
        boolean isConfig = false;
        String targetConfigName = "";

        try {
            HashMap<String, String> props = null;

            Config config = domain.getConfigNamed(target);
            if (config != null) {
                targetConfigName = target;
                isConfig = true;

                Server targetServer = domain.getServerNamed(SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME);
                if (targetServer.getConfigRef().equals(target)) {
                    isDas = true;
                }
            } else {

                Server targetServer = domain.getServerNamed(target);

                if (targetServer != null && targetServer.isDas()) {
                    isDas = true;
                } else {
                    com.sun.enterprise.config.serverbeans.Cluster cluster = domain.getClusterNamed(target);
                    if (cluster != null) {
                        isCluster = true;
                        targetConfigName = cluster.getConfigRef();
                    } else if (targetServer != null) {
                        isInstance = true;
                        targetConfigName = targetServer.getConfigRef();
                    }
                }

                if (isInstance) {
                    Cluster clusterForInstance = targetServer.getCluster();
                    if (clusterForInstance != null) {
                        targetConfigName = clusterForInstance.getConfigRef();
                    }
                }
            }

            if (isCluster || isInstance) {
                props = (HashMap<String, String>) loggingConfig.getLoggingProperties(targetConfigName);
            } else if (isDas) {
                props = (HashMap<String, String>) loggingConfig.getLoggingProperties();
            } else if (isConfig) {
                // This loop is for the config which is not part of any target
                props = (HashMap<String, String>) loggingConfig.getLoggingProperties(targetConfigName);
            } else {
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                String msg = localStrings.getLocalString("invalid.target.sys.props",
                        "Invalid target: {0}. Valid default target is a server named ''server'' (default) or cluster name.", target);
                report.setMessage(msg);
                return;
            }

            List<String> keys = new ArrayList<String>();
            keys.addAll(props.keySet());
            Collections.sort(keys);
            Iterator<String> it2 = keys.iterator();

            // The following Map is used to hold the REST data
            Map<String, String> logAttributes = new HashMap<String, String>();

            while (it2.hasNext()) {
                String name = it2.next();
                if (!name.endsWith(".level") && !name.equals(".level")) {
                    final ActionReport.MessagePart part = report.getTopMessagePart()
                            .addChild();
                    part.setMessage(name + "\t" + "<" + props.get(name) + ">");
                    logAttributes.put(name, props.get(name));
                }
            }
            Properties restData = new Properties();
            restData.put("logAttributes", logAttributes);
            restData.put("defaultLoggingProperties", loggingConfig.getDefaultLoggingProperties());
            report.setExtraProperties(restData);

        } catch (IOException ex) {
            report.setMessage(localStrings.getLocalString("get.log.attribute.failed",
                    "Could not get logging attributes for {0}.", target));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    }
View Full Code Here

     * where the keys are the paramter names and the values the parameter values
     *
     * @param context information
     */
    public void execute(AdminCommandContext context) {
        final ActionReport report = context.getActionReport();
        Config targetConfig = domain.getConfigNamed(target);
        if (targetConfig != null)
            config = targetConfig;
       
        Server targetServer = domain.getServerNamed(target);
        //String configRef = targetServer.getConfigRef();
        if (targetServer!=null) {
           config = domain.getConfigNamed(targetServer.getConfigRef());
        }
        com.sun.enterprise.config.serverbeans.Cluster cluster =domain.getClusterNamed(target);
        if (cluster!=null) {
            config = domain.getConfigNamed(cluster.getConfigRef());
        }

        if (jmsHostName == null) {
            report.setMessage(localStrings.getLocalString("create.jms.host.noJmsHost",
                            "No JMS Host name specified."));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        JmsService jmsservice = config.getExtensionByType(JmsService.class);
        /*for (Config c : configs.getConfig()) {

               if(configRef.equals(c.getName()))
                     jmsservice = c.getJmsService();
            }*/

        // ensure we don't already have one of this name before creating it.
        for (JmsHost jmsHost : jmsservice.getJmsHost()) {
                if (jmsHostName.equals(jmsHost.getName())) {
                    if (force) {
                        ActionReport deleteReport = report.addSubActionsReport();
                        ParameterMap parameters = new ParameterMap();
                         parameters.set("DEFAULT", jmsHostName);
                         parameters.set("target", target);
                        commandRunner.getCommandInvocation("delete-jms-host", deleteReport, context.getSubject()).parameters(parameters).execute();
                        if (ActionReport.ExitCode.FAILURE.equals(deleteReport.getActionExitCode())) {
                            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                            return;
                        }
                        break;
                    } else {
View Full Code Here

    final private static LocalStringManagerImpl localStrings = new LocalStringManagerImpl(ListLoggerLevels.class);

    public void execute(AdminCommandContext context) {

        final ActionReport report = context.getActionReport();
        boolean isCluster = false;
        boolean isDas = false;
        boolean isInstance = false;
        boolean isConfig = false;
        String targetConfigName = "";

        try {
            HashMap<String, String> props = null;

            Config config = domain.getConfigNamed(target);
            if (config != null) {
                targetConfigName = target;
                isConfig = true;

                Server targetServer = domain.getServerNamed(SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME);
                if (targetServer.getConfigRef().equals(target)) {
                    isDas = true;
                }
            } else {

                Server targetServer = domain.getServerNamed(target);

                if (targetServer != null && targetServer.isDas()) {
                    isDas = true;
                } else {
                    com.sun.enterprise.config.serverbeans.Cluster cluster = domain.getClusterNamed(target);
                    if (cluster != null) {
                        isCluster = true;
                        targetConfigName = cluster.getConfigRef();
                    } else if (targetServer != null) {
                        isInstance = true;
                        targetConfigName = targetServer.getConfigRef();
                    }
                }

                if (isInstance) {
                    Cluster clusterForInstance = targetServer.getCluster();
                    if (clusterForInstance != null) {
                        targetConfigName = clusterForInstance.getConfigRef();
                    }
                }
            }

            if (isCluster || isInstance) {
                props = (HashMap<String, String>) loggingConfig.getLoggingProperties(targetConfigName);
            } else if (isDas) {
                props = (HashMap<String, String>) loggingConfig.getLoggingProperties();
            } else if (isConfig) {
                // This loop is for the config which is not part of any target
                props = (HashMap<String, String>) loggingConfig.getLoggingProperties(targetConfigName);
            } else {
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                String msg = localStrings.getLocalString("invalid.target.sys.props",
                        "Invalid target: {0}. Valid default target is a server named ''server'' (default) or cluster name.", target);
                report.setMessage(msg);
                return;
            }

            List<String> keys = new ArrayList<String>();
            keys.addAll(props.keySet());
            Collections.sort(keys);
            Iterator<String> it2 = keys.iterator();
            // The following Map & List are used to hold the REST data
            Map<String, String> logLevelMap = new HashMap<String, String>();
            List<String> loggerList = new ArrayList<String>();
            while (it2.hasNext()) {
                String name = it2.next();
                if (name.endsWith(".level") && !name.equals(".level")) {
                    final ActionReport.MessagePart part = report.getTopMessagePart()
                            .addChild();
                    String n = name.substring(0, name.lastIndexOf(".level"));
                    part.setMessage(n + "\t" + "<" + (String) props.get(name) + ">");
                    logLevelMap.put(n, props.get(name)); //Needed for REST xml and JSON output
                    loggerList.add(n); //Needed for REST xml and JSON output                   
                }
            }
            // Populate the extraProperties data structure for REST...
            Properties restData = new Properties();
            restData.put("logLevels", logLevelMap);
            restData.put("loggers", loggerList);
            report.setExtraProperties(restData);

        } catch (IOException ex) {
            report.setMessage(localStrings.getLocalString("get.log.level.failed",
                    "Could not get logging levels for {0}.", target));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);


    }
View Full Code Here

                } else {
                    params.origin = OpsParams.Origin.load;
                }
                params.target = _ejbContainerUtil.getServerEnvironment().getInstanceName();

                ActionReport report = _ejbContainerUtil.getServices().
                        getService(ActionReport.class, "plain");
                Deployment deployment = _ejbContainerUtil.getDeployment();
                ExtendedDeploymentContext dc = deployment.getBuilder(
                        logger, params, report).source(app).build();
                dc.addTransientAppMetaData(DatabaseConstants.JTA_DATASOURCE_JNDI_NAME_OVERRIDE, resourceName);
                Properties appProps = dc.getAppProps();
                appProps.setProperty(ServerTags.OBJECT_TYPE, DeploymentProperties.SYSTEM_ALL);

                deployment.deploy(dc);

                if (report.getActionExitCode() != ActionReport.ExitCode.SUCCESS) {
                    logger.log (Level.WARNING, "Cannot deploy or load EJBTimerService: ",
                            report.getFailureCause());
                } else {
                    deployed = true;
                }
            } catch (Exception e) {
                logger.log (Level.WARNING, "Cannot deploy or load EJBTimerService: ", e);
View Full Code Here

                    }
                }
            }
            throw ex;
        }
        ActionReport ar = rac.getActionReport();
        if (ar != null && ExitCode.WARNING == ar.getActionExitCode()) {
            return WARNING;
        }
        return SUCCESS;
    }
View Full Code Here

    private Logger logger = Logger.getAnonymousLogger();

    public CommandResult run(String command, String... args){
        try {
            ActionReport actionReport = executeCommand(command, args);
            return convert(actionReport);
        } catch (Exception e) {
            return convert(e);
        }
    }
View Full Code Here

     * @return
     * @throws CommandException
     */
    /* package */ ActionReport executeCommand(String command, String... args) throws CommandException {
        ParameterMap commandParams = getParameters(command, args);
        final ActionReport actionReport = createActionReport();

        org.glassfish.api.admin.CommandRunner.CommandInvocation inv =
                commandRunner.getCommandInvocation(command, actionReport, embeddedSystemAdministrator.getSubject());

        inv.parameters(commandParams).execute();
View Full Code Here

     *
     * @param context information
     */
    public void execute(AdminCommandContext context) {

        final ActionReport report = context.getActionReport();
        Config targetConfig = domain.getConfigNamed(target);
                if (targetConfig != null)
                    config = targetConfig;
               
        Server targetServer = domain.getServerNamed(target);
        //String configRef = targetServer.getConfigRef();
        if (targetServer!=null) {
            config = domain.getConfigNamed(targetServer.getConfigRef());
        }
        com.sun.enterprise.config.serverbeans.Cluster cluster =domain.getClusterNamed(target);
        if (cluster!=null) {
            config = domain.getConfigNamed(cluster.getConfigRef());
        }

        JmsService jmsService = config.getExtensionByType(JmsService.class);
            /*for (Config c : configs.getConfig()) {
                if(configRef.equals(c.getName()))
                     jmsService = c.getJmsService();
            } */

            if (jmsService == null) {
            report.setMessage(localStrings.getLocalString("list.jms.host.invalidTarget",
                            "Invalid Target specified."));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
          }
           try {
            ArrayList<String> list = new ArrayList();
            for (JmsHost r : jmsService.getJmsHost()) {
                list.add(r.getName());
            }

            for (String jmsName : list) {
                final ActionReport.MessagePart part = report.getTopMessagePart().addChild();
                part.setMessage(jmsName);
            }
        } catch (Exception e) {
            report.setMessage(localStrings.getLocalString("list.jms.host.fail",
                    "Unable to list JMS Hosts") + " " + e.getLocalizedMessage());
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setFailureCause(e);
            return;
        }
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    }
View Full Code Here

    @Inject
    ServerContext serverContext;

    public void execute(AdminCommandContext context) {

        final ActionReport report = context.getActionReport();

        try {
            validateJMSDestName(destName);
            validateJMSDestType(destType);
        } catch (IllegalArgumentException e) {
            report.setMessage(e.getMessage());
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }

        if (destType.equals(JMS_DEST_TYPE_QUEUE)) {
            if (props == null) {
                props = new Properties();
            }
            if (!props.containsKey(MAX_ACTIVE_CONSUMERS_PROPERTY)
                    && !props.containsKey(MAX_ACTIVE_CONSUMERS_ATTRIBUTE)) {
                props.put(MAX_ACTIVE_CONSUMERS_ATTRIBUTE, DEFAULT_MAX_ACTIVE_CONSUMERS);
            }
        }
        try {
            createJMSDestination(report, context.getSubject());
        } catch (Exception e) {
            report.setMessage(localStrings.getLocalString("create.jms.destination.CannotCreateJMSDest",
                    "Unable to create JMS Destination."));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
View Full Code Here

TOP

Related Classes of org.glassfish.api.ActionReport$MessagePart

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.