workflows

package
v0.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2021 License: Apache-2.0 Imports: 9 Imported by: 6

Documentation

Overview

Package workflows provides interaction with the workflows API in the OpenStack Mistral service.

Workflow represents a process that can be described in a various number of ways and that can do some job interesting to the end user. Each workflow consists of tasks (at least one) describing what exact steps should be made during workflow execution.

Workflow definition is written in Mistral Workflow Language v2. You can find all specification here: https://docs.openstack.org/mistral/latest/user/wf_lang_v2.html

List workflows

listOpts := workflows.ListOpts{
	Namespace: "some-namespace",
}

allPages, err := workflows.List(mistralClient, listOpts).AllPages()
if err != nil {
	panic(err)
}

allWorkflows, err := workflows.ExtractWorkflows(allPages)
if err != nil {
	panic(err)
}

for _, workflow := range allWorkflows {
	fmt.Printf("%+v\n", workflow)
}

Get a workflow

workflow, err := workflows.Get(mistralClient, "604a3a1e-94e3-4066-a34a-aa56873ef236").Extract()
if err != nil {
	t.Fatalf("Unable to get workflow %s: %v", id, err)
}

fmt.Printf("%+v\n", workflow)

Create a workflow

	workflowDefinition := `---
      version: '2.0'

      workflow_echo:
        description: Simple workflow example
        type: direct
        input:
          - msg

        tasks:
          test:
            action: std.echo output="<% $.msg %>"`

	createOpts := &workflows.CreateOpts{
		Definition: strings.NewReader(workflowDefinition),
		Scope: "private",
		Namespace: "some-namespace",
	}

	workflow, err := workflows.Create(mistralClient, createOpts).Extract()
	if err != nil {
		panic(err)
	}

	fmt.Printf("%+v\n", workflow)

Delete a workflow

res := workflows.Delete(fake.ServiceClient(), "604a3a1e-94e3-4066-a34a-aa56873ef236")
if res.Err != nil {
	panic(res.Err)
}

Index

Constants

View Source
const (
	// FilterEQ checks equality.
	FilterEQ = "eq"
	// FilterNEQ checks non equality.
	FilterNEQ = "neq"
	// FilterIN checks for belonging in a list, comma separated.
	FilterIN = "in"
	// FilterNIN checks for values that does not belong from a list, comma separated.
	FilterNIN = "nin"
	// FilterGT checks for values strictly greater.
	FilterGT = "gt"
	// FilterGTE checks for values greater or equal.
	FilterGTE = "gte"
	// FilterLT checks for values strictly lower.
	FilterLT = "lt"
	// FilterLTE checks for values lower or equal.
	FilterLTE = "lte"
	// FilterHas checks for values that contains the requested parameter.
	FilterHas = "has"
)

Variables

This section is empty.

Functions

func List

List performs a call to list cron triggers. You may provide options to filter the results.

Types

type CreateOpts

type CreateOpts struct {
	// Scope is the scope of the workflow.
	// Allowed values are "private" and "public".
	Scope string `q:"scope"`

	// Namespace will define the namespace of the workflow.
	Namespace string `q:"namespace"`

	// Definition is the workflow definition written in Mistral Workflow Language v2.
	Definition io.Reader
}

CreateOpts specifies parameters used to create a cron trigger.

func (CreateOpts) ToWorkflowCreateParams

func (opts CreateOpts) ToWorkflowCreateParams() (io.Reader, string, error)

ToWorkflowCreateParams constructs a request query string from CreateOpts.

type CreateOptsBuilder

type CreateOptsBuilder interface {
	ToWorkflowCreateParams() (io.Reader, string, error)
}

CreateOptsBuilder allows extension to add additional parameters to the Create request.

type CreateResult

type CreateResult struct {
	gophercloud.Result
}

CreateResult is the response of a Post operations. Call its Extract method to interpret it as a list of Workflows.

func Create

func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult)

Create requests the creation of a new execution.

func (CreateResult) Extract

func (r CreateResult) Extract() ([]Workflow, error)

Extract helps to get created Workflow struct from a Create function.

type DeleteResult

type DeleteResult struct {
	gophercloud.ErrResult
}

DeleteResult is the result from a Delete operation. Call its ExtractErr method to determine the success of the call.

func Delete

func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult)

Delete deletes the specified execution.

type FilterType

type FilterType string

FilterType represents a valid filter to use for filtering executions.

type GetResult

type GetResult struct {
	gophercloud.Result
}

GetResult is the response of Get operations. Call its Extract method to interpret it as a Workflow.

