-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
YARN-11536. [Federation] Router CLI Supports Batch Save the SubCluste…
…rPolicyConfiguration Of Queues.
- Loading branch information
Showing
10 changed files
with
344 additions
and
4 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...pache/hadoop/yarn/server/api/protocolrecords/BatchSaveFederationQueuePoliciesRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* 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.api.protocolrecords; | ||
|
||
import org.apache.hadoop.classification.InterfaceAudience.Private; | ||
import org.apache.hadoop.classification.InterfaceAudience.Public; | ||
import org.apache.hadoop.classification.InterfaceStability.Unstable; | ||
import org.apache.hadoop.yarn.util.Records; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* In Federation mode, | ||
* we will support batch save queues policies to FederationStateStore. | ||
*/ | ||
@Private | ||
@Unstable | ||
public abstract class BatchSaveFederationQueuePoliciesRequest { | ||
|
||
@Private | ||
@Unstable | ||
public static BatchSaveFederationQueuePoliciesRequest newInstance( | ||
List<FederationQueueWeight> federationQueueWeights) { | ||
BatchSaveFederationQueuePoliciesRequest request = | ||
Records.newRecord(BatchSaveFederationQueuePoliciesRequest.class); | ||
request.setFederationQueueWeights(federationQueueWeights); | ||
return request; | ||
} | ||
|
||
@Public | ||
@Unstable | ||
public abstract List<FederationQueueWeight> getFederationQueueWeights(); | ||
|
||
@Private | ||
@Unstable | ||
public abstract void setFederationQueueWeights( | ||
List<FederationQueueWeight> federationQueueWeights); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
.../hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/util/MemoryPageUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* 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.client.util; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* This is a memory paging utility that is used to paginate a dataset. | ||
* | ||
* This class is designed to support batch entry queue policies. | ||
*/ | ||
public class MemoryPageUtils<T> { | ||
private List<T> dataList; | ||
private int pageSize; | ||
|
||
/** | ||
* MemoryPageUtils constructor. | ||
* | ||
* @param pageSize Number of records returned per page. | ||
*/ | ||
public MemoryPageUtils(int pageSize) { | ||
this.pageSize = pageSize; | ||
this.dataList = new ArrayList<>(); | ||
} | ||
|
||
public void addToMemory(T data) { | ||
dataList.add(data); | ||
} | ||
|
||
public List<T> readFromMemory(int pageNumber) { | ||
int startIndex = pageNumber * pageSize; | ||
int endIndex = Math.min(startIndex + pageSize, dataList.size()); | ||
if (startIndex >= dataList.size()) { | ||
return null; | ||
} | ||
return dataList.subList(startIndex, endIndex); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...n/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/TestMemoryPageUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* 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.client; | ||
|
||
import org.apache.hadoop.yarn.client.util.MemoryPageUtils; | ||
import org.junit.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
|
||
/** | ||
* The purpose of this class is to test | ||
* whether the memory paging function is as expected. | ||
*/ | ||
public class TestMemoryPageUtils { | ||
|
||
@Test | ||
public void testMemoryPage() { | ||
// We design such a unit test for testing pagination, and we prepare 6 pieces of policy data. | ||
// If 1 page is followed by 5 pieces of data, we will get 2 pages. | ||
// Page 1 will contain 5 records and page 2 will contain 1 record. | ||
MemoryPageUtils<String> policies = new MemoryPageUtils<>(5); | ||
policies.addToMemory("policy-1"); | ||
policies.addToMemory("policy-2"); | ||
policies.addToMemory("policy-3"); | ||
policies.addToMemory("policy-4"); | ||
policies.addToMemory("policy-5"); | ||
policies.addToMemory("policy-6"); | ||
|
||
// Page 1 will return 5 records. | ||
List<String> firstPage = policies.readFromMemory(0); | ||
assertEquals(5, firstPage.size()); | ||
|
||
// Page 2 will return 1 records | ||
List<String> secondPage = policies.readFromMemory(1); | ||
assertEquals(1, secondPage.size()); | ||
|
||
// Page 10, This is a wrong number of pages, we will get null. | ||
List<String> tenPage = policies.readFromMemory(10); | ||
assertNull(tenPage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/resources/federation-weights.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?xml version="1.0"?> | ||
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?> | ||
|
||
<!-- | ||
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. | ||
--> | ||
|
||
<federationWeights> | ||
<weight> | ||
<queue> | ||
<name>root.a</name> | ||
<amrmPolicyWeights> | ||
<subClusterIdInfo> | ||
<id>SC-1</id> | ||
<weight>0.7</weight> | ||
</subClusterIdInfo> | ||
<subClusterIdInfo> | ||
<id>SC-2</id> | ||
<weight>0.3</weight> | ||
</subClusterIdInfo> | ||
</amrmPolicyWeights> | ||
<routerPolicyWeights> | ||
<subClusterIdInfo> | ||
<id>SC-1</id> | ||
<weight>0.6</weight> | ||
</subClusterIdInfo> | ||
<subClusterIdInfo> | ||
<id>SC-2</id> | ||
<weight>0.4</weight> | ||
</subClusterIdInfo> | ||
</routerPolicyWeights> | ||
<headroomAlpha>1.0</headroomAlpha> | ||
</queue> | ||
</weight> | ||
</federationWeights> |
Oops, something went wrong.