Search in sources :

Example 1 with VirtualMachineLease

use of com.netflix.fenzo.VirtualMachineLease in project elastic-job by dangdangdotcom.

the class TaskLaunchScheduledService method runOneIteration.

@Override
protected void runOneIteration() throws Exception {
    try {
        LaunchingTasks launchingTasks = new LaunchingTasks(facadeService.getEligibleJobContext());
        List<VirtualMachineLease> virtualMachineLeases = LeasesQueue.getInstance().drainTo();
        Collection<VMAssignmentResult> vmAssignmentResults = taskScheduler.scheduleOnce(launchingTasks.getPendingTasks(), virtualMachineLeases).getResultMap().values();
        List<TaskContext> taskContextsList = new LinkedList<>();
        Map<List<Protos.OfferID>, List<Protos.TaskInfo>> offerIdTaskInfoMap = new HashMap<>();
        for (VMAssignmentResult each : vmAssignmentResults) {
            List<VirtualMachineLease> leasesUsed = each.getLeasesUsed();
            List<Protos.TaskInfo> taskInfoList = new ArrayList<>(each.getTasksAssigned().size() * 10);
            taskInfoList.addAll(getTaskInfoList(launchingTasks.getIntegrityViolationJobs(vmAssignmentResults), each, leasesUsed.get(0).hostname(), leasesUsed.get(0).getOffer().getSlaveId()));
            for (Protos.TaskInfo taskInfo : taskInfoList) {
                taskContextsList.add(TaskContext.from(taskInfo.getTaskId().getValue()));
            }
            offerIdTaskInfoMap.put(getOfferIDs(leasesUsed), taskInfoList);
        }
        for (TaskContext each : taskContextsList) {
            facadeService.addRunning(each);
            jobEventBus.post(createJobStatusTraceEvent(each));
        }
        facadeService.removeLaunchTasksFromQueue(taskContextsList);
        for (Entry<List<OfferID>, List<TaskInfo>> each : offerIdTaskInfoMap.entrySet()) {
            schedulerDriver.launchTasks(each.getKey(), each.getValue());
        }
    //CHECKSTYLE:OFF
    } catch (Throwable throwable) {
        //CHECKSTYLE:ON
        log.error("Launch task error", throwable);
    }
}
Also used : TaskContext(com.dangdang.ddframe.job.context.TaskContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VirtualMachineLease(com.netflix.fenzo.VirtualMachineLease) TaskInfo(org.apache.mesos.Protos.TaskInfo) LinkedList(java.util.LinkedList) TaskInfo(org.apache.mesos.Protos.TaskInfo) Protos(org.apache.mesos.Protos) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) VMAssignmentResult(com.netflix.fenzo.VMAssignmentResult)

Example 2 with VirtualMachineLease

use of com.netflix.fenzo.VirtualMachineLease in project elastic-job by dangdangdotcom.

the class TaskLaunchScheduledServiceTest method assertRunOneIterationWithScriptJob.

@Test
public void assertRunOneIterationWithScriptJob() throws Exception {
    when(facadeService.getEligibleJobContext()).thenReturn(Lists.newArrayList(JobContext.from(CloudJobConfigurationBuilder.createScriptCloudJobConfiguration("script_job", 1), ExecutionType.READY)));
    Map<String, VMAssignmentResult> vmAssignmentResultMap = new HashMap<>();
    vmAssignmentResultMap.put("rs1", new VMAssignmentResult("localhost", Lists.<VirtualMachineLease>newArrayList(new VMLeaseObject(OfferBuilder.createOffer("offer_0"))), Sets.newHashSet(mockTaskAssignmentResult("script_job", ExecutionType.READY))));
    when(taskScheduler.scheduleOnce(anyListOf(TaskRequest.class), anyListOf(VirtualMachineLease.class))).thenReturn(new SchedulingResult(vmAssignmentResultMap));
    when(facadeService.loadAppConfig("test_app")).thenReturn(Optional.of(CloudAppConfigurationBuilder.createCloudAppConfiguration("test_app")));
    when(facadeService.load("script_job")).thenReturn(Optional.of(CloudJobConfigurationBuilder.createScriptCloudJobConfiguration("script_job", 1)));
    when(taskScheduler.getTaskAssigner()).thenReturn(mock(Action2.class));
    taskLaunchScheduledService.runOneIteration();
    verify(facadeService).removeLaunchTasksFromQueue(anyListOf(TaskContext.class));
    verify(facadeService).isRunning(TaskContext.from(String.format("%s@-@0@-@%s@-@unassigned-slave@-@0", "script_job", ExecutionType.READY)));
    verify(facadeService).loadAppConfig("test_app");
    verify(jobEventBus).post(Matchers.<JobStatusTraceEvent>any());
}
Also used : VMLeaseObject(com.netflix.fenzo.plugins.VMLeaseObject) TaskContext(com.dangdang.ddframe.job.context.TaskContext) Action2(com.netflix.fenzo.functions.Action2) HashMap(java.util.HashMap) TaskRequest(com.netflix.fenzo.TaskRequest) VMAssignmentResult(com.netflix.fenzo.VMAssignmentResult) VirtualMachineLease(com.netflix.fenzo.VirtualMachineLease) SchedulingResult(com.netflix.fenzo.SchedulingResult) Test(org.junit.Test)

