Search in sources :

Example 1 with Type

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

the class ValueUtils method subtract.

public static Value subtract(Value val1, Value val2) {
    Type type1 = val1.getType();
    Type type2 = val2.getType();
    if (type1 != type2) {
        return null;
    }
    switch(type1) {
        case SCALAR:
            Value.Scalar scalar = subtract(val1.getScalar(), val2.getScalar());
            return Value.newBuilder().setType(type1).setScalar(scalar).build();
        case RANGES:
            Value.Ranges ranges = subtract(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)

Example 2 with Type

use of org.apache.mesos.Protos.Value.Type 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 3 with Type

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

the class ValueUtils method compare.

public static Integer compare(Value val1, Value val2) {
    Type type1 = val1.getType();
    Type type2 = val2.getType();
    if (type1 != type2) {
        return null;
    }
    switch(type1) {
        case SCALAR:
            return compare(val1.getScalar(), val2.getScalar());
        case RANGES:
            return compare(val1.getRanges(), val2.getRanges());
        default:
            return null;
    }
}
Also used : Type(org.apache.mesos.Protos.Value.Type)

Example 4 with Type

use of org.apache.mesos.Protos.Value.Type 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

Type (org.apache.mesos.Protos.Value.Type)4 Value (org.apache.mesos.Protos.Value)3