org.apache.mesos.Protos.Attribute Java Examples

The following examples show how to use org.apache.mesos.Protos.Attribute. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimulatedTitusAgent.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
private Offer createOfferForAvailableResources() {
    Protos.OfferID offerId = Protos.OfferID.newBuilder().setValue(slaveId.getValue() + "_O_" + offerIdx++).build();
    String enis = "ResourceSet-ENIs-7-" + networkResourceTracker.getIpsPerEni();
    return offerTemplate.clone()
            .setId(offerId)
            .setSlaveId(slaveId)
            .addAllResources(asList(
                    Resource.newBuilder().setName("cpus").setType(Type.SCALAR).setScalar(Scalar.newBuilder().setValue(availableCPUs)).build(),
                    Resource.newBuilder().setName("gpu").setType(Type.SCALAR).setScalar(Scalar.newBuilder().setValue(availableGPUs)).build(),
                    Resource.newBuilder().setName("mem").setType(Type.SCALAR).setScalar(Scalar.newBuilder().setValue(availableMemory)).build(),
                    Resource.newBuilder().setName("disk").setType(Type.SCALAR).setScalar(Scalar.newBuilder().setValue(availableDisk)).build(),
                    Resource.newBuilder().setName("ports").setType(Type.RANGES).setRanges(
                            Ranges.newBuilder().addRange(Protos.Value.Range.newBuilder().setBegin(1024).setEnd(65535).build()).build()
                    ).build(),
                    Resource.newBuilder().setName("network").setType(Type.SCALAR).setScalar(Scalar.newBuilder().setValue(availableNetworkMbs)).build()
            ))
            .addAllAttributes(asList(
                    Attribute.newBuilder().setName("cluster").setType(Type.TEXT).setText(Text.newBuilder().setValue(clusterName)).build(),
                    Attribute.newBuilder().setName("asg").setType(Type.TEXT).setText(Text.newBuilder().setValue(clusterName)).build(),
                    Attribute.newBuilder().setName("id").setType(Type.TEXT).setText(Text.newBuilder().setValue(hostName)).build(),
                    Attribute.newBuilder().setName("itype").setType(Type.TEXT).setText(Text.newBuilder().setValue(instanceType.getDescriptor().getId())).build(),
                    Attribute.newBuilder().setName("SLAVE_ID").setType(Type.TEXT).setText(Text.newBuilder().setValue(clusterName)).build(),
                    Attribute.newBuilder().setName("res").setType(Type.TEXT).setText(Text.newBuilder().setValue(enis)).build()
            ))
            .build();
}
 
Example #2
Source File: SimulatedTitusAgentCluster.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
private SimulatedTitusAgent createAgent() {
    String hostName = ComputeResources.asHostname(computeResources.allocateIpAddress(), name);
    String zoneId = ZONES[(int) (zoneCounter.getAndIncrement() % ZONES.length)];
    Protos.SlaveID slaveId = Protos.SlaveID.newBuilder().setValue(hostName).build();

    Protos.Offer.Builder agentOfferTemplate = offerTemplate.clone()
            .setHostname(hostName)
            .addAttributes(Attribute.newBuilder().setName("zone").setType(Type.TEXT).setText(Text.newBuilder().setValue(zoneId).build()).build())
            .setUrl(Protos.URL.newBuilder()
                    .setScheme("http")
                    .setAddress(Protos.Address.newBuilder().setHostname(hostName).setPort(5051))
                    .setPath("slave")
            );

    SimulatedTitusAgent agent = new SimulatedTitusAgent(name, computeResources, hostName, slaveId, agentOfferTemplate, instanceType,
            cpus, gpus, memory, disk, networkMbs, ipPerEni, containerPlayersManager, Schedulers.computation());
    agents.put(agent.getId(), agent);
    topologUpdateSubject.onNext(AgentChangeEvent.newInstance(this, agent));
    return agent;
}
 
