Exemplo n.º 1
0
Arquivo: helpers.go Projeto: bac/juju
// Payloads2TrackArgs converts the provided payload info into arguments
// for the Track API endpoint.
func Payloads2TrackArgs(payloads []payload.Payload) TrackArgs {
	var args TrackArgs
	for _, pl := range payloads {
		fullPayload := payload.FullPayloadInfo{Payload: pl}
		arg := api.Payload2api(fullPayload)
		args.Payloads = append(args.Payloads, arg)
	}
	return args
}
Exemplo n.º 2
0
func (s *publicSuite) TestListAllFilters(c *gc.C) {
	pl := payload.FullPayloadInfo{
		Payload: payload.Payload{
			PayloadClass: charm.PayloadClass{
				Name: "spam",
				Type: "docker",
			},
			ID:     "idspam",
			Status: payload.StateRunning,
			Labels: []string{"a-tag"},
			Unit:   "a-service/0",
		},
		Machine: "1",
	}
	apiPayload := api.Payload2api(pl)
	s.state.payloads = append(s.state.payloads, pl)

	facade := PublicAPI{s.state}
	patterns := []string{
		"spam",               // name
		"docker",             // type
		"idspam",             // ID
		payload.StateRunning, // status
		"a-service/0",        // unit
		"1",                  // machine
		"a-tag",              // tags
	}
	for _, pattern := range patterns {
		c.Logf("trying pattern %q", pattern)

		args := api.EnvListArgs{
			Patterns: []string{
				pattern,
			},
		}
		results, err := facade.List(args)
		c.Assert(err, jc.ErrorIsNil)

		c.Check(results, jc.DeepEquals, api.EnvListResults{
			Results: []api.Payload{
				apiPayload,
			},
		})
	}
}
Exemplo n.º 3
0
Arquivo: helpers.go Projeto: bac/juju
// Result2api converts the payload.Result into a PayloadResult.
func Result2api(result payload.Result) PayloadResult {
	res := PayloadResult{
		NotFound: result.NotFound,
	}

	if result.ID != "" {
		res.Tag = names.NewPayloadTag(result.ID).String()
	}

	if result.Payload != nil {
		pl := api.Payload2api(*result.Payload)
		res.Payload = &pl
	}

	if result.Error != nil {
		res.Error = common.ServerError(result.Error)
	}

	return res
}
Exemplo n.º 4
0
// List builds the list of payloads being tracked for
// the given unit and IDs. If no IDs are provided then all tracked
// payloads for the unit are returned.
func (a PublicAPI) List(args api.EnvListArgs) (api.EnvListResults, error) {
	var r api.EnvListResults

	payloads, err := a.State.ListAll()
	if err != nil {
		return r, errors.Trace(err)
	}

	filters, err := payload.BuildPredicatesFor(args.Patterns)
	if err != nil {
		return r, errors.Trace(err)
	}
	payloads = payload.Filter(payloads, filters...)

	for _, payload := range payloads {
		apiInfo := api.Payload2api(payload)
		r.Results = append(r.Results, apiInfo)
	}
	return r, nil
}
Exemplo n.º 5
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
}