service

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2019 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const MainServiceKey = "service"

MainServiceKey is key for main service.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dependency

type Dependency struct {
	// Key is the key of dependency.
	Key string `hash:"name:1" validate:"printascii"`

	// Image is the Docker image.
	Image string `hash:"name:2" validate:"printascii"`

	// Volumes are the Docker volumes.
	Volumes []string `hash:"name:3" validate:"unique,dive,printascii"`

	// VolumesFrom are the docker volumes-from from.
	VolumesFrom []string `hash:"name:4" validate:"unique,dive,printascii"`

	// Ports holds ports configuration for container.
	Ports []string `hash:"name:5" validate:"unique,dive,portmap"`

	// Command is the Docker command which will be executed when container started.
	Command string `hash:"name:6" validate:"printascii"`

	// Argument holds the args to pass to the Docker container
	Args []string `hash:"name:7" validate:"dive,printascii"`

	// Env is a slice of environment variables in key=value format.
	Env []string `hash:"name:8" validate:"unique,dive,env"`
}

Dependency represents a Docker container and it holds instructions about how it should run.

type Event

type Event struct {
	// Key is the key of event.
	Key string `hash:"name:1" validate:"printascii"`

	// Name is the name of event.
	Name string `hash:"name:2" validate:"printascii"`

	// Description is the description of event.
	Description string `hash:"name:3" validate:"printascii"`

	// Data holds the input parameters of event.
	Data []*Parameter `hash:"name:4" validate:"dive,required"`
}

Event describes a service task.

type EventNotFoundError added in v0.2.0

type EventNotFoundError struct {
	EventKey    string
	ServiceName string
}

EventNotFoundError is an error returned when corresponding event cannot be found in service.

func (*EventNotFoundError) Error added in v0.2.0

func (e *EventNotFoundError) Error() string

type InvalidEventDataError added in v0.2.0

type InvalidEventDataError struct {
	EventKey    string
	ServiceName string
	Warnings    []*ParameterWarning
}

InvalidEventDataError is an error returned when the data of corresponding event is not valid.

func (*InvalidEventDataError) Error added in v0.2.0

func (e *InvalidEventDataError) Error() string

type InvalidTaskInputError added in v0.2.0

type InvalidTaskInputError struct {
	TaskKey     string
	ServiceName string
	Warnings    []*ParameterWarning
}

InvalidTaskInputError is an error returned when the inputs of corresponding task are not valid.

func (*InvalidTaskInputError) Error added in v0.2.0

func (e *InvalidTaskInputError) Error() string

type InvalidTaskOutputError added in v0.3.0

type InvalidTaskOutputError struct {
	TaskKey     string
	ServiceName string
	Warnings    []*ParameterWarning
}

InvalidTaskOutputError is an error returned when the outputs of corresponding task are not valid.

func (*InvalidTaskOutputError) Error added in v0.3.0

func (e *InvalidTaskOutputError) Error() string

type Parameter

type Parameter struct {
	// Key is the key of parameter.
	Key string `hash:"name:1" validate:"printascii"`

	// Name is the name of parameter.
	Name string `hash:"name:2" validate:"printascii"`

	// Description is the description of parameter.
	Description string `hash:"name:3" validate:"printascii"`

	// Type is the data type of parameter.
	Type string `hash:"name:4" validate:"required,printascii,oneof=String Number Boolean Object Any"`

	// Optional indicates if parameter is optional.
	Optional bool `hash:"name:5"`

	// Repeated is to have an array of this parameter
	Repeated bool `hash:"name:6"`

	// Definition of the structure of the object when the type is object
	Object []*Parameter `hash:"name:7" validate:"unique,dive,required"`
}

Parameter describes task input parameters, output parameters of a task output and input parameters of an event.

type ParameterWarning added in v0.2.0

type ParameterWarning struct {
	Key       string
	Warning   string
	Parameter *Parameter
}

ParameterWarning contains a specific warning related to a parameter.

func (*ParameterWarning) String added in v0.2.0

func (p *ParameterWarning) String() string

type Service

type Service struct {
	// Hash is calculated from the combination of service's source and mesg.yml.
	// It represents the service uniquely.
	Hash hash.Hash `hash:"-" validate:"required"`

	// Sid is the service id.
	// It needs to be unique and can be used to access to service.
	Sid string `hash:"name:1"  validate:"required,printascii,max=63,domain"`

	// Name is the service name.
	Name string `hash:"name:2" validate:"required,printascii"`

	// Description is service description.
	Description string `hash:"name:3" validate:"printascii"`

	// Tasks are the list of tasks that service can execute.
	Tasks []*Task `hash:"name:4" validate:"dive,required"`

	// Events are the list of events that service can emit.
	Events []*Event `hash:"name:5" validate:"dive,required"`

	// Dependencies are the Docker containers that service can depend on.
	Dependencies []*Dependency `hash:"name:6" validate:"dive,required"`

	// Configuration of the service
	Configuration *Dependency `hash:"name:8" validate:"required"`

	// Repository holds the service's repository url if it's living on
	// a Git host.
	Repository string `hash:"name:7" validate:"omitempty,uri"`

	// Source is the hash id of service's source code on IPFS.
	Source string `hash:"name:9" validate:"required,printascii"`

	// Workflows is a list of workflows that the service implements
	Workflows []*Workflow `hash:"name:10" validate:"dive,required"`
}

Service represents a MESG service.

func (*Service) GetDependency added in v0.11.0

