Search in sources :

Example 16 with MesosResourcePool

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);
}
Also used : DefaultPodSpec(com.mesosphere.sdk.specification.DefaultPodSpec) PodSpec(com.mesosphere.sdk.specification.PodSpec) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) PodInstance(com.mesosphere.sdk.specification.PodInstance) PlacementRule(com.mesosphere.sdk.offer.evaluate.placement.PlacementRule) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) MesosResourcePool(com.mesosphere.sdk.offer.MesosResourcePool) Protos(org.apache.mesos.Protos) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) Test(org.junit.Test)

Example 17 with MesosResourcePool

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");
}
Also used : MesosResourcePool(com.mesosphere.sdk.offer.MesosResourcePool) Protos(org.apache.mesos.Protos) Test(org.junit.Test)

Example 18 with MesosResourcePool

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");
}
Also used : MesosResourcePool(com.mesosphere.sdk.offer.MesosResourcePool) Protos(org.apache.mesos.Protos) Test(org.junit.Test)

Aggregations

MesosResourcePool (com.mesosphere.sdk.offer.MesosResourcePool)18 Test (org.junit.Test)18 Protos (org.apache.mesos.Protos)15 PodInstanceRequirement (com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement)6 DiscoveryInfo (org.apache.mesos.Protos.DiscoveryInfo)4 EndpointUtils (com.mesosphere.sdk.http.EndpointUtils)2 PlacementRule (com.mesosphere.sdk.offer.evaluate.placement.PlacementRule)2 DefaultPodInstance (com.mesosphere.sdk.scheduler.plan.DefaultPodInstance)2 DefaultPodSpec (com.mesosphere.sdk.specification.DefaultPodSpec)2 PodInstance (com.mesosphere.sdk.specification.PodInstance)2 PodSpec (com.mesosphere.sdk.specification.PodSpec)2 IOException (java.io.IOException)1