Search in sources :

Example 1 with Type

use of org.apache.myriad.scheduler.constraints.Constraint.Type in project incubator-myriad by apache.

the class ByteBufferSupport method toByteBuffer.

public static ByteBuffer toByteBuffer(NodeTask nt) {
    // Determine the size of ByteBuffer to allocate
    // The ServiceResourceProfile toString() returns Json, if this ever changes then this
    // will fail. Json is expected.
    byte[] profile = toBytes(nt.getProfile().toString());
    int size = profile.length + INT_SIZE;
    Constraint constraint = nt.getConstraint();
    Constraint.Type type = constraint == null ? Type.NULL : constraint.getType();
    size += INT_SIZE;
    byte[] constraintBytes = ZERO_BYTES;
    if (constraint != null) {
        constraintBytes = toBytes(constraint.toString());
        size += constraintBytes.length + INT_SIZE;
    } else {
        size += INT_SIZE;
    }
    byte[] hostname = toBytes(nt.getHostname());
    size += hostname.length + INT_SIZE;
    if (nt.getSlaveId() != null) {
        size += nt.getSlaveId().getSerializedSize() + INT_SIZE;
    } else {
        size += INT_SIZE;
    }
    if (nt.getTaskStatus() != null) {
        size += nt.getTaskStatus().getSerializedSize() + INT_SIZE;
    } else {
        size += INT_SIZE;
    }
    if (nt.getExecutorInfo() != null) {
        size += nt.getExecutorInfo().getSerializedSize() + INT_SIZE;
    } else {
        size += INT_SIZE;
    }
    byte[] taskPrefixBytes = ZERO_BYTES;
    if (nt.getTaskPrefix() != null) {
        taskPrefixBytes = toBytes(nt.getTaskPrefix());
        size += taskPrefixBytes.length + INT_SIZE;
    }
    // Allocate and populate the buffer.
    ByteBuffer bb = createBuffer(size);
    putBytes(bb, profile);
    bb.putInt(type.ordinal());
    putBytes(bb, constraintBytes);
    putBytes(bb, hostname);
    putBytes(bb, getSlaveBytes(nt));
    putBytes(bb, getTaskBytes(nt));
    putBytes(bb, getExecutorInfoBytes(nt));
    putBytes(bb, taskPrefixBytes);
    // Make sure the buffer is at the beginning
    bb.rewind();
    return bb;
}
Also used : LikeConstraint(org.apache.myriad.scheduler.constraints.LikeConstraint) Constraint(org.apache.myriad.scheduler.constraints.Constraint) Type(org.apache.myriad.scheduler.constraints.Constraint.Type) ByteBuffer(java.nio.ByteBuffer) LikeConstraint(org.apache.myriad.scheduler.constraints.LikeConstraint) Constraint(org.apache.myriad.scheduler.constraints.Constraint)

Example 2 with Type

use of org.apache.myriad.scheduler.constraints.Constraint.Type in project incubator-myriad by apache.

the class ByteBufferSupport method getConstraint.

public static Constraint getConstraint(ByteBuffer bb) {
    Constraint.Type type = Constraint.Type.values()[bb.getInt()];
    String p = toString(bb);
    switch(type) {
        case NULL:
            return null;
        case LIKE:
            if (StringUtils.isNotEmpty(p)) {
                return gson.fromJson(p, LikeConstraint.class);
            }
    }
    return null;
}
Also used : LikeConstraint(org.apache.myriad.scheduler.constraints.LikeConstraint) Constraint(org.apache.myriad.scheduler.constraints.Constraint) Type(org.apache.myriad.scheduler.constraints.Constraint.Type)

Aggregations

Constraint (org.apache.myriad.scheduler.constraints.Constraint)2 Type (org.apache.myriad.scheduler.constraints.Constraint.Type)2 LikeConstraint (org.apache.myriad.scheduler.constraints.LikeConstraint)2 ByteBuffer (java.nio.ByteBuffer)1