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));
}
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));
}
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));
}
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));
}
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());
}
Aggregations