awsiotjobs

package module
v0.0.0-...-cb60b0f Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTLSConfig

func NewTLSConfig(caCertPath, certPath, privKeyPath string) *tls.Config

NewTLSConfig creates a new TLS config

Types

type Client

type Client struct {
	Iot IMqttClient //mqtt.Client
	// contains filtered or unexported fields
}

Client defines the client for connecting to AWSIoTJobs.

func NewClient

func NewClient(config Config) Client

NewClient returns a new AWSIoTJobsClient using the configuration

func (*Client) ConnectAndSubscribe

func (client *Client) ConnectAndSubscribe()

ConnectAndSubscribe connects to AWS IoT Core and subscribed to the job topics

type Config

type Config struct {
	Port            int
	CaCertPath      string
	CertificatePath string
	PrivateKeyPath  string
	Endpoint        string
	ThingName       string
	ClientID        string
	Handler         func(je JobExecutioner)
}

Config is the configuration to connect to AWS IoT

func NewConfig

func NewConfig() Config

NewConfig return a new config object with the default paramters

func (*Config) FromFile

func (c *Config) FromFile(file string) error

FromFile reads the configuration from a JSON file

{
	"Port":           88,
	"CaCertPath":     "ca",
	"CertificatePath":"cert",
	"PrivateKeyPath": "key",
	"Endpoint":       "ep",
	"ThingName":      "tn",
	"ClientID":       "cid"
}

type IMqttClient

type IMqttClient interface {
	Publish(string, byte, bool, interface{}) mqtt.Token
	Subscribe(string, byte, mqtt.MessageHandler) mqtt.Token
	Unsubscribe(...string) mqtt.Token
	Connect() mqtt.Token
}

IMqttClient represents the Mqtt client interface used by this library, allows also for better testability

type JobDocument

type JobDocument map[string]interface{}

JobDocument represent the Job Document passed by AWS IoT Jobs. We use a generic map[string]interface{} since the documents are JSON based

type JobError

type JobError struct {
	ErrCode    string
	ErrMessage string
}

JobError contains the error code and message for a Job error

func (JobError) Error

func (err JobError) Error() string

type JobExecution

type JobExecution struct {
	JobID           string        `json:"jobId"`
	ThingName       string        `json:"thingName"`
	JobDocument     JobDocument   `json:"jobDocument"`
	Status          string        `json:"status"`
	StatusDetails   StatusDetails `json:"statusDetails"`
	QueuedAt        int64         `json:"queuedAt"`
	StartedAt       int64         `json:"startedAt"`
	LastUpdatedAt   int64         `json:"lastUpdatedAt"`
	VersionNumber   int64         `json:"versionNumber"`
	ExecutionNumber int64         `json:"executionNumber"`
	// contains filtered or unexported fields
}

JobExecution represents the AWS IoT job execution document JOB MESSAGE SAMPLE

{
	"timestamp":1573561673,
	"execution":{
		"jobId":"mender_install-7cf96d",
		"status":"IN_PROGRESS",
		"queuedAt":1573560519,
		"startedAt":1573560656,
		"lastUpdatedAt":1573560656,
		"versionNumber":2,
		"executionNumber":1,
		"jobDocument": {
			"operation":"mender_install",
			"url":"https://fwupdate-demo"
		}
	}
}

func (*JobExecution) Fail

func (je *JobExecution) Fail(err JobError) error

Success reports a fialed job execution to AWS IoT Device Management By passing a StatusDetails structure to the function you can store some additional information regarding the reason of the failure. This function should be called to notify Device Management that the job failed. If there are other jobs pending, they will be immediately notified to the client.

func (*JobExecution) GetJobDocument

func (je *JobExecution) GetJobDocument() JobDocument

GetJobDocument is the accessor to the JobDocument

func (*JobExecution) GetJobID

func (je *JobExecution) GetJobID() string

GetJobID is the accessor to JobID

func (*JobExecution) GetStatusDetails

func (je *JobExecution) GetStatusDetails() StatusDetails

GetStatusDetails is the accessor to the StatusDetails

func (*JobExecution) GetThingName

func (je *JobExecution) GetThingName() string

GetThingName is the accessor to the ThingName

func (*JobExecution) InProgress

func (je *JobExecution) InProgress(statusDetails StatusDetails) error

InProgress reports the execution in progress to AWS IoT Device Management The argument which is passed to the function is reported in the StatusDetails field of the job. You can use InProgress in case the execution of your job will take some time or needs multiple steps and you need to be able to recover from an interruption. The next time you access the Jobs API, you'll get the pending job execution and the correspondin state.

func (*JobExecution) Publish

func (je *JobExecution) Publish(topic string, qos byte, payload interface{})

Publish is a wrapper on the mqtt Publish

func (*JobExecution) Reject

func (je *JobExecution) Reject(err JobError) error

Reject reports that the client could not handle the job execution, for example because the document was not understood or missing compulsory information. By passing a StatusDetails structure to the function you can store some additional information regarding the reason of the rejection. If there are other jobs pending, they will be immediately notified to the client.

func (*JobExecution) Success

func (je *JobExecution) Success(statusDetails StatusDetails) error

Success reports a successfull job execution to AWS IoT Device Management By passing a StatusDetails structure to the function you can store some additional information regarding the execution. This function should be called to notify Device Management that the job was successfully performed. If there are other jobs pending, they will be immediately notified to the client.

func (*JobExecution) Terminate

func (je *JobExecution) Terminate()

Terminate the job execution if the process has to stop

type JobExecutioner

type JobExecutioner interface {
	GetJobDocument() JobDocument
	GetStatusDetails() StatusDetails
	Publish(string, byte, interface{})
	Success(StatusDetails) error
	Fail(JobError) error
	Reject(JobError) error
	InProgress(StatusDetails) error
	Terminate()
	GetThingName() string
	GetJobID() string
}

JobExecutioner is an interface allowig the concrete Job handler to interact with the JobExecution logic

type StatusDetails

type StatusDetails map[string]interface{}

StatusDetails represents the Status Details passed by AWS IoT Jobs We use a generic map[string]interface{} since the documents are JSON based

Jump to

Keyboard shortcuts

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