-
Notifications
You must be signed in to change notification settings - Fork 3
/
lib_operation_status.go
85 lines (74 loc) · 3.59 KB
/
lib_operation_status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) 2021 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
package hawkbit
// OperationStatus represents the status of an operation (install/remove) called on a device.
type OperationStatus struct {
// CorrelationID is used for correlating the status-update with the operation called before.
CorrelationID string `json:"correlationId"`
// Status represents one of the predefined status, representing the failure, progress or sucess of the operation.
Status Status `json:"status"`
// SoftwareModule is required in the case of an install/download/cancel operation, absent in case of
// remove or cancelRemove.
SoftwareModule *SoftwareModuleID `json:"softwareModule,omitempty"`
// Software is required for a remove or cancelRemove operation, absent in case of install/download/cancel.
Software []*DependencyDescription `json:"software,omitempty"`
// Progress represents the progress indicator in percentage.
Progress int `json:"progress,omitempty"`
// Message from the device to give more context to the transmitted status.
Message string `json:"message,omitempty"`
// StatusCode represents a custom status code transmitted by the device.
StatusCode string `json:"statusCode,omitempty"`
}
// NewOperationStatusUpdate returns an OperationStatus with the mandatory fields needed for software module update operation.
func NewOperationStatusUpdate(correlationID string, status Status, softwareModule *SoftwareModuleID) *OperationStatus {
return &OperationStatus{CorrelationID: correlationID, Status: status, SoftwareModule: softwareModule}
}
// NewOperationStatusRemove returns an OperationStatus with the mandatory fields needed for software module remove operation.
func NewOperationStatusRemove(correlationID string, status Status,
software ...*DependencyDescription) *OperationStatus {
return &OperationStatus{CorrelationID: correlationID, Status: status, Software: software}
}
// WithCorrelationID sets the correlation id of the operation status.
func (os *OperationStatus) WithCorrelationID(correlationID string) *OperationStatus {
os.CorrelationID = correlationID
return os
}
// WithStatus sets the status of the operation status.
func (os *OperationStatus) WithStatus(status Status) *OperationStatus {
os.Status = status
return os
}
// WithSoftwareModule sets the software module id of the operation status.
func (os *OperationStatus) WithSoftwareModule(softwareModule *SoftwareModuleID) *OperationStatus {
os.SoftwareModule = softwareModule
return os
}
// WithSoftware sets the removed software to the operation status.
func (os *OperationStatus) WithSoftware(software ...*DependencyDescription) *OperationStatus {
os.Software = software
return os
}
// WithProgress sets the progress of the operation status.
func (os *OperationStatus) WithProgress(progress int) *OperationStatus {
os.Progress = progress
return os
}
// WithMessage sets the message of the operation status.
func (os *OperationStatus) WithMessage(message string) *OperationStatus {
os.Message = message
return os
}
// WithStatusCode sets the status code of the operation status.
func (os *OperationStatus) WithStatusCode(statusCode string) *OperationStatus {
os.StatusCode = statusCode
return os
}