From 5fecc410ca975da4eb54fd385915e5f86ab8cd34 Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Tue, 11 Jul 2023 23:56:30 +0800 Subject: [PATCH] YARN-11525. Fix CheckStyle. --- .../SaveFederationQueuePolicyResponse.java | 16 +++++++++++ ...erver_resourcemanager_service_protos.proto | 1 + .../hadoop/yarn/client/cli/RouterCLI.java | 1 + ...veFederationQueuePolicyResponsePBImpl.java | 28 +++++++++++++++++++ .../rmadmin/FederationRMAdminInterceptor.java | 2 +- .../TestFederationRMAdminInterceptor.java | 1 + 6 files changed, 48 insertions(+), 1 deletion(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/SaveFederationQueuePolicyResponse.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/SaveFederationQueuePolicyResponse.java index 4bff7022dc81a..827734f676e72 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/SaveFederationQueuePolicyResponse.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/SaveFederationQueuePolicyResponse.java @@ -17,6 +17,7 @@ */ package org.apache.hadoop.yarn.server.api.protocolrecords; +import org.apache.hadoop.classification.InterfaceAudience.Public; import org.apache.hadoop.classification.InterfaceAudience.Private; import org.apache.hadoop.classification.InterfaceStability.Unstable; import org.apache.hadoop.yarn.util.Records; @@ -27,4 +28,19 @@ public abstract class SaveFederationQueuePolicyResponse { public static SaveFederationQueuePolicyResponse newInstance() { return Records.newRecord(SaveFederationQueuePolicyResponse.class); } + + public static SaveFederationQueuePolicyResponse newInstance(String msg) { + SaveFederationQueuePolicyResponse response = + Records.newRecord(SaveFederationQueuePolicyResponse.class); + response.setMessage(msg); + return response; + } + + @Public + @Unstable + public abstract String getMessage(); + + @Public + @Unstable + public abstract void setMessage(String msg); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/server/yarn_server_resourcemanager_service_protos.proto b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/server/yarn_server_resourcemanager_service_protos.proto index c2ec535e5c439..4e330fb1e632f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/server/yarn_server_resourcemanager_service_protos.proto +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/server/yarn_server_resourcemanager_service_protos.proto @@ -177,6 +177,7 @@ message SaveFederationQueuePolicyRequestProto { } message SaveFederationQueuePolicyResponseProto { + required string message = 1; } ////////////////////////////////////////////////////////////////// diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RouterCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RouterCLI.java index e483e31170b72..1a8f1f06c6535 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RouterCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RouterCLI.java @@ -333,6 +333,7 @@ private int handleSavePolicy(String policy) { SaveFederationQueuePolicyRequest request = parsePolicy(policy); ResourceManagerAdministrationProtocol adminProtocol = createAdminProtocol(); SaveFederationQueuePolicyResponse response = adminProtocol.saveFederationQueuePolicy(request); + System.out.println(response.getMessage()); return EXIT_SUCCESS; } catch (YarnException | IOException e) { LOG.error("handleSavePolicy error.", e); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/impl/pb/SaveFederationQueuePolicyResponsePBImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/impl/pb/SaveFederationQueuePolicyResponsePBImpl.java index c627ec45f86f4..26f4ed0f60e02 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/impl/pb/SaveFederationQueuePolicyResponsePBImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/impl/pb/SaveFederationQueuePolicyResponsePBImpl.java @@ -20,6 +20,7 @@ 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.proto.YarnServerResourceManagerServiceProtos.SaveFederationQueuePolicyResponseProtoOrBuilder; import org.apache.hadoop.yarn.proto.YarnServerResourceManagerServiceProtos.SaveFederationQueuePolicyResponseProto; import org.apache.hadoop.yarn.server.api.protocolrecords.SaveFederationQueuePolicyResponse; @@ -65,4 +66,31 @@ public boolean equals(Object other) { public String toString() { return TextFormat.shortDebugString(getProto()); } + + @Override + public String getMessage() { + SaveFederationQueuePolicyResponseProtoOrBuilder p = viaProto ? proto : builder; + boolean hasMessage = p.hasMessage(); + if (hasMessage) { + return p.getMessage(); + } + return null; + } + + private synchronized void maybeInitBuilder() { + if (viaProto || builder == null) { + builder = SaveFederationQueuePolicyResponseProto.newBuilder(proto); + } + viaProto = false; + } + + @Override + public void setMessage(String msg) { + maybeInitBuilder(); + if (msg == null) { + builder.clearMessage(); + return; + } + builder.setMessage(msg); + } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/rmadmin/FederationRMAdminInterceptor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/rmadmin/FederationRMAdminInterceptor.java index 5a3ad80074b85..15fbb78f205c6 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/rmadmin/FederationRMAdminInterceptor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/rmadmin/FederationRMAdminInterceptor.java @@ -930,7 +930,7 @@ public SaveFederationQueuePolicyResponse saveFederationQueuePolicy( federationFacade.setPolicyConfiguration(policyConfiguration); long stopTime = clock.getTime(); routerMetrics.succeededSaveFederationQueuePolicyRetrieved(stopTime - startTime); - return SaveFederationQueuePolicyResponse.newInstance(); + return SaveFederationQueuePolicyResponse.newInstance("save policy success."); } catch (Exception e) { routerMetrics.incrSaveFederationQueuePolicyFailedRetrieved(); RouterServerUtil.logAndThrowException(e, diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/rmadmin/TestFederationRMAdminInterceptor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/rmadmin/TestFederationRMAdminInterceptor.java index b3260d55c0399..402325037a1df 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/rmadmin/TestFederationRMAdminInterceptor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/rmadmin/TestFederationRMAdminInterceptor.java @@ -641,6 +641,7 @@ public void testSaveFederationQueuePolicyRequest() throws IOException, YarnExcep SaveFederationQueuePolicyRequest.newInstance(queue, federationQueueWeight, policyTypeName); SaveFederationQueuePolicyResponse response = interceptor.saveFederationQueuePolicy(request); assertNotNull(response); + assertEquals("save policy success.", response.getMessage()); FederationStateStoreFacade federationFacade = interceptor.getFederationFacade(); SubClusterPolicyConfiguration policyConfiguration = federationFacade.getPolicyConfiguration(queue);