Example #3
Source File: AttributeStringUtilsTest.java    From dcos-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetAttributeString() {
    Attribute.Builder attr = Attribute.newBuilder().setType(Type.SET).setName("ram");
    attr.getSetBuilder().addItem("");
    assertEquals("ram:{}", AttributeStringUtils.toString(attr.build()));

    attr = Attribute.newBuilder().setType(Type.SET).setName("ports");
    attr.getSetBuilder().addItem("a").addItem("b").addItem("c");
    assertEquals("ports:{a,b,c}", AttributeStringUtils.toString(attr.build()));

    attr = Attribute.newBuilder().setType(Type.SET).setName("disk");
    attr.getSetBuilder().addItem("-1").addItem("-2");
    assertEquals("disk:{-1,-2}", AttributeStringUtils.toString(attr.build()));

    attr = Attribute.newBuilder().setType(Type.SET).setName("");
    attr.getSetBuilder().addItem("-1").addItem("-2");
    assertEquals(":{-1,-2}", AttributeStringUtils.toString(attr.build()));

    attr = Attribute.newBuilder().setType(Type.SET).setName("empty");
    assertEquals("empty:{}", AttributeStringUtils.toString(attr.build()));

    attr = Attribute.newBuilder().setType(Type.SET).setName("");
    assertEquals(":{}", AttributeStringUtils.toString(attr.build()));
}
 
Example #4
Source File: AttributeStringUtilsTest.java    From dcos-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testTextAttributeString() {
    Attribute.Builder attr = Attribute.newBuilder().setType(Type.TEXT).setName("ram");
    attr.getTextBuilder().setValue(":::");
    assertEquals("ram::::", AttributeStringUtils.toString(attr.build()));

    attr = Attribute.newBuilder().setType(Type.TEXT).setName("ram");
    attr.getTextBuilder().setValue("abc");
    assertEquals("ram:abc", AttributeStringUtils.toString(attr.build()));

    attr = Attribute.newBuilder().setType(Type.TEXT).setName("");
    attr.getTextBuilder().setValue("123");
    assertEquals(":" + "123" /* workaround for lint thinking this is an IP */,
            AttributeStringUtils.toString(attr.build()));

    attr = Attribute.newBuilder().setType(Type.TEXT).setName("empty");
    assertEquals("empty:", AttributeStringUtils.toString(attr.build()));

    attr = Attribute.newBuilder().setType(Type.TEXT).setName("");
    assertEquals(":", AttributeStringUtils.toString(attr.build()));
}
 
Example #5
Source File: AttributeStringUtilsTest.java    From dcos-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testMixedAttributeStrings() {
    List<Attribute> attrs = new ArrayList<>();
    assertEquals("", AttributeStringUtils.toString(attrs));

    Attribute.Builder attr = Attribute.newBuilder().setType(Type.TEXT).setName("ram");
    attr.getTextBuilder().setValue("");
    attrs.add(attr.build());
    assertEquals("ram:", AttributeStringUtils.toString(attrs));

    attr = Attribute.newBuilder().setType(Type.SET).setName("ports");
    attr.getSetBuilder().addItem("a").addItem("b").addItem("c");
    attrs.add(attr.build());
    assertEquals("ram:;ports:{a,b,c}", AttributeStringUtils.toString(attrs));

    attr = Attribute.newBuilder().setType(Type.SCALAR).setName("roundup1");
    attr.getScalarBuilder().setValue(1.99999);
    attrs.add(attr.build());
    assertEquals("ram:;ports:{a,b,c};roundup1:2.000", AttributeStringUtils.toString(attrs));

    attr = Attribute.newBuilder().setType(Type.RANGES).setName("disk");
    attr.getRangesBuilder().addRangeBuilder().setBegin(-321).setEnd(-123);
    attrs.add(attr.build());
    assertEquals("ram:;ports:{a,b,c};roundup1:2.000;disk:[-321--123]", AttributeStringUtils.toString(attrs));
}
 
Example #6
Source File: LikeConstraint.java    From incubator-myriad with Apache License 2.0 6 votes vote down vote up
public boolean matchesSlaveAttributes(Collection<Attribute> attributes) {
  if (!lhs.equalsIgnoreCase(HOSTNAME) && attributes != null) {
    for (Attribute attr : attributes) {
      if (attr.getName().equalsIgnoreCase(lhs)) {
        switch (attr.getType()) {
          case TEXT:
            return this.pattern.matcher(attr.getText().getValue()).matches();

          case SCALAR:
            return this.pattern.matcher(String.valueOf(attr.getScalar().getValue())).matches();

          default:
            LOGGER.warn("LIKE constraint currently doesn't support Mesos slave attributes " + "of type {}. Attribute Name: {}",
                attr.getType(), attr.getName());
            return false;

        }
      }
    }
  }
  return false;
}
 
