use of org.apache.nifi.cluster.protocol.message.NodeConnectionStatusResponseMessage in project nifi by apache.
the class NodeClusterCoordinator method handleNodeConnectionStatusRequest.
private NodeConnectionStatusResponseMessage handleNodeConnectionStatusRequest() {
final NodeConnectionStatusResponseMessage msg = new NodeConnectionStatusResponseMessage();
final NodeIdentifier self = getLocalNodeIdentifier();
if (self != null) {
final NodeConnectionStatus connectionStatus = nodeStatuses.get(self);
msg.setNodeConnectionStatus(connectionStatus);
}
return msg;
}
use of org.apache.nifi.cluster.protocol.message.NodeConnectionStatusResponseMessage in project nifi by apache.
the class TestJaxbProtocolUtils method testRoundTripConnectionStatusResponse.
@Test
public void testRoundTripConnectionStatusResponse() throws JAXBException {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final NodeConnectionStatusResponseMessage msg = new NodeConnectionStatusResponseMessage();
final NodeIdentifier nodeId = new NodeIdentifier("id", "localhost", 8000, "localhost", 8001, "localhost", 8002, 8003, true);
final NodeConnectionStatus nodeStatus = new NodeConnectionStatus(nodeId, DisconnectionCode.NOT_YET_CONNECTED);
msg.setNodeConnectionStatus(nodeStatus);
JaxbProtocolUtils.JAXB_CONTEXT.createMarshaller().marshal(msg, baos);
final Object unmarshalled = JaxbProtocolUtils.JAXB_CONTEXT.createUnmarshaller().unmarshal(new ByteArrayInputStream(baos.toByteArray()));
assertTrue(unmarshalled instanceof NodeConnectionStatusResponseMessage);
final NodeConnectionStatusResponseMessage unmarshalledMsg = (NodeConnectionStatusResponseMessage) unmarshalled;
final NodeConnectionStatus unmarshalledStatus = unmarshalledMsg.getNodeConnectionStatus();
assertEquals(nodeStatus, unmarshalledStatus);
}
use of org.apache.nifi.cluster.protocol.message.NodeConnectionStatusResponseMessage in project nifi by apache.
the class StandardClusterCoordinationProtocolSender method requestNodeConnectionStatus.
@Override
public NodeConnectionStatus requestNodeConnectionStatus(final String hostname, final int port) {
Objects.requireNonNull(hostname);
final NodeConnectionStatusRequestMessage msg = new NodeConnectionStatusRequestMessage();
final byte[] msgBytes;
try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
final ProtocolMessageMarshaller<ProtocolMessage> marshaller = protocolContext.createMarshaller();
marshaller.marshal(msg, baos);
msgBytes = baos.toByteArray();
} catch (final IOException e) {
throw new ProtocolException("Failed to marshal NodeIdentifierRequestMessage", e);
}
try (final Socket socket = createSocket(hostname, port, true)) {
// marshal message to output stream
socket.getOutputStream().write(msgBytes);
final ProtocolMessage response;
try {
// unmarshall response and return
final ProtocolMessageUnmarshaller<ProtocolMessage> unmarshaller = protocolContext.createUnmarshaller();
response = unmarshaller.unmarshal(socket.getInputStream());
} catch (final IOException ioe) {
throw new ProtocolException("Failed unmarshalling '" + MessageType.RECONNECTION_RESPONSE + "' protocol message due to: " + ioe, ioe);
}
if (MessageType.NODE_CONNECTION_STATUS_RESPONSE == response.getType()) {
return ((NodeConnectionStatusResponseMessage) response).getNodeConnectionStatus();
} else {
throw new ProtocolException("Expected message type '" + MessageType.NODE_CONNECTION_STATUS_RESPONSE + "' but found '" + response.getType() + "'");
}
} catch (final IOException ioe) {
throw new ProtocolException("Failed to request Node Identifer from " + hostname + ":" + port, ioe);
}
}
Aggregations