本文整理汇总了Golang中launchpad/net/juju-core/log.Errorf函数的典型用法代码示例。如果您正苦于以下问题:Golang Errorf函数的具体用法?Golang Errorf怎么用?Golang Errorf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Errorf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: serveCharm
func (s *Server) serveCharm(w http.ResponseWriter, r *http.Request) {
if !strings.HasPrefix(r.URL.Path, "/charm/") {
panic("serveCharm: bad url")
}
curl, err := charm.ParseURL("cs:" + r.URL.Path[len("/charm/"):])
if err != nil {
w.WriteHeader(http.StatusNotFound)
return
}
info, rc, err := s.store.OpenCharm(curl)
if err == ErrNotFound {
w.WriteHeader(http.StatusNotFound)
return
}
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
log.Errorf("store: cannot open charm %q: %v", curl, err)
return
}
if statsEnabled(r) {
go s.store.IncCounter(charmStatsKey(curl, "charm-bundle"))
}
defer rc.Close()
w.Header().Set("Connection", "close") // No keep-alive for now.
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Length", strconv.FormatInt(info.BundleSize(), 10))
_, err = io.Copy(w, rc)
if err != nil {
log.Errorf("store: failed to stream charm %q: %v", curl, err)
}
}
示例2: finish
// finish completes the charm writing process and inserts the final metadata.
// After it completes the charm will be available for consumption.
func (w *charmWriter) finish() error {
if w.file == nil {
return nil
}
defer w.session.Close()
id := w.file.Id()
size := w.file.Size()
err := w.file.Close()
if err != nil {
log.Errorf("store: Failed to close GridFS file: %v", err)
return err
}
charms := w.session.Charms()
sha256 := hex.EncodeToString(w.sha256.Sum(nil))
charm := charmDoc{
w.urls,
w.revision,
w.digest,
sha256,
size,
id.(bson.ObjectId),
w.charm.Meta(),
w.charm.Config(),
}
if err = charms.Insert(&charm); err != nil {
err = maybeConflict(err)
log.Errorf("store: Failed to insert new revision of charm %v: %v", w.urls, err)
return err
}
return nil
}
示例3: PublishCharmsDistro
// PublishCharmsDistro publishes all branch tips found in
// the /charms distribution in Launchpad onto store under
// the "cs:" scheme.
// apiBase specifies the Launchpad base API URL, such
// as lpad.Production or lpad.Staging.
// Errors found while processing one or more branches are
// all returned as a PublishBranchErrors value.
func PublishCharmsDistro(store *Store, apiBase lpad.APIBase) error {
oauth := &lpad.OAuth{Anonymous: true, Consumer: "juju"}
root, err := lpad.Login(apiBase, oauth)
if err != nil {
return err
}
distro, err := root.Distro("charms")
if err != nil {
return err
}
tips, err := distro.BranchTips(time.Time{})
if err != nil {
return err
}
var errs PublishBranchErrors
for _, tip := range tips {
if !strings.HasSuffix(tip.UniqueName, "/trunk") {
continue
}
burl, curl, err := uniqueNameURLs(tip.UniqueName)
if err != nil {
errs = append(errs, PublishBranchError{tip.UniqueName, err})
log.Errorf("%v\n", err)
continue
}
log.Infof("----- %s\n", burl)
if tip.Revision == "" {
errs = append(errs, PublishBranchError{burl, fmt.Errorf("branch has no revisions")})
log.Errorf("branch has no revisions\n")
continue
}
// Charm is published in the personal URL and in any explicitly
// assigned official series.
urls := []*charm.URL{curl}
schema, name := curl.Schema, curl.Name
for _, series := range tip.OfficialSeries {
curl = &charm.URL{Schema: schema, Name: name, Series: series, Revision: -1}
curl.Series = series
curl.User = ""
urls = append(urls, curl)
}
err = PublishBazaarBranch(store, urls, burl, tip.Revision)
if err == ErrRedundantUpdate {
continue
}
if err != nil {
errs = append(errs, PublishBranchError{burl, err})
log.Errorf("%v\n", err)
}
}
if errs != nil {
return errs
}
return nil
}
示例4: startMachine
func (p *Provisioner) startMachine(m *state.Machine) error {
// TODO(dfc) the state.Info passed to environ.StartInstance remains contentious
// however as the PA only knows one state.Info, and that info is used by MAs and
// UAs to locate the state for this environment, it is logical to use the same
// state.Info as the PA.
stateInfo, apiInfo, err := p.setupAuthentication(m)
if err != nil {
return err
}
cons, err := m.Constraints()
if err != nil {
return err
}
// Generate a unique nonce for the new instance.
uuid, err := utils.NewUUID()
if err != nil {
return err
}
// Generated nonce has the format: "machine-#:UUID". The first
// part is a badge, specifying the tag of the machine the provisioner
// is running on, while the second part is a random UUID.
nonce := fmt.Sprintf("%s:%s", state.MachineTag(p.machineId), uuid.String())
inst, err := p.environ.StartInstance(m.Id(), nonce, m.Series(), cons, stateInfo, apiInfo)
if err != nil {
// Set the state to error, so the machine will be skipped next
// time until the error is resolved, but don't return an
// error; just keep going with the other machines.
log.Errorf("worker/provisioner: cannot start instance for machine %q: %v", m, err)
if err1 := m.SetStatus(params.StatusError, err.Error()); err1 != nil {
// Something is wrong with this machine, better report it back.
log.Errorf("worker/provisioner: cannot set error status for machine %q: %v", m, err1)
return err1
}
return nil
}
if err := m.SetProvisioned(inst.Id(), nonce); err != nil {
// The machine is started, but we can't record the mapping in
// state. It'll keep running while we fail out and restart,
// but will then be detected by findUnknownInstances and
// killed again.
//
// TODO(dimitern) Stop the instance right away here.
//
// Multiple instantiations of a given machine (with the same
// machine ID) cannot coexist, because findUnknownInstances is
// called before startMachines. However, if the first machine
// had started to do work before being replaced, we may
// encounter surprising problems.
return err
}
// populate the local cache
p.instances[m.Id()] = inst
p.machines[inst.Id()] = m.Id()
log.Noticef("worker/provisioner: started machine %s as instance %s", m, inst.Id())
return nil
}
示例5: tryLock
// tryLock tries locking l.keys, one at a time, and succeeds only if it
// can lock all of them in order. The keys should be pre-sorted so that
// two-way conflicts can't happen. If any of the keys fail to be locked,
// and expiring the old lock doesn't work, tryLock undoes all previous
// locks and aborts with an error.
func (l *UpdateLock) tryLock() error {
for i, key := range l.keys {
log.Debugf("store: Trying to lock charm %s for updates...", key)
doc := bson.D{{"_id", key}, {"time", l.time}}
err := l.locks.Insert(doc)
if err == nil {
log.Debugf("store: Charm %s is now locked for updates.", key)
continue
}
if lerr, ok := err.(*mgo.LastError); ok && lerr.Code == 11000 {
log.Debugf("store: Charm %s is locked. Trying to expire lock.", key)
l.tryExpire(key)
err = l.locks.Insert(doc)
if err == nil {
log.Debugf("store: Charm %s is now locked for updates.", key)
continue
}
}
// Couldn't lock everyone. Undo previous locks.
for j := i - 1; j >= 0; j-- {
// Using time below should be unnecessary, but it's an extra check.
// Can't do anything about errors here. Lock will expire anyway.
l.locks.Remove(bson.D{{"_id", l.keys[j]}, {"time", l.time}})
}
err = maybeConflict(err)
log.Errorf("store: Can't lock charms %v for updating: %v", l.keys, err)
return err
}
return nil
}
示例6: ensureIndexes
func (s *Store) ensureIndexes() error {
session := s.session
indexes := []struct {
c *mgo.Collection
i mgo.Index
}{{
session.StatCounters(),
mgo.Index{Key: []string{"k", "t"}, Unique: true},
}, {
session.StatTokens(),
mgo.Index{Key: []string{"t"}, Unique: true},
}, {
session.Charms(),
mgo.Index{Key: []string{"urls", "revision"}, Unique: true},
}, {
session.Events(),
mgo.Index{Key: []string{"urls", "digest"}},
}}
for _, idx := range indexes {
err := idx.c.EnsureIndex(idx.i)
if err != nil {
log.Errorf("store: Error ensuring stat.counters index: %v", err)
return err
}
}
return nil
}
示例7: Wait
func (c *closeWorker) Wait() error {
err := c.worker.Wait()
if err := c.closer.Close(); err != nil {
log.Errorf("closeWorker: close error: %v", err)
}
return err
}
示例8: newFilter
// newFilter returns a filter that handles state changes pertaining to the
// supplied unit.
func newFilter(st *state.State, unitName string) (*filter, error) {
f := &filter{
st: st,
outUnitDying: make(chan struct{}),
outConfig: make(chan struct{}),
outConfigOn: make(chan struct{}),
outUpgrade: make(chan *charm.URL),
outUpgradeOn: make(chan *charm.URL),
outResolved: make(chan state.ResolvedMode),
outResolvedOn: make(chan state.ResolvedMode),
outRelations: make(chan []int),
outRelationsOn: make(chan []int),
wantForcedUpgrade: make(chan bool),
wantResolved: make(chan struct{}),
discardConfig: make(chan struct{}),
setCharm: make(chan *charm.URL),
didSetCharm: make(chan struct{}),
clearResolved: make(chan struct{}),
didClearResolved: make(chan struct{}),
}
go func() {
defer f.tomb.Done()
err := f.loop(unitName)
log.Errorf("worker/uniter/filter: %v", err)
f.tomb.Kill(err)
}()
return f, nil
}
示例9: CharmInfo
// CharmInfo retrieves the CharmInfo value for the charm at url.
func (s *Store) CharmInfo(url *charm.URL) (info *CharmInfo, err error) {
session := s.session.Copy()
defer session.Close()
log.Debugf("store: Retrieving charm info for %s", url)
rev := url.Revision
url = url.WithRevision(-1)
charms := session.Charms()
var cdoc charmDoc
var qdoc interface{}
if rev == -1 {
qdoc = bson.D{{"urls", url}}
} else {
qdoc = bson.D{{"urls", url}, {"revision", rev}}
}
err = charms.Find(qdoc).Sort("-revision").One(&cdoc)
if err != nil {
log.Errorf("store: Failed to find charm %s: %v", url, err)
return nil, ErrNotFound
}
info = &CharmInfo{
cdoc.Revision,
cdoc.Digest,
cdoc.Sha256,
cdoc.Size,
cdoc.FileId,
cdoc.Meta,
cdoc.Config,
}
return info, nil
}
示例10: run
func (srv *Server) run(lis net.Listener) {
defer srv.tomb.Done()
defer srv.wg.Wait() // wait for any outstanding requests to complete.
srv.wg.Add(1)
go func() {
<-srv.tomb.Dying()
lis.Close()
srv.wg.Done()
}()
handler := websocket.Handler(func(conn *websocket.Conn) {
srv.wg.Add(1)
defer srv.wg.Done()
// If we've got to this stage and the tomb is still
// alive, we know that any tomb.Kill must occur after we
// have called wg.Add, so we avoid the possibility of a
// handler goroutine running after Stop has returned.
if srv.tomb.Err() != tomb.ErrStillAlive {
return
}
if err := srv.serveConn(conn); err != nil {
log.Errorf("state/api: error serving RPCs: %v", err)
}
})
// The error from http.Serve is not interesting.
http.Serve(lis, handler)
}
示例11: Run
// Run executes the subcommand that was selected in Init.
func (c *SuperCommand) Run(ctx *Context) error {
if c.showDescription {
if c.Purpose != "" {
fmt.Fprintf(ctx.Stdout, "%s\n", c.Purpose)
} else {
fmt.Fprintf(ctx.Stdout, "%s: no description available\n", c.Info().Name)
}
return nil
}
if c.subcmd == nil {
panic("Run: missing subcommand; Init failed or not called")
}
if c.Log != nil {
if err := c.Log.Start(ctx); err != nil {
return err
}
}
err := c.subcmd.Run(ctx)
if err != nil && err != ErrSilent {
log.Errorf("command failed: %v", err)
} else {
log.Infof("command finished")
}
return err
}
示例12: Open
// Open connects to the server described by the given
// info, waits for it to be initialized, and returns a new State
// representing the environment connected to.
// It returns unauthorizedError if access is unauthorized.
func Open(info *Info, opts DialOpts) (*State, error) {
log.Infof("state: opening state; mongo addresses: %q; entity %q", info.Addrs, info.Tag)
if len(info.Addrs) == 0 {
return nil, stderrors.New("no mongo addresses")
}
if len(info.CACert) == 0 {
return nil, stderrors.New("missing CA certificate")
}
xcert, err := cert.ParseCert(info.CACert)
if err != nil {
return nil, fmt.Errorf("cannot parse CA certificate: %v", err)
}
pool := x509.NewCertPool()
pool.AddCert(xcert)
tlsConfig := &tls.Config{
RootCAs: pool,
ServerName: "anything",
}
dial := func(addr net.Addr) (net.Conn, error) {
c, err := net.Dial("tcp", addr.String())
if err != nil {
log.Errorf("state: connection failed, will retry: %v", err)
return nil, err
}
cc := tls.Client(c, tlsConfig)
if err := cc.Handshake(); err != nil {
log.Errorf("state: TLS handshake failed: %v", err)
return nil, err
}
return cc, nil
}
session, err := mgo.DialWithInfo(&mgo.DialInfo{
Addrs: info.Addrs,
Timeout: opts.Timeout,
Dial: dial,
})
if err != nil {
return nil, err
}
log.Infof("state: connection established")
st, err := newState(session, info)
if err != nil {
session.Close()
return nil, err
}
return st, nil
}
示例13: Handle
func (c *Cleaner) Handle() error {
if err := c.st.Cleanup(); err != nil {
log.Errorf("worker/cleaner: cannot cleanup state: %v", err)
}
// We do not return the err from Cleanup, because we don't want to stop
// the loop as a failure
return nil
}
示例14: forgetUnit
// forgetUnit cleans the unit data after the unit is removed.
func (fw *Firewaller) forgetUnit(unitd *unitData) {
name := unitd.unit.Name()
serviced := unitd.serviced
machined := unitd.machined
if err := unitd.Stop(); err != nil {
log.Errorf("worker/firewaller: unit watcher %q returned error when stopping: %v", name, err)
}
// Clean up after stopping.
delete(fw.unitds, name)
delete(machined.unitds, name)
delete(serviced.unitds, name)
if len(serviced.unitds) == 0 {
// Stop service data after all units are removed.
if err := serviced.Stop(); err != nil {
log.Errorf("worker/firewaller: service watcher %q returned error when stopping: %v", serviced.service, err)
}
delete(fw.serviceds, serviced.service.Name())
}
}
示例15: mustLackRevision
// mustLackRevision returns an error if any of the urls has a revision.
func mustLackRevision(context string, urls ...*charm.URL) error {
for _, url := range urls {
if url.Revision != -1 {
err := fmt.Errorf("%s: got charm URL with revision: %s", context, url)
log.Errorf("store: %v", err)
return err
}
}
return nil
}