本文整理汇总了Golang中github.com/coreos/fleet/third_party/github.com/golang/glog.Errorf函数的典型用法代码示例。如果您正苦于以下问题:Golang Errorf函数的具体用法?Golang Errorf怎么用?Golang Errorf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Errorf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ResolveJobOffer
func (self *Engine) ResolveJobOffer(jobName string, machBootId string) error {
log.V(2).Infof("Attempting to lock JobOffer(%s)", jobName)
mutex := self.lockJobOffer(jobName)
if mutex == nil {
log.V(2).Infof("Could not lock JobOffer(%s)", jobName)
return errors.New("Could not lock JobOffer")
}
defer mutex.Unlock()
log.V(2).Infof("Claimed JobOffer(%s)", jobName)
log.V(2).Infof("Resolving JobOffer(%s), scheduling to Machine(%s)", jobName, machBootId)
err := self.registry.ResolveJobOffer(jobName)
if err != nil {
log.Errorf("Failed resolving JobOffer(%s): %v", jobName, err)
return err
}
err = self.registry.ScheduleJob(jobName, machBootId)
if err != nil {
log.Errorf("Failed scheduling Job(%s): %v", jobName, err)
return err
}
log.Infof("Scheduled Job(%s) to Machine(%s)", jobName, machBootId)
return nil
}
示例2: ResolveJobOffer
func (e *Engine) ResolveJobOffer(jobName string, machID string) error {
log.V(1).Infof("Attempting to lock JobOffer(%s)", jobName)
mutex := e.registry.LockJobOffer(jobName, e.machine.State().ID)
if mutex == nil {
log.V(1).Infof("Could not lock JobOffer(%s)", jobName)
return errors.New("Could not lock JobOffer")
}
defer mutex.Unlock()
log.V(1).Infof("Claimed JobOffer(%s)", jobName)
err := e.registry.ResolveJobOffer(jobName)
if err != nil {
log.Errorf("Failed resolving JobOffer(%s): %v", jobName, err)
return err
}
err = e.registry.ScheduleJob(jobName, machID)
if err != nil {
log.Errorf("Failed scheduling Job(%s): %v", jobName, err)
return err
}
log.Infof("Scheduled Job(%s) to Machine(%s)", jobName, machID)
return nil
}
示例3: UpdateLoggingFlagsFromConfig
func UpdateLoggingFlagsFromConfig(conf *Config) {
err := flag.Lookup("v").Value.Set(strconv.Itoa(conf.Verbosity))
if err != nil {
glog.Errorf("Failed to apply config.Verbosity to flag.v: %v", err)
}
err = flag.Lookup("logtostderr").Value.Set("true")
if err != nil {
glog.Errorf("Failed to set flag.logtostderr to true: %v", err)
}
}
示例4: HandleEventJobScheduled
func (eh *EventHandler) HandleEventJobScheduled(ev event.Event) {
jobName := ev.Payload.(string)
target := ev.Context.(string)
eh.agent.state.Lock()
defer eh.agent.state.Unlock()
log.V(1).Infof("EventJobScheduled(%s): Dropping outstanding offers and bids", jobName)
eh.agent.state.PurgeOffer(jobName)
if target != eh.agent.Machine().State().ID {
log.Infof("EventJobScheduled(%s): Job not scheduled to this Agent, purging related data from cache", jobName)
eh.agent.state.PurgeJob(jobName)
log.Infof("EventJobScheduled(%s): Checking outstanding job offers", jobName)
eh.agent.BidForPossibleJobs()
return
}
log.Infof("EventJobScheduled(%s): Job scheduled to this Agent", jobName)
j := eh.agent.FetchJob(jobName)
if j == nil {
log.Errorf("EventJobScheduled(%s): Failed to fetch Job", jobName)
return
}
if !eh.agent.VerifyJob(j) {
log.Errorf("EventJobScheduled(%s): Failed to verify Job", j.Name)
return
}
if !eh.agent.AbleToRun(j) {
log.Infof("EventJobScheduled(%s): Unable to run scheduled Job, unscheduling.", jobName)
eh.agent.registry.ClearJobTarget(jobName, target)
eh.agent.state.PurgeJob(jobName)
return
}
log.Infof("EventJobScheduled(%s): Loading Job", j.Name)
eh.agent.LoadJob(j)
log.Infof("EventJobScheduled(%s): Bidding for all possible peers of Job", j.Name)
eh.agent.BidForPossiblePeers(j.Name)
ts := eh.agent.registry.GetJobTargetState(j.Name)
if ts == nil || *ts != job.JobStateLaunched {
return
}
log.Infof("EventJobScheduled(%s): Starting Job", j.Name)
eh.agent.StartJob(j.Name)
}
示例5: Heartbeat
// Periodically report to the Registry at an interval equal to
// half of the provided ttl. Stop reporting when the provided
// channel is closed. Failed attempts to report state to the
// Registry are retried twice before moving on to the next
// reporting interval.
func (a *Agent) Heartbeat(ttl time.Duration, stop chan bool) {
attempt := func(attempts int, f func() error) (err error) {
if attempts < 1 {
return fmt.Errorf("attempts argument must be 1 or greater, got %d", attempts)
}
// The amount of time the retry mechanism waits after a failed attempt
// doubles following each failure. This is a simple exponential backoff.
sleep := time.Second
for i := 1; i <= attempts; i++ {
err = f()
if err == nil || i == attempts {
break
}
sleep = sleep * 2
log.V(2).Infof("function returned err, retrying in %v: %v", sleep, err)
time.Sleep(sleep)
}
return err
}
heartbeat := func() error {
return a.registry.SetMachineState(a.machine.State(), ttl)
}
// Explicitly heartbeat immediately to push state to the
// Registry as quickly as possible
a.machine.RefreshState()
if err := attempt(3, heartbeat); err != nil {
log.Errorf("Failed heartbeat after 3 attempts: %v", err)
}
interval := ttl / refreshInterval
ticker := time.Tick(interval)
for {
select {
case <-stop:
log.V(2).Info("MachineHeartbeat exiting due to stop signal")
return
case <-ticker:
log.V(2).Info("MachineHeartbeat tick")
a.machine.RefreshState()
if err := attempt(3, heartbeat); err != nil {
log.Errorf("Failed heartbeat after 3 attempts: %v", err)
}
}
}
}
示例6: HandleEventJobScheduled
func (eh *EventHandler) HandleEventJobScheduled(ev event.Event) {
jobName := ev.Payload.(string)
log.V(1).Infof("EventJobScheduled(%s): Dropping outstanding offers and bids", jobName)
eh.agent.OfferResolved(jobName)
if ev.Context.(machine.MachineState).BootId != eh.agent.Machine().State().BootId {
log.V(1).Infof("EventJobScheduled(%s): Job not scheduled to this Agent, checking unbade offers", jobName)
eh.agent.BidForPossibleJobs()
return
}
log.V(1).Infof("EventJobScheduled(%s): Job scheduled to this Agent", jobName)
j := eh.agent.FetchJob(jobName)
if j == nil {
log.Errorf("EventJobScheduled(%s): Failed to fetch Job")
return
}
if !eh.agent.AbleToRun(j) {
log.V(1).Infof("EventJobScheduled(%s): Unable to run scheduled Job, rescheduling.", jobName)
eh.agent.RescheduleJob(j)
return
}
log.V(1).Infof("EventJobScheduled(%s): Starting Job", j.Name)
eh.agent.StartJob(j)
log.V(1).Infof("EventJobScheduled(%s): Bidding for all possible peers of Job", j.Name)
eh.agent.BidForPossiblePeers(j.Name)
}
示例7: OfferJob
func (e *Engine) OfferJob(j job.Job) error {
log.V(1).Infof("Attempting to lock Job(%s)", j.Name)
mutex := e.registry.LockJob(j.Name, e.machine.State().ID)
if mutex == nil {
log.V(1).Infof("Could not lock Job(%s)", j.Name)
return errors.New("Could not lock Job")
}
defer mutex.Unlock()
log.V(1).Infof("Claimed Job(%s)", j.Name)
machineIDs, err := e.partitionCluster(&j)
if err != nil {
log.Errorf("Failed partitioning cluster for Job(%s): %v", j.Name, err)
return err
}
offer := job.NewOfferFromJob(j, machineIDs)
err = e.registry.CreateJobOffer(offer)
if err == nil {
log.Infof("Published JobOffer(%s)", offer.Job.Name)
}
return err
}
示例8: Publish
// Publish is a long-running function that streams dbus events through
// a translation layer and on to the EventBus
func (m *SystemdManager) Publish(bus *event.EventBus, stopchan chan bool) {
m.Systemd.Subscribe()
changechan, errchan := m.subscriptions.Subscribe()
stream := NewEventStream()
stream.Stream(changechan, bus.Channel)
for true {
select {
case <-stopchan:
break
case err := <-errchan:
var errString string
if err != nil {
errString = err.Error()
} else {
errString = "N/A"
}
log.Errorf("Received error from dbus: err=%s", errString)
}
}
stream.Close()
m.Systemd.Unsubscribe()
}
示例9: JobScheduledLocally
// JobScheduledLocally clears all state related to the indicated
// job's offers/bids before attempting to load and possibly start
// the job. The ability to run the job will be revalidated before
// loading, and unscheduled if such validation fails.
func (a *Agent) JobScheduledLocally(jobName string) {
a.state.Lock()
defer a.state.Unlock()
log.Infof("Dropping offer and bid for Job(%s) from cache", jobName)
a.state.PurgeOffer(jobName)
j := a.fetchJob(jobName)
if j == nil {
log.Errorf("Failed to fetch Job(%s)", jobName)
return
}
if !a.ableToRun(j) {
log.Infof("Unable to run locally-scheduled Job(%s), unscheduling", jobName)
a.registry.ClearJobTarget(jobName, a.Machine.State().ID)
a.state.PurgeJob(jobName)
return
}
a.loadJob(j)
log.Infof("Bidding for all possible peers of Job(%s)", j.Name)
a.bidForPossiblePeers(j.Name)
ts, _ := a.registry.GetJobTargetState(j.Name)
if ts == nil || *ts != job.JobStateLaunched {
return
}
log.Infof("Job(%s) loaded, now starting it", j.Name)
a.startJobUnlocked(j.Name)
}
示例10: stopUnit
func (m *SystemdManager) stopUnit(name string) {
if stat, err := m.Systemd.StopUnit(name, "replace"); err != nil {
log.Errorf("Failed to stop systemd unit %s: %v", name, err)
} else {
log.Infof("Stopped systemd unit %s(%s)", name, stat)
}
}
示例11: GetAllPayloads
func (r *Registry) GetAllPayloads() []job.JobPayload {
var payloads []job.JobPayload
key := path.Join(keyPrefix, payloadPrefix)
resp, err := r.etcd.Get(key, true, true)
if err != nil {
return payloads
}
for _, node := range resp.Node.Nodes {
var jp job.JobPayload
//TODO: Handle the error generated by unmarshal
unmarshal(node.Value, &jp)
if err != nil {
log.Errorf(err.Error())
continue
}
payloads = append(payloads, jp)
}
return payloads
}
示例12: OfferJob
func (self *Engine) OfferJob(j job.Job) error {
log.V(2).Infof("Attempting to lock Job(%s)", j.Name)
mutex := self.lockJob(j.Name)
if mutex == nil {
log.V(1).Infof("Could not lock Job(%s)", j.Name)
return errors.New("Could not lock Job")
}
defer mutex.Unlock()
log.V(1).Infof("Claimed Job", j.Name)
machineBootIds, err := self.partitionCluster(&j)
if err != nil {
log.Errorf("Failed partitioning cluster for Job(%s): %v", j.Name, err)
return err
}
offer := job.NewOfferFromJob(j, machineBootIds)
log.V(2).Infof("Publishing JobOffer(%s)", offer.Job.Name)
self.registry.CreateJobOffer(offer)
log.Infof("Published JobOffer(%s)", offer.Job.Name)
return nil
}
示例13: Purge
// Purge removes the Agent's state from the Registry
func (a *Agent) Purge() {
// Continue heartbeating the agent's machine state while attempting to
// stop all the locally-running jobs
purged := make(chan bool)
go a.heartbeatAgent(a.ttl, purged)
a.state.Lock()
scheduled := a.state.ScheduledJobs()
a.state.Unlock()
machID := a.Machine.State().ID
for _, jobName := range scheduled {
log.Infof("Unloading Job(%s) from local machine", jobName)
a.unloadJob(jobName)
log.Infof("Unscheduling Job(%s) from local machine", jobName)
a.registry.ClearJobTarget(jobName, machID)
}
// Jobs have been stopped, the heartbeat can stop
close(purged)
log.Info("Removing Agent from Registry")
if err := a.registry.RemoveMachineState(machID); err != nil {
log.Errorf("Failed to remove Machine %s from Registry: %s", machID, err.Error())
}
}
示例14: UnresolvedJobOffers
func (r *Registry) UnresolvedJobOffers() []job.JobOffer {
var offers []job.JobOffer
key := path.Join(keyPrefix, offerPrefix)
resp, err := r.etcd.Get(key, true, true)
if err != nil {
return offers
}
for _, node := range resp.Node.Nodes {
key := path.Join(node.Key, "object")
resp, err := r.etcd.Get(key, true, true)
// The object was probably handled between when we attempted to
// start resolving offers and when we actually tried to get it
if err != nil {
continue
}
var jo job.JobOffer
err = unmarshal(resp.Node.Value, &jo)
if err != nil {
log.Errorf(err.Error())
continue
}
offers = append(offers, jo)
}
return offers
}
示例15: HandleEventMachineRemoved
func (eh *EventHandler) HandleEventMachineRemoved(ev event.Event) {
machID := ev.Payload.(string)
mutex := eh.engine.registry.LockMachine(machID, eh.engine.machine.State().ID)
if mutex == nil {
log.V(1).Infof("EventMachineRemoved(%s): failed to lock Machine, ignoring event", machID)
return
}
defer mutex.Unlock()
jobs := getJobsScheduledToMachine(eh.engine.registry, machID)
for _, j := range jobs {
log.Infof("EventMachineRemoved(%s): clearing UnitState(%s)", machID, j.Name)
err := eh.engine.registry.RemoveUnitState(j.Name)
if err != nil {
log.Errorf("Failed removing UnitState(%s) from Registry: %v", j.Name, err)
}
log.Infof("EventMachineRemoved(%s): unscheduling Job(%s)", machID, j.Name)
eh.engine.registry.ClearJobTarget(j.Name, machID)
}
for _, j := range jobs {
log.Infof("EventMachineRemoved(%s): re-publishing JobOffer(%s)", machID, j.Name)
eh.engine.OfferJob(j)
}
eh.engine.clust.machineRemoved(machID)
}