func()

in pkg/scheduler/placement/user_rule.go [69:124]


func (ur *userRule) placeApplication(app *objects.Application, queueFn func(string) *objects.Queue) (string, error) {
	// before anything run the filter
	userName := app.GetUser().User
	if !ur.filter.allowUser(app.GetUser()) {
		log.Log(log.SchedApplication).Debug("User rule filtered",
			zap.String("application", app.ApplicationID),
			zap.Any("user", app.GetUser()))
		return "", nil
	}
	childQueueName := replaceDot(userName)
	if err := configs.IsQueueNameValid(childQueueName); err != nil {
		return "", err
	}
	var parentName string
	var err error
	// run the parent rule if set
	if ur.parent != nil {
		parentName, err = ur.parent.placeApplication(app, queueFn)
		// failed parent rule, fail this rule
		if err != nil {
			return "", err
		}
		// rule did not match: this could be filter or create flag related
		if parentName == "" {
			return "", nil
		}
		// check if this is a parent queue and qualify it
		if !strings.HasPrefix(parentName, configs.RootQueue+configs.DOT) {
			parentName = configs.RootQueue + configs.DOT + parentName
		}
		// if the parent queue exists it cannot be a leaf
		parentQueue := queueFn(parentName)
		if parentQueue != nil && parentQueue.IsLeafQueue() {
			return "", fmt.Errorf("parent rule returned a leaf queue: %s", parentName)
		}
	}
	// the parent is set from the rule otherwise set it to the root
	if parentName == "" {
		parentName = configs.RootQueue
	}
	queueName := parentName + configs.DOT + childQueueName
	// Log the result before we check the create flag
	log.Log(log.SchedApplication).Debug("User rule intermediate result",
		zap.String("application", app.ApplicationID),
		zap.String("queue", queueName))
	// get the queue object
	queue := queueFn(queueName)
	// if we cannot create the queue it must exist, rule does not match otherwise
	if !ur.create && queue == nil {
		return "", nil
	}
	log.Log(log.SchedApplication).Info("User rule application placed",
		zap.String("application", app.ApplicationID),
		zap.String("queue", queueName))
	return queueName, nil
}