Example 3 with VirtualMachineLease

use of com.netflix.fenzo.VirtualMachineLease in project elastic-job by dangdangdotcom.

the class TaskLaunchScheduledServiceTest method assertRunOneIteration.

@Test
public void assertRunOneIteration() throws Exception {
    when(facadeService.getEligibleJobContext()).thenReturn(Lists.newArrayList(JobContext.from(CloudJobConfigurationBuilder.createCloudJobConfiguration("failover_job", CloudJobExecutionType.DAEMON, 1), ExecutionType.FAILOVER)));
    Map<String, VMAssignmentResult> vmAssignmentResultMap = new HashMap<>();
    vmAssignmentResultMap.put("rs1", new VMAssignmentResult("localhost", Lists.<VirtualMachineLease>newArrayList(new VMLeaseObject(OfferBuilder.createOffer("offer_0"))), Sets.newHashSet(mockTaskAssignmentResult("failover_job", ExecutionType.FAILOVER))));
    when(taskScheduler.scheduleOnce(anyListOf(TaskRequest.class), anyListOf(VirtualMachineLease.class))).thenReturn(new SchedulingResult(vmAssignmentResultMap));
    when(facadeService.load("failover_job")).thenReturn(Optional.of(CloudJobConfigurationBuilder.createCloudJobConfiguration("failover_job")));
    when(facadeService.getFailoverTaskId(any(MetaInfo.class))).thenReturn(Optional.of(String.format("%s@-@0@-@%s@-@unassigned-slave@-@0", "failover_job", ExecutionType.FAILOVER.name())));
    when(taskScheduler.getTaskAssigner()).thenReturn(mock(Action2.class));
    taskLaunchScheduledService.runOneIteration();
    verify(facadeService).removeLaunchTasksFromQueue(anyListOf(TaskContext.class));
    verify(facadeService).loadAppConfig("test_app");
    verify(jobEventBus).post(Matchers.<JobStatusTraceEvent>any());
}
Also used : VMLeaseObject(com.netflix.fenzo.plugins.VMLeaseObject) TaskContext(com.dangdang.ddframe.job.context.TaskContext) Action2(com.netflix.fenzo.functions.Action2) HashMap(java.util.HashMap) MetaInfo(com.dangdang.ddframe.job.context.TaskContext.MetaInfo) TaskRequest(com.netflix.fenzo.TaskRequest) VMAssignmentResult(com.netflix.fenzo.VMAssignmentResult) VirtualMachineLease(com.netflix.fenzo.VirtualMachineLease) SchedulingResult(com.netflix.fenzo.SchedulingResult) Test(org.junit.Test)

Aggregations

TaskContext (com.dangdang.ddframe.job.context.TaskContext)3 VMAssignmentResult (com.netflix.fenzo.VMAssignmentResult)3 VirtualMachineLease (com.netflix.fenzo.VirtualMachineLease)3 HashMap (java.util.HashMap)3 SchedulingResult (com.netflix.fenzo.SchedulingResult)2 TaskRequest (com.netflix.fenzo.TaskRequest)2 Action2 (com.netflix.fenzo.functions.Action2)2 VMLeaseObject (com.netflix.fenzo.plugins.VMLeaseObject)2 Test (org.junit.Test)2 MetaInfo (com.dangdang.ddframe.job.context.TaskContext.MetaInfo)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Protos (org.apache.mesos.Protos)1 TaskInfo (org.apache.mesos.Protos.TaskInfo)1