Example #7
Source File: SchedulerUtils.java    From myriad with Apache License 2.0 6 votes vote down vote up
public static boolean isMatchSlaveAttributes(Offer offer,
		Map<String, String> requestAttributes) {
	boolean match = true;

	Map<String, String> offerAttributes = new HashMap<String, String>();
	for (Attribute attribute : offer.getAttributesList()) {
		offerAttributes.put(attribute.getName(), attribute.getText()
				.getValue());
	}

	// Match with offer attributes only if request has attributes.
	if (!MapUtils.isEmpty(requestAttributes)) {
		match = offerAttributes.equals(requestAttributes);
	}

	LOGGER.info(
			"Match status: {} for offer: {} and requestAttributes: {}",
			match, offer, requestAttributes);

	return match;
}
 
Example #8
Source File: SimulatedTitusAgent.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
private Optional<String> getZoneIdFromOfferTemplate(Offer.Builder offerTemplate) {
    for (Attribute attribute : offerTemplate.getAttributesList()) {
        if (attribute.getName().equals("zone")) {
            return Optional.of(attribute.getText().getValue());
        }
    }
    return Optional.empty();
}
 
Example #9
Source File: SimulatedTitusAgentCluster.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
private SimulatedTitusAgentCluster(String name,
                                   ComputeResources computeResources,
                                   AwsInstanceType instanceType,
                                   double cpus,
                                   double gpus,
                                   int memory,
                                   int disk,
                                   int networkMbs,
                                   int ipPerEni,
                                   ContainerPlayersManager containerPlayersManager,
                                   int maxSize) {
    this.name = name;
    this.computeResources = computeResources;
    this.instanceType = instanceType;
    this.cpus = cpus;
    this.gpus = gpus;
    this.memory = memory;
    this.disk = disk;
    this.networkMbs = networkMbs;
    this.ipPerEni = ipPerEni;
    this.containerPlayersManager = containerPlayersManager;
    this.maxSize = maxSize;

    this.offerTemplate = Protos.Offer.newBuilder()
            .setFrameworkId(Protos.FrameworkID.newBuilder().setValue("EmbeddedTitusMaster"))
            .addAllAttributes(asList(
                    Attribute.newBuilder().setName("CLUSTER_NAME").setType(Type.SCALAR).setText(Text.newBuilder().setValue(name)).build(),
                    Attribute.newBuilder().setName("region").setType(Type.SCALAR).setText(Text.newBuilder().setValue("us-east-1")).build(),
                    Attribute.newBuilder().setName("stack").setType(Type.SCALAR).setText(Text.newBuilder().setValue("local")).build(),
                    Attribute.newBuilder().setName("itype").setType(Type.TEXT).setText(Text.newBuilder().setValue(instanceType.name())).build()
            ));
}
 
Example #10
Source File: RoundRobinByAttributeRule.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
@Override
protected String getKey(Offer offer) {
  for (Attribute attribute : offer.getAttributesList()) {
    if (attribute.getName().equalsIgnoreCase(attributeName)) {
      return AttributeStringUtils.toString(AttributeStringUtils.toValue(attribute));
    }
  }
  return null;
}
 
Example #11
Source File: AttributeStringUtilsTest.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testRangeAttributeString() {
    Attribute.Builder attr = Attribute.newBuilder().setType(Type.RANGES).setName("ram");
    attr.getRangesBuilder().addRangeBuilder().setBegin(1).setEnd(2);
    assertEquals("ram:[1-2]", AttributeStringUtils.toString(attr.build()));

    attr = Attribute.newBuilder().setType(Type.RANGES).setName("ports");
    attr.getRangesBuilder().addRangeBuilder().setBegin(1).setEnd(2);
    attr.getRangesBuilder().addRangeBuilder().setBegin(-321).setEnd(-123);
    attr.getRangesBuilder().addRangeBuilder().setBegin(21000).setEnd(24000);
    attr.getRangesBuilder().addRangeBuilder().setBegin(0).setEnd(0);
    attr.getRangesBuilder().addRangeBuilder().setBegin(30000).setEnd(34000);
    attr.getRangesBuilder().addRangeBuilder().setBegin(321).setEnd(123);
    assertEquals("ports:[1-2,-321--123,21000-24000,0-0,30000-34000,321-123]",
            AttributeStringUtils.toString(attr.build()));

    attr = Attribute.newBuilder().setType(Type.RANGES).setName("ram");
    attr.getRangesBuilder().addRangeBuilder().setBegin(0).setEnd(0);
    assertEquals("ram:[0-0]", AttributeStringUtils.toString(attr.build()));

    attr = Attribute.newBuilder().setType(Type.RANGES).setName("disk");
    attr.getRangesBuilder().addRangeBuilder().setBegin(-321).setEnd(-123);
    assertEquals("disk:[-321--123]", AttributeStringUtils.toString(attr.build()));

    attr = Attribute.newBuilder().setType(Type.RANGES).setName("");
    attr.getRangesBuilder().addRangeBuilder().setBegin(-321).setEnd(-123);
    assertEquals(":[-321--123]", AttributeStringUtils.toString(attr.build()));

    attr = Attribute.newBuilder().setType(Type.RANGES).setName("empty");
    assertEquals("empty:[]", AttributeStringUtils.toString(attr.build()));

    attr = Attribute.newBuilder().setType(Type.RANGES).setName("");
    assertEquals(":[]", AttributeStringUtils.toString(attr.build()));
}
 
