Search in sources :

Example 6 with Value

use of org.apache.mesos.Protos.Value in project dcos-commons by mesosphere.

the class ValueUtils method getValue.

public static Value getValue(Resource resource) {
    Type type = resource.getType();
    Value.Builder builder = Value.newBuilder();
    builder.setType(type);
    switch(type) {
        case SCALAR:
            return builder.setScalar(resource.getScalar()).build();
        case RANGES:
            return builder.setRanges(resource.getRanges()).build();
        case SET:
            return builder.setSet(resource.getSet()).build();
        default:
            return null;
    }
}
Also used : Type(org.apache.mesos.Protos.Value.Type) Value(org.apache.mesos.Protos.Value)

Example 7 with Value

use of org.apache.mesos.Protos.Value in project dcos-commons by mesosphere.

the class ValueUtils method add.

public static Value add(Value val1, Value val2) {
    Type type1 = val1.getType();
    Type type2 = val2.getType();
    if (type1 != type2) {
        return null;
    }
    switch(type1) {
        case SCALAR:
            Value.Scalar scalar = add(val1.getScalar(), val2.getScalar());
            return Value.newBuilder().setType(type1).setScalar(scalar).build();
        case RANGES:
            Value.Ranges ranges = add(val1.getRanges(), val2.getRanges());
            return Value.newBuilder().setType(type1).setRanges(ranges).build();
        default:
            return null;
    }
}
Also used : Type(org.apache.mesos.Protos.Value.Type) Value(org.apache.mesos.Protos.Value)

Aggregations

Value (org.apache.mesos.Protos.Value)7 Type (org.apache.mesos.Protos.Value.Type)3 Resource (org.apache.mesos.Protos.Resource)2