final ch.qos.logback.classic.Logger taskLog = taskBuilder.buildTaskLogger(taskId, taskInfo.getExecutor().getExecutorId().getValue()); final SingularityExecutorTask task = taskBuilder.buildTask(taskId, executorDriver, taskInfo, taskLog);
private OfferRequirement getExistingOfferRequirement(String type, Protos.TaskInfo taskInfo) { LOGGER.info("Getting existing OfferRequirement for task: {}", taskInfo); ExecutorInfo execInfo = taskInfo.getExecutor(); taskInfo = Protos.TaskInfo.newBuilder(taskInfo).clearExecutor().build(); try { return OfferRequirement.create(type, Arrays.asList(taskInfo), Optional.of(execInfo)); } catch (InvalidRequirementException e) { LOGGER.error("Failed to construct OfferRequirement with Exception: ", e); return null; } } }
private OfferRequirement getCreateOfferRequirement(String type, Protos.TaskInfo taskInfo) { ExecutorInfo execInfo = taskInfo.getExecutor(); taskInfo = Protos.TaskInfo.newBuilder(taskInfo).clearExecutor().build(); try { return OfferRequirement.create(type, Arrays.asList(taskInfo), Optional.of(execInfo)); } catch (InvalidRequirementException e) { LOGGER.error("Failed to construct OfferRequirement with Exception: ", e); return null; } }
@Test public void testUpdateCpuConfig() { CassandraDaemonTask daemonTask = testTaskFactory.create( TEST_DAEMON_NAME, TEST_CONFIG_NAME, testTaskExecutor, CassandraConfig.DEFAULT); double newCpu = 1.0; CassandraConfig updatedConfig = CassandraConfig.create( "2.2.5", newCpu, 4096, 10240, VolumeRequirement.VolumeType.ROOT, "", HeapConfig.DEFAULT, Location.DEFAULT, 7199, false, UUID.randomUUID().toString(), CassandraApplicationConfig.builder().build()); CassandraDaemonTask updatedTask = daemonTask.updateConfig( updatedConfig, testExecutorConfig, TEST_CONFIG_ID); Assert.assertNotEquals(normalizeCassandraTaskInfo(daemonTask), normalizeCassandraTaskInfo(updatedTask)); Assert.assertEquals(newCpu, updatedTask.getConfig().getCpus(), 0.0); Assert.assertTrue(allUrisAreCacheable(updatedTask.getTaskInfo().getExecutor().getCommand().getUrisList(), false)); }
@Test public void testLaunchExpectedMultiplePorts() throws Exception { // Launch for the first time: get ports 10000,10001 PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(10000, 10001); List<Resource> reserveResources = recordLaunchWithCompleteOfferedResources( podInstanceRequirement, ResourceTestUtils.getUnreservedPorts(10000, 10001)); Assert.assertEquals(reserveResources.toString(), 5, reserveResources.size()); String resourceId0 = getResourceId(reserveResources.get(3)); String resourceId1 = getResourceId(reserveResources.get(4)); Collection<Resource> expectedResources = getExpectedExecutorResources( stateStore.fetchTasks().iterator().next().getExecutor()); expectedResources.addAll(Arrays.asList( ResourceTestUtils.getReservedPorts(10000, 10000, resourceId0), ResourceTestUtils.getReservedPorts(10001, 10001, resourceId1))); // Now try relaunch: List<OfferRecommendation> recommendations = evaluator.evaluate( PodInstanceRequirementTestUtils.getPortRequirement(10000, 10001), Arrays.asList(OfferTestUtils.getOffer(expectedResources))); Assert.assertEquals(2, recommendations.size()); // Validate LAUNCH Operation Operation launchOperation = recommendations.get(0).getOperation().get(); Assert.assertEquals(Operation.Type.LAUNCH_GROUP, launchOperation.getType()); List<Resource> launchResources = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0).getResourcesList(); Assert.assertEquals(launchResources.toString(), 2, launchResources.size()); Assert.assertEquals(resourceId0, getResourceId(launchResources.get(0))); Assert.assertEquals(resourceId1, getResourceId(launchResources.get(1))); Assert.assertFalse(recommendations.get(1).getOperation().isPresent()); }
/** * This method keeps the resources associated with tasks in the state store up to date, when a task which shares * their resource-set is launched. * * @param podInstance the parent pod associated with the task being launched * @param taskInfo the task being launched */ @VisibleForTesting void updateTaskResourcesWithinResourceSet(PodInstance podInstance, Protos.TaskInfo taskInfo) { Optional<TaskSpec> taskSpec = TaskUtils.getTaskSpec(podInstance, taskInfo.getName()); if (!taskSpec.isPresent()) { return; } // Update any other TaskInfos in this resource set to have the same resources: Collection<Protos.TaskInfo> taskInfosWithSameResourceSet = getOtherTasksInResourceSet(podInstance, taskSpec.get()); stateStore.storeTasks(updateTasksWithResources( taskInfosWithSameResourceSet, taskInfo.getResourcesList(), taskInfo.hasExecutor() ? Optional.of(taskInfo.getExecutor().getResourcesList()) : Optional.empty())); }
@Test public void testLaunchExpectedStaticPort() throws Exception { // Launch for the first time: get port 555 PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(555); Resource reserveResource = recordLaunchWithCompleteOfferedResources( podInstanceRequirement, ResourceTestUtils.getUnreservedPorts(555, 555)).get(3); String resourceId = getResourceId(reserveResource); Collection<Resource> expectedResources = getExpectedExecutorResources( stateStore.fetchTasks().iterator().next().getExecutor()); expectedResources.add(ResourceTestUtils.getReservedPorts(555, 555, resourceId)); // Launch on previously reserved resources List<OfferRecommendation> recommendations = evaluator.evaluate( podInstanceRequirement, Arrays.asList(OfferTestUtils.getOffer(expectedResources))); Assert.assertEquals(2, recommendations.size()); // Validate LAUNCH Operation Protos.Offer.Operation launchOperation = recommendations.get(0).getOperation().get(); Assert.assertEquals(Operation.Type.LAUNCH_GROUP, launchOperation.getType()); Protos.Resource launchResource = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0).getResources(0); Assert.assertEquals(resourceId, getResourceId(launchResource)); Assert.assertFalse(recommendations.get(1).getOperation().isPresent()); }
public static Protos.Offer generateUpdateOffer( String frameworkId, Protos.TaskInfo taskInfo, Protos.TaskInfo templateTaskInfo, double cpu, int memory, int disk) { final String offerUUID = UUID.randomUUID().toString(); return Protos.Offer .newBuilder() .setId(Protos.OfferID.newBuilder().setValue(offerUUID)) .setFrameworkId(Protos.FrameworkID.newBuilder().setValue(frameworkId)) .setSlaveId(Protos.SlaveID.newBuilder().setValue(taskInfo.getSlaveId().getValue())) .setHostname("127.0.0.1") .addAllResources(taskInfo.getResourcesList()) .addAllResources(taskInfo.getExecutor().getResourcesList()) .addAllResources(templateTaskInfo.getResourcesList()) .addResources(ResourceUtils.getUnreservedScalar("cpus", cpu)) .addResources(ResourceUtils.getUnreservedScalar("mem", memory)) .addResources(ResourceUtils.getUnreservedScalar("disk", disk)) .build(); }
@Test public void testRelaunchExpectedScalar() throws Exception { PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getCpuRequirement(1.0); // Launch for the first time. String resourceId = getResourceId( recordLaunchWithCompleteOfferedResources( podInstanceRequirement, ResourceTestUtils.getUnreservedCpus(2.0)).get(3)); // Launch again on expected resources. Collection<Protos.Resource> expectedResources = getExpectedExecutorResources( stateStore.fetchTasks().iterator().next().getExecutor()); expectedResources.add(ResourceTestUtils.getReservedCpus(1.0, resourceId)); List<OfferRecommendation> recommendations = evaluator.evaluate( podInstanceRequirement, Arrays.asList(OfferTestUtils.getOffer(expectedResources))); Assert.assertEquals(2, recommendations.size()); // Validate LAUNCH Operation Protos.Offer.Operation launchOperation = recommendations.get(0).getOperation().get(); Protos.Resource launchResource = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0).getResources(0); Assert.assertEquals(Protos.Offer.Operation.Type.LAUNCH_GROUP, launchOperation.getType()); Assert.assertEquals(resourceId, getResourceId(launchResource)); }
@Test public void testLaunchExpectedDynamicPort() throws Exception { // Launch for the first time: get port 10000 PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(0); Resource reserveResource = recordLaunchWithCompleteOfferedResources( podInstanceRequirement, ResourceTestUtils.getUnreservedPorts(10000, 10000)).get(3); String resourceId = getResourceId(reserveResource); Collection<Resource> expectedResources = getExpectedExecutorResources( stateStore.fetchTasks().iterator().next().getExecutor()); expectedResources.add(ResourceTestUtils.getReservedPorts(10000, 10000, resourceId)); // Relaunch: detect (from envvar) and reuse previously reserved dynamic port 10000 List<OfferRecommendation> recommendations = evaluator.evaluate( podInstanceRequirement, Arrays.asList(OfferTestUtils.getOffer(expectedResources))); Assert.assertEquals(2, recommendations.size()); // Validate LAUNCH Operation Operation launchOperation = recommendations.get(0).getOperation().get(); Assert.assertEquals(Operation.Type.LAUNCH_GROUP, launchOperation.getType()); Resource launchResource = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0).getResources(0); Assert.assertEquals(resourceId, getResourceId(launchResource)); Assert.assertFalse(recommendations.get(1).getOperation().isPresent()); }
/** * Gets the task's status. * * @return The status associated with the task. */ public Protos.TaskStatus.Builder getStatusBuilder( final Protos.TaskState state, final Optional<String> message ) { Protos.TaskStatus.Builder builder = Protos.TaskStatus.newBuilder() .setSlaveId(info.getSlaveId()) .setTaskId(info.getTaskId()) .setState(state) .setData(getData().withState(state).getBytes()) .setExecutorId(info.getExecutor().getExecutorId()) .setSource(Protos.TaskStatus.Source.SOURCE_EXECUTOR); message.map(builder::setMessage); return builder; }
public static Protos.Offer generateReplacementOffer( String frameworkId, Protos.TaskInfo taskInfo, Protos.TaskInfo templateTaskInfo) { final String offerUUID = UUID.randomUUID().toString(); return Protos.Offer .newBuilder() .setId(Protos.OfferID.newBuilder().setValue(offerUUID)) .setFrameworkId(Protos.FrameworkID.newBuilder().setValue(frameworkId)) .setSlaveId(Protos.SlaveID.newBuilder().setValue(taskInfo.getSlaveId().getValue())) .setHostname("127.0.0.1") .addAllResources(taskInfo.getResourcesList()) .addAllResources(taskInfo.getExecutor().getResourcesList()) .addAllResources(templateTaskInfo.getResourcesList()) .build(); }
@Test public void shouldAddJarInfoAndRemoveContainerInfo() { when(configuration.isFrameworkUseDocker()).thenReturn(false); String address = "http://localhost:1234"; when(configuration.getFrameworkFileServerAddress()).thenReturn(address); when(configuration.nativeCommand(any())).thenReturn("ls"); TaskInfoFactory factory = new TaskInfoFactory(clusterState); Date now = new DateTime().withDayOfMonth(1).withDayOfYear(1).withYear(1970).withHourOfDay(1).withMinuteOfHour(2).withSecondOfMinute(3).withMillisOfSecond(400).toDate(); when(clock.now()).thenReturn(now); when(clock.nowUTC()).thenReturn(ZonedDateTime.now(ZoneOffset.UTC)); Protos.TaskInfo taskInfo = factory.createTask(configuration, frameworkState, getOffer(frameworkState.getFrameworkID()), clock); assertFalse(taskInfo.getContainer().isInitialized()); assertTrue(taskInfo.getExecutor().getCommand().isInitialized()); assertEquals(2, taskInfo.getCommand().getUrisCount()); assertTrue(taskInfo.getCommand().getUris(0).getValue().contains(address)); }
/** * Returns a list of all the resources associated with a task, including {@link Executor} resources. * * @param taskInfo The {@link Protos.TaskInfo} containing the {@link Protos.Resource}. * @return a list of {@link Protos.Resource}s. */ public static List<Protos.Resource> getAllResources(Protos.TaskInfo taskInfo) { // Get all resources from both the task level and the executor level List<Protos.Resource> resources = new ArrayList<>(taskInfo.getResourcesList()); if (taskInfo.hasExecutor()) { resources.addAll(taskInfo.getExecutor().getResourcesList()); } return resources; }
@Override public OfferRequirement getReplacementOfferRequirement(String type, Protos.TaskInfo taskInfo) { LOGGER.info("Getting replacement requirement for task: {}", taskInfo.getTaskId().getValue()); ExecutorInfo execInfo = taskInfo.getExecutor(); taskInfo = Protos.TaskInfo.newBuilder(taskInfo).clearExecutor().build(); try { return OfferRequirement.create(type, Arrays.asList(taskInfo), Optional.of(execInfo)); } catch (InvalidRequirementException e) { LOGGER.error("Failed to construct OfferRequirement with Exception: ", e); return null; } }
/** * Pretty-print mesos protobuf TaskInfo. * <p/> * XXX(erikdw): not including command, container (+data), nor health_check. */ public static String taskInfoToString(TaskInfo task) { Map<String, String> map = new LinkedHashMap<>(); map.put("task_id", task.getTaskId().getValue()); map.put("slave_id", task.getSlaveId().getValue()); map.putAll(resourcesToOrderedMap(task.getResourcesList())); map.put("executor_id", task.getExecutor().getExecutorId().getValue()); return JSONValue.toJSONString(map); }
private Protos.TaskInfo normalizeCassandraTaskInfo(CassandraDaemonTask daemonTask) { Protos.TaskInfo daemonTaskInfo = daemonTask.getTaskInfo(); Protos.ExecutorInfo expectedExecutorInfo = Protos.ExecutorInfo.newBuilder(daemonTaskInfo.getExecutor()) .setExecutorId(Protos.ExecutorID.newBuilder().setValue("")) .build(); daemonTaskInfo = Protos.TaskInfo.newBuilder(daemonTaskInfo) .setTaskId(Protos.TaskID.newBuilder().setValue("")) .setExecutor(expectedExecutorInfo) .build(); return daemonTaskInfo; }
/** * Gets the executor for the task. * * @return The CassandraTaskExecutor associated with the task. */ public CassandraTaskExecutor getExecutor() { return new CassandraTaskExecutor(info.getExecutor()); }
protected Protos.TaskStatus.Builder getStatusBuilder() { return Protos.TaskStatus.newBuilder() .setTaskId(getTaskInfo().getTaskId()) .setSlaveId(getTaskInfo().getSlaveId()) .setExecutorId(getTaskInfo().getExecutor().getExecutorId()) .setSource(Protos.TaskStatus.Source.SOURCE_EXECUTOR); }
public List<Variable> getEnv() { return taskInfo.getExecutor().getCommand().getEnvironment().getVariablesList(); }