Search in sources :

Example 1 with MesosResourcePool

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

the class NamedVIPEvaluationStageTest method testDiscoveryInfoPopulated.

@Test
public void testDiscoveryInfoPopulated() throws Exception {
    Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000);
    Protos.Offer offer = OfferTestUtils.getOffer(offeredPorts);
    PodInfoBuilder podInfoBuilder = getPodInfoBuilderOnNetwork(10000, Collections.emptyList(), Optional.empty());
    // Evaluate stage
    NamedVIPEvaluationStage vipEvaluationStage = getEvaluationStageOnNetwork(10000, Optional.empty(), Optional.empty());
    EvaluationOutcome outcome = vipEvaluationStage.evaluate(new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE)), podInfoBuilder);
    Assert.assertTrue(outcome.isPassing());
    Protos.DiscoveryInfo discoveryInfo = podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME).getDiscovery();
    String expectedName = TestConstants.POD_TYPE + "-0-" + TestConstants.TASK_NAME;
    String observedName = discoveryInfo.getName();
    Assert.assertEquals(expectedName, observedName);
    Assert.assertEquals(DiscoveryInfo.Visibility.CLUSTER, discoveryInfo.getVisibility());
    Protos.Port port = discoveryInfo.getPorts().getPorts(0);
    Assert.assertEquals(port.getNumber(), 10000);
    Assert.assertEquals(port.getProtocol(), "sctp");
    Assert.assertEquals(1, port.getLabels().getLabelsCount());
    Protos.Label vipLabel = port.getLabels().getLabels(0);
    Assert.assertEquals("pod-type-0-test-task-name", discoveryInfo.getName());
    Assert.assertTrue(vipLabel.getKey().startsWith("VIP_"));
    Assert.assertEquals(vipLabel.getValue(), "test-vip:80");
}
Also used : MesosResourcePool(com.mesosphere.sdk.offer.MesosResourcePool) Protos(org.apache.mesos.Protos) DiscoveryInfo(org.apache.mesos.Protos.DiscoveryInfo) Test(org.junit.Test)

Example 2 with MesosResourcePool

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

the class NamedVIPEvaluationStageTest method testDiscoveryInfoWhenOnOverlay.

@Test
public void testDiscoveryInfoWhenOnOverlay() throws Exception {
    Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000);
    Protos.Offer offer = OfferTestUtils.getOffer(offeredPorts);
    // non-offered port
    Integer containerPort = 80;
    String overlayNetwork = "dcos";
    PodInfoBuilder podInfoBuilder = getPodInfoBuilderOnNetwork(containerPort, Collections.emptyList(), Optional.of(overlayNetwork));
    NamedVIPEvaluationStage vipEvaluationStage = getEvaluationStageOnNetwork(containerPort, Optional.empty(), Optional.of(overlayNetwork));
    EvaluationOutcome outcome = vipEvaluationStage.evaluate(new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE)), podInfoBuilder);
    Assert.assertTrue(outcome.isPassing());
    Protos.DiscoveryInfo discoveryInfo = podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME).getDiscovery();
    String expectedName = TestConstants.POD_TYPE + "-0-" + TestConstants.TASK_NAME;
    String observedName = discoveryInfo.getName();
    Assert.assertEquals(expectedName, observedName);
    Assert.assertEquals(DiscoveryInfo.Visibility.CLUSTER, discoveryInfo.getVisibility());
    Protos.TaskInfo.Builder taskBuilder = podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME);
    Assert.assertEquals(0, taskBuilder.getResourcesCount());
    Protos.Port port = discoveryInfo.getPorts().getPorts(0);
    Assert.assertEquals(port.getNumber(), containerPort.longValue());
    Assert.assertEquals(port.getProtocol(), "sctp");
    Assert.assertEquals(2, port.getLabels().getLabelsCount());
    Collection<EndpointUtils.VipInfo> vips = AuxLabelAccess.getVIPsFromLabels(TestConstants.TASK_NAME, port);
    Assert.assertEquals(1, vips.size());
    EndpointUtils.VipInfo vip = vips.iterator().next();
    Assert.assertEquals("test-vip", vip.getVipName());
    Assert.assertEquals(80, vip.getVipPort());
    assertIsOverlayLabel(port.getLabels().getLabels(1));
}
Also used : MesosResourcePool(com.mesosphere.sdk.offer.MesosResourcePool) EndpointUtils(com.mesosphere.sdk.http.EndpointUtils) Protos(org.apache.mesos.Protos) DiscoveryInfo(org.apache.mesos.Protos.DiscoveryInfo) Test(org.junit.Test)

Example 3 with MesosResourcePool

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

the class NamedVIPEvaluationStageTest method testDiscoveryInfoOnBridgeNetwork.

