Java Code Examples for org.apache.mesos.Protos#TaskInfo

The following examples show how to use org.apache.mesos.Protos#TaskInfo . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskInfoBuilder.java    From logstash with Apache License 2.0 6 votes vote down vote up
private Protos.TaskInfo buildNativeTask(String taskId, Protos.Offer offer) {
    ExecutorEnvironmentalVariables executorEnvVars = new ExecutorEnvironmentalVariables(executorConfig, logstashConfig);
    executorEnvVars.addToList(ExecutorEnvironmentalVariables.LOGSTASH_PATH, "./logstash-" + LOGSTASH_VERSION + "/bin/logstash");

    Protos.CommandInfo.Builder commandInfoBuilder = Protos.CommandInfo.newBuilder()
            .setEnvironment(Protos.Environment.newBuilder().addAllVariables(
                    executorEnvVars.getList()))
            .setValue(frameworkConfig.getExecutorCommand())
            .addAllUris(Arrays.asList(
                    Protos.CommandInfo.URI.newBuilder().setValue(frameworkConfig.getLogstashTarballUri()).build(),
                    Protos.CommandInfo.URI.newBuilder().setValue(frameworkConfig.getLogstashExecutorUri()).build()
            ));

    Protos.ExecutorInfo executorInfo = Protos.ExecutorInfo.newBuilder()
            .setName(LogstashConstants.NODE_NAME + " executor")
            .setExecutorId(Protos.ExecutorID.newBuilder().setValue("executor." + UUID.randomUUID()))
            .setCommand(commandInfoBuilder)
            .build();

    return createTask(taskId, offer, executorInfo);
}
 
Example 2
Source File: TaskInfoFactoryTest.java    From elasticsearch with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example 3
Source File: OfferEvaluatorPortsTest.java    From dcos-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testReserveTaskDynamicPort() throws Exception {
    Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000);
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(0);

    List<OfferRecommendation> recommendations =
            evaluator.evaluate(podInstanceRequirement, OfferTestUtils.getCompleteOffers(offeredPorts));

    Assert.assertEquals(6, recommendations.size());

    Protos.Offer.Operation launchOperation = recommendations.get(4).getOperation().get();
    Assert.assertFalse(recommendations.get(5).getOperation().isPresent());

    Protos.TaskInfo taskInfo = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0);
    Protos.Resource fulfilledPortResource = taskInfo.getResources(0);
    Assert.assertFalse(getResourceId(fulfilledPortResource).isEmpty());

    Map<String, Protos.Environment.Variable> envvars = EnvUtils.toMap(taskInfo.getCommand().getEnvironment());
    Assert.assertEquals(envvars.toString(),
            String.valueOf(10000), envvars.get(TestConstants.PORT_ENV_NAME + "_0").getValue());
}
 
Example 4
Source File: RestoreSnapshotTask.java    From dcos-cassandra-service with Apache License 2.0 6 votes vote down vote up
public static RestoreSnapshotTask create(
        final Protos.TaskInfo template,
        final CassandraDaemonTask daemon,
        final BackupRestoreContext context) {

    CassandraData data = CassandraData.createRestoreSnapshotData(
            "",
            context
                .forNode(daemon.getName())
                .withLocalLocation(daemon.getVolumePath() + "/data"));

    String name = nameForDaemon(daemon);
    Protos.TaskInfo completedTemplate = Protos.TaskInfo.newBuilder(template)
            .setName(name)
            .setTaskId(TaskUtils.toTaskId(name))
            .setData(data.getBytes())
            .build();

    completedTemplate = org.apache.mesos.offer.TaskUtils.clearTransient(completedTemplate);

    return new RestoreSnapshotTask(completedTemplate);
}
 
Example 5
Source File: SimulatedRemoteMesosSchedulerDriver.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
private SimulatedTask toSimulatedTask(Protos.TaskInfo taskInfo) {
    TitanProtos.ContainerInfo containerInfo;
    try {
        containerInfo = TitanProtos.ContainerInfo.parseFrom(taskInfo.getData());
    } catch (InvalidProtocolBufferException e) {
        throw new IllegalStateException(e);
    }

    Map<String, String> completeEnv = new HashMap<>(containerInfo.getTitusProvidedEnvMap());
    completeEnv.putAll(containerInfo.getUserProvidedEnvMap());

    return SimulatedTask.newBuilder()
            .setTaskId(taskInfo.getTaskId().getValue())
            .setInstanceId(taskInfo.getSlaveId().getValue())
            .setComputeResources(TitusCloudSimulator.SimulatedComputeResources.newBuilder()
                    .setCpu(getResourceValue("cpus", taskInfo))
                    .setGpu(getResourceValue("gpu", taskInfo))
                    .setMemoryMB(getResourceValue("mem", taskInfo))
                    .setDiskMB(getResourceValue("disk", taskInfo))
                    .setNetworkMB(getResourceValue("network", taskInfo))
            )
            .setEniLabel(containerInfo.getNetworkConfigInfo().getEniLabel())
            .putAllEnv(completeEnv)
            .build();
}
 
