@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((nodeId == null) ? 0 : nodeId.hashCode()); result = prime * result + ((state == null) ? 0 : state.hashCode()); return result; }
private String summarizeStatusChange(final NodeConnectionStatus oldStatus, final NodeConnectionStatus status) { final StringBuilder sb = new StringBuilder(); if (oldStatus == null || status.getState() != oldStatus.getState()) { sb.append("Node Status changed from ").append(oldStatus == null ? "[Unknown Node]" : oldStatus.getState().toString()).append(" to ").append(status.getState().toString()); if (status.getReason() != null) { sb.append(" due to ").append(status.getReason()); } else if (status.getDisconnectCode() != null) { sb.append(" due to ").append(status.getDisconnectCode().toString()); } } return sb.toString(); }
@Override public Set<NodeIdentifier> getNodeIdentifiers(final NodeConnectionState... states) { final Set<NodeConnectionState> statesOfInterest = new HashSet<>(); if (states.length == 0) { for (final NodeConnectionState state : NodeConnectionState.values()) { statesOfInterest.add(state); } } else { for (final NodeConnectionState state : states) { statesOfInterest.add(state); } } return nodeStatuses.entrySet().stream() .filter(entry -> statesOfInterest.contains(entry.getValue().getState())) .map(entry -> entry.getKey()) .collect(Collectors.toSet()); }
@Override public void deleteNode(final String nodeId) { final NiFiUser user = NiFiUserUtils.getNiFiUser(); if (user == null) { throw new WebApplicationException(new Throwable("Unable to access details for current user.")); } final String userDn = user.getIdentity(); final NodeIdentifier nodeIdentifier = clusterCoordinator.getNodeIdentifier(nodeId); if (nodeIdentifier == null) { throw new UnknownNodeException("Cannot remove Node with ID " + nodeId + " because it is not part of the cluster"); } final NodeConnectionStatus nodeConnectionStatus = clusterCoordinator.getConnectionStatus(nodeIdentifier); if (!nodeConnectionStatus.getState().equals(NodeConnectionState.OFFLOADED) && !nodeConnectionStatus.getState().equals(NodeConnectionState.DISCONNECTED)) { throw new IllegalNodeDeletionException("Cannot remove Node with ID " + nodeId + " because it is not disconnected or offloaded, current state = " + nodeConnectionStatus.getState()); } clusterCoordinator.removeNode(nodeIdentifier, userDn); heartbeatMonitor.removeHeartbeat(nodeIdentifier); }
@Override public NodeDTO updateNode(final NodeDTO nodeDTO) { final NiFiUser user = NiFiUserUtils.getNiFiUser(); if (user == null) { throw new WebApplicationException(new Throwable("Unable to access details for current user.")); } final String userDn = user.getIdentity(); final NodeIdentifier nodeId = clusterCoordinator.getNodeIdentifier(nodeDTO.getNodeId()); if (nodeId == null) { throw new UnknownNodeException("No node exists with ID " + nodeDTO.getNodeId()); } if (NodeConnectionState.CONNECTING.name().equalsIgnoreCase(nodeDTO.getStatus())) { clusterCoordinator.requestNodeConnect(nodeId, userDn); } else if (NodeConnectionState.OFFLOADING.name().equalsIgnoreCase(nodeDTO.getStatus())) { clusterCoordinator.requestNodeOffload(nodeId, OffloadCode.OFFLOADED, "User " + userDn + " requested that node be offloaded"); } else if (NodeConnectionState.DISCONNECTING.name().equalsIgnoreCase(nodeDTO.getStatus())) { clusterCoordinator.requestNodeDisconnect(nodeId, DisconnectionCode.USER_DISCONNECTED, "User " + userDn + " requested that node be disconnected from cluster"); } return getNode(nodeId); }
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; }
if (!NodeConnectionState.CONNECTED.name().equals(node.getStatus())) { continue;
nodeDto.setAddress(nodeId.getApiAddress()); nodeDto.setApiPort(nodeId.getApiPort()); nodeDto.setStatus(status.getState().name()); nodeDto.setRoles(roles); if (status.getConnectionRequestTime() != null) {
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((nodeId == null) ? 0 : nodeId.hashCode()); result = prime * result + ((state == null) ? 0 : state.hashCode()); return result; }