@Test
public void testDiscoveryInfoOnBridgeNetwork() throws Exception {
    Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000);
    Protos.Offer offer = OfferTestUtils.getOffer(offeredPorts);
    // non-offered port
    Integer containerPort = 10000;
    String bridgeNetwork = "mesos-bridge";
    PodInfoBuilder podInfoBuilder = getPodInfoBuilderOnNetwork(containerPort, Collections.emptyList(), Optional.of(bridgeNetwork));
    NamedVIPEvaluationStage vipEvaluationStage = getEvaluationStageOnNetwork(containerPort, Optional.empty(), Optional.of(bridgeNetwork));
    EvaluationOutcome outcome = vipEvaluationStage.evaluate(new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE)), podInfoBuilder);
    Assert.assertTrue(outcome.isPassing());
    Protos.DiscoveryInfo discoveryInfo = podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME).getDiscovery();
    String expectedName = TestConstants.POD_TYPE + "-0-" + TestConstants.TASK_NAME;
    String observedName = discoveryInfo.getName();
    Assert.assertEquals(expectedName, observedName);
    Assert.assertEquals(DiscoveryInfo.Visibility.CLUSTER, discoveryInfo.getVisibility());
    Protos.TaskInfo.Builder taskBuilder = podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME);
    // expect that bridge uses ports
    Assert.assertEquals(1, taskBuilder.getResourcesCount());
    Protos.Port port = discoveryInfo.getPorts().getPorts(0);
    Assert.assertEquals(port.getNumber(), containerPort.longValue());
    Assert.assertEquals(port.getProtocol(), "sctp");
    Assert.assertEquals(2, port.getLabels().getLabelsCount());
    Protos.Label vipLabel = port.getLabels().getLabels(0);
    Assert.assertTrue(vipLabel.getKey().startsWith("VIP_"));
    Assert.assertEquals(vipLabel.getValue(), "test-vip:80");
    assertIsBridgeLabel(port.getLabels().getLabels(1));
}
Also used : MesosResourcePool(com.mesosphere.sdk.offer.MesosResourcePool) Protos(org.apache.mesos.Protos) DiscoveryInfo(org.apache.mesos.Protos.DiscoveryInfo) Test(org.junit.Test)

Example 4 with MesosResourcePool

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

the class NamedVIPEvaluationStageTest method testDiscoveryInfoWhenOnOverlayWithDynamicPort.

@Test
public void testDiscoveryInfoWhenOnOverlayWithDynamicPort() throws Exception {
    Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000);
    Protos.Offer offer = OfferTestUtils.getOffer(offeredPorts);
    // non-offered port
    Integer containerPort = 0;
    String overlayNetwork = "dcos";
    PodInfoBuilder podInfoBuilder = getPodInfoBuilderOnNetwork(containerPort, Collections.emptyList(), Optional.of(overlayNetwork));
    NamedVIPEvaluationStage vipEvaluationStage = getEvaluationStageOnNetwork(containerPort, Optional.empty(), Optional.of(overlayNetwork));
    EvaluationOutcome outcome = vipEvaluationStage.evaluate(new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE)), podInfoBuilder);
    Assert.assertTrue(outcome.isPassing());
    Protos.DiscoveryInfo discoveryInfo = podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME).getDiscovery();
    String expectedName = TestConstants.POD_TYPE + "-0-" + TestConstants.TASK_NAME;
    String observedName = discoveryInfo.getName();
    Assert.assertEquals(expectedName, observedName);
    Assert.assertEquals(DiscoveryInfo.Visibility.CLUSTER, discoveryInfo.getVisibility());
    Protos.TaskInfo.Builder taskBuilder = podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME);
    Assert.assertEquals(0, taskBuilder.getResourcesCount());
    Protos.Port port = discoveryInfo.getPorts().getPorts(0);
    Assert.assertEquals(port.getNumber(), DcosConstants.OVERLAY_DYNAMIC_PORT_RANGE_START.longValue());
    Assert.assertEquals(port.getProtocol(), "sctp");
    Assert.assertEquals(2, port.getLabels().getLabelsCount());
    Collection<EndpointUtils.VipInfo> vips = AuxLabelAccess.getVIPsFromLabels(TestConstants.TASK_NAME, port);
    Assert.assertEquals(1, vips.size());
    EndpointUtils.VipInfo vip = vips.iterator().next();
    Assert.assertEquals("test-vip", vip.getVipName());
    Assert.assertEquals(80, vip.getVipPort());
    assertIsOverlayLabel(port.getLabels().getLabels(1));
}
Also used : MesosResourcePool(com.mesosphere.sdk.offer.MesosResourcePool) EndpointUtils(com.mesosphere.sdk.http.EndpointUtils) Protos(org.apache.mesos.Protos) DiscoveryInfo(org.apache.mesos.Protos.DiscoveryInfo) Test(org.junit.Test)

Example 5 with MesosResourcePool

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

the class ExecutorEvaluationStageTest method testRejectOfferWithoutExpectedExecutorId.

@Test
public void testRejectOfferWithoutExpectedExecutorId() throws Exception {
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getCpuRequirement(1.0);
    // Record launch and RUNNING status
    String resourceId = getFirstResourceId(recordLaunchWithCompleteOfferedResources(podInstanceRequirement, ResourceTestUtils.getUnreservedCpus(1.1), ResourceTestUtils.getUnreservedMem(256), ResourceTestUtils.getUnreservedDisk(512)));
    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.getCompleteOffer(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(), true, Collections.emptyMap()));
    Assert.assertFalse(outcome.isPassing());
}
Also used : MesosResourcePool(com.mesosphere.sdk.offer.MesosResourcePool) Protos(org.apache.mesos.Protos) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) 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