public static ConnectionResponse createBlockedByFirewallResponse() { return new ConnectionResponse("Blocked by Firewall"); }
@Override public AdaptedConnectionResponse marshal(final ConnectionResponse cr) { final AdaptedConnectionResponse aCr = new AdaptedConnectionResponse(); if (cr != null) { aCr.setDataFlow(cr.getDataFlow()); aCr.setNodeIdentifier(cr.getNodeIdentifier()); aCr.setTryLaterSeconds(cr.getTryLaterSeconds()); aCr.setRejectionReason(cr.getRejectionReason()); aCr.setInstanceId(cr.getInstanceId()); aCr.setNodeConnectionStatuses(cr.getNodeConnectionStatuses()); aCr.setComponentRevisions(cr.getComponentRevisions()); } return aCr; }
private void loadFromConnectionResponse(final ConnectionResponse response) throws ConnectionException { writeLock.lock(); try { if (response.getNodeConnectionStatuses() != null) { clusterCoordinator.resetNodeStatuses(response.getNodeConnectionStatuses().stream() .collect(Collectors.toMap(NodeConnectionStatus::getNodeIdentifier, status -> status))); final DataFlow dataFlow = response.getDataFlow(); if (logger.isTraceEnabled()) { logger.trace("ResponseFlow = " + new String(dataFlow.getFlow(), StandardCharsets.UTF_8)); nodeId = response.getNodeIdentifier(); logger.info("Setting Flow Controller's Node ID: " + nodeId); controller.setNodeId(nodeId); clusterCoordinator.setLocalNodeIdentifier(nodeId); clusterCoordinator.setConnected(true); revisionManager.reset(response.getComponentRevisions().stream().map(ComponentRevision::toRevision).collect(Collectors.toList())); controller.setClustered(true, response.getInstanceId());
response = senderListener.requestConnection(requestMsg).getConnectionResponse(); if (response.shouldTryLater()) { logger.info("Requested by cluster coordinator to retry connection in " + response.getTryLaterSeconds() + " seconds with explanation: " + response.getRejectionReason()); try { Thread.sleep(response.getTryLaterSeconds() * 1000); } catch (final InterruptedException ie) { break; } else if (response.getRejectionReason() != null) { logger.warn("Connection request was blocked by cluster coordinator with the explanation: " + response.getRejectionReason()); Thread.sleep(response == null ? 5000 : response.getTryLaterSeconds()); } catch (final InterruptedException ie) { Thread.currentThread().interrupt(); } else if (response.shouldTryLater()) { + response.getRejectionReason() + "'. However, the maximum number of retries have already completed. Will load local flow and connect to the cluster when able."); return null; } else { final Map<String, String> map = Collections.singletonMap(NODE_UUID, response.getNodeIdentifier().getId()); controller.getStateManagerProvider().getStateManager(CLUSTER_NODE_CONFIG).setState(map, Scope.LOCAL); } catch (final IOException ioe) {
private void handleReconnectionRequest(final ReconnectionRequestMessage request) { try { logger.info("Processing reconnection request from cluster coordinator."); // reconnect ConnectionResponse connectionResponse = new ConnectionResponse(getNodeId(), request.getDataFlow(), request.getInstanceId(), request.getNodeConnectionStatuses(), request.getComponentRevisions()); if (connectionResponse.getDataFlow() == null) { logger.info("Received a Reconnection Request that contained no DataFlow. Will attempt to connect to cluster using local flow."); connectionResponse = connect(false, false, createDataFlowFromController()); } loadFromConnectionResponse(connectionResponse); clusterCoordinator.resetNodeStatuses(connectionResponse.getNodeConnectionStatuses().stream() .collect(Collectors.toMap(NodeConnectionStatus::getNodeIdentifier, status -> status))); // reconnected, this node needs to explicitly write the inherited flow to disk, and resume heartbeats saveFlowChanges(); controller.resumeHeartbeats(); logger.info("Node reconnected."); } catch (final Exception ex) { // disconnect controller if (controller.isClustered()) { disconnect("Failed to properly handle Reconnection request due to " + ex.toString()); } logger.error("Handling reconnection request failed due to: " + ex, ex); handleConnectionFailure(ex); } }
@Override public ConnectionResponse unmarshal(final AdaptedConnectionResponse aCr) { if (aCr.shouldTryLater()) { return new ConnectionResponse(aCr.getTryLaterSeconds(), aCr.getRejectionReason()); } else if (aCr.getRejectionReason() != null) { return ConnectionResponse.createRejectionResponse(aCr.getRejectionReason()); } else { return new ConnectionResponse(aCr.getNodeIdentifier(), aCr.getDataFlow(), aCr.getInstanceId(), aCr.getNodeConnectionStatuses(), aCr.getComponentRevisions()); } }
private ConnectionResponseMessage handleConnectionRequest(final ConnectionRequestMessage requestMessage, final Set<String> nodeIdentities) { final NodeIdentifier proposedIdentifier = requestMessage.getConnectionRequest().getProposedNodeIdentifier(); final NodeIdentifier withNodeIdentities = addNodeIdentities(proposedIdentifier, nodeIdentities); final DataFlow dataFlow = requestMessage.getConnectionRequest().getDataFlow(); final ConnectionRequest requestWithNodeIdentities = new ConnectionRequest(withNodeIdentities, dataFlow); // Resolve Node identifier. final NodeIdentifier resolvedNodeId = resolveNodeId(proposedIdentifier); if (isBlockedByFirewall(nodeIdentities)) { // if the socket address is not listed in the firewall, then return a null response logger.info("Firewall blocked connection request from node " + resolvedNodeId + " with Node Identities " + nodeIdentities); final ConnectionResponse response = ConnectionResponse.createBlockedByFirewallResponse(); final ConnectionResponseMessage responseMessage = new ConnectionResponseMessage(); responseMessage.setConnectionResponse(response); return responseMessage; } if (requireElection) { final DataFlow electedDataFlow = flowElection.castVote(dataFlow, withNodeIdentities); if (electedDataFlow == null) { logger.info("Received Connection Request from {}; responding with Flow Election In Progress message", withNodeIdentities); return createFlowElectionInProgressResponse(); } else { logger.info("Received Connection Request from {}; responding with DataFlow that was elected", withNodeIdentities); return createConnectionResponse(requestWithNodeIdentities, resolvedNodeId, electedDataFlow); } } logger.info("Received Connection Request from {}; responding with my DataFlow", withNodeIdentities); return createConnectionResponse(requestWithNodeIdentities, resolvedNodeId); }
@Override public ConnectionResponse unmarshal(final AdaptedConnectionResponse aCr) { if (aCr.shouldTryLater()) { return new ConnectionResponse(aCr.getTryLaterSeconds(), aCr.getRejectionReason()); } else if (aCr.getRejectionReason() != null) { return ConnectionResponse.createRejectionResponse(aCr.getRejectionReason()); } else { return new ConnectionResponse(aCr.getNodeIdentifier(), aCr.getDataFlow(), aCr.getInstanceId(), aCr.getNodeConnectionStatuses(), aCr.getComponentRevisions()); } }
@Override public AdaptedConnectionResponse marshal(final ConnectionResponse cr) { final AdaptedConnectionResponse aCr = new AdaptedConnectionResponse(); if (cr != null) { aCr.setDataFlow(cr.getDataFlow()); aCr.setNodeIdentifier(cr.getNodeIdentifier()); aCr.setTryLaterSeconds(cr.getTryLaterSeconds()); aCr.setRejectionReason(cr.getRejectionReason()); aCr.setInstanceId(cr.getInstanceId()); aCr.setNodeConnectionStatuses(cr.getNodeConnectionStatuses()); aCr.setComponentRevisions(cr.getComponentRevisions()); } return aCr; }
public static ConnectionResponse createConflictingNodeIdResponse(final String otherNode) { return new ConnectionResponse("The Node Identifier provided already belongs to node " + otherNode); }
public static ConnectionResponse createRejectionResponse(final String explanation) { return new ConnectionResponse(explanation); }
private ConnectionResponseMessage createFlowElectionInProgressResponse() { final ConnectionResponseMessage responseMessage = new ConnectionResponseMessage(); final String statusDescription = flowElection.getStatusDescription(); responseMessage.setConnectionResponse(new ConnectionResponse(5, "Cluster is still voting on which Flow is the correct flow for the cluster. " + statusDescription)); return responseMessage; }
private ConnectionResponseMessage createConnectionResponse(final ConnectionRequest request, final NodeIdentifier resolvedNodeIdentifier, final DataFlow clusterDataFlow) { if (clusterDataFlow == null) { final ConnectionResponseMessage responseMessage = new ConnectionResponseMessage(); responseMessage.setConnectionResponse(new ConnectionResponse(5, "The cluster dataflow is not yet available")); return responseMessage; } // Set node's status to 'CONNECTING' NodeConnectionStatus status = getConnectionStatus(resolvedNodeIdentifier); if (status == null) { addNodeEvent(resolvedNodeIdentifier, "Connection requested from new node. Setting status to connecting."); } else { addNodeEvent(resolvedNodeIdentifier, "Connection requested from existing node. Setting status to connecting."); } status = new NodeConnectionStatus(resolvedNodeIdentifier, NodeConnectionState.CONNECTING, null, null, null, System.currentTimeMillis()); updateNodeStatus(status); final ConnectionResponse response = new ConnectionResponse(resolvedNodeIdentifier, clusterDataFlow, instanceId, getConnectionStatuses(), revisionManager.getAllRevisions().stream().map(rev -> ComponentRevision.fromRevision(rev)).collect(Collectors.toList())); final ConnectionResponseMessage responseMessage = new ConnectionResponseMessage(); responseMessage.setConnectionResponse(response); return responseMessage; }
public static ConnectionResponse createBlockedByFirewallResponse() { return new ConnectionResponse("Blocked by Firewall"); }
public static ConnectionResponse createRejectionResponse(final String explanation) { return new ConnectionResponse(explanation); }
public static ConnectionResponse createConflictingNodeIdResponse(final String otherNode) { return new ConnectionResponse("The Node Identifier provided already belongs to node " + otherNode); }