diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/upgrade/DisallowedUntilOmVersion.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/upgrade/DisallowedUntilOmVersion.java new file mode 100644 index 000000000000..ad04f9db0fbc --- /dev/null +++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/upgrade/DisallowedUntilOmVersion.java @@ -0,0 +1,39 @@ +/* + * 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.upgrade; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.apache.hadoop.ozone.OzoneManagerVersion; + +/** + * Annotation used to "disallow" an API until the OM has finalized to the + * associated {@link OzoneManagerVersion}. Helps to keep the method logic + * and upgrade related cross-cutting concerns separate. + * + *
This is the {@link OzoneManagerVersion}-keyed counterpart of
+ * {@link DisallowedUntilLayoutVersion}, for features added after Zero Downtime Upgrade (ZDU) when
+ * {@link OMLayoutFeature} was frozen.
+ */
+@Target({ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface DisallowedUntilOmVersion {
+ OzoneManagerVersion value();
+}
diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/upgrade/OMLayoutFeatureAspect.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/upgrade/OMRequestVersionAspect.java
similarity index 77%
rename from hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/upgrade/OMLayoutFeatureAspect.java
rename to hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/upgrade/OMRequestVersionAspect.java
index 479d47c31e62..351175eb8ff1 100644
--- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/upgrade/OMLayoutFeatureAspect.java
+++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/upgrade/OMRequestVersionAspect.java
@@ -31,18 +31,29 @@
import org.aspectj.lang.reflect.MethodSignature;
/**
- * 'Aspect' for OM Layout Feature API. All methods annotated with the
- * specific annotation will have pre-processing done here to check layout
- * version compatibility.
+ * 'Aspect' for OM component version API. All methods annotated with the
+ * specific annotation will have pre-processing done here to check version compatibility.
*/
@Aspect
-public class OMLayoutFeatureAspect {
+public class OMRequestVersionAspect {
@Before("@annotation(DisallowedUntilLayoutVersion) && execution(* *(..))")
public void checkLayoutFeature(JoinPoint joinPoint) throws IOException {
ComponentVersion layoutFeature = ((MethodSignature) joinPoint.getSignature())
.getMethod().getAnnotation(DisallowedUntilLayoutVersion.class)
.value();
+ checkFeatureAllowed(joinPoint, layoutFeature);
+ }
+
+ @Before("@annotation(DisallowedUntilOmVersion) && execution(* *(..))")
+ public void checkOmVersion(JoinPoint joinPoint) throws IOException {
+ ComponentVersion omVersion = ((MethodSignature) joinPoint.getSignature())
+ .getMethod().getAnnotation(DisallowedUntilOmVersion.class)
+ .value();
+ checkFeatureAllowed(joinPoint, omVersion);
+ }
+
+ private void checkFeatureAllowed(JoinPoint joinPoint, ComponentVersion version) throws IOException {
OMVersionManager versionManager = null;
final Object[] args = joinPoint.getArgs();
if (joinPoint.getTarget() instanceof OzoneManagerRequestHandler) {
@@ -56,22 +67,22 @@ public void checkLayoutFeature(JoinPoint joinPoint) throws IOException {
versionManager = ozoneManager.getVersionManager();
} else {
throw new IOException(
- "Unable to resolve OMVersionManager for layout validation; "
+ "Unable to resolve OMVersionManager for version validation; "
+ "expected OzoneManagerRequestHandler or OMClientRequest.preExecute: "
+ joinPoint.toShortString());
}
// Throws an exception that must be propagated if the request is not allowed.
- checkIsAllowed(joinPoint.getSignature().toShortString(), versionManager, layoutFeature);
+ checkIsAllowed(joinPoint.getSignature().toShortString(), versionManager, version);
}
private void checkIsAllowed(String operationName,
OMVersionManager omVersionManager,
- ComponentVersion layoutFeature) throws OMException {
- if (!omVersionManager.isAllowed(layoutFeature)) {
+ ComponentVersion version) throws OMException {
+ if (!omVersionManager.isAllowed(version)) {
throw new OMException(String.format("Operation %s cannot be invoked " +
"before finalization. It belongs to version %s. Current apparent version is %s",
operationName,
- layoutFeature,
+ version,
omVersionManager.getApparentVersion()),
NOT_SUPPORTED_OPERATION_PRIOR_FINALIZATION);
}
@@ -81,8 +92,8 @@ private void checkIsAllowed(String operationName,
* Note: Without this, it occasionally throws NoSuchMethodError when running
* the test.
*/
- public static OMLayoutFeatureAspect aspectOf() {
- return new OMLayoutFeatureAspect();
+ public static OMRequestVersionAspect aspectOf() {
+ return new OMRequestVersionAspect();
}
}
diff --git a/hadoop-ozone/ozone-manager/src/main/resources/META-INF/aop.xml b/hadoop-ozone/ozone-manager/src/main/resources/META-INF/aop.xml
index a96b5e8b71bc..7c512cebc16a 100644
--- a/hadoop-ozone/ozone-manager/src/main/resources/META-INF/aop.xml
+++ b/hadoop-ozone/ozone-manager/src/main/resources/META-INF/aop.xml
@@ -14,7 +14,7 @@
-->