Search in sources :

Example 6 with HeartbeatPayload

use of org.apache.nifi.cluster.protocol.HeartbeatPayload in project nifi by apache.

the class TestJaxbProtocolUtils method testRoundTripHeartbeat.

@Test
public void testRoundTripHeartbeat() throws JAXBException {
    final NodeIdentifier nodeId = new NodeIdentifier("id", "localhost", 8000, "localhost", 8001, "localhost", 8002, 8003, true);
    final NodeConnectionStatus nodeStatus = new NodeConnectionStatus(nodeId, DisconnectionCode.NOT_YET_CONNECTED);
    final HeartbeatPayload payload = new HeartbeatPayload();
    payload.setActiveThreadCount(1);
    payload.setSystemStartTime(System.currentTimeMillis());
    payload.setTotalFlowFileBytes(83L);
    payload.setTotalFlowFileCount(4);
    final List<NodeConnectionStatus> clusterStatus = Collections.singletonList(nodeStatus);
    payload.setClusterStatus(clusterStatus);
    final Heartbeat heartbeat = new Heartbeat(nodeId, nodeStatus, payload.marshal());
    final HeartbeatMessage msg = new HeartbeatMessage();
    msg.setHeartbeat(heartbeat);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    JaxbProtocolUtils.JAXB_CONTEXT.createMarshaller().marshal(msg, baos);
    final Object unmarshalled = JaxbProtocolUtils.JAXB_CONTEXT.createUnmarshaller().unmarshal(new ByteArrayInputStream(baos.toByteArray()));
    assertTrue(unmarshalled instanceof HeartbeatMessage);
}
Also used : HeartbeatMessage(org.apache.nifi.cluster.protocol.message.HeartbeatMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Heartbeat(org.apache.nifi.cluster.protocol.Heartbeat) HeartbeatPayload(org.apache.nifi.cluster.protocol.HeartbeatPayload) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NodeConnectionStatus(org.apache.nifi.cluster.coordination.node.NodeConnectionStatus) Test(org.junit.Test)

Example 7 with HeartbeatPayload

use of org.apache.nifi.cluster.protocol.HeartbeatPayload in project nifi by apache.

the class StandardNodeHeartbeat method fromHeartbeatMessage.

public static StandardNodeHeartbeat fromHeartbeatMessage(final HeartbeatMessage message, final long timestamp) {
    final Heartbeat heartbeat = message.getHeartbeat();
    final HeartbeatPayload payload = HeartbeatPayload.unmarshal(heartbeat.getPayload());
    return new StandardNodeHeartbeat(heartbeat.getNodeIdentifier(), timestamp, heartbeat.getConnectionStatus(), (int) payload.getTotalFlowFileCount(), payload.getTotalFlowFileBytes(), payload.getActiveThreadCount(), payload.getSystemStartTime());
}
Also used : Heartbeat(org.apache.nifi.cluster.protocol.Heartbeat) HeartbeatPayload(org.apache.nifi.cluster.protocol.HeartbeatPayload)

Example 8 with HeartbeatPayload

use of org.apache.nifi.cluster.protocol.HeartbeatPayload in project nifi by apache.

the class FlowController method createHeartbeatMessage.

HeartbeatMessage createHeartbeatMessage() {
    try {
        HeartbeatBean bean = heartbeatBeanRef.get();
        if (bean == null) {
            readLock.lock();
            try {
                bean = new HeartbeatBean(getGroup(getRootGroupId()), isPrimary());
            } finally {
                readLock.unlock();
            }
        }
        // create heartbeat payload
        final HeartbeatPayload hbPayload = new HeartbeatPayload();
        hbPayload.setSystemStartTime(systemStartTime);
        hbPayload.setActiveThreadCount(getActiveThreadCount());
        final QueueSize queueSize = getTotalFlowFileCount(bean.getRootGroup());
        hbPayload.setTotalFlowFileCount(queueSize.getObjectCount());
        hbPayload.setTotalFlowFileBytes(queueSize.getByteCount());
        hbPayload.setClusterStatus(clusterCoordinator.getConnectionStatuses());
        // create heartbeat message
        final NodeIdentifier nodeId = getNodeId();
        if (nodeId == null) {
            LOG.warn("Cannot create Heartbeat Message because node's identifier is not known at this time");
            return null;
        }
        final Heartbeat heartbeat = new Heartbeat(nodeId, connectionStatus, hbPayload.marshal());
        final HeartbeatMessage message = new HeartbeatMessage();
        message.setHeartbeat(heartbeat);
        LOG.debug("Generated heartbeat");
        return message;
    } catch (final Throwable ex) {
        LOG.warn("Failed to create heartbeat due to: " + ex, ex);
        return null;
    }
}
Also used : QueueSize(org.apache.nifi.controller.queue.QueueSize) HeartbeatMessage(org.apache.nifi.cluster.protocol.message.HeartbeatMessage) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Heartbeat(org.apache.nifi.cluster.protocol.Heartbeat) HeartbeatPayload(org.apache.nifi.cluster.protocol.HeartbeatPayload)

Aggregations

HeartbeatPayload (org.apache.nifi.cluster.protocol.HeartbeatPayload)8 Heartbeat (org.apache.nifi.cluster.protocol.Heartbeat)4 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)4 HeartbeatMessage (org.apache.nifi.cluster.protocol.message.HeartbeatMessage)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 NodeConnectionStatus (org.apache.nifi.cluster.coordination.node.NodeConnectionStatus)3 Test (org.junit.Test)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 HeartbeatResponseMessage (org.apache.nifi.cluster.protocol.message.HeartbeatResponseMessage)2 IOException (java.io.IOException)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 ClusterCoordinator (org.apache.nifi.cluster.coordination.ClusterCoordinator)1 ClusterRoles (org.apache.nifi.cluster.coordination.node.ClusterRoles)1