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


Golang ActualLRP.Since方法代碼示例

本文整理匯總了Golang中github.com/cloudfoundry-incubator/bbs/models.ActualLRP.Since方法的典型用法代碼示例。如果您正苦於以下問題:Golang ActualLRP.Since方法的具體用法?Golang ActualLRP.Since怎麽用?Golang ActualLRP.Since使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/cloudfoundry-incubator/bbs/models.ActualLRP的用法示例。


在下文中一共展示了ActualLRP.Since方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: unclaimActualLRPWithIndex

func (db *ETCDDB) unclaimActualLRPWithIndex(
	logger lager.Logger,
	lrp *models.ActualLRP,
	storeIndex uint64,
	actualLRPKey *models.ActualLRPKey,
	actualLRPInstanceKey *models.ActualLRPInstanceKey,
) (change stateChange, err error) {
	logger = logger.Session("unclaim-actual-lrp-with-index")
	defer func() {
		logger.Debug("complete", lager.Data{"stateChange": change, "error": err})
	}()
	if !lrp.ActualLRPKey.Equal(actualLRPKey) {
		logger.Error("failed-actual-lrp-key-differs", models.ErrActualLRPCannotBeUnclaimed)
		return stateDidNotChange, models.ErrActualLRPCannotBeUnclaimed
	}

	if lrp.State == models.ActualLRPStateUnclaimed {
		logger.Info("already-unclaimed")
		return stateDidNotChange, nil
	}

	if !lrp.ActualLRPInstanceKey.Equal(actualLRPInstanceKey) {
		logger.Error("failed-actual-lrp-instance-key-differs", models.ErrActualLRPCannotBeUnclaimed)
		return stateDidNotChange, models.ErrActualLRPCannotBeUnclaimed
	}

	lrp.Since = db.clock.Now().UnixNano()
	lrp.State = models.ActualLRPStateUnclaimed
	lrp.ActualLRPInstanceKey = models.ActualLRPInstanceKey{}
	lrp.ActualLRPNetInfo = models.EmptyActualLRPNetInfo()
	lrp.ModificationTag.Increment()

	err = lrp.Validate()
	if err != nil {
		logger.Error("failed-to-validate-unclaimed-lrp", err)
		return stateDidNotChange, models.NewError(models.Error_InvalidRecord, err.Error())
	}

	lrpData, serialErr := db.serializeModel(logger, lrp)
	if serialErr != nil {
		logger.Error("failed-to-marshal-unclaimed-lrp", serialErr)
		return stateDidNotChange, serialErr
	}

	_, err = db.client.CompareAndSwap(ActualLRPSchemaPath(actualLRPKey.ProcessGuid, actualLRPKey.Index), lrpData, 0, storeIndex)
	if err != nil {
		logger.Error("failed-to-compare-and-swap", err)
		return stateDidNotChange, models.ErrActualLRPCannotBeUnclaimed
	}

	logger.Debug("changed-to-unclaimed")
	return stateDidChange, nil
}
開發者ID:emc-xchallenge,項目名稱:bbs,代碼行數:53,代碼來源:actual_lrp_db.go

示例2: EvacuateActualLRP

func (db *ETCDDB) EvacuateActualLRP(
	logger lager.Logger,
	lrpKey *models.ActualLRPKey,
	instanceKey *models.ActualLRPInstanceKey,
	netInfo *models.ActualLRPNetInfo,
	ttl uint64,
) (*models.ActualLRPGroup, error) {
	logger = logger.Session("evacuate-actual-lrp", lager.Data{"process_guid": lrpKey.ProcessGuid, "index": lrpKey.Index})

	logger.Debug("starting")
	defer logger.Debug("complete")

	node, err := db.fetchRaw(logger, EvacuatingActualLRPSchemaPath(lrpKey.ProcessGuid, lrpKey.Index))
	bbsErr := models.ConvertError(err)
	if bbsErr != nil {
		if bbsErr.Type == models.Error_ResourceNotFound {
			return db.createEvacuatingActualLRP(logger, lrpKey, instanceKey, netInfo, ttl)
		}
		return nil, bbsErr
	}

	lrp := models.ActualLRP{}
	err = db.deserializeModel(logger, node, &lrp)
	if err != nil {
		return nil, err
	}

	if lrp.ActualLRPKey.Equal(lrpKey) &&
		lrp.ActualLRPInstanceKey.Equal(instanceKey) &&
		reflect.DeepEqual(lrp.ActualLRPNetInfo, *netInfo) {
		return &models.ActualLRPGroup{Evacuating: &lrp}, nil
	}

	lrp.ActualLRPNetInfo = *netInfo
	lrp.ActualLRPKey = *lrpKey
	lrp.ActualLRPInstanceKey = *instanceKey
	lrp.Since = db.clock.Now().UnixNano()
	lrp.ModificationTag.Increment()

	data, err := db.serializeModel(logger, &lrp)
	if err != nil {
		logger.Error("failed-serializing", err)
		return nil, err
	}

	_, err = db.client.CompareAndSwap(EvacuatingActualLRPSchemaPath(lrp.ProcessGuid, lrp.Index), data, ttl, node.ModifiedIndex)
	if err != nil {
		return nil, ErrorFromEtcdError(logger, err)
	}

	return &models.ActualLRPGroup{Evacuating: &lrp}, nil
}
開發者ID:timani,項目名稱:bbs,代碼行數:52,代碼來源:evacuation_db.go

