Search in sources :

Example 1 with BrokerMQAddress

use of com.sun.messaging.jmq.jmsserver.core.BrokerMQAddress in project openmq by eclipse-ee4j.

the class ChangeClusterMasterBrokerHandler method handle.

/**
 * Handle the incomming administration message.
 *
 * @param con The Connection the message came in on.
 * @param cmd_msg The administration message
 * @param cmd_props The properties from the administration message
 */
@Override
public boolean handle(IMQConnection con, Packet cmd_msg, Hashtable cmd_props) {
    int status = Status.OK;
    String emsg = null;
    if (DEBUG) {
        logger.log(Logger.INFO, this.getClass().getName() + ": " + cmd_props);
    }
    boolean notificationOnly = false, fromJMSRA = false;
    String oldmb = (String) cmd_props.get(MessageType.JMQ_CLUSTER_OLD_MASTER_BROKER);
    String newmb = (String) cmd_props.get(MessageType.JMQ_CLUSTER_NEW_MASTER_BROKER);
    Object val = cmd_props.get(MessageType.JMQ_JMSRA_MANAGED_BROKER);
    if (val != null && Boolean.parseBoolean(val.toString())) {
        fromJMSRA = true;
    }
    val = cmd_props.get(MessageType.JMQ_JMSRA_NOTIFICATION_ONLY);
    if (val != null && Boolean.parseBoolean(val.toString()) && fromJMSRA && Globals.isJMSRAManagedBroker()) {
        notificationOnly = true;
    }
    logger.log(logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_ADMIN_RECEIVED_CMD, MessageType.getString(MessageType.CHANGE_CLUSTER_MASTER_BROKER) + "[" + MessageType.JMQ_CLUSTER_NEW_MASTER_BROKER + "=" + newmb + ", " + MessageType.JMQ_CLUSTER_OLD_MASTER_BROKER + "=" + oldmb + "]" + (fromJMSRA ? "JMSRA" : "") + (notificationOnly ? "(" + MessageType.JMQ_JMSRA_NOTIFICATION_ONLY + ")" : "")));
    if (Globals.getHAEnabled()) {
        status = Status.PRECONDITION_FAILED;
        emsg = rb.getKString(rb.E_OP_NOT_APPLY_TO_HA_BROKER, MessageType.getString(MessageType.CHANGE_CLUSTER_MASTER_BROKER));
        logger.log(Logger.ERROR, emsg);
        sendReply(status, emsg, con, cmd_msg);
        return true;
    }
    if (Globals.useSharedConfigRecord()) {
        status = Status.PRECONDITION_FAILED;
        emsg = rb.getKString(rb.E_OP_NOT_APPLY_NO_MASTER_BROKER_MODE, MessageType.getString(MessageType.CHANGE_CLUSTER_MASTER_BROKER));
        logger.log(Logger.ERROR, emsg);
        sendReply(status, emsg, con, cmd_msg);
        return true;
    }
    try {
        BrokerStateHandler.setExclusiveRequestLock(ExclusiveRequest.CHANGE_MASTER_BROKER);
    } catch (Throwable t) {
        status = Status.PRECONDITION_FAILED;
        if (t instanceof BrokerException) {
            status = ((BrokerException) t).getStatusCode();
        }
        emsg = MessageType.getString(MessageType.CHANGE_CLUSTER_MASTER_BROKER) + ": " + Status.getString(status) + " - " + t.getMessage();
        logger.log(Logger.ERROR, emsg);
        status = Status.PRECONDITION_FAILED;
        sendReply(status, emsg, con, cmd_msg);
        return true;
    }
    try {
        if (!Globals.dynamicChangeMasterBrokerEnabled()) {
            throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_NO_SUPPORT_DYNAMIC_CHANGE_MASTER_BROKER), Status.NOT_ALLOWED);
        }
        if (newmb == null) {
            throw new IllegalArgumentException("null " + MessageType.JMQ_CLUSTER_NEW_MASTER_BROKER);
        }
        if (!fromJMSRA && Globals.isJMSRAManagedBroker()) {
            throw new IllegalAccessException(Globals.getBrokerResources().getKString(BrokerResources.X_ADMIN_CHANGE_MASTER_NOT_FROM_JMSRA));
        }
        ClusterManager cm = Globals.getClusterManager();
        BrokerMQAddress self = (BrokerMQAddress) cm.getMQAddress();
        BrokerMQAddress master = (cm.getMasterBroker() == null ? null : (BrokerMQAddress) cm.getMasterBroker().getBrokerURL());
        BrokerMQAddress newmba = BrokerMQAddress.createAddress(newmb);
        BrokerMQAddress oldmba = null;
        if (oldmb != null) {
            oldmba = BrokerMQAddress.createAddress(oldmb);
        }
        if (notificationOnly) {
            if (master == null) {
                emsg = "IllegalStateException for notification " + MessageType.getString(MessageType.CHANGE_CLUSTER_MASTER_BROKER) + ": No master broker";
                logger.log(logger.ERROR, emsg);
                sendReply(Status.ERROR, emsg, con, cmd_msg);
                Broker.getBroker().exit(1, emsg, BrokerEvent.Type.ERROR);
                throw new IllegalStateException(emsg);
            }
            if (newmba.equals(self)) {
                if (!master.equals(self)) {
                    emsg = "IllegalStateException for notification " + MessageType.getString(MessageType.CHANGE_CLUSTER_MASTER_BROKER) + ": This broker, which has master broker " + master + ", is not the master broker as expected";
                    logger.log(logger.ERROR, emsg);
                    sendReply(Status.ERROR, emsg, con, cmd_msg);
                    Broker.getBroker().exit(1, emsg, BrokerEvent.Type.ERROR);
                    return true;
                }
            }
            if (oldmba != null && oldmba.equals(self)) {
                if (!master.equals(newmba)) {
                    emsg = "IllegalStateException for notification " + MessageType.getString(MessageType.CHANGE_CLUSTER_MASTER_BROKER) + ": This broker, which is the old master broker " + oldmba + ", does not have " + newmba + " as the master broker as expected";
                    logger.log(logger.ERROR, emsg);
                    sendReply(Status.ERROR, emsg, con, cmd_msg);
                    Broker.getBroker().exit(1, emsg, BrokerEvent.Type.ERROR);
                    return true;
                }
            }
            sendReply(Status.OK, null, con, cmd_msg);
            return true;
        }
        if (master == null) {
            throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_CLUSTER_NO_MASTER_BROKER_REJECT_CHANGE_MASTER), Status.PRECONDITION_FAILED);
        }
        if (newmba.equals(master)) {
            logger.log(logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_CLUSTER_CHANGE_MASTER_BROKER_SAME, newmba));
            sendReply(Status.OK, null, con, cmd_msg);
            return true;
        }
        if (oldmba == null) {
            oldmba = master;
        }
        if (!oldmba.equals(master)) {
            throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_CLUSTER_CHANGE_MASTER_BROKER_MISMATCH, oldmba.toString(), master), Status.PRECONDITION_FAILED);
        }
        if (!self.equals(master)) {
            if (!Globals.isJMSRAManagedBroker()) {
                throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_CLUSTER_THIS_BROKER_NOT_MASTER_BROKER_REJECT_CHANGE_MASTER, master.toString()), Status.NOT_ALLOWED);
            }
            sendReply(Status.OK, null, con, cmd_msg);
            return true;
        }
        Globals.getClusterBroadcast().changeMasterBroker(newmba, oldmba);
        sendReply(Status.OK, null, con, cmd_msg);
        return true;
    } catch (Exception e) {
        status = Status.ERROR;
        emsg = e.getMessage();
        if (e instanceof BrokerException) {
            status = ((BrokerException) e).getStatusCode();
            emsg = emsg + "[" + Status.getString(status) + "]";
        }
        logger.logStack(Logger.ERROR, emsg, e);
        sendReply(status, emsg, con, cmd_msg);
        return true;
    } finally {
        BrokerStateHandler.unsetExclusiveRequestLock(ExclusiveRequest.CHANGE_MASTER_BROKER);
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ClusterManager(com.sun.messaging.jmq.jmsserver.cluster.api.ClusterManager) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) BrokerMQAddress(com.sun.messaging.jmq.jmsserver.core.BrokerMQAddress)

