Example #1
0
func (api *restAPI) fillWorkSpecShort(namespace coordinate.Namespace, name string, short *restdata.WorkSpecShort) error {
	short.Name = name
	return buildURLs(api.Router,
		"namespace", namespace.Name(),
		"spec", name,
	).URL(&short.URL, "workSpec").Error
}
Example #2
0
func (api *restAPI) fillWorkerShort(namespace coordinate.Namespace, worker coordinate.Worker, short *restdata.WorkerShort) error {
	short.Name = worker.Name()
	return buildURLs(api.Router,
		"namespace", namespace.Name(),
		"worker", short.Name,
	).
		URL(&short.URL, "worker").
		Error
}
Example #3
0
func (api *restAPI) attemptURLBuilder(namespace coordinate.Namespace, attempt coordinate.Attempt, startTime time.Time, err error) *urlBuilder {
	unit := attempt.WorkUnit()
	spec := unit.WorkSpec()
	worker := attempt.Worker()
	if err == nil {
		return buildURLs(api.Router,
			"namespace", namespace.Name(),
			"spec", spec.Name(),
			"unit", unit.Name(),
			"worker", worker.Name(),
			"start", startTime.Format(time.RFC3339),
		)
	}
	return &urlBuilder{Error: err}
}
Example #4
0
func (api *restAPI) fillWorkUnit(namespace coordinate.Namespace, spec coordinate.WorkSpec, unit coordinate.WorkUnit, repr *restdata.WorkUnit) error {
	err := api.fillWorkUnitShort(namespace, spec, unit.Name(), &repr.WorkUnitShort)
	if err == nil {
		repr.Data, err = unit.Data()
	}
	if err == nil {
		var meta coordinate.WorkUnitMeta
		meta, err = unit.Meta()
		repr.Meta = &meta
	}
	if err == nil {
		repr.Status, err = unit.Status()
	}
	if err == nil {
		err = buildURLs(api.Router,
			"namespace", namespace.Name(),
			"spec", spec.Name(),
			"unit", unit.Name(),
		).
			URL(&repr.WorkSpecURL, "workSpec").
			URL(&repr.AttemptsURL, "workUnitAttempts").
			Error
	}
	if err == nil {
		var attempt coordinate.Attempt
		attempt, err = unit.ActiveAttempt()
		if err == nil && attempt != nil {
			// This is cheating, a little, but it's probably
			// the easiest way to reuse this code
			var short restdata.AttemptShort
			err = api.fillAttemptShort(namespace, attempt, &short)
			if err == nil {
				repr.ActiveAttemptURL = short.URL
			}
		}
	}
	return err
}
Example #5
0
func (api *restAPI) fillWorkSpec(namespace coordinate.Namespace, name string, repr *restdata.WorkSpec) error {
	err := api.fillWorkSpecShort(namespace, name, &repr.WorkSpecShort)
	if err == nil {
		err = buildURLs(api.Router,
			"namespace", namespace.Name(),
			"spec", name).
			URL(&repr.WorkUnitsURL, "workUnits").
			Template(&repr.WorkUnitURL, "workUnit", "unit").
			URL(&repr.MetaURL, "workSpecMeta").
			URL(&repr.WorkUnitCountsURL, "workSpecCounts").
			URL(&repr.WorkUnitChangeURL, "workSpecChange").
			URL(&repr.WorkUnitAdjustURL, "workSpecAdjust").
			Error
	}
	if err == nil {
		repr.MetaURL += "{?counts}"
		qs := "{?name*,status*,previous,limit}"
		repr.WorkUnitQueryURL = repr.WorkUnitsURL + qs
		repr.WorkUnitChangeURL += qs
		repr.WorkUnitAdjustURL += qs
	}
	return err
}
Example #6
0
func (api *restAPI) fillNamespaceShort(namespace coordinate.Namespace, summary *restdata.NamespaceShort) error {
	summary.Name = namespace.Name()
	return buildURLs(api.Router, "namespace", summary.Name).
		URL(&summary.URL, "namespace").
		Error
}
Example #7
0
func (api *restAPI) fillWorker(namespace coordinate.Namespace, worker coordinate.Worker, result *restdata.Worker) error {
	err := api.fillWorkerShort(namespace, worker, &result.WorkerShort)
	if err == nil {
		err = buildURLs(api.Router,
			"namespace", namespace.Name(),
			"worker", worker.Name(),
		).
			URL(&result.RequestAttemptsURL, "workerRequestAttempts").
			URL(&result.MakeAttemptURL, "workerMakeAttempt").
			URL(&result.ActiveAttemptsURL, "workerActiveAttempts").
			URL(&result.AllAttemptsURL, "workerAllAttempts").
			URL(&result.ChildAttemptsURL, "workerChildAttempts").
			Error
	}
	var parent coordinate.Worker
	if err == nil {
		parent, err = worker.Parent()
	}
	if err == nil && parent != nil {
		parentName := parent.Name()
		result.Parent = &parentName
		err = buildURLs(api.Router,
			"namespace", namespace.Name(),
			"worker", parent.Name(),
		).
			URL(&result.ParentURL, "worker").
			Error
	}
	var children []coordinate.Worker
	if err == nil {
		children, err = worker.Children()
	}
	if err == nil {
		result.ChildURLs = make([]string, len(children))
		for i, child := range children {
			err = buildURLs(api.Router,
				"namespace", namespace.Name(),
				"worker", child.Name(),
			).
				URL(&result.ChildURLs[i], "worker").
				Error
			if err != nil {
				break
			}
		}
	}
	if err == nil {
		result.Active, err = worker.Active()
	}
	if err == nil {
		result.Mode, err = worker.Mode()
	}
	if err == nil {
		result.Data, err = worker.Data()
	}
	if err == nil {
		result.Expiration, err = worker.Expiration()
	}
	if err == nil {
		result.LastUpdate, err = worker.LastUpdate()
	}
	return err
}