예제 #1
0
파일: base_test.go 프로젝트: bac/juju
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
}
예제 #2
0
파일: base_test.go 프로젝트: bac/juju
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
}
예제 #3
0
파일: base_test.go 프로젝트: bac/juju
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
}
예제 #4
0
파일: context.go 프로젝트: imoapps/juju
// 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
}
예제 #5
0
파일: context.go 프로젝트: imoapps/juju
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
}
예제 #6
0
파일: context.go 프로젝트: imoapps/juju
// 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
}
예제 #7
0
파일: context.go 프로젝트: bac/juju
// 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
}