diff options
Diffstat (limited to 'src/orchestrator/api')
-rw-r--r-- | src/orchestrator/api/api.go | 3 | ||||
-rw-r--r-- | src/orchestrator/api/controllerhandler.go | 17 | ||||
-rw-r--r-- | src/orchestrator/api/controllerhandler_test.go | 51 |
3 files changed, 37 insertions, 34 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 { |