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