aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/api
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2018-11-15 17:09:54 -0800
committerVictor Morales <victor.morales@intel.com>2018-11-19 14:41:49 -0800
commit3f780f7973081903f1ab6ea01a855fb6c5512a48 (patch)
tree93c596d4b438df56fc9894162b1f5a2292ea0068 /src/k8splugin/api
parent1b76b8fada122365b9adf99cc305721cc114d30a (diff)
Reconcile names in code and Jira items
k8splugin manages deployment of resource bundles and these are not restricted to vnfs. This names' change is to reflect that functionality. P2: using rb instead of resource bundle Issue-ID: MULTICLOUD-410 Change-Id: I09e0b92a8fc13562e1c6bb17dc8bc13de97264d7 Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src/k8splugin/api')
-rw-r--r--src/k8splugin/api/api.go16
-rw-r--r--src/k8splugin/api/defhandler.go (renamed from src/k8splugin/api/vnfdhandler.go)46
-rw-r--r--src/k8splugin/api/defhandler_test.go (renamed from src/k8splugin/api/vnfdhandler_test.go)136
3 files changed, 99 insertions, 99 deletions
diff --git a/src/k8splugin/api/api.go b/src/k8splugin/api/api.go
index f05fbb0b..571a9576 100644
--- a/src/k8splugin/api/api.go
+++ b/src/k8splugin/api/api.go
@@ -14,7 +14,7 @@ limitations under the License.
package api
import (
- "k8splugin/vnfd"
+ "k8splugin/rb"
"os"
"path/filepath"
"plugin"
@@ -106,13 +106,13 @@ func NewRouter(kubeconfig string) *mux.Router {
vnfInstanceHandler.HandleFunc("/{cloudRegionID}/{namespace}/{externalVNFID}", DeleteHandler).Methods("DELETE")
vnfInstanceHandler.HandleFunc("/{cloudRegionID}/{namespace}/{externalVNFID}", GetHandler).Methods("GET")
- vnfdRouter := router.PathPrefix("/v1/vnfd").Subrouter()
- vh := vnfdHandler{vnfdClient: vnfd.GetVNFDClient()}
- vnfdRouter.HandleFunc("", vh.vnfdCreateHandler).Methods("POST")
- vnfdRouter.HandleFunc("/{vnfdID}/upload", vh.vnfdUploadHandler).Methods("POST")
- vnfdRouter.HandleFunc("", vh.vnfdListHandler).Methods("GET")
- vnfdRouter.HandleFunc("/{vnfdID}", vh.vnfdGetHandler).Methods("GET")
- vnfdRouter.HandleFunc("/{vnfdID}", vh.vnfdDeleteHandler).Methods("DELETE")
+ resRouter := router.PathPrefix("/v1/rb").Subrouter()
+ rbdef := rbDefinitionHandler{client: rb.NewDefinitionClient()}
+ resRouter.HandleFunc("/definition", rbdef.createHandler).Methods("POST")
+ resRouter.HandleFunc("/definition/{rbdID}/upload", rbdef.uploadHandler).Methods("POST")
+ resRouter.HandleFunc("/definition", rbdef.listHandler).Methods("GET")
+ resRouter.HandleFunc("/definition/{rbdID}", rbdef.getHandler).Methods("GET")
+ resRouter.HandleFunc("/definition/{rbdID}", rbdef.deleteHandler).Methods("DELETE")
// (TODO): Fix update method
// vnfInstanceHandler.HandleFunc("/{vnfInstanceId}", UpdateHandler).Methods("PUT")
diff --git a/src/k8splugin/api/vnfdhandler.go b/src/k8splugin/api/defhandler.go
index ff777826..c8c03496 100644
--- a/src/k8splugin/api/vnfdhandler.go
+++ b/src/k8splugin/api/defhandler.go
@@ -20,22 +20,22 @@ import (
"encoding/json"
"net/http"
- "k8splugin/vnfd"
+ "k8splugin/rb"
"github.com/gorilla/mux"
)
// Used to store backend implementations objects
// Also simplifies mocking for unit testing purposes
-type vnfdHandler struct {
- // Interface that implements vnfDefinition operations
+type rbDefinitionHandler struct {
+ // Interface that implements bundle Definition operations
// We will set this variable with a mock interface for testing
- vnfdClient vnfd.VNFDefinitionInterface
+ client rb.DefinitionManager
}
-// vnfdCreateHandler handles creation of the vnfd entry in the database
-func (h vnfdHandler) vnfdCreateHandler(w http.ResponseWriter, r *http.Request) {
- var v vnfd.VNFDefinition
+// createHandler handles creation of the definition entry in the database
+func (h rbDefinitionHandler) createHandler(w http.ResponseWriter, r *http.Request) {
+ var v rb.Definition
if r.Body == nil {
http.Error(w, "Empty body", http.StatusBadRequest)
@@ -54,7 +54,7 @@ func (h vnfdHandler) vnfdCreateHandler(w http.ResponseWriter, r *http.Request) {
return
}
- ret, err := h.vnfdClient.Create(v)
+ ret, err := h.client.Create(v)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@@ -69,15 +69,15 @@ func (h vnfdHandler) vnfdCreateHandler(w http.ResponseWriter, r *http.Request) {
}
}
-// vnfdUploadHandler handles upload of the vnf tar file into the database
+// uploadHandler handles upload of the bundle tar file into the database
// Note: This will be implemented in a different patch
-func (h vnfdHandler) vnfdUploadHandler(w http.ResponseWriter, r *http.Request) {
+func (h rbDefinitionHandler) uploadHandler(w http.ResponseWriter, r *http.Request) {
}
-// vnfdListHandler handles GET (list) operations on the /v1/vnfd endpoint
-// Returns a list of vnfd.VNFDefinitions
-func (h vnfdHandler) vnfdListHandler(w http.ResponseWriter, r *http.Request) {
- ret, err := h.vnfdClient.List()
+// listHandler handles GET (list) operations on the endpoint
+// Returns a list of rb.Definitions
+func (h rbDefinitionHandler) listHandler(w http.ResponseWriter, r *http.Request) {
+ ret, err := h.client.List()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@@ -92,13 +92,13 @@ func (h vnfdHandler) vnfdListHandler(w http.ResponseWriter, r *http.Request) {
}
}
-// vnfdGetHandler handles GET operations on a particular VNFID
-// Returns a vnfd.VNFDefinition
-func (h vnfdHandler) vnfdGetHandler(w http.ResponseWriter, r *http.Request) {
+// getHandler handles GET operations on a particular ids
+// Returns a rb.Definition
+func (h rbDefinitionHandler) getHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
- vnfdID := vars["vnfdID"]
+ id := vars["rbdID"]
- ret, err := h.vnfdClient.Get(vnfdID)
+ ret, err := h.client.Get(id)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@@ -113,12 +113,12 @@ func (h vnfdHandler) vnfdGetHandler(w http.ResponseWriter, r *http.Request) {
}
}
-// vnfdDeleteHandler handles DELETE operations on a particular VNFID
-func (h vnfdHandler) vnfdDeleteHandler(w http.ResponseWriter, r *http.Request) {
+// deleteHandler handles DELETE operations on a particular bundle definition id
+func (h rbDefinitionHandler) deleteHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
- vnfdID := vars["vnfdID"]
+ id := vars["rbdID"]
- err := h.vnfdClient.Delete(vnfdID)
+ err := h.client.Delete(id)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
diff --git a/src/k8splugin/api/vnfdhandler_test.go b/src/k8splugin/api/defhandler_test.go
index e393be6f..b83f0b7a 100644
--- a/src/k8splugin/api/vnfdhandler_test.go
+++ b/src/k8splugin/api/defhandler_test.go
@@ -20,7 +20,7 @@ import (
"bytes"
"encoding/json"
"io"
- "k8splugin/vnfd"
+ "k8splugin/rb"
"net/http"
"net/http/httptest"
"reflect"
@@ -32,54 +32,54 @@ import (
//Creating an embedded interface via anonymous variable
//This allows us to make mockDB satisfy the DatabaseConnection
//interface even if we are not implementing all the methods in it
-type mockVNFDefinition struct {
- vnfd.VNFDefinitionInterface
+type mockRBDefinition struct {
+ rb.DefinitionManager
// Items and err will be used to customize each test
- // via a localized instantiation of mockVNFDefinition
- Items []vnfd.VNFDefinition
+ // via a localized instantiation of mockRBDefinition
+ Items []rb.Definition
Err error
}
-func (m *mockVNFDefinition) Create(inp vnfd.VNFDefinition) (vnfd.VNFDefinition, error) {
+func (m *mockRBDefinition) Create(inp rb.Definition) (rb.Definition, error) {
if m.Err != nil {
- return vnfd.VNFDefinition{}, m.Err
+ return rb.Definition{}, m.Err
}
return m.Items[0], nil
}
-func (m *mockVNFDefinition) List() ([]vnfd.VNFDefinition, error) {
+func (m *mockRBDefinition) List() ([]rb.Definition, error) {
if m.Err != nil {
- return []vnfd.VNFDefinition{}, m.Err
+ return []rb.Definition{}, m.Err
}
return m.Items, nil
}
-func (m *mockVNFDefinition) Get(vnfID string) (vnfd.VNFDefinition, error) {
+func (m *mockRBDefinition) Get(id string) (rb.Definition, error) {
if m.Err != nil {
- return vnfd.VNFDefinition{}, m.Err
+ return rb.Definition{}, m.Err
}
return m.Items[0], nil
}
-func (m *mockVNFDefinition) Delete(vnfID string) error {
+func (m *mockRBDefinition) Delete(id string) error {
return m.Err
}
-func TestVnfdCreateHandler(t *testing.T) {
+func TestRBDefCreateHandler(t *testing.T) {
testCases := []struct {
label string
reader io.Reader
- expected vnfd.VNFDefinition
+ expected rb.Definition
expectedCode int
- vnfdClient *mockVNFDefinition
+ rbDefClient *mockRBDefinition
}{
{
label: "Missing Body Failure",
expectedCode: http.StatusBadRequest,
- vnfdClient: &mockVNFDefinition{},
+ rbDefClient: &mockRBDefinition{},
},
{
label: "Create without UUID",
@@ -89,18 +89,18 @@ func TestVnfdCreateHandler(t *testing.T) {
"description":"test description",
"service-type":"firewall"
}`)),
- expected: vnfd.VNFDefinition{
+ expected: rb.Definition{
UUID: "123e4567-e89b-12d3-a456-426655440000",
- Name: "testvnf",
+ Name: "testresourcebundle",
Description: "test description",
ServiceType: "firewall",
},
- vnfdClient: &mockVNFDefinition{
+ rbDefClient: &mockRBDefinition{
//Items that will be returned by the mocked Client
- Items: []vnfd.VNFDefinition{
+ Items: []rb.Definition{
{
UUID: "123e4567-e89b-12d3-a456-426655440000",
- Name: "testvnf",
+ Name: "testresourcebundle",
Description: "test description",
ServiceType: "firewall",
},
@@ -111,15 +111,15 @@ func TestVnfdCreateHandler(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.label, func(t *testing.T) {
- vh := vnfdHandler{vnfdClient: testCase.vnfdClient}
- req, err := http.NewRequest("POST", "/v1/vnfd", testCase.reader)
+ vh := rbDefinitionHandler{client: testCase.rbDefClient}
+ req, err := http.NewRequest("POST", "/v1/resource/definition", testCase.reader)
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
- hr := http.HandlerFunc(vh.vnfdCreateHandler)
+ hr := http.HandlerFunc(vh.createHandler)
hr.ServeHTTP(rr, req)
//Check returned code
@@ -129,11 +129,11 @@ func TestVnfdCreateHandler(t *testing.T) {
//Check returned body only if statusCreated
if rr.Code == http.StatusCreated {
- got := vnfd.VNFDefinition{}
+ got := rb.Definition{}
json.NewDecoder(rr.Body).Decode(&got)
if reflect.DeepEqual(testCase.expected, got) == false {
- t.Errorf("vnfdCreateHandler returned unexpected body: got %v;"+
+ t.Errorf("createHandler returned unexpected body: got %v;"+
" expected %v", got, testCase.expected)
}
}
@@ -141,43 +141,43 @@ func TestVnfdCreateHandler(t *testing.T) {
}
}
-func TestVnfdListHandler(t *testing.T) {
+func TestRBDefListHandler(t *testing.T) {
testCases := []struct {
label string
- expected []vnfd.VNFDefinition
+ expected []rb.Definition
expectedCode int
- vnfdClient *mockVNFDefinition
+ rbDefClient *mockRBDefinition
}{
{
- label: "List VNF Definitions",
+ label: "List Bundle Definitions",
expectedCode: http.StatusOK,
- expected: []vnfd.VNFDefinition{
+ expected: []rb.Definition{
{
UUID: "123e4567-e89b-12d3-a456-426655440000",
- Name: "testvnf",
+ Name: "testresourcebundle",
Description: "test description",
ServiceType: "firewall",
},
{
UUID: "123e4567-e89b-12d3-a456-426655441111",
- Name: "testvnf2",
+ Name: "testresourcebundle2",
Description: "test description",
ServiceType: "dns",
},
},
- vnfdClient: &mockVNFDefinition{
+ rbDefClient: &mockRBDefinition{
// list of definitions that will be returned by the mockclient
- Items: []vnfd.VNFDefinition{
+ Items: []rb.Definition{
{
UUID: "123e4567-e89b-12d3-a456-426655440000",
- Name: "testvnf",
+ Name: "testresourcebundle",
Description: "test description",
ServiceType: "firewall",
},
{
UUID: "123e4567-e89b-12d3-a456-426655441111",
- Name: "testvnf2",
+ Name: "testresourcebundle2",
Description: "test description",
ServiceType: "dns",
},
@@ -188,14 +188,14 @@ func TestVnfdListHandler(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.label, func(t *testing.T) {
- vh := vnfdHandler{vnfdClient: testCase.vnfdClient}
- req, err := http.NewRequest("GET", "/v1/vnfd", nil)
+ vh := rbDefinitionHandler{client: testCase.rbDefClient}
+ req, err := http.NewRequest("GET", "/v1/resource/definition", nil)
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
- hr := http.HandlerFunc(vh.vnfdListHandler)
+ hr := http.HandlerFunc(vh.listHandler)
hr.ServeHTTP(rr, req)
//Check returned code
@@ -205,11 +205,11 @@ func TestVnfdListHandler(t *testing.T) {
//Check returned body only if statusOK
if rr.Code == http.StatusOK {
- got := []vnfd.VNFDefinition{}
+ got := []rb.Definition{}
json.NewDecoder(rr.Body).Decode(&got)
if reflect.DeepEqual(testCase.expected, got) == false {
- t.Errorf("vnfdListHandler returned unexpected body: got %v;"+
+ t.Errorf("listHandler returned unexpected body: got %v;"+
" expected %v", got, testCase.expected)
}
}
@@ -217,31 +217,31 @@ func TestVnfdListHandler(t *testing.T) {
}
}
-func TestVnfdGetHandler(t *testing.T) {
+func TestRBDefGetHandler(t *testing.T) {
testCases := []struct {
label string
- expected vnfd.VNFDefinition
+ expected rb.Definition
inpUUID string
expectedCode int
- vnfdClient *mockVNFDefinition
+ rbDefClient *mockRBDefinition
}{
{
- label: "Get VNF Definition",
+ label: "Get Bundle Definition",
expectedCode: http.StatusOK,
- expected: vnfd.VNFDefinition{
+ expected: rb.Definition{
UUID: "123e4567-e89b-12d3-a456-426655441111",
- Name: "testvnf2",
+ Name: "testresourcebundle2",
Description: "test description",
ServiceType: "dns",
},
inpUUID: "123e4567-e89b-12d3-a456-426655441111",
- vnfdClient: &mockVNFDefinition{
+ rbDefClient: &mockRBDefinition{
// list of definitions that will be returned by the mockclient
- Items: []vnfd.VNFDefinition{
+ Items: []rb.Definition{
{
UUID: "123e4567-e89b-12d3-a456-426655441111",
- Name: "testvnf2",
+ Name: "testresourcebundle2",
Description: "test description",
ServiceType: "dns",
},
@@ -249,12 +249,12 @@ func TestVnfdGetHandler(t *testing.T) {
},
},
{
- label: "Get Non-Exiting VNF Definition",
+ label: "Get Non-Exiting Bundle Definition",
expectedCode: http.StatusInternalServerError,
inpUUID: "123e4567-e89b-12d3-a456-426655440000",
- vnfdClient: &mockVNFDefinition{
+ rbDefClient: &mockRBDefinition{
// list of definitions that will be returned by the mockclient
- Items: []vnfd.VNFDefinition{},
+ Items: []rb.Definition{},
Err: pkgerrors.New("Internal Error"),
},
},
@@ -262,14 +262,14 @@ func TestVnfdGetHandler(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.label, func(t *testing.T) {
- vh := vnfdHandler{vnfdClient: testCase.vnfdClient}
- req, err := http.NewRequest("GET", "/v1/vnfd/"+testCase.inpUUID, nil)
+ vh := rbDefinitionHandler{client: testCase.rbDefClient}
+ req, err := http.NewRequest("GET", "/v1/resource/definition/"+testCase.inpUUID, nil)
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
- hr := http.HandlerFunc(vh.vnfdGetHandler)
+ hr := http.HandlerFunc(vh.getHandler)
hr.ServeHTTP(rr, req)
//Check returned code
@@ -279,11 +279,11 @@ func TestVnfdGetHandler(t *testing.T) {
//Check returned body only if statusOK
if rr.Code == http.StatusOK {
- got := vnfd.VNFDefinition{}
+ got := rb.Definition{}
json.NewDecoder(rr.Body).Decode(&got)
if reflect.DeepEqual(testCase.expected, got) == false {
- t.Errorf("vnfdListHandler returned unexpected body: got %v;"+
+ t.Errorf("listHandler returned unexpected body: got %v;"+
" expected %v", got, testCase.expected)
}
}
@@ -291,25 +291,25 @@ func TestVnfdGetHandler(t *testing.T) {
}
}
-func TestVnfdDeleteHandler(t *testing.T) {
+func TestRBDefDeleteHandler(t *testing.T) {
testCases := []struct {
label string
inpUUID string
expectedCode int
- vnfdClient *mockVNFDefinition
+ rbDefClient *mockRBDefinition
}{
{
- label: "Delete VNF Definition",
+ label: "Delete Bundle Definition",
expectedCode: http.StatusNoContent,
inpUUID: "123e4567-e89b-12d3-a456-426655441111",
- vnfdClient: &mockVNFDefinition{},
+ rbDefClient: &mockRBDefinition{},
},
{
- label: "Delete Non-Exiting VNF Definition",
+ label: "Delete Non-Exiting Bundle Definition",
expectedCode: http.StatusInternalServerError,
inpUUID: "123e4567-e89b-12d3-a456-426655440000",
- vnfdClient: &mockVNFDefinition{
+ rbDefClient: &mockRBDefinition{
Err: pkgerrors.New("Internal Error"),
},
},
@@ -317,14 +317,14 @@ func TestVnfdDeleteHandler(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.label, func(t *testing.T) {
- vh := vnfdHandler{vnfdClient: testCase.vnfdClient}
- req, err := http.NewRequest("GET", "/v1/vnfd/"+testCase.inpUUID, nil)
+ vh := rbDefinitionHandler{client: testCase.rbDefClient}
+ req, err := http.NewRequest("GET", "/v1/resource/definition/"+testCase.inpUUID, nil)
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
- hr := http.HandlerFunc(vh.vnfdDeleteHandler)
+ hr := http.HandlerFunc(vh.deleteHandler)
hr.ServeHTTP(rr, req)
//Check returned code