use of org.apache.nifi.cluster.protocol.NodeIdentifier in project nifi by apache.
the class NodeClusterCoordinator method shutdown.
@Override
public void shutdown() {
if (closed) {
return;
}
closed = true;
final NodeIdentifier localId = getLocalNodeIdentifier();
if (localId != null) {
final NodeConnectionStatus shutdownStatus = new NodeConnectionStatus(localId, DisconnectionCode.NODE_SHUTDOWN);
updateNodeStatus(shutdownStatus, false);
logger.info("Successfully notified other nodes that I am shutting down");
}
}
use of org.apache.nifi.cluster.protocol.NodeIdentifier 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.NodeIdentifier in project nifi by apache.
the class NodeClusterCoordinator method notifyOthersOfNodeStatusChange.
/**
* Notifies other nodes that the status of a node changed
*
* @param updatedStatus the updated status for a node in the cluster
* @param notifyAllNodes if <code>true</code> will notify all nodes. If
* <code>false</code>, will notify only the cluster coordinator
*/
void notifyOthersOfNodeStatusChange(final NodeConnectionStatus updatedStatus, final boolean notifyAllNodes, final boolean waitForCoordinator) {
// If this node is the active cluster coordinator, then we are going to replicate to all nodes.
// Otherwise, get the active coordinator (or wait for one to become active) and then notify the coordinator.
final Set<NodeIdentifier> nodesToNotify;
if (notifyAllNodes) {
nodesToNotify = getNodeIdentifiers(NodeConnectionState.CONNECTED, NodeConnectionState.CONNECTING);
// Do not notify ourselves because we already know about the status update.
nodesToNotify.remove(getLocalNodeIdentifier());
} else if (waitForCoordinator) {
nodesToNotify = Collections.singleton(waitForElectedClusterCoordinator());
} else {
final NodeIdentifier nodeId = getElectedActiveCoordinatorNode();
if (nodeId == null) {
return;
}
nodesToNotify = Collections.singleton(nodeId);
}
final NodeStatusChangeMessage message = new NodeStatusChangeMessage();
message.setNodeId(updatedStatus.getNodeIdentifier());
message.setNodeConnectionStatus(updatedStatus);
senderListener.notifyNodeStatusChange(nodesToNotify, message);
}
use of org.apache.nifi.cluster.protocol.NodeIdentifier in project nifi by apache.
the class NodeClusterCoordinator method requestNodeDisconnect.
@Override
public void requestNodeDisconnect(final NodeIdentifier nodeId, final DisconnectionCode disconnectionCode, final String explanation) {
final Set<NodeIdentifier> connectedNodeIds = getNodeIdentifiers(NodeConnectionState.CONNECTED);
if (connectedNodeIds.size() == 1 && connectedNodeIds.contains(nodeId)) {
throw new IllegalNodeDisconnectionException("Cannot disconnect node " + nodeId + " because it is the only node currently connected");
}
logger.info("Requesting that {} disconnect due to {}", nodeId, explanation == null ? disconnectionCode : explanation);
updateNodeStatus(new NodeConnectionStatus(nodeId, disconnectionCode, explanation));
// shutdown, as we will not be able to connect to the node anyway.
if (disconnectionCode == DisconnectionCode.NODE_SHUTDOWN) {
return;
}
final DisconnectMessage request = new DisconnectMessage();
request.setNodeId(nodeId);
request.setExplanation(explanation);
addNodeEvent(nodeId, "Disconnection requested due to " + explanation);
disconnectAsynchronously(request, 10, 5);
}
use of org.apache.nifi.cluster.protocol.NodeIdentifier in project nifi by apache.
the class AffectedComponentEntityMerger method mergeAffectedComponents.
public void mergeAffectedComponents(final Set<AffectedComponentEntity> affectedComponents, final Map<NodeIdentifier, Set<AffectedComponentEntity>> affectedComponentMap) {
final Map<String, Integer> activeThreadCounts = new HashMap<>();
final Map<String, String> states = new HashMap<>();
final Map<String, PermissionsDTO> canReads = new HashMap<>();
for (final Map.Entry<NodeIdentifier, Set<AffectedComponentEntity>> nodeEntry : affectedComponentMap.entrySet()) {
final Set<AffectedComponentEntity> nodeAffectedComponents = nodeEntry.getValue();
// go through all the nodes referencing components
if (nodeAffectedComponents != null) {
for (final AffectedComponentEntity nodeAffectedComponentEntity : nodeAffectedComponents) {
final AffectedComponentDTO nodeAffectedComponent = nodeAffectedComponentEntity.getComponent();
if (nodeAffectedComponentEntity.getPermissions().getCanRead()) {
// handle active thread counts
if (nodeAffectedComponent.getActiveThreadCount() != null && nodeAffectedComponent.getActiveThreadCount() > 0) {
final Integer current = activeThreadCounts.get(nodeAffectedComponent.getId());
if (current == null) {
activeThreadCounts.put(nodeAffectedComponent.getId(), nodeAffectedComponent.getActiveThreadCount());
} else {
activeThreadCounts.put(nodeAffectedComponent.getId(), nodeAffectedComponent.getActiveThreadCount() + current);
}
}
// handle controller service state
final String state = states.get(nodeAffectedComponent.getId());
if (state == null) {
if (ControllerServiceState.DISABLING.name().equals(nodeAffectedComponent.getState())) {
states.put(nodeAffectedComponent.getId(), ControllerServiceState.DISABLING.name());
} else if (ControllerServiceState.ENABLING.name().equals(nodeAffectedComponent.getState())) {
states.put(nodeAffectedComponent.getId(), ControllerServiceState.ENABLING.name());
}
}
}
// handle read permissions
final PermissionsDTO mergedPermissions = canReads.get(nodeAffectedComponentEntity.getId());
final PermissionsDTO permissions = nodeAffectedComponentEntity.getPermissions();
if (permissions != null) {
if (mergedPermissions == null) {
canReads.put(nodeAffectedComponentEntity.getId(), permissions);
} else {
PermissionsDtoMerger.mergePermissions(mergedPermissions, permissions);
}
}
}
}
}
// go through each affected components
if (affectedComponents != null) {
for (final AffectedComponentEntity affectedComponent : affectedComponents) {
final PermissionsDTO permissions = canReads.get(affectedComponent.getId());
if (permissions != null && permissions.getCanRead() != null && permissions.getCanRead()) {
final Integer activeThreadCount = activeThreadCounts.get(affectedComponent.getId());
if (activeThreadCount != null) {
affectedComponent.getComponent().setActiveThreadCount(activeThreadCount);
}
final String state = states.get(affectedComponent.getId());
if (state != null) {
affectedComponent.getComponent().setState(state);
}
} else {
affectedComponent.setPermissions(permissions);
affectedComponent.setComponent(null);
}
}
}
}
Aggregations