Example 6
Source File: StateStoreTest.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testStoreFetchTaskAndStatus() throws Exception {
    Protos.TaskInfo testTask = createTask(TestConstants.TASK_NAME);
    store.storeTasks(Arrays.asList(testTask));
    Collection<Protos.TaskInfo> outTasks = store.fetchTasks();
    assertEquals(1, outTasks.size());
    assertEquals(testTask, outTasks.iterator().next());

    store.storeStatus(TestConstants.TASK_NAME, TASK_STATUS);
    assertEquals(TASK_STATUS, store.fetchStatus(TestConstants.TASK_NAME).get());
}
 
Example 7
Source File: DefaultSchedulerTest.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
private static Protos.TaskInfo getTask(Collection<OfferRecommendation> operations) {
    for (OfferRecommendation operation : operations) {
        if (operation.getOperation().get().getType().equals(Offer.Operation.Type.LAUNCH_GROUP)) {
            return operation.getOperation().get().getLaunchGroup().getTaskGroup().getTasks(0);
        }
    }

    return null;
}
 
Example 8
Source File: OfferEvaluatorPortsTest.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testReserveStaticPort() throws Exception {
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(555);
    Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(555, 555);

    List<OfferRecommendation> recommendations =
            evaluator.evaluate(podInstanceRequirement, OfferTestUtils.getCompleteOffers(offeredPorts));

    Assert.assertEquals(Arrays.asList(
            Protos.Offer.Operation.Type.RESERVE,
            Protos.Offer.Operation.Type.RESERVE,
            Protos.Offer.Operation.Type.RESERVE,
            Protos.Offer.Operation.Type.RESERVE,
            Offer.Operation.Type.LAUNCH_GROUP,
            null),
            recommendations.stream()
                    .map(rec -> rec.getOperation().isPresent() ? rec.getOperation().get().getType() : null)
                    .collect(Collectors.toList()));

    Protos.Offer.Operation launchOperation = recommendations.get(4).getOperation().get();
    Protos.TaskInfo taskInfo = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0);
    Protos.Resource fulfilledPortResource = taskInfo.getResources(0);
    Assert.assertFalse(getResourceId(fulfilledPortResource).isEmpty());

    Map<String, Protos.Environment.Variable> envvars = EnvUtils.toMap(taskInfo.getCommand().getEnvironment());
    Assert.assertEquals(String.valueOf(555), envvars.get(TestConstants.PORT_ENV_NAME + "_555").getValue());
}
 
Example 9
Source File: TaskInfoFactory.java    From elasticsearch with Apache License 2.0 5 votes vote down vote up
public static Task parse(Protos.TaskInfo taskInfo, Protos.TaskStatus taskStatus, Clock clock) {
    Properties data = new Properties();
    try {
        data.load(taskInfo.getData().newInput());
    } catch (IOException e) {
        throw new RuntimeException("Failed to parse properties", e);
    }

    String hostName = Optional.ofNullable(data.getProperty("hostname")).orElseGet(() -> {
        LOGGER.error("Hostname is empty. Reported IP addresses will be incorrect.");
        return "";
    });
    String ipAddress = data.getProperty("ipAddress", hostName);

    final ZonedDateTime startedAt = Optional.ofNullable(data.getProperty("startedAt"))
            .map(s -> s.endsWith("...") ? s.substring(0, 29) : s) //We're convert dates that was capped with Properties.list() method, see https://github.com/mesos/elasticsearch/pull/367
            .map(ZonedDateTime::parse)
            .orElseGet(clock::nowUTC)
            .withZoneSameInstant(ZoneOffset.UTC);

    if (!taskInfo.getDiscovery().isInitialized()) {
        throw new IndexOutOfBoundsException("TaskInfo has no discovery information.");
    }

    return new Task(
            hostName,
            taskInfo.getTaskId().getValue(),
            taskStatus == null ? Protos.TaskState.TASK_STAGING : taskStatus.getState(),
            startedAt,
            new InetSocketAddress(ipAddress, taskInfo.getDiscovery().getPorts().getPorts(Discovery.CLIENT_PORT_INDEX).getNumber()),
            new InetSocketAddress(ipAddress, taskInfo.getDiscovery().getPorts().getPorts(Discovery.TRANSPORT_PORT_INDEX).getNumber())
    );
}
 
