Github user markap14 commented on a diff in the pull request:
https://github.com/apache/nifi/pull/323#discussion_r60782947
--- Diff:
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/impl/WebClusterManagerCoordinator.java
---
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nifi.cluster.manager.impl;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.nifi.cluster.coordination.ClusterCoordinator;
+import org.apache.nifi.cluster.coordination.node.DisconnectionCode;
+import org.apache.nifi.cluster.coordination.node.NodeConnectionState;
+import org.apache.nifi.cluster.coordination.node.NodeConnectionStatus;
+import org.apache.nifi.cluster.node.Node;
+import org.apache.nifi.cluster.node.Node.Status;
+import org.apache.nifi.cluster.protocol.ConnectionRequest;
+import org.apache.nifi.cluster.protocol.NodeIdentifier;
+import org.apache.nifi.reporting.Severity;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class WebClusterManagerCoordinator implements ClusterCoordinator {
+ private static final Logger logger =
LoggerFactory.getLogger(WebClusterManagerCoordinator.class);
+
+ private final WebClusterManager clusterManager;
+
+ public WebClusterManagerCoordinator(final WebClusterManager
clusterManager) {
+ this.clusterManager = clusterManager;
+ }
+
+ @Override
+ public void requestNodeConnect(final NodeIdentifier nodeId) {
+ final Node node = clusterManager.getRawNode(nodeId.getId());
+
+ if (node == null) {
+ final ConnectionRequest connectionRequest = new
ConnectionRequest(nodeId);
+ clusterManager.requestConnection(connectionRequest);
+ } else {
+ node.setStatus(Status.DISCONNECTED);
+ clusterManager.requestReconnection(nodeId.getId(),
"Anonymous");
+ }
+ }
+
+ @Override
+ public void finishNodeConnection(final NodeIdentifier nodeId) {
+ final Node node = clusterManager.getRawNode(nodeId.getId());
+ if (node == null) {
+ logger.error("Attempting to Finish Node Connection but could
not find Node with Identifier {}", nodeId);
+ return;
+ }
+
+ node.setStatus(Status.CONNECTED);
+ }
+
+ @Override
+ public void requestNodeDisconnect(final NodeIdentifier nodeId, final
DisconnectionCode disconnectionCode, final String explanation) {
+ try {
+ clusterManager.requestDisconnection(nodeId, false,
explanation);
+
+ if (disconnectionCode == DisconnectionCode.LACK_OF_HEARTBEAT) {
+ final Node node =
clusterManager.getRawNode(nodeId.getId());
+ if (node != null) {
+ node.setHeartbeatDisconnection();
+ }
+ }
+ } catch (final Exception e) {
+ logger.error("Failed to request node {} disconnect from
cluster due to {}", nodeId, e);
+ logger.error("", e);
--- End diff --
The first line logs a toString() of the Exception, whereas the second line
logs the stack trace. Personally, I find the log messages easier to read this
way when someone copies & pastes it, as they often do not look to grab a stack
trace but if the toString() of the Exception is part of the original message,
it makes it more clear.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---