Search in sources :

Example 6 with TaskLabelWriter

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

the class DefaultStepFactoryTest method testInitialStateForRunningTaskOnDefaultExecutorDependsOnReadinessCheck.

@Test
public void testInitialStateForRunningTaskOnDefaultExecutorDependsOnReadinessCheck() throws Exception {
    Capabilities mockCapabilities = Mockito.mock(Capabilities.class);
    Mockito.when(mockCapabilities.supportsDefaultExecutor()).thenReturn(true);
    Capabilities.overrideCapabilities(mockCapabilities);
    PodInstance podInstance = getPodInstanceWithASingleTask();
    List<String> tasksToLaunch = podInstance.getPod().getTasks().stream().map(taskSpec -> taskSpec.getName()).collect(Collectors.toList());
    UUID configId = UUID.randomUUID();
    configStore.setTargetConfig(configId);
    String taskName = podInstance.getName() + '-' + tasksToLaunch.get(0);
    stateStore.storeTasks(ImmutableList.of(Protos.TaskInfo.newBuilder().setName(taskName).setTaskId(CommonIdUtils.toTaskId(TestConstants.SERVICE_NAME, taskName)).setSlaveId(Protos.SlaveID.newBuilder().setValue("proto-field-required")).setLabels(new TaskLabelWriter(TestConstants.TASK_INFO).setTargetConfiguration(configId).setReadinessCheck(Protos.HealthCheck.newBuilder().build()).toProto()).build()));
    Protos.TaskInfo taskInfo = stateStore.fetchTask(taskName).get();
    stateStore.storeStatus(taskName, Protos.TaskStatus.newBuilder().setState(Protos.TaskState.TASK_RUNNING).setTaskId(taskInfo.getTaskId()).setLabels(Protos.Labels.newBuilder().addLabels(Protos.Label.newBuilder().setKey("readiness_check_passed").setValue("false").build()).build()).build());
    assertThat(((DefaultStepFactory) stepFactory).hasReachedGoalState(podInstance, stateStore.fetchTask(taskName).get()), is(false));
    Step step = stepFactory.getStep(podInstance, tasksToLaunch);
    assertThat(step.isComplete(), is(false));
    assertThat(step.isPending(), is(true));
    stateStore.storeStatus(taskName, Protos.TaskStatus.newBuilder().setState(Protos.TaskState.TASK_RUNNING).setTaskId(taskInfo.getTaskId()).setLabels(Protos.Labels.newBuilder().addLabels(Protos.Label.newBuilder().setKey("readiness_check_passed").setValue("true").build()).build()).build());
    assertThat(((DefaultStepFactory) stepFactory).hasReachedGoalState(podInstance, stateStore.fetchTask(taskName).get()), is(true));
    step = stepFactory.getStep(podInstance, tasksToLaunch);
    assertThat(step.isComplete(), is(true));
    assertThat(step.isPending(), is(false));
}
Also used : SchedulerConfigTestUtils(com.mesosphere.sdk.testutils.SchedulerConfigTestUtils) Protos(org.apache.mesos.Protos) SchedulerConfig(com.mesosphere.sdk.scheduler.SchedulerConfig) Arrays(java.util.Arrays) TestConstants(com.mesosphere.sdk.testutils.TestConstants) CommonIdUtils(com.mesosphere.sdk.offer.CommonIdUtils) Test(org.junit.Test) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) MemPersister(com.mesosphere.sdk.storage.MemPersister) TaskLabelWriter(com.mesosphere.sdk.offer.taskdata.TaskLabelWriter) ConfigStore(com.mesosphere.sdk.state.ConfigStore) Assert.assertThat(org.junit.Assert.assertThat) Mockito(org.mockito.Mockito) Capabilities(com.mesosphere.sdk.dcos.Capabilities) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) com.mesosphere.sdk.specification(com.mesosphere.sdk.specification) StateStore(com.mesosphere.sdk.state.StateStore) Persister(com.mesosphere.sdk.storage.Persister) Matchers.is(org.hamcrest.Matchers.is) TestPodFactory(com.mesosphere.sdk.testutils.TestPodFactory) Assert(org.junit.Assert) Protos(org.apache.mesos.Protos) Capabilities(com.mesosphere.sdk.dcos.Capabilities) TaskLabelWriter(com.mesosphere.sdk.offer.taskdata.TaskLabelWriter) UUID(java.util.UUID) Test(org.junit.Test)

Example 7 with TaskLabelWriter

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

the class DefaultStepFactoryTest method testTaskWithOnceGoalStateCanReachGoalState.