示例3:

				ActualLRPKey: models.NewActualLRPKey(
					"process-guid-1",
					2,
					"domain-1",
				),
				ActualLRPInstanceKey: models.NewActualLRPInstanceKey(
					"instance-guid-1",
					"cell-id-1",
				),
				State: models.ActualLRPStateClaimed,
				Since: 4444,
			}

			evacuatingLRP2 = actualLRP2
			evacuatingLRP2.State = models.ActualLRPStateRunning
			evacuatingLRP2.Since = 3417
		})

		JustBeforeEach(func() {
			handler.ActualLRPGroups(responseRecorder, request)
		})

		Context("when reading actual lrps from DB succeeds", func() {
			var actualLRPGroups *models.ActualLRPGroups

			BeforeEach(func() {
				actualLRPGroups = &models.ActualLRPGroups{
					[]*models.ActualLRPGroup{
						{Instance: &actualLRP1},
						{Instance: &actualLRP2, Evacuating: &evacuatingLRP2},
					},
開發者ID:Gerg,項目名稱:bbs,代碼行數:31,代碼來源:actual_lrp_handlers_test.go

示例4:

			ActualLRPKey: models.NewActualLRPKey(
				"process-guid-1",
				2,
				"domain-1",
			),
			ActualLRPInstanceKey: models.NewActualLRPInstanceKey(
				"instance-guid-1",
				"cell-id-1",
			),
			State: proto.String(models.ActualLRPStateClaimed),
			Since: proto.Int64(4444),
		}

		evacuatingLRP2 = actualLRP2
		evacuatingLRP2.State = proto.String(models.ActualLRPStateRunning)
		evacuatingLRP2.Since = proto.Int64(3417)
	})

	// old before each
	BeforeEach(func() {
		oldActualLRP1 = oldmodels.ActualLRP{
			ActualLRPKey: oldmodels.NewActualLRPKey(
				"process-guid-0",
				1,
				"domain-0",
			),
			ActualLRPInstanceKey: oldmodels.NewActualLRPInstanceKey(
				"instance-guid-0",
				"cell-id-0",
			),
			State: oldmodels.ActualLRPStateRunning,
開發者ID:se77en,項目名稱:lattice,代碼行數:31,代碼來源:actual_lrp_handlers_test.go

示例5:

		BeforeEach(func() {
			guid = "the-guid"
			index = 1
			ttl = 60
			actualLRP = model_helpers.NewValidActualLRP(guid, index)

			etcdHelper.SetRawEvacuatingActualLRP(actualLRP, ttl)

			node, err := storeClient.Get(etcd.EvacuatingActualLRPSchemaPath(guid, index), false, false)
			fakeStoreClient.GetReturns(node, err)
		})

		Context("when the something about the actual LRP has changed", func() {
			BeforeEach(func() {
				clock.IncrementBySeconds(5)
				actualLRP.Since = clock.Now().UnixNano()
			})

			Context("when the lrp key changes", func() {
				BeforeEach(func() {
					actualLRP.Domain = "some-other-domain"
				})

				It("persists the evacuating lrp in etcd", func() {
					group, err := etcdDB.EvacuateActualLRP(logger, &actualLRP.ActualLRPKey, &actualLRP.ActualLRPInstanceKey, &actualLRP.ActualLRPNetInfo, ttl)
					Expect(err).NotTo(HaveOccurred())

					actualLRP.ModificationTag.Increment()
					actualLRPGroup, err := etcdDB.ActualLRPGroupByProcessGuidAndIndex(logger, guid, index)
					Expect(err).NotTo(HaveOccurred())
					Expect(actualLRPGroup.Evacuating).To(BeEquivalentTo(actualLRP))
開發者ID:timani,項目名稱:bbs,代碼行數:31,代碼來源:evacuation_db_test.go

示例6:

				CellId:       "my-cell-id",
				InstanceGuid: "my-instance-guid",
			}
			actualLRP, startErr = client.StartActualLRP(&unclaimedLRPKey, &instanceKey, &netInfo)
		})

		It("starts the actual_lrp", func() {
			Expect(startErr).NotTo(HaveOccurred())

			expectedActualLRP := *unclaimedLRP
			expectedActualLRP.State = models.ActualLRPStateRunning
			expectedActualLRP.ActualLRPInstanceKey = instanceKey
			expectedActualLRP.ActualLRPNetInfo = netInfo
			expectedActualLRP.ModificationTag.Increment()
			expectedActualLRP.Since = 0
			actualLRP.Since = 0
			Expect(*actualLRP).To(Equal(expectedActualLRP))

			fetchedActualLRPGroup, err := client.ActualLRPGroupByProcessGuidAndIndex(unclaimedProcessGuid, unclaimedIndex)
			Expect(err).NotTo(HaveOccurred())

			fetchedActualLRP, evacuating := fetchedActualLRPGroup.Resolve()
			Expect(evacuating).To(BeFalse())
			fetchedActualLRP.Since = 0

			Expect(*fetchedActualLRP).To(Equal(expectedActualLRP))
		})
	})

	Describe("POST /v1/actual_lrps/fail", func() {
		var (
開發者ID:Gerg,項目名稱:bbs,代碼行數:31,代碼來源:actual_lrp_test.go


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