summaryrefslogtreecommitdiffstats
path: root/src/clm
diff options
context:
space:
mode:
authorEric Multanen <eric.w.multanen@intel.com>2020-07-22 14:11:05 -0700
committerEric Multanen <eric.w.multanen@intel.com>2020-08-03 15:40:09 -0700
commitb2c23afb03b393b05fe38dd7c54b1de3c42deaf3 (patch)
tree5e845ad676a62e4bde17a6c4a846544164b0ad40 /src/clm
parentd6f900721c81a2c03cb1a21a3d2064e9a69fc4b7 (diff)
Add StateInfo structure synced resources
Add a StateInfo structure to the Cluster and Deployment-Intent-Group resources to keep track of the lifecycle state of these resources. Moved the appcontext id that was being kept into this structure as well. Enabled the approve state (and API) for the deployment intent group. Issue-ID: MULTICLOUD-1042 Signed-off-by: Eric Multanen <eric.w.multanen@intel.com> Change-Id: I36602d8a0658d9d6d37b8799f9a372a7d1042496
Diffstat (limited to 'src/clm')
-rw-r--r--src/clm/api/clusterhandler_test.go10
-rw-r--r--src/clm/go.mod15
-rw-r--r--src/clm/pkg/cluster/cluster.go47
3 files changed, 40 insertions, 32 deletions
diff --git a/src/clm/api/clusterhandler_test.go b/src/clm/api/clusterhandler_test.go
index 4bbc91b1..076718df 100644
--- a/src/clm/api/clusterhandler_test.go
+++ b/src/clm/api/clusterhandler_test.go
@@ -28,8 +28,8 @@ import (
"testing"
"github.com/onap/multicloud-k8s/src/clm/pkg/cluster"
- "github.com/onap/multicloud-k8s/src/orchestrator/pkg/appcontext"
types "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module/types"
+ "github.com/onap/multicloud-k8s/src/orchestrator/pkg/state"
pkgerrors "github.com/pkg/errors"
)
@@ -43,7 +43,7 @@ type mockClusterManager struct {
ClusterProviderItems []cluster.ClusterProvider
ClusterItems []cluster.Cluster
ClusterContentItems []cluster.ClusterContent
- ClusterContextItems []appcontext.AppContext
+ ClusterStateInfo []state.StateInfo
ClusterLabelItems []cluster.ClusterLabel
ClusterKvPairsItems []cluster.ClusterKvPairs
ClusterList []string
@@ -102,12 +102,12 @@ func (m *mockClusterManager) GetClusterContent(provider, name string) (cluster.C
return m.ClusterContentItems[0], nil
}
-func (m *mockClusterManager) GetClusterContext(provider, name string) (appcontext.AppContext, string, error) {
+func (m *mockClusterManager) GetClusterState(provider, name string) (state.StateInfo, error) {
if m.Err != nil {
- return appcontext.AppContext{}, "", m.Err
+ return state.StateInfo{}, m.Err
}
- return m.ClusterContextItems[0], "", nil
+ return m.ClusterStateInfo[0], nil
}
func (m *mockClusterManager) GetClusters(provider string) ([]cluster.Cluster, error) {
diff --git a/src/clm/go.mod b/src/clm/go.mod
index 0e655566..1d174b12 100644
--- a/src/clm/go.mod
+++ b/src/clm/go.mod
@@ -2,25 +2,24 @@ module github.com/onap/multicloud-k8s/src/clm
require (
github.com/ghodss/yaml v1.0.0
- github.com/go-stack/stack v1.8.0 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/gorilla/handlers v1.3.0
- github.com/gorilla/mux v1.6.2
+ github.com/gorilla/mux v1.7.3
github.com/k8snetworkplumbingwg/network-attachment-definition-client v0.0.0-20200127152046-0ee521d56061
- github.com/onap/multicloud-k8s/src/orchestrator v0.0.0-20200601021239-7959bd4c6fd4
+ github.com/onap/multicloud-k8s/src/orchestrator v0.0.0-20200721211210-783ed87fb39a
github.com/opencontainers/go-digest v1.0.0 // indirect
- github.com/pkg/errors v0.8.1
- github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c // indirect
- github.com/xdg/stringprep v1.0.0 // indirect
- google.golang.org/grpc v1.27.1
+ github.com/pkg/errors v0.9.1
+ google.golang.org/grpc v1.28.0
gopkg.in/yaml.v2 v2.2.8
k8s.io/api v0.0.0-20190831074750-7364b6bdad65
- k8s.io/apimachinery v0.0.0-20190831074630-461753078381
+ k8s.io/apimachinery v0.18.2
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
k8s.io/kubernetes v1.14.1
)
replace (
+ github.com/onap/multicloud-k8s/src/orchestrator => ../orchestrator
+ github.com/onap/multicloud-k8s/src/clm => ../clm
k8s.io/api => k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.0.0-20190409022649-727a075fdec8
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20190404173353-6a84e37a896d
diff --git a/src/clm/pkg/cluster/cluster.go b/src/clm/pkg/cluster/cluster.go
index ac7f31f7..9505bd97 100644
--- a/src/clm/pkg/cluster/cluster.go
+++ b/src/clm/pkg/cluster/cluster.go
@@ -17,9 +17,9 @@
package cluster
import (
- appcontext "github.com/onap/multicloud-k8s/src/orchestrator/pkg/appcontext"
"github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/db"
mtypes "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module/types"
+ "github.com/onap/multicloud-k8s/src/orchestrator/pkg/state"
pkgerrors "github.com/pkg/errors"
)
@@ -28,7 +28,7 @@ type clientDbInfo struct {
storeName string // name of the mongodb collection to use for client documents
tagMeta string // attribute key name for the json data of a client document
tagContent string // attribute key name for the file data of a client document
- tagContext string // attribute key name for context object in App Context
+ tagState string // attribute key name for StateInfo object in the cluster
}
// ClusterProvider contains the parameters needed for ClusterProviders
@@ -101,7 +101,7 @@ type ClusterManager interface {
CreateCluster(provider string, pr Cluster, qr ClusterContent) (Cluster, error)
GetCluster(provider, name string) (Cluster, error)
GetClusterContent(provider, name string) (ClusterContent, error)
- GetClusterContext(provider, name string) (appcontext.AppContext, string, error)
+ GetClusterState(provider, name string) (state.StateInfo, error)
GetClusters(provider string) ([]Cluster, error)
GetClustersWithLabel(provider, label string) ([]string, error)
DeleteCluster(provider, name string) error
@@ -129,7 +129,7 @@ func NewClusterClient() *ClusterClient {
storeName: "cluster",
tagMeta: "clustermetadata",
tagContent: "clustercontent",
- tagContext: "clustercontext",
+ tagState: "stateInfo",
},
}
}
@@ -254,6 +254,17 @@ func (v *ClusterClient) CreateCluster(provider string, p Cluster, q ClusterConte
return Cluster{}, pkgerrors.Wrap(err, "Creating DB Entry")
}
+ // Add the stateInfo record
+ stateInfo := state.StateInfo{
+ State: state.StateEnum.Created,
+ ContextId: "",
+ }
+
+ err = db.DBconn.Insert(v.db.storeName, key, nil, v.db.tagState, stateInfo)
+ if err != nil {
+ return Cluster{}, pkgerrors.Wrap(err, "Creating cluster StateInfo")
+ }
+
return p, nil
}
@@ -309,31 +320,29 @@ func (v *ClusterClient) GetClusterContent(provider, name string) (ClusterContent
return ClusterContent{}, pkgerrors.New("Error getting Cluster Content")
}
-// GetClusterContext returns the AppContext for corresponding provider and name
-func (v *ClusterClient) GetClusterContext(provider, name string) (appcontext.AppContext, string, error) {
+// GetClusterState returns the StateInfo structure for corresponding cluster provider and cluster
+func (v *ClusterClient) GetClusterState(provider, name string) (state.StateInfo, error) {
//Construct key and tag to select the entry
key := ClusterKey{
ClusterProviderName: provider,
ClusterName: name,
}
- value, err := db.DBconn.Find(v.db.storeName, key, v.db.tagContext)
+ result, err := db.DBconn.Find(v.db.storeName, key, v.db.tagState)
if err != nil {
- return appcontext.AppContext{}, "", pkgerrors.Wrap(err, "Get Cluster Context")
+ return state.StateInfo{}, pkgerrors.Wrap(err, "Get Cluster StateInfo")
}
- //value is a byte array
- if value != nil {
- ctxVal := string(value[0])
- var cc appcontext.AppContext
- _, err = cc.LoadAppContext(ctxVal)
+ if result != nil {
+ s := state.StateInfo{}
+ err = db.DBconn.Unmarshal(result[0], &s)
if err != nil {
- return appcontext.AppContext{}, "", pkgerrors.Wrap(err, "Reinitializing Cluster AppContext")
+ return state.StateInfo{}, pkgerrors.Wrap(err, "Unmarshalling Cluster StateInfo")
}
- return cc, ctxVal, nil
+ return s, nil
}
- return appcontext.AppContext{}, "", pkgerrors.New("Error getting Cluster AppContext")
+ return state.StateInfo{}, pkgerrors.New("Error getting Cluster StateInfo")
}
// GetClusters returns all the Clusters for corresponding provider
@@ -393,9 +402,9 @@ func (v *ClusterClient) DeleteCluster(provider, name string) error {
ClusterProviderName: provider,
ClusterName: name,
}
- _, _, err := v.GetClusterContext(provider, name)
- if err == nil {
- return pkgerrors.Errorf("Cannot delete cluster until context is deleted: %v, %v", provider, name)
+ s, err := v.GetClusterState(provider, name)
+ if err == nil && s.State == state.StateEnum.Applied {
+ return pkgerrors.Errorf("Cluster network intents must be terminated before it can be deleted: " + name)
}
err = db.DBconn.Remove(v.db.storeName, key)