Example #1
0
func (self *manager) ResourceRequirementsWouldMatch(offer *mesosproto.Offer, taskRequest *managerInterface.Task) bool {
	for _, resource := range offer.GetResources() {
		switch {
		case *resource.Name == "cpus":
			if resource.Scalar.GetValue() < float64(taskRequest.Cpus) {
				return false
			}
		case *resource.Name == "mem":
			if resource.Scalar.GetValue() < float64(taskRequest.Mem) {
				return false
			}
		}
	}
	for _, attribute := range offer.GetAttributes() {
		switch {
		case *attribute.Name == "nodetype":
			if len(taskRequest.NodeType) > 0 && attribute.Text.GetValue() != taskRequest.NodeType {
				return false
			}
		case *attribute.Name == "nodename":
			if len(taskRequest.NodeName) > 0 && attribute.Text.GetValue() != taskRequest.NodeName {
				return false
			}
		}
	}

	return true
}
Example #2
0
func removeOfferFromList(offers []*mesosproto.Offer, offer *mesosproto.Offer) []*mesosproto.Offer {
	numberOfOffers := len(offers)
	if numberOfOffers == 0 {
		return []*mesosproto.Offer{}
	}

	result := make([]*mesosproto.Offer, 0)
	for _, value := range offers {
		if offer.GetId().GetValue() == value.GetId().GetValue() {
			continue
		}
		result = append(result, value)
	}

	return result
}