Search in sources :

Example 1 with ParameterMap

use of org.glassfish.api.admin.ParameterMap 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)

Example 2 with ParameterMap

use of org.glassfish.api.admin.ParameterMap in project Payara by payara.

the class CreateIiopListenerTest method tearDown.

@After
public void tearDown() throws TransactionFailure {
    ConfigSupport.apply(new SingleConfigCode<IiopService>() {

        public Object run(IiopService param) throws PropertyVetoException, TransactionFailure {
            List<IiopListener> listenerList = param.getIiopListener();
            for (IiopListener listener : listenerList) {
                String currListenerId = listener.getId();
                if (currListenerId != null && currListenerId.equals("iiop_1")) {
                    listenerList.remove(listener);
                    break;
                }
            }
            return listenerList;
        }
    }, iiopService);
    parameters = new ParameterMap();
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) IiopListener(org.glassfish.orb.admin.config.IiopListener) IiopService(org.glassfish.orb.admin.config.IiopService) List(java.util.List) ParameterMap(org.glassfish.api.admin.ParameterMap) After(org.junit.After)

Example 3 with ParameterMap

use of org.glassfish.api.admin.ParameterMap in project Payara by payara.

the class ListIiopListenersTest method testExecuteSuccessListNoListener.

/**
 * Test of execute method, of class ListIiopListener.
 * list-iiop-listeners
 */
@Test
public void testExecuteSuccessListNoListener() {
    parameters = new ParameterMap();
    ListIiopListeners listCommand = services.getService(ListIiopListeners.class);
    cr.getCommandInvocation("list-iiop-listeners", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
    CreateIiopListenerTest.checkActionReport(context.getActionReport());
    List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
    assertEquals(origNum, list.size());
    List<String> listStr = new ArrayList<String>();
    for (MessagePart mp : list) {
        listStr.add(mp.getMessage());
    }
    assertFalse(listStr.contains("listener"));
}
Also used : MessagePart(org.glassfish.api.ActionReport.MessagePart) ArrayList(java.util.ArrayList) ParameterMap(org.glassfish.api.admin.ParameterMap) Test(org.junit.Test)

Example 4 with ParameterMap

use of org.glassfish.api.admin.ParameterMap in project Payara by payara.

the class CreateJMSHost 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());
    }
    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);
    // 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 {
                report.setMessage(localStrings.getLocalString("create.jms.host.duplicate", "A JMS Host named {0} already exists.", jmsHostName));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<JmsService>() {

            public Object run(JmsService param) throws PropertyVetoException, TransactionFailure {
                // TODO: need a way to create a JmsHost instance
                JmsHost jmsHost = param.createChild(JmsHost.class);
                jmsHost.setAdminPassword(mqpassword);
                jmsHost.setAdminUserName(mquser);
                jmsHost.setName(jmsHostName);
                jmsHost.setHost(mqhost);
                jmsHost.setPort(mqport);
                if (props != null) {
                    for (Map.Entry e : props.entrySet()) {
                        Property prop = jmsHost.createChild(Property.class);
                        prop.setName((String) e.getKey());
                        prop.setValue((String) e.getValue());
                        jmsHost.getProperty().add(prop);
                    }
                }
                param.getJmsHost().add(jmsHost);
                return jmsHost;
            }
        }, jmsservice);
    } catch (TransactionFailure tfe) {
        report.setMessage(localStrings.getLocalString("create.jms.host.fail", "Unable to create jms host {0}.", jmsHostName) + " " + tfe.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(tfe);
    }
    report.setMessage(localStrings.getLocalString("create.jms.host.success", "Jms Host {0} created.", jmsHostName));
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) JmsService(com.sun.enterprise.connectors.jms.config.JmsService) ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) com.sun.enterprise.config.serverbeans(com.sun.enterprise.config.serverbeans) PropertyVetoException(java.beans.PropertyVetoException) JmsHost(com.sun.enterprise.connectors.jms.config.JmsHost) Property(org.jvnet.hk2.config.types.Property)

Example 5 with ParameterMap

use of org.glassfish.api.admin.ParameterMap in project Payara by payara.

the class SetRestMonitoringConfigurationCommand method messageSecurityProviderExists.

private boolean messageSecurityProviderExists(ActionReport subActionReport, Subject subject) {
    boolean exists = false;
    CommandInvocation invocation = commandRunner.getCommandInvocation("list-message-security-providers", subActionReport, subject, false);
    ParameterMap parameters = new ParameterMap();
    parameters.add("layer", "HttpServlet");
    invocation.parameters(parameters).execute();
    for (MessagePart message : subActionReport.getTopMessagePart().getChildren()) {
        if (message.getMessage().equals(AUTH_MODULE_NAME)) {
            exists = true;
            break;
        }
    }
    return exists;
}
Also used : MessagePart(org.glassfish.api.ActionReport.MessagePart) ParameterMap(org.glassfish.api.admin.ParameterMap) CommandInvocation(org.glassfish.api.admin.CommandRunner.CommandInvocation)

Aggregations

ParameterMap (org.glassfish.api.admin.ParameterMap)149 ActionReport (org.glassfish.api.ActionReport)68 CommandRunner (org.glassfish.api.admin.CommandRunner)37 Test (org.junit.Test)25 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)24 Map (java.util.Map)20 PropsFileActionReporter (com.sun.enterprise.v3.common.PropsFileActionReporter)19 AdminCommandContextImpl (org.glassfish.api.admin.AdminCommandContextImpl)18 List (java.util.List)16 ArrayList (java.util.ArrayList)15 CommandRunner (org.glassfish.embeddable.CommandRunner)15 IOException (java.io.IOException)14 ConfigApiTest (org.glassfish.tests.utils.ConfigApiTest)13 Before (org.junit.Before)13 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)13 CommandException (org.glassfish.api.admin.CommandException)12 File (java.io.File)11 MessagePart (org.glassfish.api.ActionReport.MessagePart)11 Resource (com.sun.enterprise.config.serverbeans.Resource)10 Logger (java.util.logging.Logger)9