當前位置: 首頁>>代碼示例>>Golang>>正文


Golang resource.Resource類代碼示例

本文整理匯總了Golang中github.com/juju/juju/resource.Resource的典型用法代碼示例。如果您正苦於以下問題:Golang Resource類的具體用法?Golang Resource怎麽用?Golang Resource使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Resource類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的github.com/juju/juju/resource.Resource類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。