Пример #1
0
// LookUp identifies the payload with the provided name and raw ID.
func (uf UnitFacade) LookUp(args internal.LookUpArgs) (internal.PayloadResults, error) {
	var r internal.PayloadResults
	for _, arg := range args.Args {
		id, err := uf.State.LookUp(arg.Name, arg.ID)
		res := internal.NewPayloadResult(id, err)
		r.Results = append(r.Results, res)
	}
	return r, nil
}
Пример #2
0
func (internalHelpersSuite) TestNewPayloadResultOkay(c *gc.C) {
	id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
	result := private.NewPayloadResult(id, nil)

	c.Check(result, jc.DeepEquals, private.PayloadResult{
		Entity: params.Entity{
			Tag: names.NewPayloadTag(id).String(),
		},
		Payload:  nil,
		NotFound: false,
		Error:    nil,
	})
}
Пример #3
0
func (internalHelpersSuite) TestNewPayloadResultNotFound(c *gc.C) {
	id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
	err := errors.NotFoundf("payload %q", id)
	result := private.NewPayloadResult(id, err)

	c.Check(result, jc.DeepEquals, private.PayloadResult{
		Entity: params.Entity{
			Tag: names.NewPayloadTag(id).String(),
		},
		Payload:  nil,
		NotFound: true,
		Error:    common.ServerError(err),
	})
}
Пример #4
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
}
Пример #5
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
}
Пример #6
0
// Track stores a payload to be tracked in state.
func (uf UnitFacade) Track(args internal.TrackArgs) (internal.PayloadResults, error) {
	logger.Debugf("tracking %d payloads from API", len(args.Payloads))

	var r internal.PayloadResults
	for _, apiPayload := range args.Payloads {
		pl, err := api.API2Payload(apiPayload)
		if err != nil {
			return r, errors.Trace(err)
		}
		logger.Debugf("tracking payload from API: %#v", pl)

		id, err := uf.track(pl.Payload)
		res := internal.NewPayloadResult(id, err)
		r.Results = append(r.Results, res)
	}
	return r, nil
}
Пример #7
0
func (uf UnitFacade) listAll() (internal.PayloadResults, error) {
	var r internal.PayloadResults

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

	for _, result := range results {
		pl := result.Payload
		id, err := uf.State.LookUp(pl.Name, pl.ID)
		if err != nil {
			logger.Errorf("failed to look up ID for %q: %v", pl.FullID(), err)
			id = ""
		}
		apipl := api.Payload2api(*pl)

		res := internal.NewPayloadResult(id, nil)
		res.Payload = &apipl
		r.Results = append(r.Results, res)
	}
	return r, nil
}