aboutsummaryrefslogtreecommitdiffstats
path: root/src/orchestrator/pkg/state
diff options
context:
space:
mode:
Diffstat (limited to 'src/orchestrator/pkg/state')
-rw-r--r--src/orchestrator/pkg/state/state_helper.go48
-rw-r--r--src/orchestrator/pkg/state/types.go12
2 files changed, 57 insertions, 3 deletions
diff --git a/src/orchestrator/pkg/state/state_helper.go b/src/orchestrator/pkg/state/state_helper.go
index a65cea8d..9d59fb75 100644
--- a/src/orchestrator/pkg/state/state_helper.go
+++ b/src/orchestrator/pkg/state/state_helper.go
@@ -16,14 +16,56 @@
package state
-import "github.com/onap/multicloud-k8s/src/orchestrator/pkg/appcontext"
+import (
+ "github.com/onap/multicloud-k8s/src/orchestrator/pkg/appcontext"
+ pkgerrors "github.com/pkg/errors"
+)
// GetAppContextFromStateInfo loads the appcontext present in the StateInfo input
-func GetAppContextFromStateInfo(s StateInfo) (appcontext.AppContext, error) {
+func GetAppContextFromId(ctxid string) (appcontext.AppContext, error) {
var cc appcontext.AppContext
- _, err := cc.LoadAppContext(s.ContextId)
+ _, err := cc.LoadAppContext(ctxid)
if err != nil {
return appcontext.AppContext{}, err
}
return cc, nil
}
+
+// GetCurrentStateFromStatInfo gets the last (current) state from StateInfo
+func GetCurrentStateFromStateInfo(s StateInfo) (StateValue, error) {
+ alen := len(s.Actions)
+ if alen == 0 {
+ return StateEnum.Undefined, pkgerrors.Errorf("No state information")
+ }
+ return s.Actions[alen-1].State, nil
+}
+
+// GetLastContextFromStatInfo gets the last (most recent) context id from StateInfo
+func GetLastContextIdFromStateInfo(s StateInfo) string {
+ alen := len(s.Actions)
+ if alen > 0 {
+ return s.Actions[alen-1].ContextId
+ } else {
+ return ""
+ }
+}
+
+// GetContextIdsFromStatInfo return a list of the unique AppContext Ids in the StateInfo
+func GetContextIdsFromStateInfo(s StateInfo) []string {
+ m := make(map[string]string)
+
+ for _, a := range s.Actions {
+ if a.ContextId != "" {
+ m[a.ContextId] = ""
+ }
+ }
+
+ ids := make([]string, len(m))
+ i := 0
+ for k := range m {
+ ids[i] = k
+ i++
+ }
+
+ return ids
+}
diff --git a/src/orchestrator/pkg/state/types.go b/src/orchestrator/pkg/state/types.go
index 25fb60d2..665a1be4 100644
--- a/src/orchestrator/pkg/state/types.go
+++ b/src/orchestrator/pkg/state/types.go
@@ -16,16 +16,27 @@
package state
+import "time"
+
// StateInfo struct is used to maintain the values for state, contextid, (and other)
// information about resources which can be instantiated via rsync.
+// The last Actions entry holds the current state of the container object.
type StateInfo struct {
+ Actions []ActionEntry
+}
+
+// ActionEntry is used to keep track of the time an action (e.g. Created, Instantiate, Terminate) was invoked
+// For actions where an AppContext is relevent, the ContextId field will be non-zero length
+type ActionEntry struct {
State StateValue
ContextId string
+ TimeStamp time.Time
}
type StateValue = string
type states struct {
+ Undefined StateValue
Created StateValue
Approved StateValue
Applied StateValue
@@ -34,6 +45,7 @@ type states struct {
}
var StateEnum = &states{
+ Undefined: "Undefined",
Created: "Created",
Approved: "Approved",
Applied: "Applied",