aboutsummaryrefslogtreecommitdiffstats
path: root/src/ncm/pkg/networkintents/providernet.go
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/ncm/pkg/networkintents/providernet.go
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/ncm/pkg/networkintents/providernet.go')
-rw-r--r--src/ncm/pkg/networkintents/providernet.go48
1 files changed, 41 insertions, 7 deletions
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;")
}