本文整理汇总了Golang中github.com/juju/juju/resource.Resource类的典型用法代码示例。如果您正苦于以下问题:Golang Resource类的具体用法?Golang Resource怎么用?Golang Resource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Resource类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: setUnitResource
func (p ResourcePersistence) setUnitResource(unitID string, res resource.Resource, progress *int64) error {
stored, err := p.getStored(res)
if err != nil {
return errors.Trace(err)
}
// TODO(ericsnow) Ensure that stored.Resource matches res? If we do
// so then the following line is unnecessary.
stored.Resource = res
if err := res.Validate(); err != nil {
return errors.Annotate(err, "bad resource")
}
buildTxn := func(attempt int) ([]txn.Op, error) {
// This is an "upsert".
var ops []txn.Op
switch attempt {
case 0:
ops = newInsertUnitResourceOps(unitID, stored, progress)
case 1:
ops = newUpdateUnitResourceOps(unitID, stored, progress)
default:
// Either insert or update will work so we should not get here.
return nil, errors.New("setting the resource failed")
}
// No pending resources so we always do this here.
ops = append(ops, p.base.ServiceExistsOps(res.ServiceID)...)
return ops, nil
}
if err := p.base.Run(buildTxn); err != nil {
return errors.Trace(err)
}
return nil
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:34,代码来源:resources_persistence.go
示例2: setResource
func (st resourceState) setResource(pendingID, applicationID, userID string, chRes charmresource.Resource, r io.Reader) (resource.Resource, error) {
id := newResourceID(applicationID, chRes.Name)
res := resource.Resource{
Resource: chRes,
ID: id,
PendingID: pendingID,
ApplicationID: applicationID,
}
if r != nil {
// TODO(ericsnow) Validate the user ID (or use a tag).
res.Username = userID
res.Timestamp = st.currentTimestamp()
}
if err := res.Validate(); err != nil {
return res, errors.Annotate(err, "bad resource metadata")
}
if r == nil {
if err := st.persist.SetResource(res); err != nil {
return res, errors.Trace(err)
}
} else {
if err := st.storeResource(res, r); err != nil {
return res, errors.Trace(err)
}
}
return res, nil
}
开发者ID:bac,项目名称:juju,代码行数:31,代码来源:resource.go
示例3: TestValidateZeroValue
func (ResourceSuite) TestValidateZeroValue(c *gc.C) {
var res resource.Resource
err := res.Validate()
c.Check(errors.Cause(err), jc.Satisfies, errors.IsNotValid)
c.Check(err, gc.ErrorMatches, `.*bad info.*`)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:8,代码来源:resource_test.go
示例4: TestValidateUploadNotUsed
func (ResourceSuite) TestValidateUploadNotUsed(c *gc.C) {
res := resource.Resource{
Resource: newFullCharmResource(c, "spam"),
ID: "a-service/spam",
ServiceID: "a-service",
}
err := res.Validate()
c.Check(err, jc.ErrorIsNil)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:11,代码来源:resource_test.go
示例5: TestValidateUploadNotUsed
func (ResourceSuite) TestValidateUploadNotUsed(c *gc.C) {
res := resource.Resource{
Resource: newFullCharmResource(c, "spam"),
ID: "a-application/spam",
ApplicationID: "a-application",
}
err := res.Validate()
c.Check(err, jc.ErrorIsNil)
}
开发者ID:bac,项目名称:juju,代码行数:11,代码来源:resource_test.go
示例6: TestValidateMissingID
func (ResourceSuite) TestValidateMissingID(c *gc.C) {
res := resource.Resource{
Resource: newFullCharmResource(c, "spam"),
ServiceID: "a-service",
Username: "a-user",
Timestamp: time.Now(),
}
err := res.Validate()
c.Check(err, jc.ErrorIsNil)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:12,代码来源:resource_test.go
示例7: TestValidateMissingServiceID
func (ResourceSuite) TestValidateMissingServiceID(c *gc.C) {
res := resource.Resource{
Resource: newFullCharmResource(c, "spam"),
ID: "a-service/spam",
Username: "a-user",
Timestamp: time.Now(),
}
err := res.Validate()
c.Check(errors.Cause(err), jc.Satisfies, errors.IsNotValid)
c.Check(err, gc.ErrorMatches, `.*missing service ID.*`)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:13,代码来源:resource_test.go
示例8: TestValidateUploadUsed
func (ResourceSuite) TestValidateUploadUsed(c *gc.C) {
res := resource.Resource{
Resource: newFullCharmResource(c, "spam"),
ID: "a-application/spam",
ApplicationID: "a-application",
Username: "a-user",
Timestamp: time.Now(),
}
err := res.Validate()
c.Check(err, jc.ErrorIsNil)
}
开发者ID:bac,项目名称:juju,代码行数:13,代码来源:resource_test.go
示例9: TestValidateBadInfo
func (ResourceSuite) TestValidateBadInfo(c *gc.C) {
var charmRes charmresource.Resource
c.Assert(charmRes.Validate(), gc.NotNil)
res := resource.Resource{
Resource: charmRes,
}
err := res.Validate()
c.Check(errors.Cause(err), jc.Satisfies, errors.IsNotValid)
c.Check(err, gc.ErrorMatches, `.*bad info.*`)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:13,代码来源:resource_test.go
示例10: TestValidateUploadPending
func (ResourceSuite) TestValidateUploadPending(c *gc.C) {
res := resource.Resource{
Resource: newFullCharmResource(c, "spam"),
ID: "a-service/spam",
PendingID: "some-unique-ID",
ServiceID: "a-service",
Username: "a-user",
Timestamp: time.Now(),
}
err := res.Validate()
c.Check(err, jc.ErrorIsNil)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:14,代码来源:resource_test.go
示例11: TestValidateMissingTimestamp
func (ResourceSuite) TestValidateMissingTimestamp(c *gc.C) {
res := resource.Resource{
Resource: newFullCharmResource(c, "spam"),
ID: "a-application/spam",
ApplicationID: "a-application",
Username: "a-user",
Timestamp: time.Time{},
}
err := res.Validate()
c.Check(errors.Cause(err), jc.Satisfies, errors.IsNotValid)
c.Check(err, gc.ErrorMatches, `.*missing timestamp.*`)
}
开发者ID:bac,项目名称:juju,代码行数:14,代码来源:resource_test.go
示例12: TestAPI2Resource
func (helpersSuite) TestAPI2Resource(c *gc.C) {
now := time.Now()
res, err := api.API2Resource(api.Resource{
CharmResource: api.CharmResource{
Name: "spam",
Type: "file",
Path: "spam.tgz",
Description: "you need it",
Origin: "upload",
Revision: 1,
Fingerprint: []byte(fingerprint),
Size: 10,
},
ID: "a-service/spam",
PendingID: "some-unique-ID",
ServiceID: "a-service",
Username: "a-user",
Timestamp: now,
})
c.Assert(err, jc.ErrorIsNil)
fp, err := charmresource.NewFingerprint([]byte(fingerprint))
c.Assert(err, jc.ErrorIsNil)
expected := resource.Resource{
Resource: charmresource.Resource{
Meta: charmresource.Meta{
Name: "spam",
Type: charmresource.TypeFile,
Path: "spam.tgz",
Description: "you need it",
},
Origin: charmresource.OriginUpload,
Revision: 1,
Fingerprint: fp,
Size: 10,
},
ID: "a-service/spam",
PendingID: "some-unique-ID",
ServiceID: "a-service",
Username: "a-user",
Timestamp: now,
}
err = expected.Validate()
c.Assert(err, jc.ErrorIsNil)
c.Check(res, jc.DeepEquals, expected)
}
开发者ID:OSBI,项目名称:juju,代码行数:47,代码来源:helpers_test.go
示例13: newResource
func newResource(c *gc.C, name, serviceID, username, content string) resource.Resource {
var timestamp time.Time
if username != "" {
timestamp = time.Now().UTC()
}
res := resource.Resource{
Resource: NewCharmResource(c, name, content),
ID: serviceID + "/" + name,
PendingID: "",
ServiceID: serviceID,
Username: username,
Timestamp: timestamp,
}
err := res.Validate()
c.Assert(err, jc.ErrorIsNil)
return res
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:17,代码来源:resource.go
示例14: TestResource2API
func (HelpersSuite) TestResource2API(c *gc.C) {
fp, err := charmresource.NewFingerprint([]byte(fingerprint))
c.Assert(err, jc.ErrorIsNil)
now := time.Now()
res := resource.Resource{
Resource: charmresource.Resource{
Meta: charmresource.Meta{
Name: "spam",
Type: charmresource.TypeFile,
Path: "spam.tgz",
Description: "you need it",
},
Origin: charmresource.OriginUpload,
Revision: 1,
Fingerprint: fp,
Size: 10,
},
ID: "a-application/spam",
PendingID: "some-unique-ID",
ApplicationID: "a-application",
Username: "a-user",
Timestamp: now,
}
err = res.Validate()
c.Assert(err, jc.ErrorIsNil)
apiRes := api.Resource2API(res)
c.Check(apiRes, jc.DeepEquals, api.Resource{
CharmResource: api.CharmResource{
Name: "spam",
Type: "file",
Path: "spam.tgz",
Description: "you need it",
Origin: "upload",
Revision: 1,
Fingerprint: []byte(fingerprint),
Size: 10,
},
ID: "a-application/spam",
PendingID: "some-unique-ID",
ApplicationID: "a-application",
Username: "a-user",
Timestamp: now,
})
}
开发者ID:bac,项目名称:juju,代码行数:45,代码来源:helpers_test.go
示例15: newResource
func newResource(c *gc.C, name, applicationID, username, content string) resource.Resource {
var timestamp time.Time
if username != "" {
// TODO(perrito666) 2016-05-02 lp:1558657
timestamp = time.Now().UTC()
}
res := resource.Resource{
Resource: NewCharmResource(c, name, content),
ID: applicationID + "/" + name,
PendingID: "",
ApplicationID: applicationID,
Username: username,
Timestamp: timestamp,
}
err := res.Validate()
c.Assert(err, jc.ErrorIsNil)
return res
}
开发者ID:bac,项目名称:juju,代码行数:18,代码来源:resource.go
示例16: TestRevisionStringNone
func (ResourceSuite) TestRevisionStringNone(c *gc.C) {
res := resource.Resource{
Resource: charmresource.Resource{
Meta: charmresource.Meta{
Name: "foo",
Type: charmresource.TypeFile,
Path: "foo.tgz",
Description: "you need it",
},
Origin: charmresource.OriginUpload,
},
ServiceID: "svc",
}
err := res.Validate()
c.Check(err, jc.ErrorIsNil)
c.Check(res.RevisionString(), gc.Equals, "-")
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:19,代码来源:resource_test.go
示例17: doc2basicResource
// doc2basicResource returns the resource info represented by the doc.
func doc2basicResource(doc resourceDoc) (resource.Resource, error) {
var res resource.Resource
resType, err := charmresource.ParseType(doc.Type)
if err != nil {
return res, errors.Annotate(err, "got invalid data from DB")
}
origin, err := charmresource.ParseOrigin(doc.Origin)
if err != nil {
return res, errors.Annotate(err, "got invalid data from DB")
}
fp, err := resource.DeserializeFingerprint(doc.Fingerprint)
if err != nil {
return res, errors.Annotate(err, "got invalid data from DB")
}
res = resource.Resource{
Resource: charmresource.Resource{
Meta: charmresource.Meta{
Name: doc.Name,
Type: resType,
Path: doc.Path,
Description: doc.Description,
},
Origin: origin,
Revision: doc.Revision,
Fingerprint: fp,
Size: doc.Size,
},
ID: doc.ID,
PendingID: doc.PendingID,
ServiceID: doc.ServiceID,
Username: doc.Username,
Timestamp: doc.Timestamp,
}
if err := res.Validate(); err != nil {
return res, errors.Annotate(err, "got invalid data from DB")
}
return res, nil
}
开发者ID:OSBI,项目名称:juju,代码行数:43,代码来源:mongo.go
示例18: FormatSvcResource
// FormatSvcResource converts the resource info into a FormattedServiceResource.
func FormatSvcResource(res resource.Resource) FormattedSvcResource {
used := !res.IsPlaceholder()
return FormattedSvcResource{
ID: res.ID,
ServiceID: res.ServiceID,
Name: res.Name,
Type: res.Type.String(),
Path: res.Path,
Description: res.Description,
Revision: res.Revision,
Origin: res.Origin.String(),
Fingerprint: res.Fingerprint.String(),
Size: res.Size,
Used: used,
Timestamp: res.Timestamp,
Username: res.Username,
combinedRevision: combinedRevision(res),
combinedOrigin: combinedOrigin(used, res),
usedYesNo: usedYesNo(used),
}
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:22,代码来源:formatter.go
示例19: TestRevisionStringTime
func (ResourceSuite) TestRevisionStringTime(c *gc.C) {
res := resource.Resource{
Resource: charmresource.Resource{
Meta: charmresource.Meta{
Name: "foo",
Type: charmresource.TypeFile,
Path: "foo.tgz",
Description: "you need it",
},
Origin: charmresource.OriginUpload,
},
ServiceID: "svc",
Username: "a-user",
Timestamp: time.Date(2012, 7, 8, 15, 59, 5, 5, time.UTC),
}
err := res.Validate()
c.Check(err, jc.ErrorIsNil)
c.Check(res.RevisionString(), gc.Equals, "2012-07-08 15:59:05 +0000 UTC")
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:21,代码来源:resource_test.go
示例20: TestRevisionStringNumber
func (ResourceSuite) TestRevisionStringNumber(c *gc.C) {
res := resource.Resource{
Resource: charmresource.Resource{
Meta: charmresource.Meta{
Name: "foo",
Type: charmresource.TypeFile,
Path: "foo.tgz",
Description: "you need it",
},
Origin: charmresource.OriginStore,
Revision: 7,
},
ApplicationID: "svc",
Username: "a-user",
Timestamp: time.Date(2012, 7, 8, 15, 59, 5, 5, time.UTC),
}
err := res.Validate()
c.Check(err, jc.ErrorIsNil)
c.Check(res.RevisionString(), gc.Equals, "7")
}
开发者ID:bac,项目名称:juju,代码行数:22,代码来源:resource_test.go
注:本文中的github.com/juju/juju/resource.Resource类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论