func (c *stubContextComponent) SetStatus(class, id, status string) error { c.stub.AddCall("SetStatus", class, id, status) if err := c.stub.NextErr(); err != nil { return errors.Trace(err) } fullID := payload.BuildID(class, id) pl := c.payloads[fullID] pl.Status = status return nil }
func (c *stubContextComponent) Untrack(class, id string) error { c.stub.AddCall("Untrack", class, id) if err := c.stub.NextErr(); err != nil { return errors.Trace(err) } fullID := payload.BuildID(class, id) c.untracks[fullID] = struct{}{} return nil }
func (c *stubContextComponent) Get(class, id string) (*payload.Payload, error) { c.stub.AddCall("Get", class, id) if err := c.stub.NextErr(); err != nil { return nil, errors.Trace(err) } fullID := payload.BuildID(class, id) info, ok := c.payloads[fullID] if !ok { return nil, errors.NotFoundf(id) } return &info, nil }
// Get returns the payload info corresponding to the given ID. func (c *Context) Get(class, id string) (*payload.Payload, error) { fullID := payload.BuildID(class, id) logger.Tracef("getting %q from hook context", fullID) actual, ok := c.updates[fullID] if !ok { actual, ok = c.payloads[fullID] if !ok { return nil, errors.NotFoundf("%s", fullID) } } return &actual, nil }
func (c *Context) SetStatus(class, id, status string) error { fullID := payload.BuildID(class, id) logger.Tracef("Calling status-set on payload context %q", fullID) res, err := c.api.SetStatus(status, fullID) if err != nil { return errors.Trace(err) } if len(res) > 0 && res[0].Error != nil { return errors.Trace(res[0].Error) } return nil }
// Untrack tells juju to stop tracking this payload. func (c *Context) Untrack(class, id string) error { fullID := payload.BuildID(class, id) logger.Tracef("Calling untrack on payload context %q", fullID) res, err := c.api.Untrack(fullID) if err != nil { return errors.Trace(err) } if len(res) > 0 && res[0].Error != nil { return errors.Trace(res[0].Error) } delete(c.payloads, id) return nil }
// SetStatus sets the identified payload's status. func (c *Context) SetStatus(class, id, status string) error { fullID := payload.BuildID(class, id) logger.Tracef("Calling status-set on payload context %q", fullID) res, err := c.api.SetStatus(status, fullID) if err != nil { return errors.Trace(err) } // TODO(ericsnow) We should not ignore a 0-len result. if len(res) > 0 && res[0].Error != nil { // In a hook context, the case where the specified payload does // not exist is a special one. A hook tool is how a charm author // communicates the state of the charm. So returning an error // here in the "missing" case makes less sense than in other // places. We could simply ignore any error that surfaces for // that case. However, returning the error communicates to the // charm author that what they're trying to communicate doesn't // make sense. return errors.Trace(res[0].Error) } return nil }