本文整理匯總了Golang中code/cloudfoundry/org/bbs/models.ActualLRP類的典型用法代碼示例。如果您正苦於以下問題:Golang ActualLRP類的具體用法?Golang ActualLRP怎麽用?Golang ActualLRP使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ActualLRP類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SetRawEvacuatingActualLRP
func (t *ETCDHelper) SetRawEvacuatingActualLRP(lrp *models.ActualLRP, ttlInSeconds uint64) {
value, err := t.serializer.Marshal(t.logger, t.format, lrp)
Expect(err).NotTo(HaveOccurred())
key := etcddb.EvacuatingActualLRPSchemaPath(lrp.GetProcessGuid(), lrp.GetIndex())
_, err = t.client.Set(key, value, ttlInSeconds)
Expect(err).NotTo(HaveOccurred())
}
示例2: UnclaimActualLRP
func (db *SQLDB) UnclaimActualLRP(logger lager.Logger, key *models.ActualLRPKey) (*models.ActualLRPGroup, *models.ActualLRPGroup, error) {
logger = logger.WithData(lager.Data{"key": key})
var beforeActualLRP models.ActualLRP
var actualLRP *models.ActualLRP
processGuid := key.ProcessGuid
index := key.Index
err := db.transact(logger, func(logger lager.Logger, tx *sql.Tx) error {
var err error
actualLRP, err = db.fetchActualLRPForUpdate(logger, processGuid, index, false, tx)
if err != nil {
logger.Error("failed-fetching-actual-lrp-for-share", err)
return err
}
beforeActualLRP = *actualLRP
if actualLRP.State == models.ActualLRPStateUnclaimed {
logger.Debug("already-unclaimed")
return models.ErrActualLRPCannotBeUnclaimed
}
logger.Info("starting")
defer logger.Info("complete")
now := db.clock.Now().UnixNano()
actualLRP.ModificationTag.Increment()
actualLRP.State = models.ActualLRPStateUnclaimed
actualLRP.ActualLRPInstanceKey.CellId = ""
actualLRP.ActualLRPInstanceKey.InstanceGuid = ""
actualLRP.Since = now
actualLRP.ActualLRPNetInfo = models.ActualLRPNetInfo{}
_, err = db.update(logger, tx, actualLRPsTable,
SQLAttributes{
"state": actualLRP.State,
"cell_id": actualLRP.CellId,
"instance_guid": actualLRP.InstanceGuid,
"modification_tag_index": actualLRP.ModificationTag.Index,
"since": actualLRP.Since,
"net_info": []byte{},
},
"process_guid = ? AND instance_index = ? AND evacuating = ?",
processGuid, index, false,
)
if err != nil {
logger.Error("failed-to-unclaim-actual-lrp", err)
return db.convertSQLError(err)
}
return nil
})
return &models.ActualLRPGroup{Instance: &beforeActualLRP}, &models.ActualLRPGroup{Instance: actualLRP}, err
}
示例3: FailActualLRP
func (db *SQLDB) FailActualLRP(logger lager.Logger, key *models.ActualLRPKey, placementError string) (*models.ActualLRPGroup, *models.ActualLRPGroup, error) {
logger = logger.WithData(lager.Data{"actual_lrp_key": key, "placement_error": placementError})
logger.Info("starting")
defer logger.Info("complete")
var beforeActualLRP models.ActualLRP
var actualLRP *models.ActualLRP
err := db.transact(logger, func(logger lager.Logger, tx *sql.Tx) error {
var err error
actualLRP, err = db.fetchActualLRPForUpdate(logger, key.ProcessGuid, key.Index, false, tx)
if err != nil {
logger.Error("failed-to-get-actual-lrp", err)
return err
}
beforeActualLRP = *actualLRP
if actualLRP.State != models.ActualLRPStateUnclaimed {
logger.Error("cannot-fail-actual-lrp", nil, lager.Data{"from_state": actualLRP.State})
return models.ErrActualLRPCannotBeFailed
}
now := db.clock.Now().UnixNano()
actualLRP.ModificationTag.Increment()
actualLRP.PlacementError = placementError
actualLRP.Since = now
evacuating := false
_, err = db.update(logger, tx, actualLRPsTable,
SQLAttributes{
"modification_tag_index": actualLRP.ModificationTag.Index,
"placement_error": truncateString(actualLRP.PlacementError, 1024),
"since": actualLRP.Since,
},
"process_guid = ? AND instance_index = ? AND evacuating = ?",
key.ProcessGuid, key.Index, evacuating,
)
if err != nil {
logger.Error("failed-failing-actual-lrp", err)
return db.convertSQLError(err)
}
return nil
})
return &models.ActualLRPGroup{Instance: &beforeActualLRP}, &models.ActualLRPGroup{Instance: actualLRP}, err
}
示例4: ClaimActualLRP
func (db *SQLDB) ClaimActualLRP(logger lager.Logger, processGuid string, index int32, instanceKey *models.ActualLRPInstanceKey) (*models.ActualLRPGroup, *models.ActualLRPGroup, error) {
logger = logger.WithData(lager.Data{"process_guid": processGuid, "index": index, "instance_key": instanceKey})
logger.Info("starting")
defer logger.Info("complete")
var beforeActualLRP models.ActualLRP
var actualLRP *models.ActualLRP
err := db.transact(logger, func(logger lager.Logger, tx *sql.Tx) error {
var err error
actualLRP, err = db.fetchActualLRPForUpdate(logger, processGuid, index, false, tx)
if err != nil {
logger.Error("failed-fetching-actual-lrp-for-share", err)
return err
}
beforeActualLRP = *actualLRP
if !actualLRP.AllowsTransitionTo(&actualLRP.ActualLRPKey, instanceKey, models.ActualLRPStateClaimed) {
logger.Error("cannot-transition-to-claimed", nil, lager.Data{"from_state": actualLRP.State, "same_instance_key": actualLRP.ActualLRPInstanceKey.Equal(instanceKey)})
return models.ErrActualLRPCannotBeClaimed
}
if actualLRP.State == models.ActualLRPStateClaimed && actualLRP.ActualLRPInstanceKey.Equal(instanceKey) {
return nil
}
actualLRP.ModificationTag.Increment()
actualLRP.State = models.ActualLRPStateClaimed
actualLRP.ActualLRPInstanceKey = *instanceKey
actualLRP.PlacementError = ""
actualLRP.ActualLRPNetInfo = models.ActualLRPNetInfo{}
actualLRP.Since = db.clock.Now().UnixNano()
_, err = db.update(logger, tx, actualLRPsTable,
SQLAttributes{
"state": actualLRP.State,
"cell_id": actualLRP.CellId,
"instance_guid": actualLRP.InstanceGuid,
"modification_tag_index": actualLRP.ModificationTag.Index,
"placement_error": actualLRP.PlacementError,
"since": actualLRP.Since,
"net_info": []byte{},
},
"process_guid = ? AND instance_index = ? AND evacuating = ?",
processGuid, index, false,
)
if err != nil {
logger.Error("failed-claiming-actual-lrp", err)
return db.convertSQLError(err)
}
return nil
})
return &models.ActualLRPGroup{Instance: &beforeActualLRP}, &models.ActualLRPGroup{Instance: actualLRP}, err
}
示例5: lrpForState
func lrpForState(state string, timeInState time.Duration) models.ActualLRP {
var actualLRPKey = models.NewActualLRPKey("some-process-guid", 1, "tests")
var instanceKey = models.NewActualLRPInstanceKey("some-instance-guid", "some-cell")
lrp := models.ActualLRP{
ActualLRPKey: actualLRPKey,
State: state,
Since: clock.Now().Add(-timeInState).UnixNano(),
}
switch state {
case models.ActualLRPStateUnclaimed:
case models.ActualLRPStateCrashed:
lrp.CrashReason = "crashed"
case models.ActualLRPStateClaimed:
lrp.ActualLRPInstanceKey = instanceKey
case models.ActualLRPStateRunning:
lrp.ActualLRPInstanceKey = instanceKey
lrp.ActualLRPNetInfo = models.NewActualLRPNetInfo("1.2.3.4", &models.PortMapping{ContainerPort: 1234, HostPort: 5678})
}
return lrp
}
示例6: 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 logger.Debug("complete", lager.Data{"state_change": 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
}
示例7: itValidatesPresenceOfPlacementError
func itValidatesPresenceOfPlacementError(lrp *models.ActualLRP) {
Context("when placement error is set", func() {
BeforeEach(func() {
lrp.PlacementError = "insufficient capacity"
})
It("validate does not return an error", func() {
Expect(lrp.Validate()).NotTo(HaveOccurred())
})
})
Context("when placement error is not set", func() {
BeforeEach(func() {
lrp.PlacementError = ""
})
It("validate does not return an error", func() {
Expect(lrp.Validate()).NotTo(HaveOccurred())
})
})
}
示例8: itValidatesAbsenceOfPlacementError
func itValidatesAbsenceOfPlacementError(lrp *models.ActualLRP) {
Context("when placement error is set", func() {
BeforeEach(func() {
lrp.PlacementError = "insufficient capacity"
})
It("validate returns an error", func() {
err := lrp.Validate()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("placement error"))
})
})
Context("when placement error is not set", func() {
BeforeEach(func() {
lrp.PlacementError = ""
})
It("validate does not return an error", func() {
Expect(lrp.Validate()).NotTo(HaveOccurred())
})
})
}
示例9: itValidatesAbsenceOfNetInfo
func itValidatesAbsenceOfNetInfo(lrp *models.ActualLRP) {
Context("when net info is set", func() {
BeforeEach(func() {
lrp.ActualLRPNetInfo = models.NewActualLRPNetInfo("1.2.3.4")
})
It("validate returns an error", func() {
err := lrp.Validate()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("net info"))
})
})
Context("when net info is not set", func() {
BeforeEach(func() {
lrp.ActualLRPNetInfo = models.ActualLRPNetInfo{}
})
It("validate does not return an error", func() {
Expect(lrp.Validate()).NotTo(HaveOccurred())
})
})
}
示例10: itValidatesAbsenceOfTheInstanceKey
func itValidatesAbsenceOfTheInstanceKey(lrp *models.ActualLRP) {
Context("when the instance key is set", func() {
BeforeEach(func() {
lrp.ActualLRPInstanceKey = models.NewActualLRPInstanceKey("some-instance", "some-cell")
})
It("validate returns an error", func() {
err := lrp.Validate()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("instance key"))
})
})
Context("when the instance key is not set", func() {
BeforeEach(func() {
lrp.ActualLRPInstanceKey = models.ActualLRPInstanceKey{}
})
It("validate does not return an error", func() {
Expect(lrp.Validate()).NotTo(HaveOccurred())
})
})
}
示例11: itValidatesPresenceOfTheLRPKey
func itValidatesPresenceOfTheLRPKey(lrp *models.ActualLRP) {
Context("when the lrp key is set", func() {
BeforeEach(func() {
lrp.ActualLRPKey = models.NewActualLRPKey("some-guid", 1, "domain")
})
It("validate does not return an error", func() {
Expect(lrp.Validate()).NotTo(HaveOccurred())
})
})
Context("when the lrp key is not set", func() {
BeforeEach(func() {
lrp.ActualLRPKey = models.ActualLRPKey{}
})
It("validate returns an error", func() {
err := lrp.Validate()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("process_guid"))
})
})
}
示例12:
"code.cloudfoundry.org/bbs/db/dbfakes"
"code.cloudfoundry.org/bbs/handlers"
"code.cloudfoundry.org/bbs/models"
"code.cloudfoundry.org/lager/lagertest"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
)
var _ = Describe("ActualLRP Handlers", func() {
var (
logger *lagertest.TestLogger
fakeActualLRPDB *dbfakes.FakeActualLRPDB
responseRecorder *httptest.ResponseRecorder
handler *handlers.ActualLRPHandler
exitCh chan struct{}
actualLRP1 models.ActualLRP
actualLRP2 models.ActualLRP
evacuatingLRP2 models.ActualLRP
)
BeforeEach(func() {
fakeActualLRPDB = new(dbfakes.FakeActualLRPDB)
logger = lagertest.NewTestLogger("test")
responseRecorder = httptest.NewRecorder()
exitCh = make(chan struct{}, 1)
handler = handlers.NewActualLRPHandler(fakeActualLRPDB, exitCh)
})
Describe("ActualLRPGroups", func() {
示例13: CrashActualLRP
func (db *SQLDB) CrashActualLRP(logger lager.Logger, key *models.ActualLRPKey, instanceKey *models.ActualLRPInstanceKey, crashReason string) (*models.ActualLRPGroup, *models.ActualLRPGroup, bool, error) {
logger = logger.WithData(lager.Data{"key": key, "instance_key": instanceKey, "crash_reason": crashReason})
logger.Info("starting")
defer logger.Info("complete")
var immediateRestart = false
var beforeActualLRP models.ActualLRP
var actualLRP *models.ActualLRP
err := db.transact(logger, func(logger lager.Logger, tx *sql.Tx) error {
var err error
actualLRP, err = db.fetchActualLRPForUpdate(logger, key.ProcessGuid, key.Index, false, tx)
if err != nil {
logger.Error("failed-to-get-actual-lrp", err)
return err
}
beforeActualLRP = *actualLRP
latestChangeTime := time.Duration(db.clock.Now().UnixNano() - actualLRP.Since)
var newCrashCount int32
if latestChangeTime > models.CrashResetTimeout && actualLRP.State == models.ActualLRPStateRunning {
newCrashCount = 1
} else {
newCrashCount = actualLRP.CrashCount + 1
}
if !actualLRP.AllowsTransitionTo(&actualLRP.ActualLRPKey, instanceKey, models.ActualLRPStateCrashed) {
logger.Error("failed-to-transition-to-crashed", nil, lager.Data{"from_state": actualLRP.State, "same_instance_key": actualLRP.ActualLRPInstanceKey.Equal(instanceKey)})
return models.ErrActualLRPCannotBeCrashed
}
actualLRP.ModificationTag.Increment()
actualLRP.State = models.ActualLRPStateCrashed
actualLRP.ActualLRPInstanceKey.InstanceGuid = ""
actualLRP.ActualLRPInstanceKey.CellId = ""
actualLRP.ActualLRPNetInfo = models.ActualLRPNetInfo{}
actualLRP.CrashCount = newCrashCount
actualLRP.CrashReason = crashReason
evacuating := false
if actualLRP.ShouldRestartImmediately(models.NewDefaultRestartCalculator()) {
actualLRP.State = models.ActualLRPStateUnclaimed
immediateRestart = true
}
now := db.clock.Now().UnixNano()
actualLRP.Since = now
_, err = db.update(logger, tx, actualLRPsTable,
SQLAttributes{
"state": actualLRP.State,
"cell_id": actualLRP.CellId,
"instance_guid": actualLRP.InstanceGuid,
"modification_tag_index": actualLRP.ModificationTag.Index,
"crash_count": actualLRP.CrashCount,
"crash_reason": truncateString(actualLRP.CrashReason, 1024),
"since": actualLRP.Since,
"net_info": []byte{},
},
"process_guid = ? AND instance_index = ? AND evacuating = ?",
key.ProcessGuid, key.Index, evacuating,
)
if err != nil {
logger.Error("failed-to-crash-actual-lrp", err)
return db.convertSQLError(err)
}
return nil
})
return &models.ActualLRPGroup{Instance: &beforeActualLRP}, &models.ActualLRPGroup{Instance: actualLRP}, immediateRestart, err
}
示例14: StartActualLRP
func (db *SQLDB) StartActualLRP(logger lager.Logger, key *models.ActualLRPKey, instanceKey *models.ActualLRPInstanceKey, netInfo *models.ActualLRPNetInfo) (*models.ActualLRPGroup, *models.ActualLRPGroup, error) {
logger = logger.WithData(lager.Data{"actual_lrp_key": key, "actual_lrp_instance_key": instanceKey, "net_info": netInfo})
var beforeActualLRP models.ActualLRP
var actualLRP *models.ActualLRP
err := db.transact(logger, func(logger lager.Logger, tx *sql.Tx) error {
var err error
actualLRP, err = db.fetchActualLRPForUpdate(logger, key.ProcessGuid, key.Index, false, tx)
if err == models.ErrResourceNotFound {
actualLRP, err = db.createRunningActualLRP(logger, key, instanceKey, netInfo, tx)
return err
}
if err != nil {
logger.Error("failed-to-get-actual-lrp", err)
return err
}
beforeActualLRP = *actualLRP
if actualLRP.ActualLRPKey.Equal(key) &&
actualLRP.ActualLRPInstanceKey.Equal(instanceKey) &&
actualLRP.ActualLRPNetInfo.Equal(netInfo) &&
actualLRP.State == models.ActualLRPStateRunning {
logger.Debug("nothing-to-change")
return nil
}
if !actualLRP.AllowsTransitionTo(key, instanceKey, models.ActualLRPStateRunning) {
logger.Error("failed-to-transition-actual-lrp-to-started", nil)
return models.ErrActualLRPCannotBeStarted
}
logger.Info("starting")
defer logger.Info("completed")
now := db.clock.Now().UnixNano()
evacuating := false
actualLRP.ActualLRPInstanceKey = *instanceKey
actualLRP.ActualLRPNetInfo = *netInfo
actualLRP.State = models.ActualLRPStateRunning
actualLRP.Since = now
actualLRP.ModificationTag.Increment()
actualLRP.PlacementError = ""
netInfoData, err := db.serializeModel(logger, &actualLRP.ActualLRPNetInfo)
if err != nil {
logger.Error("failed-to-serialize-net-info", err)
return err
}
_, err = db.update(logger, tx, actualLRPsTable,
SQLAttributes{
"state": actualLRP.State,
"cell_id": actualLRP.CellId,
"instance_guid": actualLRP.InstanceGuid,
"modification_tag_index": actualLRP.ModificationTag.Index,
"placement_error": actualLRP.PlacementError,
"since": actualLRP.Since,
"net_info": netInfoData,
},
"process_guid = ? AND instance_index = ? AND evacuating = ?",
key.ProcessGuid, key.Index, evacuating,
)
if err != nil {
logger.Error("failed-starting-actual-lrp", err)
return db.convertSQLError(err)
}
return nil
})
return &models.ActualLRPGroup{Instance: &beforeActualLRP}, &models.ActualLRPGroup{Instance: actualLRP}, err
}
示例15:
var response models.RemoveEvacuatingActualLRPResponse
err := response.Unmarshal(responseRecorder.Body.Bytes())
Expect(err).NotTo(HaveOccurred())
Expect(response.Error).NotTo(BeNil())
Expect(response.Error).To(Equal(models.ErrResourceNotFound))
})
})
})
Describe("EvacuateClaimedActualLRP", func() {
var (
request *http.Request
requestBody *models.EvacuateClaimedActualLRPRequest
actual *models.ActualLRP
afterActual *models.ActualLRP
desiredLRP *models.DesiredLRP
)
BeforeEach(func() {
desiredLRP = model_helpers.NewValidDesiredLRP("the-guid")
fakeDesiredLRPDB.DesiredLRPByProcessGuidReturns(desiredLRP, nil)
actual = model_helpers.NewValidActualLRP("process-guid", 1)
requestBody = &models.EvacuateClaimedActualLRPRequest{
ActualLrpKey: &actual.ActualLRPKey,
ActualLrpInstanceKey: &actual.ActualLRPInstanceKey,
}
afterActual = model_helpers.NewValidActualLRP("process-guid", 1)
afterActual.State = models.ActualLRPStateUnclaimed