@Test
public void testTaskWithOnceGoalStateCanReachGoalState() throws Exception {
    Capabilities mockCapabilities = Mockito.mock(Capabilities.class);
    Mockito.when(mockCapabilities.supportsDefaultExecutor()).thenReturn(true);
    Capabilities.overrideCapabilities(mockCapabilities);
    PodInstance podInstance = getPodInstanceWithGoalState(GoalState.ONCE);
    List<String> tasksToLaunch = podInstance.getPod().getTasks().stream().map(taskSpec -> taskSpec.getName()).collect(Collectors.toList());
    UUID configId = UUID.randomUUID();
    configStore.setTargetConfig(configId);
    String taskName = podInstance.getName() + '-' + tasksToLaunch.get(0);
    stateStore.storeTasks(ImmutableList.of(Protos.TaskInfo.newBuilder().setName(taskName).setTaskId(CommonIdUtils.toTaskId(TestConstants.SERVICE_NAME, taskName)).setSlaveId(Protos.SlaveID.newBuilder().setValue("proto-field-required")).setLabels(new TaskLabelWriter(TestConstants.TASK_INFO).setTargetConfiguration(configId).toProto()).build()));
    Protos.TaskInfo taskInfo = stateStore.fetchTask(taskName).get();
    stateStore.storeStatus(taskName, Protos.TaskStatus.newBuilder().setState(Protos.TaskState.TASK_RUNNING).setTaskId(taskInfo.getTaskId()).build());
    assertThat(((DefaultStepFactory) stepFactory).hasReachedGoalState(podInstance, stateStore.fetchTask(taskName).get()), is(false));
    stateStore.storeStatus(taskName, Protos.TaskStatus.newBuilder().setState(Protos.TaskState.TASK_FINISHED).setTaskId(taskInfo.getTaskId()).build());
    assertThat(((DefaultStepFactory) stepFactory).hasReachedGoalState(podInstance, stateStore.fetchTask(taskName).get()), is(true));
}
Also used : SchedulerConfigTestUtils(com.mesosphere.sdk.testutils.SchedulerConfigTestUtils) Protos(org.apache.mesos.Protos) SchedulerConfig(com.mesosphere.sdk.scheduler.SchedulerConfig) Arrays(java.util.Arrays) TestConstants(com.mesosphere.sdk.testutils.TestConstants) CommonIdUtils(com.mesosphere.sdk.offer.CommonIdUtils) Test(org.junit.Test) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) MemPersister(com.mesosphere.sdk.storage.MemPersister) TaskLabelWriter(com.mesosphere.sdk.offer.taskdata.TaskLabelWriter) ConfigStore(com.mesosphere.sdk.state.ConfigStore) Assert.assertThat(org.junit.Assert.assertThat) Mockito(org.mockito.Mockito) Capabilities(com.mesosphere.sdk.dcos.Capabilities) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) com.mesosphere.sdk.specification(com.mesosphere.sdk.specification) StateStore(com.mesosphere.sdk.state.StateStore) Persister(com.mesosphere.sdk.storage.Persister) Matchers.is(org.hamcrest.Matchers.is) TestPodFactory(com.mesosphere.sdk.testutils.TestPodFactory) Assert(org.junit.Assert) Protos(org.apache.mesos.Protos) Capabilities(com.mesosphere.sdk.dcos.Capabilities) TaskLabelWriter(com.mesosphere.sdk.offer.taskdata.TaskLabelWriter) UUID(java.util.UUID) Test(org.junit.Test)

Example 8 with TaskLabelWriter

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

the class DefaultStepFactoryTest method testTaskWithFinishedGoalStateCanReachGoalState.

