sodonnel commented on code in PR #10493: URL: https://github.com/apache/ozone/pull/10493#discussion_r3429390832
########## 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: In some respects I like that "ignored" explicitly states "this is not used" while an empty string doesn't really document anything. If this was a key that was going to be stored many times and the ignored bytes would take up space, I certainly wouldn't do it this way, but as it stands I think its ok. -- 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]
