errose28 commented on code in PR #10493:
URL: https://github.com/apache/ozone/pull/10493#discussion_r3424068842
##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/upgrade/FinalizeSubCommand.java:
##########
@@ -17,27 +17,37 @@
package org.apache.hadoop.ozone.admin.upgrade;
-import java.io.IOException;
+import java.util.concurrent.Callable;
+import org.apache.hadoop.hdds.cli.AbstractSubcommand;
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.admin.om.OmAddressOptions;
+import org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol;
import picocli.CommandLine;
/**
- * Sub command to finalize a cluster upgrade.
+ * Handler for the ozone admin upgrade finalize command.
*/
@CommandLine.Command(
name = "finalize",
- description = "Finalize a cluster upgrade",
+ description = "Initiates the the process to finalize a cluster upgrade.",
mixinStandardHelpOptions = true,
- versionProvider = HddsVersionProvider.class)
-public class FinalizeSubCommand extends ScmSubcommand {
+ versionProvider = HddsVersionProvider.class
+)
+public class FinalizeSubCommand extends AbstractSubcommand implements
Callable<Void> {
Review Comment:
Is this connected to the CLI under `ozone admin upgrade`? I don't see that
here and currently the acceptance tests are not executing this path. If
finalize is expected to work end to end from the new CLI after this change we
should update the upgrade acceptance tests to use it.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/upgrade/OMStartFinalizeUpgradeRequest.java:
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.hadoop.ozone.om.request.upgrade;
+
+import static
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.Type.StartFinalizeUpgrade;
+
+import java.io.IOException;
+import java.util.HashMap;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.audit.AuditLogger;
+import org.apache.hadoop.ozone.audit.OMAction;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.execution.flowcontrol.ExecutionContext;
+import org.apache.hadoop.ozone.om.request.OMClientRequest;
+import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import
org.apache.hadoop.ozone.om.response.upgrade.OMStartFinalizeUpgradeResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
+import
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Starts the cluster upgrade finalization process.
+ */
+public class OMStartFinalizeUpgradeRequest extends OMClientRequest {
+ private static final Logger LOG =
LoggerFactory.getLogger(OMStartFinalizeUpgradeRequest.class);
+
+ public OMStartFinalizeUpgradeRequest(OMRequest omRequest) {
+ super(omRequest);
+ }
+
+ @Override
+ public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {
+ OMRequest omRequest = super.preExecute(ozoneManager);
+ if (ozoneManager.isAdminAuthorizationEnabled()) {
+ UserGroupInformation ugi = createUGIForApi();
+ if (!ozoneManager.isAdmin(ugi)) {
+ throw new OMException("Access denied for user " + ugi + ". "
+ + "Superuser privilege is required to start finalize upgrade.",
OMException.ResultCodes.ACCESS_DENIED);
+ }
+ }
+ ozoneManager.getScmClient().getContainerClient().finalizeUpgrade();
+ LOG.info("Successfully triggered the finalize upgrade process in SCM");
+ return omRequest;
+ }
+
+ @Override
+ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
ExecutionContext context) {
+ LOG.trace("Request: {}", getOmRequest());
+ AuditLogger auditLogger = ozoneManager.getSystemAuditLogger();
+ OzoneManagerProtocolProtos.UserInfo userInfo =
getOmRequest().getUserInfo();
+ OMResponse.Builder responseBuilder =
OmResponseUtil.getOMResponseBuilder(getOmRequest());
+ responseBuilder.setCmdType(StartFinalizeUpgrade);
+ OMClientResponse response = null;
+ Exception exception = null;
+
+ try {
+ OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
+ omMetadataManager.getMetaTable().addCacheEntry(
+ new CacheKey<>(OzoneConsts.FINALIZATION_IN_PROGRESS_KEY),
CacheValue.get(context.getIndex(), "ignored"));
Review Comment:
Can we just write an empty string?
##########
hadoop-ozone/interface-client/src/main/proto/OmClientProtocol.proto:
##########
@@ -157,6 +157,7 @@ enum Type {
GetObjectTagging = 141;
DeleteObjectTagging = 142;
SubmitSnapshotDiff = 143;
+ StartFinalizeUpgrade = 144;
Review Comment:
We should be able to mark the old finalize related requests as deprecated,
either with proto syntax or a comment where that is not supported.
##########
hadoop-ozone/cli-admin/src/test/java/org/apache/hadoop/ozone/admin/upgrade/TestFinalizeSubCommand.java:
##########
@@ -42,10 +44,21 @@ public class TestFinalizeSubCommand {
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
private final PrintStream originalOut = System.out;
private FinalizeSubCommand cmd;
+ private OzoneManagerProtocol omClient;
@BeforeEach
- public void setup() throws UnsupportedEncodingException {
- cmd = new FinalizeSubCommand();
+ public void setup() throws IOException {
+ omClient = mock(OzoneManagerProtocol.class);
+
+ // Mock close() to do nothing - needed for try-with-resources
+ doNothing().when(omClient).close();
+
+ cmd = new FinalizeSubCommand() {
+ @Override
+ protected OzoneManagerProtocol getClient() throws Exception {
+ return omClient;
+ }
+ };
Review Comment:
Probably simpler to make an `@VisibleForTesting` setter to inject the mock
client instead.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]