pendingOrderingPolicyRecovery) {
- if (null != this.pendingOPForRecoveredApps) {
- pendingOrderingPolicyRecovery
- .addAllSchedulableEntities(this.pendingOPForRecoveredApps
- .getSchedulableEntities());
- }
- this.pendingOPForRecoveredApps = pendingOrderingPolicyRecovery;
- }
/*
* Holds shared values used by all applications in
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/policy/FifoOrderingPolicyForPendingApps.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/policy/FifoOrderingPolicyForPendingApps.java
new file mode 100644
index 00000000000..08912893942
--- /dev/null
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/policy/FifoOrderingPolicyForPendingApps.java
@@ -0,0 +1,73 @@
+/**
+ * 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.resourcemanager.scheduler.policy;
+
+import java.util.*;
+
+import org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer;
+
+/**
+ * This ordering policy is used for pending applications only.
+ * An OrderingPolicy which orders SchedulableEntities by
+ *
+ * - Recovering application
+ *
- Priority of an application
+ *
- Input order
+ *
+ *
+ * Example : If schedulableEntities with E1(true,1,1) E2(true,2,2) E3(true,3,3)
+ * E4(false,4,4) E5(false,4,5) are added. The ordering policy assignment
+ * iterator is in the order of E3(true,3,3) E2(true,2,2) E1(true,1,1)
+ * E5(false,5,5) E4(false,4,4)
+ */
+public class FifoOrderingPolicyForPendingApps
+ extends AbstractComparatorOrderingPolicy {
+
+ public FifoOrderingPolicyForPendingApps() {
+ List> comparators =
+ new ArrayList>();
+ comparators.add(new RecoveryComparator());
+ comparators.add(new PriorityComparator());
+ comparators.add(new FifoComparator());
+ this.comparator = new CompoundComparator(comparators);
+ this.schedulableEntities = new TreeSet(comparator);
+ }
+
+ @Override
+ public String getInfo() {
+ return "FifoOrderingPolicyForPendingApps";
+ }
+
+ @Override
+ public void configure(Map conf) {
+ }
+
+ @Override
+ public void containerAllocated(S schedulableEntity, RMContainer r) {
+ }
+
+ @Override
+ public void containerReleased(S schedulableEntity, RMContainer r) {
+ }
+
+ @Override
+ public void demandUpdated(S schedulableEntity) {
+ }
+
+}
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/policy/RecoveryComparator.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/policy/RecoveryComparator.java
new file mode 100644
index 00000000000..87f07e74f61
--- /dev/null
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/policy/RecoveryComparator.java
@@ -0,0 +1,33 @@
+/**
+ * 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.resourcemanager.scheduler.policy;
+
+import java.util.Comparator;
+
+/**
+ * A Comparator which orders SchedulableEntities by isRecovering flag.
+ */
+public class RecoveryComparator implements Comparator {
+ @Override
+ public int compare(SchedulableEntity se1, SchedulableEntity se2) {
+ int val1 = se1.isRecovering() ? 1 : 0;
+ int val2 = se2.isRecovering() ? 1 : 0;
+ return val2 - val1;
+ }
+}
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/policy/SchedulableEntity.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/policy/SchedulableEntity.java
index 2ccb1cd3b19..41b83ce7162 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/policy/SchedulableEntity.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/policy/SchedulableEntity.java
@@ -18,15 +18,12 @@
package org.apache.hadoop.yarn.server.resourcemanager.scheduler.policy;
-import java.util.*;
-
import org.apache.hadoop.yarn.api.records.Priority;
-import org.apache.hadoop.yarn.api.records.Resource;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceUsage;
/**
- * A SchedulableEntity is a process to be scheduled,
+ * A SchedulableEntity is a process to be scheduled.
* for example, an application / application attempt
*/
public interface SchedulableEntity {
@@ -53,4 +50,9 @@ public interface SchedulableEntity {
*/
public Priority getPriority();
+ /**
+ * Whether application was running before RM restart.
+ */
+ public boolean isRecovering();
+
}
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestLeafQueue.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestLeafQueue.java
index 1922a35d34c..42dcd6de5e3 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestLeafQueue.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestLeafQueue.java
@@ -2399,7 +2399,6 @@ public class TestLeafQueue {
LeafQueue a = stubLeafQueue((LeafQueue)queues.get(A));
a.setOrderingPolicy(new FifoOrderingPolicy());
- a.setPendingAppsOrderingPolicy(new FifoOrderingPolicy());
String host_0_0 = "127.0.0.1";
String rack_0 = "rack_0";
@@ -2549,7 +2548,6 @@ public class TestLeafQueue {
new FairOrderingPolicy();
a.setOrderingPolicy(schedulingOrder);
- a.setPendingAppsOrderingPolicy(new FairOrderingPolicy());
String host_0_0 = "127.0.0.1";
String rack_0 = "rack_0";
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/policy/MockSchedulableEntity.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/policy/MockSchedulableEntity.java
index bf4c98a554a..4f251bf4e38 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/policy/MockSchedulableEntity.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/policy/MockSchedulableEntity.java
@@ -32,9 +32,17 @@ public class MockSchedulableEntity implements SchedulableEntity {
private String id;
private long serial = 0;
private Priority priority;
+ private boolean isRecovering;
public MockSchedulableEntity() { }
+ public MockSchedulableEntity(long serial, int priority,
+ boolean isRecovering) {
+ this.serial = serial;
+ this.priority = Priority.newInstance(priority);
+ this.isRecovering = isRecovering;
+ }
+
public void setId(String id) {
this.id = id;
}
@@ -84,4 +92,13 @@ public class MockSchedulableEntity implements SchedulableEntity {
public void setApplicationPriority(Priority priority) {
this.priority = priority;
}
+
+ @Override
+ public boolean isRecovering() {
+ return isRecovering;
+ }
+
+ protected void setRecovering(boolean entityRecovering) {
+ this.isRecovering = entityRecovering;
+ }
}
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/policy/TestFifoOrderingPolicyForPendingApps.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/policy/TestFifoOrderingPolicyForPendingApps.java
new file mode 100644
index 00000000000..befa8e6c321
--- /dev/null
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/policy/TestFifoOrderingPolicyForPendingApps.java
@@ -0,0 +1,89 @@
+/**
+ * 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.resourcemanager.scheduler.policy;
+
+import java.util.*;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestFifoOrderingPolicyForPendingApps {
+
+ @Test
+ public void testFifoOrderingPolicyForPendingApps() {
+ FifoOrderingPolicyForPendingApps policy =
+ new FifoOrderingPolicyForPendingApps();
+
+ MockSchedulableEntity r1 = new MockSchedulableEntity();
+ MockSchedulableEntity r2 = new MockSchedulableEntity();
+
+ Assert.assertEquals(policy.getComparator().compare(r1, r2), 0);
+
+ r1.setSerial(1);
+ r1.setRecovering(true);
+ Assert.assertEquals(policy.getComparator().compare(r1, r2), -1);
+
+ r1.setRecovering(false);
+ r2.setSerial(2);
+ r2.setRecovering(true);
+ Assert.assertEquals(policy.getComparator().compare(r1, r2), 1);
+ }
+
+ /**
+ * Entities submitted with E1-Recovering, E2-Recovering, E3-Recovering, E4-not
+ * recovering, E5-not recovering.
+ * Expected Iterator Output : E-3 E-2 E-1 E-5 E-4
+ */
+ @Test
+ public void testIterators() {
+ OrderingPolicy schedOrder =
+ new FifoOrderingPolicyForPendingApps();
+
+ MockSchedulableEntity msp1 = new MockSchedulableEntity(1, 1, true);
+ MockSchedulableEntity msp2 = new MockSchedulableEntity(2, 2, true);
+ MockSchedulableEntity msp3 = new MockSchedulableEntity(3, 3, true);
+ MockSchedulableEntity msp4 = new MockSchedulableEntity(4, 2, true);
+ MockSchedulableEntity msp5 = new MockSchedulableEntity(5, 5, false);
+ MockSchedulableEntity msp6 = new MockSchedulableEntity(6, 6, false);
+ MockSchedulableEntity msp7 = new MockSchedulableEntity(7, 5, false);
+
+ schedOrder.addSchedulableEntity(msp1);
+ schedOrder.addSchedulableEntity(msp2);
+ schedOrder.addSchedulableEntity(msp3);
+ schedOrder.addSchedulableEntity(msp4);
+ schedOrder.addSchedulableEntity(msp5);
+ schedOrder.addSchedulableEntity(msp6);
+ schedOrder.addSchedulableEntity(msp7);
+
+ // Assignment with serial id's are 3,2,4,1,6,5,7
+ checkSerials(schedOrder.getAssignmentIterator(), new long[] { 3, 2, 4, 1,
+ 6, 5, 7 });
+
+ //Preemption, youngest to oldest
+ checkSerials(schedOrder.getPreemptionIterator(), new long[] { 7, 5, 6, 1,
+ 4, 2, 3 });
+ }
+
+ public void checkSerials(Iterator si,
+ long[] serials) {
+ for (int i = 0; i < serials.length; i++) {
+ Assert.assertEquals(si.next().getSerial(), serials[i]);
+ }
+ }
+}