Search in sources :

Example 1 with DefaultPodInstance

use of com.mesosphere.sdk.scheduler.plan.DefaultPodInstance in project dcos-commons by mesosphere.

the class OfferEvaluatorPlacementTest method testColocateAgents.

@Test
public void testColocateAgents() throws Exception {
    Protos.Resource offeredCpu = ResourceTestUtils.getUnreservedCpus(2.0);
    // Don't launch
    PlacementRule placementRule = PlacementUtils.getAgentPlacementRule(Collections.emptyList(), Arrays.asList("some-random-agent")).get();
    PodSpec podSpec = PodInstanceRequirementTestUtils.getCpuRequirement(1.0).getPodInstance().getPod();
    podSpec = DefaultPodSpec.newBuilder(podSpec).placementRule(placementRule).build();
    PodInstance podInstance = new DefaultPodInstance(podSpec, 0);
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, Arrays.asList(TestConstants.TASK_NAME)).build();
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getCompleteOffer(offeredCpu)));
    Assert.assertEquals(0, recommendations.size());
    // Launch
    placementRule = PlacementUtils.getAgentPlacementRule(Collections.emptyList(), Arrays.asList(TestConstants.AGENT_ID.getValue())).get();
    podSpec = DefaultPodSpec.newBuilder(podSpec).placementRule(placementRule).build();
    podInstance = new DefaultPodInstance(podSpec, 0);
    podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, Arrays.asList(TestConstants.TASK_NAME)).build();
    recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getCompleteOffer(offeredCpu)));
    Assert.assertEquals(5, recommendations.size());
}
Also used : Protos(org.apache.mesos.Protos) 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) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 2 with DefaultPodInstance

use of com.mesosphere.sdk.scheduler.plan.DefaultPodInstance in project dcos-commons by mesosphere.

the class OfferEvaluatorPlacementTest method testAvoidAgents.

@Test
public void testAvoidAgents() throws Exception {
    Protos.Resource offeredCpu = ResourceTestUtils.getUnreservedCpus(2.0);
    // Don't launch
    PlacementRule placementRule = PlacementUtils.getAgentPlacementRule(Arrays.asList(TestConstants.AGENT_ID.getValue()), Collections.emptyList()).get();
    PodSpec podSpec = PodInstanceRequirementTestUtils.getCpuRequirement(1.0).getPodInstance().getPod();
    podSpec = DefaultPodSpec.newBuilder(podSpec).placementRule(placementRule).build();
    PodInstance podInstance = new DefaultPodInstance(podSpec, 0);
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, Arrays.asList(TestConstants.TASK_NAME)).build();
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getCompleteOffer(offeredCpu)));
    Assert.assertEquals(0, recommendations.size());
    // Launch
    placementRule = PlacementUtils.getAgentPlacementRule(Arrays.asList("some-random-agent"), Collections.emptyList()).get();
    podSpec = DefaultPodSpec.newBuilder(podSpec).placementRule(placementRule).build();
    podInstance = new DefaultPodInstance(podSpec, 0);
    podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, Arrays.asList(TestConstants.TASK_NAME)).build();
    recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getCompleteOffer(offeredCpu)));
    Assert.assertEquals(5, recommendations.size());
}
Also used : Protos(org.apache.mesos.Protos) 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) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 3 with DefaultPodInstance

use of com.mesosphere.sdk.scheduler.plan.DefaultPodInstance in project dcos-commons by mesosphere.

the class NamedVIPEvaluationStageTest method getPodInstanceRequirement.

private static PodInstanceRequirement getPodInstanceRequirement(int taskPort, Collection<String> networkNames) {
    // Build Pod
    ResourceSet resourceSet = DefaultResourceSet.newBuilder(TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL).id("resourceSet").cpus(1.0).addResource(getNamedVIPSpec(taskPort, networkNames)).build();
    CommandSpec commandSpec = DefaultCommandSpec.newBuilder(Collections.emptyMap()).value("./cmd").build();
    TaskSpec taskSpec = DefaultTaskSpec.newBuilder().name(TestConstants.TASK_NAME).commandSpec(commandSpec).goalState(GoalState.RUNNING).resourceSet(resourceSet).build();
    PodSpec podSpec = DefaultPodSpec.newBuilder("executor-uri").addTask(taskSpec).count(1).type(TestConstants.POD_TYPE).build();
    PodInstance podInstance = new DefaultPodInstance(podSpec, 0);
    return PodInstanceRequirement.newBuilder(podInstance, Arrays.asList(TestConstants.TASK_NAME)).build();
}
Also used : DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance)

Example 4 with DefaultPodInstance

use of com.mesosphere.sdk.scheduler.plan.DefaultPodInstance in project dcos-commons by mesosphere.

the class TaskTypeRuleTest method getPodInstance.

