/** * Get the ZK path for the given task ID (with leading slash). */ private static String getPathForWorker(Protos.TaskID taskID) { checkNotNull(taskID, "taskID"); return String.format("/%s", taskID.getValue()); } }
/** {@inheritDoc} */ @Override public synchronized void resourceOffers(SchedulerDriver schedulerDriver, List<Protos.Offer> offers) { log.log(Level.FINE, "Offers resources: {0}", offers.size()); for (Protos.Offer offer : offers) { IgniteTask igniteTask = checkOffer(offer); // Decline offer which doesn't match by mem or cpu. if (igniteTask == null) { schedulerDriver.declineOffer(offer.getId()); continue; } // Generate a unique task ID. Protos.TaskID taskId = Protos.TaskID.newBuilder() .setValue(Integer.toString(taskIdGenerator.incrementAndGet())).build(); log.log(Level.INFO, "Launching task: {0}", igniteTask); // Create task to run. Protos.TaskInfo task = createTask(offer, igniteTask, taskId); try { schedulerDriver.launchTasks(Collections.singletonList(offer.getId()), Collections.singletonList(task), Protos.Filters.newBuilder().setRefuseSeconds(1).build()); } catch (RuntimeException e) { log.log(Level.SEVERE, "Failed launch task. Task id: {0}. Task info: {1}", new Object[]{taskId, task, e}); throw e; } tasks.put(taskId.getValue(), igniteTask); } }
@Override public Collection<ResourceProfile> startNewWorker(ResourceProfile resourceProfile) { LOG.info("Starting a new worker."); try { // generate new workers into persistent state and launch associated actors MesosWorkerStore.Worker worker = MesosWorkerStore.Worker.newWorker(workerStore.newTaskID(), resourceProfile); workerStore.putWorker(worker); workersInNew.put(extractResourceID(worker.taskID()), worker); LaunchableMesosWorker launchable = createLaunchableMesosWorker(worker.taskID()); LOG.info("Scheduling Mesos task {} with ({} MB, {} cpus).", launchable.taskID().getValue(), launchable.taskRequest().getMemory(), launchable.taskRequest().getCPUs()); // tell the task monitor about the new plans taskMonitor.tell(new TaskMonitor.TaskGoalStateUpdated(extractGoalState(worker)), selfActor); // tell the launch coordinator to launch the new tasks launchCoordinator.tell(new LaunchCoordinator.Launch(Collections.singletonList(launchable)), selfActor); return slotsPerWorker; } catch (Exception ex) { onFatalError(new ResourceManagerException("Unable to request new workers.", ex)); return Collections.emptyList(); } }
@Override public void killTask(ExecutorDriver driver, TaskID id) { LOG.warn("killTask not implemented in executor {}, so " + "cowardly refusing to kill task {}", _executorId, id.getValue()); }
@Test public void testFoldered1ToTaskId() throws Exception { Protos.TaskID taskId = CommonIdUtils.toTaskId(TEST_FOLDERED_SERVICE_NAME, TEST_TASK_NAME); Assert.assertTrue(taskId.getValue().startsWith(TEST_FOLDERED_SANITIZED_NAME + "__" + TEST_TASK_NAME + "__")); Assert.assertNotNull(UUID.fromString(taskId.getValue().split("__")[2])); Assert.assertEquals(TEST_TASK_NAME, CommonIdUtils.toTaskName(taskId)); Assert.assertEquals(TEST_FOLDERED_SANITIZED_NAME, CommonIdUtils.toSanitizedServiceName(taskId).get()); }
@Test public void testToTaskId() throws Exception { Protos.TaskID taskId = CommonIdUtils.toTaskId(TEST_SERVICE_NAME, TEST_TASK_NAME); Assert.assertTrue(taskId.getValue().startsWith(TEST_SERVICE_NAME + "__" + TEST_TASK_NAME + "__")); Assert.assertNotNull(UUID.fromString(taskId.getValue().split("__")[2])); Assert.assertEquals(TEST_TASK_NAME, CommonIdUtils.toTaskName(taskId)); Assert.assertEquals(TEST_SERVICE_NAME, CommonIdUtils.toSanitizedServiceName(taskId).get()); }
/** * Gets the unique identifier for the task. * * @return The universally unique identifier for the task. */ public String getId() { return info.getTaskId().getValue(); }
@Override public void killTask(ExecutorDriver driver, TaskID taskId) { LOG.info("Killing task : " + taskId.getValue()); try { groomServer.shutdown(); } catch (IOException e) { LOG.error("Failed to shutdown TaskTracker", e); } }
/** * Converts the unique {@link TaskID} into a Framework defined task name. * <p> * For example: "path.to.service__instance-0__aoeu5678" => "instance-0" * * @see #toTaskId(String) */ public static String toTaskName(Protos.TaskID taskId) throws TaskException { return extractTaskNameFromId(taskId.getValue()); }
private Properties getBaseQuartzProperties() { Properties result = new Properties(); result.put("org.quartz.threadPool.class", org.quartz.simpl.SimpleThreadPool.class.getName()); result.put("org.quartz.threadPool.threadCount", "1"); result.put("org.quartz.scheduler.instanceName", taskId.getValue()); if (!jobRootConfig.getTypeConfig().getCoreConfig().isMisfire()) { result.put("org.quartz.jobStore.misfireThreshold", "1"); } result.put("org.quartz.plugin.shutdownhook.class", ShutdownHookPlugin.class.getName()); result.put("org.quartz.plugin.shutdownhook.cleanShutdown", Boolean.TRUE.toString()); return result; }
@Test public void testFoldered2ToTaskId() throws Exception { Protos.TaskID taskId = CommonIdUtils.toTaskId(TEST_FOLDERED_SERVICE_NAME2, TEST_TASK_NAME); Assert.assertTrue(taskId.getValue().startsWith(TEST_FOLDERED_SANITIZED_NAME + "__" + TEST_TASK_NAME + "__")); Assert.assertNotNull(UUID.fromString(taskId.getValue().split("__")[2])); Assert.assertEquals(TEST_TASK_NAME, CommonIdUtils.toTaskName(taskId)); Assert.assertEquals(TEST_FOLDERED_SANITIZED_NAME, CommonIdUtils.toSanitizedServiceName(taskId).get()); }
@Override public String toString() { return String.format("%s(%s):%s", taskInfo.getName(), taskInfo.getTaskId().getValue(), status); } }
final String taskId = taskInfo.getTaskId().getValue();
/** * Invoked when a task running within this executor has been killed * (via SchedulerDriver::killTask). Note that no status update will * be sent on behalf of the executor, the executor is responsible * for creating a new TaskStatus (i.e., with TASK_KILLED) and * invoking ExecutorDriver::sendStatusUpdate. */ @Override public void killTask(ExecutorDriver executorDriver, Protos.TaskID taskID) { final String taskId = taskID.getValue(); LOG.info("Asked to kill task {}", taskId); KillState killState = monitor.requestKill(taskId); switch (killState) { case DIDNT_EXIST: case INCONSISTENT_STATE: LOG.warn("Couldn't kill task {} due to killState {}", taskId, killState); break; case DESTROYING_PROCESS: case INTERRUPTING_PRE_PROCESS: case KILLING_PROCESS: LOG.info("Requested kill of task {} with killState {}", taskId, killState); break; } }
.setName("Ignite node " + taskId.getValue()) .setTaskId(taskId) .setSlaveId(offer.getSlaveId())
.setSlaveId(slaveId) .setTaskId(taskID) .setName(taskID.getValue()); .replaceAll(Matcher.quoteReplacement(taskID.getValue())); env.addVariables(variable(MesosConfigKeys.ENV_FLINK_CONTAINER_ID, taskInfo.getTaskId().getValue())); env.addVariables(variable(MesosConfigKeys.ENV_TASK_NAME, taskInfo.getTaskId().getValue())); env.addVariables(variable(MesosConfigKeys.ENV_FRAMEWORK_NAME, mesosConfiguration.frameworkInfo().getName()));
/** {@inheritDoc} */ @Override public synchronized void statusUpdate(SchedulerDriver schedulerDriver, Protos.TaskStatus taskStatus) { final String taskId = taskStatus.getTaskId().getValue(); log.log(Level.INFO, "Received update event task: {0} is in state: {1}", new Object[]{taskId, taskStatus.getState()}); if (taskStatus.getState().equals(Protos.TaskState.TASK_FAILED) || taskStatus.getState().equals(Protos.TaskState.TASK_ERROR) || taskStatus.getState().equals(Protos.TaskState.TASK_FINISHED) || taskStatus.getState().equals(Protos.TaskState.TASK_KILLED) || taskStatus.getState().equals(Protos.TaskState.TASK_LOST)) { IgniteTask failedTask = tasks.remove(taskId); if (failedTask != null) { List<Protos.Request> requests = new ArrayList<>(); Protos.Request request = Protos.Request.newBuilder() .addResources(Protos.Resource.newBuilder() .setType(Protos.Value.Type.SCALAR) .setName(MEM) .setScalar(Protos.Value.Scalar.newBuilder().setValue(failedTask.mem()))) .addResources(Protos.Resource.newBuilder() .setType(Protos.Value.Type.SCALAR) .setName(CPU) .setScalar(Protos.Value.Scalar.newBuilder().setValue(failedTask.cpuCores()))) .build(); requests.add(request); schedulerDriver.requestResources(requests); } } }
worker.taskID().getValue(), worker.hostname().get());
@Override public String getId() { return taskID.getValue(); }
/** * Extracts a unique ResourceID from the Mesos task. * * @param taskId the Mesos TaskID * @return The ResourceID for the container */ static ResourceID extractResourceID(Protos.TaskID taskId) { return new ResourceID(taskId.getValue()); }