func (s *Service) GetDependency(dependencyKey string) (*Dependency, error)

GetDependency returns dependency dependencyKey or a not found error.

func (*Service) GetEvent added in v0.3.0

func (s *Service) GetEvent(eventKey string) (*Event, error)

GetEvent returns event eventKey of service.

func (*Service) GetTask added in v0.3.0

func (s *Service) GetTask(taskKey string) (*Task, error)

GetTask returns task taskKey of service.

func (*Service) RequireEventData added in v0.11.0

func (s *Service) RequireEventData(eventKey string, eventData map[string]interface{}) error

RequireEventData requires event datas to be matched with parameter schemas.

func (*Service) RequireTaskInputs added in v0.11.0

func (s *Service) RequireTaskInputs(taskKey string, taskInputs map[string]interface{}) error

RequireTaskInputs requires task inputs to match with parameter schemas.

func (*Service) RequireTaskOutputs added in v0.11.0

func (s *Service) RequireTaskOutputs(taskKey string, taskOutputs map[string]interface{}) error

RequireTaskOutputs requires task outputs to match with parameter schemas.

func (*Service) ValidateEventData added in v0.11.0

func (s *Service) ValidateEventData(eventKey string, eventData map[string]interface{}) ([]*ParameterWarning, error)

ValidateEventData produces warnings for event datas that doesn't satisfy their parameter schemas.

func (*Service) ValidateTaskInputs added in v0.11.0

func (s *Service) ValidateTaskInputs(taskKey string, taskInputs map[string]interface{}) ([]*ParameterWarning, error)

ValidateTaskInputs produces warnings for task inputs that doesn't satisfy their parameter schemas.

func (*Service) ValidateTaskOutputs added in v0.11.0

func (s *Service) ValidateTaskOutputs(taskKey string, taskOutputs map[string]interface{}) ([]*ParameterWarning, error)

ValidateTaskOutputs produces warnings for task outputs that doesn't satisfy their parameter schemas.

type StatusType

type StatusType uint

StatusType of the service.

const (
	UNKNOWN StatusType = iota
	STOPPED
	STARTING
	PARTIAL
	RUNNING
)

Possible statuses for service.

func (StatusType) String added in v0.3.0

func (s StatusType) String() string

type Task

type Task struct {
	// Key is the key of task.
	Key string `hash:"name:1" validate:"printascii"`

	// Name is the name of task.
	Name string `hash:"name:2" validate:"printascii"`

	// Description is the description of task.
	Description string `hash:"name:3" validate:"printascii"`

	// Inputs are the definition of the execution inputs of task.
	Inputs []*Parameter `hash:"name:4" validate:"dive,required"`

	// Outputs are the definition of the execution results of task.
	Outputs []*Parameter `hash:"name:5" validate:"dive,required"`
}

Task describes a service task.

type TaskNotFoundError added in v0.2.0

type TaskNotFoundError struct {
	TaskKey     string
	ServiceName string
}

TaskNotFoundError is an error returned when corresponding task cannot be found in service.

func (*TaskNotFoundError) Error added in v0.2.0

func (e *TaskNotFoundError) Error() string

type TriggerType added in v0.12.0

type TriggerType uint

TriggerType is the type for the possible triggers for a workflow

const (
	EVENT TriggerType = iota + 1
	RESULT
)

List of possible triggers for a workflow

type Workflow added in v0.12.0

type Workflow struct {
	Trigger *WorkflowTrigger `hash:"name:1" validate:"required"`
	Task    *WorkflowTask    `hash:"name:2" validate:"required"`
	Key     string           `hash:"name:3" validate:"required"`
}

Workflow describes a workflow of a service

type WorkflowPredicate added in v0.12.0

type WorkflowPredicate uint

WorkflowPredicate is the type of conditions that can be applied in a filter of a workflow trigger

const (
	EQ WorkflowPredicate = iota + 1
)

List of possible conditions for workflow's filter

type WorkflowTask added in v0.12.0

type WorkflowTask struct {
	InstanceHash hash.Hash `hash:"name:1" validate:"required"`
	TaskKey      string    `hash:"name:2" validate:"printascii"`
}

WorkflowTask describes the instructions for the workflow to execute a task

type WorkflowTrigger added in v0.12.0

type WorkflowTrigger struct {
	InstanceHash hash.Hash                `hash:"name:1" validate:"required"`
	Key          string                   `hash:"name:2" validate:"printascii,printascii"`
	Type         TriggerType              `hash:"name:3" validate:"required"`
	Filters      []*WorkflowTriggerFilter `hash:"name:4" validate:"dive,required"`
}

WorkflowTrigger is an event that triggers a workflow

func (*WorkflowTrigger) Match added in v0.12.0

func (t *WorkflowTrigger) Match(trigger TriggerType, instanceHash hash.Hash, key string, data map[string]interface{}) bool

Match returns true if a workflow trigger is matching the given parameters

type WorkflowTriggerFilter added in v0.12.0

type WorkflowTriggerFilter struct {
	Key       string            `hash:"name:1" validate:"required,printascii"`
	Predicate WorkflowPredicate `hash:"name:2" validate:"required"`
	Value     interface{}       `hash:"name:3"`
}

WorkflowTriggerFilter is the filter definition that can be applied to a workflow trigger

func (*WorkflowTriggerFilter) Match added in v0.12.0

func (f *WorkflowTriggerFilter) Match(inputs map[string]interface{}) bool

Match returns true the current filter matches the given data

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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