本文整理汇总了Golang中github.com/juju/juju/resource.ServiceResources.CharmStoreResources方法的典型用法代码示例。如果您正苦于以下问题:Golang ServiceResources.CharmStoreResources方法的具体用法?Golang ServiceResources.CharmStoreResources怎么用?Golang ServiceResources.CharmStoreResources使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/resource.ServiceResources
的用法示例。
在下文中一共展示了ServiceResources.CharmStoreResources方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: APIResult2ServiceResources
// APIResult2ServiceResources converts a ResourcesResult into a resource.ServiceResources.
func APIResult2ServiceResources(apiResult ResourcesResult) (resource.ServiceResources, error) {
var result resource.ServiceResources
if apiResult.Error != nil {
// TODO(ericsnow) Return the resources too?
err := common.RestoreError(apiResult.Error)
return resource.ServiceResources{}, errors.Trace(err)
}
for _, apiRes := range apiResult.Resources {
res, err := API2Resource(apiRes)
if err != nil {
// This could happen if the server is misbehaving
// or non-conforming.
// TODO(ericsnow) Aggregate errors?
return resource.ServiceResources{}, errors.Annotate(err, "got bad data from server")
}
result.Resources = append(result.Resources, res)
}
for _, unitRes := range apiResult.UnitResources {
tag, err := names.ParseUnitTag(unitRes.Tag)
if err != nil {
return resource.ServiceResources{}, errors.Annotate(err, "got bad data from server")
}
resNames := map[string]bool{}
unitResources := resource.UnitResources{Tag: tag}
for _, apiRes := range unitRes.Resources {
res, err := API2Resource(apiRes)
if err != nil {
return resource.ServiceResources{}, errors.Annotate(err, "got bad data from server")
}
resNames[res.Name] = true
unitResources.Resources = append(unitResources.Resources, res)
}
if len(unitRes.DownloadProgress) > 0 {
unitResources.DownloadProgress = make(map[string]int64)
for resName, progress := range unitRes.DownloadProgress {
if _, ok := resNames[resName]; !ok {
err := errors.Errorf("got progress from unrecognized resource %q", resName)
return resource.ServiceResources{}, errors.Annotate(err, "got bad data from server")
}
unitResources.DownloadProgress[resName] = progress
}
}
result.UnitResources = append(result.UnitResources, unitResources)
}
for _, chRes := range apiResult.CharmStoreResources {
res, err := API2CharmResource(chRes)
if err != nil {
return resource.ServiceResources{}, errors.Annotate(err, "got bad data from server")
}
result.CharmStoreResources = append(result.CharmStoreResources, res)
}
return result, nil
}
示例2: ListResources
// ListResources returns the info for each non-pending resource of the
// identified service.
func (p ResourcePersistence) ListResources(serviceID string) (resource.ServiceResources, error) {
logger.Tracef("listing all resources for service %q", serviceID)
docs, err := p.resources(serviceID)
if err != nil {
return resource.ServiceResources{}, errors.Trace(err)
}
store := map[string]charmresource.Resource{}
units := map[names.UnitTag][]resource.Resource{}
downloadProgress := make(map[names.UnitTag]map[string]int64)
var results resource.ServiceResources
for _, doc := range docs {
if doc.PendingID != "" {
continue
}
res, err := doc2basicResource(doc)
if err != nil {
return resource.ServiceResources{}, errors.Trace(err)
}
if !doc.LastPolled.IsZero() {
store[res.Name] = res.Resource
continue
}
if doc.UnitID == "" {
results.Resources = append(results.Resources, res)
continue
}
tag := names.NewUnitTag(doc.UnitID)
if doc.PendingID == "" {
units[tag] = append(units[tag], res)
}
if doc.DownloadProgress != nil {
if downloadProgress[tag] == nil {
downloadProgress[tag] = make(map[string]int64)
}
downloadProgress[tag][doc.Name] = *doc.DownloadProgress
}
}
for _, res := range results.Resources {
storeRes := store[res.Name]
results.CharmStoreResources = append(results.CharmStoreResources, storeRes)
}
for tag, res := range units {
results.UnitResources = append(results.UnitResources, resource.UnitResources{
Tag: tag,
Resources: res,
DownloadProgress: downloadProgress[tag],
})
}
return results, nil
}
示例3: newPersistenceResources
func newPersistenceResources(c *gc.C, serviceID string, names ...string) (resource.ServiceResources, []resourceDoc) {
var svcResources resource.ServiceResources
var docs []resourceDoc
for _, name := range names {
res, doc := newPersistenceResource(c, serviceID, name)
svcResources.Resources = append(svcResources.Resources, res.Resource)
svcResources.CharmStoreResources = append(svcResources.CharmStoreResources, res.Resource.Resource)
docs = append(docs, doc)
csDoc := doc // a copy
csDoc.DocID += "#charmstore"
csDoc.Username = ""
csDoc.Timestamp = coretesting.ZeroTime()
csDoc.StoragePath = ""
csDoc.LastPolled = coretesting.NonZeroTime().UTC()
docs = append(docs, csDoc)
}
return svcResources, docs
}