@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final NodeResponse other = (NodeResponse) obj; if (this.nodeId != other.nodeId && (this.nodeId == null || !this.nodeId.equals(other.nodeId))) { return false; } return true; }
@Override public void setLocalNodeIdentifier(final NodeIdentifier nodeId) { if (nodeId == null || nodeId.equals(this.nodeId)) { return; } this.nodeId = nodeId; nodeStatuses.computeIfAbsent(nodeId, id -> new NodeConnectionStatus(id, DisconnectionCode.NOT_YET_CONNECTED)); eventListeners.forEach(listener -> listener.onLocalNodeIdentifierSet(nodeId)); }
@Override public boolean isActiveClusterCoordinator() { final NodeIdentifier self = getLocalNodeIdentifier(); return self != null && self.equals(getElectedActiveCoordinatorNode()); }
if (nodeIdentifier.equals(localNodeId)) { if (partition instanceof LocalQueuePartition) { logger.debug("{} Local Node Identifier set to {} and QueuePartition with this identifier is already a Local Queue Partition", SocketLoadBalancedFlowFileQueue.this,
private void storeState() { final ObjectMapper mapper = new ObjectMapper(); final JsonFactory jsonFactory = new JsonFactory(); jsonFactory.setCodec(mapper); try { final Map<String, String> stateMap = new HashMap<>(); final NodeIdentifier localNodeId = getLocalNodeIdentifier(); for (final NodeIdentifier nodeId : getNodeIdentifiers()) { final boolean isLocalId = nodeId.equals(localNodeId); final NodeIdentifierDescriptor descriptor = NodeIdentifierDescriptor.fromNodeIdentifier(nodeId, isLocalId); try (final StringWriter writer = new StringWriter()) { final JsonGenerator jsonGenerator = jsonFactory.createGenerator(writer); jsonGenerator.writeObject(descriptor); final String serializedDescriptor = writer.toString(); stateMap.put(nodeId.getId(), serializedDescriptor); } } stateManager.setState(stateMap, Scope.LOCAL); logger.debug("Stored the following state as the Cluster Topology: {}", stateMap); } catch (final Exception e) { logger.warn("Failed to store cluster topology to local State Manager. Upon restart of NiFi, the cluster topology may not be accurate until joining the cluster.", e); } }
@Override public void onNodeStateChange(final NodeIdentifier nodeId, final NodeConnectionState newState) { partitionWriteLock.lock(); try { if (!offloaded) { return; } switch (newState) { case CONNECTED: if (nodeId != null && nodeId.equals(clusterCoordinator.getLocalNodeIdentifier())) { // the node with this queue was connected to the cluster, make sure the queue is not offloaded resetOffloadedQueue(); } break; case OFFLOADED: case OFFLOADING: case DISCONNECTED: case DISCONNECTING: onNodeRemoved(nodeId); break; } } finally { partitionWriteLock.unlock(); } } }
if (nodeId.equals(clusterCoordinator.getLocalNodeIdentifier())) { queuePartitions[i] = localPartition; } else {
for (int i = 0; i < sortedNodeIdentifiers.size(); i++) { final NodeIdentifier nodeId = sortedNodeIdentifiers.get(i); if (nodeId.equals(clusterCoordinator.getLocalNodeIdentifier())) { updatedQueuePartitions[i] = localPartition; localPartitionIncluded = true;
if (activeCoordinator != null && !activeCoordinator.equals(clusterCoordinator.getLocalNodeIdentifier())) {
if (otherResponse.getNodeId().equals(nodeResponse.getNodeId())) { continue;