Search in sources :

Example 21 with JmsService

use of com.sun.enterprise.connectors.jms.config.JmsService in project Payara by payara.

the class JMSPing 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();
    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();
                   } */
    String defaultJmshostStr = jmsservice.getDefaultJmsHost();
    JmsHost defaultJmsHost = null;
    for (JmsHost jmshost : jmsservice.getJmsHost()) {
        if (jmshost.getName().equals(defaultJmshostStr)) {
            defaultJmsHost = jmshost;
        }
    }
    if (defaultJmsHost == null) {
        report.setMessage(localStrings.getLocalString("jms-ping.noDefaultJMSHost", "Unable to PING the JMS Broker as no Default JMS Host is configured on the DAS"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    String tmpJMSResource = "test_jms_adapter";
    ActionReport subReport = report.addSubActionsReport();
    createJMSResource(defaultJmsHost, subReport, tmpJMSResource, context.getSubject());
    if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
        report.setMessage(localStrings.getLocalString("jms-ping.cannotCreateJMSResource", "Unable to create a temporary Connection Factory to the JMS Host"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        boolean value = pingConnectionPool(tmpJMSResource + JNDINAME_APPENDER);
        if (!value) {
            report.setMessage(localStrings.getLocalString("jms-ping.pingConnectionPoolFailed", "Pinging to the JMS Host failed."));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        } else {
            report.setMessage(localStrings.getLocalString("jms-ping.pingConnectionPoolSuccess", "JMS-ping command executed successfully"));
            report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        }
    } catch (ResourceException e) {
        report.setMessage(localStrings.getLocalString("jms-ping.pingConnectionPoolException", "An exception occured while trying to ping the JMS Host.", e.getMessage()));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
    deleteJMSResource(subReport, tmpJMSResource, context.getSubject());
    if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
        report.setMessage(localStrings.getLocalString("jms-ping.cannotdeleteJMSResource", "Unable to delete the temporary JMS Resource " + tmpJMSResource + ". Please delete this manually.", tmpJMSResource));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) JmsService(com.sun.enterprise.connectors.jms.config.JmsService) ResourceException(javax.resource.ResourceException) ActionReport(org.glassfish.api.ActionReport) JmsHost(com.sun.enterprise.connectors.jms.config.JmsHost) Cluster(com.sun.enterprise.config.serverbeans.Cluster)

Example 22 with JmsService

use of com.sun.enterprise.connectors.jms.config.JmsService in project Payara by payara.

the class ChangeMasterBrokerCommand 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();
    final String newMB = newMasterBroker;
    Server newMBServer = domain.getServerNamed(newMasterBroker);
    if (newMBServer == null) {
        report.setMessage(localStrings.getLocalString("change.master.broker.invalidServerName", "Invalid server name specified. There is no server by this name"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // domain.getClusterNamed(clusterName);
    Cluster cluster = newMBServer.getCluster();
    if (cluster == null) {
        report.setMessage(localStrings.getLocalString("change.master.broker.invalidClusterName", "The server specified is not associated with a cluster. The server assocaited with the master broker has to be a part of the cluster"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    /*if(!cluster.getName().equals(newMBServer.getCluster().getName()))
        {
            report.setMessage(localStrings.getLocalString("configure.jms.cluster.invalidClusterName",
                            "{0} does not belong to the specified cluster", newMasterBroker));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        } */
    Nodes nodes = domain.getNodes();
    config = domain.getConfigNamed(cluster.getConfigRef());
    JmsService jmsservice = config.getExtensionByType(JmsService.class);
    Server oldMBServer = null;
    // Else use the first configured instance in the cluster list
    if (jmsservice.getMasterBroker() != null) {
        oldMBServer = domain.getServerNamed(jmsservice.getMasterBroker());
    } else {
        List<Server> serverList = cluster.getInstances();
        // if(serverList == null || serverList.size() == 0){
        // report.setMessage(localStrings.getLocalString("change.master.broker.invalidCluster",
        // "No servers configured in cluster {0}", clusterName));
        // report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        // return;
        // }
        oldMBServer = serverList.get(0);
    }
    String oldMasterBrokerPort = JmsRaUtil.getJMSPropertyValue(oldMBServer);
    if (oldMasterBrokerPort == null) {
        SystemProperty sp = config.getSystemProperty("JMS_PROVIDER_PORT");
        if (sp != null)
            oldMasterBrokerPort = sp.getValue();
    }
    if (oldMasterBrokerPort == null)
        oldMasterBrokerPort = getDefaultJmsHost(jmsservice).getPort();
    String oldMasterBrokerHost = nodes.getNode(oldMBServer.getNodeRef()).getNodeHost();
    String newMasterBrokerPort = JmsRaUtil.getJMSPropertyValue(newMBServer);
    if (newMasterBrokerPort == null)
        newMasterBrokerPort = getDefaultJmsHost(jmsservice).getPort();
    String newMasterBrokerHost = nodes.getNode(newMBServer.getNodeRef()).getNodeHost();
    String oldMasterBroker = oldMasterBrokerHost + ":" + oldMasterBrokerPort;
    String newMasterBroker = newMasterBrokerHost + ":" + newMasterBrokerPort;
    // System.out.println("1: IN deleteinstanceCheck supplimental oldMasterBroker = " + oldMasterBroker + " newmasterBroker " + newMasterBroker);
    try {
        CompositeData result = updateMasterBroker(oldMBServer.getName(), oldMasterBroker, newMasterBroker);
        boolean success = ((Boolean) result.get("Success")).booleanValue();
        if (!success) {
            int statusCode = ((Integer) result.get("StatusCode")).intValue();
            String detailMessage = (String) result.get("DetailMessage");
            String msg = " " + detailMessage;
            if (BrokerStatusCode.BAD_REQUEST.getCode() == statusCode || BrokerStatusCode.NOT_ALLOWED.getCode() == statusCode || BrokerStatusCode.UNAVAILABLE.getCode() == statusCode || BrokerStatusCode.PRECONDITION_FAILED.getCode() == statusCode) {
                msg = localStrings.getLocalString("change.master.broker.errorMsg", "{0}. But it didn't affect current master broker configuration.", msg);
            } else {
                msg = msg + ". " + localStrings.getLocalString("change.master.broker.otherErrorMsg", "The cluster should be shutdown and configured with the new master broker then restarts.");
            }
            report.setMessage(localStrings.getLocalString("change.master.broker.CannotChangeMB", "Unable to change master broker.{0}", msg));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    } catch (Exception e) {
        report.setMessage(localStrings.getLocalString("change.master.broker.CannotChangeMB", "Unable to change master broker.{0}", ""));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        /*String setCommandStr = cluster.getConfigRef() + "." + "jms-service" + "." +"master-Broker";
            ParameterMap parameters = new ParameterMap();
            parameters.set(setCommandStr, newMB );

            ActionReport subReport = report.addSubActionsReport();
	        commandRunner.getCommandInvocation("set", subReport, context.getSubject()).parameters(parameters).execute();

              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;
              }*/
        ConfigSupport.apply(new SingleConfigCode<JmsService>() {

            public Object run(JmsService param) throws PropertyVetoException, TransactionFailure {
                param.setMasterBroker(newMB);
                return param;
            }
        }, jmsservice);
    } catch (Exception tfe) {
        report.setMessage(localStrings.getLocalString("change.master.broker.fail", "Unable to update the domain.xml with the new master broker") + " " + tfe.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(tfe);
    }
    report.setMessage(localStrings.getLocalString("change.master.broker.success", "Master broker change has executed successfully for Cluster {0}.", cluster.getName()));
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) JmsService(com.sun.enterprise.connectors.jms.config.JmsService) CompositeData(javax.management.openmbean.CompositeData) Cluster(com.sun.enterprise.config.serverbeans.Cluster) ActionReport(org.glassfish.api.ActionReport) PropertyVetoException(java.beans.PropertyVetoException) PropertyVetoException(java.beans.PropertyVetoException)

Aggregations

JmsService (com.sun.enterprise.connectors.jms.config.JmsService)22 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)10 JmsHost (com.sun.enterprise.connectors.jms.config.JmsHost)10 PrivilegedActionException (java.security.PrivilegedActionException)6 ResourceAdapterInternalException (javax.resource.spi.ResourceAdapterInternalException)6 ActionReport (org.glassfish.api.ActionReport)6 PropertyVetoException (java.beans.PropertyVetoException)5 URISyntaxException (java.net.URISyntaxException)5 ExecutionException (java.util.concurrent.ExecutionException)5 MultiException (org.glassfish.hk2.api.MultiException)5 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)4 com.sun.enterprise.config.serverbeans (com.sun.enterprise.config.serverbeans)3 Cluster (com.sun.enterprise.config.serverbeans.Cluster)3 Server (com.sun.enterprise.config.serverbeans.Server)3 ServerContext (org.glassfish.internal.api.ServerContext)3 Domain (com.sun.enterprise.config.serverbeans.Domain)2 JmsAvailability (com.sun.enterprise.connectors.jms.config.JmsAvailability)2 ActiveJmsResourceAdapter (com.sun.enterprise.connectors.jms.system.ActiveJmsResourceAdapter)2 ConnectorConfigProperty (com.sun.enterprise.deployment.ConnectorConfigProperty)2 ConnectorDescriptor (com.sun.enterprise.deployment.ConnectorDescriptor)2