Search in sources :

Example 1 with TaskInfo

use of org.apache.mesos.Protos.TaskInfo 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 TaskInfo

use of org.apache.mesos.Protos.TaskInfo in project elastic-job by dangdangdotcom.

the class TaskExecutorThreadTest method assertLaunchTaskWithWrongElasticJobClass.

@Test
public void assertLaunchTaskWithWrongElasticJobClass() {
    TaskInfo taskInfo = buildWrongElasticJobClass();
    TaskThread taskThread = new TaskExecutor().new TaskThread(executorDriver, taskInfo);
    try {
        taskThread.run();
    } catch (final JobSystemException ex) {
        assertTrue(ex.getMessage().startsWith("Elastic-Job: Class 'com.dangdang.ddframe.job.cloud.executor.TaskExecutorThreadTest' must implements ElasticJob interface."));
    }
}
Also used : TaskInfo(org.apache.mesos.Protos.TaskInfo) TaskThread(com.dangdang.ddframe.job.cloud.executor.TaskExecutor.TaskThread) JobSystemException(com.dangdang.ddframe.job.exception.JobSystemException) Test(org.junit.Test)

Example 3 with TaskInfo

use of org.apache.mesos.Protos.TaskInfo in project elastic-job by dangdangdotcom.

the class TaskExecutorThreadTest method assertLaunchTaskWithDaemonTaskAndJavaScriptJob.

@Test
public void assertLaunchTaskWithDaemonTaskAndJavaScriptJob() {
    TaskInfo taskInfo = buildSpringScriptTransientTaskInfo();
    TaskThread taskThread = new TaskExecutor().new TaskThread(executorDriver, taskInfo);
    taskThread.run();
    verify(executorDriver).sendStatusUpdate(Protos.TaskStatus.newBuilder().setTaskId(taskInfo.getTaskId()).setState(TaskState.TASK_RUNNING).build());
    verify(executorDriver).sendStatusUpdate(Protos.TaskStatus.newBuilder().setTaskId(taskInfo.getTaskId()).setState(Protos.TaskState.TASK_FINISHED).build());
}
Also used : TaskInfo(org.apache.mesos.Protos.TaskInfo) TaskThread(com.dangdang.ddframe.job.cloud.executor.TaskExecutor.TaskThread) Test(org.junit.Test)

Example 4 with TaskInfo

use of org.apache.mesos.Protos.TaskInfo in project jesos by groupon.

the class InternalSchedulerDriver method doLaunchTasks.

//
// Launch Tasks processing
//
private void doLaunchTasks(final LaunchTasksMessage message) {
    final MasterInfo masterInfo = context.connectedMaster();
    if (masterInfo == null) {
        loseAllTasks(message.getTasksList(), "Master disconnected");
        return;
    }
    final ImmutableList.Builder<TaskInfo> builder = ImmutableList.builder();
    for (TaskInfo taskInfo : message.getTasksList()) {
        if (taskInfo.hasExecutor() == taskInfo.hasCommand()) {
            loseTask(taskInfo, "TaskInfo must have either an 'executor' or a 'command'");
            // for(...
            continue;
        }
        if (taskInfo.hasExecutor()) {
            if (taskInfo.getExecutor().hasFrameworkId()) {
                final FrameworkID executorFrameworkId = taskInfo.getExecutor().getFrameworkId();
                if (!executorFrameworkId.equals(context.getFrameworkId())) {
                    loseTask(taskInfo, format("ExecutorInfo has an invalid FrameworkID (Actual: %s vs Expected: %s)", executorFrameworkId.getValue(), context.getFrameworkId().getValue()));
                    // for(...
                    continue;
                }
            } else {
                // Executor present but not framework id. Set the framework id.
                taskInfo = TaskInfo.newBuilder(taskInfo).setExecutor(ExecutorInfo.newBuilder(taskInfo.getExecutor()).setFrameworkId(context.getFrameworkId())).build();
            }
        }
        builder.add(taskInfo);
    }
    final List<TaskInfo> launchTasks = builder.build();
    for (final OfferID offer : message.getOfferIdsList()) {
        if (!context.hasOffers(offer)) {
            LOG.warn("Unknown offer %s ignored!", offer.getValue());
        }
        for (final TaskInfo launchTask : launchTasks) {
            if (context.hasOffer(offer, launchTask.getSlaveId())) {
                context.addSlave(launchTask.getSlaveId(), context.getOffer(offer, launchTask.getSlaveId()));
            }
        }
        context.removeAllOffers(offer);
    }
    final LaunchTasksMessage launchMessage = LaunchTasksMessage.newBuilder(message).setFrameworkId(context.getFrameworkId()).clearTasks().addAllTasks(launchTasks).build();
    eventBus.post(new RemoteMessageEnvelope(context.getDriverUPID(), context.getMasterUPID(), launchMessage));
}
Also used : TaskInfo(org.apache.mesos.Protos.TaskInfo) OfferID(org.apache.mesos.Protos.OfferID) MasterInfo(org.apache.mesos.Protos.MasterInfo) RemoteMessageEnvelope(com.groupon.mesos.scheduler.SchedulerMessageEnvelope.RemoteMessageEnvelope) ImmutableList(com.google.common.collect.ImmutableList) FrameworkID(org.apache.mesos.Protos.FrameworkID) LaunchTasksMessage(mesos.internal.Messages.LaunchTasksMessage)