@Test
public void testTaskWithFinishedGoalStateCanReachGoalState() throws Exception {
    Capabilities mockCapabilities = Mockito.mock(Capabilities.class);
    Mockito.when(mockCapabilities.supportsDefaultExecutor()).thenReturn(true);
    Capabilities.overrideCapabilities(mockCapabilities);
    PodInstance podInstance = getPodInstanceWithGoalState(GoalState.FINISHED);
    List<String> tasksToLaunch = podInstance.getPod().getTasks().stream().map(taskSpec -> taskSpec.getName()).collect(Collectors.toList());
    UUID configId = UUID.randomUUID();
    configStore.setTargetConfig(configId);
    String taskName = podInstance.getName() + '-' + tasksToLaunch.get(0);
    stateStore.storeTasks(ImmutableList.of(Protos.TaskInfo.newBuilder().setName(taskName).setTaskId(CommonIdUtils.toTaskId(TestConstants.SERVICE_NAME, taskName)).setSlaveId(Protos.SlaveID.newBuilder().setValue("proto-field-required")).setLabels(new TaskLabelWriter(TestConstants.TASK_INFO).setTargetConfiguration(configId).toProto()).build()));
    Protos.TaskInfo taskInfo = stateStore.fetchTask(taskName).get();
    stateStore.storeStatus(taskName, Protos.TaskStatus.newBuilder().setState(Protos.TaskState.TASK_RUNNING).setTaskId(taskInfo.getTaskId()).build());
    assertThat(((DefaultStepFactory) stepFactory).hasReachedGoalState(podInstance, stateStore.fetchTask(taskName).get()), is(false));
    stateStore.storeStatus(taskName, Protos.TaskStatus.newBuilder().setState(Protos.TaskState.TASK_FINISHED).setTaskId(taskInfo.getTaskId()).build());
    assertThat(((DefaultStepFactory) stepFactory).hasReachedGoalState(podInstance, stateStore.fetchTask(taskName).get()), is(true));
}
Also used : SchedulerConfigTestUtils(com.mesosphere.sdk.testutils.SchedulerConfigTestUtils) Protos(org.apache.mesos.Protos) SchedulerConfig(com.mesosphere.sdk.scheduler.SchedulerConfig) Arrays(java.util.Arrays) TestConstants(com.mesosphere.sdk.testutils.TestConstants) CommonIdUtils(com.mesosphere.sdk.offer.CommonIdUtils) Test(org.junit.Test) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) MemPersister(com.mesosphere.sdk.storage.MemPersister) TaskLabelWriter(com.mesosphere.sdk.offer.taskdata.TaskLabelWriter) ConfigStore(com.mesosphere.sdk.state.ConfigStore) Assert.assertThat(org.junit.Assert.assertThat) Mockito(org.mockito.Mockito) Capabilities(com.mesosphere.sdk.dcos.Capabilities) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) com.mesosphere.sdk.specification(com.mesosphere.sdk.specification) StateStore(com.mesosphere.sdk.state.StateStore) Persister(com.mesosphere.sdk.storage.Persister) Matchers.is(org.hamcrest.Matchers.is) TestPodFactory(com.mesosphere.sdk.testutils.TestPodFactory) Assert(org.junit.Assert) Protos(org.apache.mesos.Protos) Capabilities(com.mesosphere.sdk.dcos.Capabilities) TaskLabelWriter(com.mesosphere.sdk.offer.taskdata.TaskLabelWriter) UUID(java.util.UUID) Test(org.junit.Test)

Example 9 with TaskLabelWriter

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

the class DefaultRecoveryPlanManagerTest method beforeEach.

@Before
public void beforeEach() throws Exception {
    MockitoAnnotations.initMocks(this);
    failureMonitor = spy(new TestingFailureMonitor());
    launchConstrainer = spy(new TestingLaunchConstrainer());
    offerAccepter = mock(OfferAccepter.class);
    Persister persister = new MemPersister();
    frameworkStore = new FrameworkStore(persister);
    stateStore = new StateStore(persister);
    File recoverySpecFile = new File(getClass().getClassLoader().getResource("recovery-plan-manager-test.yml").getPath());
    serviceSpec = DefaultServiceSpec.newGenerator(recoverySpecFile, SCHEDULER_CONFIG).build();
    configStore = new ConfigStore<>(DefaultServiceSpec.getConfigurationFactory(serviceSpec), persister);
    UUID configTarget = configStore.store(serviceSpec);
    configStore.setTargetConfig(configTarget);
    taskInfo = TaskInfo.newBuilder(taskInfo).setLabels(new TaskLabelWriter(taskInfo).setTargetConfiguration(configTarget).setIndex(0).toProto()).setName("test-task-type-0-test-task-name").setTaskId(CommonIdUtils.toTaskId(TestConstants.SERVICE_NAME, "test-task-type-0-test-task-name")).build();
    taskInfos = Collections.singletonList(taskInfo);
    recoveryManager = spy(new DefaultRecoveryPlanManager(stateStore, configStore, new HashSet<>(Arrays.asList(taskInfo.getName())), launchConstrainer, failureMonitor));
    mockDeployManager = mock(PlanManager.class);
    final Plan mockDeployPlan = mock(Plan.class);
    when(mockDeployManager.getPlan()).thenReturn(mockDeployPlan);
    planScheduler = new DefaultPlanScheduler(offerAccepter, new OfferEvaluator(frameworkStore, stateStore, new OfferOutcomeTracker(), serviceSpec.getName(), configTarget, ArtifactResource.getUrlFactory(TestConstants.SERVICE_NAME), SchedulerConfigTestUtils.getTestSchedulerConfig(), Optional.empty(), true), stateStore);
    planCoordinator = new DefaultPlanCoordinator(Arrays.asList(mockDeployManager, recoveryManager));
}
Also used : TestingLaunchConstrainer(com.mesosphere.sdk.scheduler.recovery.constrain.TestingLaunchConstrainer) OfferAccepter(com.mesosphere.sdk.offer.OfferAccepter) MemPersister(com.mesosphere.sdk.storage.MemPersister) StateStore(com.mesosphere.sdk.state.StateStore) OfferEvaluator(com.mesosphere.sdk.offer.evaluate.OfferEvaluator) OfferOutcomeTracker(com.mesosphere.sdk.offer.history.OfferOutcomeTracker) TaskLabelWriter(com.mesosphere.sdk.offer.taskdata.TaskLabelWriter) MemPersister(com.mesosphere.sdk.storage.MemPersister) Persister(com.mesosphere.sdk.storage.Persister) TestingFailureMonitor(com.mesosphere.sdk.scheduler.recovery.monitor.TestingFailureMonitor) FrameworkStore(com.mesosphere.sdk.state.FrameworkStore) File(java.io.File) Before(org.junit.Before)