Example #12
Source File: AttributeStringUtilsTest.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testScalarAttributeString() {
    Attribute.Builder attr = Attribute.newBuilder().setType(Type.SCALAR).setName("ram");
    attr.getScalarBuilder().setValue(0);
    assertEquals("ram:0.000", AttributeStringUtils.toString(attr.build()));

    attr = Attribute.newBuilder().setType(Type.SCALAR).setName("ports");
    attr.getScalarBuilder().setValue(0.000);
    assertEquals("ports:0.000", AttributeStringUtils.toString(attr.build()));

    attr = Attribute.newBuilder().setType(Type.SCALAR).setName("ports");
    attr.getScalarBuilder().setValue(0.0001);
    assertEquals("ports:0.000", AttributeStringUtils.toString(attr.build()));

    attr = Attribute.newBuilder().setType(Type.SCALAR).setName("ports");
    attr.getScalarBuilder().setValue(0.0005);
    assertEquals("ports:0.001", AttributeStringUtils.toString(attr.build()));

    attr = Attribute.newBuilder().setType(Type.SCALAR).setName("rounddown");
    attr.getScalarBuilder().setValue(-1.99999);
    assertEquals("rounddown:-2.000", AttributeStringUtils.toString(attr.build()));

    attr = Attribute.newBuilder().setType(Type.SCALAR).setName("roundup1");
    attr.getScalarBuilder().setValue(1.99999);
    assertEquals("roundup1:2.000", AttributeStringUtils.toString(attr.build()));

    attr = Attribute.newBuilder().setType(Type.SCALAR).setName("");
    attr.getScalarBuilder().setValue(1.99999);
    assertEquals(":2.000", AttributeStringUtils.toString(attr.build()));

    attr = Attribute.newBuilder().setType(Type.SCALAR).setName("roundup2");
    attr.getScalarBuilder().setValue(999999.99999);
    assertEquals("roundup2:1000000.000", AttributeStringUtils.toString(attr.build()));

    attr = Attribute.newBuilder().setType(Type.SCALAR).setName("empty");
    assertEquals("empty:0.000", AttributeStringUtils.toString(attr.build()));

    attr = Attribute.newBuilder().setType(Type.SCALAR).setName("");
    assertEquals(":0.000", AttributeStringUtils.toString(attr.build()));
}
 
Example #13
Source File: LikeConstraintTest.java    From incubator-myriad with Apache License 2.0 5 votes vote down vote up
private Protos.Attribute getTextAttribute(String name, String value) {
  return Protos.Attribute.newBuilder()
    .setName(name)
    .setType(TEXT)
    .setText(Text.newBuilder()
    .setValue(value))
    .build();
}
 
Example #14
Source File: NodeTask.java    From incubator-myriad with Apache License 2.0 4 votes vote down vote up
public void setSlaveAttributes(List<Attribute> slaveAttributes) {
  this.slaveAttributes = slaveAttributes;
}
 
Example #15
Source File: NodeTask.java    From incubator-myriad with Apache License 2.0 4 votes vote down vote up
public List<Attribute> getSlaveAttributes() {
  return slaveAttributes;
}
 
Example #16
Source File: LikeConstraintTest.java    From incubator-myriad with Apache License 2.0 4 votes vote down vote up
@Test
public void testMatchSlaveAttributes() throws Exception {
  List<Attribute> attributes = Lists.newArrayList(getTextAttribute("dfs", "dfs-test"));
  assertTrue(constraintThree.matchesSlaveAttributes(attributes));
}