Skip to content

Commit

Permalink
YARN-11483. Fix CheckStyle.
Browse files Browse the repository at this point in the history
  • Loading branch information
slfan1989 committed Nov 8, 2023
1 parent d789bf6 commit 4721e3f
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public void setup() throws Exception {
return QueryFederationQueuePoliciesResponse.newInstance(1, 1, 1, 10, weights);
});


Configuration config = new Configuration();
config.setBoolean(YarnConfiguration.FEDERATION_ENABLED, true);

Expand Down Expand Up @@ -271,7 +272,7 @@ public void testListPolicies() throws Exception {
@Test
public void testBuildHelpMsg() throws Exception {
Map<String, RouterCLI.RouterCmdUsageInfos> adminUsage = rmAdminCLI.getAdminUsage();
assertEquals(2, adminUsage.size());
assertEquals(3, adminUsage.size());

RouterCLI.RouterCmdUsageInfos deregisterSubClusterUsageInfos =
adminUsage.get("-deregisterSubCluster");
Expand All @@ -291,5 +292,11 @@ public void testBuildHelpMsg() throws Exception {
policyExamplesMap.forEach((cmd, cmdExamples) -> {
assertEquals(2, cmdExamples.size());
});

RouterCLI.RouterCmdUsageInfos applicationUsageInfos = adminUsage.get("-application");
assertNotNull(applicationUsageInfos);
Map<String, List<String>> applicationExamplesMap = applicationUsageInfos.getExamples();
assertNotNull(applicationExamplesMap);
assertEquals(1, applicationExamplesMap.size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.apache.hadoop.thirdparty.protobuf.TextFormat;
import org.apache.hadoop.yarn.proto.YarnServerResourceManagerServiceProtos.DeleteFederationApplicationResponseProto;
import org.apache.hadoop.yarn.proto.YarnServerResourceManagerServiceProtos.DeleteFederationApplicationResponseProtoOrBuilder;
import org.apache.hadoop.yarn.server.api.protocolrecords.DeleteFederationApplicationRequest;
import org.apache.hadoop.yarn.server.api.protocolrecords.DeleteFederationApplicationResponse;

@Private
Expand Down Expand Up @@ -57,7 +56,7 @@ public int hashCode() {

@Override
public boolean equals(Object other) {
if (!(other instanceof DeleteFederationApplicationRequest)) {
if (!(other instanceof DeleteFederationApplicationResponse)) {
return false;
}
DeleteFederationApplicationResponsePBImpl otherImpl = this.getClass().cast(other);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ public final class RouterMetrics {
private MutableGaugeInt numBatchSaveFederationQueuePoliciesFailedRetrieved;
@Metric("# of listFederationQueuePolicies failed to be retrieved")
private MutableGaugeInt numListFederationQueuePoliciesFailedRetrieved;
@Metric("# of deleteFederationApplication failed to be retrieved")
private MutableGaugeInt numDeleteFederationApplicationFailedRetrieved;
@Metric("# of refreshAdminAcls failed to be retrieved")
private MutableGaugeInt numRefreshAdminAclsFailedRetrieved;
@Metric("# of refreshServiceAcls failed to be retrieved")
Expand Down Expand Up @@ -307,6 +309,8 @@ public final class RouterMetrics {
private MutableRate totalSucceededBatchSaveFederationQueuePoliciesRetrieved;
@Metric("Total number of successful Retrieved ListFederationQueuePolicies and latency(ms)")
private MutableRate totalSucceededListFederationQueuePoliciesFailedRetrieved;
@Metric("Total number of successful Retrieved DeleteFederationApplication and latency(ms)")
private MutableRate totalSucceededDeleteFederationApplicationFailedRetrieved;
@Metric("Total number of successful Retrieved RefreshAdminAcls and latency(ms)")
private MutableRate totalSucceededRefreshAdminAclsRetrieved;
@Metric("Total number of successful Retrieved RefreshServiceAcls and latency(ms)")
Expand Down Expand Up @@ -396,6 +400,7 @@ public final class RouterMetrics {
private MutableQuantiles saveFederationQueuePolicyLatency;
private MutableQuantiles batchSaveFederationQueuePoliciesLatency;
private MutableQuantiles listFederationQueuePoliciesLatency;
private MutableQuantiles deleteFederationApplicationLatency;
private MutableQuantiles refreshAdminAclsLatency;
private MutableQuantiles refreshServiceAclsLatency;
private MutableQuantiles replaceLabelsOnNodesLatency;
Expand Down Expand Up @@ -618,6 +623,10 @@ private RouterMetrics() {
"listFederationQueuePoliciesLatency",
"latency of list federationqueuepolicies timeouts", "ops", "latency", 10);

deleteFederationApplicationLatency = registry.newQuantiles(
"deleteFederationApplicationLatency",
"latency of delete FederationApplication timeouts", "ops", "latency", 10);

refreshAdminAclsLatency = registry.newQuantiles("refreshAdminAclsLatency",
"latency of refresh admin acls timeouts", "ops", "latency", 10);

Expand Down Expand Up @@ -962,6 +971,11 @@ public long getNumSucceededListFederationQueuePoliciesFailedRetrieved() {
return totalSucceededListFederationQueuePoliciesFailedRetrieved.lastStat().numSamples();
}

@VisibleForTesting
public long getNumSucceededDeleteFederationApplicationFailedRetrieved() {
return totalSucceededDeleteFederationApplicationFailedRetrieved.lastStat().numSamples();
}

@VisibleForTesting
public long getNumSucceededRefreshAdminAclsRetrieved() {
return totalSucceededRefreshAdminAclsRetrieved.lastStat().numSamples();
Expand Down Expand Up @@ -1322,6 +1336,11 @@ public double getLatencySucceededListFederationQueuePoliciesRetrieved() {
return totalSucceededListFederationQueuePoliciesFailedRetrieved.lastStat().mean();
}

@VisibleForTesting
public double getLatencySucceededDeleteFederationApplicationFailedRetrieved() {
return totalSucceededDeleteFederationApplicationFailedRetrieved.lastStat().mean();
}

@VisibleForTesting
public double getLatencySucceededRefreshAdminAclsRetrieved() {
return totalSucceededRefreshAdminAclsRetrieved.lastStat().mean();
Expand Down Expand Up @@ -1629,6 +1648,10 @@ public int getListFederationQueuePoliciesFailedRetrieved() {
return numListFederationQueuePoliciesFailedRetrieved.value();
}

public int getDeleteFederationApplicationFailedRetrieved() {
return numDeleteFederationApplicationFailedRetrieved.value();
}

public int getNumRefreshAdminAclsFailedRetrieved() {
return numRefreshAdminAclsFailedRetrieved.value();
}
Expand Down Expand Up @@ -1996,6 +2019,11 @@ public void succeededListFederationQueuePoliciesRetrieved(long duration) {
listFederationQueuePoliciesLatency.add(duration);
}

public void succeededDeleteFederationApplicationFailedRetrieved(long duration) {
totalSucceededDeleteFederationApplicationFailedRetrieved.add(duration);
deleteFederationApplicationLatency.add(duration);
}

public void succeededRefreshAdminAclsRetrieved(long duration) {
totalSucceededRefreshAdminAclsRetrieved.add(duration);
refreshAdminAclsLatency.add(duration);
Expand Down Expand Up @@ -2286,6 +2314,10 @@ public void incrListFederationQueuePoliciesFailedRetrieved() {
numListFederationQueuePoliciesFailedRetrieved.incr();
}

public void incrDeleteFederationApplicationFailedRetrieved() {
numDeleteFederationApplicationFailedRetrieved.incr();
}

public void incrRefreshAdminAclsFailedRetrieved() {
numRefreshAdminAclsFailedRetrieved.incr();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1094,24 +1094,36 @@ public QueryFederationQueuePoliciesResponse listFederationQueuePolicies(
@Override
public DeleteFederationApplicationResponse deleteFederationApplication(
DeleteFederationApplicationRequest request) throws YarnException, IOException {

// Parameter validation.
if (request == null) {
routerMetrics.incrDeleteFederationApplicationFailedRetrieved();
RouterServerUtil.logAndThrowException(
"Missing deleteFederationApplication Request.", null);
}

String application = request.getApplication();
if (StringUtils.isBlank(application)) {
routerMetrics.incrDeleteFederationApplicationFailedRetrieved();
RouterServerUtil.logAndThrowException(
"ApplicationId cannot be null.", null);
}

// Try calling deleteApplicationHomeSubCluster to delete the application.
try {
ApplicationId applicationId = ApplicationId.fromString(request.getApplication());
long startTime = clock.getTime();
ApplicationId applicationId = ApplicationId.fromString(application);
federationFacade.deleteApplicationHomeSubCluster(applicationId);
long stopTime = clock.getTime();
routerMetrics.succeededDeleteFederationApplicationFailedRetrieved(stopTime - startTime);
return DeleteFederationApplicationResponse.newInstance(
"application = " + applicationId + " delete success.");
"applicationId = " + applicationId + " delete success.");
} catch (Exception e) {
RouterServerUtil.logAndThrowException(e,
"Unable to deleteFederationApplication due to exception. " + e.getMessage());
}

throw new YarnException("Unable to listFederationQueuePolicies.");
throw new YarnException("Unable to deleteFederationApplication.");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
import org.apache.hadoop.test.LambdaTestUtils;
import org.apache.hadoop.yarn.api.records.ApplicationId;
import org.apache.hadoop.yarn.api.records.DecommissionType;
import org.apache.hadoop.yarn.api.records.NodeId;
import org.apache.hadoop.yarn.api.records.Resource;
Expand All @@ -31,13 +32,48 @@
import org.apache.hadoop.yarn.api.records.NodeAttributeType;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.exceptions.YarnException;
import org.apache.hadoop.yarn.server.api.protocolrecords.*;
import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshNodesRequest;
import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshQueuesRequest;
import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshQueuesResponse;
import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshSuperUserGroupsConfigurationRequest;
import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshSuperUserGroupsConfigurationResponse;
import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshUserToGroupsMappingsRequest;
import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshUserToGroupsMappingsResponse;
import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshAdminAclsRequest;
import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshAdminAclsResponse;
import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshServiceAclsRequest;
import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshServiceAclsResponse;
import org.apache.hadoop.yarn.server.api.protocolrecords.UpdateNodeResourceRequest;
import org.apache.hadoop.yarn.server.api.protocolrecords.UpdateNodeResourceResponse;
import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshNodesResourcesRequest;
import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshNodesResourcesResponse;
import org.apache.hadoop.yarn.server.api.protocolrecords.AddToClusterNodeLabelsRequest;
import org.apache.hadoop.yarn.server.api.protocolrecords.AddToClusterNodeLabelsResponse;
import org.apache.hadoop.yarn.server.api.protocolrecords.RemoveFromClusterNodeLabelsRequest;
import org.apache.hadoop.yarn.server.api.protocolrecords.RemoveFromClusterNodeLabelsResponse;
import org.apache.hadoop.yarn.server.api.protocolrecords.ReplaceLabelsOnNodeRequest;
import org.apache.hadoop.yarn.server.api.protocolrecords.ReplaceLabelsOnNodeResponse;
import org.apache.hadoop.yarn.server.api.protocolrecords.CheckForDecommissioningNodesRequest;
import org.apache.hadoop.yarn.server.api.protocolrecords.CheckForDecommissioningNodesResponse;
import org.apache.hadoop.yarn.server.api.protocolrecords.NodesToAttributesMappingRequest;
import org.apache.hadoop.yarn.server.api.protocolrecords.AttributeMappingOperationType;
import org.apache.hadoop.yarn.server.api.protocolrecords.NodeToAttributes;
import org.apache.hadoop.yarn.server.api.protocolrecords.FederationQueueWeight;
import org.apache.hadoop.yarn.server.api.protocolrecords.SaveFederationQueuePolicyRequest;
import org.apache.hadoop.yarn.server.api.protocolrecords.SaveFederationQueuePolicyResponse;
import org.apache.hadoop.yarn.server.api.protocolrecords.BatchSaveFederationQueuePoliciesRequest;
import org.apache.hadoop.yarn.server.api.protocolrecords.BatchSaveFederationQueuePoliciesResponse;
import org.apache.hadoop.yarn.server.api.protocolrecords.QueryFederationQueuePoliciesRequest;
import org.apache.hadoop.yarn.server.api.protocolrecords.QueryFederationQueuePoliciesResponse;
import org.apache.hadoop.yarn.server.api.protocolrecords.DeleteFederationApplicationRequest;
import org.apache.hadoop.yarn.server.api.protocolrecords.DeleteFederationApplicationResponse;
import org.apache.hadoop.yarn.server.federation.policies.dao.WeightedPolicyInfo;
import org.apache.hadoop.yarn.server.federation.policies.manager.WeightedLocalityPolicyManager;
import org.apache.hadoop.yarn.server.federation.store.impl.MemoryFederationStateStore;
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId;
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterIdInfo;
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterPolicyConfiguration;
import org.apache.hadoop.yarn.server.federation.store.records.ApplicationHomeSubCluster;
import org.apache.hadoop.yarn.server.federation.utils.FederationStateStoreFacade;
import org.apache.hadoop.yarn.server.federation.utils.FederationStateStoreTestUtil;
import org.junit.Assert;
Expand Down Expand Up @@ -960,10 +996,25 @@ public void testFilterPoliciesConfigurationsByQueues() throws Exception {


@Test
public void testDeleteFederationApplication() throws IOException, YarnException {
DeleteFederationApplicationRequest request =
DeleteFederationApplicationRequest.newInstance("application_1");
DeleteFederationApplicationResponse response = interceptor.deleteFederationApplication(request);
assertNotNull(response);
public void testDeleteFederationApplication() throws Exception {
ApplicationId applicationId = ApplicationId.newInstance(10, 1);
DeleteFederationApplicationRequest request1 =
DeleteFederationApplicationRequest.newInstance(applicationId.toString());
LambdaTestUtils.intercept(YarnException.class,
"Application application_10_0001 does not exist.",
() -> interceptor.deleteFederationApplication(request1));

ApplicationId applicationId2 = ApplicationId.newInstance(10, 2);
SubClusterId homeSubCluster = SubClusterId.newInstance("SC-1");
ApplicationHomeSubCluster appHomeSubCluster =
ApplicationHomeSubCluster.newInstance(applicationId2, homeSubCluster);
facade.addApplicationHomeSubCluster(appHomeSubCluster);
DeleteFederationApplicationRequest request2 =
DeleteFederationApplicationRequest.newInstance(applicationId2.toString());
DeleteFederationApplicationResponse deleteFederationApplicationResponse =
interceptor.deleteFederationApplication(request2);
assertNotNull(deleteFederationApplicationResponse);
assertEquals("applicationId = " + applicationId2 + " delete success.",
deleteFederationApplicationResponse.getMessage());
}
}

0 comments on commit 4721e3f

Please sign in to comment.