Beispiel #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
}
Beispiel #2
0
func (internalHelpersSuite) TestResult2apiOkay(c *gc.C) {
	id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
	result := private.Result2api(payload.Result{
		ID:       id,
		Payload:  nil,
		NotFound: false,
		Error:    nil,
	})

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

	c.Check(result, jc.DeepEquals, private.PayloadResult{
		Entity: params.Entity{
			Tag: names.NewPayloadTag(id).String(),
		},
		Payload:  nil,
		NotFound: false,
		Error:    common.ServerError(err),
	})
}
Beispiel #4
0
func (internalHelpersSuite) TestResult2apiInfo(c *gc.C) {
	id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
	result := private.Result2api(payload.Result{
		ID:       id,
		NotFound: false,
		Error:    nil,
		Payload: &payload.FullPayloadInfo{
			Payload: payload.Payload{
				PayloadClass: charm.PayloadClass{
					Name: "foobar",
					Type: "type",
				},
				ID:     "idfoo",
				Status: payload.StateRunning,
				Unit:   "a-service/0",
			},
			Machine: "1",
		},
	})

	c.Check(result, jc.DeepEquals, private.PayloadResult{
		Entity: params.Entity{
			Tag: names.NewPayloadTag(id).String(),
		},
		NotFound: false,
		Error:    nil,
		Payload: &api.Payload{
			Class:   "foobar",
			Type:    "type",
			ID:      "idfoo",
			Status:  payload.StateRunning,
			Unit:    "unit-a-service-0",
			Machine: "machine-1",
		},
	})
}