当前位置: 首页>>代码示例>>Java>>正文


Java SchedulerDriver.reconcileTasks方法代码示例

本文整理汇总了Java中org.apache.mesos.SchedulerDriver.reconcileTasks方法的典型用法代码示例。如果您正苦于以下问题:Java SchedulerDriver.reconcileTasks方法的具体用法?Java SchedulerDriver.reconcileTasks怎么用?Java SchedulerDriver.reconcileTasks使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.mesos.SchedulerDriver的用法示例。


在下文中一共展示了SchedulerDriver.reconcileTasks方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startReconciliation

import org.apache.mesos.SchedulerDriver; //导入方法依赖的package包/类
public ReconciliationState startReconciliation() {
  if (!isRunningReconciliation.compareAndSet(false, true)) {
    LOG.info("Reconciliation is already running, NOT starting a new reconciliation process");
    return ReconciliationState.ALREADY_RUNNING;
  }

  Optional<SchedulerDriver> schedulerDriver = schedulerDriverSupplier.get();

  if (!schedulerDriver.isPresent()) {
    LOG.trace("Not running reconciliation - no schedulerDriver present");
    isRunningReconciliation.set(false);
    return ReconciliationState.NO_DRIVER;
  }

  final long reconciliationStart = System.currentTimeMillis();
  final List<SingularityTaskId> activeTaskIds = taskManager.getActiveTaskIds();

  LOG.info("Starting a reconciliation cycle - {} current active tasks", activeTaskIds.size());

  SchedulerDriver driver = schedulerDriver.get();
  driver.reconcileTasks(Collections.<TaskStatus> emptyList());

  scheduleReconciliationCheck(driver, reconciliationStart, activeTaskIds, 0);

  return ReconciliationState.STARTED;
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:27,代码来源:SingularityTaskReconciliation.java

示例2: reconcileAllRunningJobs

import org.apache.mesos.SchedulerDriver; //导入方法依赖的package包/类
private void reconcileAllRunningJobs(SchedulerDriver driver) throws IOException {
    List<Job> jobs = Database.getInstance().getRunning();
    List<Protos.TaskStatus> taskStatuses = jobs.stream().map(job -> {
        Protos.TaskStatus.Builder builder = Protos.TaskStatus.newBuilder()
                .setTaskId(Protos.TaskID.newBuilder().setValue(job.taskId()))
                // According to the document the master does not examine state but
                // is required by protobuf to encode
                .setState(Protos.TaskState.TASK_RUNNING);
        if (job.slaveId() != null) {
            builder.setSlaveId(Protos.SlaveID.newBuilder().setValue(job.slaveId()));
        }
        return builder.build();
    }).collect(Collectors.toList());

    if (taskStatuses.size() > 0) {
        driver.reconcileTasks(taskStatuses);
    }
}
 
开发者ID:retz,项目名称:retz,代码行数:19,代码来源:RetzScheduler.java

示例3: checkReconciliation

import org.apache.mesos.SchedulerDriver; //导入方法依赖的package包/类
private void checkReconciliation(final SchedulerDriver driver, final long reconciliationStart, final Collection<SingularityTaskId> remainingTaskIds, final int numTimes) {
  final List<SingularityTaskStatusHolder> taskStatusHolders = taskManager.getLastActiveTaskStatusesFor(remainingTaskIds);
  final List<TaskStatus> taskStatuses = Lists.newArrayListWithCapacity(taskStatusHolders.size());

  for (SingularityTaskStatusHolder taskStatusHolder : taskStatusHolders) {
    if (taskStatusHolder.getServerId().equals(serverId) && taskStatusHolder.getServerTimestamp() > reconciliationStart) {
      continue;
    }

    if (taskStatusHolder.getTaskStatus().isPresent()) {
      LOG.debug("Re-requesting task status for {}", taskStatusHolder.getTaskId());
      taskStatuses.add(taskStatusHolder.getTaskStatus().get());
    } else {
      TaskStatus.Builder fakeTaskStatusBuilder = TaskStatus.newBuilder()
          .setTaskId(TaskID.newBuilder().setValue(taskStatusHolder.getTaskId().getId()))
          .setState(TaskState.TASK_STARTING);

      if (taskStatusHolder.getSlaveId().isPresent()) {
        fakeTaskStatusBuilder.setSlaveId(SlaveID.newBuilder().setValue(taskStatusHolder.getSlaveId().get()));
      }

      LOG.info("Task {} didn't have a TaskStatus yet, submitting fake status", taskStatusHolder.getTaskId());
      taskStatuses.add(fakeTaskStatusBuilder.build());
    }
  }

  if (taskStatuses.isEmpty()) {
    LOG.info("Task reconciliation ended after {} checks and {}", numTimes, JavaUtils.duration(reconciliationStart));

    isRunningReconciliation.set(false);

    return;
  }

  LOG.info("Requesting reconciliation of {} taskStatuses, task reconciliation has been running for {}", taskStatuses.size(), JavaUtils.duration(reconciliationStart));

  driver.reconcileTasks(taskStatuses);

  scheduleReconciliationCheck(driver, reconciliationStart, remainingTaskIds, numTimes);
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:41,代码来源:SingularityTaskReconciliation.java

示例4: reconcile

import org.apache.mesos.SchedulerDriver; //导入方法依赖的package包/类
/**
 * This function is expected to be called repeatedly. It executes the following pseudocode
 * across multiple calls:
 * <code>
 * unreconciledList = tasksKnownByScheduler // provided by the StateStore
 * while (!unreconciledList.isEmpty()) {
 *   // explicit reconciliation (PHASE 1)
 *   if (timerSinceLastCallExpired) {
 *     driver.reconcile(unreconciledList);
 *   }
 * }
 * driver.reconcile(emptyList); // implicit reconciliation (PHASE 2)
 * </code>
 */
@Override
public void reconcile(final SchedulerDriver driver) {
    if (isImplicitReconciliationTriggered.get()) {
        // PHASE 3: implicit reconciliation has been triggered, we're done
        return;
    }

    /**
     * NOTE: It is important not to hold a lock when making calls to {@link driver}.  The driver
     * holds a lock internally when making calls to the Scheduler.  If both the scheduler and driver
     * follow the pattern of acquiring a lock and making a remote call then deadlocks occur.  To avoid
     * this we unilaterally enforce that we do not hold any locks while making calls to {@link driver}.
     */
    Collection<TaskStatus> tasksToReconcile = Collections.emptyList();
    synchronized (unreconciled) {
        if (!unreconciled.isEmpty()) {
            final long nowMs = getCurrentTimeMillis();
            // PHASE 1: unreconciled tasks remain: trigger explicit reconciliation against the
            // remaining known tasks originally reported by the StateStore.
            if (nowMs >= lastRequestTimeMs + backOffMs) {
                // update timer values for the next reconcile() call:
                lastRequestTimeMs = nowMs;
                long newBackoff = backOffMs * MULTIPLIER;
                backOffMs = Math.min(newBackoff > 0 ? newBackoff : 0, MAX_BACKOFF_MS);

                // pass a COPY of the list, in case driver is doing anything with it..:
                tasksToReconcile = ImmutableList.copyOf(unreconciled.values());
            } else {
                // timer has not expired yet, do nothing for this call
                LOGGER.info("Too soon since last explicit reconciliation trigger. Waiting at "
                        + "least {}ms before next explicit reconciliation ({} remaining tasks)",
                        lastRequestTimeMs + backOffMs - nowMs, unreconciled.size());
                return;
            }
        }
    }

    if (tasksToReconcile.isEmpty()) {
        // PHASE 2: no unreconciled tasks remain, trigger a single implicit reconciliation,
        // where we get the list of all tasks currently known to Mesos.
        LOGGER.info("Triggering implicit final reconciliation of all tasks");

        // reset the timer values in case we're started again in the future
        resetTimerValues();
        isImplicitReconciliationTriggered.set(true); // enter PHASE 3/complete

    } else {
        LOGGER.info("Triggering explicit reconciliation of {} remaining tasks, next "
                        + "explicit reconciliation in {}ms or later",
                unreconciled.size(), backOffMs);
    }

    driver.reconcileTasks(tasksToReconcile);
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:69,代码来源:DefaultReconciler.java


注:本文中的org.apache.mesos.SchedulerDriver.reconcileTasks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。