Documentation
¶
Index ¶
- func NewTLSConfig(caCertPath, certPath, privKeyPath string) *tls.Config
- type Client
- type Config
- type IMqttClient
- type JobDocument
- type JobError
- type JobExecution
- func (je *JobExecution) Fail(err JobError) error
- func (je *JobExecution) GetJobDocument() JobDocument
- func (je *JobExecution) GetJobID() string
- func (je *JobExecution) GetStatusDetails() StatusDetails
- func (je *JobExecution) GetThingName() string
- func (je *JobExecution) InProgress(statusDetails StatusDetails) error
- func (je *JobExecution) Publish(topic string, qos byte, payload interface{})
- func (je *JobExecution) Reject(err JobError) error
- func (je *JobExecution) Success(statusDetails StatusDetails) error
- func (je *JobExecution) Terminate()
- type JobExecutioner
- type StatusDetails
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewTLSConfig ¶
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 (*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
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 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