Example #1
0
// actionIdFromTag converts an ActionTag to an actionId
func actionIdFromTag(tag names.ActionTag) string {
	ptag := tag.PrefixTag()
	if ptag == nil {
		return ""
	}
	return fmt.Sprintf("%s%d", ensureActionMarker(ptag.Id()), tag.Sequence())
}
Example #2
0
// ActionFinish captures the structured output of an action.
func (st *State) ActionFinish(tag names.ActionTag, status string, results map[string]interface{}, message string) error {
	var outcome params.ErrorResults

	args := params.ActionExecutionResults{
		Results: []params.ActionExecutionResult{
			{
				ActionTag: tag.String(),
				Status:    status,
				Results:   results,
				Message:   message,
			},
		},
	}

	err := st.facade.FacadeCall("FinishActions", args, &outcome)
	if err != nil {
		return err
	}
	if len(outcome.Results) != 1 {
		return fmt.Errorf("expected 1 result, got %d", len(outcome.Results))
	}
	result := outcome.Results[0]
	if result.Error != nil {
		return result.Error
	}
	return nil
}
Example #3
0
// getOneAction retrieves a single Action from the state server.
func (st *State) getOneAction(tag *names.ActionTag) (params.ActionsQueryResult, error) {
	nothing := params.ActionsQueryResult{}

	args := params.Entities{
		Entities: []params.Entity{
			{Tag: tag.String()},
		},
	}

	var results params.ActionsQueryResults
	err := st.facade.FacadeCall("Actions", args, &results)
	if err != nil {
		return nothing, err
	}

	if len(results.Results) > 1 {
		return nothing, fmt.Errorf("expected only 1 action query result, got %d", len(results.Results))
	}

	// handle server errors
	result := results.Results[0]
	if err := result.Error; err != nil {
		return nothing, err
	}

	return result, nil
}
Example #4
0
// ActionBegin marks an action as running.
func (c *Client) ActionBegin(tag names.ActionTag) error {
	var results params.ErrorResults

	args := params.Entities{
		Entities: []params.Entity{{Tag: tag.String()}},
	}

	err := c.facade.FacadeCall("BeginActions", args, &results)
	if err != nil {
		return errors.Trace(err)
	}

	return results.OneError()
}
Example #5
0
// ActionFinish captures the structured output of an action.
func (c *Client) ActionFinish(tag names.ActionTag, status string, actionResults map[string]interface{}, message string) error {
	var results params.ErrorResults

	args := params.ActionExecutionResults{
		Results: []params.ActionExecutionResult{{
			ActionTag: tag.String(),
			Status:    status,
			Results:   actionResults,
			Message:   message,
		}},
	}

	err := c.facade.FacadeCall("FinishActions", args, &results)
	if err != nil {
		return errors.Trace(err)
	}

	return results.OneError()
}
Example #6
0
// ActionBegin marks an action as running.
func (st *State) ActionBegin(tag names.ActionTag) error {
	var outcome params.ErrorResults

	args := params.Entities{
		Entities: []params.Entity{
			{Tag: tag.String()},
		},
	}

	err := st.facade.FacadeCall("BeginActions", args, &outcome)
	if err != nil {
		return err
	}
	if len(outcome.Results) != 1 {
		return fmt.Errorf("expected 1 result, got %d", len(outcome.Results))
	}
	result := outcome.Results[0]
	if result.Error != nil {
		return result.Error
	}
	return nil
}
Example #7
0
func (c *Client) getOneAction(tag names.ActionTag) (params.ActionResult, error) {
	nothing := params.ActionResult{}

	args := params.Entities{
		Entities: []params.Entity{{Tag: tag.String()}},
	}

	var results params.ActionResults
	err := c.facade.FacadeCall("Actions", args, &results)
	if err != nil {
		return nothing, errors.Trace(err)
	}

	if len(results.Results) > 1 {
		return nothing, errors.Errorf("expected only 1 action query result, got %d", len(results.Results))
	}

	result := results.Results[0]
	if result.Error != nil {
		return nothing, errors.Trace(result.Error)
	}

	return result, nil
}
Example #8
0
// ActionFail captures the action tag and error of a failed action.
func (st *State) ActionFail(tag names.ActionTag, err string) error {
	var result params.BoolResult
	args := params.ActionResult{ActionTag: tag.String(), Message: err, Failed: true}
	return st.facade.FacadeCall("ActionFinish", args, &result)
}
Example #9
0
// ActionComplete captures the structured output of an action.
func (st *State) ActionComplete(tag names.ActionTag, results map[string]interface{}) error {
	var result params.BoolResult
	args := params.ActionResult{ActionTag: tag.String(), Results: results}
	return st.facade.FacadeCall("ActionFinish", args, &result)
}
Example #10
0
func (st *State) ActionFail(tag names.ActionTag, errorMessage string) error {
	var result params.BoolResult
	args := params.ActionResult{ActionTag: tag.String(), Output: errorMessage}
	return st.call("ActionFail", args, &result)
}
Example #11
0
func (st *State) ActionComplete(tag names.ActionTag, output string) error {
	var result params.BoolResult
	args := params.ActionResult{ActionTag: tag.String(), Output: output}
	return st.call("ActionComplete", args, &result)
}
Example #12
0
// ActionByTag returns an Action given an ActionTag.
func (st *State) ActionByTag(tag names.ActionTag) (Action, error) {
	return st.Action(tag.Id())
}
Example #13
0
// actionIdFromTag converts an ActionTag to an actionId
func actionIdFromTag(tag names.ActionTag) string {
	prefix := actionPrefixFromUnitId(tag.UnitTag().Id())
	return actionId(prefix, tag.Sequence())
}