Example 10
Source File: PerformanceToolUtil.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
/**
 * Performance tool annotations are encoded as environment variables like this:
 * {@code TASK_LIFECYCLE_1=selector: slots=0.. slotStep=2; launched: delay=2s; startInitiated: delay=3s; started: delay=60s; killInitiated: delay=5s}<br>
 */
public static Map<String, String> findPerformanceTestAnnotations(Protos.TaskInfo taskInfo) {
    TitanProtos.ContainerInfo containerInfo;
    try {
        containerInfo = TitanProtos.ContainerInfo.parseFrom(taskInfo.getData());
    } catch (InvalidProtocolBufferException e) {
        return Collections.emptyMap();
    }
    return findTaskLifecycleEnv(containerInfo.getUserProvidedEnvMap())
            .map(PerformanceToolUtil::toAnnotations)
            .orElse(Collections.emptyMap());
}
 
Example 11
Source File: StateStoreUtilsTest.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
private static Protos.TaskInfo newTaskInfo(final String taskName, final Protos.TaskID taskID) {
    Protos.TaskInfo.Builder taskBuilder = Protos.TaskInfo.newBuilder()
            .setName(taskName)
            .setTaskId(taskID);
    taskBuilder.getSlaveIdBuilder().setValue("proto-field-required");
    return taskBuilder.build();
}
 
Example 12
Source File: TaskInfoFactoryTest.java    From elasticsearch with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldAllowUserRequestForFixedHttpAndRandomTransportPort() {
    when(configuration.getElasticsearchPorts()).thenReturn(Arrays.asList(123, 0));
    TaskInfoFactory factory = new TaskInfoFactory(clusterState);
    Protos.TaskInfo taskInfo = factory.createTask(configuration, frameworkState, getOffer(frameworkState.getFrameworkID()), new Clock());
    assertTrue(taskInfo.isInitialized());
    assertTrue(taskInfo.toString().contains("123"));
    assertTrue(taskInfo.toString().contains("9200"));
}
 
Example 13
Source File: ServiceTest.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
@Override
public void expect(ClusterState state, SchedulerDriver mockDriver) throws AssertionError {
    Optional<Protos.TaskInfo> task = new StateStore(persisterWithTasks).fetchTask(taskName);
    Assert.assertTrue(String.format("Task %s not found", taskName), task.isPresent());
    Assert.assertEquals(String.format("Expected zero resources, got: %s", task.get().getResourcesList()),
            0, task.get().getResourcesCount());
}
 
Example 14
Source File: AbstractRoundRobinRuleTest.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
private List<Protos.TaskInfo> getDummyTasks(int count) {
    List<Protos.TaskInfo> tasks = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        tasks.add(TestConstants.TASK_INFO);
    }

    return tasks;
}
 
Example 15
Source File: MesosNimbusTest.java    From storm with Apache License 2.0 4 votes vote down vote up
private boolean hasResources(Protos.TaskInfo taskInfo, Double cpus, Double mem, Long port) {
  return hasResources(taskInfo.getResourcesList(), cpus, mem, port);
}
 
Example 16
Source File: LaunchOfferRecommendation.java    From dcos-commons with Apache License 2.0 4 votes vote down vote up
public Protos.TaskInfo getTaskInfo() {
  return operation.getLaunchGroup().getTaskGroup().getTasks(0);
}
 
Example 17
Source File: NodeTargetStateTest.java    From cassandra-mesos-deprecated with Apache License 2.0 4 votes vote down vote up
@Test
public void testServerTaskRemove() throws InvalidProtocolBufferException {

    final Protos.TaskInfo[] executorMetadata = threeNodeCluster();

    // cluster now up with 3 running nodes

    // server-task no longer running
    executorTaskError(executorMetadata[0]);

    // server-task cannot start again
    launchExecutor(slaves[0], 3);
    executorTaskRunning(executorMetadata[0]);
    launchTask(slaves[0], CassandraFrameworkProtos.TaskDetails.TaskDetailsType.CASSANDRA_SERVER_RUN);

}
 