Example 2 with BrokerMQAddress

use of com.sun.messaging.jmq.jmsserver.core.BrokerMQAddress in project openmq by eclipse-ee4j.

the class ClusterImpl method checkConfigServer.

protected boolean checkConfigServer(BrokerAddressImpl b) {
    synchronized (configServerLock) {
        if (configServerResolved) {
            // Alredy resolved...
            return true;
        }
        if (configServer == null) {
            // Illegal config, reject cluster connections.
            return false;
        }
        BrokerMQAddress key = b.getMQAddress();
        if (key.equals(configServer.getMQAddress())) {
            configServer = b;
            configServerResolved = true;
            if (warningTask != null) {
                warningTask.cancel();
                warningTask = null;
            }
        }
        return configServerResolved;
    }
}
Also used : BrokerMQAddress(com.sun.messaging.jmq.jmsserver.core.BrokerMQAddress)

Example 3 with BrokerMQAddress

use of com.sun.messaging.jmq.jmsserver.core.BrokerMQAddress in project openmq by eclipse-ee4j.

the class ClusterImpl method getDebugState.

@Override
public Hashtable getDebugState() {
    Hashtable ht = new Hashtable();
    ht.put("self", self.toString());
    BrokerAddressImpl cs = configServer;
    if (cs != null) {
        ht.put("configServer[masterbroker]", cs.toString());
        ht.put("configServerResolved", Boolean.valueOf(configServerResolved));
    }
    ArrayList clist = null;
    synchronized (connectList) {
        clist = new ArrayList(connectList.keySet());
    }
    ht.put("connectListCount", String.valueOf(clist.size()));
    Iterator itr = clist.iterator();
    while (itr.hasNext()) {
        BrokerMQAddress key = (BrokerMQAddress) itr.next();
        BrokerLink link = (BrokerLink) connectList.get(key);
        if (link != null) {
            ht.put(key.toString(), link.toString());
        }
    }
    return ht;
}
Also used : BrokerMQAddress(com.sun.messaging.jmq.jmsserver.core.BrokerMQAddress)

