YARN-447. Move ApplicationComparator in CapacityScheduler to use comparator in ApplicationId. Contributed by Nemon Lou.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1463405 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
17be263e9b
commit
bcce9354bc
|
@ -112,6 +112,9 @@ Release 2.0.5-beta - UNRELEASED
|
||||||
YARN-309. Changed NodeManager to obtain heart-beat interval from the
|
YARN-309. Changed NodeManager to obtain heart-beat interval from the
|
||||||
ResourceManager. (Xuan Gong via vinodkv)
|
ResourceManager. (Xuan Gong via vinodkv)
|
||||||
|
|
||||||
|
YARN-447. Move ApplicationComparator in CapacityScheduler to use comparator
|
||||||
|
in ApplicationId. (Nemon Lou via vinodkv)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
|
|
@ -108,7 +108,7 @@ implements ResourceScheduler, CapacitySchedulerContext, Configurable {
|
||||||
new Comparator<FiCaSchedulerApp>() {
|
new Comparator<FiCaSchedulerApp>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(FiCaSchedulerApp a1, FiCaSchedulerApp a2) {
|
public int compare(FiCaSchedulerApp a1, FiCaSchedulerApp a2) {
|
||||||
return a1.getApplicationId().getId() - a2.getApplicationId().getId();
|
return a1.getApplicationId().compareTo(a2.getApplicationId());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,10 @@
|
||||||
package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity;
|
package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
@ -43,13 +45,19 @@ import org.apache.hadoop.yarn.server.resourcemanager.Task;
|
||||||
import org.apache.hadoop.yarn.server.resourcemanager.resource.Resources;
|
import org.apache.hadoop.yarn.server.resourcemanager.resource.Resources;
|
||||||
import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode;
|
import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode;
|
||||||
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler;
|
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler;
|
||||||
|
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerApp;
|
||||||
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeAddedSchedulerEvent;
|
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeAddedSchedulerEvent;
|
||||||
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeRemovedSchedulerEvent;
|
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeRemovedSchedulerEvent;
|
||||||
import org.apache.hadoop.yarn.server.resourcemanager.security.ClientToAMTokenSecretManagerInRM;
|
import org.apache.hadoop.yarn.server.resourcemanager.security.ClientToAMTokenSecretManagerInRM;
|
||||||
import org.apache.hadoop.yarn.server.resourcemanager.security.RMContainerTokenSecretManager;
|
import org.apache.hadoop.yarn.server.resourcemanager.security.RMContainerTokenSecretManager;
|
||||||
|
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
||||||
|
import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
|
||||||
public class TestCapacityScheduler {
|
public class TestCapacityScheduler {
|
||||||
private static final Log LOG = LogFactory.getLog(TestCapacityScheduler.class);
|
private static final Log LOG = LogFactory.getLog(TestCapacityScheduler.class);
|
||||||
|
@ -453,4 +461,32 @@ public class TestCapacityScheduler {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test (timeout = 5000)
|
||||||
|
public void testApplicationComparator()
|
||||||
|
{
|
||||||
|
CapacityScheduler cs = new CapacityScheduler();
|
||||||
|
Comparator<FiCaSchedulerApp> appComparator= cs.getApplicationComparator();
|
||||||
|
ApplicationId id1 = RecordFactoryProvider.getRecordFactory(null).newRecordInstance(ApplicationId.class);
|
||||||
|
id1.setClusterTimestamp(1);
|
||||||
|
id1.setId(1);
|
||||||
|
ApplicationId id2 = RecordFactoryProvider.getRecordFactory(null).newRecordInstance(ApplicationId.class);
|
||||||
|
id2.setClusterTimestamp(1);
|
||||||
|
id2.setId(2);
|
||||||
|
ApplicationId id3 = RecordFactoryProvider.getRecordFactory(null).newRecordInstance(ApplicationId.class);
|
||||||
|
id3.setClusterTimestamp(2);
|
||||||
|
id3.setId(1);
|
||||||
|
//same clusterId
|
||||||
|
FiCaSchedulerApp app1 = Mockito.mock(FiCaSchedulerApp.class);
|
||||||
|
when(app1.getApplicationId()).thenReturn(id1);
|
||||||
|
FiCaSchedulerApp app2 = Mockito.mock(FiCaSchedulerApp.class);
|
||||||
|
when(app2.getApplicationId()).thenReturn(id2);
|
||||||
|
FiCaSchedulerApp app3 = Mockito.mock(FiCaSchedulerApp.class);
|
||||||
|
when(app3.getApplicationId()).thenReturn(id3);
|
||||||
|
assertTrue(appComparator.compare(app1, app2) < 0);
|
||||||
|
//different clusterId
|
||||||
|
assertTrue(appComparator.compare(app1, app3) < 0);
|
||||||
|
assertTrue(appComparator.compare(app2, app3) < 0);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaS
|
||||||
import org.apache.hadoop.yarn.server.resourcemanager.security.ApplicationTokenSecretManager;
|
import org.apache.hadoop.yarn.server.resourcemanager.security.ApplicationTokenSecretManager;
|
||||||
import org.apache.hadoop.yarn.server.resourcemanager.security.ClientToAMTokenSecretManagerInRM;
|
import org.apache.hadoop.yarn.server.resourcemanager.security.ClientToAMTokenSecretManagerInRM;
|
||||||
import org.apache.hadoop.yarn.server.resourcemanager.security.RMContainerTokenSecretManager;
|
import org.apache.hadoop.yarn.server.resourcemanager.security.RMContainerTokenSecretManager;
|
||||||
|
import org.apache.hadoop.yarn.util.BuilderUtils;
|
||||||
|
|
||||||
public class TestUtils {
|
public class TestUtils {
|
||||||
private static final Log LOG = LogFactory.getLog(TestUtils.class);
|
private static final Log LOG = LogFactory.getLog(TestUtils.class);
|
||||||
|
@ -136,9 +137,7 @@ public class TestUtils {
|
||||||
|
|
||||||
public static ApplicationAttemptId
|
public static ApplicationAttemptId
|
||||||
getMockApplicationAttemptId(int appId, int attemptId) {
|
getMockApplicationAttemptId(int appId, int attemptId) {
|
||||||
ApplicationId applicationId = mock(ApplicationId.class);
|
ApplicationId applicationId = BuilderUtils.newApplicationId(0l, appId);
|
||||||
when(applicationId.getClusterTimestamp()).thenReturn(0L);
|
|
||||||
when(applicationId.getId()).thenReturn(appId);
|
|
||||||
ApplicationAttemptId applicationAttemptId = mock(ApplicationAttemptId.class);
|
ApplicationAttemptId applicationAttemptId = mock(ApplicationAttemptId.class);
|
||||||
when(applicationAttemptId.getApplicationId()).thenReturn(applicationId);
|
when(applicationAttemptId.getApplicationId()).thenReturn(applicationId);
|
||||||
when(applicationAttemptId.getAttemptId()).thenReturn(attemptId);
|
when(applicationAttemptId.getAttemptId()).thenReturn(attemptId);
|
||||||
|
|
Loading…
Reference in New Issue