-
Notifications
You must be signed in to change notification settings - Fork 70
/
bundle_recipe.go
75 lines (64 loc) · 1.8 KB
/
bundle_recipe.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
package recipes
import (
"fmt"
log "github.com/sirupsen/logrus"
"github.com/newrelic/newrelic-cli/internal/install/execution"
"github.com/newrelic/newrelic-cli/internal/install/types"
)
type BundleRecipe struct {
Recipe *types.OpenInstallationRecipe
Dependencies []*BundleRecipe
DetectedStatuses []*DetectedStatusType
}
type DetectedStatusType struct {
Status execution.RecipeStatusType
DurationMs int64
}
func (br *BundleRecipe) AddDetectionStatus(newStatus execution.RecipeStatusType, durationMs int64) {
if br.HasStatus(newStatus) {
return
}
br.DetectedStatuses = append(br.DetectedStatuses, &DetectedStatusType{Status: newStatus, DurationMs: durationMs})
}
func (br *BundleRecipe) HasStatus(status execution.RecipeStatusType) bool {
for _, detectedStatus := range br.DetectedStatuses {
if detectedStatus.Status == status {
return true
}
}
return false
}
func (br *BundleRecipe) AreAllDependenciesAvailable() bool {
for _, depName := range br.Recipe.Dependencies {
if br.IsNameInDependencies(depName) {
continue
}
log.Debugf("recipe %s is missing a dependency for %s", br.Recipe.Name, depName)
return false
}
for _, ds := range br.Dependencies {
if !ds.HasStatus(execution.RecipeStatusTypes.AVAILABLE) {
return false
}
}
return true
}
func (br *BundleRecipe) IsNameInDependencies(depName string) bool {
for _, ds := range br.Dependencies {
if ds.Recipe.Name == depName {
return true
}
}
return false
}
func (ds *DetectedStatusType) String() string {
result := string(ds.Status)
if ds.DurationMs > 0 {
result = fmt.Sprintf("%s %dms", result, ds.DurationMs)
}
return fmt.Sprintf("{%s}", result)
}
func (br *BundleRecipe) String() string {
result := fmt.Sprintf("%s %s", br.Recipe.Name, br.DetectedStatuses)
return fmt.Sprintf("{%s}", result)
}