Example 4 with BrokerMQAddress

use of com.sun.messaging.jmq.jmsserver.core.BrokerMQAddress in project openmq by eclipse-ee4j.

the class ClusterImpl method brokerAdded.

/**
 * Called when a new broker has been added.
 *
 * @param broker the new broker added.
 */
@Override
public void brokerAdded(ClusteredBroker broker, UID uid) {
    if (!broker.isConfigBroker()) {
        if (DEBUG) {
            logger.log(logger.INFO, "ClusterImpl:brokerAdded: Ignore dynamic broker " + broker);
        }
        return;
    }
    BrokerMQAddress key = (BrokerMQAddress) broker.getBrokerURL();
    if (!key.equals(self.getMQAddress()) && !connectList.containsKey(key)) {
        boolean newLink = false;
        // XXX 1
        BrokerLink link = searchBrokerList(key);
        if (link == null) {
            BrokerAddressImpl b = null;
            try {
                b = new BrokerAddressImpl(key, null, Globals.getHAEnabled(), broker.getBrokerName());
                link = new BrokerLink(self, b, this);
                newLink = true;
            } catch (Exception e) {
                logger.logStack(logger.ERROR, br.getKString(br.W_CLUSTER_AUTOCONNECT_ADD_FAILED, broker), e);
                return;
            }
        }
        // XXX 2
        link.setAutoConnect(true);
        connectList.put(key, link);
        if (DEBUG) {
            logger.log(Logger.INFO, "ClusterImpl: Added link to connectList - " + link);
        }
        if (newLink) {
            link.start();
        }
        return;
    }
    if (DEBUG) {
        logger.log(logger.INFO, "Broker link for " + key + " (" + broker + ") already exist");
    }
}
Also used : LoopbackAddressException(com.sun.messaging.jmq.jmsserver.util.LoopbackAddressException) LoadException(com.sun.messaging.jmq.jmsserver.persist.api.LoadException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) BrokerMQAddress(com.sun.messaging.jmq.jmsserver.core.BrokerMQAddress)

