jfrazee commented on a change in pull request #5004:
URL: https://github.com/apache/nifi/pull/5004#discussion_r619298454
##########
File path:
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-runtime/src/main/java/org/apache/nifi/BootstrapListener.java
##########
@@ -202,6 +203,23 @@ public void run() {
case DUMP:
logger.info("Received DUMP request
from Bootstrap");
writeDump(socket.getOutputStream());
+ break;
+ case DECOMMISSION:
+ logger.info("Received DECOMMISSION
request from Bootstrap");
+
+ try {
+ decommission();
+
sendAnswer(socket.getOutputStream(), "DECOMMISSION");
+ nifi.shutdownHook(false);
+ } catch (final Exception e) {
+ final OutputStream out =
socket.getOutputStream();
+
+ out.write(("Failed to decommission
node: " + e + "; see app-log for additional
details").getBytes(StandardCharsets.UTF_8));
Review comment:
JFYI, sometimes there's nothing in app-log, leave it to you whether you
think that matters.
##########
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();
+ logger.info("Node successfully removed from cluster. Decommission is
complete.");
+ }
+
+ private void disconnectNode() throws InterruptedException {
+ logger.info("Requesting that Node disconnect from cluster");
+
+ while (true) {
+ final Future<Void> future =
clusterCoordinator.requestNodeDisconnect(localNodeIdentifier,
DisconnectionCode.USER_DISCONNECTED, "Node is being decommissioned");
+ try {
+ future.get();
+ return;
+ } catch (final ExecutionException e) {
+ final Throwable cause = e.getCause();
+ logger.error("Failed when attempting to disconnect node from
cluster", cause);
+ }
+ }
Review comment:
AFAICT the while in `disconnectNode()`, `offloadNode()`,
`waitForState()`, `waitForOffloadToFinish()` and `waitForRemoval()` can end up
in infinite loops but they'll never be interrupted.
You can't really determine how long an offload should take but disconnect
and removal should be fast, so does it make sense to have a timeout?
##########
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();
+ logger.info("Node successfully removed from cluster. Decommission is
complete.");
+ }
+
+ private void disconnectNode() throws InterruptedException {
+ logger.info("Requesting that Node disconnect from cluster");
+
+ while (true) {
+ final Future<Void> future =
clusterCoordinator.requestNodeDisconnect(localNodeIdentifier,
DisconnectionCode.USER_DISCONNECTED, "Node is being decommissioned");
+ try {
+ future.get();
+ return;
+ } catch (final ExecutionException e) {
+ final Throwable cause = e.getCause();
+ logger.error("Failed when attempting to disconnect node from
cluster", cause);
+ }
+ }
+ }
+
+ private void waitForDisconnection() throws InterruptedException {
+ logger.info("Waiting for Node to be completely disconnected from
cluster");
+ waitForState(Collections.singleton(NodeConnectionState.DISCONNECTED));
+ }
+
+ private void offloadNode() throws InterruptedException {
+ logger.info("Requesting that Node be offloaded");
+
+ while (true) {
Review comment:
Similar comment as above.
##########
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:
Can this use `waitForState()`? If the difference is that in
`waitForState()` that you do want to retry if there's a null since it might be
in progress and eventually be in a non-null state then there could be an NPE.
Otherwise I think `waitForState()` and `waitForRemoval()` are doing the same
thing.
--
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]