Esempio n. 1
0
// List builds the list of payload being tracked for
// the given unit and IDs. If no IDs are provided then all tracked
// payloads for the unit are returned.
func (uf UnitFacade) List(args params.Entities) (internal.PayloadResults, error) {
	if len(args.Entities) == 0 {
		return uf.listAll()
	}

	var ids []string
	for _, entity := range args.Entities {
		id, err := internal.API2ID(entity.Tag)
		if err != nil {
			return internal.PayloadResults{}, errors.Trace(err)
		}
		ids = append(ids, id)
	}

	results, err := uf.State.List(ids...)
	if err != nil {
		return internal.PayloadResults{}, errors.Trace(err)
	}

	var r internal.PayloadResults
	for _, result := range results {
		res := internal.Result2api(result)
		r.Results = append(r.Results, res)
	}
	return r, nil
}
Esempio n. 2
0
// Untrack marks the identified payload as no longer being tracked.
func (uf UnitFacade) Untrack(args params.Entities) (internal.PayloadResults, error) {
	var r internal.PayloadResults
	for _, entity := range args.Entities {
		id, err := internal.API2ID(entity.Tag)
		if err != nil {
			return r, errors.Trace(err)
		}

		err = uf.State.Untrack(id)
		res := internal.NewPayloadResult(id, err)
		r.Results = append(r.Results, res)
	}
	return r, nil
}
Esempio n. 3
0
// SetStatus sets the raw status of a payload.
func (uf UnitFacade) SetStatus(args internal.SetStatusArgs) (internal.PayloadResults, error) {
	var r internal.PayloadResults
	for _, arg := range args.Args {
		id, err := internal.API2ID(arg.Tag)
		if err != nil {
			return r, errors.Trace(err)
		}

		err = uf.State.SetStatus(id, arg.Status)
		res := internal.NewPayloadResult(id, err)
		r.Results = append(r.Results, res)
	}
	return r, nil
}