Search in sources :

Example 11 with TaskLabelWriter

use of com.mesosphere.sdk.offer.taskdata.TaskLabelWriter in project dcos-commons by mesosphere.

the class StateStoreUtilsTest method newTaskInfo.

private static Protos.TaskInfo newTaskInfo(final String taskName, final ConfigStore<ServiceSpec> configStore) throws ConfigStoreException {
    Protos.TaskInfo.Builder taskInfoBuilder = newTaskInfo(taskName).toBuilder();
    // POD type
    final UUID targetConfig = configStore.getTargetConfig();
    final int podIndex = 0;
    final String podType = configStore.fetch(targetConfig).getPods().get(podIndex).getType();
    // create default labels:
    taskInfoBuilder.setLabels(new TaskLabelWriter(taskInfoBuilder).setTargetConfiguration(targetConfig).setType(podType).setIndex(podIndex).toProto());
    return taskInfoBuilder.build();
}
Also used : TaskLabelWriter(com.mesosphere.sdk.offer.taskdata.TaskLabelWriter) UUID(java.util.UUID)

Example 12 with TaskLabelWriter

use of com.mesosphere.sdk.offer.taskdata.TaskLabelWriter in project dcos-commons by mesosphere.

the class PersistentLaunchRecorderTest method testUpdateResourcesNoSharedTasksInStateStore.

@Test
public void testUpdateResourcesNoSharedTasksInStateStore() throws TaskException {
    Protos.Resource targetResource = Protos.Resource.newBuilder().setName("cpus").setType(Protos.Value.Type.SCALAR).setScalar(Protos.Value.Scalar.newBuilder().setValue(1.0)).build();
    String taskName = "pod-0-init";
    Protos.TaskInfo taskInfo = baseTaskInfo.toBuilder().setLabels(new TaskLabelWriter(baseTaskInfo).setType("pod").setIndex(0).toProto()).setName(taskName).addAllResources(Arrays.asList(targetResource)).build();
    stateStore.storeTasks(Arrays.asList(taskInfo));
    Assert.assertEquals(1, stateStore.fetchTaskNames().size());
    persistentLaunchRecorder.updateTaskResourcesWithinResourceSet(persistentLaunchRecorder.getPodInstance(taskInfo).get(), taskInfo);
    Assert.assertEquals(1, stateStore.fetchTaskNames().size());
    Assert.assertEquals(targetResource, stateStore.fetchTask(taskName).get().getResources(0));
}
Also used : Protos(org.apache.mesos.Protos) TaskLabelWriter(com.mesosphere.sdk.offer.taskdata.TaskLabelWriter) Test(org.junit.Test)

Example 13 with TaskLabelWriter

use of com.mesosphere.sdk.offer.taskdata.TaskLabelWriter in project dcos-commons by mesosphere.

the class TaskUtilsTest method buildTask.

private static Protos.TaskInfo buildTask(ConfigStore<ServiceSpec> configStore, int index, String task) {
    Protos.TaskInfo.Builder taskBuilder = Protos.TaskInfo.newBuilder().setTaskId(TestConstants.TASK_ID).setSlaveId(TestConstants.AGENT_ID).setName(String.format("server-%d-%s", index, task));
    UUID id;
    try {
        id = configStore.getTargetConfig();
    } catch (ConfigStoreException e) {
        throw new IllegalStateException(e);
    }
    taskBuilder.setLabels(new TaskLabelWriter(taskBuilder).setIndex(index).setType("server").setTargetConfiguration(id).toProto());
    return taskBuilder.build();
}
Also used : ConfigStoreException(com.mesosphere.sdk.state.ConfigStoreException) TaskLabelWriter(com.mesosphere.sdk.offer.taskdata.TaskLabelWriter) UUID(java.util.UUID)

Example 14 with TaskLabelWriter

use of com.mesosphere.sdk.offer.taskdata.TaskLabelWriter in project dcos-commons by mesosphere.

the class RoundRobinByHostnameRuleTest method getTaskInfo.

private static TaskInfo getTaskInfo(String name, String host) {
    TaskInfo.Builder infoBuilder = TaskTestUtils.getTaskInfo(Collections.emptyList()).toBuilder().setName(name).setTaskId(CommonIdUtils.toTaskId(TestConstants.SERVICE_NAME, name));
    infoBuilder.setLabels(new TaskLabelWriter(infoBuilder).setHostname(offerWithHost(host)).toProto());
    return infoBuilder.build();
}
Also used : TaskInfo(org.apache.mesos.Protos.TaskInfo) TaskLabelWriter(com.mesosphere.sdk.offer.taskdata.TaskLabelWriter)

Example 15 with TaskLabelWriter

use of com.mesosphere.sdk.offer.taskdata.TaskLabelWriter in project dcos-commons by mesosphere.

the class TaskTypeRuleTest method getTask.

private static TaskInfo getTask(String type, String id, String agent) {
    TaskInfo.Builder taskBuilder = TaskTestUtils.getTaskInfo(Collections.emptyList()).toBuilder();
    taskBuilder.getTaskIdBuilder().setValue(id);
    try {
        taskBuilder.setName(CommonIdUtils.toTaskName(taskBuilder.getTaskId()));
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
    taskBuilder.getSlaveIdBuilder().setValue(agent);
    taskBuilder.setLabels(new TaskLabelWriter(taskBuilder).setType(type).toProto());
    return taskBuilder.build();
}
Also used : TaskInfo(org.apache.mesos.Protos.TaskInfo) TaskLabelWriter(com.mesosphere.sdk.offer.taskdata.TaskLabelWriter) InvalidRequirementException(com.mesosphere.sdk.offer.InvalidRequirementException) IOException(java.io.IOException)

Aggregations

TaskLabelWriter (com.mesosphere.sdk.offer.taskdata.TaskLabelWriter)21 Protos (org.apache.mesos.Protos)11 Test (org.junit.Test)9 UUID (java.util.UUID)7 StateStore (com.mesosphere.sdk.state.StateStore)6 MemPersister (com.mesosphere.sdk.storage.MemPersister)6 Persister (com.mesosphere.sdk.storage.Persister)6 TaskInfo (org.apache.mesos.Protos.TaskInfo)6 ImmutableList (com.google.common.collect.ImmutableList)5 Capabilities (com.mesosphere.sdk.dcos.Capabilities)5 CommonIdUtils (com.mesosphere.sdk.offer.CommonIdUtils)5 SchedulerConfig (com.mesosphere.sdk.scheduler.SchedulerConfig)5 com.mesosphere.sdk.specification (com.mesosphere.sdk.specification)5 ConfigStore (com.mesosphere.sdk.state.ConfigStore)5 SchedulerConfigTestUtils (com.mesosphere.sdk.testutils.SchedulerConfigTestUtils)5 TestConstants (com.mesosphere.sdk.testutils.TestConstants)5 TestPodFactory (com.mesosphere.sdk.testutils.TestPodFactory)5 Arrays (java.util.Arrays)5 List (java.util.List)5 Collectors (java.util.stream.Collectors)5