summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xkud/tests/ncm-test.sh201
-rw-r--r--src/ncm/cmd/main.go59
-rw-r--r--src/ncm/go.mod1
-rw-r--r--src/ncm/pkg/grpc/contextupdateserver/contextupdateserver.go45
-rw-r--r--src/ncm/pkg/grpc/register.go58
-rw-r--r--src/orchestrator/api/api.go3
-rw-r--r--src/orchestrator/api/controllerhandler.go17
-rw-r--r--src/orchestrator/api/controllerhandler_test.go51
-rw-r--r--src/orchestrator/cmd/main.go4
-rw-r--r--src/orchestrator/pkg/module/controller/controller.go (renamed from src/orchestrator/pkg/module/controller.go)7
-rw-r--r--src/orchestrator/pkg/module/controller/controller_test.go (renamed from src/orchestrator/pkg/module/controller_test.go)9
-rw-r--r--src/orchestrator/pkg/module/module.go43
-rw-r--r--src/orchestrator/pkg/module/types/types.go58
13 files changed, 472 insertions, 84 deletions
diff --git a/kud/tests/ncm-test.sh b/kud/tests/ncm-test.sh
new file mode 100755
index 00000000..363a1819
--- /dev/null
+++ b/kud/tests/ncm-test.sh
@@ -0,0 +1,201 @@
+#!/bin/bash
+set -o errexit
+set -o nounset
+set -o pipefail
+
+source _functions.sh
+
+base_url=${base_url:-"http://localhost:9016/v2"}
+
+# ncm data samples
+clusterprovidername="cluster-provider-a"
+clusterproviderdata="$(cat<<EOF
+{
+ "metadata": {
+ "name": "$clusterprovidername",
+ "description": "description of $clusterprovidername",
+ "userData1": "$clusterprovidername user data 1",
+ "userData2": "$clusterprovidername user data 2"
+ }
+}
+EOF
+)"
+
+clustername="cluster-a"
+clusterdata="$(cat<<EOF
+{
+ "metadata": {
+ "name": "$clustername",
+ "description": "description of $clustername",
+ "userData1": "$clustername user data 1",
+ "userData2": "$clustername user data 2"
+ }
+}
+EOF
+)"
+
+# set $kubeconfigfile before running script to point to the desired config file
+defaultkubeconfig="$(cat<<EOF
+{
+ "not a good kube config file"
+}
+EOF
+)"
+echo "$defaultkubeconfig" > /tmp/ncmkubeconfig
+
+kubeconfigfile=${kubeconfigfile:-"/tmp/ncmkubeconfig"}
+
+labelname="LabelA"
+labeldata="$(cat<<EOF
+{"label-name": "$labelname"}
+EOF
+)"
+
+kvname="kva"
+kvdata="$(cat<<EOF
+{
+ "metadata": {
+ "name": "$kvname",
+ "description": "this is key value $kvname",
+ "userData1": "cluster $kvname pair data",
+ "userData2": "cluster $kvname pair data a"
+ },
+ "spec": {
+ "kv" : [
+ {"keyA": "value A"},
+ {"keyB": "value B"},
+ {"keyC": "value C"}
+ ]
+ }
+}
+EOF
+)"
+
+networkname="network-a"
+networkdata="$(cat<<EOF
+{
+ "metadata": {
+ "name": "$networkname",
+ "description": "Description of $networkname",
+ "userData1": "$networkname data part A",
+ "userData2": "$networkname data part B"
+ },
+ "spec": {
+ "cniType": "ovn4nfv",
+ "ipv4Subnets": [
+ {
+ "subnet": "172.16.33.0/24",
+ "name": "subnet3",
+ "gateway": "172.16.33.1/32",
+ "excludeIps": "172.16.33.2 172.16.33.5..172.16.33.10"
+ },
+ {
+ "subnet": "172.16.34.0/24",
+ "name": "subnet4",
+ "gateway": "172.16.34.1/32",
+ "excludeIps": "172.16.34.2 172.16.34.5..172.16.34.10"
+ }
+ ]
+ }
+}
+EOF
+)"
+
+providernetworkname="providernetwork-a"
+providernetworkdata="$(cat<<EOF
+{
+ "metadata": {
+ "name": "$providernetworkname",
+ "description": "Description of $providernetworkname",
+ "userData1": "$providernetworkname data part A",
+ "userData2": "$providernetworkname data part B"
+ },
+ "spec": {
+ "cniType": "ovn4nfv",
+ "ipv4Subnets": [
+ {
+ "subnet": "172.16.31.0/24",
+ "name": "subnet1",
+ "gateway": "172.16.31.1/32",
+ "excludeIps": "172.16.31.2 172.16.31.5..172.16.31.10"
+ },
+ {
+ "subnet": "172.16.32.0/24",
+ "name": "subnet2",
+ "gateway": "172.16.32.1/32",
+ "excludeIps": "172.16.32.2 172.16.32.5..172.16.32.10"
+ }
+ ],
+ "providerNetType": "VLAN",
+ "vlan": {
+ "vlanId": 100,
+ "providerInterfaceName": "eth1",
+ "logicalInterfaceName": "eth1.100",
+ "vlanNodeSelector": "specific",
+ "nodeLabelList": [
+ "kubernetes.io/hostname=localhost",
+ "kubernetes.io/name=localhost"
+ ]
+ }
+ }
+}
+EOF
+)"
+
+
+function createNcmData {
+ call_api -d "${clusterproviderdata}" "${base_url}/cluster-providers"
+ call_api -H "Content-Type: multipart/form-data" -F "metadata=$clusterdata" -F "file=@$kubeconfigfile" "${base_url}/cluster-providers/${clusterprovidername}/clusters"
+ call_api -d "${labeldata}" "${base_url}/cluster-providers/${clusterprovidername}/clusters/${clustername}/labels"
+ call_api -d "${kvdata}" "${base_url}/cluster-providers/${clusterprovidername}/clusters/${clustername}/kv-pairs"
+ call_api -d "${providernetworkdata}" "${base_url}/cluster-providers/${clusterprovidername}/clusters/${clustername}/provider-networks"
+ call_api -d "${networkdata}" "${base_url}/cluster-providers/${clusterprovidername}/clusters/${clustername}/networks"
+}
+
+# apply the network and providernetwork to an appcontext and instantiate with resource synchronizer (when implemented)
+function applyNcmData {
+ call_api -d "{ }" "${base_url}/cluster-providers/${clusterprovidername}/clusters/${clustername}/apply"
+}
+
+# deletes the appcontext (eventually will terminate from resource synchronizer when that funcationality is ready)
+function terminateNcmData {
+ call_api -d "{ }" "${base_url}/cluster-providers/${clusterprovidername}/clusters/${clustername}/terminate"
+}
+
+function getNcmData {
+ call_api "${base_url}/cluster-providers/${clusterprovidername}" | jq .
+ call_api -H "Accept: application/json" "${base_url}/cluster-providers/${clusterprovidername}/clusters/${clustername}" | jq .
+ call_api "${base_url}/cluster-providers/${clusterprovidername}/clusters?label=${labelname}" | jq .
+ call_api "${base_url}/cluster-providers/${clusterprovidername}/clusters/${clustername}/kv-pairs/${kvname}" | jq .
+ call_api "${base_url}/cluster-providers/${clusterprovidername}/clusters/${clustername}/networks/${networkname}" | jq .
+ call_api "${base_url}/cluster-providers/${clusterprovidername}/clusters/${clustername}/provider-networks/${providernetworkname}" | jq .
+
+}
+
+function deleteNcmData {
+ call_api -X DELETE "${base_url}/cluster-providers/${clusterprovidername}/clusters/${clustername}/networks/${networkname}"
+ call_api -X DELETE "${base_url}/cluster-providers/${clusterprovidername}/clusters/${clustername}/provider-networks/${providernetworkname}"
+ call_api -X DELETE "${base_url}/cluster-providers/${clusterprovidername}/clusters/${clustername}/labels/${labelname}"
+ call_api -X DELETE "${base_url}/cluster-providers/${clusterprovidername}/clusters/${clustername}/kv-pairs/${kvname}"
+ call_api -X DELETE "${base_url}/cluster-providers/${clusterprovidername}/clusters/${clustername}"
+ call_api -X DELETE "${base_url}/cluster-providers/${clusterprovidername}"
+}
+
+function usage {
+ echo "Usage: $0 create|apply|get|terminate|delete"
+ exit
+}
+
+# Put in logic to select from a few choices: create, get, delete
+if [ "$#" -ne 1 ] ; then
+ usage
+fi
+
+case "$1" in
+ "create" ) createNcmData ;;
+ "apply" ) applyNcmData ;;
+ "terminate" ) terminateNcmData ;;
+ "get" ) getNcmData ;;
+ "delete" ) deleteNcmData ;;
+ *) usage ;;
+esac
diff --git a/src/ncm/cmd/main.go b/src/ncm/cmd/main.go
index c4ae423f..49af81ee 100644
--- a/src/ncm/cmd/main.go
+++ b/src/ncm/cmd/main.go
@@ -15,23 +15,73 @@ package main
import (
"context"
+ "fmt"
"log"
"math/rand"
+ "net"
"net/http"
"os"
"os/signal"
+ "strings"
"time"
"github.com/gorilla/handlers"
"github.com/onap/multicloud-k8s/src/ncm/api"
+ register "github.com/onap/multicloud-k8s/src/ncm/pkg/grpc"
+ "github.com/onap/multicloud-k8s/src/ncm/pkg/grpc/contextupdateserver"
+ updatepb "github.com/onap/multicloud-k8s/src/orchestrator/pkg/grpc/contextupdate"
"github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/auth"
"github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/config"
contextDb "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/contextdb"
"github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/db"
+ "google.golang.org/grpc"
+ "google.golang.org/grpc/credentials"
+ "google.golang.org/grpc/testdata"
)
-func main() {
+func startGrpcServer() error {
+ var tls bool
+
+ if strings.Contains(config.GetConfiguration().GrpcEnableTLS, "enable") {
+ tls = true
+ } else {
+ tls = false
+ }
+ certFile := config.GetConfiguration().GrpcServerCert
+ keyFile := config.GetConfiguration().GrpcServerKey
+
+ host, port := register.GetServerHostPort()
+
+ lis, err := net.Listen("tcp", fmt.Sprintf("%s:%d", host, port))
+ if err != nil {
+ log.Fatalf("Could not listen to port: %v", err)
+ }
+ var opts []grpc.ServerOption
+ if tls {
+ if certFile == "" {
+ certFile = testdata.Path("server.pem")
+ }
+ if keyFile == "" {
+ keyFile = testdata.Path("server.key")
+ }
+ creds, err := credentials.NewServerTLSFromFile(certFile, keyFile)
+ if err != nil {
+ log.Fatalf("Could not generate credentials %v", err)
+ }
+ opts = []grpc.ServerOption{grpc.Creds(creds)}
+ }
+ grpcServer := grpc.NewServer(opts...)
+ updatepb.RegisterContextupdateServer(grpcServer, contextupdateserver.NewContextupdateServer())
+ log.Println("Starting Network Configuration Manager gRPC Server")
+ err = grpcServer.Serve(lis)
+ if err != nil {
+ log.Fatalf("ncm grpc server is not serving %v", err)
+ }
+ return err
+}
+
+func main() {
rand.Seed(time.Now().UnixNano())
err := db.InitializeDatabaseConnection("mco")
@@ -56,6 +106,13 @@ func main() {
Addr: ":" + config.GetConfiguration().ServicePort,
}
+ go func() {
+ err := startGrpcServer()
+ if err != nil {
+ log.Fatalf("GRPC server failed to start")
+ }
+ }()
+
connectionsClose := make(chan struct{})
go func() {
c := make(chan os.Signal, 1)
diff --git a/src/ncm/go.mod b/src/ncm/go.mod
index 8b45298f..19f83bdf 100644
--- a/src/ncm/go.mod
+++ b/src/ncm/go.mod
@@ -13,6 +13,7 @@ require (
go.etcd.io/etcd v3.3.12+incompatible
go.mongodb.org/mongo-driver v1.0.0
golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3
+ google.golang.org/grpc v1.27.1
gopkg.in/yaml.v2 v2.2.8
k8s.io/api v0.0.0-20190831074750-7364b6bdad65
k8s.io/apimachinery v0.0.0-20190831074630-461753078381
diff --git a/src/ncm/pkg/grpc/contextupdateserver/contextupdateserver.go b/src/ncm/pkg/grpc/contextupdateserver/contextupdateserver.go
new file mode 100644
index 00000000..fc548ccc
--- /dev/null
+++ b/src/ncm/pkg/grpc/contextupdateserver/contextupdateserver.go
@@ -0,0 +1,45 @@
+/*
+Copyright 2020 Intel Corporation.
+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 contextupdateserver
+
+import (
+ "context"
+ "encoding/json"
+ "log"
+
+ contextpb "github.com/onap/multicloud-k8s/src/orchestrator/pkg/grpc/contextupdate"
+ //"google.golang.org/grpc/codes"
+ //"google.golang.org/grpc/status"
+)
+
+type contextupdateServer struct {
+ contextpb.UnimplementedContextupdateServer
+}
+
+func (cs *contextupdateServer) UpdateAppContext(ctx context.Context, req *contextpb.ContextUpdateRequest) (*contextpb.ContextUpdateResponse, error) {
+ contextUpdateReq, _ := json.Marshal(req)
+ log.Println("GRPC Server received contextupdateRequest: ", string(contextUpdateReq))
+
+ // Insert call to Server Functionality here
+ //
+ //
+
+ return &contextpb.ContextUpdateResponse{AppContextUpdated: true}, nil
+}
+
+// NewContextUpdateServer exported
+func NewContextupdateServer() *contextupdateServer {
+ s := &contextupdateServer{}
+ return s
+}
diff --git a/src/ncm/pkg/grpc/register.go b/src/ncm/pkg/grpc/register.go
new file mode 100644
index 00000000..07d8f5c0
--- /dev/null
+++ b/src/ncm/pkg/grpc/register.go
@@ -0,0 +1,58 @@
+/*
+Copyright 2020 Intel Corporation.
+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 grpc
+
+import (
+ "os"
+ "strconv"
+ "strings"
+
+ log "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/logutils"
+)
+
+const default_host = "localhost"
+const default_port = 9030
+const default_ncm_name = "ncm"
+const ENV_NCM_NAME = "NCM_NAME"
+
+func GetServerHostPort() (string, int) {
+
+ // expect name of this ncm program to be in env variable "NCM_NAME" - e.g. NCM_NAME="ncm"
+ serviceName := os.Getenv(ENV_NCM_NAME)
+ if serviceName == "" {
+ serviceName = default_ncm_name
+ log.Info("Using default name for NCM service name", log.Fields{
+ "Name": serviceName,
+ })
+ }
+
+ // expect service name to be in env variable - e.g. NCM_SERVICE_HOST
+ host := os.Getenv(strings.ToUpper(serviceName) + "_SERVICE_HOST")
+ if host == "" {
+ host = default_host
+ log.Info("Using default host for ncm gRPC controller", log.Fields{
+ "Host": host,
+ })
+ }
+
+ // expect service port to be in env variable - e.g. NCM_SERVICE_PORT
+ port, err := strconv.Atoi(os.Getenv(strings.ToUpper(serviceName) + "_SERVICE_PORT"))
+ if err != nil || port < 0 {
+ port = default_port
+ log.Info("Using default port for ncm gRPC controller", log.Fields{
+ "Port": port,
+ })
+ }
+ return host, port
+}
diff --git a/src/orchestrator/api/api.go b/src/orchestrator/api/api.go
index 8b4b91a1..5703226f 100644
--- a/src/orchestrator/api/api.go
+++ b/src/orchestrator/api/api.go
@@ -19,6 +19,7 @@ package api
import (
"github.com/gorilla/mux"
moduleLib "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module"
+ controller "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module/controller"
)
var moduleClient *moduleLib.Client
@@ -27,7 +28,7 @@ var moduleClient *moduleLib.Client
func NewRouter(projectClient moduleLib.ProjectManager,
compositeAppClient moduleLib.CompositeAppManager,
appClient moduleLib.AppManager,
- ControllerClient moduleLib.ControllerManager,
+ ControllerClient controller.ControllerManager,
genericPlacementIntentClient moduleLib.GenericPlacementIntentManager,
appIntentClient moduleLib.AppIntentManager,
deploymentIntentGrpClient moduleLib.DeploymentIntentGroupManager,
diff --git a/src/orchestrator/api/controllerhandler.go b/src/orchestrator/api/controllerhandler.go
index 1dad2bf8..5df691f3 100644
--- a/src/orchestrator/api/controllerhandler.go
+++ b/src/orchestrator/api/controllerhandler.go
@@ -23,7 +23,8 @@ import (
"github.com/gorilla/mux"
"github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/validation"
- moduleLib "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module"
+ controller "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module/controller"
+ mtypes "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module/types"
pkgerrors "github.com/pkg/errors"
)
@@ -32,13 +33,13 @@ import (
type controllerHandler struct {
// Interface that implements controller operations
// We will set this variable with a mock interface for testing
- client moduleLib.ControllerManager
+ client controller.ControllerManager
}
// Check for valid format of input parameters
-func validateControllerInputs(c moduleLib.Controller) error {
+func validateControllerInputs(c controller.Controller) error {
// validate metadata
- err := moduleLib.IsValidMetadata(c.Metadata)
+ err := mtypes.IsValidMetadata(c.Metadata)
if err != nil {
return pkgerrors.Wrap(err, "Invalid controller metadata")
}
@@ -54,7 +55,7 @@ func validateControllerInputs(c moduleLib.Controller) error {
}
found := false
- for _, val := range moduleLib.CONTROLLER_TYPES {
+ for _, val := range controller.CONTROLLER_TYPES {
if c.Spec.Type == val {
found = true
break
@@ -64,7 +65,7 @@ func validateControllerInputs(c moduleLib.Controller) error {
return pkgerrors.Errorf("Invalid controller type: %v", c.Spec.Type)
}
- errs = validation.IsValidNumber(c.Spec.Priority, moduleLib.MinControllerPriority, moduleLib.MaxControllerPriority)
+ errs = validation.IsValidNumber(c.Spec.Priority, controller.MinControllerPriority, controller.MaxControllerPriority)
if len(errs) > 0 {
return pkgerrors.Errorf("Invalid controller priority = [%v], errors: %v", c.Spec.Priority, errs)
}
@@ -74,7 +75,7 @@ func validateControllerInputs(c moduleLib.Controller) error {
// Create handles creation of the controller entry in the database
func (h controllerHandler) createHandler(w http.ResponseWriter, r *http.Request) {
- var m moduleLib.Controller
+ var m controller.Controller
err := json.NewDecoder(r.Body).Decode(&m)
switch {
@@ -109,7 +110,7 @@ func (h controllerHandler) createHandler(w http.ResponseWriter, r *http.Request)
// Put handles creation or update of the controller entry in the database
func (h controllerHandler) putHandler(w http.ResponseWriter, r *http.Request) {
- var m moduleLib.Controller
+ var m controller.Controller
vars := mux.Vars(r)
name := vars["controller-name"]
diff --git a/src/orchestrator/api/controllerhandler_test.go b/src/orchestrator/api/controllerhandler_test.go
index b88fc1e7..6cbb2a79 100644
--- a/src/orchestrator/api/controllerhandler_test.go
+++ b/src/orchestrator/api/controllerhandler_test.go
@@ -25,7 +25,8 @@ import (
"reflect"
"testing"
- moduleLib "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module"
+ "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module/controller"
+ "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module/types"
pkgerrors "github.com/pkg/errors"
)
@@ -36,29 +37,29 @@ import (
type mockControllerManager struct {
// Items and err will be used to customize each test
// via a localized instantiation of mockControllerManager
- Items []moduleLib.Controller
+ Items []controller.Controller
Err error
}
-func (m *mockControllerManager) CreateController(inp moduleLib.Controller, mayExist bool) (moduleLib.Controller, error) {
+func (m *mockControllerManager) CreateController(inp controller.Controller, mayExist bool) (controller.Controller, error) {
if m.Err != nil {
- return moduleLib.Controller{}, m.Err
+ return controller.Controller{}, m.Err
}
return m.Items[0], nil
}
-func (m *mockControllerManager) GetController(name string) (moduleLib.Controller, error) {
+func (m *mockControllerManager) GetController(name string) (controller.Controller, error) {
if m.Err != nil {
- return moduleLib.Controller{}, m.Err
+ return controller.Controller{}, m.Err
}
return m.Items[0], nil
}
-func (m *mockControllerManager) GetControllers() ([]moduleLib.Controller, error) {
+func (m *mockControllerManager) GetControllers() ([]controller.Controller, error) {
if m.Err != nil {
- return []moduleLib.Controller{}, m.Err
+ return []controller.Controller{}, m.Err
}
return m.Items, nil
@@ -76,7 +77,7 @@ func TestControllerCreateHandler(t *testing.T) {
testCases := []struct {
label string
reader io.Reader
- expected moduleLib.Controller
+ expected controller.Controller
expectedCode int
controllerClient *mockControllerManager
}{
@@ -96,23 +97,23 @@ func TestControllerCreateHandler(t *testing.T) {
"ip-address":"10.188.234.1",
"port":8080 }
}`)),
- expected: moduleLib.Controller{
- Metadata: moduleLib.Metadata{
+ expected: controller.Controller{
+ Metadata: types.Metadata{
Name: "testController",
},
- Spec: moduleLib.ControllerSpec{
+ Spec: controller.ControllerSpec{
Host: "10.188.234.1",
Port: 8080,
},
},
controllerClient: &mockControllerManager{
//Items that will be returned by the mocked Client
- Items: []moduleLib.Controller{
+ Items: []controller.Controller{
{
- Metadata: moduleLib.Metadata{
+ Metadata: types.Metadata{
Name: "testController",
},
- Spec: moduleLib.ControllerSpec{
+ Spec: controller.ControllerSpec{
Host: "10.188.234.1",
Port: 8080,
},
@@ -142,7 +143,7 @@ func TestControllerCreateHandler(t *testing.T) {
//Check returned body only if statusCreated
if resp.StatusCode == http.StatusCreated {
- got := moduleLib.Controller{}
+ got := controller.Controller{}
json.NewDecoder(resp.Body).Decode(&got)
if reflect.DeepEqual(testCase.expected, got) == false {
@@ -158,7 +159,7 @@ func TestControllerGetHandler(t *testing.T) {
testCases := []struct {
label string
- expected moduleLib.Controller
+ expected controller.Controller
name, version string
expectedCode int
controllerClient *mockControllerManager
@@ -166,23 +167,23 @@ func TestControllerGetHandler(t *testing.T) {
{
label: "Get Controller",
expectedCode: http.StatusOK,
- expected: moduleLib.Controller{
- Metadata: moduleLib.Metadata{
+ expected: controller.Controller{
+ Metadata: types.Metadata{
Name: "testController",
},
- Spec: moduleLib.ControllerSpec{
+ Spec: controller.ControllerSpec{
Host: "10.188.234.1",
Port: 8080,
},
},
name: "testController",
controllerClient: &mockControllerManager{
- Items: []moduleLib.Controller{
+ Items: []controller.Controller{
{
- Metadata: moduleLib.Metadata{
+ Metadata: types.Metadata{
Name: "testController",
},
- Spec: moduleLib.ControllerSpec{
+ Spec: controller.ControllerSpec{
Host: "10.188.234.1",
Port: 8080,
},
@@ -195,7 +196,7 @@ func TestControllerGetHandler(t *testing.T) {
expectedCode: http.StatusInternalServerError,
name: "nonexistingController",
controllerClient: &mockControllerManager{
- Items: []moduleLib.Controller{},
+ Items: []controller.Controller{},
Err: pkgerrors.New("Internal Error"),
},
},
@@ -213,7 +214,7 @@ func TestControllerGetHandler(t *testing.T) {
//Check returned body only if statusOK
if resp.StatusCode == http.StatusOK {
- got := moduleLib.Controller{}
+ got := controller.Controller{}
json.NewDecoder(resp.Body).Decode(&got)
if reflect.DeepEqual(testCase.expected, got) == false {
diff --git a/src/orchestrator/cmd/main.go b/src/orchestrator/cmd/main.go
index 7f258bbf..b5792b9b 100644
--- a/src/orchestrator/cmd/main.go
+++ b/src/orchestrator/cmd/main.go
@@ -29,7 +29,7 @@ import (
contextDb "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/contextdb"
"github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/db"
"github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/rpc"
- "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module"
+ "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module/controller"
)
func main() {
@@ -58,7 +58,7 @@ func main() {
Addr: ":" + config.GetConfiguration().ServicePort,
}
- module.NewControllerClient().InitControllers()
+ controller.NewControllerClient().InitControllers()
connectionsClose := make(chan struct{})
go func() {
diff --git a/src/orchestrator/pkg/module/controller.go b/src/orchestrator/pkg/module/controller/controller.go
index 6827af87..c4957413 100644
--- a/src/orchestrator/pkg/module/controller.go
+++ b/src/orchestrator/pkg/module/controller/controller.go
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package module
+package controller
import (
"encoding/json"
@@ -22,14 +22,15 @@ import (
"github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/db"
log "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/logutils"
rpc "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/rpc"
+ mtypes "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module/types"
pkgerrors "github.com/pkg/errors"
)
// Controller contains the parameters needed for Controllers
// It implements the interface for managing the Controllers
type Controller struct {
- Metadata Metadata `json:"metadata"`
- Spec ControllerSpec `json:"spec"`
+ Metadata mtypes.Metadata `json:"metadata"`
+ Spec ControllerSpec `json:"spec"`
}
type ControllerSpec struct {
diff --git a/src/orchestrator/pkg/module/controller_test.go b/src/orchestrator/pkg/module/controller/controller_test.go
index a13f43a5..44e7a0ca 100644
--- a/src/orchestrator/pkg/module/controller_test.go
+++ b/src/orchestrator/pkg/module/controller/controller_test.go
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package module
+package controller
import (
"reflect"
@@ -22,6 +22,7 @@ import (
"testing"
"github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/db"
+ "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module/types"
pkgerrors "github.com/pkg/errors"
)
@@ -37,7 +38,7 @@ func TestCreateController(t *testing.T) {
{
label: "Create Controller",
inp: Controller{
- Metadata: Metadata{
+ Metadata: types.Metadata{
Name: "testController",
},
Spec: ControllerSpec{
@@ -46,7 +47,7 @@ func TestCreateController(t *testing.T) {
},
},
expected: Controller{
- Metadata: Metadata{
+ Metadata: types.Metadata{
Name: "testController",
},
Spec: ControllerSpec{
@@ -102,7 +103,7 @@ func TestGetController(t *testing.T) {
label: "Get Controller",
name: "testController",
expected: Controller{
- Metadata: Metadata{
+ Metadata: types.Metadata{
Name: "testController",
},
Spec: ControllerSpec{
diff --git a/src/orchestrator/pkg/module/module.go b/src/orchestrator/pkg/module/module.go
index 463a55b3..5ac704e6 100644
--- a/src/orchestrator/pkg/module/module.go
+++ b/src/orchestrator/pkg/module/module.go
@@ -17,8 +17,7 @@
package module
import (
- "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/validation"
- pkgerrors "github.com/pkg/errors"
+ "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module/controller"
)
// Client for using the services in the orchestrator
@@ -26,7 +25,7 @@ type Client struct {
Project *ProjectClient
CompositeApp *CompositeAppClient
App *AppClient
- Controller *ControllerClient
+ Controller *controller.ControllerClient
GenericPlacementIntent *GenericPlacementIntentClient
AppIntent *AppIntentClient
DeploymentIntentGroup *DeploymentIntentGroupClient
@@ -43,7 +42,7 @@ func NewClient() *Client {
c.Project = NewProjectClient()
c.CompositeApp = NewCompositeAppClient()
c.App = NewAppClient()
- c.Controller = NewControllerClient()
+ c.Controller = controller.NewControllerClient()
c.GenericPlacementIntent = NewGenericPlacementIntentClient()
c.AppIntent = NewAppIntentClient()
c.DeploymentIntentGroup = NewDeploymentIntentGroupClient()
@@ -54,39 +53,3 @@ func NewClient() *Client {
c.Instantiation = NewInstantiationClient()
return c
}
-
-// It implements the interface for managing the ClusterProviders
-const MAX_DESCRIPTION_LEN int = 1024
-const MAX_USERDATA_LEN int = 4096
-
-type Metadata struct {
- Name string `json:"name" yaml:"name"`
- Description string `json:"description" yaml:"-"`
- UserData1 string `json:"userData1" yaml:"-"`
- UserData2 string `json:"userData2" yaml:"-"`
-}
-
-// Check for valid format Metadata
-func IsValidMetadata(metadata Metadata) error {
- errs := validation.IsValidName(metadata.Name)
- if len(errs) > 0 {
- return pkgerrors.Errorf("Invalid Metadata name=[%v], errors: %v", metadata.Name, errs)
- }
-
- errs = validation.IsValidString(metadata.Description, 0, MAX_DESCRIPTION_LEN, validation.VALID_ANY_STR)
- if len(errs) > 0 {
- return pkgerrors.Errorf("Invalid Metadata description=[%v], errors: %v", metadata.Description, errs)
- }
-
- errs = validation.IsValidString(metadata.UserData1, 0, MAX_DESCRIPTION_LEN, validation.VALID_ANY_STR)
- if len(errs) > 0 {
- return pkgerrors.Errorf("Invalid Metadata description=[%v], errors: %v", metadata.UserData1, errs)
- }
-
- errs = validation.IsValidString(metadata.UserData2, 0, MAX_DESCRIPTION_LEN, validation.VALID_ANY_STR)
- if len(errs) > 0 {
- return pkgerrors.Errorf("Invalid Metadata description=[%v], errors: %v", metadata.UserData2, errs)
- }
-
- return nil
-}
diff --git a/src/orchestrator/pkg/module/types/types.go b/src/orchestrator/pkg/module/types/types.go
new file mode 100644
index 00000000..0159444d
--- /dev/null
+++ b/src/orchestrator/pkg/module/types/types.go
@@ -0,0 +1,58 @@
+/*
+ * 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 types
+
+import (
+ "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/validation"
+ pkgerrors "github.com/pkg/errors"
+)
+
+// It implements the interface for managing the ClusterProviders
+const MAX_DESCRIPTION_LEN int = 1024
+const MAX_USERDATA_LEN int = 4096
+
+type Metadata struct {
+ Name string `json:"name" yaml:"name"`
+ Description string `json:"description" yaml:"-"`
+ UserData1 string `json:"userData1" yaml:"-"`
+ UserData2 string `json:"userData2" yaml:"-"`
+}
+
+// Check for valid format Metadata
+func IsValidMetadata(metadata Metadata) error {
+ errs := validation.IsValidName(metadata.Name)
+ if len(errs) > 0 {
+ return pkgerrors.Errorf("Invalid Metadata name=[%v], errors: %v", metadata.Name, errs)
+ }
+
+ errs = validation.IsValidString(metadata.Description, 0, MAX_DESCRIPTION_LEN, validation.VALID_ANY_STR)
+ if len(errs) > 0 {
+ return pkgerrors.Errorf("Invalid Metadata description=[%v], errors: %v", metadata.Description, errs)
+ }
+
+ errs = validation.IsValidString(metadata.UserData1, 0, MAX_DESCRIPTION_LEN, validation.VALID_ANY_STR)
+ if len(errs) > 0 {
+ return pkgerrors.Errorf("Invalid Metadata description=[%v], errors: %v", metadata.UserData1, errs)
+ }
+
+ errs = validation.IsValidString(metadata.UserData2, 0, MAX_DESCRIPTION_LEN, validation.VALID_ANY_STR)
+ if len(errs) > 0 {
+ return pkgerrors.Errorf("Invalid Metadata description=[%v], errors: %v", metadata.UserData2, errs)
+ }
+
+ return nil
+}