Example 18
Source File: OfferEvaluatorTest.java    From dcos-commons with Apache License 2.0 4 votes vote down vote up
@Test
public void testTransientToPermanentFailure() throws Exception {
    ServiceSpec serviceSpec = getServiceSpec("resource-set-seq.yml");

    PodSpec podSpec = serviceSpec.getPods().get(0);
    PodInstance podInstance = new DefaultPodInstance(podSpec, 0);
    PodInstanceRequirement podInstanceRequirement =
            PodInstanceRequirement.newBuilder(podInstance, Arrays.asList("node")).build();

    Protos.Offer sufficientOffer = OfferTestUtils.getCompleteOffer(Arrays.asList(
            ResourceTestUtils.getUnreservedCpus(3.0),
            ResourceTestUtils.getUnreservedDisk(500.0)));

    // Launch Task with RUNNING goal state, for first time.
    List<OfferRecommendation> recommendations = evaluator.evaluate(
            podInstanceRequirement,
            Arrays.asList(sufficientOffer));

    Assert.assertEquals(Arrays.asList(
            // Executor creation
            Protos.Offer.Operation.Type.RESERVE,
            Protos.Offer.Operation.Type.RESERVE,
            Protos.Offer.Operation.Type.RESERVE,
            // backup task (ResourceSet=sidecar-resources) -- no launch
            Protos.Offer.Operation.Type.RESERVE,
            null,
            // bootstrap+format+node tasks (ResourceSet=name-resources) -- only node is launched
            Protos.Offer.Operation.Type.RESERVE,
            Protos.Offer.Operation.Type.RESERVE,
            Protos.Offer.Operation.Type.CREATE,
            null,
            null,
            Protos.Offer.Operation.Type.LAUNCH_GROUP,
            null),
            recommendations.stream()
                    .map(rec -> rec.getOperation().isPresent() ? rec.getOperation().get().getType() : null)
                    .collect(Collectors.toList()));

    recordOperations(recommendations);

    // Fail the task due to a lost Agent
    Protos.TaskInfo taskInfo = stateStore.fetchTask(TaskUtils.getTaskNames(podInstance).get(0)).get();
    final Protos.TaskStatus failedStatus = TaskTestUtils.generateStatus(
            taskInfo.getTaskId(),
            Protos.TaskState.TASK_LOST);
    stateStore.storeStatus(taskInfo.getName(), failedStatus);

    // Mark the pod instance as permanently failed.
    FailureUtils.setPermanentlyFailed(stateStore, podInstance);
    recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(sufficientOffer));

    // A new deployment replaces the prior one above.
    Assert.assertEquals(Arrays.asList(
            // Executor creation
            Protos.Offer.Operation.Type.RESERVE,
            Protos.Offer.Operation.Type.RESERVE,
            Protos.Offer.Operation.Type.RESERVE,
            // backup task (ResourceSet=sidecar-resources) -- no launch
            Protos.Offer.Operation.Type.RESERVE,
            null,
            // bootstrap+format+node tasks (ResourceSet=name-resources) -- only node is launched
            Protos.Offer.Operation.Type.RESERVE,
            Protos.Offer.Operation.Type.RESERVE,
            Protos.Offer.Operation.Type.CREATE,
            null,
            null,
            Protos.Offer.Operation.Type.LAUNCH_GROUP,
            null),
            recommendations.stream()
                    .map(rec -> rec.getOperation().isPresent() ? rec.getOperation().get().getType() : null)
                    .collect(Collectors.toList()));
}
 
Example 19
Source File: AbstractCassandraSchedulerTest.java    From cassandra-mesos-deprecated with Apache License 2.0 4 votes vote down vote up
protected void sendHealthCheckResult(final Protos.TaskInfo taskInfo, final CassandraFrameworkProtos.HealthCheckDetails healthCheckDetails) {
    scheduler.frameworkMessage(driver, executorId(taskInfo), taskInfo.getSlaveId(),
        CassandraFrameworkProtos.SlaveStatusDetails.newBuilder()
            .setStatusDetailsType(CassandraFrameworkProtos.SlaveStatusDetails.StatusDetailsType.HEALTH_CHECK_DETAILS)
            .setHealthCheckDetails(healthCheckDetails).build().toByteArray());
}
 
Example 20
Source File: TaskUtils.java    From dcos-commons with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the zone of a task.
 *
 * @param taskInfo The {@link TaskInfo} to get zone information from.
 * @return A string indicating the zone the task is in.
 */
public static String getTaskZone(Protos.TaskInfo taskInfo) {
  return taskInfo.getCommand().getEnvironment().getVariablesList().stream()
      .filter(variable -> variable.getName().equals(EnvConstants.ZONE_TASKENV)).findFirst().get().getValue();
}