Example 5 with TaskInfo

use of org.apache.mesos.Protos.TaskInfo in project elastic-job by dangdangdotcom.

the class TaskLaunchScheduledService method getTaskInfoList.

private List<Protos.TaskInfo> getTaskInfoList(final Collection<String> integrityViolationJobs, final VMAssignmentResult vmAssignmentResult, final String hostname, final Protos.SlaveID slaveId) {
    List<Protos.TaskInfo> result = new ArrayList<>(vmAssignmentResult.getTasksAssigned().size());
    for (TaskAssignmentResult each : vmAssignmentResult.getTasksAssigned()) {
        TaskContext taskContext = TaskContext.from(each.getTaskId());
        String jobName = taskContext.getMetaInfo().getJobName();
        if (!integrityViolationJobs.contains(jobName) && !facadeService.isRunning(taskContext) && !facadeService.isJobDisabled(jobName)) {
            Protos.TaskInfo taskInfo = getTaskInfo(slaveId, each);
            if (null != taskInfo) {
                result.add(taskInfo);
                facadeService.addMapping(taskInfo.getTaskId().getValue(), hostname);
                taskScheduler.getTaskAssigner().call(each.getRequest(), hostname);
            }
        }
    }
    return result;
}
Also used : TaskInfo(org.apache.mesos.Protos.TaskInfo) TaskContext(com.dangdang.ddframe.job.context.TaskContext) Protos(org.apache.mesos.Protos) ArrayList(java.util.ArrayList) TaskAssignmentResult(com.netflix.fenzo.TaskAssignmentResult) ByteString(com.google.protobuf.ByteString) TaskInfo(org.apache.mesos.Protos.TaskInfo)

Aggregations

TaskInfo (org.apache.mesos.Protos.TaskInfo)10 TaskThread (com.dangdang.ddframe.job.cloud.executor.TaskExecutor.TaskThread)5 Test (org.junit.Test)5 TaskContext (com.dangdang.ddframe.job.context.TaskContext)2 JobSystemException (com.dangdang.ddframe.job.exception.JobSystemException)2 ByteString (com.google.protobuf.ByteString)2 ArrayList (java.util.ArrayList)2 Protos (org.apache.mesos.Protos)2 OfferID (org.apache.mesos.Protos.OfferID)2 TopologyDetails (backtype.storm.scheduler.TopologyDetails)1 WorkerSlot (backtype.storm.scheduler.WorkerSlot)1 ImmutableList (com.google.common.collect.ImmutableList)1 Subscribe (com.google.common.eventbus.Subscribe)1 RemoteMessageEnvelope (com.groupon.mesos.scheduler.SchedulerMessageEnvelope.RemoteMessageEnvelope)1 TaskAssignmentResult (com.netflix.fenzo.TaskAssignmentResult)1 VMAssignmentResult (com.netflix.fenzo.VMAssignmentResult)1 VirtualMachineLease (com.netflix.fenzo.VirtualMachineLease)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1