本文整理汇总了Golang中code/cloudfoundry/org/lager.Logger.WithData方法的典型用法代码示例。如果您正苦于以下问题:Golang Logger.WithData方法的具体用法?Golang Logger.WithData怎么用?Golang Logger.WithData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类code/cloudfoundry/org/lager.Logger
的用法示例。
在下文中一共展示了Logger.WithData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RemoveDesiredLRP
func (h *DesiredLRPHandler) RemoveDesiredLRP(logger lager.Logger, w http.ResponseWriter, req *http.Request) {
logger = logger.Session("remove-desired-lrp")
request := &models.RemoveDesiredLRPRequest{}
response := &models.DesiredLRPLifecycleResponse{}
defer func() { exitIfUnrecoverable(logger, h.exitChan, response.Error) }()
defer writeResponse(w, response)
err := parseRequest(logger, req, request)
if err != nil {
response.Error = models.ConvertError(err)
return
}
logger = logger.WithData(lager.Data{"process_guid": request.ProcessGuid})
desiredLRP, err := h.desiredLRPDB.DesiredLRPByProcessGuid(logger.Session("fetch-desired"), request.ProcessGuid)
if err != nil {
response.Error = models.ConvertError(err)
return
}
err = h.desiredLRPDB.RemoveDesiredLRP(logger.Session("remove-desired"), request.ProcessGuid)
if err != nil {
response.Error = models.ConvertError(err)
return
}
go h.desiredHub.Emit(models.NewDesiredLRPRemovedEvent(desiredLRP))
h.stopInstancesFrom(logger, request.ProcessGuid, 0)
}
示例2: ResolvingTask
// The stager calls this when it wants to claim a completed task. This ensures that only one
// stager ever attempts to handle a completed task
func (db *ETCDDB) ResolvingTask(logger lager.Logger, taskGuid string) error {
logger = logger.WithData(lager.Data{"task_guid": taskGuid})
logger.Info("starting")
defer logger.Info("finished")
task, index, err := db.taskByGuidWithIndex(logger, taskGuid)
if err != nil {
logger.Error("failed-getting-task", err)
return err
}
err = task.ValidateTransitionTo(models.Task_Resolving)
if err != nil {
logger.Error("invalid-state-transition", err)
return err
}
task.UpdatedAt = db.clock.Now().UnixNano()
task.State = models.Task_Resolving
value, err := db.serializeModel(logger, task)
if err != nil {
return err
}
_, err = db.client.CompareAndSwap(TaskSchemaPathByGuid(taskGuid), value, NO_TTL, index)
if err != nil {
return ErrorFromEtcdError(logger, err)
}
return nil
}
示例3: CompleteTask
// The cell calls this when it has finished running the task (be it success or failure)
// stagerTaskBBS will retry this repeatedly if it gets a StoreTimeout error (up to N seconds?)
// This really really shouldn't fail. If it does, blog about it and walk away. If it failed in a
// consistent way (i.e. key already exists), there's probably a flaw in our design.
func (db *ETCDDB) CompleteTask(logger lager.Logger, taskGuid, cellId string, failed bool, failureReason, result string) (*models.Task, error) {
logger = logger.WithData(lager.Data{"task_guid": taskGuid, "cell_id": cellId})
logger.Info("starting")
defer logger.Info("finished")
task, index, err := db.taskByGuidWithIndex(logger, taskGuid)
if err != nil {
logger.Error("failed-getting-task", err)
return nil, err
}
if task.State == models.Task_Running && task.CellId != cellId {
err = models.NewRunningOnDifferentCellError(cellId, task.CellId)
logger.Error("invalid-cell-id", err)
return nil, err
}
if err = task.ValidateTransitionTo(models.Task_Completed); err != nil {
logger.Error("invalid-state-transition", err)
return nil, err
}
return task, db.completeTask(logger, task, index, failed, failureReason, result)
}
示例4: FailActualLRP
func (db *ETCDDB) FailActualLRP(logger lager.Logger, key *models.ActualLRPKey, errorMessage string) (*models.ActualLRPGroup, *models.ActualLRPGroup, error) {
logger = logger.WithData(lager.Data{"actual_lrp_key": key, "error_message": errorMessage})
logger.Info("starting")
lrp, prevIndex, err := db.rawActualLRPByProcessGuidAndIndex(logger, key.ProcessGuid, key.Index)
if err != nil {
logger.Error("failed-to-get-actual-lrp", err)
return nil, nil, err
}
beforeActualLRP := *lrp
if lrp.State != models.ActualLRPStateUnclaimed {
return nil, nil, models.ErrActualLRPCannotBeFailed
}
lrp.ModificationTag.Increment()
lrp.PlacementError = errorMessage
lrp.Since = db.clock.Now().UnixNano()
lrpData, serialErr := db.serializeModel(logger, lrp)
if serialErr != nil {
return nil, nil, serialErr
}
_, err = db.client.CompareAndSwap(ActualLRPSchemaPath(key.ProcessGuid, key.Index), lrpData, 0, prevIndex)
if err != nil {
logger.Error("failed", err)
return nil, nil, models.ErrActualLRPCannotBeFailed
}
logger.Info("succeeded")
return &models.ActualLRPGroup{Instance: &beforeActualLRP}, &models.ActualLRPGroup{Instance: lrp}, nil
}
示例5: DesireTask
func (db *ETCDDB) DesireTask(logger lager.Logger, taskDef *models.TaskDefinition, taskGuid, domain string) error {
logger = logger.WithData(lager.Data{"task_guid": taskGuid})
logger.Info("starting")
defer logger.Info("finished")
now := db.clock.Now().UnixNano()
task := &models.Task{
TaskDefinition: taskDef,
TaskGuid: taskGuid,
Domain: domain,
State: models.Task_Pending,
CreatedAt: now,
UpdatedAt: now,
}
value, err := db.serializeModel(logger, task)
if err != nil {
return err
}
logger.Debug("persisting-task")
_, err = db.client.Create(TaskSchemaPathByGuid(task.TaskGuid), value, NO_TTL)
if err != nil {
return ErrorFromEtcdError(logger, err)
}
logger.Debug("succeeded-persisting-task")
return nil
}
示例6: HandleCompletedTask
func HandleCompletedTask(logger lager.Logger, httpClient *http.Client, taskDB db.TaskDB, task *models.Task) {
logger = logger.Session("handle-completed-task", lager.Data{"task_guid": task.TaskGuid})
if task.CompletionCallbackUrl != "" {
modelErr := taskDB.ResolvingTask(logger, task.TaskGuid)
if modelErr != nil {
logger.Error("marking-task-as-resolving-failed", modelErr)
return
}
logger = logger.WithData(lager.Data{"callback_url": task.CompletionCallbackUrl})
json, err := json.Marshal(&models.TaskCallbackResponse{
TaskGuid: task.TaskGuid,
Failed: task.Failed,
FailureReason: task.FailureReason,
Result: task.Result,
Annotation: task.Annotation,
CreatedAt: task.CreatedAt,
})
if err != nil {
logger.Error("marshalling-task-failed", err)
return
}
var statusCode int
for i := 0; i < MAX_CB_RETRIES; i++ {
request, err := http.NewRequest("POST", task.CompletionCallbackUrl, bytes.NewReader(json))
if err != nil {
logger.Error("building-request-failed", err)
return
}
request.Header.Set("Content-Type", "application/json")
response, err := httpClient.Do(request)
if err != nil {
matched, _ := regexp.MatchString("Client.Timeout|use of closed network connection", err.Error())
if matched {
continue
}
logger.Error("doing-request-failed", err)
return
}
defer response.Body.Close()
statusCode = response.StatusCode
if shouldResolve(statusCode) {
modelErr := taskDB.DeleteTask(logger, task.TaskGuid)
if modelErr != nil {
logger.Error("delete-task-failed", modelErr)
}
return
}
}
logger.Info("callback-failed", lager.Data{"status_code": statusCode})
}
return
}
示例7: RemoveDesiredLRP
// RemoveDesiredLRP deletes the DesiredLRPSchedulingInfo and the DesiredLRPRunInfo
// from the database. We delete DesiredLRPSchedulingInfo first because the system
// uses it to determine wheter the lrp is present. In the event that only the
// RunInfo fails to delete, the orphaned DesiredLRPRunInfo will be garbage
// collected later by convergence.
func (db *ETCDDB) RemoveDesiredLRP(logger lager.Logger, processGuid string) error {
logger = logger.WithData(lager.Data{"process_guid": processGuid})
logger.Info("starting")
defer logger.Info("complete")
_, schedulingInfoErr := db.client.Delete(DesiredLRPSchedulingInfoSchemaPath(processGuid), true)
schedulingInfoErr = ErrorFromEtcdError(logger, schedulingInfoErr)
if schedulingInfoErr != nil && schedulingInfoErr != models.ErrResourceNotFound {
logger.Error("failed-deleting-scheduling-info", schedulingInfoErr)
return schedulingInfoErr
}
_, runInfoErr := db.client.Delete(DesiredLRPRunInfoSchemaPath(processGuid), true)
runInfoErr = ErrorFromEtcdError(logger, runInfoErr)
if runInfoErr != nil && runInfoErr != models.ErrResourceNotFound {
logger.Error("failed-deleting-run-info", runInfoErr)
return runInfoErr
}
if schedulingInfoErr == models.ErrResourceNotFound && runInfoErr == models.ErrResourceNotFound {
// If neither component of the desired LRP exists, don't bother trying to delete running instances
return models.ErrResourceNotFound
}
return nil
}
示例8: CancelTask
// The cell calls this when the user requested to cancel the task
// stagerTaskBBS will retry this repeatedly if it gets a StoreTimeout error (up to N seconds?)
// Will fail if the task has already been cancelled or completed normally
func (db *ETCDDB) CancelTask(logger lager.Logger, taskGuid string) (*models.Task, string, error) {
logger = logger.WithData(lager.Data{"task_guid": taskGuid})
logger.Info("starting")
defer logger.Info("finished")
task, index, err := db.taskByGuidWithIndex(logger, taskGuid)
if err != nil {
logger.Error("failed-to-fetch-task", err)
return nil, "", err
}
if err = task.ValidateTransitionTo(models.Task_Completed); err != nil {
if task.State != models.Task_Pending {
logger.Error("invalid-state-transition", err)
return nil, "", err
}
}
logger.Info("completing-task")
cellID := task.CellId
err = db.completeTask(logger, task, index, true, "task was cancelled", "")
if err != nil {
logger.Error("failed-completing-task", err)
return nil, "", err
}
logger.Info("succeeded-completing-task")
return task, cellID, nil
}
示例9: ActualLRPGroupsByProcessGuid
func (db *SQLDB) ActualLRPGroupsByProcessGuid(logger lager.Logger, processGuid string) ([]*models.ActualLRPGroup, error) {
logger = logger.WithData(lager.Data{"process_guid": processGuid})
logger.Debug("starting")
defer logger.Debug("complete")
return db.getActualLRPS(logger, "process_guid = ?", processGuid)
}
示例10: 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
}
示例11: StartActualLRP
func (db *ETCDDB) 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,
})
lrp, prevIndex, err := db.rawActualLRPByProcessGuidAndIndex(logger, key.ProcessGuid, key.Index)
bbsErr := models.ConvertError(err)
if bbsErr != nil {
if bbsErr.Type == models.Error_ResourceNotFound {
lrp, err := db.createRunningActualLRP(logger, key, instanceKey, netInfo)
return nil, &models.ActualLRPGroup{Instance: lrp}, err
}
logger.Error("failed-to-get-actual-lrp", err)
return nil, nil, err
}
beforeActualLRP := *lrp
if lrp.ActualLRPKey.Equal(key) &&
lrp.ActualLRPInstanceKey.Equal(instanceKey) &&
lrp.ActualLRPNetInfo.Equal(netInfo) &&
lrp.State == models.ActualLRPStateRunning {
lrpGroup := &models.ActualLRPGroup{Instance: lrp}
return lrpGroup, lrpGroup, nil
}
if !lrp.AllowsTransitionTo(key, instanceKey, models.ActualLRPStateRunning) {
logger.Error("failed-to-transition-actual-lrp-to-started", nil)
return nil, nil, models.ErrActualLRPCannotBeStarted
}
logger.Info("starting")
defer logger.Info("completed")
lrp.ModificationTag.Increment()
lrp.State = models.ActualLRPStateRunning
lrp.Since = db.clock.Now().UnixNano()
lrp.ActualLRPInstanceKey = *instanceKey
lrp.ActualLRPNetInfo = *netInfo
lrp.PlacementError = ""
lrpData, serializeErr := db.serializeModel(logger, lrp)
if serializeErr != nil {
return nil, nil, serializeErr
}
_, err = db.client.CompareAndSwap(ActualLRPSchemaPath(key.ProcessGuid, key.Index), lrpData, 0, prevIndex)
if err != nil {
logger.Error("failed", err)
return nil, nil, models.ErrActualLRPCannotBeStarted
}
return &models.ActualLRPGroup{Instance: &beforeActualLRP}, &models.ActualLRPGroup{Instance: lrp}, nil
}
示例12: 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
}
示例13: CrashActualLRP
func (db *ETCDDB) CrashActualLRP(logger lager.Logger, key *models.ActualLRPKey, instanceKey *models.ActualLRPInstanceKey, errorMessage string) (*models.ActualLRPGroup, *models.ActualLRPGroup, bool, error) {
logger = logger.WithData(lager.Data{"actual_lrp_key": key, "actual_lrp_instance_key": instanceKey})
logger.Info("starting")
lrp, prevIndex, err := db.rawActualLRPByProcessGuidAndIndex(logger, key.ProcessGuid, key.Index)
if err != nil {
logger.Error("failed-to-get-actual-lrp", err)
return nil, nil, false, err
}
beforeActualLRP := *lrp
latestChangeTime := time.Duration(db.clock.Now().UnixNano() - lrp.Since)
var newCrashCount int32
if latestChangeTime > models.CrashResetTimeout && lrp.State == models.ActualLRPStateRunning {
newCrashCount = 1
} else {
newCrashCount = lrp.CrashCount + 1
}
logger.Debug("retrieved-lrp")
if !lrp.AllowsTransitionTo(key, instanceKey, models.ActualLRPStateCrashed) {
logger.Error("failed-to-transition-to-crashed", nil, lager.Data{"from_state": lrp.State, "same_instance_key": lrp.ActualLRPInstanceKey.Equal(instanceKey)})
return nil, nil, false, models.ErrActualLRPCannotBeCrashed
}
lrp.State = models.ActualLRPStateCrashed
lrp.Since = db.clock.Now().UnixNano()
lrp.CrashCount = newCrashCount
lrp.ActualLRPInstanceKey = models.ActualLRPInstanceKey{}
lrp.ActualLRPNetInfo = models.EmptyActualLRPNetInfo()
lrp.ModificationTag.Increment()
lrp.CrashReason = errorMessage
var immediateRestart bool
if lrp.ShouldRestartImmediately(models.NewDefaultRestartCalculator()) {
lrp.State = models.ActualLRPStateUnclaimed
immediateRestart = true
}
lrpData, serializeErr := db.serializeModel(logger, lrp)
if serializeErr != nil {
return nil, nil, false, serializeErr
}
_, err = db.client.CompareAndSwap(ActualLRPSchemaPath(key.ProcessGuid, key.Index), lrpData, 0, prevIndex)
if err != nil {
logger.Error("failed", err)
return nil, nil, false, models.ErrActualLRPCannotBeCrashed
}
logger.Info("succeeded")
return &models.ActualLRPGroup{Instance: &beforeActualLRP}, &models.ActualLRPGroup{Instance: lrp}, immediateRestart, nil
}
示例14: DesiredLRPs
func (db *ETCDDB) DesiredLRPs(logger lager.Logger, filter models.DesiredLRPFilter) ([]*models.DesiredLRP, error) {
logger = logger.WithData(lager.Data{"filter": filter})
logger.Info("start")
defer logger.Info("complete")
desireds, _, err := db.desiredLRPs(logger, filter)
if err != nil {
logger.Error("failed", err)
}
return desireds, err
}
示例15: DesiredLRPByProcessGuid
func (db *SQLDB) DesiredLRPByProcessGuid(logger lager.Logger, processGuid string) (*models.DesiredLRP, error) {
logger = logger.WithData(lager.Data{"process_guid": processGuid})
logger.Debug("starting")
defer logger.Debug("complete")
row := db.one(logger, db.db, desiredLRPsTable,
desiredLRPColumns, NoLockRow,
"process_guid = ?", processGuid,
)
return db.fetchDesiredLRP(logger, row)
}