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);
}
}
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."));
}
}
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());
}
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));
}
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;
}
Aggregations