From b2c9f4c61d00bf18e7a253c410479f8124640106 Mon Sep 17 00:00:00 2001 From: Rajamohan Raj Date: Wed, 26 Aug 2020 00:28:12 +0000 Subject: Adding validations for all JSON data across modules Issue-ID: MULTICLOUD-1198 Signed-off-by: Rajamohan Raj Change-Id: Idc2fbfd6e875bd7b662c7d60925aeb776b3f7bea --- src/clm/api/clusterhandler.go | 31 +++++ src/clm/api/clusterhandler_test.go | 6 + src/clm/json-schemas/cluster-kv.json | 54 +++++++++ src/clm/json-schemas/cluster-label.json | 13 ++ src/clm/json-schemas/metadata.json | 37 ++++++ src/ncm/api/networkhandler.go | 9 ++ src/ncm/api/providernethandler.go | 8 ++ src/ncm/json-schemas/provider-network.json | 122 +++++++++++++++++++ src/ncm/json-schemas/virtual-network.json | 75 ++++++++++++ src/orchestrator/api/add_intents_handler.go | 5 +- src/orchestrator/api/app_intent_handler.go | 5 +- src/orchestrator/api/app_profilehandler.go | 5 +- src/orchestrator/api/apphandler.go | 5 +- src/orchestrator/api/composite_app_handler.go | 5 +- src/orchestrator/api/composite_profilehandler.go | 5 +- .../api/composite_profilehandler_test.go | 4 + src/orchestrator/api/controllerhandler.go | 5 +- src/orchestrator/api/controllerhandler_test.go | 4 + .../api/deployment_intent_groups_handler.go | 5 +- .../api/generic_placement_intent_handler.go | 5 +- src/orchestrator/api/json-schemas/cluster-kv.json | 54 --------- .../api/json-schemas/cluster-label.json | 13 -- .../api/json-schemas/composite-app.json | 45 ------- .../api/json-schemas/composite-profile.json | 46 -------- src/orchestrator/api/json-schemas/controller.json | 73 ------------ .../api/json-schemas/deployment-group-intent.json | 79 ------------- .../api/json-schemas/deployment-intent.json | 55 --------- .../json-schemas/generic-placement-intent-app.json | 117 ------------------ .../api/json-schemas/generic-placement-intent.json | 51 -------- src/orchestrator/api/json-schemas/metadata.json | 37 ------ .../api/json-schemas/network-load-interface.json | 77 ------------ .../api/json-schemas/network-workload.json | 67 ----------- .../api/json-schemas/provider-network.json | 122 ------------------- .../api/json-schemas/virtual-network.json | 75 ------------ src/orchestrator/api/projecthandler.go | 6 +- src/orchestrator/api/projecthandler_test.go | 4 + src/orchestrator/json-schemas/composite-app.json | 45 +++++++ .../json-schemas/composite-profile.json | 46 ++++++++ src/orchestrator/json-schemas/controller.json | 73 ++++++++++++ .../json-schemas/deployment-group-intent.json | 79 +++++++++++++ .../json-schemas/deployment-intent.json | 55 +++++++++ .../json-schemas/generic-placement-intent-app.json | 117 ++++++++++++++++++ .../json-schemas/generic-placement-intent.json | 51 ++++++++ src/orchestrator/json-schemas/metadata.json | 37 ++++++ src/orchestrator/scripts/start-dev.sh | 2 +- src/ovnaction/api/netcontrolintenthandler.go | 13 ++ src/ovnaction/api/workloadifintenthandler.go | 8 ++ src/ovnaction/api/workloadintenthandler.go | 8 ++ src/ovnaction/json-schemas/metadata.json | 37 ++++++ .../json-schemas/network-load-interface.json | 77 ++++++++++++ src/ovnaction/json-schemas/network-workload.json | 67 +++++++++++ src/tools/emcoctl/Readme.md | 131 +++++++++++++++++++++ src/tools/emcoctl/examples/emco-cfg.yaml | 6 +- src/tools/emcoctl/examples/test.yaml | 17 +-- src/tools/emcoctl/examples/vfw.yaml | 34 +++--- 55 files changed, 1273 insertions(+), 959 deletions(-) create mode 100644 src/clm/json-schemas/cluster-kv.json create mode 100644 src/clm/json-schemas/cluster-label.json create mode 100644 src/clm/json-schemas/metadata.json create mode 100644 src/ncm/json-schemas/provider-network.json create mode 100644 src/ncm/json-schemas/virtual-network.json delete mode 100644 src/orchestrator/api/json-schemas/cluster-kv.json delete mode 100644 src/orchestrator/api/json-schemas/cluster-label.json delete mode 100644 src/orchestrator/api/json-schemas/composite-app.json delete mode 100644 src/orchestrator/api/json-schemas/composite-profile.json delete mode 100644 src/orchestrator/api/json-schemas/controller.json delete mode 100644 src/orchestrator/api/json-schemas/deployment-group-intent.json delete mode 100644 src/orchestrator/api/json-schemas/deployment-intent.json delete mode 100644 src/orchestrator/api/json-schemas/generic-placement-intent-app.json delete mode 100644 src/orchestrator/api/json-schemas/generic-placement-intent.json delete mode 100644 src/orchestrator/api/json-schemas/metadata.json delete mode 100644 src/orchestrator/api/json-schemas/network-load-interface.json delete mode 100644 src/orchestrator/api/json-schemas/network-workload.json delete mode 100644 src/orchestrator/api/json-schemas/provider-network.json delete mode 100644 src/orchestrator/api/json-schemas/virtual-network.json create mode 100644 src/orchestrator/json-schemas/composite-app.json create mode 100644 src/orchestrator/json-schemas/composite-profile.json create mode 100644 src/orchestrator/json-schemas/controller.json create mode 100644 src/orchestrator/json-schemas/deployment-group-intent.json create mode 100644 src/orchestrator/json-schemas/deployment-intent.json create mode 100644 src/orchestrator/json-schemas/generic-placement-intent-app.json create mode 100644 src/orchestrator/json-schemas/generic-placement-intent.json create mode 100644 src/orchestrator/json-schemas/metadata.json create mode 100644 src/ovnaction/json-schemas/metadata.json create mode 100644 src/ovnaction/json-schemas/network-load-interface.json create mode 100644 src/ovnaction/json-schemas/network-workload.json (limited to 'src') diff --git a/src/clm/api/clusterhandler.go b/src/clm/api/clusterhandler.go index 84dd3230..75fcc561 100644 --- a/src/clm/api/clusterhandler.go +++ b/src/clm/api/clusterhandler.go @@ -28,10 +28,16 @@ import ( "net/textproto" clusterPkg "github.com/onap/multicloud-k8s/src/clm/pkg/cluster" + "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/validation" "github.com/gorilla/mux" ) +var cpJSONFile string = "json-schemas/metadata.json" +var ckvJSONFile string = "json-schemas/cluster-kv.json" +var clJSONFile string = "json-schemas/cluster-label.json" + + // Used to store backend implementations objects // Also simplifies mocking for unit testing purposes type clusterHandler struct { @@ -55,6 +61,12 @@ func (h clusterHandler) createClusterProviderHandler(w http.ResponseWriter, r *h return } + err, httpError := validation.ValidateJsonSchemaData(cpJSONFile, p) + if err != nil { + http.Error(w, err.Error(), httpError) + return + } + // Name is required. if p.Metadata.Name == "" { http.Error(w, "Missing name in POST request", http.StatusBadRequest) @@ -148,6 +160,12 @@ func (h clusterHandler) createClusterHandler(w http.ResponseWriter, r *http.Requ return } + err, httpError := validation.ValidateJsonSchemaData(cpJSONFile, p) + if err != nil { + http.Error(w, err.Error(), httpError) + return + } + //Read the file section and ignore the header file, _, err := r.FormFile("file") if err != nil { @@ -333,6 +351,12 @@ func (h clusterHandler) createClusterLabelHandler(w http.ResponseWriter, r *http err := json.NewDecoder(r.Body).Decode(&p) + err, httpError := validation.ValidateJsonSchemaData(clJSONFile, p) + if err != nil { + http.Error(w, err.Error(), httpError) + return + } + // LabelName is required. if p.LabelName == "" { http.Error(w, "Missing label name in POST request", http.StatusBadRequest) @@ -413,6 +437,13 @@ func (h clusterHandler) createClusterKvPairsHandler(w http.ResponseWriter, r *ht err := json.NewDecoder(r.Body).Decode(&p) + // Verify JSON Body + err, httpError := validation.ValidateJsonSchemaData(ckvJSONFile, p) + if err != nil { + http.Error(w, err.Error(), httpError) + return + } + // KvPairsName is required. if p.Metadata.Name == "" { http.Error(w, "Missing Key Value pair name in POST request", http.StatusBadRequest) diff --git a/src/clm/api/clusterhandler_test.go b/src/clm/api/clusterhandler_test.go index 076718df..a866835b 100644 --- a/src/clm/api/clusterhandler_test.go +++ b/src/clm/api/clusterhandler_test.go @@ -186,6 +186,12 @@ func (m *mockClusterManager) DeleteClusterKvPairs(provider, clusterName, kvpair return m.Err } +func init() { + cpJSONFile = "../json-schemas/metadata.json" + ckvJSONFile = "../json-schemas/cluster-kv.json" + clJSONFile = "../json-schemas/cluster-label.json" +} + func TestClusterProviderCreateHandler(t *testing.T) { testCases := []struct { label string diff --git a/src/clm/json-schemas/cluster-kv.json b/src/clm/json-schemas/cluster-kv.json new file mode 100644 index 00000000..c7013bab --- /dev/null +++ b/src/clm/json-schemas/cluster-kv.json @@ -0,0 +1,54 @@ +{ + "$schema": "http://json-schema.org/schema#", + "type": "object", + "properties": { + "spec": { + "required": [ + "kv" + ], + "type": "object", + "properties": { + "kv": { + "items": { + "additionalProperties": { + "type": "string", + "maxLength": 128 + }, + "type": "object" + }, + "type": "array" + } + } + }, + "metadata": { + "required": ["name"], + "properties": { + "userData2": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some more data", + "maxLength": 512 + }, + "userData1": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some data", + "maxLength": 512 + }, + "name": { + "description": "Name of the resource", + "type": "string", + "example": "ResName", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + }, + "description": { + "description": "Description for the resource", + "type": "string", + "example": "Resource description", + "maxLength": 1024 + } + } + } + } + } \ No newline at end of file diff --git a/src/clm/json-schemas/cluster-label.json b/src/clm/json-schemas/cluster-label.json new file mode 100644 index 00000000..22267b3d --- /dev/null +++ b/src/clm/json-schemas/cluster-label.json @@ -0,0 +1,13 @@ +{ + "$schema": "http://json-schema.org/schema#", + "type": "object", + "properties": { + "label-name": { + "description": "Logical Cloud to use for this intent", + "type": "string", + "example": "cluster-label-1", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + } + } + } \ No newline at end of file diff --git a/src/clm/json-schemas/metadata.json b/src/clm/json-schemas/metadata.json new file mode 100644 index 00000000..960545ee --- /dev/null +++ b/src/clm/json-schemas/metadata.json @@ -0,0 +1,37 @@ + +{ + "$schema": "http://json-schema.org/schema#", + "type": "object", + "properties": { + "metadata": { + "required": ["name"], + "properties": { + "userData2": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some more data", + "maxLength": 512 + }, + "userData1": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some data", + "maxLength": 512 + }, + "name": { + "description": "Name of the resource", + "type": "string", + "example": "ResName", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + }, + "description": { + "description": "Description for the resource", + "type": "string", + "example": "Resource description", + "maxLength": 1024 + } + } + } + } + } \ No newline at end of file diff --git a/src/ncm/api/networkhandler.go b/src/ncm/api/networkhandler.go index ed266697..6f305be1 100644 --- a/src/ncm/api/networkhandler.go +++ b/src/ncm/api/networkhandler.go @@ -30,6 +30,9 @@ import ( "github.com/gorilla/mux" ) +var vnJSONFile string = "json-schemas/virtual-network.json" + + // Used to store backend implementations objects // Also simplifies mocking for unit testing purposes type networkHandler struct { @@ -86,6 +89,12 @@ func (h networkHandler) createNetworkHandler(w http.ResponseWriter, r *http.Requ return } + err, httpError := validation.ValidateJsonSchemaData(vnJSONFile, p) +if err != nil { + http.Error(w, err.Error(), httpError) + return +} + // Name is required. if p.Metadata.Name == "" { http.Error(w, "Missing name in POST request", http.StatusBadRequest) diff --git a/src/ncm/api/providernethandler.go b/src/ncm/api/providernethandler.go index 66a41a4d..48d5d7ea 100644 --- a/src/ncm/api/providernethandler.go +++ b/src/ncm/api/providernethandler.go @@ -31,6 +31,8 @@ import ( "github.com/gorilla/mux" ) +var pnetJSONFile string = "json-schemas/provider-network.json" + // Used to store backend implementations objects // Also simplifies mocking for unit testing purposes type providernetHandler struct { @@ -139,6 +141,12 @@ func (h providernetHandler) createProviderNetHandler(w http.ResponseWriter, r *h return } + err, httpError := validation.ValidateJsonSchemaData(pnetJSONFile, p) +if err != nil { + http.Error(w, err.Error(), httpError) + return +} + // Name is required. if p.Metadata.Name == "" { http.Error(w, "Missing name in POST request", http.StatusBadRequest) diff --git a/src/ncm/json-schemas/provider-network.json b/src/ncm/json-schemas/provider-network.json new file mode 100644 index 00000000..0aef0304 --- /dev/null +++ b/src/ncm/json-schemas/provider-network.json @@ -0,0 +1,122 @@ +{ + "$schema": "http://json-schema.org/schema#", + "type": "object", + "properties": { + "spec": { + "required": [ + "cniType", + "ipv4Subnets", + "providerNetType", + "vlan" + ], + "type": "object", + "properties": { + "ipv4Subnets": { + "items": { + "required": [ + "name", + "subnet" + ], + "type": "object", + "properties": { + "subnet": { + "type": "string", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + }, + "excludeIps": { + "type": "string", + "maxLength": 128 + }, + "gateway": { + "type": "string", + "maxLength": 128 + }, + "name": { + "type": "string", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + } + } + }, + "type": "array" + }, + "cniType": { + "type": "string", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + }, + "vlan": { + "required": [ + "logicalInterfaceName", + "nodeLabelList", + "providerInterfaceName", + "vlanID", + "vlanNodeSelector" + ], + "type": "object", + "properties": { + "vlanNodeSelector": { + "type": "string", + "maxLength": 128 + }, + "nodeLabelList": { + "items": { + "type": "string", + "maxLength": 128 + }, + "type": "array" + }, + "providerInterfaceName": { + "type": "string", + "maxLength": 128 + }, + "vlanID": { + "type": "string", + "maxLength": 128 + }, + "logicalInterfaceName": { + "type": "string", + "maxLength": 128 + } + } + }, + "providerNetType": { + "type": "string", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + } + } + }, + "metadata": { + "required": ["name"], + "properties": { + "userData2": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some more data", + "maxLength": 512 + }, + "userData1": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some data", + "maxLength": 512 + }, + "name": { + "description": "Name of the resource", + "type": "string", + "example": "ResName", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + }, + "description": { + "description": "Description for the resource", + "type": "string", + "example": "Resource description", + "maxLength": 1024 + } + } + } + } +} \ No newline at end of file diff --git a/src/ncm/json-schemas/virtual-network.json b/src/ncm/json-schemas/virtual-network.json new file mode 100644 index 00000000..f2bc9d3d --- /dev/null +++ b/src/ncm/json-schemas/virtual-network.json @@ -0,0 +1,75 @@ +{ + "$schema": "http://json-schema.org/schema#", + "type": "object", + "properties": { + "spec": { + "properties": { + "ipv4Subnets": { + "items": { + "required": [ + "name", + "subnet" + ], + "type": "object", + "properties": { + "subnet": { + "type": "string", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + }, + "excludeIps": { + "type": "string", + "maxLength": 1024 + }, + "gateway": { + "type": "string", + "maxLength": 128 + }, + "name": { + "type": "string", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + } + } + }, + "type": "array" + }, + "cniType": { + "type": "string", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + } + } + }, + "metadata": { + "required": ["name"], + "properties": { + "userData2": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some more data", + "maxLength": 512 + }, + "userData1": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some data", + "maxLength": 512 + }, + "name": { + "description": "Name of the resource", + "type": "string", + "example": "ResName", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + }, + "description": { + "description": "Description for the resource", + "type": "string", + "example": "Resource description", + "maxLength": 1024 + } + } + } + } +} \ No newline at end of file diff --git a/src/orchestrator/api/add_intents_handler.go b/src/orchestrator/api/add_intents_handler.go index 21a33739..66f3839a 100644 --- a/src/orchestrator/api/add_intents_handler.go +++ b/src/orchestrator/api/add_intents_handler.go @@ -27,6 +27,8 @@ import ( "github.com/gorilla/mux" ) +var addIntentJSONFile string = "json-schemas/deployment-intent.json" + type intentHandler struct { client moduleLib.IntentManager } @@ -46,9 +48,8 @@ func (h intentHandler) addIntentHandler(w http.ResponseWriter, r *http.Request) return } - jsonFile := "json-schemas/deployment-intent.json" // Verify JSON Body - err, httpError := validation.ValidateJsonSchemaData(jsonFile, i) + err, httpError := validation.ValidateJsonSchemaData(addIntentJSONFile, i) if err != nil { http.Error(w, err.Error(), httpError) return diff --git a/src/orchestrator/api/app_intent_handler.go b/src/orchestrator/api/app_intent_handler.go index a51b9b92..1d48f8a6 100644 --- a/src/orchestrator/api/app_intent_handler.go +++ b/src/orchestrator/api/app_intent_handler.go @@ -26,6 +26,8 @@ import ( moduleLib "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module" ) +var appIntentJSONFile string = "json-schemas/generic-placement-intent-app.json" + /* Used to store backend implementation objects Also simplifies mocking for unit testing purposes */ @@ -48,9 +50,8 @@ func (h appIntentHandler) createAppIntentHandler(w http.ResponseWriter, r *http. return } - jsonFile := "json-schemas/generic-placement-intent-app.json" // Verify JSON Body - err, httpError := validation.ValidateJsonSchemaData(jsonFile, a) + err, httpError := validation.ValidateJsonSchemaData(appIntentJSONFile, a) if err != nil { http.Error(w, err.Error(), httpError) return diff --git a/src/orchestrator/api/app_profilehandler.go b/src/orchestrator/api/app_profilehandler.go index 2fa0f26d..58cd2145 100644 --- a/src/orchestrator/api/app_profilehandler.go +++ b/src/orchestrator/api/app_profilehandler.go @@ -34,6 +34,8 @@ import ( pkgerrors "github.com/pkg/errors" ) +var appProfileJSONFile string = "json-schemas/metadata.json" + /* Used to store backend implementation objects Also simplifies mocking for unit testing purposes */ @@ -73,9 +75,8 @@ func (h appProfileHandler) createAppProfileHandler(w http.ResponseWriter, r *htt return } - jsonFile := "json-schemas/metadata.json" // Verify JSON Body - err, httpError := validation.ValidateJsonSchemaData(jsonFile, ap) + err, httpError := validation.ValidateJsonSchemaData(appProfileJSONFile, ap) if err != nil { http.Error(w, err.Error(), httpError) return diff --git a/src/orchestrator/api/apphandler.go b/src/orchestrator/api/apphandler.go index 7d901a8f..7429f5c2 100644 --- a/src/orchestrator/api/apphandler.go +++ b/src/orchestrator/api/apphandler.go @@ -33,6 +33,8 @@ import ( "github.com/gorilla/mux" ) +var appJSONFile string = "json-schemas/metadata.json" + // appHandler to store backend implementations objects // Also simplifies mocking for unit testing purposes type appHandler struct { @@ -70,9 +72,8 @@ func (h appHandler) createAppHandler(w http.ResponseWriter, r *http.Request) { return } - jsonFile := "json-schemas/metadata.json" // Verify JSON Body - err, httpError := validation.ValidateJsonSchemaData(jsonFile, a) + err, httpError := validation.ValidateJsonSchemaData(appJSONFile, a) if err != nil { http.Error(w, err.Error(), httpError) return diff --git a/src/orchestrator/api/composite_app_handler.go b/src/orchestrator/api/composite_app_handler.go index 1e69c353..d531b28d 100644 --- a/src/orchestrator/api/composite_app_handler.go +++ b/src/orchestrator/api/composite_app_handler.go @@ -26,6 +26,8 @@ import ( moduleLib "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module" ) +var caJSONFile string = "json-schemas/composite-app.json" + // compositeAppHandler to store backend implementations objects // Also simplifies mocking for unit testing purposes type compositeAppHandler struct { @@ -47,9 +49,8 @@ func (h compositeAppHandler) createHandler(w http.ResponseWriter, r *http.Reques http.Error(w, err.Error(), http.StatusUnprocessableEntity) return } - jsonFile := "json-schemas/composite-app.json" // Verify JSON Body - err, httpError := validation.ValidateJsonSchemaData(jsonFile, c) + err, httpError := validation.ValidateJsonSchemaData(caJSONFile, c) if err != nil { http.Error(w, err.Error(), httpError) return diff --git a/src/orchestrator/api/composite_profilehandler.go b/src/orchestrator/api/composite_profilehandler.go index 5a3fb19c..de1c8f2d 100644 --- a/src/orchestrator/api/composite_profilehandler.go +++ b/src/orchestrator/api/composite_profilehandler.go @@ -27,6 +27,8 @@ import ( "github.com/gorilla/mux" ) +var caprofileJSONFile string = "json-schemas/metadata.json" + /* Used to store backend implementation objects Also simplifies mocking for unit testing purposes */ @@ -49,9 +51,8 @@ func (h compositeProfileHandler) createHandler(w http.ResponseWriter, r *http.Re return } - jsonFile := "json-schemas/metadata.json" // Verify JSON Body - err, httpError := validation.ValidateJsonSchemaData(jsonFile, cpf) + err, httpError := validation.ValidateJsonSchemaData(caprofileJSONFile, cpf) if err != nil { http.Error(w, err.Error(), httpError) return diff --git a/src/orchestrator/api/composite_profilehandler_test.go b/src/orchestrator/api/composite_profilehandler_test.go index ec3ec24b..d1e34230 100644 --- a/src/orchestrator/api/composite_profilehandler_test.go +++ b/src/orchestrator/api/composite_profilehandler_test.go @@ -70,6 +70,10 @@ func (m *mockCompositeProfileManager) DeleteCompositeProfile(name string, projec return m.Err } +func init() { + caprofileJSONFile = "../json-schemas/metadata.json" +} + func Test_compositeProfileHandler_createHandler(t *testing.T) { testCases := []struct { label string diff --git a/src/orchestrator/api/controllerhandler.go b/src/orchestrator/api/controllerhandler.go index be300d89..418aa70f 100644 --- a/src/orchestrator/api/controllerhandler.go +++ b/src/orchestrator/api/controllerhandler.go @@ -28,6 +28,8 @@ import ( pkgerrors "github.com/pkg/errors" ) +var controllerJSONFile string = "json-schemas/controller.json" + // Used to store backend implementations objects // Also simplifies mocking for unit testing purposes type controllerHandler struct { @@ -87,9 +89,8 @@ func (h controllerHandler) createHandler(w http.ResponseWriter, r *http.Request) return } - jsonFile := "json-schemas/controller.json" // Verify JSON Body - err, httpError := validation.ValidateJsonSchemaData(jsonFile, m) + err, httpError := validation.ValidateJsonSchemaData(controllerJSONFile, m) if err != nil { http.Error(w, err.Error(), httpError) return diff --git a/src/orchestrator/api/controllerhandler_test.go b/src/orchestrator/api/controllerhandler_test.go index 6cbb2a79..ecc2d1f7 100644 --- a/src/orchestrator/api/controllerhandler_test.go +++ b/src/orchestrator/api/controllerhandler_test.go @@ -73,6 +73,10 @@ func (m *mockControllerManager) InitControllers() { return } +func init() { + controllerJSONFile = "../json-schemas/controller.json" +} + func TestControllerCreateHandler(t *testing.T) { testCases := []struct { label string diff --git a/src/orchestrator/api/deployment_intent_groups_handler.go b/src/orchestrator/api/deployment_intent_groups_handler.go index 76dea14c..b9466a2c 100644 --- a/src/orchestrator/api/deployment_intent_groups_handler.go +++ b/src/orchestrator/api/deployment_intent_groups_handler.go @@ -27,6 +27,8 @@ import ( "github.com/gorilla/mux" ) +var dpiJSONFile string = "json-schemas/deployment-group-intent.json" + /* Used to store backend implementation objects Also simplifies mocking for unit testing purposes */ @@ -49,9 +51,8 @@ func (h deploymentIntentGroupHandler) createDeploymentIntentGroupHandler(w http. return } - jsonFile := "json-schemas/deployment-group-intent.json" // Verify JSON Body - err, httpError := validation.ValidateJsonSchemaData(jsonFile, d) + err, httpError := validation.ValidateJsonSchemaData(dpiJSONFile, d) if err != nil { http.Error(w, err.Error(), httpError) return diff --git a/src/orchestrator/api/generic_placement_intent_handler.go b/src/orchestrator/api/generic_placement_intent_handler.go index 16f1f234..2415ae2c 100644 --- a/src/orchestrator/api/generic_placement_intent_handler.go +++ b/src/orchestrator/api/generic_placement_intent_handler.go @@ -27,6 +27,8 @@ import ( "github.com/gorilla/mux" ) +var gpiJSONFile string = "json-schemas/generic-placement-intent.json" + /* Used to store backend implementation objects Also simplifies mocking for unit testing purposes */ @@ -49,9 +51,8 @@ func (h genericPlacementIntentHandler) createGenericPlacementIntentHandler(w htt return } - jsonFile := "json-schemas/generic-placement-intent.json" // Verify JSON Body - err, httpError := validation.ValidateJsonSchemaData(jsonFile, g) + err, httpError := validation.ValidateJsonSchemaData(gpiJSONFile, g) if err != nil { http.Error(w, err.Error(), httpError) return diff --git a/src/orchestrator/api/json-schemas/cluster-kv.json b/src/orchestrator/api/json-schemas/cluster-kv.json deleted file mode 100644 index c7013bab..00000000 --- a/src/orchestrator/api/json-schemas/cluster-kv.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "type": "object", - "properties": { - "spec": { - "required": [ - "kv" - ], - "type": "object", - "properties": { - "kv": { - "items": { - "additionalProperties": { - "type": "string", - "maxLength": 128 - }, - "type": "object" - }, - "type": "array" - } - } - }, - "metadata": { - "required": ["name"], - "properties": { - "userData2": { - "description": "User relevant data for the resource", - "type": "string", - "example": "Some more data", - "maxLength": 512 - }, - "userData1": { - "description": "User relevant data for the resource", - "type": "string", - "example": "Some data", - "maxLength": 512 - }, - "name": { - "description": "Name of the resource", - "type": "string", - "example": "ResName", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - }, - "description": { - "description": "Description for the resource", - "type": "string", - "example": "Resource description", - "maxLength": 1024 - } - } - } - } - } \ No newline at end of file diff --git a/src/orchestrator/api/json-schemas/cluster-label.json b/src/orchestrator/api/json-schemas/cluster-label.json deleted file mode 100644 index 22267b3d..00000000 --- a/src/orchestrator/api/json-schemas/cluster-label.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "type": "object", - "properties": { - "label-name": { - "description": "Logical Cloud to use for this intent", - "type": "string", - "example": "cluster-label-1", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - } - } - } \ No newline at end of file diff --git a/src/orchestrator/api/json-schemas/composite-app.json b/src/orchestrator/api/json-schemas/composite-app.json deleted file mode 100644 index 3f976831..00000000 --- a/src/orchestrator/api/json-schemas/composite-app.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "type": "object", - "properties": { - "spec": { - "version": { - "description": "Composite Application Version", - "type": "string", - "example": "v1", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - } - }, - "metadata": { - "required": ["name"], - "properties": { - "userData2": { - "description": "User relevant data for the resource", - "type": "string", - "example": "Some more data", - "maxLength": 512 - }, - "userData1": { - "description": "User relevant data for the resource", - "type": "string", - "example": "Some data", - "maxLength": 512 - }, - "name": { - "description": "Name of the resource", - "type": "string", - "example": "ResName", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - }, - "description": { - "description": "Description for the resource", - "type": "string", - "example": "Resource description", - "maxLength": 1024 - } - } - } - } - } \ No newline at end of file diff --git a/src/orchestrator/api/json-schemas/composite-profile.json b/src/orchestrator/api/json-schemas/composite-profile.json deleted file mode 100644 index e404a64c..00000000 --- a/src/orchestrator/api/json-schemas/composite-profile.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "type": "object", - "properties": { - "app-name": { - "description": "Application Name", - "required": [ - "app-name" - ], - "type": "string", - "example": "Application1", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - }, - "metadata": { - "required": ["name"], - "properties": { - "userData2": { - "description": "User relevant data for the resource", - "type": "string", - "example": "Some more data", - "maxLength": 512 - }, - "userData1": { - "description": "User relevant data for the resource", - "type": "string", - "example": "Some data", - "maxLength": 512 - }, - "name": { - "description": "Name of the resource", - "type": "string", - "example": "ResName", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - }, - "description": { - "description": "Description for the resource", - "type": "string", - "example": "Resource description", - "maxLength": 1024 - } - } - } - } - } \ No newline at end of file diff --git a/src/orchestrator/api/json-schemas/controller.json b/src/orchestrator/api/json-schemas/controller.json deleted file mode 100644 index 3263ff21..00000000 --- a/src/orchestrator/api/json-schemas/controller.json +++ /dev/null @@ -1,73 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "type": "object", - "properties": { - "spec": { - "required": [ - "host", - "port", - "type", - "priority" - ], - "type": "object", - "properties": { - "priority": { - "description": "Priority of controller to be called", - "type": "integer", - "example": 4, - "minimum": 0, - "maximum": 100 - }, - "host": { - "description": "Controller reachibility information", - "type": "string", - "example": "10.7.100.4", - "maxLength": 128 - }, - "type": { - "description": "Type of controller (placement, action are 2 types supported)", - "type": "string", - "example": "placement", - "maxLength": 48 - }, - "port": { - "description": "Port for controller", - "type": "integer", - "minimum": 0, - "maximum": 50000, - "example": 9029 - } - } - }, - "metadata": { - "required": ["name"], - "properties": { - "userData2": { - "description": "User relevant data for the resource", - "type": "string", - "example": "Some more data", - "maxLength": 512 - }, - "userData1": { - "description": "User relevant data for the resource", - "type": "string", - "example": "Some data", - "maxLength": 512 - }, - "name": { - "description": "Name of the resource", - "type": "string", - "example": "ResName", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - }, - "description": { - "description": "Description for the resource", - "type": "string", - "example": "Resource description", - "maxLength": 1024 - } - } - } - } - } \ No newline at end of file diff --git a/src/orchestrator/api/json-schemas/deployment-group-intent.json b/src/orchestrator/api/json-schemas/deployment-group-intent.json deleted file mode 100644 index 2740747b..00000000 --- a/src/orchestrator/api/json-schemas/deployment-group-intent.json +++ /dev/null @@ -1,79 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "type": "object", - "properties": { - "spec": { - "required": [ - "profile", - "version" - ], - "type": "object", - "description": "DepSpecData has profile, version, OverrideValuesObj", - "properties": { - "override-values": { - "items": { - "required": [ - "app-name", - "values" - ], - "type": "object", - "description": "OverrideValues has appName and ValuesObj", - "properties": { - "app-name": { - "type": "string" - }, - "values": { - "additionalProperties": { - "type": "string", - "maxLength": 128 - }, - "type": "object" - } - } - }, - "type": "array" - }, - "profile": { - "type": "string", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - }, - "version": { - "type": "string", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - } - } - }, - "metadata": { - "required": ["name"], - "properties": { - "userData2": { - "description": "User relevant data for the resource", - "type": "string", - "example": "Some more data", - "maxLength": 512 - }, - "userData1": { - "description": "User relevant data for the resource", - "type": "string", - "example": "Some data", - "maxLength": 512 - }, - "name": { - "description": "Name of the resource", - "type": "string", - "example": "ResName", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - }, - "description": { - "description": "Description for the resource", - "type": "string", - "example": "Resource description", - "maxLength": 1024 - } - } - } - } - } \ No newline at end of file diff --git a/src/orchestrator/api/json-schemas/deployment-intent.json b/src/orchestrator/api/json-schemas/deployment-intent.json deleted file mode 100644 index 6bdc0b43..00000000 --- a/src/orchestrator/api/json-schemas/deployment-intent.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "type": "object", - "properties": { - "spec": { - "required": [ - "intent" - ], - "type": "object", - "description": "IntentSpecData has Intent", - "properties": { - "intent": { - "additionalProperties": { - "type": "string", - "maxLength": 128 - }, - "type": "object", - "example": { - "generic-placement-intent": "gpi-name" - } - } - } - }, - "metadata": { - "required": ["name"], - "properties": { - "userData2": { - "description": "User relevant data for the resource", - "type": "string", - "example": "Some more data", - "maxLength": 512 - }, - "userData1": { - "description": "User relevant data for the resource", - "type": "string", - "example": "Some data", - "maxLength": 512 - }, - "name": { - "description": "Name of the resource", - "type": "string", - "example": "ResName", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - }, - "description": { - "description": "Description for the resource", - "type": "string", - "example": "Resource description", - "maxLength": 1024 - } - } - } - } -} \ No newline at end of file diff --git a/src/orchestrator/api/json-schemas/generic-placement-intent-app.json b/src/orchestrator/api/json-schemas/generic-placement-intent-app.json deleted file mode 100644 index 0b6447c2..00000000 --- a/src/orchestrator/api/json-schemas/generic-placement-intent-app.json +++ /dev/null @@ -1,117 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "type": "object", - "properties": { - "spec": { - "properties": { - "app-name": { - "type": "string", - "example": "appl", - "maxLength": 128 - }, - "anyOf": { - "items": { - "type": "object", - "description": "AnyOf consists of Array of ProviderName & ClusterLabelNames", - "properties": { - "cluster-label-name": { - "type": "string", - "example": "east", - "maxLength": 128 - }, - "provider-name": { - "type": "string", - "example": "provider1", - "maxLength": 128 - }, - "cluster-name": { - "type": "string", - "example": "cluster1", - "maxLength": 128 - } - } - }, - "type": "array" - }, - "allOf": { - "items": { - "type": "object", - "description": "AllOf ProviderName, ClusterName, ClusterLabelName and AnyOfArray", - "properties": { - "provider-name": { - "type": "string", - "example": "provider2", - "maxLength": 128 - }, - "cluster-label-name": { - "type": "string", - "example": "west", - "maxLength": 128 - }, - "anyOf": { - "items": { - "type": "object", - "description": "AnyOf consists of Array of ProviderName & ClusterLabelNames", - "properties": { - "cluster-label-name": { - "type": "string", - "example": "east", - "maxLength": 128 - }, - "provider-name": { - "type": "string", - "example": "provider1", - "maxLength": 128 - }, - "cluster-name": { - "type": "string", - "example": "cluster1", - "maxLength": 128 - } - } - }, - "type": "array" - }, - "cluster-name": { - "type": "string", - "example": "cluster2", - "maxLength": 128 - } - } - }, - "type": "array" - } - } - }, - "metadata": { - "required": ["name"], - "properties": { - "userData2": { - "description": "User relevant data for the resource", - "type": "string", - "example": "Some more data", - "maxLength": 512 - }, - "userData1": { - "description": "User relevant data for the resource", - "type": "string", - "example": "Some data", - "maxLength": 512 - }, - "name": { - "description": "Name of the resource", - "type": "string", - "example": "ResName", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - }, - "description": { - "description": "Description for the resource", - "type": "string", - "example": "Resource description", - "maxLength": 1024 - } - } - } - } -} \ No newline at end of file diff --git a/src/orchestrator/api/json-schemas/generic-placement-intent.json b/src/orchestrator/api/json-schemas/generic-placement-intent.json deleted file mode 100644 index 44df9087..00000000 --- a/src/orchestrator/api/json-schemas/generic-placement-intent.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "type": "object", - "properties": { - "spec": { - "type": "object", - "description": "Spec", - "properties": { - "logical-cloud": { - "description": "Logical Cloud to use for this intent", - "required": [ - "logical-cloud" - ], - "type": "string", - "example": "cloud1", - "maxLength": 128 - } - } - }, - "metadata": { - "required": ["name"], - "properties": { - "userData2": { - "description": "User relevant data for the resource", - "type": "string", - "example": "Some more data", - "maxLength": 512 - }, - "userData1": { - "description": "User relevant data for the resource", - "type": "string", - "example": "Some data", - "maxLength": 512 - }, - "name": { - "description": "Name of the resource", - "type": "string", - "example": "ResName", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - }, - "description": { - "description": "Description for the resource", - "type": "string", - "example": "Resource description", - "maxLength": 1024 - } - } - } - } - } \ No newline at end of file diff --git a/src/orchestrator/api/json-schemas/metadata.json b/src/orchestrator/api/json-schemas/metadata.json deleted file mode 100644 index 960545ee..00000000 --- a/src/orchestrator/api/json-schemas/metadata.json +++ /dev/null @@ -1,37 +0,0 @@ - -{ - "$schema": "http://json-schema.org/schema#", - "type": "object", - "properties": { - "metadata": { - "required": ["name"], - "properties": { - "userData2": { - "description": "User relevant data for the resource", - "type": "string", - "example": "Some more data", - "maxLength": 512 - }, - "userData1": { - "description": "User relevant data for the resource", - "type": "string", - "example": "Some data", - "maxLength": 512 - }, - "name": { - "description": "Name of the resource", - "type": "string", - "example": "ResName", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - }, - "description": { - "description": "Description for the resource", - "type": "string", - "example": "Resource description", - "maxLength": 1024 - } - } - } - } - } \ No newline at end of file diff --git a/src/orchestrator/api/json-schemas/network-load-interface.json b/src/orchestrator/api/json-schemas/network-load-interface.json deleted file mode 100644 index dd5b40d1..00000000 --- a/src/orchestrator/api/json-schemas/network-load-interface.json +++ /dev/null @@ -1,77 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "type": "object", - "properties": { - "spec": { - "required": [ - "interface", - "name" - ], - "type": "object", - "properties": { - "interface": { - "description": "interface Name", - "type": "string", - "example": "eth0", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - }, - "macAddress": { - "description": "Name of the network", - "type": "string", - "example": "x.x.x.x", - "maxLength": 128 - }, - "ipAddress": { - "description": "Name of the network", - "type": "string", - "example": "0.0.0.0", - "maxLength": 128 - }, - "name": { - "description": "Name of the network", - "type": "string", - "example": "provider-1", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - }, - "defaultGateway": { - "description": "Is this interface default gateway", - "type": "boolean", - "example": false, - "maxLength": 128 - } - } - }, - "metadata": { - "required": ["name"], - "properties": { - "userData2": { - "description": "User relevant data for the resource", - "type": "string", - "example": "Some more data", - "maxLength": 512 - }, - "userData1": { - "description": "User relevant data for the resource", - "type": "string", - "example": "Some data", - "maxLength": 512 - }, - "name": { - "description": "Name of the resource", - "type": "string", - "example": "ResName", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - }, - "description": { - "description": "Description for the resource", - "type": "string", - "example": "Resource description", - "maxLength": 1024 - } - } - } - } - } \ No newline at end of file diff --git a/src/orchestrator/api/json-schemas/network-workload.json b/src/orchestrator/api/json-schemas/network-workload.json deleted file mode 100644 index c5dc14cb..00000000 --- a/src/orchestrator/api/json-schemas/network-workload.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "type": "object", - "properties": { - "spec": { - "type": "object", - "description": "Newtwork Workload Intent", - "properties": { - "spec": { - "type": "object", - "properties": { - "workload-resource": { - "description": "Name of the workload", - "type": "string", - "example": "firewall", - "maxLength": 254, - "pattern": "[-_0-9a-zA-Z]+$" - }, - "type": { - "description": "Type of the workload", - "type": "string", - "example": "deployment", - "maxLength": 128 - }, - "application-name": { - "description": "Application Name", - "type": "string", - "example": "Application1", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - } - } - }, - "metadata": { - "required": ["name"], - "properties": { - "userData2": { - "description": "User relevant data for the resource", - "type": "string", - "example": "Some more data", - "maxLength": 512 - }, - "userData1": { - "description": "User relevant data for the resource", - "type": "string", - "example": "Some data", - "maxLength": 512 - }, - "name": { - "description": "Name of the resource", - "type": "string", - "example": "ResName", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - }, - "description": { - "description": "Description for the resource", - "type": "string", - "example": "Resource description", - "maxLength": 1024 - } - } - } - } - } - } -} \ No newline at end of file diff --git a/src/orchestrator/api/json-schemas/provider-network.json b/src/orchestrator/api/json-schemas/provider-network.json deleted file mode 100644 index 0aef0304..00000000 --- a/src/orchestrator/api/json-schemas/provider-network.json +++ /dev/null @@ -1,122 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "type": "object", - "properties": { - "spec": { - "required": [ - "cniType", - "ipv4Subnets", - "providerNetType", - "vlan" - ], - "type": "object", - "properties": { - "ipv4Subnets": { - "items": { - "required": [ - "name", - "subnet" - ], - "type": "object", - "properties": { - "subnet": { - "type": "string", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - }, - "excludeIps": { - "type": "string", - "maxLength": 128 - }, - "gateway": { - "type": "string", - "maxLength": 128 - }, - "name": { - "type": "string", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - } - } - }, - "type": "array" - }, - "cniType": { - "type": "string", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - }, - "vlan": { - "required": [ - "logicalInterfaceName", - "nodeLabelList", - "providerInterfaceName", - "vlanID", - "vlanNodeSelector" - ], - "type": "object", - "properties": { - "vlanNodeSelector": { - "type": "string", - "maxLength": 128 - }, - "nodeLabelList": { - "items": { - "type": "string", - "maxLength": 128 - }, - "type": "array" - }, - "providerInterfaceName": { - "type": "string", - "maxLength": 128 - }, - "vlanID": { - "type": "string", - "maxLength": 128 - }, - "logicalInterfaceName": { - "type": "string", - "maxLength": 128 - } - } - }, - "providerNetType": { - "type": "string", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - } - } - }, - "metadata": { - "required": ["name"], - "properties": { - "userData2": { - "description": "User relevant data for the resource", - "type": "string", - "example": "Some more data", - "maxLength": 512 - }, - "userData1": { - "description": "User relevant data for the resource", - "type": "string", - "example": "Some data", - "maxLength": 512 - }, - "name": { - "description": "Name of the resource", - "type": "string", - "example": "ResName", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - }, - "description": { - "description": "Description for the resource", - "type": "string", - "example": "Resource description", - "maxLength": 1024 - } - } - } - } -} \ No newline at end of file diff --git a/src/orchestrator/api/json-schemas/virtual-network.json b/src/orchestrator/api/json-schemas/virtual-network.json deleted file mode 100644 index f2bc9d3d..00000000 --- a/src/orchestrator/api/json-schemas/virtual-network.json +++ /dev/null @@ -1,75 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "type": "object", - "properties": { - "spec": { - "properties": { - "ipv4Subnets": { - "items": { - "required": [ - "name", - "subnet" - ], - "type": "object", - "properties": { - "subnet": { - "type": "string", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - }, - "excludeIps": { - "type": "string", - "maxLength": 1024 - }, - "gateway": { - "type": "string", - "maxLength": 128 - }, - "name": { - "type": "string", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - } - } - }, - "type": "array" - }, - "cniType": { - "type": "string", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - } - } - }, - "metadata": { - "required": ["name"], - "properties": { - "userData2": { - "description": "User relevant data for the resource", - "type": "string", - "example": "Some more data", - "maxLength": 512 - }, - "userData1": { - "description": "User relevant data for the resource", - "type": "string", - "example": "Some data", - "maxLength": 512 - }, - "name": { - "description": "Name of the resource", - "type": "string", - "example": "ResName", - "maxLength": 128, - "pattern": "[-_0-9a-zA-Z]+$" - }, - "description": { - "description": "Description for the resource", - "type": "string", - "example": "Resource description", - "maxLength": 1024 - } - } - } - } -} \ No newline at end of file diff --git a/src/orchestrator/api/projecthandler.go b/src/orchestrator/api/projecthandler.go index f130d283..07cd79ce 100644 --- a/src/orchestrator/api/projecthandler.go +++ b/src/orchestrator/api/projecthandler.go @@ -26,6 +26,8 @@ import ( moduleLib "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module" ) +var projectJSONFile string = "json-schemas/metadata.json" + // Used to store backend implementations objects // Also simplifies mocking for unit testing purposes type projectHandler struct { @@ -47,9 +49,9 @@ func (h projectHandler) createHandler(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), http.StatusUnprocessableEntity) return } - jsonFile := "json-schemas/metadata.json" + // Verify JSON Body - err, httpError := validation.ValidateJsonSchemaData(jsonFile, p) + err, httpError := validation.ValidateJsonSchemaData(projectJSONFile, p) if err != nil { http.Error(w, err.Error(), httpError) return diff --git a/src/orchestrator/api/projecthandler_test.go b/src/orchestrator/api/projecthandler_test.go index ef5fdf07..5e88bab9 100644 --- a/src/orchestrator/api/projecthandler_test.go +++ b/src/orchestrator/api/projecthandler_test.go @@ -64,6 +64,10 @@ func (m *mockProjectManager) GetAllProjects() ([]moduleLib.Project, error) { return []moduleLib.Project{}, m.Err } +func init() { + projectJSONFile = "../json-schemas/metadata.json" +} + func TestProjectCreateHandler(t *testing.T) { testCases := []struct { label string diff --git a/src/orchestrator/json-schemas/composite-app.json b/src/orchestrator/json-schemas/composite-app.json new file mode 100644 index 00000000..3f976831 --- /dev/null +++ b/src/orchestrator/json-schemas/composite-app.json @@ -0,0 +1,45 @@ +{ + "$schema": "http://json-schema.org/schema#", + "type": "object", + "properties": { + "spec": { + "version": { + "description": "Composite Application Version", + "type": "string", + "example": "v1", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + } + }, + "metadata": { + "required": ["name"], + "properties": { + "userData2": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some more data", + "maxLength": 512 + }, + "userData1": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some data", + "maxLength": 512 + }, + "name": { + "description": "Name of the resource", + "type": "string", + "example": "ResName", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + }, + "description": { + "description": "Description for the resource", + "type": "string", + "example": "Resource description", + "maxLength": 1024 + } + } + } + } + } \ No newline at end of file diff --git a/src/orchestrator/json-schemas/composite-profile.json b/src/orchestrator/json-schemas/composite-profile.json new file mode 100644 index 00000000..e404a64c --- /dev/null +++ b/src/orchestrator/json-schemas/composite-profile.json @@ -0,0 +1,46 @@ +{ + "$schema": "http://json-schema.org/schema#", + "type": "object", + "properties": { + "app-name": { + "description": "Application Name", + "required": [ + "app-name" + ], + "type": "string", + "example": "Application1", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + }, + "metadata": { + "required": ["name"], + "properties": { + "userData2": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some more data", + "maxLength": 512 + }, + "userData1": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some data", + "maxLength": 512 + }, + "name": { + "description": "Name of the resource", + "type": "string", + "example": "ResName", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + }, + "description": { + "description": "Description for the resource", + "type": "string", + "example": "Resource description", + "maxLength": 1024 + } + } + } + } + } \ No newline at end of file diff --git a/src/orchestrator/json-schemas/controller.json b/src/orchestrator/json-schemas/controller.json new file mode 100644 index 00000000..3263ff21 --- /dev/null +++ b/src/orchestrator/json-schemas/controller.json @@ -0,0 +1,73 @@ +{ + "$schema": "http://json-schema.org/schema#", + "type": "object", + "properties": { + "spec": { + "required": [ + "host", + "port", + "type", + "priority" + ], + "type": "object", + "properties": { + "priority": { + "description": "Priority of controller to be called", + "type": "integer", + "example": 4, + "minimum": 0, + "maximum": 100 + }, + "host": { + "description": "Controller reachibility information", + "type": "string", + "example": "10.7.100.4", + "maxLength": 128 + }, + "type": { + "description": "Type of controller (placement, action are 2 types supported)", + "type": "string", + "example": "placement", + "maxLength": 48 + }, + "port": { + "description": "Port for controller", + "type": "integer", + "minimum": 0, + "maximum": 50000, + "example": 9029 + } + } + }, + "metadata": { + "required": ["name"], + "properties": { + "userData2": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some more data", + "maxLength": 512 + }, + "userData1": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some data", + "maxLength": 512 + }, + "name": { + "description": "Name of the resource", + "type": "string", + "example": "ResName", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + }, + "description": { + "description": "Description for the resource", + "type": "string", + "example": "Resource description", + "maxLength": 1024 + } + } + } + } + } \ No newline at end of file diff --git a/src/orchestrator/json-schemas/deployment-group-intent.json b/src/orchestrator/json-schemas/deployment-group-intent.json new file mode 100644 index 00000000..2740747b --- /dev/null +++ b/src/orchestrator/json-schemas/deployment-group-intent.json @@ -0,0 +1,79 @@ +{ + "$schema": "http://json-schema.org/schema#", + "type": "object", + "properties": { + "spec": { + "required": [ + "profile", + "version" + ], + "type": "object", + "description": "DepSpecData has profile, version, OverrideValuesObj", + "properties": { + "override-values": { + "items": { + "required": [ + "app-name", + "values" + ], + "type": "object", + "description": "OverrideValues has appName and ValuesObj", + "properties": { + "app-name": { + "type": "string" + }, + "values": { + "additionalProperties": { + "type": "string", + "maxLength": 128 + }, + "type": "object" + } + } + }, + "type": "array" + }, + "profile": { + "type": "string", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + }, + "version": { + "type": "string", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + } + } + }, + "metadata": { + "required": ["name"], + "properties": { + "userData2": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some more data", + "maxLength": 512 + }, + "userData1": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some data", + "maxLength": 512 + }, + "name": { + "description": "Name of the resource", + "type": "string", + "example": "ResName", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + }, + "description": { + "description": "Description for the resource", + "type": "string", + "example": "Resource description", + "maxLength": 1024 + } + } + } + } + } \ No newline at end of file diff --git a/src/orchestrator/json-schemas/deployment-intent.json b/src/orchestrator/json-schemas/deployment-intent.json new file mode 100644 index 00000000..6bdc0b43 --- /dev/null +++ b/src/orchestrator/json-schemas/deployment-intent.json @@ -0,0 +1,55 @@ +{ + "$schema": "http://json-schema.org/schema#", + "type": "object", + "properties": { + "spec": { + "required": [ + "intent" + ], + "type": "object", + "description": "IntentSpecData has Intent", + "properties": { + "intent": { + "additionalProperties": { + "type": "string", + "maxLength": 128 + }, + "type": "object", + "example": { + "generic-placement-intent": "gpi-name" + } + } + } + }, + "metadata": { + "required": ["name"], + "properties": { + "userData2": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some more data", + "maxLength": 512 + }, + "userData1": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some data", + "maxLength": 512 + }, + "name": { + "description": "Name of the resource", + "type": "string", + "example": "ResName", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + }, + "description": { + "description": "Description for the resource", + "type": "string", + "example": "Resource description", + "maxLength": 1024 + } + } + } + } +} \ No newline at end of file diff --git a/src/orchestrator/json-schemas/generic-placement-intent-app.json b/src/orchestrator/json-schemas/generic-placement-intent-app.json new file mode 100644 index 00000000..0b6447c2 --- /dev/null +++ b/src/orchestrator/json-schemas/generic-placement-intent-app.json @@ -0,0 +1,117 @@ +{ + "$schema": "http://json-schema.org/schema#", + "type": "object", + "properties": { + "spec": { + "properties": { + "app-name": { + "type": "string", + "example": "appl", + "maxLength": 128 + }, + "anyOf": { + "items": { + "type": "object", + "description": "AnyOf consists of Array of ProviderName & ClusterLabelNames", + "properties": { + "cluster-label-name": { + "type": "string", + "example": "east", + "maxLength": 128 + }, + "provider-name": { + "type": "string", + "example": "provider1", + "maxLength": 128 + }, + "cluster-name": { + "type": "string", + "example": "cluster1", + "maxLength": 128 + } + } + }, + "type": "array" + }, + "allOf": { + "items": { + "type": "object", + "description": "AllOf ProviderName, ClusterName, ClusterLabelName and AnyOfArray", + "properties": { + "provider-name": { + "type": "string", + "example": "provider2", + "maxLength": 128 + }, + "cluster-label-name": { + "type": "string", + "example": "west", + "maxLength": 128 + }, + "anyOf": { + "items": { + "type": "object", + "description": "AnyOf consists of Array of ProviderName & ClusterLabelNames", + "properties": { + "cluster-label-name": { + "type": "string", + "example": "east", + "maxLength": 128 + }, + "provider-name": { + "type": "string", + "example": "provider1", + "maxLength": 128 + }, + "cluster-name": { + "type": "string", + "example": "cluster1", + "maxLength": 128 + } + } + }, + "type": "array" + }, + "cluster-name": { + "type": "string", + "example": "cluster2", + "maxLength": 128 + } + } + }, + "type": "array" + } + } + }, + "metadata": { + "required": ["name"], + "properties": { + "userData2": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some more data", + "maxLength": 512 + }, + "userData1": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some data", + "maxLength": 512 + }, + "name": { + "description": "Name of the resource", + "type": "string", + "example": "ResName", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + }, + "description": { + "description": "Description for the resource", + "type": "string", + "example": "Resource description", + "maxLength": 1024 + } + } + } + } +} \ No newline at end of file diff --git a/src/orchestrator/json-schemas/generic-placement-intent.json b/src/orchestrator/json-schemas/generic-placement-intent.json new file mode 100644 index 00000000..44df9087 --- /dev/null +++ b/src/orchestrator/json-schemas/generic-placement-intent.json @@ -0,0 +1,51 @@ +{ + "$schema": "http://json-schema.org/schema#", + "type": "object", + "properties": { + "spec": { + "type": "object", + "description": "Spec", + "properties": { + "logical-cloud": { + "description": "Logical Cloud to use for this intent", + "required": [ + "logical-cloud" + ], + "type": "string", + "example": "cloud1", + "maxLength": 128 + } + } + }, + "metadata": { + "required": ["name"], + "properties": { + "userData2": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some more data", + "maxLength": 512 + }, + "userData1": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some data", + "maxLength": 512 + }, + "name": { + "description": "Name of the resource", + "type": "string", + "example": "ResName", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + }, + "description": { + "description": "Description for the resource", + "type": "string", + "example": "Resource description", + "maxLength": 1024 + } + } + } + } + } \ No newline at end of file diff --git a/src/orchestrator/json-schemas/metadata.json b/src/orchestrator/json-schemas/metadata.json new file mode 100644 index 00000000..960545ee --- /dev/null +++ b/src/orchestrator/json-schemas/metadata.json @@ -0,0 +1,37 @@ + +{ + "$schema": "http://json-schema.org/schema#", + "type": "object", + "properties": { + "metadata": { + "required": ["name"], + "properties": { + "userData2": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some more data", + "maxLength": 512 + }, + "userData1": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some data", + "maxLength": 512 + }, + "name": { + "description": "Name of the resource", + "type": "string", + "example": "ResName", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + }, + "description": { + "description": "Description for the resource", + "type": "string", + "example": "Resource description", + "maxLength": 1024 + } + } + } + } + } \ No newline at end of file diff --git a/src/orchestrator/scripts/start-dev.sh b/src/orchestrator/scripts/start-dev.sh index 003773be..ad21dc47 100755 --- a/src/orchestrator/scripts/start-dev.sh +++ b/src/orchestrator/scripts/start-dev.sh @@ -28,6 +28,6 @@ echo "Compiling source code" pushd $opath generate_config make all -cp -r $k8s_path/src/orchestrator/api/json-schemas $k8s_path/src/orchestrator +cp -r $k8s_path/src/orchestrator/json-schemas $k8s_path/src/orchestrator ./orchestrator popd diff --git a/src/ovnaction/api/netcontrolintenthandler.go b/src/ovnaction/api/netcontrolintenthandler.go index fe2109b6..631f13c4 100644 --- a/src/ovnaction/api/netcontrolintenthandler.go +++ b/src/ovnaction/api/netcontrolintenthandler.go @@ -24,10 +24,16 @@ import ( moduleLib "github.com/onap/multicloud-k8s/src/ovnaction/pkg/module" pkgerrors "github.com/pkg/errors" + "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/validation" + "github.com/gorilla/mux" ) +var netCntIntJSONFile string = "json-schemas/metadata.json" + + + // Used to store backend implementations objects // Also simplifies mocking for unit testing purposes type netcontrolintentHandler struct { @@ -65,6 +71,13 @@ func (h netcontrolintentHandler) createHandler(w http.ResponseWriter, r *http.Re return } + err, httpError := validation.ValidateJsonSchemaData(netCntIntJSONFile, nci) +if err != nil { + http.Error(w, err.Error(), httpError) + return +} + + // Name is required. if nci.Metadata.Name == "" { http.Error(w, "Missing name in POST request", http.StatusBadRequest) diff --git a/src/ovnaction/api/workloadifintenthandler.go b/src/ovnaction/api/workloadifintenthandler.go index cf8f45bf..e7be6317 100644 --- a/src/ovnaction/api/workloadifintenthandler.go +++ b/src/ovnaction/api/workloadifintenthandler.go @@ -29,6 +29,8 @@ import ( "github.com/gorilla/mux" ) +var netIfJSONFile string = "json-schemas/network-load-interface.json" + // Used to store backend implementations objects // Also simplifies mocking for unit testing purposes type workloadifintentHandler struct { @@ -102,6 +104,12 @@ func (h workloadifintentHandler) createHandler(w http.ResponseWriter, r *http.Re return } + err, httpError := validation.ValidateJsonSchemaData(netIfJSONFile, wif) +if err != nil { + http.Error(w, err.Error(), httpError) + return +} + // Name is required. if wif.Metadata.Name == "" { http.Error(w, "Missing name in POST request", http.StatusBadRequest) diff --git a/src/ovnaction/api/workloadintenthandler.go b/src/ovnaction/api/workloadintenthandler.go index cf7ecebc..acf4edbb 100644 --- a/src/ovnaction/api/workloadintenthandler.go +++ b/src/ovnaction/api/workloadintenthandler.go @@ -29,6 +29,8 @@ import ( "github.com/gorilla/mux" ) +var workloadIntJSONFile string = "json-schemas/network-workload.json" + // Used to store backend implementations objects // Also simplifies mocking for unit testing purposes type workloadintentHandler struct { @@ -82,6 +84,12 @@ func (h workloadintentHandler) createHandler(w http.ResponseWriter, r *http.Requ return } + err, httpError := validation.ValidateJsonSchemaData(workloadIntJSONFile, wi) +if err != nil { + http.Error(w, err.Error(), httpError) + return +} + // Name is required. if wi.Metadata.Name == "" { http.Error(w, "Missing name in POST request", http.StatusBadRequest) diff --git a/src/ovnaction/json-schemas/metadata.json b/src/ovnaction/json-schemas/metadata.json new file mode 100644 index 00000000..960545ee --- /dev/null +++ b/src/ovnaction/json-schemas/metadata.json @@ -0,0 +1,37 @@ + +{ + "$schema": "http://json-schema.org/schema#", + "type": "object", + "properties": { + "metadata": { + "required": ["name"], + "properties": { + "userData2": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some more data", + "maxLength": 512 + }, + "userData1": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some data", + "maxLength": 512 + }, + "name": { + "description": "Name of the resource", + "type": "string", + "example": "ResName", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + }, + "description": { + "description": "Description for the resource", + "type": "string", + "example": "Resource description", + "maxLength": 1024 + } + } + } + } + } \ No newline at end of file diff --git a/src/ovnaction/json-schemas/network-load-interface.json b/src/ovnaction/json-schemas/network-load-interface.json new file mode 100644 index 00000000..896f4f2b --- /dev/null +++ b/src/ovnaction/json-schemas/network-load-interface.json @@ -0,0 +1,77 @@ +{ + "$schema": "http://json-schema.org/schema#", + "type": "object", + "properties": { + "spec": { + "required": [ + "interface", + "name" + ], + "type": "object", + "properties": { + "interface": { + "description": "interface Name", + "type": "string", + "example": "eth0", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + }, + "macAddress": { + "description": "Name of the network", + "type": "string", + "example": "x.x.x.x", + "maxLength": 128 + }, + "ipAddress": { + "description": "Name of the network", + "type": "string", + "example": "0.0.0.0", + "maxLength": 128 + }, + "name": { + "description": "Name of the network", + "type": "string", + "example": "provider-1", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + }, + "defaultGateway": { + "description": "Is this interface default gateway", + "type": "string", + "example": "false", + "maxLength": 128 + } + } + }, + "metadata": { + "required": ["name"], + "properties": { + "userData2": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some more data", + "maxLength": 512 + }, + "userData1": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some data", + "maxLength": 512 + }, + "name": { + "description": "Name of the resource", + "type": "string", + "example": "ResName", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + }, + "description": { + "description": "Description for the resource", + "type": "string", + "example": "Resource description", + "maxLength": 1024 + } + } + } + } + } \ No newline at end of file diff --git a/src/ovnaction/json-schemas/network-workload.json b/src/ovnaction/json-schemas/network-workload.json new file mode 100644 index 00000000..c5dc14cb --- /dev/null +++ b/src/ovnaction/json-schemas/network-workload.json @@ -0,0 +1,67 @@ +{ + "$schema": "http://json-schema.org/schema#", + "type": "object", + "properties": { + "spec": { + "type": "object", + "description": "Newtwork Workload Intent", + "properties": { + "spec": { + "type": "object", + "properties": { + "workload-resource": { + "description": "Name of the workload", + "type": "string", + "example": "firewall", + "maxLength": 254, + "pattern": "[-_0-9a-zA-Z]+$" + }, + "type": { + "description": "Type of the workload", + "type": "string", + "example": "deployment", + "maxLength": 128 + }, + "application-name": { + "description": "Application Name", + "type": "string", + "example": "Application1", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + } + } + }, + "metadata": { + "required": ["name"], + "properties": { + "userData2": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some more data", + "maxLength": 512 + }, + "userData1": { + "description": "User relevant data for the resource", + "type": "string", + "example": "Some data", + "maxLength": 512 + }, + "name": { + "description": "Name of the resource", + "type": "string", + "example": "ResName", + "maxLength": 128, + "pattern": "[-_0-9a-zA-Z]+$" + }, + "description": { + "description": "Description for the resource", + "type": "string", + "example": "Resource description", + "maxLength": 1024 + } + } + } + } + } + } +} \ No newline at end of file diff --git a/src/tools/emcoctl/Readme.md b/src/tools/emcoctl/Readme.md index ecbcf4de..105398c1 100644 --- a/src/tools/emcoctl/Readme.md +++ b/src/tools/emcoctl/Readme.md @@ -84,3 +84,134 @@ For deleting one resource anchor can be provided as an arguement `$ emcoctl delete ` `$ emcoctl delete projects/testvfw/composite-apps/compositevfw/v1/deployment-intent-groups/vfw_deployment_intent_group` + + +## Using helm charts through emcoctl + +When you need to use emcoctl for deploying helm +charts the following steps are required. + +1. Make sure that the composite app which you are planning to deploy, the tree structure is as below + +``` + +$ tree collection/app1/ +collection/app1/ +├── helm +│   └── collectd +│   ├── Chart.yaml +│   ├── resources +│   │   └── collectd.conf +│   ├── templates +│   │   ├── configmap.yaml +│   │   ├── daemonset.yaml +│   │   ├── _helpers.tpl +│   │   ├── NOTES.txt +│   │   └── service.yaml +│   └── values.yaml +└── profile + ├── manifest.yaml + └── override_values.yaml + +5 directories, 10 files + +$ tree collection/m3db/ +collection/m3db/ +├── helm +│   └── m3db +│   ├── Chart.yaml +│   ├── del.yaml +│   ├── templates +│   │   └── m3dbcluster.yaml +│   └── values.yaml +└── profile + ├── manifest.yaml + └── override_values.yaml + +4 directories, 6 files + +``` + +### NOTE +``` +* In the above example, we have a composite app : collection +The collection composite-app shown has two apps : app1(collectd) +and m3db +* Each app has two dirs : a. HELM and b. PROFILE. +* Helm dir shall have the real helm charts of the app. +* profile shall have the two files - manifest.yaml and override_values.yaml for creating the customized profile. +``` + +### Commands for making the tar files from helm. + +``` + tar -czf collectd.tar.gz -C $test_folder/vnfs/comp-app/collection/app1/helm . + tar -czf collectd_profile.tar.gz -C $test_folder/vnfs/comp-app/collection/app1/profile . + ---------------------------------------- + tar -czf m3db.tar.gz -C $test_folder/vnfs/comp-app/collection/m3db/helm . + tar -czf m3db_profile.tar.gz -C $test_folder/vnfs/comp-app/collection/m3db/profile . +``` + +Once you have generated the tar files, you need to give the path in file which you are applying using the emcoctl. For eg: + +``` +#adding collectd app to the composite app +version: emco/v2 +resourceContext: + anchor: projects/proj1/composite-apps/collection-composite-app/v1/apps +metadata : + name: collectd + description: "description for app" + userData1: test1 + userData2: test2 +file: + /opt/csar/cb009bfe-bbee-11e8-9766-525400435678/collectd.tar.gz + +``` + +``` +#adding collectd app profiles to the composite profile +version: emco/v2 +resourceContext: + anchor: projects/proj1/composite-apps/collection-composite-app/v1/composite-profiles/collection-composite-profile/profiles +metadata : + name: collectd-profile + description: test + userData1: test1 + userData2: test2 +spec: + app-name: collectd +file: + /opt/csar/cb009bfe-bbee-11e8-9766-525400435678/collectd_profile.tar.gz + +``` + +### Running the emcoctl + +``` +* Make sure that the emcoctl is build.You can build it by issuing the 'make' command. +Dir : $MULTICLOUD-K8s_HOME/src/tools/emcoctl +``` +* Then run the emcoctl by command: +``` +./emcoctl --config ./examples/emco-cfg.yaml apply -f ./examples/test.yaml + +``` + +Here, emco-cfg.yaml contains the config/port details of each of the microservices you are using. +A sample configuration is : + +``` + orchestrator: + host: localhost + port: 9015 + clm: + host: localhost + port: 9019 + ncm: + host: localhost + port: 9016 + ovnaction: + host: localhost + port: 9051 +``` diff --git a/src/tools/emcoctl/examples/emco-cfg.yaml b/src/tools/emcoctl/examples/emco-cfg.yaml index c1703def..a7e284ab 100644 --- a/src/tools/emcoctl/examples/emco-cfg.yaml +++ b/src/tools/emcoctl/examples/emco-cfg.yaml @@ -3,10 +3,10 @@ port: 9015 clm: host: localhost - port: 9061 + port: 9019 ncm: host: localhost - port: 9031 + port: 9016 ovnaction: host: localhost - port: 9051 \ No newline at end of file + port: 9018 diff --git a/src/tools/emcoctl/examples/test.yaml b/src/tools/emcoctl/examples/test.yaml index 924f7e55..e54ff36e 100644 --- a/src/tools/emcoctl/examples/test.yaml +++ b/src/tools/emcoctl/examples/test.yaml @@ -33,7 +33,7 @@ metadata : userData1: test1 userData2: test2 file: - kubeconfig + /home/otc/.kube/config --- #Add label cluster @@ -77,7 +77,7 @@ metadata : userData1: test1 userData2: test2 file: - prometheus-operator.tar.gz + /opt/csar/cb009bfe-bbee-11e8-9766-525400435678/prometheus-operator.tar.gz --- #adding collectd app to the composite app @@ -90,7 +90,7 @@ metadata : userData1: test1 userData2: test2 file: - collectd.tar.gz + /opt/csar/cb009bfe-bbee-11e8-9766-525400435678/collectd.tar.gz --- #creating collection composite profile entry @@ -116,7 +116,9 @@ metadata : spec: app-name: prometheus-operator file: - prometheus-operator_profile.tar.gz + /opt/csar/cb009bfe-bbee-11e8-9766-525400435678/prometheus-operator_profile.tar.gz + + --- #adding collectd app profiles to the composite profile @@ -131,7 +133,8 @@ metadata : spec: app-name: collectd file: - collectd_profile.tar.gz + /opt/csar/cb009bfe-bbee-11e8-9766-525400435678/collectd_profile.tar.gz + --- #create the generic placement intent @@ -160,7 +163,7 @@ spec: app-name: prometheus-operator intent: allOf: - - provider-name: cluster-provider1 + - provider-name: provider1 cluster-label-name: edge-cluster --- #add the prometheus app placement intent to the generic placement intent @@ -176,7 +179,7 @@ spec: app-name: collectd intent: allOf: - - provider-name: cluster-provider1 + - provider-name: provider1 cluster-label-name: edge-cluster --- diff --git a/src/tools/emcoctl/examples/vfw.yaml b/src/tools/emcoctl/examples/vfw.yaml index b5df4834..c84a1bab 100644 --- a/src/tools/emcoctl/examples/vfw.yaml +++ b/src/tools/emcoctl/examples/vfw.yaml @@ -38,7 +38,7 @@ resourceContext: metadata : name: edge01 file: - kubeconfig + /home/otc/.kube/config --- #Add label cluster @@ -89,7 +89,7 @@ spec: --- version: emco/v2 resourceContext: - anchor: cluster-providers/vfw-cluster-provider/clusters/edge01/apply + anchor: cluster-providers/vfw-cluster-provider/clusters/edge01/apply --- #create project @@ -100,7 +100,7 @@ metadata : name: testvfw --- -#creating collection composite app entry +#creating vfw composite app entry version: emco/v2 resourceContext: anchor: projects/testvfw/composite-apps @@ -110,37 +110,37 @@ spec: version: v1 --- -#adding prometheus app to the composite app +#adding packetgen app to the composite app version: emco/v2 resourceContext: anchor: projects/testvfw/composite-apps/compositevfw/v1/apps metadata : name: packetgen file: - /home/vagrant/multicloud-k8s/kud/demo/composite-firewall/packetgen.tar.gz + /opt/csar/cb009bfe-bbee-11e8-9766-525400435678/packetgen.tar.gz --- -#adding prometheus app to the composite app +#adding firewall app to the composite app version: emco/v2 resourceContext: anchor: projects/testvfw/composite-apps/compositevfw/v1/apps metadata : name: firewall file: - /home/vagrant/multicloud-k8s/kud/demo/composite-firewall/firewall.tar.gz + /opt/csar/cb009bfe-bbee-11e8-9766-525400435678/firewall.tar.gz --- -#adding collectd app to the composite app +#adding sink app to the composite app version: emco/v2 resourceContext: anchor: projects/testvfw/composite-apps/compositevfw/v1/apps metadata : name: sink file: - /home/vagrant/multicloud-k8s/kud/demo/composite-firewall/sink.tar.gz + /opt/csar/cb009bfe-bbee-11e8-9766-525400435678/sink.tar.gz --- -#creating collection composite profile entry +#creating vfw composite profile entry version: emco/v2 resourceContext: anchor: projects/testvfw/composite-apps/compositevfw/v1/composite-profiles @@ -148,7 +148,7 @@ metadata : name: vfw_composite-profile --- -#adding prometheus app profiles to the composite profile +#adding packetgen app profiles to the composite profile version: emco/v2 resourceContext: anchor: projects/testvfw/composite-apps/compositevfw/v1/composite-profiles/vfw_composite-profile/profiles @@ -157,7 +157,7 @@ metadata : spec: app-name: packetgen file: - /home/vagrant/multicloud-k8s/kud/demo/composite-firewall/profile.tar.gz + /opt/csar/cb009bfe-bbee-11e8-9766-525400435678/profile.tar.gz --- #adding firewall app profiles to the composite profile @@ -169,7 +169,7 @@ metadata : spec: app-name: firewall file: - /home/vagrant/multicloud-k8s/kud/demo/composite-firewall/profile.tar.gz + /opt/csar/cb009bfe-bbee-11e8-9766-525400435678/profile.tar.gz --- #adding firewall app profiles to the composite profile @@ -181,7 +181,7 @@ metadata : spec: app-name: sink file: - /home/vagrant/multicloud-k8s/kud/demo/composite-firewall/profile.tar.gz + /opt/csar/cb009bfe-bbee-11e8-9766-525400435678/profile.tar.gz --- #create the generic placement intent @@ -194,7 +194,7 @@ spec: logical-cloud: NA --- -#add the prometheus app placement intent to the generic placement intent +#add the packetgen app placement intent to the generic placement intent version: emco/v2 resourceContext: anchor: projects/testvfw/composite-apps/compositevfw/v1/generic-placement-intents/fw-placement-intent/app-intents @@ -207,7 +207,7 @@ spec: - provider-name: vfw-cluster-provider cluster-label-name: LabelA --- -#add the prometheus app placement intent to the generic placement intent +#add the firewall app placement intent to the generic placement intent version: emco/v2 resourceContext: anchor: projects/testvfw/composite-apps/compositevfw/v1/generic-placement-intents/fw-placement-intent/app-intents @@ -221,7 +221,7 @@ spec: cluster-label-name: LabelA --- -#add the prometheus app placement intent to the generic placement intent +#add the sink app placement intent to the generic placement intent version: emco/v2 resourceContext: anchor: projects/testvfw/composite-apps/compositevfw/v1/generic-placement-intents/fw-placement-intent/app-intents -- cgit 1.2.3-korg