示例#1
0
func Resource(resource *mesos.Resource) string {
	var buffer bytes.Buffer

	buffer.WriteString(resource.GetName())
	buffer.WriteString(":")
	if resource.GetScalar() != nil {
		buffer.WriteString(fmt.Sprintf("%.2f", resource.GetScalar().GetValue()))
	}
	if resource.GetRanges() != nil {
		for _, r := range resource.GetRanges().GetRange() {
			buffer.WriteString(fmt.Sprintf("[%d..%d]", r.GetBegin(), r.GetEnd()))
		}
	}

	return buffer.String()
}
示例#2
0
func formatResource(resource *mesosproto.Resource) string {
	switch resource.GetType() {
	case mesosproto.Value_SCALAR:
		if resource.GetName() == "disk" || resource.GetName() == "mem" {
			return units.BytesSize(resource.GetScalar().GetValue() * 1024 * 1024)
		}
		return fmt.Sprintf("%d", int(resource.GetScalar().GetValue()))

	case mesosproto.Value_RANGES:
		var ranges []string
		for _, r := range resource.GetRanges().GetRange() {
			ranges = append(ranges, fmt.Sprintf("%d-%d", r.GetBegin(), r.GetEnd()))
		}
		return strings.Join(ranges, ", ")
	}
	return "?"
}
示例#3
0
// isScalar returns true if the given resource is a scalar type.
func isScalar(r *mesos.Resource) bool {
	return r.GetType() == mesos.Value_SCALAR
}
示例#4
0
func AddResourceReservation(resource *mesos.Resource, principal string, role string) *mesos.Resource {
	resource.Reservation = &mesos.Resource_ReservationInfo{Principal: proto.String(principal)}
	resource.Role = proto.String(role)
	return resource
}
示例#5
0
func AddResourceRevocable(resource *mesos.Resource) *mesos.Resource {
	resource.Revocable = &mesos.Resource_RevocableInfo{}
	return resource
}