Example #1
0
File: server.go Project: bac/juju
// ListResources returns the list of resources for the given application.
func (f Facade) ListResources(args api.ListResourcesArgs) (api.ResourcesResults, error) {
	var r api.ResourcesResults
	r.Results = make([]api.ResourcesResult, len(args.Entities))

	for i, e := range args.Entities {
		logger.Tracef("Listing resources for %q", e.Tag)
		tag, apierr := parseApplicationTag(e.Tag)
		if apierr != nil {
			r.Results[i] = api.ResourcesResult{
				ErrorResult: params.ErrorResult{
					Error: apierr,
				},
			}
			continue
		}

		svcRes, err := f.store.ListResources(tag.Id())
		if err != nil {
			r.Results[i] = errorResult(err)
			continue
		}

		r.Results[i] = api.ServiceResources2APIResult(svcRes)
	}
	return r, nil
}
Example #2
0
File: server.go Project: OSBI/juju
// ListResources returns the list of resources for the given service.
func (f Facade) ListResources(args api.ListResourcesArgs) (api.ResourcesResults, error) {
	var r api.ResourcesResults
	r.Results = make([]api.ResourcesResult, len(args.Entities))

	for i, e := range args.Entities {
		logger.Tracef("Listing resources for %q", e.Tag)
		tag, apierr := parseServiceTag(e.Tag)
		if apierr != nil {
			r.Results[i] = api.ResourcesResult{
				ErrorResult: params.ErrorResult{
					Error: apierr,
				},
			}
			continue
		}

		svcRes, err := f.store.ListResources(tag.Id())
		if err != nil {
			r.Results[i] = errorResult(err)
			continue
		}

		var result api.ResourcesResult
		for _, res := range svcRes.Resources {
			result.Resources = append(result.Resources, api.Resource2API(res))
		}
		for _, unitRes := range svcRes.UnitResources {
			unit := api.UnitResources{
				Entity: params.Entity{Tag: unitRes.Tag.String()},
			}
			for _, res := range unitRes.Resources {
				unit.Resources = append(unit.Resources, api.Resource2API(res))
			}
			result.UnitResources = append(result.UnitResources, unit)
		}
		r.Results[i] = result
	}
	return r, nil
}