Search in sources :

Example 1 with ClusterWorkloadRequestMessage

use of org.apache.nifi.cluster.protocol.message.ClusterWorkloadRequestMessage in project nifi by apache.

the class NodeClusterCoordinator method getClusterWorkload.

@Override
public Map<NodeIdentifier, NodeWorkload> getClusterWorkload() throws IOException {
    final ClusterWorkloadRequestMessage request = new ClusterWorkloadRequestMessage();
    final ClusterWorkloadResponseMessage response = nodeProtocolSender.clusterWorkload(request);
    return response.getNodeWorkloads();
}
Also used : ClusterWorkloadResponseMessage(org.apache.nifi.cluster.protocol.message.ClusterWorkloadResponseMessage) ClusterWorkloadRequestMessage(org.apache.nifi.cluster.protocol.message.ClusterWorkloadRequestMessage)

Example 2 with ClusterWorkloadRequestMessage

use of org.apache.nifi.cluster.protocol.message.ClusterWorkloadRequestMessage in project nifi by apache.

the class TestJaxbProtocolUtils method testRoundTripClusterWorkloadRequest.

@Test
public void testRoundTripClusterWorkloadRequest() throws JAXBException {
    final ClusterWorkloadRequestMessage msg = new ClusterWorkloadRequestMessage();
    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 ClusterWorkloadRequestMessage);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ClusterWorkloadRequestMessage(org.apache.nifi.cluster.protocol.message.ClusterWorkloadRequestMessage) Test(org.junit.Test)

Example 3 with ClusterWorkloadRequestMessage

use of org.apache.nifi.cluster.protocol.message.ClusterWorkloadRequestMessage in project nifi by apache.

the class ClusterProtocolHeartbeatMonitor method handleClusterWorkload.

private ProtocolMessage handleClusterWorkload(final ClusterWorkloadRequestMessage msg) {
    final ClusterWorkloadResponseMessage response = new ClusterWorkloadResponseMessage();
    final Map<NodeIdentifier, NodeWorkload> workloads = new HashMap<>();
    getLatestHeartbeats().values().stream().filter(hb -> NodeConnectionState.CONNECTED.equals(hb.getConnectionStatus().getState())).forEach(hb -> {
        NodeWorkload wl = new NodeWorkload();
        wl.setReportedTimestamp(hb.getTimestamp());
        wl.setSystemStartTime(hb.getSystemStartTime());
        wl.setActiveThreadCount(hb.getActiveThreadCount());
        wl.setFlowFileCount(hb.getFlowFileCount());
        wl.setFlowFileBytes(hb.getFlowFileBytes());
        workloads.put(hb.getNodeIdentifier(), wl);
    });
    response.setNodeWorkloads(workloads);
    return response;
}
Also used : ClusterWorkloadResponseMessage(org.apache.nifi.cluster.protocol.message.ClusterWorkloadResponseMessage) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) HeartbeatPayload(org.apache.nifi.cluster.protocol.HeartbeatPayload) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Function(java.util.function.Function) HeartbeatMessage(org.apache.nifi.cluster.protocol.message.HeartbeatMessage) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ClusterCoordinator(org.apache.nifi.cluster.coordination.ClusterCoordinator) MessageType(org.apache.nifi.cluster.protocol.message.ProtocolMessage.MessageType) NodeConnectionState(org.apache.nifi.cluster.coordination.node.NodeConnectionState) NodeConnectionStatus(org.apache.nifi.cluster.coordination.node.NodeConnectionStatus) ProtocolHandler(org.apache.nifi.cluster.protocol.ProtocolHandler) HeartbeatResponseMessage(org.apache.nifi.cluster.protocol.message.HeartbeatResponseMessage) Logger(org.slf4j.Logger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Heartbeat(org.apache.nifi.cluster.protocol.Heartbeat) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) ProtocolException(org.apache.nifi.cluster.protocol.ProtocolException) NiFiProperties(org.apache.nifi.util.NiFiProperties) ClusterWorkloadRequestMessage(org.apache.nifi.cluster.protocol.message.ClusterWorkloadRequestMessage) NodeWorkload(org.apache.nifi.cluster.coordination.node.NodeWorkload) ProtocolListener(org.apache.nifi.cluster.protocol.ProtocolListener) Collections(java.util.Collections) ProtocolMessage(org.apache.nifi.cluster.protocol.message.ProtocolMessage) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ClusterWorkloadResponseMessage(org.apache.nifi.cluster.protocol.message.ClusterWorkloadResponseMessage) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) NodeWorkload(org.apache.nifi.cluster.coordination.node.NodeWorkload)

Aggregations

ClusterWorkloadRequestMessage (org.apache.nifi.cluster.protocol.message.ClusterWorkloadRequestMessage)3 ClusterWorkloadResponseMessage (org.apache.nifi.cluster.protocol.message.ClusterWorkloadResponseMessage)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 ClusterCoordinator (org.apache.nifi.cluster.coordination.ClusterCoordinator)1 NodeConnectionState (org.apache.nifi.cluster.coordination.node.NodeConnectionState)1 NodeConnectionStatus (org.apache.nifi.cluster.coordination.node.NodeConnectionStatus)1 NodeWorkload (org.apache.nifi.cluster.coordination.node.NodeWorkload)1 Heartbeat (org.apache.nifi.cluster.protocol.Heartbeat)1 HeartbeatPayload (org.apache.nifi.cluster.protocol.HeartbeatPayload)1