private static PodInstance getPodInstance(TaskInfo taskInfo) {
    try {
        TaskLabelReader labels = new TaskLabelReader(taskInfo);
        ResourceSet resourceSet = PodInstanceRequirementTestUtils.getCpuResourceSet(1.0);
        PodSpec podSpec = PodInstanceRequirementTestUtils.getRequirement(resourceSet, labels.getType(), labels.getIndex()).getPodInstance().getPod();
        return new DefaultPodInstance(podSpec, labels.getIndex());
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}
Also used : TaskLabelReader(com.mesosphere.sdk.offer.taskdata.TaskLabelReader) PodSpec(com.mesosphere.sdk.specification.PodSpec) ResourceSet(com.mesosphere.sdk.specification.ResourceSet) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) InvalidRequirementException(com.mesosphere.sdk.offer.InvalidRequirementException) IOException(java.io.IOException)

Example 5 with DefaultPodInstance

use of com.mesosphere.sdk.scheduler.plan.DefaultPodInstance in project dcos-commons by mesosphere.

the class TLSEvaluationStageTest method getRequirementWithTransportEncryption.

private static PodInstanceRequirement getRequirementWithTransportEncryption(ResourceSet resourceSet, String type, int index, Collection<TransportEncryptionSpec> transportEncryptionSpecs) {
    TaskSpec taskSpec = DefaultTaskSpec.newBuilder().name(TestConstants.TASK_NAME).commandSpec(DefaultCommandSpec.newBuilder(Collections.emptyMap()).value(TestConstants.TASK_CMD).build()).goalState(GoalState.RUNNING).resourceSet(resourceSet).setTransportEncryption(transportEncryptionSpecs).build();
    PodSpec podSpec = DefaultPodSpec.newBuilder("executor-uri").type(type).count(1).tasks(Arrays.asList(taskSpec)).preReservedRole(Constants.ANY_ROLE).build();
    PodInstance podInstance = new DefaultPodInstance(podSpec, index);
    List<String> taskNames = podInstance.getPod().getTasks().stream().map(ts -> ts.getName()).collect(Collectors.toList());
    return PodInstanceRequirement.newBuilder(podInstance, taskNames).build();
}
Also used : Protos(org.apache.mesos.Protos) SchedulerConfig(com.mesosphere.sdk.scheduler.SchedulerConfig) java.util(java.util) TestConstants(com.mesosphere.sdk.testutils.TestConstants) MesosResourcePool(com.mesosphere.sdk.offer.MesosResourcePool) TLSArtifactsUpdater(com.mesosphere.sdk.offer.evaluate.security.TLSArtifactsUpdater) Matchers(org.mockito.Matchers) Mock(org.mockito.Mock) PodInstanceRequirementTestUtils(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirementTestUtils) ArtifactResource(com.mesosphere.sdk.http.endpoints.ArtifactResource) OfferTestUtils(com.mesosphere.sdk.testutils.OfferTestUtils) MockitoAnnotations(org.mockito.MockitoAnnotations) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) Constants(com.mesosphere.sdk.offer.Constants) TLSArtifact(com.mesosphere.sdk.offer.evaluate.security.TLSArtifact) Before(org.junit.Before) TLSArtifactPaths(com.mesosphere.sdk.offer.evaluate.security.TLSArtifactPaths) SchedulerConfigTestUtils(com.mesosphere.sdk.testutils.SchedulerConfigTestUtils) InvalidRequirementException(com.mesosphere.sdk.offer.InvalidRequirementException) Test(org.junit.Test) IOException(java.io.IOException) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) Collectors(java.util.stream.Collectors) Mockito(org.mockito.Mockito) com.mesosphere.sdk.specification(com.mesosphere.sdk.specification) Assert(org.junit.Assert) ResourceTestUtils(com.mesosphere.sdk.testutils.ResourceTestUtils) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance)

Aggregations

DefaultPodInstance (com.mesosphere.sdk.scheduler.plan.DefaultPodInstance)20 PodInstanceRequirement (com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement)12 Protos (org.apache.mesos.Protos)12 Test (org.junit.Test)12 PodSpec (com.mesosphere.sdk.specification.PodSpec)9 DefaultPodSpec (com.mesosphere.sdk.specification.DefaultPodSpec)7 PlacementRule (com.mesosphere.sdk.offer.evaluate.placement.PlacementRule)6 PodInstance (com.mesosphere.sdk.specification.PodInstance)6 InvalidRequirementException (com.mesosphere.sdk.offer.InvalidRequirementException)4 OfferRecommendation (com.mesosphere.sdk.offer.OfferRecommendation)4 ArtifactResource (com.mesosphere.sdk.http.endpoints.ArtifactResource)3 MesosResourcePool (com.mesosphere.sdk.offer.MesosResourcePool)3 TaskLabelReader (com.mesosphere.sdk.offer.taskdata.TaskLabelReader)3 SchedulerConfig (com.mesosphere.sdk.scheduler.SchedulerConfig)3 com.mesosphere.sdk.specification (com.mesosphere.sdk.specification)3 ResourceSet (com.mesosphere.sdk.specification.ResourceSet)3 File (java.io.File)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 Assert (org.junit.Assert)3