Search in sources :

Example 6 with PreemptionMessage

use of org.apache.hadoop.yarn.api.records.PreemptionMessage in project hadoop by apache.

the class TestKillAMPreemptionPolicy method testKillAMPreemptPolicy.

@SuppressWarnings("unchecked")
@Test
public void testKillAMPreemptPolicy() {
    ApplicationId appId = ApplicationId.newInstance(123456789, 1);
    ContainerId container = ContainerId.newContainerId(ApplicationAttemptId.newInstance(appId, 1), 1);
    AMPreemptionPolicy.Context mPctxt = mock(AMPreemptionPolicy.Context.class);
    when(mPctxt.getTaskAttempt(any(ContainerId.class))).thenReturn(MRBuilderUtils.newTaskAttemptId(MRBuilderUtils.newTaskId(MRBuilderUtils.newJobId(appId, 1), 1, TaskType.MAP), 0));
    List<Container> p = new ArrayList<Container>();
    p.add(Container.newInstance(container, null, null, null, null, null));
    when(mPctxt.getContainers(any(TaskType.class))).thenReturn(p);
    KillAMPreemptionPolicy policy = new KillAMPreemptionPolicy();
    // strictContract is null & contract is null
    RunningAppContext mActxt = getRunningAppContext();
    policy.init(mActxt);
    PreemptionMessage pM = getPreemptionMessage(false, false, container);
    policy.preempt(mPctxt, pM);
    verify(mActxt.getEventHandler(), times(0)).handle(any(TaskAttemptEvent.class));
    verify(mActxt.getEventHandler(), times(0)).handle(any(JobCounterUpdateEvent.class));
    // strictContract is not null & contract is null
    mActxt = getRunningAppContext();
    policy.init(mActxt);
    pM = getPreemptionMessage(true, false, container);
    policy.preempt(mPctxt, pM);
    verify(mActxt.getEventHandler(), times(2)).handle(any(TaskAttemptEvent.class));
    verify(mActxt.getEventHandler(), times(2)).handle(any(JobCounterUpdateEvent.class));
    // strictContract is null & contract is not null
    mActxt = getRunningAppContext();
    policy.init(mActxt);
    pM = getPreemptionMessage(false, true, container);
    policy.preempt(mPctxt, pM);
    verify(mActxt.getEventHandler(), times(2)).handle(any(TaskAttemptEvent.class));
    verify(mActxt.getEventHandler(), times(2)).handle(any(JobCounterUpdateEvent.class));
    // strictContract is not null & contract is not null
    mActxt = getRunningAppContext();
    policy.init(mActxt);
    pM = getPreemptionMessage(true, true, container);
    policy.preempt(mPctxt, pM);
    verify(mActxt.getEventHandler(), times(4)).handle(any(TaskAttemptEvent.class));
    verify(mActxt.getEventHandler(), times(4)).handle(any(JobCounterUpdateEvent.class));
}
Also used : PreemptionMessage(org.apache.hadoop.yarn.api.records.PreemptionMessage) RunningAppContext(org.apache.hadoop.mapreduce.v2.app.MRAppMaster.RunningAppContext) ArrayList(java.util.ArrayList) KillAMPreemptionPolicy(org.apache.hadoop.mapreduce.v2.app.rm.preemption.KillAMPreemptionPolicy) TaskAttemptEvent(org.apache.hadoop.mapreduce.v2.app.job.event.TaskAttemptEvent) JobCounterUpdateEvent(org.apache.hadoop.mapreduce.v2.app.job.event.JobCounterUpdateEvent) PreemptionContainer(org.apache.hadoop.yarn.api.records.PreemptionContainer) Container(org.apache.hadoop.yarn.api.records.Container) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) TaskType(org.apache.hadoop.mapreduce.v2.api.records.TaskType) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) KillAMPreemptionPolicy(org.apache.hadoop.mapreduce.v2.app.rm.preemption.KillAMPreemptionPolicy) AMPreemptionPolicy(org.apache.hadoop.mapreduce.v2.app.rm.preemption.AMPreemptionPolicy) Test(org.junit.Test)

Example 7 with PreemptionMessage

use of org.apache.hadoop.yarn.api.records.PreemptionMessage in project hadoop by apache.

the class TestKillAMPreemptionPolicy method getPreemptionMessage.

private PreemptionMessage getPreemptionMessage(boolean strictContract, boolean contract, final ContainerId container) {
    PreemptionMessage preemptionMessage = recordFactory.newRecordInstance(PreemptionMessage.class);
    Set<PreemptionContainer> cntrs = new HashSet<PreemptionContainer>();
    PreemptionContainer preemptContainer = recordFactory.newRecordInstance(PreemptionContainer.class);
    preemptContainer.setId(container);
    cntrs.add(preemptContainer);
    if (strictContract) {
        StrictPreemptionContract set = recordFactory.newRecordInstance(StrictPreemptionContract.class);
        set.setContainers(cntrs);
        preemptionMessage.setStrictContract(set);
    }
    if (contract) {
        PreemptionContract preemptContract = recordFactory.newRecordInstance(PreemptionContract.class);
        preemptContract.setContainers(cntrs);
        preemptionMessage.setContract(preemptContract);
    }
    return preemptionMessage;
}
Also used : StrictPreemptionContract(org.apache.hadoop.yarn.api.records.StrictPreemptionContract) PreemptionMessage(org.apache.hadoop.yarn.api.records.PreemptionMessage) PreemptionContainer(org.apache.hadoop.yarn.api.records.PreemptionContainer) PreemptionContract(org.apache.hadoop.yarn.api.records.PreemptionContract) StrictPreemptionContract(org.apache.hadoop.yarn.api.records.StrictPreemptionContract) HashSet(java.util.HashSet)

Aggregations

PreemptionMessage (org.apache.hadoop.yarn.api.records.PreemptionMessage)7 PreemptionContainer (org.apache.hadoop.yarn.api.records.PreemptionContainer)6 ArrayList (java.util.ArrayList)5 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)5 Container (org.apache.hadoop.yarn.api.records.Container)4 HashSet (java.util.HashSet)3 TaskType (org.apache.hadoop.mapreduce.v2.api.records.TaskType)3 RunningAppContext (org.apache.hadoop.mapreduce.v2.app.MRAppMaster.RunningAppContext)3 AMPreemptionPolicy (org.apache.hadoop.mapreduce.v2.app.rm.preemption.AMPreemptionPolicy)3 PreemptionContract (org.apache.hadoop.yarn.api.records.PreemptionContract)3 StrictPreemptionContract (org.apache.hadoop.yarn.api.records.StrictPreemptionContract)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TaskAttemptId (org.apache.hadoop.mapreduce.v2.api.records.TaskAttemptId)2 CheckpointAMPreemptionPolicy (org.apache.hadoop.mapreduce.v2.app.rm.preemption.CheckpointAMPreemptionPolicy)2 PreemptionResourceRequest (org.apache.hadoop.yarn.api.records.PreemptionResourceRequest)2 ResourceRequest (org.apache.hadoop.yarn.api.records.ResourceRequest)2 IOException (java.io.IOException)1 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)1