Search in sources :

Example 11 with HBMessage

use of org.apache.storm.generated.HBMessage in project storm by apache.

the class PacemakerServer method received.

public void received(Object mesg, String remote, Channel channel) throws InterruptedException {
    cleanPipeline(channel);
    boolean authenticated = (authMethod == ThriftNettyServerCodec.AuthMethod.NONE) || authenticated_channels.contains(channel);
    HBMessage m = (HBMessage) mesg;
    LOG.debug("received message. Passing to handler. {} : {} : {}", handler.toString(), m.toString(), channel.toString());
    HBMessage response = handler.handleMessage(m, authenticated);
    if (response != null) {
        LOG.debug("Got Response from handler: {}", response);
        channel.write(response);
    } else {
        LOG.info("Got null response from handler handling message: {}", m);
    }
}
Also used : HBMessage(org.apache.storm.generated.HBMessage)

Example 12 with HBMessage

use of org.apache.storm.generated.HBMessage in project storm by apache.

the class ThriftEncoder method encode.

@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) {
    if (msg == null) {
        return null;
    }
    LOG.debug("Trying to encode: " + msg.getClass().toString() + " : " + msg.toString());
    HBMessage m;
    if (msg instanceof INettySerializable) {
        INettySerializable nettyMsg = (INettySerializable) msg;
        HBServerMessageType type;
        if (msg instanceof ControlMessage) {
            type = HBServerMessageType.CONTROL_MESSAGE;
        } else if (msg instanceof SaslMessageToken) {
            type = HBServerMessageType.SASL_MESSAGE_TOKEN;
        } else {
            LOG.error("Didn't recognise INettySerializable: " + nettyMsg.toString());
            throw new RuntimeException("Unrecognized INettySerializable.");
        }
        m = encodeNettySerializable(nettyMsg, type);
    } else {
        m = (HBMessage) msg;
    }
    try {
        byte[] serialized = Utils.thriftSerialize(m);
        ChannelBuffer ret = ChannelBuffers.directBuffer(serialized.length + 4);
        ret.writeInt(serialized.length);
        ret.writeBytes(serialized);
        return ret;
    } catch (RuntimeException e) {
        LOG.error("Failed to serialize.", e);
        throw e;
    }
}
Also used : HBServerMessageType(org.apache.storm.generated.HBServerMessageType) SaslMessageToken(org.apache.storm.messaging.netty.SaslMessageToken) INettySerializable(org.apache.storm.messaging.netty.INettySerializable) HBMessage(org.apache.storm.generated.HBMessage) ControlMessage(org.apache.storm.messaging.netty.ControlMessage) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 13 with HBMessage

use of org.apache.storm.generated.HBMessage in project storm by apache.

the class Pacemaker method getAllNodesForPath.

private HBMessage getAllNodesForPath(String path, boolean authenticated) {
    LOG.debug("List all nodes for path {}", path);
    if (authenticated) {
        Set<String> pulseIds = new HashSet<>();
        for (String key : heartbeats.keySet()) {
            String[] replaceStr = key.replaceFirst(path, "").split("/");
            String trimmed = null;
            for (String str : replaceStr) {
                if (!str.equals("")) {
                    trimmed = str;
                    break;
                }
            }
            if (trimmed != null && key.indexOf(path) == 0) {
                pulseIds.add(trimmed);
            }
        }
        HBMessageData hbMessageData = HBMessageData.nodes(new HBNodes(new ArrayList(pulseIds)));
        return new HBMessage(HBServerMessageType.GET_ALL_NODES_FOR_PATH_RESPONSE, hbMessageData);
    } else {
        return notAuthorized();
    }
}
Also used : HBNodes(org.apache.storm.generated.HBNodes) ArrayList(java.util.ArrayList) HBMessageData(org.apache.storm.generated.HBMessageData) HBMessage(org.apache.storm.generated.HBMessage) HashSet(java.util.HashSet)

Example 14 with HBMessage

use of org.apache.storm.generated.HBMessage in project storm by apache.

the class Pacemaker method pathExists.

private HBMessage pathExists(String path, boolean authenticated) {
    HBMessage response = null;
    if (authenticated) {
        boolean itDoes = heartbeats.containsKey(path);
        LOG.debug("Checking if path [ {} ] exists... {} .", path, itDoes);
        response = new HBMessage(HBServerMessageType.EXISTS_RESPONSE, HBMessageData.boolval(itDoes));
    } else {
        response = notAuthorized();
    }
    return response;
}
Also used : HBMessage(org.apache.storm.generated.HBMessage)

Example 15 with HBMessage

use of org.apache.storm.generated.HBMessage in project storm by apache.

the class PacemakerClient method gotMessage.

public void gotMessage(HBMessage m) {
    int message_id = m.get_message_id();
    if (message_id >= 0 && message_id < maxPending) {
        LOG.debug("Pacemaker client got message: {}", m.toString());
        HBMessage request = messages[message_id];
        if (request == null) {
            LOG.debug("No message for slot: {}", Integer.toString(message_id));
        } else {
            synchronized (request) {
                messages[message_id] = m;
                request.notifyAll();
                availableMessageSlots.add(message_id);
            }
        }
    } else {
        LOG.error("Got Message with bad id: {}", m.toString());
    }
}
Also used : HBMessage(org.apache.storm.generated.HBMessage)

Aggregations

HBMessage (org.apache.storm.generated.HBMessage)22 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)9 Pacemaker (org.apache.storm.pacemaker.Pacemaker)9 Test (org.junit.Test)9 HBPulse (org.apache.storm.generated.HBPulse)5 HBMessageData (org.apache.storm.generated.HBMessageData)3 ArrayList (java.util.ArrayList)2 ControlMessage (org.apache.storm.messaging.netty.ControlMessage)2 SaslMessageToken (org.apache.storm.messaging.netty.SaslMessageToken)2 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 HBNodes (org.apache.storm.generated.HBNodes)1 HBServerMessageType (org.apache.storm.generated.HBServerMessageType)1 INettySerializable (org.apache.storm.messaging.netty.INettySerializable)1 Channel (org.jboss.netty.channel.Channel)1