Search in sources :

Example 1 with ResourceSet

use of com.mesosphere.sdk.specification.ResourceSet 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 2 with ResourceSet

use of com.mesosphere.sdk.specification.ResourceSet in project dcos-commons by mesosphere.

the class OfferEvaluatorVolumesTest method testConsumeMultipleMountVolumesFailure.

@Test
public void testConsumeMultipleMountVolumesFailure() throws Exception {
    Resource offeredResource = ResourceTestUtils.getUnreservedMountVolume(2000);
    ResourceSet volumeResourceSet = DefaultResourceSet.newBuilder(TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL).id(TestConstants.RESOURCE_SET_ID).cpus(1.0).addVolume(VolumeSpec.Type.MOUNT.name(), 1000.0, TestConstants.CONTAINER_PATH + "-A").addVolume(VolumeSpec.Type.MOUNT.name(), 1000.0, TestConstants.CONTAINER_PATH + "-B").build();
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getRequirement(volumeResourceSet, 0);
    Protos.Offer offer = OfferTestUtils.getCompleteOffer(Arrays.asList(offeredResource));
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(offer));
    Assert.assertEquals(0, recommendations.size());
}
Also used : Protos(org.apache.mesos.Protos) Resource(org.apache.mesos.Protos.Resource) ResourceSet(com.mesosphere.sdk.specification.ResourceSet) DefaultResourceSet(com.mesosphere.sdk.specification.DefaultResourceSet) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 3 with ResourceSet

use of com.mesosphere.sdk.specification.ResourceSet in project dcos-commons by mesosphere.

the class OfferEvaluatorVolumesTest method testCreateMultipleRootVolumes.

@Test
public void testCreateMultipleRootVolumes() throws Exception {
    ResourceSet resourceSet = DefaultResourceSet.newBuilder(TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL).id(TestConstants.RESOURCE_SET_ID).cpus(1.0).addVolume(VolumeSpec.Type.ROOT.name(), 1.0, TestConstants.CONTAINER_PATH + "-a").addVolume(VolumeSpec.Type.ROOT.name(), 2.0, TestConstants.CONTAINER_PATH + "-b").build();
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getRequirement(resourceSet, 0);
    Resource offeredDisk = ResourceTestUtils.getUnreservedDisk(3);
    Resource offeredCpu = ResourceTestUtils.getUnreservedCpus(1.0);
    Protos.Offer offer = OfferTestUtils.getCompleteOffer(Arrays.asList(offeredCpu, offeredDisk));
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(offer));
    Assert.assertEquals(9, recommendations.size());
    Assert.assertEquals(Operation.Type.RESERVE, recommendations.get(0).getOperation().getType());
    Assert.assertEquals(Operation.Type.RESERVE, recommendations.get(1).getOperation().getType());
    Assert.assertEquals(Operation.Type.CREATE, recommendations.get(2).getOperation().getType());
    Assert.assertEquals(Operation.Type.RESERVE, recommendations.get(3).getOperation().getType());
    Assert.assertEquals(Operation.Type.CREATE, recommendations.get(4).getOperation().getType());
    Assert.assertEquals(Operation.Type.LAUNCH_GROUP, recommendations.get(8).getOperation().getType());
    // Validate Create Operation
    Operation createOperation = recommendations.get(2).getOperation();
    Assert.assertEquals(TestConstants.CONTAINER_PATH + "-a", createOperation.getCreate().getVolumes(0).getDisk().getVolume().getContainerPath());
    // Validate Create Operation
    createOperation = recommendations.get(4).getOperation();
    Assert.assertEquals(TestConstants.CONTAINER_PATH + "-b", createOperation.getCreate().getVolumes(0).getDisk().getVolume().getContainerPath());
    // Validate Launch Operation
    Operation launchOperation = recommendations.get(8).getOperation();
    for (Protos.TaskInfo taskInfo : launchOperation.getLaunch().getTaskInfosList()) {
        for (Resource resource : taskInfo.getResourcesList()) {
            Assert.assertFalse(getResourceId(resource).isEmpty());
        }
    }
}
Also used : Protos(org.apache.mesos.Protos) Resource(org.apache.mesos.Protos.Resource) ResourceSet(com.mesosphere.sdk.specification.ResourceSet) DefaultResourceSet(com.mesosphere.sdk.specification.DefaultResourceSet) Operation(org.apache.mesos.Protos.Offer.Operation) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 4 with ResourceSet

use of com.mesosphere.sdk.specification.ResourceSet in project dcos-commons by mesosphere.

the class RoundRobinByHostnameRuleTest 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) TaskException(com.mesosphere.sdk.offer.TaskException)

Example 5 with ResourceSet

use of com.mesosphere.sdk.specification.ResourceSet in project dcos-commons by mesosphere.

the class RoundRobinByAttributeRuleTest 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) DefaultPodSpec(com.mesosphere.sdk.specification.DefaultPodSpec) ResourceSet(com.mesosphere.sdk.specification.ResourceSet) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) InvalidRequirementException(com.mesosphere.sdk.offer.InvalidRequirementException) TaskException(com.mesosphere.sdk.offer.TaskException)

Aggregations

ResourceSet (com.mesosphere.sdk.specification.ResourceSet)5 InvalidRequirementException (com.mesosphere.sdk.offer.InvalidRequirementException)3 TaskLabelReader (com.mesosphere.sdk.offer.taskdata.TaskLabelReader)3 DefaultPodInstance (com.mesosphere.sdk.scheduler.plan.DefaultPodInstance)3 PodSpec (com.mesosphere.sdk.specification.PodSpec)3 OfferRecommendation (com.mesosphere.sdk.offer.OfferRecommendation)2 TaskException (com.mesosphere.sdk.offer.TaskException)2 PodInstanceRequirement (com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement)2 DefaultResourceSet (com.mesosphere.sdk.specification.DefaultResourceSet)2 Protos (org.apache.mesos.Protos)2 Resource (org.apache.mesos.Protos.Resource)2 Test (org.junit.Test)2 DefaultPodSpec (com.mesosphere.sdk.specification.DefaultPodSpec)1 IOException (java.io.IOException)1 Operation (org.apache.mesos.Protos.Offer.Operation)1