Exemplo n.º 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()
}
Exemplo n.º 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 "?"
}
Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 5
0
func AddResourceRevocable(resource *mesos.Resource) *mesos.Resource {
	resource.Revocable = &mesos.Resource_RevocableInfo{}
	return resource
}