use of com.mesosphere.sdk.offer.MesosResourcePool in project dcos-commons by mesosphere.
the class TLSEvaluationStageTest method testSuccessTLS.
@Test
public void testSuccessTLS() throws Exception {
ArrayList<TransportEncryptionSpec> transportEncryptionSpecs = new ArrayList<>();
transportEncryptionSpecs.add(new DefaultTransportEncryptionSpec.Builder().name("test-tls").type(TransportEncryptionSpec.Type.TLS).build());
Protos.Offer offer = OfferTestUtils.getOffer(ResourceTestUtils.getUnreservedCpus(2.0));
PodInfoBuilder podInfoBuilder = getPodInfoBuilderForTransportEncryption(transportEncryptionSpecs);
EvaluationOutcome outcome = tlsEvaluationStage.evaluate(new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE)), podInfoBuilder);
Assert.assertTrue(outcome.isPassing());
// Check that TLS update was invoked
verify(mockTLSArtifactsUpdater).update(Matchers.any(), Matchers.any(), Matchers.eq("test-tls"));
Protos.ContainerInfo executorContainer = podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME).getExecutor().getContainer();
Assert.assertEquals(0, executorContainer.getVolumesCount());
Protos.ContainerInfo taskContainer = podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME).getContainer();
assertTLSArtifacts(taskContainer, tlsArtifactPaths, "test-tls");
}
use of com.mesosphere.sdk.offer.MesosResourcePool in project dcos-commons by mesosphere.
the class TLSEvaluationStageTest method testFailure.
@Test
public void testFailure() throws Exception {
doThrow(new IOException("test")).when(mockTLSArtifactsUpdater).update(Matchers.any(), Matchers.any(), Matchers.any());
ArrayList<TransportEncryptionSpec> transportEncryptionSpecs = new ArrayList<>();
transportEncryptionSpecs.add(new DefaultTransportEncryptionSpec.Builder().name("test-tls").type(TransportEncryptionSpec.Type.TLS).build());
Protos.Offer offer = OfferTestUtils.getOffer(ResourceTestUtils.getUnreservedCpus(2.0));
PodInfoBuilder podInfoBuilder = getPodInfoBuilderForTransportEncryption(transportEncryptionSpecs);
EvaluationOutcome outcome = tlsEvaluationStage.evaluate(new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE)), podInfoBuilder);
Assert.assertFalse(outcome.isPassing());
}
use of com.mesosphere.sdk.offer.MesosResourcePool in project dcos-commons by mesosphere.
the class PlacementRuleEvaluationStageTest method testOfferPassesPlacementRule.
@Test
public void testOfferPassesPlacementRule() throws Exception {
String agent = "test-agent";
Protos.Resource offered = ResourceTestUtils.getUnreservedCpus(1.0);
PlacementRule rule = AgentRule.require(agent);
Protos.Offer offer = offerWithAgent(agent, offered);
MesosResourcePool mesosResourcePool = new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE));
PodSpec podSpec = PodInstanceRequirementTestUtils.getCpuRequirement(1.0).getPodInstance().getPod();
DefaultPodSpec.newBuilder(podSpec).placementRule(rule);
PodInstance podInstance = new DefaultPodInstance(podSpec, 0);
List<String> taskNames = TaskUtils.getTaskNames(podInstance);
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, taskNames).build();
PlacementRuleEvaluationStage placementRuleEvaluationStage = new PlacementRuleEvaluationStage(Collections.emptyList(), rule);
EvaluationOutcome outcome = placementRuleEvaluationStage.evaluate(mesosResourcePool, new PodInfoBuilder(podInstanceRequirement, TestConstants.SERVICE_NAME, UUID.randomUUID(), ArtifactResource.getUrlFactory(TestConstants.SERVICE_NAME), SchedulerConfigTestUtils.getTestSchedulerConfig(), Collections.emptyList(), TestConstants.FRAMEWORK_ID, true, Collections.emptyMap()));
Assert.assertTrue(outcome.isPassing());
Assert.assertEquals(3, mesosResourcePool.getUnreservedMergedPool().size());
Assert.assertTrue(Math.abs(mesosResourcePool.getUnreservedMergedPool().get("cpus").getScalar().getValue() - 1.1) < 0.01);
}
use of com.mesosphere.sdk.offer.MesosResourcePool in project dcos-commons by mesosphere.
the class ExecutorEvaluationStageTest method testRejectOfferWithoutExpectedExecutorIdCustomExecutor.
@Test
public void testRejectOfferWithoutExpectedExecutorIdCustomExecutor() throws Exception {
useCustomExecutor();
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getCpuRequirement(1.0);
// Record launch and RUNNING status
String resourceId = getFirstResourceId(recordLaunchWithOfferedResources(podInstanceRequirement, ResourceTestUtils.getUnreservedCpus(1.0)));
String taskName = stateStore.fetchTaskNames().stream().findFirst().get();
Protos.TaskInfo taskInfo = stateStore.fetchTask(taskName).get();
stateStore.storeStatus(taskInfo.getName(), Protos.TaskStatus.newBuilder().setState(Protos.TaskState.TASK_RUNNING).setTaskId(taskInfo.getTaskId()).build());
Protos.Resource expectedTaskCpu = ResourceTestUtils.getReservedCpus(1.0, resourceId);
MesosResourcePool resources = new MesosResourcePool(OfferTestUtils.getOffer(Arrays.asList(expectedTaskCpu)), Optional.of(Constants.ANY_ROLE));
ExecutorEvaluationStage executorEvaluationStage = new ExecutorEvaluationStage(TestConstants.SERVICE_NAME, Optional.of(taskInfo.getExecutor().getExecutorId()));
EvaluationOutcome outcome = executorEvaluationStage.evaluate(resources, new PodInfoBuilder(podInstanceRequirement, TestConstants.SERVICE_NAME, UUID.randomUUID(), ArtifactResource.getUrlFactory(TestConstants.SERVICE_NAME), SchedulerConfigTestUtils.getTestSchedulerConfig(), stateStore.fetchTasks(), frameworkStore.fetchFrameworkId().get(), false, Collections.emptyMap()));
Assert.assertFalse(outcome.isPassing());
}
use of com.mesosphere.sdk.offer.MesosResourcePool in project dcos-commons by mesosphere.
the class LaunchEvaluationStageTest method labelsAreCorrect.
@Test
public void labelsAreCorrect() {
stage.evaluate(new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE)), podInfoBuilder);
Protos.TaskInfo.Builder taskBuilder = podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME);
// labels are sorted alphabetically (see LabelUtils):
Protos.Label label = taskBuilder.getLabels().getLabels(0);
Assert.assertEquals("goal_state", label.getKey());
Assert.assertEquals(GoalState.RUNNING.name(), label.getValue());
label = taskBuilder.getLabels().getLabels(1);
Assert.assertEquals("index", label.getKey());
Assert.assertEquals(Integer.toString(TestConstants.TASK_INDEX), label.getValue());
label = taskBuilder.getLabels().getLabels(2);
Assert.assertEquals("offer_attributes", label.getKey());
Assert.assertEquals("", label.getValue());
label = taskBuilder.getLabels().getLabels(3);
Assert.assertEquals("offer_hostname", label.getKey());
Assert.assertEquals(TestConstants.HOSTNAME, label.getValue());
label = taskBuilder.getLabels().getLabels(4);
Assert.assertEquals("target_configuration", label.getKey());
Assert.assertEquals(36, label.getValue().length());
label = taskBuilder.getLabels().getLabels(5);
Assert.assertEquals(label.getKey(), "task_type");
Assert.assertEquals(TestConstants.POD_TYPE, label.getValue());
}
Aggregations