requestBody:
content: {}
- /projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}/destroy:
+ /projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}/terminate:
parameters:
- $ref: '#/components/parameters/projectName'
- $ref: '#/components/parameters/compositeAppName'
post:
tags:
- Deployment Lifecycle
- summary: Destroy a Deployment
- description: Destroy a Deployment
- operationId: destroyDeploymentIntentGroup
+ summary: Terminate a Deployment
+ description: Terminate a Deployment
+ operationId: terminateDeploymentIntentGroup
responses:
'200':
description: Success
required: true
schema:
type: string
- maxLength: 128
\ No newline at end of file
+ maxLength: 128
deleteOrchestratorData
}
function instantiate {
- # call_api -d "{ }" "${base_url_orchestrator}/projects/${projectname}/composite-apps/${vfw_compositeapp_name}/${vfw_compositeapp_version}/deployment-intent-groups/${deployment_intent_group_name}/approve"
+ call_api -d "{ }" "${base_url_orchestrator}/projects/${projectname}/composite-apps/${vfw_compositeapp_name}/${vfw_compositeapp_version}/deployment-intent-groups/${deployment_intent_group_name}/approve"
call_api -d "{ }" "${base_url_orchestrator}/projects/${projectname}/composite-apps/${operators_compositeapp_name}/${compositeapp_version}/deployment-intent-groups/${deployment_intent_group_name}/instantiate"
}
#BEGIN: Instantiation
print_msg "Getting the sorted templates for each of the apps.."
+call_api -d "" "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/deployment-intent-groups/${deploymentIntentGroupName}/approve"
call_api -d "" "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/deployment-intent-groups/${deploymentIntentGroupName}/instantiate"
# END: Instantiation
# }
function instantiate {
- # call_api -d "{ }" "${base_url_orchestrator}/projects/${projectname}/composite-apps/${vfw_compositeapp_name}/${vfw_compositeapp_version}/deployment-intent-groups/${deployment_intent_group_name}/approve"
+ call_api -d "{ }" "${base_url_orchestrator}/projects/${projectname}/composite-apps/${vfw_compositeapp_name}/${vfw_compositeapp_version}/deployment-intent-groups/${deployment_intent_group_name}/approve"
call_api -d "{ }" "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/deployment-intent-groups/${deployment_intent_group_name}/instantiate"
}
}
function instantiate {
+ call_api -d "{ }" "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/deployment-intent-groups/${deployment_intent_group_name}/approve"
call_api -d "{ }" "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/deployment-intent-groups/${deployment_intent_group_name}/instantiate"
}
}
function instantiateVfw {
- # call_api -d "{ }" "${base_url_orchestrator}/projects/${projectname}/composite-apps/${vfw_compositeapp_name}/${vfw_compositeapp_version}/deployment-intent-groups/${deployment_intent_group_name}/approve"
+ call_api -d "{ }" "${base_url_orchestrator}/projects/${projectname}/composite-apps/${vfw_compositeapp_name}/${vfw_compositeapp_version}/deployment-intent-groups/${deployment_intent_group_name}/approve"
call_api -d "{ }" "${base_url_orchestrator}/projects/${projectname}/composite-apps/${vfw_compositeapp_name}/${vfw_compositeapp_version}/deployment-intent-groups/${deployment_intent_group_name}/instantiate"
}
"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"
)
ClusterProviderItems []cluster.ClusterProvider
ClusterItems []cluster.Cluster
ClusterContentItems []cluster.ClusterContent
- ClusterContextItems []appcontext.AppContext
+ ClusterStateInfo []state.StateInfo
ClusterLabelItems []cluster.ClusterLabel
ClusterKvPairsItems []cluster.ClusterKvPairs
ClusterList []string
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) {
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
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"
)
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
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
storeName: "cluster",
tagMeta: "clustermetadata",
tagContent: "clustercontent",
- tagContext: "clustercontext",
+ tagState: "stateInfo",
},
}
}
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
}
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
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)
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
}
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"
)
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)
// 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{
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;")
}
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"
)
// 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,
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 {
// 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{
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;")
}
"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"
)
StoreName: "cluster",
TagMeta: "clustermetadata",
TagContent: "clustercontent",
- TagContext: "clustercontext",
+ TagState: "stateInfo",
},
}
}
// 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
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 {
"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
// 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
}
client: instantiationClient,
}
+ router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}/approve", instantiationHandler.approveHandler).Methods("POST")
+ router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}/terminate", instantiationHandler.terminateHandler).Methods("POST")
router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}/instantiate", instantiationHandler.instantiateHandler).Methods("POST")
router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}/terminate", instantiationHandler.terminateHandler).Methods("POST")
router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}/status", instantiationHandler.statusHandler).Methods("GET")
client moduleLib.InstantiationManager
}
+func (h instantiationHandler) approveHandler(w http.ResponseWriter, r *http.Request) {
+
+ vars := mux.Vars(r)
+ p := vars["project-name"]
+ ca := vars["composite-app-name"]
+ v := vars["composite-app-version"]
+ di := vars["deployment-intent-group-name"]
+
+ iErr := h.client.Approve(p, ca, v, di)
+ if iErr != nil {
+ http.Error(w, iErr.Error(), http.StatusInternalServerError)
+ return
+ }
+ w.WriteHeader(http.StatusAccepted)
+
+}
+
func (h instantiationHandler) instantiateHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
github.com/lib/pq v1.6.0 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
- github.com/onap/multicloud-k8s/src/clm v0.0.0-00010101000000-000000000000
github.com/onap/multicloud-k8s/src/monitor v0.0.0-20200630152613-7c20f73e7c5d
github.com/onap/multicloud-k8s/src/ncm v0.0.0-20200515060444-c77850a75eee
github.com/onap/multicloud-k8s/src/rsync v0.0.0-20200630152613-7c20f73e7c5d
"encoding/json"
"reflect"
- appcontext "github.com/onap/multicloud-k8s/src/orchestrator/pkg/appcontext"
"github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/db"
+ "github.com/onap/multicloud-k8s/src/orchestrator/pkg/state"
pkgerrors "github.com/pkg/errors"
)
type DeploymentIntentGroupManager interface {
CreateDeploymentIntentGroup(d DeploymentIntentGroup, p string, ca string, v string) (DeploymentIntentGroup, error)
GetDeploymentIntentGroup(di string, p string, ca string, v string) (DeploymentIntentGroup, error)
- GetDeploymentIntentGroupContext(di string, p string, ca string, v string) (appcontext.AppContext, string, error)
+ GetDeploymentIntentGroupState(di string, p string, ca string, v string) (state.StateInfo, error)
DeleteDeploymentIntentGroup(di string, p string, ca string, v string) error
GetAllDeploymentIntentGroups(p string, ca string, v string) ([]DeploymentIntentGroup, error)
}
type DeploymentIntentGroupClient struct {
storeName string
tagMetaData string
- tagContext string
+ tagState string
}
// NewDeploymentIntentGroupClient return an instance of DeploymentIntentGroupClient which implements DeploymentIntentGroupManager
return &DeploymentIntentGroupClient{
storeName: "orchestrator",
tagMetaData: "deploymentintentgroupmetadata",
- tagContext: "contextid",
+ tagState: "stateInfo",
}
}
return DeploymentIntentGroup{}, pkgerrors.Wrap(err, "Create DB entry error")
}
+ // Add the stateInfo record
+ stateInfo := state.StateInfo{
+ State: state.StateEnum.Created,
+ ContextId: "",
+ }
+
+ err = db.DBconn.Insert(c.storeName, gkey, nil, c.tagState, stateInfo)
+ if err != nil {
+ return DeploymentIntentGroup{}, pkgerrors.Wrap(err, "Error updating the stateInfo of the DeploymentIntentGroup: "+d.MetaData.Name)
+ }
+
return d, nil
}
}
-// GetDeploymentIntentGroupContext returns the AppContent with a given DeploymentIntentname, project, compositeAppName and version of compositeApp
-func (c *DeploymentIntentGroupClient) GetDeploymentIntentGroupContext(di string, p string, ca string, v string) (appcontext.AppContext, string, error) {
+// GetDeploymentIntentGroupState returns the AppContent with a given DeploymentIntentname, project, compositeAppName and version of compositeApp
+func (c *DeploymentIntentGroupClient) GetDeploymentIntentGroupState(di string, p string, ca string, v string) (state.StateInfo, error) {
key := DeploymentIntentGroupKey{
Name: di,
Version: v,
}
- result, err := db.DBconn.Find(c.storeName, key, c.tagContext)
+ result, err := db.DBconn.Find(c.storeName, key, c.tagState)
if err != nil {
- return appcontext.AppContext{}, "", pkgerrors.Wrap(err, "Get DeploymentIntentGroup Context error")
+ return state.StateInfo{}, pkgerrors.Wrap(err, "Get DeploymentIntentGroup StateInfo error")
}
if result != nil {
- ctxVal := string(result[0])
- var cc appcontext.AppContext
- _, err = cc.LoadAppContext(ctxVal)
+ s := state.StateInfo{}
+ err = db.DBconn.Unmarshal(result[0], &s)
if err != nil {
- return appcontext.AppContext{}, "", pkgerrors.Wrap(err, "Error loading DeploymentIntentGroup Appcontext")
+ return state.StateInfo{}, pkgerrors.Wrap(err, "Unmarshalling DeploymentIntentGroup StateInfo")
}
- return cc, ctxVal, nil
+ return s, nil
}
- return appcontext.AppContext{}, "", pkgerrors.New("Error getting DeploymentIntentGroup AppContext")
+ return state.StateInfo{}, pkgerrors.New("Error getting DeploymentIntentGroup StateInfo")
}
// DeleteDeploymentIntentGroup deletes a DeploymentIntentGroup
CompositeApp: ca,
Version: v,
}
- _, _, err := c.GetDeploymentIntentGroupContext(di, p, ca, v)
- if err == nil {
- return pkgerrors.New("DeploymentIntentGroup must be terminated before it can be deleted " + di)
+ s, err := c.GetDeploymentIntentGroupState(di, p, ca, v)
+ if err == nil && s.State == state.StateEnum.Instantiated {
+ return pkgerrors.Errorf("DeploymentIntentGroup must be terminated before it can be deleted " + di)
}
err = db.DBconn.Remove(c.storeName, k)
gpic "github.com/onap/multicloud-k8s/src/orchestrator/pkg/gpic"
"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"
"github.com/onap/multicloud-k8s/src/orchestrator/utils/helm"
pkgerrors "github.com/pkg/errors"
)
// InstantiationManager is an interface which exposes the
// InstantiationManager functionalities
type InstantiationManager interface {
- //ApproveInstantiation(p string, ca string, v string, di string) (error)
+ Approve(p string, ca string, v string, di string) error
Instantiate(p string, ca string, v string, di string) error
Status(p string, ca string, v string, di string) (StatusData, error)
Terminate(p string, ca string, v string, di string) error
}
-// InstantiationClientDbInfo consists of storeName and tagContext
+// InstantiationClientDbInfo consists of storeName and tagState
type InstantiationClientDbInfo struct {
- storeName string // name of the mongodb collection to use for Instantiationclient documents
- tagContext string // attribute key name for context object in App Context
+ storeName string // name of the mongodb collection to use for Instantiationclient documents
+ tagState string // attribute key name for context object in App Context
}
// NewInstantiationClient returns an instance of InstantiationClient
func NewInstantiationClient() *InstantiationClient {
return &InstantiationClient{
db: InstantiationClientDbInfo{
- storeName: "orchestrator",
- tagContext: "contextid",
+ storeName: "orchestrator",
+ tagState: "stateInfo",
},
}
}
-// TODO
-//ApproveInstantiation approves an instantiation
-// func (c InstantiationClient) ApproveInstantiation(p string, ca string, v string, di string) (error){
-// }
+//Approve approves an instantiation
+func (c InstantiationClient) Approve(p string, ca string, v string, di string) error {
+ s, err := NewDeploymentIntentGroupClient().GetDeploymentIntentGroupState(di, p, ca, v)
+ if err != nil {
+ return pkgerrors.Wrap(err, "DeploymentIntentGroup has no state info: "+di)
+ }
+ switch s.State {
+ case state.StateEnum.Approved:
+ return nil
+ case state.StateEnum.Terminated:
+ break
+ case state.StateEnum.Created:
+ break
+ case state.StateEnum.Applied:
+ return pkgerrors.Errorf("DeploymentIntentGroup is in an invalid state" + s.State)
+ case state.StateEnum.Instantiated:
+ return pkgerrors.Errorf("DeploymentIntentGroup has already been instantiated" + di)
+ default:
+ return pkgerrors.Errorf("DeploymentIntentGroup is in an unknown state" + s.State)
+ }
+
+ key := DeploymentIntentGroupKey{
+ Name: di,
+ Project: p,
+ CompositeApp: ca,
+ Version: v,
+ }
+ stateInfo := state.StateInfo{
+ State: state.StateEnum.Approved,
+ ContextId: "",
+ }
+
+ err = db.DBconn.Insert(c.db.storeName, key, nil, c.db.tagState, stateInfo)
+ if err != nil {
+ return pkgerrors.Wrap(err, "Error updating the stateInfo of the DeploymentIntentGroup: "+di)
+ }
+
+ return nil
+}
func getOverrideValuesByAppName(ov []OverrideValues, a string) map[string]string {
for _, eachOverrideVal := range ov {
return pkgerrors.Wrap(err, "Not finding the deploymentIntentGroup")
}
- _, _, err = NewDeploymentIntentGroupClient().GetDeploymentIntentGroupContext(di, p, ca, v)
- if err == nil {
- return pkgerrors.Errorf("DeploymentIntentGroup has already been instantiated: " + di)
+ s, err := NewDeploymentIntentGroupClient().GetDeploymentIntentGroupState(di, p, ca, v)
+ if err != nil {
+ return pkgerrors.Errorf("Error retrieving DeploymentIntentGroup stateInfo: " + di)
+ }
+ switch s.State {
+ case state.StateEnum.Approved:
+ break
+ case state.StateEnum.Terminated:
+ break // TODO - ideally, should check that all resources have completed being terminated
+ case state.StateEnum.Created:
+ return pkgerrors.Errorf("DeploymentIntentGroup must be Approved before instantiating" + di)
+ case state.StateEnum.Applied:
+ return pkgerrors.Errorf("DeploymentIntentGroup is in an invalid state" + di)
+ case state.StateEnum.Instantiated:
+ return pkgerrors.Errorf("DeploymentIntentGroup has already been instantiated" + di)
+ default:
+ return pkgerrors.Errorf("DeploymentIntentGroup is in an unknown state" + s.State)
}
rName := dIGrp.Spec.Version //rName is releaseName
CompositeApp: ca,
Version: v,
}
-
- err = db.DBconn.Insert(c.db.storeName, key, nil, c.db.tagContext, ctxval)
+ stateInfo := state.StateInfo{
+ State: state.StateEnum.Instantiated,
+ ContextId: ctxval.(string),
+ }
+ err = db.DBconn.Insert(c.db.storeName, key, nil, c.db.tagState, stateInfo)
if err != nil {
cleanuperr := context.DeleteCompositeApp()
if cleanuperr != nil {
*/
func (c InstantiationClient) Status(p string, ca string, v string, di string) (StatusData, error) {
- ac, _, err := NewDeploymentIntentGroupClient().GetDeploymentIntentGroupContext(di, p, ca, v)
+ s, err := NewDeploymentIntentGroupClient().GetDeploymentIntentGroupState(di, p, ca, v)
if err != nil {
return StatusData{}, pkgerrors.Wrap(err, "deploymentIntentGroup not found: "+di)
}
+ ac, err := state.GetAppContextFromStateInfo(s)
+ if err != nil {
+ return StatusData{}, pkgerrors.Wrap(err, "AppContext for deploymentIntentGroup not found: "+di)
+ }
+
// Get all apps in this composite app
allApps, err := NewAppClient().GetApps(p, ca, v)
if err != nil {
*/
func (c InstantiationClient) Terminate(p string, ca string, v string, di string) error {
- ac, ctxval, err := NewDeploymentIntentGroupClient().GetDeploymentIntentGroupContext(di, p, ca, v)
+ s, err := NewDeploymentIntentGroupClient().GetDeploymentIntentGroupState(di, p, ca, v)
+ if err != nil {
+ return pkgerrors.Wrap(err, "DeploymentIntentGroup has no state info: "+di)
+ } else if s.State != state.StateEnum.Instantiated {
+ return pkgerrors.Errorf("DeploymentIntentGroup is not instantiated" + di)
+ }
+
+ ac, err := state.GetAppContextFromStateInfo(s)
if err != nil {
- return pkgerrors.Wrap(err, "DeploymentIntentGroup has no app context: "+di)
+ return pkgerrors.Wrap(err, "AppContext for deploymentIntentGroup not found: "+di)
}
- err = callRsyncUninstall(ctxval)
+ err = callRsyncUninstall(s.ContextId)
if err != nil {
return err
}
CompositeApp: ca,
Version: v,
}
+ stateInfo := state.StateInfo{
+ State: state.StateEnum.Terminated,
+ ContextId: "",
+ }
- err = db.DBconn.RemoveTag(c.db.storeName, key, c.db.tagContext)
+ err = db.DBconn.Insert(c.db.storeName, key, nil, c.db.tagState, stateInfo)
if err != nil {
- return pkgerrors.Wrap(err, "Error removing the app context tag from DeploymentIntentGroup: "+di)
+ return pkgerrors.Wrap(err, "Error updating the stateInfo of the DeploymentIntentGroup: "+di)
}
return nil
--- /dev/null
+/*
+ * Copyright 2020 Intel Corporation, Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package state
+
+import "github.com/onap/multicloud-k8s/src/orchestrator/pkg/appcontext"
+
+// GetAppContextFromStateInfo loads the appcontext present in the StateInfo input
+func GetAppContextFromStateInfo(s StateInfo) (appcontext.AppContext, error) {
+ var cc appcontext.AppContext
+ _, err := cc.LoadAppContext(s.ContextId)
+ if err != nil {
+ return appcontext.AppContext{}, err
+ }
+ return cc, nil
+}
--- /dev/null
+/*
+ * Copyright 2020 Intel Corporation, Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package state
+
+// StateInfo struct is used to maintain the values for state, contextid, (and other)
+// information about resources which can be instantiated via rsync.
+type StateInfo struct {
+ State StateValue
+ ContextId string
+}
+
+type StateValue = string
+
+type states struct {
+ Created StateValue
+ Approved StateValue
+ Applied StateValue
+ Instantiated StateValue
+ Terminated StateValue
+}
+
+var StateEnum = &states{
+ Created: "Created",
+ Approved: "Approved",
+ Applied: "Applied",
+ Instantiated: "Instantiated",
+ Terminated: "Terminated",
+}