Example 5 with BrokerMQAddress

use of com.sun.messaging.jmq.jmsserver.core.BrokerMQAddress in project openmq by eclipse-ee4j.

the class ClusterImpl method initBrokerList.

/**
 * Processes the configuration and command line info.
 *
 * Creates 'connectList' : A mapping of Remote BrokerAddress <--> BrokerLink objects for all the 'autoConnect' links
 * that are initiated by this broker.
 */
private void initBrokerList() throws BrokerException {
    connectList = Collections.synchronizedMap(new HashMap());
    BrokerMQAddress selfKey = self.getMQAddress();
    if (DEBUG) {
        logger.log(Logger.INFO, "ClusterImpl:initBrokerList. selfKey =" + selfKey);
    }
    ClusteredBroker cb = null;
    BrokerAddressImpl b = null;
    BrokerLink link = null;
    Iterator itr = clsmgr.getConfigBrokers();
    int i = 0;
    while (itr.hasNext()) {
        cb = (ClusteredBroker) itr.next();
        try {
            b = new BrokerAddressImpl((BrokerMQAddress) cb.getBrokerURL(), null, Globals.getHAEnabled(), cb.getBrokerName());
        } catch (Exception e) {
            throw new BrokerException(e.getMessage(), e);
        }
        BrokerMQAddress key = b.getMQAddress();
        if (!key.equals(selfKey)) {
            link = new BrokerLink(self, b, this);
            link.setAutoConnect(true);
            connectList.put(key, link);
            i++;
            if (DEBUG) {
                logger.log(Logger.INFO, "ClusterImpl: Added to connectList: key=" + key + ", link=" + link + " (" + i + ")");
            }
        }
    }
    brokerList = new HashMap();
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) LoopbackAddressException(com.sun.messaging.jmq.jmsserver.util.LoopbackAddressException) LoadException(com.sun.messaging.jmq.jmsserver.persist.api.LoadException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) BrokerMQAddress(com.sun.messaging.jmq.jmsserver.core.BrokerMQAddress)

Aggregations

BrokerMQAddress (com.sun.messaging.jmq.jmsserver.core.BrokerMQAddress)16 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)7 LoadException (com.sun.messaging.jmq.jmsserver.persist.api.LoadException)4 LoopbackAddressException (com.sun.messaging.jmq.jmsserver.util.LoopbackAddressException)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 ClusterManager (com.sun.messaging.jmq.jmsserver.cluster.api.ClusterManager)3 Iterator (java.util.Iterator)3 ClusteredBroker (com.sun.messaging.jmq.jmsserver.cluster.api.ClusteredBroker)2 OperationNotAllowedException (com.sun.messaging.jmq.jmsserver.util.OperationNotAllowedException)2 UID (com.sun.messaging.jmq.util.UID)2 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)1 BrokerStateHandler (com.sun.messaging.jmq.jmsserver.BrokerStateHandler)1 PropertyUpdateException (com.sun.messaging.jmq.jmsserver.config.PropertyUpdateException)1 BrokerAddress (com.sun.messaging.jmq.jmsserver.core.BrokerAddress)1 DestinationList (com.sun.messaging.jmq.jmsserver.core.DestinationList)1 BrokerResources (com.sun.messaging.jmq.jmsserver.resources.BrokerResources)1 IMQBasicConnection (com.sun.messaging.jmq.jmsserver.service.imq.IMQBasicConnection)1 IMQConnection (com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection)1 Logger (com.sun.messaging.jmq.util.log.Logger)1 InetAddress (java.net.InetAddress)1