summaryrefslogtreecommitdiffstats
path: root/src/ncm
diff options
context:
space:
mode:
Diffstat (limited to 'src/ncm')
-rw-r--r--src/ncm/pkg/module/types/module_definitions.go2
-rw-r--r--src/ncm/pkg/networkintents/network.go40
-rw-r--r--src/ncm/pkg/networkintents/providernet.go48
-rw-r--r--src/ncm/pkg/scheduler/scheduler.go82
4 files changed, 139 insertions, 33 deletions
diff --git a/src/ncm/pkg/module/types/module_definitions.go b/src/ncm/pkg/module/types/module_definitions.go
index 0dd657ac..0c85cdb1 100644
--- a/src/ncm/pkg/module/types/module_definitions.go
+++ b/src/ncm/pkg/module/types/module_definitions.go
@@ -20,5 +20,5 @@ 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 context object in App Context
}
diff --git a/src/ncm/pkg/networkintents/network.go b/src/ncm/pkg/networkintents/network.go
index de8ee504..58480cc8 100644
--- a/src/ncm/pkg/networkintents/network.go
+++ b/src/ncm/pkg/networkintents/network.go
@@ -22,6 +22,7 @@ import (
nettypes "github.com/onap/multicloud-k8s/src/ncm/pkg/networkintents/types"
"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"
)
@@ -89,11 +90,25 @@ func (v *NetworkClient) CreateNetwork(p Network, clusterProvider, cluster string
NetworkName: p.Metadata.Name,
}
- //Check if cluster exists
- _, err := clusterPkg.NewClusterClient().GetCluster(clusterProvider, cluster)
+ //Check if cluster exists and in a state for adding network intents
+ s, err := clusterPkg.NewClusterClient().GetClusterState(clusterProvider, cluster)
if err != nil {
return Network{}, pkgerrors.New("Unable to find the cluster")
}
+ switch s.State {
+ case state.StateEnum.Approved:
+ return Network{}, pkgerrors.Errorf("Cluster is in an invalid state: " + cluster + " " + state.StateEnum.Approved)
+ case state.StateEnum.Terminated:
+ break
+ case state.StateEnum.Created:
+ break
+ case state.StateEnum.Applied:
+ return Network{}, pkgerrors.Errorf("Existing cluster network intents must be terminated before creating: " + cluster)
+ case state.StateEnum.Instantiated:
+ return Network{}, pkgerrors.Errorf("Cluster is in an invalid state: " + cluster + " " + state.StateEnum.Instantiated)
+ default:
+ return Network{}, pkgerrors.Errorf("Cluster is in an invalid state: " + cluster + " " + s.State)
+ }
//Check if this Network already exists
_, err = v.GetNetwork(p.Metadata.Name, clusterProvider, cluster)
@@ -167,6 +182,25 @@ func (v *NetworkClient) GetNetworks(clusterProvider, cluster string) ([]Network,
// Delete the Network from database
func (v *NetworkClient) DeleteNetwork(name, clusterProvider, cluster string) error {
+ // verify cluster is in a state where network intent can be deleted
+ s, err := clusterPkg.NewClusterClient().GetClusterState(clusterProvider, cluster)
+ if err != nil {
+ return pkgerrors.New("Unable to find the cluster")
+ }
+ switch s.State {
+ case state.StateEnum.Approved:
+ return pkgerrors.Errorf("Cluster is in an invalid state: " + cluster + " " + state.StateEnum.Approved)
+ case state.StateEnum.Terminated:
+ break
+ case state.StateEnum.Created:
+ break
+ case state.StateEnum.Applied:
+ return pkgerrors.Errorf("Cluster network intents must be terminated before deleting: " + cluster)
+ case state.StateEnum.Instantiated:
+ return pkgerrors.Errorf("Cluster is in an invalid state: " + cluster + " " + state.StateEnum.Instantiated)
+ default:
+ return pkgerrors.Errorf("Cluster is in an invalid state: " + cluster + " " + s.State)
+ }
//Construct key and tag to select the entry
key := NetworkKey{
@@ -175,7 +209,7 @@ func (v *NetworkClient) DeleteNetwork(name, clusterProvider, cluster string) err
NetworkName: name,
}
- err := db.DBconn.Remove(v.db.StoreName, key)
+ err = db.DBconn.Remove(v.db.StoreName, key)
if err != nil {
return pkgerrors.Wrap(err, "Delete Network Entry;")
}
diff --git a/src/ncm/pkg/networkintents/providernet.go b/src/ncm/pkg/networkintents/providernet.go
index 072e07f6..dbe6e46c 100644
--- a/src/ncm/pkg/networkintents/providernet.go
+++ b/src/ncm/pkg/networkintents/providernet.go
@@ -22,6 +22,7 @@ import (
nettypes "github.com/onap/multicloud-k8s/src/ncm/pkg/networkintents/types"
"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"
)
@@ -84,6 +85,26 @@ func NewProviderNetClient() *ProviderNetClient {
// CreateProviderNet - create a new ProviderNet
func (v *ProviderNetClient) CreateProviderNet(p ProviderNet, clusterProvider, cluster string, exists bool) (ProviderNet, error) {
+ // verify cluster exists and in state to add provider networks
+ s, err := clusterPkg.NewClusterClient().GetClusterState(clusterProvider, cluster)
+ if err != nil {
+ return ProviderNet{}, pkgerrors.New("Unable to find the cluster")
+ }
+ switch s.State {
+ case state.StateEnum.Approved:
+ return ProviderNet{}, pkgerrors.Wrap(err, "Cluster is in an invalid state: "+cluster+" "+state.StateEnum.Approved)
+ case state.StateEnum.Terminated:
+ break
+ case state.StateEnum.Created:
+ break
+ case state.StateEnum.Applied:
+ return ProviderNet{}, pkgerrors.Wrap(err, "Existing cluster provider network intents must be terminated before creating: "+cluster)
+ case state.StateEnum.Instantiated:
+ return ProviderNet{}, pkgerrors.Wrap(err, "Cluster is in an invalid state: "+cluster+" "+state.StateEnum.Instantiated)
+ default:
+ return ProviderNet{}, pkgerrors.Wrap(err, "Cluster is in an invalid state: "+cluster+" "+s.State)
+ }
+
//Construct key and tag to select the entry
key := ProviderNetKey{
ClusterProviderName: clusterProvider,
@@ -91,12 +112,6 @@ func (v *ProviderNetClient) CreateProviderNet(p ProviderNet, clusterProvider, cl
ProviderNetName: p.Metadata.Name,
}
- //Check if cluster exists
- _, err := clusterPkg.NewClusterClient().GetCluster(clusterProvider, cluster)
- if err != nil {
- return ProviderNet{}, pkgerrors.New("Unable to find the cluster")
- }
-
//Check if this ProviderNet already exists
_, err = v.GetProviderNet(p.Metadata.Name, clusterProvider, cluster)
if err == nil && !exists {
@@ -169,6 +184,25 @@ func (v *ProviderNetClient) GetProviderNets(clusterProvider, cluster string) ([]
// Delete the ProviderNet from database
func (v *ProviderNetClient) DeleteProviderNet(name, clusterProvider, cluster string) error {
+ // verify cluster is in a state where provider network intent can be deleted
+ s, err := clusterPkg.NewClusterClient().GetClusterState(clusterProvider, cluster)
+ if err != nil {
+ return pkgerrors.New("Unable to find the cluster")
+ }
+ switch s.State {
+ case state.StateEnum.Approved:
+ return pkgerrors.Wrap(err, "Cluster is in an invalid state: "+cluster+" "+state.StateEnum.Approved)
+ case state.StateEnum.Terminated:
+ break
+ case state.StateEnum.Created:
+ break
+ case state.StateEnum.Applied:
+ return pkgerrors.Wrap(err, "Cluster provider network intents must be terminated before deleting: "+cluster)
+ case state.StateEnum.Instantiated:
+ return pkgerrors.Wrap(err, "Cluster is in an invalid state: "+cluster+" "+state.StateEnum.Instantiated)
+ default:
+ return pkgerrors.Wrap(err, "Cluster is in an invalid state: "+cluster+" "+s.State)
+ }
//Construct key and tag to select the entry
key := ProviderNetKey{
@@ -177,7 +211,7 @@ func (v *ProviderNetClient) DeleteProviderNet(name, clusterProvider, cluster str
ProviderNetName: name,
}
- err := db.DBconn.Remove(v.db.StoreName, key)
+ err = db.DBconn.Remove(v.db.StoreName, key)
if err != nil {
return pkgerrors.Wrap(err, "Delete ProviderNet Entry;")
}
diff --git a/src/ncm/pkg/scheduler/scheduler.go b/src/ncm/pkg/scheduler/scheduler.go
index 4886a67e..8ced68b8 100644
--- a/src/ncm/pkg/scheduler/scheduler.go
+++ b/src/ncm/pkg/scheduler/scheduler.go
@@ -27,6 +27,7 @@ import (
"github.com/onap/multicloud-k8s/src/orchestrator/pkg/grpc/installappclient"
"github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/db"
log "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/logutils"
+ "github.com/onap/multicloud-k8s/src/orchestrator/pkg/state"
pkgerrors "github.com/pkg/errors"
)
@@ -51,7 +52,7 @@ func NewSchedulerClient() *SchedulerClient {
StoreName: "cluster",
TagMeta: "clustermetadata",
TagContent: "clustercontent",
- TagContext: "clustercontext",
+ TagState: "stateInfo",
},
}
}
@@ -59,9 +60,23 @@ func NewSchedulerClient() *SchedulerClient {
// Apply Network Intents associated with a cluster
func (v *SchedulerClient) ApplyNetworkIntents(clusterProvider, cluster string) error {
- _, _, err := clusterPkg.NewClusterClient().GetClusterContext(clusterProvider, cluster)
- if err == nil {
- return pkgerrors.Errorf("Cluster network intents have already been applied: %v, %v", clusterProvider, cluster)
+ s, err := clusterPkg.NewClusterClient().GetClusterState(clusterProvider, cluster)
+ if err != nil {
+ return pkgerrors.Errorf("Error finding cluster: %v %v", clusterProvider, cluster)
+ }
+ switch s.State {
+ case state.StateEnum.Approved:
+ return pkgerrors.Wrap(err, "Cluster is in an invalid state: "+cluster+" "+state.StateEnum.Approved)
+ case state.StateEnum.Terminated:
+ break
+ case state.StateEnum.Created:
+ break
+ case state.StateEnum.Applied:
+ return nil
+ case state.StateEnum.Instantiated:
+ return pkgerrors.Wrap(err, "Cluster is in an invalid state: "+cluster+" "+state.StateEnum.Instantiated)
+ default:
+ return pkgerrors.Wrap(err, "Cluster is in an invalid state: "+cluster+" "+s.State)
}
// Make an app context for the network intent resources
@@ -135,12 +150,17 @@ func (v *SchedulerClient) ApplyNetworkIntents(clusterProvider, cluster string) e
return pkgerrors.Wrap(err, "Error adding Cluster to AppContext")
}
- // save the context in the cluster db record
+ // update the StateInfo in the cluster db record
key := clusterPkg.ClusterKey{
ClusterProviderName: clusterProvider,
ClusterName: cluster,
}
- err = db.DBconn.Insert(v.db.StoreName, key, nil, v.db.TagContext, ctxVal)
+ stateInfo := state.StateInfo{
+ State: state.StateEnum.Applied,
+ ContextId: ctxVal.(string),
+ }
+
+ err = db.DBconn.Insert(v.db.StoreName, key, nil, v.db.TagState, stateInfo)
if err != nil {
cleanuperr := ac.DeleteCompositeApp()
if cleanuperr != nil {
@@ -149,7 +169,7 @@ func (v *SchedulerClient) ApplyNetworkIntents(clusterProvider, cluster string) e
"cluster": cluster,
})
}
- return pkgerrors.Wrap(err, "Error adding AppContext to DB")
+ return pkgerrors.Wrap(err, "Error updating the stateInfo of cluster: "+cluster)
}
// call resource synchronizer to instantiate the CRs in the cluster
@@ -163,37 +183,55 @@ func (v *SchedulerClient) ApplyNetworkIntents(clusterProvider, cluster string) e
// Terminate Network Intents associated with a cluster
func (v *SchedulerClient) TerminateNetworkIntents(clusterProvider, cluster string) error {
- context, ctxVal, err := clusterPkg.NewClusterClient().GetClusterContext(clusterProvider, cluster)
+ s, err := clusterPkg.NewClusterClient().GetClusterState(clusterProvider, cluster)
if err != nil {
- return pkgerrors.Wrapf(err, "Error finding AppContext for cluster: %v, %v", clusterProvider, cluster)
+ return pkgerrors.Wrapf(err, "Error finding StateInfo for cluster: %v, %v", clusterProvider, cluster)
+ }
+ switch s.State {
+ case state.StateEnum.Approved:
+ return pkgerrors.Wrap(err, "Cluster is in an invalid state: "+cluster+" "+state.StateEnum.Approved)
+ case state.StateEnum.Terminated:
+ return nil
+ case state.StateEnum.Created:
+ return pkgerrors.Wrap(err, "Cluster network intents have not been applied: "+cluster)
+ case state.StateEnum.Applied:
+ break
+ case state.StateEnum.Instantiated:
+ return pkgerrors.Wrap(err, "Cluster is in an invalid state: "+cluster+" "+state.StateEnum.Instantiated)
+ default:
+ return pkgerrors.Wrap(err, "Cluster is in an invalid state: "+cluster+" "+s.State)
}
// call resource synchronizer to terminate the CRs in the cluster
- err = installappclient.InvokeUninstallApp(ctxVal)
+ err = installappclient.InvokeUninstallApp(s.ContextId)
if err != nil {
return err
}
// remove the app context
- cleanuperr := context.DeleteCompositeApp()
- if cleanuperr != nil {
- log.Warn("Error deleted AppContext", log.Fields{
- "cluster-provider": clusterProvider,
- "cluster": cluster,
- })
+ context, err := state.GetAppContextFromStateInfo(s)
+ if err != nil {
+ return pkgerrors.Wrap(err, "Error getting appcontext from cluster StateInfo : "+clusterProvider+" "+cluster)
+ }
+ err = context.DeleteCompositeApp()
+ if err != nil {
+ return pkgerrors.Wrap(err, "Error deleting appcontext of cluster : "+clusterProvider+" "+cluster)
}
- // remove the app context field from the cluster db record
+ // update StateInfo
key := clusterPkg.ClusterKey{
ClusterProviderName: clusterProvider,
ClusterName: cluster,
}
- err = db.DBconn.RemoveTag(v.db.StoreName, key, v.db.TagContext)
+ stateInfo := state.StateInfo{
+ State: state.StateEnum.Terminated,
+ ContextId: "",
+ }
+
+ err = db.DBconn.Insert(v.db.StoreName, key, nil, v.db.TagState, stateInfo)
if err != nil {
- log.Warn("Error removing AppContext from Cluster document", log.Fields{
- "cluster-provider": clusterProvider,
- "cluster": cluster,
- })
+ return pkgerrors.Wrap(err, "Error updating the stateInfo of cluster: "+cluster)
}
+
return nil
}