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());
}
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());
}
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();
}
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);
}
}
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();
}
Aggregations