markap14 commented on a change in pull request #5004:
URL: https://github.com/apache/nifi/pull/5004#discussion_r619407468



##########
File path: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/lifecycle/ClusterDecommissionTask.java
##########
@@ -0,0 +1,173 @@
+/*
+ * 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.lifecycle;
+
+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.coordination.node.OffloadCode;
+import org.apache.nifi.cluster.protocol.NodeIdentifier;
+import org.apache.nifi.controller.DecommissionTask;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+public class ClusterDecommissionTask implements DecommissionTask {
+    private static final Logger logger = 
LoggerFactory.getLogger(ClusterDecommissionTask.class);
+    private static final int delaySeconds = 3;
+
+    private final ClusterCoordinator clusterCoordinator;
+    private NodeIdentifier localNodeIdentifier;
+
+    public ClusterDecommissionTask(final ClusterCoordinator 
clusterCoordinator) {
+        this.clusterCoordinator = clusterCoordinator;
+    }
+
+    @Override
+    public synchronized void decommission() throws InterruptedException {
+        if (clusterCoordinator == null) {
+            throw new IllegalStateException("Cannot decommission Node because 
it is not part of a cluster");
+        }
+
+        logger.info("Decommissioning Node...");
+        localNodeIdentifier = clusterCoordinator.getLocalNodeIdentifier();
+        if (localNodeIdentifier == null) {
+            throw new IllegalStateException("Node has not yet connected to the 
cluster");
+        }
+
+        disconnectNode();
+        logger.info("Requested that node be disconnected from cluster");
+
+        waitForDisconnection();
+        logger.info("Successfully disconnected node from cluster");
+
+        offloadNode();
+        logger.info("Successfully triggered Node Offload. Will wait for 
offload to complete");
+
+        waitForOffloadToFinish();
+        logger.info("Offload has successfully completed.");
+
+        removeFromCluster();
+        logger.info("Requested that node be removed from cluster.");
+
+        waitForRemoval();

Review comment:
       Yeah so `waitForRemoval()` is a bit special because it completes if it 
determines that the state is `null` or if it's REMOVED. So that null check had 
to be handled differently. I did consider combining them but felt it was just 
cleaner to break it out as a special case.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to