You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2020/12/11 00:23:05 UTC

[GitHub] [ozone] fapifta commented on a change in pull request #1651: HDDS-4178. SCM Finalize client command implementation

fapifta commented on a change in pull request #1651:
URL: https://github.com/apache/ozone/pull/1651#discussion_r540598745



##########
File path: hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/upgrade/FinalizeScmUpgradeSubcommand.java
##########
@@ -0,0 +1,153 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.hdds.scm.cli.upgrade;
+
+import static org.apache.hadoop.hdds.scm.cli.upgrade.FinalizeUpgradeCommandUtil.emitCancellationMsg;
+import static org.apache.hadoop.hdds.scm.cli.upgrade.FinalizeUpgradeCommandUtil.emitExitMsg;
+import static org.apache.hadoop.hdds.scm.cli.upgrade.FinalizeUpgradeCommandUtil.emitFinishedMsg;
+import static org.apache.hadoop.hdds.scm.cli.upgrade.FinalizeUpgradeCommandUtil.emitGeneralErrorMsg;
+import static org.apache.hadoop.hdds.scm.cli.upgrade.FinalizeUpgradeCommandUtil.handleInvalidRequestAfterInitiatingFinalization;
+import static org.apache.hadoop.hdds.scm.cli.upgrade.FinalizeUpgradeCommandUtil.isDone;
+import static org.apache.hadoop.hdds.scm.cli.upgrade.FinalizeUpgradeCommandUtil.isFinalized;
+import static org.apache.hadoop.hdds.scm.cli.upgrade.FinalizeUpgradeCommandUtil.isInprogress;
+import static org.apache.hadoop.hdds.scm.cli.upgrade.FinalizeUpgradeCommandUtil.isStarting;
+
+import java.io.IOException;
+import java.util.UUID;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CancellationException;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+import org.apache.hadoop.hdds.cli.HddsVersionProvider;
+import org.apache.hadoop.hdds.scm.cli.ScmSubcommand;
+import org.apache.hadoop.hdds.scm.client.ScmClient;
+import org.apache.hadoop.ozone.upgrade.UpgradeException;
+import org.apache.hadoop.ozone.upgrade.UpgradeFinalizer;
+import org.apache.hadoop.ozone.upgrade.UpgradeFinalizer.StatusAndMessages;
+
+import picocli.CommandLine;
+
+/**
+ * Handler of Finalize SCM command.
+ */
+@CommandLine.Command(
+    name = "finalizeupgrade",
+    description = "Finalize SCM Upgrade",
+    mixinStandardHelpOptions = true,
+    versionProvider = HddsVersionProvider.class)
+
+public class FinalizeScmUpgradeSubcommand extends ScmSubcommand {
+  @CommandLine.Option(
+      names = {"--takeover"},
+      description = "Forces takeover of monitoring from another client, if "
+          + "finalization has already been started and did not finish yet."
+  )
+  private boolean force;
+
+  @Override
+  public void execute(ScmClient scmClient)
+      throws IOException, ExecutionException {
+    String upgradeClientID = "Upgrade-Client-" + UUID.randomUUID().toString();
+    try {
+      StatusAndMessages finalizationResponse =
+          scmClient.finalizeScmUpgrade(upgradeClientID);
+      if (isFinalized(finalizationResponse.status())){
+        System.out.println("Upgrade has already been finalized.");
+        emitExitMsg();
+        return;
+      } else if (!isStarting(finalizationResponse.status())){
+        System.err.println("Invalid response from Storage Container Manager.");
+        System.err.println(
+            "Current finalization status is: " + finalizationResponse.status()
+        );
+        throw new IOException("Exiting...");
+      }
+    } catch (UpgradeException e) {
+      handleInvalidRequestAfterInitiatingFinalization(force, e);
+    }
+    monitorAndWaitFinalization(scmClient, upgradeClientID);
+    return;
+  }
+
+  private void monitorAndWaitFinalization(ScmClient client,
+                                          String upgradeClientID) throws
+      ExecutionException {
+    ExecutorService exec = Executors.newSingleThreadExecutor();
+    Future<?> monitor =
+        exec.submit(new UpgradeMonitor(client, upgradeClientID, force));
+    try {
+      monitor.get();
+      emitFinishedMsg("Storage Container Manager");
+    } catch (CancellationException |InterruptedException e) {
+      emitCancellationMsg("Storage Container Manager");
+    } catch (ExecutionException e) {
+      emitGeneralErrorMsg();
+      throw e;

Review comment:
       I think, here we should just throw the cause of the ExecutionException wrapped into an IOException here.
   I believe it is a better approach, as with that other subcommands are not forced to declare to throw two types of exceptions.
   
   However as an alternative I am absolutely fine with declaring execute to throw an Exception, and do not mark specific Exceptions to be thrown.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org