Exemplo n.º 1
0
func (a *Application) GetConstraints() map[string][]constraints.Constraint {
	constraints, err := constraints.ParseConstraints(a.Constraints)
	if err != nil {
		panic(err) //constraints should be validated before this call
	}
	return constraints
}
Exemplo n.º 2
0
func (a *Application) Validate() error {
	if a.Type == "" {
		return ErrApplicationNoType
	}

	if len(a.Tasks) > 0 {
		_, ok := TaskRunners[a.Type]
		if !ok {
			Logger.Info("%s: %s", ErrApplicationNoTaskRunner, a.Type)
			return ErrApplicationNoTaskRunner
		}
	}

	if a.ID == "" {
		return ErrApplicationNoID
	}

	if a.Cpu <= 0.0 {
		return ErrApplicationInvalidCPU
	}

	if a.Mem <= 0.0 {
		return ErrApplicationInvalidMem
	}

	if a.Instances != "" && a.Instances != "all" {
		instances, err := strconv.Atoi(a.Instances)
		if err != nil || instances < 1 {
			return ErrApplicationInvalidInstances
		}
	}

	_, err := constraints.ParseConstraints(a.Constraints)
	if err != nil {
		return err
	}

	return nil
}