use of com.mesosphere.sdk.offer.MesosResourcePool in project dcos-commons by mesosphere.
the class PlacementRuleEvaluationStageTest method testOfferFailsPlacementRule.
@Test
public void testOfferFailsPlacementRule() throws Exception {
String agent = "test-agent";
Protos.Resource offered = ResourceTestUtils.getUnreservedCpus(1.0);
PlacementRule rule = AgentRule.require(agent);
Protos.Offer offer = offerWithAgent("other-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.assertFalse(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 TLSEvaluationStageTest method testArtifactsExist.
@Test
public void testArtifactsExist() 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 testSuccessKeystore.
@Test
public void testSuccessKeystore() throws Exception {
ArrayList<TransportEncryptionSpec> transportEncryptionSpecs = new ArrayList<>();
transportEncryptionSpecs.add(new DefaultTransportEncryptionSpec.Builder().name("test-tls").type(TransportEncryptionSpec.Type.KEYSTORE).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();
assertKeystoreArtifacts(taskContainer, tlsArtifactPaths, "test-tls");
}
Aggregations