Search in sources :

Example 21 with ActionReport

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

the class CreateJMSDestination method execute.

@Override
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;
    }
}
Also used : ActionReport(org.glassfish.api.ActionReport)

Example 22 with ActionReport

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

the class CreateJMSResource 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) {
    final ActionReport report = context.getActionReport();
    // Collection connPools = domain.getResources().getResources(ConnectorConnectionPool.class);
    if (resourceType == null) {
        report.setMessage(localStrings.getLocalString("create.jms.resource.noResourceType", "No Resoruce Type specified for JMS Resource."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (jndiName == null) {
        report.setMessage(localStrings.getLocalString("create.jms.resource.noJndiName", "No JNDI name specified for JMS Resource."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (!(resourceType.equals(TOPIC_CF) || resourceType.equals(QUEUE_CF) || resourceType.equals(UNIFIED_CF) || resourceType.equals(TOPIC) || resourceType.equals(QUEUE))) {
        report.setMessage(localStrings.getLocalString("create.jms.resource.InvalidResourceType", "Invalid Resource Type specified for JMS Resource."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    jndiNameForConnectionPool = jndiName + JNDINAME_APPENDER;
    if (force) {
        Resource res = null;
        if (resourceType.equals(TOPIC) || resourceType.equals(QUEUE))
            res = ConnectorsUtil.getResourceByName(domain.getResources(), AdminObjectResource.class, jndiName);
        else
            res = ConnectorsUtil.getResourceByName(domain.getResources(), ConnectorResource.class, jndiName);
        if (res != null) {
            ActionReport deleteReport = report.addSubActionsReport();
            ParameterMap parameters = new ParameterMap();
            parameters.set(DEFAULT_OPERAND, jndiName);
            parameters.set("target", target);
            commandRunner.getCommandInvocation("delete-jms-resource", deleteReport, context.getSubject()).parameters(parameters).execute();
            if (ActionReport.ExitCode.FAILURE.equals(deleteReport.getActionExitCode())) {
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
    }
    // Populate the JMS RA map
    populateJmsRAMap();
    /* Map MQ properties to Resource adapter properties */
    if (props != null) {
        Enumeration en = props.keys();
        while (en.hasMoreElements()) {
            String key = (String) en.nextElement();
            String raKey = getMappedName(key);
            if (raKey == null)
                raKey = key;
            props.put(raKey, (String) props.get(key));
            if (!raKey.equals(key))
                props.remove(key);
        }
    }
    ActionReport subReport = report.addSubActionsReport();
    if (resourceType.equals(TOPIC_CF) || resourceType.equals(QUEUE_CF) || resourceType.equals(UNIFIED_CF)) {
        ConnectorConnectionPool cpool = (ConnectorConnectionPool) ConnectorsUtil.getResourceByName(domain.getResources(), ConnectorConnectionPool.class, jndiNameForConnectionPool);
        boolean createdPool = false;
        // If pool is already existing, do not try to create it again
        if (cpool == null || !filterForTarget(jndiNameForConnectionPool)) {
            // Add connector-connection-pool.
            ParameterMap parameters = populateConnectionPoolParameters();
            commandRunner.getCommandInvocation("create-connector-connection-pool", subReport, context.getSubject()).parameters(parameters).execute();
            createdPool = true;
            if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
                report.setMessage(localStrings.getLocalString("create.jms.resource.cannotCreateConnectionPool", "Unable to create connection pool."));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
        ParameterMap params = populateConnectionResourceParameters();
        commandRunner.getCommandInvocation("create-connector-resource", subReport, context.getSubject()).parameters(params).execute();
        if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
            report.setMessage(localStrings.getLocalString("create.jms.resource.cannotCreateConnectorResource", "Unable to create connection resource."));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            // rollback the connection pool ONLY if we created it...
            if (createdPool) {
                ParameterMap paramsForRollback = new ParameterMap();
                paramsForRollback.set(DEFAULT_OPERAND, jndiNameForConnectionPool);
                commandRunner.getCommandInvocation("delete-connector-connection-pool", subReport, context.getSubject()).parameters(paramsForRollback).execute();
            }
            return;
        }
    } else if (resourceType.equals(TOPIC) || resourceType.equals(QUEUE)) {
        ParameterMap aoAttrList = new ParameterMap();
        try {
            // validate the provided properties and modify it if required.
            Properties properties = validateDestinationResourceProps(props, jndiName);
            // aoAttrList.put("property", properties);
            StringBuilder builder = new StringBuilder();
            for (java.util.Map.Entry<Object, Object> prop : properties.entrySet()) {
                builder.append(prop.getKey()).append("=").append(prop.getValue()).append(":");
            }
            String propString = builder.toString();
            int lastColonIndex = propString.lastIndexOf(":");
            if (lastColonIndex >= 0) {
                propString = propString.substring(0, lastColonIndex);
            }
            aoAttrList.set("property", propString);
        } catch (Exception e) {
            report.setMessage(localStrings.getLocalString("create.jms.resource.cannotCreateAdminObjectWithRootCause", "Unable to create admin object. Reason: " + e.getMessage(), e.getMessage()));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        // create admin object
        aoAttrList.set(DEFAULT_OPERAND, jndiName);
        aoAttrList.set("restype", resourceType);
        aoAttrList.set("raname", DEFAULT_JMS_ADAPTER);
        aoAttrList.set("target", target);
        if (enabled != null)
            aoAttrList.set("enabled", Boolean.toString(enabled));
        commandRunner.getCommandInvocation("create-admin-object", subReport, context.getSubject()).parameters(aoAttrList).execute();
        if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
            report.setMessage(localStrings.getLocalString("create.jms.resource.cannotCreateAdminObject", "Unable to create admin object."));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
    report.setActionExitCode(ec);
}
Also used : ConnectorConnectionPool(org.glassfish.connectors.config.ConnectorConnectionPool) Enumeration(java.util.Enumeration) AdminObjectResource(org.glassfish.connectors.config.AdminObjectResource) ConnectorResource(org.glassfish.connectors.config.ConnectorResource) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties)

Example 23 with ActionReport

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

the class ListJMSDestinations method execute.

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);
        // handleException(e);
        e.printStackTrace();
        report.setMessage(localStrings.getLocalString("list.jms.dest.fail", // + " " + e.getLocalizedMessage());
        "Unable to list JMS Destinations. Please ensure that the Message Queue Brokers are running"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
}
Also used : ActionReport(org.glassfish.api.ActionReport)

Example 24 with ActionReport

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

the class ListJMSResources 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
 */
@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    ArrayList<Map<String, String>> list = new ArrayList<>();
    Properties extraProperties = new Properties();
    Collection adminObjectResourceList = domain.getResources().getResources(AdminObjectResource.class);
    Collection connectorResourcesList = domain.getResources().getResources(ConnectorResource.class);
    Object[] connectorResources = connectorResourcesList.toArray();
    Object[] adminObjectResources = adminObjectResourceList.toArray();
    if (resourceType == null) {
        try {
            // list all JMS resources
            for (Object r : adminObjectResources) {
                AdminObjectResource adminObject = (AdminObjectResource) r;
                if (JMSRA.equals(adminObject.getResAdapter())) {
                    Map<String, String> m = new HashMap<>();
                    m.put("name", adminObject.getJndiName());
                    list.add(m);
                }
            }
            for (Object c : connectorResources) {
                ConnectorResource cr = (ConnectorResource) c;
                ConnectorConnectionPool cp = (ConnectorConnectionPool) ConnectorsUtil.getResourceByName(domain.getResources(), ConnectorConnectionPool.class, cr.getPoolName());
                if (cp != null && JMSRA.equals(cp.getResourceAdapterName())) {
                    Map<String, String> m = new HashMap<>();
                    m.put("name", cr.getJndiName());
                    list.add(m);
                }
            }
        } catch (Exception e) {
            report.setMessage(localStrings.getLocalString("list.jms.resources.fail", "Unable to list JMS Resources") + " " + e.getLocalizedMessage());
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setFailureCause(e);
            return;
        }
    } else {
        switch(resourceType) {
            case TOPIC_CF:
            case QUEUE_CF:
            case UNIFIED_CF:
                for (Object c : connectorResources) {
                    ConnectorResource cr = (ConnectorResource) c;
                    ConnectorConnectionPool cp = (ConnectorConnectionPool) ConnectorsUtil.getResourceByName(domain.getResources(), ConnectorConnectionPool.class, cr.getPoolName());
                    if (cp != null && resourceType.equals(cp.getConnectionDefinitionName()) && JMSRA.equals(cp.getResourceAdapterName())) {
                        Map<String, String> m = new HashMap<>();
                        m.put("name", cr.getJndiName());
                        list.add(m);
                    }
                }
                break;
            case TOPIC:
            case QUEUE:
                for (Object r : adminObjectResources) {
                    AdminObjectResource res = (AdminObjectResource) r;
                    if (resourceType.equals(res.getResType()) && JMSRA.equals(res.getResAdapter())) {
                        Map<String, String> m = new HashMap<>();
                        m.put("name", res.getJndiName());
                        list.add(m);
                    }
                }
                break;
        }
    }
    if (!list.isEmpty()) {
        List<Map<String, String>> resourceList = CommandTarget.DOMAIN.isValid(habitat, target) ? list : filterListForTarget(list);
        List<DefaultResourceProxy> drps = habitat.getAllServices(DefaultResourceProxy.class);
        for (Map<String, String> m : resourceList) {
            String jndiName = m.get("name");
            final ActionReport.MessagePart part = report.getTopMessagePart().addChild();
            part.setMessage(jndiName);
            String logicalName = DefaultResourceProxy.Util.getLogicalName(drps, jndiName);
            if (logicalName != null) {
                m.put("logical-jndi-name", logicalName);
            }
        }
        extraProperties.put("jmsResources", resourceList);
    }
    report.setExtraProperties(extraProperties);
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : ConnectorConnectionPool(org.glassfish.connectors.config.ConnectorConnectionPool) DefaultResourceProxy(org.glassfish.api.naming.DefaultResourceProxy) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) Collection(java.util.Collection) AdminObjectResource(org.glassfish.connectors.config.AdminObjectResource) HashMap(java.util.HashMap) Map(java.util.Map) ConnectorResource(org.glassfish.connectors.config.ConnectorResource)

Example 25 with ActionReport

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

the class ListJMSHosts 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) {
    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);
    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);
}
Also used : JmsService(com.sun.enterprise.connectors.jms.config.JmsService) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) com.sun.enterprise.config.serverbeans(com.sun.enterprise.config.serverbeans) JmsHost(com.sun.enterprise.connectors.jms.config.JmsHost)

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