-
Notifications
You must be signed in to change notification settings - Fork 73
/
nerdstorage_status_reporter.go
119 lines (94 loc) · 3.49 KB
/
nerdstorage_status_reporter.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package execution
import (
log "github.com/sirupsen/logrus"
configAPI "github.com/newrelic/newrelic-cli/internal/config/api"
"github.com/newrelic/newrelic-cli/internal/install/types"
"github.com/newrelic/newrelic-client-go/pkg/nerdstorage"
)
const (
packageID = "00000000-0000-0000-0000-000000000000"
collectionID = "openInstallLibrary"
)
// NerdstorageStatusReporter is an implementation of the ExecutionStatusReporter
// interface that reports execution status into NerdStorage.
type NerdstorageStatusReporter struct {
client NerdStorageClient
}
// NewNerdStorageStatusReporter returns a new instance of NerdStorageExecutionStatusReporter.
func NewNerdStorageStatusReporter(client NerdStorageClient) *NerdstorageStatusReporter {
r := NerdstorageStatusReporter{
client: client,
}
return &r
}
func (r NerdstorageStatusReporter) RecipesSelected(status *InstallStatus, recipes []types.OpenInstallationRecipe) error {
return nil
}
// RecipeAvailable reports that a recipe is available for installation on
// the underlying host.
func (r NerdstorageStatusReporter) RecipeAvailable(status *InstallStatus, recipe types.OpenInstallationRecipe) error {
return r.writeStatus(status)
}
func (r NerdstorageStatusReporter) RecipeFailed(status *InstallStatus, event RecipeStatusEvent) error {
return r.writeStatus(status)
}
func (r NerdstorageStatusReporter) RecipeInstalling(status *InstallStatus, event RecipeStatusEvent) error {
return r.writeStatus(status)
}
func (r NerdstorageStatusReporter) RecipeInstalled(status *InstallStatus, event RecipeStatusEvent) error {
return r.writeStatus(status)
}
func (r NerdstorageStatusReporter) RecipeRecommended(status *InstallStatus, event RecipeStatusEvent) error {
return r.writeStatus(status)
}
func (r NerdstorageStatusReporter) RecipeSkipped(status *InstallStatus, event RecipeStatusEvent) error {
return r.writeStatus(status)
}
func (r NerdstorageStatusReporter) InstallStarted(status *InstallStatus) error {
return r.writeStatus(status)
}
func (r NerdstorageStatusReporter) InstallComplete(status *InstallStatus) error {
return r.writeStatus(status)
}
func (r NerdstorageStatusReporter) InstallCanceled(status *InstallStatus) error {
return r.writeStatus(status)
}
func (r NerdstorageStatusReporter) RecipeUnsupported(status *InstallStatus, event RecipeStatusEvent) error {
return r.writeStatus(status)
}
func (r NerdstorageStatusReporter) DiscoveryComplete(status *InstallStatus, dm types.DiscoveryManifest) error {
return r.writeStatus(status)
}
func (r NerdstorageStatusReporter) UpdateRequired(status *InstallStatus) error {
return nil
}
func (r NerdstorageStatusReporter) writeStatus(status *InstallStatus) error {
i := r.buildExecutionStatusDocument(status)
_, err := r.client.WriteDocumentWithUserScope(i)
if err != nil {
return err
}
for _, g := range status.EntityGUIDs {
_, err = r.client.WriteDocumentWithEntityScope(g, i)
if err != nil {
return err
}
}
if len(status.EntityGUIDs) == 0 {
log.Debug("no entity GUIDs available, skipping entity-scoped status updates")
}
accountID := configAPI.GetActiveProfileAccountID()
_, err = r.client.WriteDocumentWithAccountScope(accountID, i)
if err != nil {
log.Debug("failed to write to account scoped nerd storage")
}
return nil
}
func (r NerdstorageStatusReporter) buildExecutionStatusDocument(status *InstallStatus) nerdstorage.WriteDocumentInput {
return nerdstorage.WriteDocumentInput{
PackageID: packageID,
Collection: collectionID,
DocumentID: status.DocumentID,
Document: status,
}
}