aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEric Multanen <eric.w.multanen@intel.com>2020-05-12 14:28:33 -0700
committerEric Multanen <eric.w.multanen@intel.com>2020-05-12 17:04:18 -0700
commitbd3e69e7a26aaa00d3367f1eeb78e91e63ebd404 (patch)
treec3188dc4f1d5a1215d27cc73d1b2fac038f23ba8 /src
parenteafedad99d1bc3ea0ffa2fb82bb8be6b7687e335 (diff)
Move controller module into separate package
Move the controller part of the module package into a separate controller package. Issue-ID: MULTICLOUD-1029 Signed-off-by: Eric Multanen <eric.w.multanen@intel.com> Change-Id: Id07c1012aeff8a72458b37d42671495510cade75
Diffstat (limited to 'src')
-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
8 files changed, 109 insertions, 83 deletions
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
+}