Example 10 with TaskLabelWriter

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

the class PortEvaluationStageTest method testDynamicPortNotStickyAfterReplacement.

@Test
public void testDynamicPortNotStickyAfterReplacement() throws Exception {
    // The initial dynamic port should be the min of the available range.
    Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10050);
    Protos.Offer offer = OfferTestUtils.getOffer(offeredPorts);
    PortSpec portSpec = new PortSpec(getPort(0), TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL, "PORT_TEST", "TEST", TestConstants.PORT_VISIBILITY, Collections.emptyList());
    PodInstanceRequirement podInstanceRequirement = getPodInstanceRequirement(portSpec);
    PodInfoBuilder podInfoBuilder = new PodInfoBuilder(podInstanceRequirement, TestConstants.SERVICE_NAME, UUID.randomUUID(), ArtifactResource.getUrlFactory(TestConstants.SERVICE_NAME), SchedulerConfigTestUtils.getTestSchedulerConfig(), Collections.emptyList(), TestConstants.FRAMEWORK_ID, true, Collections.emptyMap());
    PortEvaluationStage portEvaluationStage = new PortEvaluationStage(portSpec, TestConstants.TASK_NAME, Optional.empty(), Optional.empty());
    MesosResourcePool mesosResourcePool = new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE));
    EvaluationOutcome outcome = portEvaluationStage.evaluate(mesosResourcePool, podInfoBuilder);
    Assert.assertEquals(true, outcome.isPassing());
    Protos.TaskInfo.Builder taskBuilder = podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME);
    checkDiscoveryInfo(taskBuilder.getDiscovery(), "TEST", 10000);
    // In a restart, we want port stickiness. It should fail if the original dynamic port is not
    // available in the offer.
    Protos.TaskInfo.Builder currentTaskBuilder = podInfoBuilder.getTaskBuilders().stream().findFirst().get();
    podInfoBuilder = new PodInfoBuilder(podInstanceRequirement, TestConstants.SERVICE_NAME, UUID.randomUUID(), ArtifactResource.getUrlFactory(TestConstants.SERVICE_NAME), SchedulerConfigTestUtils.getTestSchedulerConfig(), Collections.singleton(currentTaskBuilder.build()), TestConstants.FRAMEWORK_ID, true, Collections.emptyMap());
    // Omit 10,000 the expected port.
    offer = OfferTestUtils.getOffer(ResourceTestUtils.getUnreservedPorts(10001, 10050));
    mesosResourcePool = new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE));
    outcome = portEvaluationStage.evaluate(mesosResourcePool, podInfoBuilder);
    Assert.assertEquals(false, outcome.isPassing());
    // In permanent replacement, the previous dynamic port should be discarded, so an offer
    // without that port should be valid.
    currentTaskBuilder.setLabels(new TaskLabelWriter(currentTaskBuilder).setPermanentlyFailed().toProto());
    podInfoBuilder = new PodInfoBuilder(podInstanceRequirement, TestConstants.SERVICE_NAME, UUID.randomUUID(), ArtifactResource.getUrlFactory(TestConstants.SERVICE_NAME), SchedulerConfigTestUtils.getTestSchedulerConfig(), Collections.singleton(currentTaskBuilder.build()), TestConstants.FRAMEWORK_ID, true, Collections.emptyMap());
    mesosResourcePool = new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE));
    outcome = portEvaluationStage.evaluate(mesosResourcePool, podInfoBuilder);
    Assert.assertEquals(true, outcome.isPassing());
}
Also used : Protos(org.apache.mesos.Protos) TaskLabelWriter(com.mesosphere.sdk.offer.taskdata.TaskLabelWriter) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) Test(org.junit.Test)

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