Skip to content

Commit 1fa7f65

Browse files
committed
YARN-11536. Fix CheckStyle.
1 parent 6de2cf6 commit 1fa7f65

File tree

10 files changed

+209
-63
lines changed

10 files changed

+209
-63
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/FederationQueueWeight.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,16 @@ protected static boolean isNumeric(String value) {
195195
@Public
196196
@Unstable
197197
public abstract void setPolicyManagerClassName(String policyManagerClassName);
198+
199+
@Override
200+
public String toString() {
201+
StringBuilder builder = new StringBuilder();
202+
builder.append("FederationQueueWeight{");
203+
builder.append("Queue:" + getQueue() + ", ");
204+
builder.append("RouterWeight:" + getRouterWeight() + ", ");
205+
builder.append("AmrmWeight:" + getAmrmWeight() + ", ");
206+
builder.append("PolicyManagerClassName:" + getPolicyManagerClassName());
207+
builder.append("}");
208+
return builder.toString();
209+
}
198210
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RouterCLI.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
import org.apache.hadoop.yarn.server.api.protocolrecords.DeregisterSubClusters;
4242
import org.apache.hadoop.yarn.server.api.protocolrecords.SaveFederationQueuePolicyRequest;
4343
import org.apache.hadoop.yarn.server.api.protocolrecords.SaveFederationQueuePolicyResponse;
44+
import org.apache.hadoop.yarn.server.api.protocolrecords.BatchSaveFederationQueuePoliciesRequest;
45+
import org.apache.hadoop.yarn.server.api.protocolrecords.BatchSaveFederationQueuePoliciesResponse;
4446
import org.apache.hadoop.yarn.server.api.protocolrecords.FederationQueueWeight;
4547
import org.slf4j.Logger;
4648
import org.slf4j.LoggerFactory;
@@ -83,7 +85,7 @@ public class RouterCLI extends Configured implements Tool {
8385
// Command2: policy
8486
.put("-policy", new UsageInfo(
8587
"[-s|--save [queue;router weight;amrm weight;headroomalpha]] " +
86-
"[-bs|--batch-save [--format xml,json] [-f|--input-file fileName]]",
88+
"[-bs|--batch-save [--format xml] [-f|--input-file fileName]]",
8789
"We provide a set of commands for Policy:" +
8890
" Include list policies, save policies, batch save policies. " +
8991
" (Note: The policy type will be directly read from the" +
@@ -419,15 +421,12 @@ private int handBatchSavePolicies(String format, String policyFile) {
419421
LOG.info("Batch Save Federation Policies. Format = {}, PolicyFile = {}.",
420422
format, policyFile);
421423
switch (format) {
422-
case FORMAT_JSON:
423-
break;
424-
case FORMAT_XML:
425-
return parseXml2Policies(policyFile);
426-
default:
427-
System.out.println("We currently only support JSON and XML formats.");
428-
return EXIT_ERROR;
424+
case FORMAT_XML:
425+
return parseXml2Policies(policyFile);
426+
default:
427+
System.out.println("We currently only support XML formats.");
428+
return EXIT_ERROR;
429429
}
430-
return EXIT_ERROR;
431430
}
432431

433432
/**
@@ -474,18 +473,25 @@ protected SaveFederationQueuePolicyRequest parsePolicy(String policy) throws Yar
474473

475474
protected int parseXml2Policies(String policiesXml) {
476475
try {
477-
List<FederationQueueWeight> federationQueueWeights = parsePoliciesByXml(policiesXml);
476+
List<FederationQueueWeight> federationQueueWeightsList = parsePoliciesByXml(policiesXml);
478477
MemoryPageUtils<FederationQueueWeight> memoryPageUtils = new MemoryPageUtils<>(20);
479-
federationQueueWeights.forEach(federationQueueWeight ->
478+
federationQueueWeightsList.forEach(federationQueueWeight ->
480479
memoryPageUtils.addToMemory(federationQueueWeight));
481480
int pages = memoryPageUtils.getPages();
482481
for (int i = 0; i < pages; i++) {
483-
482+
List<FederationQueueWeight> federationQueueWeights =
483+
memoryPageUtils.readFromMemory(i);
484+
BatchSaveFederationQueuePoliciesRequest request =
485+
BatchSaveFederationQueuePoliciesRequest.newInstance(federationQueueWeights);
486+
ResourceManagerAdministrationProtocol adminProtocol = createAdminProtocol();
487+
BatchSaveFederationQueuePoliciesResponse response =
488+
adminProtocol.batchSaveFederationQueuePolicies(request);
489+
System.out.println("page<" + i + "> : " + response.getMessage());
484490
}
485491
} catch (Exception e) {
486-
492+
LOG.error("BatchSaveFederationQueuePolicies error", e);
487493
}
488-
return 0;
494+
return EXIT_ERROR;
489495
}
490496

491497
protected List<FederationQueueWeight> parsePoliciesByXml(String policiesXml)

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestRouterCLI.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
import org.mockito.stubbing.Answer;
3535

3636
import java.io.ByteArrayOutputStream;
37-
import java.io.File;
38-
import java.io.InputStream;
3937
import java.io.PrintStream;
4038
import java.util.ArrayList;
4139
import java.util.Date;

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/server/api/impl/pb/client/ResourceManagerAdministrationProtocolPBClientImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.apache.hadoop.ipc.RPC;
3030
import org.apache.hadoop.yarn.exceptions.YarnException;
3131
import org.apache.hadoop.yarn.ipc.RPCUtil;
32-
import org.apache.hadoop.yarn.proto.YarnServerResourceManagerServiceProtos;
3332
import org.apache.hadoop.yarn.proto.YarnServerResourceManagerServiceProtos.AddToClusterNodeLabelsRequestProto;
3433
import org.apache.hadoop.yarn.proto.YarnServerResourceManagerServiceProtos.CheckForDecommissioningNodesRequestProto;
3534
import org.apache.hadoop.yarn.proto.YarnServerResourceManagerServiceProtos.GetGroupsForUserRequestProto;

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/server/api/impl/pb/service/ResourceManagerAdministrationProtocolPBServiceImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,11 @@ public SaveFederationQueuePolicyResponseProto saveFederationQueuePolicy(RpcContr
410410
public BatchSaveFederationQueuePoliciesResponseProto batchSaveFederationQueuePolicies(
411411
RpcController controller, BatchSaveFederationQueuePoliciesRequestProto proto)
412412
throws ServiceException {
413-
BatchSaveFederationQueuePoliciesRequest request = new BatchSaveFederationQueuePoliciesRequestPBImpl(proto);
413+
BatchSaveFederationQueuePoliciesRequest request =
414+
new BatchSaveFederationQueuePoliciesRequestPBImpl(proto);
414415
try {
415-
BatchSaveFederationQueuePoliciesResponse response = real.batchSaveFederationQueuePolicies(request);
416+
BatchSaveFederationQueuePoliciesResponse response =
417+
real.batchSaveFederationQueuePolicies(request);
416418
return ((BatchSaveFederationQueuePoliciesResponsePBImpl) response).getProto();
417419
} catch (YarnException e) {
418420
throw new ServiceException(e);

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/impl/pb/BatchSaveFederationQueuePoliciesRequestPBImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private void mergeLocalToProto() {
6868
if (this.federationQueueWeights != null) {
6969
for (FederationQueueWeight federationQueueWeight : federationQueueWeights) {
7070
FederationQueueWeightPBImpl federationQueueWeightPBImpl =
71-
(FederationQueueWeightPBImpl) federationQueueWeight;
71+
(FederationQueueWeightPBImpl) federationQueueWeight;
7272
builder.addFederationQueueWeights(federationQueueWeightPBImpl.getProto());
7373
}
7474
}
@@ -85,7 +85,7 @@ public BatchSaveFederationQueuePoliciesRequestProto getProto() {
8585

8686
private void initDeregisterSubClustersMapping() {
8787
if (this.federationQueueWeights != null) {
88-
return;
88+
return;
8989
}
9090

9191
BatchSaveFederationQueuePoliciesRequestProtoOrBuilder p = viaProto ? proto : builder;
@@ -105,7 +105,7 @@ private void initDeregisterSubClustersMapping() {
105105
}
106106

107107
this.federationQueueWeights = attributes;
108-
}
108+
}
109109

110110
@Override
111111
public List<FederationQueueWeight> getFederationQueueWeights() {
@@ -133,7 +133,7 @@ public int hashCode() {
133133
@Override
134134
public boolean equals(Object other) {
135135
if (!(other instanceof BatchSaveFederationQueuePoliciesRequest)) {
136-
return false;
136+
return false;
137137
}
138138

139139
BatchSaveFederationQueuePoliciesRequestPBImpl otherImpl = this.getClass().cast(other);

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/impl/pb/BatchSaveFederationQueuePoliciesResponsePBImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public String getMessage() {
7979
public void setMessage(String msg) {
8080
maybeInitBuilder();
8181
if (msg == null) {
82-
builder.clearMessage();
83-
return;
82+
builder.clearMessage();
83+
return;
8484
}
8585
builder.setMessage(msg);
8686
}
@@ -94,6 +94,6 @@ private synchronized void maybeInitBuilder() {
9494

9595
@Override
9696
public String toString() {
97-
return TextFormat.shortDebugString(getProto());
97+
return TextFormat.shortDebugString(getProto());
9898
}
9999
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/AdminService.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,13 +1058,35 @@ public DeregisterSubClusterResponse deregisterSubCluster(
10581058
"Please call Router's deregisterSubCluster to set.");
10591059
}
10601060

1061+
/**
1062+
* In YARN-Federation mode, We will be storing the Policy information for Queues.
1063+
*
1064+
* RM does not support saveFederationQueuePolicy,
1065+
* saveFederationQueuePolicy is supported by Router.
1066+
*
1067+
* @param request saveFederationQueuePolicy Request
1068+
* @return Response from saveFederationQueuePolicy.
1069+
* @throws YarnException exceptions from yarn servers.
1070+
* @throws IOException if an IO error occurred.
1071+
*/
10611072
@Override
10621073
public SaveFederationQueuePolicyResponse saveFederationQueuePolicy(
10631074
SaveFederationQueuePolicyRequest request) throws YarnException, IOException {
10641075
throw new YarnException("It is not allowed to call the RM's saveFederationQueuePolicy. " +
10651076
" Please call Router's saveFederationQueuePolicy to set Policy.");
10661077
}
10671078

1079+
/**
1080+
* In YARN-Federation mode, this method provides a way to save queue policies in batches.
1081+
*
1082+
* RM does not support batchSaveFederationQueuePolicies,
1083+
* batchSaveFederationQueuePolicies is supported by Router.
1084+
*
1085+
* @param request BatchSaveFederationQueuePolicies Request
1086+
* @return Response from batchSaveFederationQueuePolicies.
1087+
* @throws YarnException exceptions from yarn servers.
1088+
* @throws IOException if an IO error occurred.
1089+
*/
10681090
@Override
10691091
public BatchSaveFederationQueuePoliciesResponse batchSaveFederationQueuePolicies(
10701092
BatchSaveFederationQueuePoliciesRequest request) throws YarnException, IOException {

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/rmadmin/FederationRMAdminInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ private void saveFederationQueuePolicy(FederationQueueWeight federationQueueWeig
10581058
* @param policyWeight policyWeight.
10591059
* @return Map of SubClusterWeight.
10601060
*/
1061-
private Map<SubClusterIdInfo, Float> getSubClusterWeightMap(String policyWeight)
1061+
protected Map<SubClusterIdInfo, Float> getSubClusterWeightMap(String policyWeight)
10621062
throws YarnException {
10631063
FederationQueueWeight.checkSubClusterQueueWeightRatioValid(policyWeight);
10641064
Map<SubClusterIdInfo, Float> result = new HashMap<>();

0 commit comments

Comments
 (0)