Search in sources :

Example 1 with Attribute

use of org.apache.mesos.v1.Protos.Attribute in project Singularity by HubSpot.

the class SingularitySchedulerTestBase method createOffer.

protected Offer createOffer(double cpus, double memory, double disk, String slave, String host, Optional<String> rack, Map<String, String> attributes, String[] portRanges, Optional<String> role) {
    AgentID slaveId = AgentID.newBuilder().setValue(slave).build();
    FrameworkID frameworkId = FrameworkID.newBuilder().setValue("framework1").build();
    Random r = new Random();
    List<Attribute> attributesList = new ArrayList<>();
    for (Map.Entry<String, String> entry : attributes.entrySet()) {
        attributesList.add(Attribute.newBuilder().setType(Type.TEXT).setName(entry.getKey()).setText(Text.newBuilder().setValue(entry.getValue()).build()).build());
    }
    Resource.Builder cpusResource = Resource.newBuilder().setType(Type.SCALAR).setName(MesosUtils.CPUS).setScalar(Scalar.newBuilder().setValue(cpus));
    Resource.Builder memoryResources = Resource.newBuilder().setType(Type.SCALAR).setName(MesosUtils.MEMORY).setScalar(Scalar.newBuilder().setValue(memory));
    Resource.Builder diskResources = Resource.newBuilder().setType(Type.SCALAR).setName(MesosUtils.DISK).setScalar(Scalar.newBuilder().setValue(disk));
    if (role.isPresent()) {
        cpusResource = cpusResource.setRole(role.get());
        memoryResources = memoryResources.setRole(role.get());
        diskResources = diskResources.setRole(role.get());
    }
    return Offer.newBuilder().setId(OfferID.newBuilder().setValue("offer" + r.nextInt(1000)).build()).setFrameworkId(frameworkId).setAgentId(slaveId).setHostname(host).setUrl(URL.newBuilder().setScheme("scheme").setAddress(Address.newBuilder().setPort(8080))).addAttributes(Attribute.newBuilder().setType(Type.TEXT).setText(Text.newBuilder().setValue(rack.or(configuration.getMesosConfiguration().getDefaultRackId()))).setName(configuration.getMesosConfiguration().getRackIdAttributeKey())).addResources(cpusResource).addResources(memoryResources).addResources(diskResources).addResources(MesosUtilsTest.buildPortRanges(portRanges)).addAllAttributes(attributesList).build();
}
Also used : Random(java.util.Random) Attribute(org.apache.mesos.v1.Protos.Attribute) ArrayList(java.util.ArrayList) TaskResource(com.hubspot.singularity.resources.TaskResource) RequestResource(com.hubspot.singularity.resources.RequestResource) PriorityResource(com.hubspot.singularity.resources.PriorityResource) DeployResource(com.hubspot.singularity.resources.DeployResource) SlaveResource(com.hubspot.singularity.resources.SlaveResource) RackResource(com.hubspot.singularity.resources.RackResource) Resource(org.apache.mesos.v1.Protos.Resource) FrameworkID(org.apache.mesos.v1.Protos.FrameworkID) AgentID(org.apache.mesos.v1.Protos.AgentID) Map(java.util.Map)

Aggregations

DeployResource (com.hubspot.singularity.resources.DeployResource)1 PriorityResource (com.hubspot.singularity.resources.PriorityResource)1 RackResource (com.hubspot.singularity.resources.RackResource)1 RequestResource (com.hubspot.singularity.resources.RequestResource)1 SlaveResource (com.hubspot.singularity.resources.SlaveResource)1 TaskResource (com.hubspot.singularity.resources.TaskResource)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Random (java.util.Random)1 AgentID (org.apache.mesos.v1.Protos.AgentID)1 Attribute (org.apache.mesos.v1.Protos.Attribute)1 FrameworkID (org.apache.mesos.v1.Protos.FrameworkID)1 Resource (org.apache.mesos.v1.Protos.Resource)1