Ejemplo n.º 1
0
// populates the list of tasks in each service
// and clobber each service in the ServiceList's Tasks with a new set
func (services *ServiceList) LoadAllAppTasks(c marathon.Client) error {
	for i, service := range *services {
		ts, err := c.GetTasks(service.AppId)
		if err != nil {
			return err
		}
		// I still really dont grok how go's pointers work for mutability
		// but this works...
		// Make sure we sort tasks, so configs have a predictable ordering and dont change every run
		sort.Sort(ts)
		(*services)[i].tasks = &ts
	}
	return nil
}
Ejemplo n.º 2
0
// populates the list of tasks in each service
// and clobber each service in the ServiceList's Tasks with a new set
func (services *ServiceList) LoadAllAppTasks(c marathon.Client) error {
	marathonApps, err := c.GetAllTasks()
	if err != nil {
		return err
	}

	for i, service := range *services {
		ts, ok := marathonApps[service.AppId]
		if !ok {
			if appPresenceRequired {
				return fmt.Errorf("%s does not exist in marathon, -app-required is true", service.AppId)
			} else {
				// we should assume an empty task set
				marathonApps[service.AppId] = marathon.TaskList{}
			}
		}

		// filter tasks for those which are actually healthy
		// if no health checks are present, marathon defers to mesos task status TASK_RUNNING -> healthy
		// so... if we find any healthcheck responses that are not alive, and dont add them to a new array
		// (because splicing is hard)
		healthyTasks := marathon.TaskList{}
		for _, t := range ts {
			healthy := true
			for _, h := range t.HealthCheckResults {
				if !h.Alive {
					log.Printf("Task %s is considered unhealthy by marathon, removing\n", t.String(), service.AppId)
					healthy = false
				}
			}
			if healthy {
				// build up the list of healthy tasks
				healthyTasks = append(healthyTasks, t)
			}
		}

		// Make sure we sort tasks, so configs have a predictable ordering and dont change every run
		sort.Sort(healthyTasks)
		// I still really dont grok how go's pointers work for mutability
		// but this works...
		(*services)[i].tasks = &healthyTasks
	}
	return nil
}