func Get

func Get(client *gophercloud.ServiceClient, id string) (r GetResult)

Get retrieves details of a single execution. Use Extract to convert its result into an Workflow.

func (GetResult) Extract

func (r GetResult) Extract() (*Workflow, error)

Extract helps to get a Workflow struct from a Get function.

type ListDateFilter

type ListDateFilter struct {
	Filter FilterType
	Value  time.Time
}

ListDateFilter allows to filter date parameters with different filters. Empty value for Filter checks for equality.

func (ListDateFilter) String

func (l ListDateFilter) String() string

type ListFilter

type ListFilter struct {
	Filter FilterType
	Value  string
}

ListFilter allows to filter string parameters with different filters. Empty value for Filter checks for equality.

func (ListFilter) String

func (l ListFilter) String() string

type ListOpts

type ListOpts struct {
	// Scope filters by the workflow's scope.
	// Values can be "private" or "public".
	Scope string `q:"scope"`
	// CreatedAt allows to filter by workflow creation date.
	CreatedAt *ListDateFilter `q:"-"`
	// UpdatedAt allows to filter by last execution update date.
	UpdatedAt *ListDateFilter `q:"-"`
	// Name allows to filter by workflow name.
	Name *ListFilter `q:"-"`
	// Tags allows to filter by tags.
	Tags []string
	// Definition allows to filter by workflow definition.
	Definition *ListFilter `q:"-"`
	// Namespace allows to filter by workflow namespace.
	Namespace *ListFilter `q:"-"`
	// SortDirs allows to select sort direction.
	// It can be "asc" or "desc" (default).
	SortDirs string `q:"sort_dirs"`
	// SortKeys allows to sort by one of the cron trigger attributes.
	SortKeys string `q:"sort_keys"`
	// Marker and Limit control paging.
	// Marker instructs List where to start listing from.
	Marker string `q:"marker"`
	// Limit instructs List to refrain from sending excessively large lists of
	// cron triggers.
	Limit int `q:"limit"`
	// ProjectID allows to filter by given project id. Admin required.
	ProjectID string `q:"project_id"`
	// AllProjects requests to get executions of all projects. Admin required.
	AllProjects int `q:"all_projects"`
}

ListOpts filters the result returned by the List() function.

func (ListOpts) ToWorkflowListQuery

func (opts ListOpts) ToWorkflowListQuery() (string, error)

ToWorkflowListQuery formats a ListOpts into a query string.

type ListOptsBuilder

type ListOptsBuilder interface {
	ToWorkflowListQuery() (string, error)
}

ListOptsBuilder allows extension to add additional parameters to the List request.

type Workflow

type Workflow struct {
	// ID is the workflow's unique ID.
	ID string `json:"id"`

	// Definition is the workflow definition in Mistral v2 DSL.
	Definition string `json:"definition"`

	// Name is the name of the workflow.
	Name string `json:"name"`

	// Namespace is the namespace of the workflow.
	Namespace string `json:"namespace"`

	// Input represents the needed input to execute the workflow.
	// This parameter is a list of each input, comma separated.
	Input string `json:"input"`

	// ProjectID is the project id owner of the workflow.
	ProjectID string `json:"project_id"`

	// Scope is the scope of the workflow.
	// Values can be "private" or "public".
	Scope string `json:"scope"`

	// Tags is a list of tags associated to the workflow.
	Tags []string `json:"tags"`

	// CreatedAt is the creation date of the workflow.
	CreatedAt time.Time `json:"-"`

	// UpdatedAt is the last update date of the workflow.
	UpdatedAt *time.Time `json:"-"`
}

Workflow represents a workflow execution on OpenStack mistral API.

func ExtractWorkflows

func ExtractWorkflows(r pagination.Page) ([]Workflow, error)

ExtractWorkflows get the list of cron triggers from a page acquired from the List call.

func (*Workflow) UnmarshalJSON

func (r *Workflow) UnmarshalJSON(b []byte) error

UnmarshalJSON implements unmarshalling custom types

type WorkflowPage

type WorkflowPage struct {
	pagination.LinkedPageBase
}

WorkflowPage contains a single page of all workflows from a List call.

func (WorkflowPage) IsEmpty

func (r WorkflowPage) IsEmpty() (bool, error)

IsEmpty checks if an WorkflowPage contains any results.

func (WorkflowPage) NextPageURL

func (r WorkflowPage) NextPageURL() (string, error)

NextPageURL finds the next page URL in a page in order to navigate to the next page of results.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL