From 70d0c6ae907d1e9519fda8bf75b77e05fa581714 Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Sun, 14 Aug 2022 04:56:48 -0700 Subject: [PATCH] YARN-9708. Fix CheckStyle. --- .../store/records/RouterStoreToken.java | 6 +- ...> RemoveStoredMasterKeyRequestPBImpl.java} | 33 ++--- .../RemoveStoredMasterKeyResponsePBImpl.java | 108 +++++++++++++++ .../pb/StoreNewMasterKeyRequestPBImpl.java | 8 +- .../pb/StoreNewMasterKeyResponsePBImpl.java | 126 ++++++++++++++++++ .../TestFederationProtocolRecords.java | 7 + 6 files changed, 265 insertions(+), 23 deletions(-) rename hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/impl/pb/{RemoveNewMasterKeyRequestPBImpl.java => RemoveStoredMasterKeyRequestPBImpl.java} (77%) create mode 100644 hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/impl/pb/RemoveStoredMasterKeyResponsePBImpl.java create mode 100644 hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/impl/pb/StoreNewMasterKeyResponsePBImpl.java diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/RouterStoreToken.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/RouterStoreToken.java index e77301bd92e74..a1a895ab8eeb1 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/RouterStoreToken.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/RouterStoreToken.java @@ -62,9 +62,9 @@ public byte[] toByteArray() throws IOException { public RMDelegationTokenIdentifier getTokenIdentifier() throws IOException { ByteArrayInputStream in = new ByteArrayInputStream(builder.getTokenIdentifier().toByteArray()); - RMDelegationTokenIdentifier identifer = new RMDelegationTokenIdentifier(); - identifer.readFields(new DataInputStream(in)); - return identifer; + RMDelegationTokenIdentifier identifier = new RMDelegationTokenIdentifier(); + identifier.readFields(new DataInputStream(in)); + return identifier; } public Long getRenewDate() { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/impl/pb/RemoveNewMasterKeyRequestPBImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/impl/pb/RemoveStoredMasterKeyRequestPBImpl.java similarity index 77% rename from hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/impl/pb/RemoveNewMasterKeyRequestPBImpl.java rename to hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/impl/pb/RemoveStoredMasterKeyRequestPBImpl.java index 9555a4874db9a..6f3f119082d89 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/impl/pb/RemoveNewMasterKeyRequestPBImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/impl/pb/RemoveStoredMasterKeyRequestPBImpl.java @@ -16,36 +16,36 @@ */ package org.apache.hadoop.yarn.server.federation.store.records.impl.pb; -import org.apache.hadoop.classification.InterfaceAudience; -import org.apache.hadoop.classification.InterfaceStability; +import org.apache.hadoop.classification.InterfaceAudience.Private; +import org.apache.hadoop.classification.InterfaceStability.Unstable; import org.apache.hadoop.thirdparty.protobuf.TextFormat; import org.apache.hadoop.yarn.federation.proto.YarnServerFederationProtos.RouterMasterKeyProto; -import org.apache.hadoop.yarn.federation.proto.YarnServerFederationProtos.StoreNewMasterKeyRequestProto; -import org.apache.hadoop.yarn.federation.proto.YarnServerFederationProtos.StoreNewMasterKeyRequestProtoOrBuilder; +import org.apache.hadoop.yarn.federation.proto.YarnServerFederationProtos.RemoveStoredMasterKeyRequestProto; +import org.apache.hadoop.yarn.federation.proto.YarnServerFederationProtos.RemoveStoredMasterKeyRequestProtoOrBuilder; +import org.apache.hadoop.yarn.server.federation.store.records.RemoveStoredMasterKeyRequest; import org.apache.hadoop.yarn.server.federation.store.records.RouterMasterKey; -import org.apache.hadoop.yarn.server.federation.store.records.StoreNewMasterKeyRequest; -@InterfaceAudience.Private -@InterfaceStability.Unstable -public class RemoveNewMasterKeyRequestPBImpl extends StoreNewMasterKeyRequest { +@Private +@Unstable +public class RemoveStoredMasterKeyRequestPBImpl extends RemoveStoredMasterKeyRequest { - private StoreNewMasterKeyRequestProto proto = StoreNewMasterKeyRequestProto.getDefaultInstance(); + private RemoveStoredMasterKeyRequestProto proto = RemoveStoredMasterKeyRequestProto.getDefaultInstance(); - private StoreNewMasterKeyRequestProto.Builder builder = null; + private RemoveStoredMasterKeyRequestProto.Builder builder = null; private boolean viaProto = false; private RouterMasterKey routerMasterKey = null; - public RemoveNewMasterKeyRequestPBImpl() { - builder = StoreNewMasterKeyRequestProto.newBuilder(); + public RemoveStoredMasterKeyRequestPBImpl() { + builder = RemoveStoredMasterKeyRequestProto.newBuilder(); } - public RemoveNewMasterKeyRequestPBImpl(StoreNewMasterKeyRequestProto proto) { + public RemoveStoredMasterKeyRequestPBImpl(RemoveStoredMasterKeyRequestProto proto) { this.proto = proto; viaProto = true; } - public StoreNewMasterKeyRequestProto getProto() { + public RemoveStoredMasterKeyRequestProto getProto() { mergeLocalToProto(); proto = viaProto ? proto : builder.build(); viaProto = true; @@ -63,7 +63,7 @@ private void mergeLocalToProto() { private void maybeInitBuilder() { if (viaProto || builder == null) { - builder = StoreNewMasterKeyRequestProto.newBuilder(proto); + builder = RemoveStoredMasterKeyRequestProto.newBuilder(proto); } viaProto = false; } @@ -100,7 +100,7 @@ public String toString() { @Override public RouterMasterKey getRouterMasterKey() { - StoreNewMasterKeyRequestProtoOrBuilder p = viaProto ? proto : builder; + RemoveStoredMasterKeyRequestProtoOrBuilder p = viaProto ? proto : builder; if (this.routerMasterKey != null) { return this.routerMasterKey; } @@ -116,6 +116,7 @@ public void setRouterMasterKey(RouterMasterKey masterKey) { maybeInitBuilder(); if (masterKey == null) { builder.clearRouterMasterKey(); + return; } this.routerMasterKey = masterKey; } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/impl/pb/RemoveStoredMasterKeyResponsePBImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/impl/pb/RemoveStoredMasterKeyResponsePBImpl.java new file mode 100644 index 0000000000000..3a136d96abda7 --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/impl/pb/RemoveStoredMasterKeyResponsePBImpl.java @@ -0,0 +1,108 @@ +/** + * 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.yarn.server.federation.store.records.impl.pb; + +import org.apache.hadoop.yarn.federation.proto.YarnServerFederationProtos; +import org.apache.hadoop.yarn.federation.proto.YarnServerFederationProtos.RouterMasterKeyProto; +import org.apache.hadoop.yarn.federation.proto.YarnServerFederationProtos.RemoveStoredMasterKeyResponseProto; +import org.apache.hadoop.yarn.federation.proto.YarnServerFederationProtos.RemoveStoredMasterKeyResponseProtoOrBuilder; +import org.apache.hadoop.yarn.server.federation.store.records.RemoveStoredMasterKeyResponse; +import org.apache.hadoop.yarn.server.federation.store.records.RouterMasterKey; + +public class RemoveStoredMasterKeyResponsePBImpl extends RemoveStoredMasterKeyResponse { + + private RemoveStoredMasterKeyResponseProto proto = + RemoveStoredMasterKeyResponseProto.getDefaultInstance(); + + private RemoveStoredMasterKeyResponseProto.Builder builder = null; + + private boolean viaProto = false; + + private RouterMasterKey routerMasterKey = null; + + public RemoveStoredMasterKeyResponsePBImpl() { + builder = RemoveStoredMasterKeyResponseProto.newBuilder(); + } + + public RemoveStoredMasterKeyResponsePBImpl(RemoveStoredMasterKeyResponseProto responseProto) { + this.proto = responseProto; + viaProto = true; + } + + public RemoveStoredMasterKeyResponseProto getProto() { + mergeLocalToProto(); + proto = viaProto ? proto : builder.build(); + viaProto = true; + return proto; + } + + private void mergeLocalToProto() { + if (viaProto) { + maybeInitBuilder(); + } + mergeLocalToBuilder(); + proto = builder.build(); + viaProto = true; + } + + private void maybeInitBuilder() { + if (viaProto || builder == null) { + builder = RemoveStoredMasterKeyResponseProto.newBuilder(proto); + } + viaProto = false; + } + + private void mergeLocalToBuilder() { + if (this.routerMasterKey != null && !((RouterMasterKeyPBImpl) this.routerMasterKey). + getProto().equals(builder.getRouterMasterKey())) { + builder.setRouterMasterKey(convertToProtoFormat(this.routerMasterKey)); + } + } + + private YarnServerFederationProtos.RouterMasterKeyProto convertToProtoFormat( + RouterMasterKey masterKey) { + return ((RouterMasterKeyPBImpl) masterKey).getProto(); + } + + + @Override + public RouterMasterKey getRouterMasterKey() { + RemoveStoredMasterKeyResponseProtoOrBuilder p = viaProto ? proto : builder; + if (this.routerMasterKey != null) { + return this.routerMasterKey; + } + if (!p.hasRouterMasterKey()) { + return null; + } + this.routerMasterKey = convertFromProtoFormat(p.getRouterMasterKey()); + return this.routerMasterKey; + } + + @Override + public void setRouterMasterKey(RouterMasterKey masterKey) { + maybeInitBuilder(); + if (masterKey == null) { + builder.clearRouterMasterKey(); + return; + } + this.routerMasterKey = masterKey; + } + + private RouterMasterKey convertFromProtoFormat(RouterMasterKeyProto masterKey) { + return new RouterMasterKeyPBImpl(masterKey); + } +} diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/impl/pb/StoreNewMasterKeyRequestPBImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/impl/pb/StoreNewMasterKeyRequestPBImpl.java index 7f9b63c874de9..ff569bee65397 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/impl/pb/StoreNewMasterKeyRequestPBImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/impl/pb/StoreNewMasterKeyRequestPBImpl.java @@ -16,8 +16,8 @@ */ package org.apache.hadoop.yarn.server.federation.store.records.impl.pb; -import org.apache.hadoop.classification.InterfaceAudience; -import org.apache.hadoop.classification.InterfaceStability; +import org.apache.hadoop.classification.InterfaceAudience.Private; +import org.apache.hadoop.classification.InterfaceStability.Unstable; import org.apache.hadoop.thirdparty.protobuf.TextFormat; import org.apache.hadoop.yarn.federation.proto.YarnServerFederationProtos.StoreNewMasterKeyRequestProto; import org.apache.hadoop.yarn.federation.proto.YarnServerFederationProtos.RouterMasterKeyProto; @@ -25,8 +25,8 @@ import org.apache.hadoop.yarn.server.federation.store.records.StoreNewMasterKeyRequest; import org.apache.hadoop.yarn.federation.proto.YarnServerFederationProtos.StoreNewMasterKeyRequestProtoOrBuilder; -@InterfaceAudience.Private -@InterfaceStability.Unstable +@Private +@Unstable public class StoreNewMasterKeyRequestPBImpl extends StoreNewMasterKeyRequest { private StoreNewMasterKeyRequestProto proto = StoreNewMasterKeyRequestProto.getDefaultInstance(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/impl/pb/StoreNewMasterKeyResponsePBImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/impl/pb/StoreNewMasterKeyResponsePBImpl.java new file mode 100644 index 0000000000000..61d7af86f041f --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/impl/pb/StoreNewMasterKeyResponsePBImpl.java @@ -0,0 +1,126 @@ +/** + * 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.yarn.server.federation.store.records.impl.pb; + +import org.apache.hadoop.classification.InterfaceAudience.Private; +import org.apache.hadoop.classification.InterfaceStability.Unstable; +import org.apache.hadoop.yarn.federation.proto.YarnServerFederationProtos.RouterMasterKeyProto; +import org.apache.hadoop.yarn.federation.proto.YarnServerFederationProtos.StoreNewMasterKeyResponseProto; +import org.apache.hadoop.yarn.federation.proto.YarnServerFederationProtos.StoreNewMasterKeyResponseProtoOrBuilder; +import org.apache.hadoop.yarn.server.federation.store.records.RouterMasterKey; +import org.apache.hadoop.yarn.server.federation.store.records.StoreNewMasterKeyResponse; + +@Private +@Unstable +public class StoreNewMasterKeyResponsePBImpl extends StoreNewMasterKeyResponse { + + private StoreNewMasterKeyResponseProto proto = + StoreNewMasterKeyResponseProto.getDefaultInstance(); + + private StoreNewMasterKeyResponseProto.Builder builder = null; + + private boolean viaProto = false; + + private RouterMasterKey routerMasterKey = null; + + public StoreNewMasterKeyResponsePBImpl() { + builder = StoreNewMasterKeyResponseProto.newBuilder(); + } + + public StoreNewMasterKeyResponsePBImpl(StoreNewMasterKeyResponseProto responseProto) { + this.proto = responseProto; + viaProto = true; + } + + public StoreNewMasterKeyResponseProto getProto() { + mergeLocalToProto(); + proto = viaProto ? proto : builder.build(); + viaProto = true; + return proto; + } + + private void mergeLocalToProto() { + if (viaProto) { + maybeInitBuilder(); + } + mergeLocalToBuilder(); + proto = builder.build(); + viaProto = true; + } + + private void maybeInitBuilder() { + if (viaProto || builder == null) { + builder = StoreNewMasterKeyResponseProto.newBuilder(proto); + } + viaProto = false; + } + + private void mergeLocalToBuilder() { + if (this.routerMasterKey != null && !((RouterMasterKeyPBImpl) this.routerMasterKey). + getProto().equals(builder.getRouterMasterKey())) { + builder.setRouterMasterKey(convertToProtoFormat(this.routerMasterKey)); + } + } + + @Override + public int hashCode() { + return getProto().hashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == null) { + return false; + } + if (other.getClass().isAssignableFrom(this.getClass())) { + return this.getProto().equals(this.getClass().cast(other).getProto()); + } + return false; + } + + private RouterMasterKeyProto convertToProtoFormat( + RouterMasterKey masterKey) { + return ((RouterMasterKeyPBImpl) masterKey).getProto(); + } + + @Override + public RouterMasterKey getRouterMasterKey() { + StoreNewMasterKeyResponseProtoOrBuilder p = viaProto ? proto : builder; + if (this.routerMasterKey != null) { + return this.routerMasterKey; + } + if (!p.hasRouterMasterKey()) { + return null; + } + this.routerMasterKey = convertFromProtoFormat(p.getRouterMasterKey()); + return this.routerMasterKey; + } + + @Override + public void setRouterMasterKey(RouterMasterKey masterKey) { + maybeInitBuilder(); + if (masterKey == null) { + builder.clearRouterMasterKey(); + return; + } + this.routerMasterKey = masterKey; + } + + private RouterMasterKey convertFromProtoFormat(RouterMasterKeyProto masterKey) { + return new RouterMasterKeyPBImpl(masterKey); + } +} diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/store/records/TestFederationProtocolRecords.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/store/records/TestFederationProtocolRecords.java index cf8cf719d01d5..85b619c48512e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/store/records/TestFederationProtocolRecords.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/store/records/TestFederationProtocolRecords.java @@ -47,6 +47,7 @@ import org.apache.hadoop.yarn.federation.proto.YarnServerFederationProtos.SubClusterRegisterResponseProto; import org.apache.hadoop.yarn.federation.proto.YarnServerFederationProtos.UpdateApplicationHomeSubClusterRequestProto; import org.apache.hadoop.yarn.federation.proto.YarnServerFederationProtos.UpdateApplicationHomeSubClusterResponseProto; +import org.apache.hadoop.yarn.federation.proto.YarnServerFederationProtos.StoreNewMasterKeyRequestProto; import org.apache.hadoop.yarn.server.federation.store.records.impl.pb.AddApplicationHomeSubClusterRequestPBImpl; import org.apache.hadoop.yarn.server.federation.store.records.impl.pb.AddApplicationHomeSubClusterResponsePBImpl; import org.apache.hadoop.yarn.server.federation.store.records.impl.pb.DeleteApplicationHomeSubClusterRequestPBImpl; @@ -75,6 +76,7 @@ import org.apache.hadoop.yarn.server.federation.store.records.impl.pb.SubClusterRegisterResponsePBImpl; import org.apache.hadoop.yarn.server.federation.store.records.impl.pb.UpdateApplicationHomeSubClusterRequestPBImpl; import org.apache.hadoop.yarn.server.federation.store.records.impl.pb.UpdateApplicationHomeSubClusterResponsePBImpl; +import org.apache.hadoop.yarn.server.federation.store.records.impl.pb.StoreNewMasterKeyRequestPBImpl; import org.apache.hadoop.yarn.server.records.Version; import org.junit.BeforeClass; import org.junit.Test; @@ -262,4 +264,9 @@ public void testGetSubClusterPoliciesConfigurationsResponse() GetSubClusterPoliciesConfigurationsResponsePBImpl.class, GetSubClusterPoliciesConfigurationsResponseProto.class); } + + @Test + public void testStoreNewMasterKeyRequest() throws Exception { + + } }