diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/orchestrator/api/api.go | 9 | ||||
-rw-r--r-- | src/orchestrator/api/composite_app_handler.go | 26 | ||||
-rw-r--r-- | src/orchestrator/api/deployment_intent_groups_handler.go | 26 | ||||
-rw-r--r-- | src/orchestrator/api/generic_placement_intent_handler.go | 26 | ||||
-rw-r--r-- | src/orchestrator/api/projecthandler.go | 25 | ||||
-rw-r--r-- | src/orchestrator/api/projecthandler_test.go | 4 | ||||
-rw-r--r-- | src/orchestrator/pkg/module/compositeapp.go | 33 | ||||
-rw-r--r-- | src/orchestrator/pkg/module/deployment_intent_groups.go | 45 | ||||
-rw-r--r-- | src/orchestrator/pkg/module/generic_placement_intent.go | 43 | ||||
-rw-r--r-- | src/orchestrator/pkg/module/project.go | 24 | ||||
-rw-r--r-- | src/rsync/pkg/context/context.go | 4 |
11 files changed, 261 insertions, 4 deletions
diff --git a/src/orchestrator/api/api.go b/src/orchestrator/api/api.go index 5abbb96d..097b9ab3 100644 --- a/src/orchestrator/api/api.go +++ b/src/orchestrator/api/api.go @@ -57,6 +57,7 @@ func NewRouter(projectClient moduleLib.ProjectManager, } router.HandleFunc("/projects", projHandler.createHandler).Methods("POST") router.HandleFunc("/projects/{project-name}", projHandler.getHandler).Methods("GET") + router.HandleFunc("/projects", projHandler.getHandler).Methods("GET") router.HandleFunc("/projects/{project-name}", projHandler.deleteHandler).Methods("DELETE") //setting routes for compositeApp @@ -68,6 +69,7 @@ func NewRouter(projectClient moduleLib.ProjectManager, } router.HandleFunc("/projects/{project-name}/composite-apps", compAppHandler.createHandler).Methods("POST") router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{version}", compAppHandler.getHandler).Methods("GET") + router.HandleFunc("/projects/{project-name}/composite-apps", compAppHandler.getAllCompositeAppsHandler).Methods("GET") router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{version}", compAppHandler.deleteHandler).Methods("DELETE") if appClient == nil { @@ -126,7 +128,11 @@ func NewRouter(projectClient moduleLib.ProjectManager, client: genericPlacementIntentClient, } router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/generic-placement-intents", genericPlacementIntentHandler.createGenericPlacementIntentHandler).Methods("POST") + router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/generic-placement-intents/{intent-name}", genericPlacementIntentHandler.getGenericPlacementHandler).Methods("GET") + + router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/generic-placement-intents", genericPlacementIntentHandler.getAllGenericPlacementIntentsHandler).Methods("GET") + router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/generic-placement-intents/{intent-name}", genericPlacementIntentHandler.deleteGenericPlacementHandler).Methods("DELETE") //setting routes for AppIntent @@ -153,6 +159,9 @@ func NewRouter(projectClient moduleLib.ProjectManager, } router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups", deploymentIntentGrpHandler.createDeploymentIntentGroupHandler).Methods("POST") router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}", deploymentIntentGrpHandler.getDeploymentIntentGroupHandler).Methods("GET") + + router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups", deploymentIntentGrpHandler.getAllDeploymentIntentGroupsHandler).Methods("GET") + router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}", deploymentIntentGrpHandler.deleteDeploymentIntentGroupHandler).Methods("DELETE") // setting routes for AddingIntents diff --git a/src/orchestrator/api/composite_app_handler.go b/src/orchestrator/api/composite_app_handler.go index b54c488e..ab052f00 100644 --- a/src/orchestrator/api/composite_app_handler.go +++ b/src/orchestrator/api/composite_app_handler.go @@ -95,6 +95,32 @@ func (h compositeAppHandler) getHandler(w http.ResponseWriter, r *http.Request) } } +// getAllCompositeAppsHandler handles the GetAllComppositeApps, returns a list of compositeApps under a project +func (h compositeAppHandler) getAllCompositeAppsHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + pName := vars["project-name"] + + var caList []moduleLib.CompositeApp + + cApps, err := h.client.GetAllCompositeApps(pName) + if err != nil { + http.Error(w, err.Error(), http.StatusNotFound) + return + } + + for _, cApp := range cApps { + caList = append(caList, moduleLib.CompositeApp{Metadata: cApp.Metadata, Spec: cApp.Spec}) + } + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + err = json.NewEncoder(w).Encode(caList) + if err != nil { + http.Error(w, err.Error(), http.StatusNotFound) + return + } + return +} + // deleteHandler handles DELETE operations on a particular CompositeApp Name func (h compositeAppHandler) deleteHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) diff --git a/src/orchestrator/api/deployment_intent_groups_handler.go b/src/orchestrator/api/deployment_intent_groups_handler.go index 3f5b3969..7620737b 100644 --- a/src/orchestrator/api/deployment_intent_groups_handler.go +++ b/src/orchestrator/api/deployment_intent_groups_handler.go @@ -22,6 +22,7 @@ import ( "net/http" moduleLib "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module" + "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/validation" "github.com/gorilla/mux" ) @@ -116,6 +117,31 @@ func (h deploymentIntentGroupHandler) getDeploymentIntentGroupHandler(w http.Res } +func (h deploymentIntentGroupHandler) getAllDeploymentIntentGroupsHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + pList := []string{"project-name", "composite-app-name", "composite-app-version"} + err := validation.IsValidParameterPresent(vars, pList) + if err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + } + p := vars["project-name"] + ca := vars["composite-app-name"] + v := vars["composite-app-version"] + + diList, err := h.client.GetAllDeploymentIntentGroups(p, ca, v) + if err != nil { + http.Error(w, err.Error(), http.StatusNotFound) + return + } + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + err = json.NewEncoder(w).Encode(diList) + if err != nil { + http.Error(w, err.Error(), http.StatusNotFound) + return + } +} + func (h deploymentIntentGroupHandler) deleteDeploymentIntentGroupHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) diff --git a/src/orchestrator/api/generic_placement_intent_handler.go b/src/orchestrator/api/generic_placement_intent_handler.go index e186735c..02dbf0be 100644 --- a/src/orchestrator/api/generic_placement_intent_handler.go +++ b/src/orchestrator/api/generic_placement_intent_handler.go @@ -21,6 +21,7 @@ import ( "io" "net/http" + "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/validation" moduleLib "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module" "github.com/gorilla/mux" @@ -113,6 +114,31 @@ func (h genericPlacementIntentHandler) getGenericPlacementHandler(w http.Respons } } +func (h genericPlacementIntentHandler) getAllGenericPlacementIntentsHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + pList := []string{"project-name", "composite-app-name", "composite-app-version"} + err := validation.IsValidParameterPresent(vars, pList) + if err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + } + p := vars["project-name"] + ca := vars["composite-app-name"] + v := vars["composite-app-version"] + + gpList, err := h.client.GetAllGenericPlacementIntents(p, ca, v) + if err != nil { + http.Error(w, err.Error(), http.StatusNotFound) + return + } + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + err = json.NewEncoder(w).Encode(gpList) + if err != nil { + http.Error(w, err.Error(), http.StatusNotFound) + return + } +} + // deleteGenericPlacementHandler handles the delete operations on intent func (h genericPlacementIntentHandler) deleteGenericPlacementHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) diff --git a/src/orchestrator/api/projecthandler.go b/src/orchestrator/api/projecthandler.go index 1e78c676..09b24096 100644 --- a/src/orchestrator/api/projecthandler.go +++ b/src/orchestrator/api/projecthandler.go @@ -75,6 +75,31 @@ func (h projectHandler) getHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) name := vars["project-name"] + // handle for get all projects + if len(name) == 0 { + var pList []moduleLib.Project + + projects, err := h.client.GetAllProjects() + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + for _, p := range projects { + pList = append(pList, moduleLib.Project{MetaData: p.MetaData}) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + err = json.NewEncoder(w).Encode(pList) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + return + + } + ret, err := h.client.GetProject(name) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/src/orchestrator/api/projecthandler_test.go b/src/orchestrator/api/projecthandler_test.go index 0212e57a..dae87e2b 100644 --- a/src/orchestrator/api/projecthandler_test.go +++ b/src/orchestrator/api/projecthandler_test.go @@ -60,6 +60,10 @@ func (m *mockProjectManager) DeleteProject(name string) error { return m.Err } +func (m *mockProjectManager) GetAllProjects() ([]moduleLib.Project, error) { + return []moduleLib.Project{}, m.Err +} + func TestProjectCreateHandler(t *testing.T) { testCases := []struct { label string diff --git a/src/orchestrator/pkg/module/compositeapp.go b/src/orchestrator/pkg/module/compositeapp.go index 70502367..5bf7ddec 100644 --- a/src/orchestrator/pkg/module/compositeapp.go +++ b/src/orchestrator/pkg/module/compositeapp.go @@ -64,6 +64,7 @@ func (cK CompositeAppKey) String() string { type CompositeAppManager interface { CreateCompositeApp(c CompositeApp, p string) (CompositeApp, error) GetCompositeApp(name string, version string, p string) (CompositeApp, error) + GetAllCompositeApps(p string) ([]CompositeApp, error) DeleteCompositeApp(name string, version string, p string) error } @@ -140,6 +141,38 @@ func (v *CompositeAppClient) GetCompositeApp(name string, version string, p stri return CompositeApp{}, pkgerrors.New("Error getting composite application") } +// GetAllCompositeApps returns all the compositeApp for a given project +func (v *CompositeAppClient) GetAllCompositeApps(p string) ([]CompositeApp, error) { + + _, err := NewProjectClient().GetProject(p) + if err != nil { + return []CompositeApp{}, pkgerrors.New("Unable to find the project") + } + + key := CompositeAppKey{ + CompositeAppName: "", + Version: "", + Project: p, + } + + var caList []CompositeApp + values, err := db.DBconn.Find(v.storeName, key, v.tagMeta) + if err != nil { + return []CompositeApp{}, pkgerrors.Wrap(err, "Getting CompositeApps") + } + + for _, value := range values { + ca := CompositeApp{} + err = db.DBconn.Unmarshal(value, &ca) + if err != nil { + return []CompositeApp{}, pkgerrors.Wrap(err, "Unmarshaling CompositeApp") + } + caList = append(caList, ca) + } + + return caList, nil +} + // DeleteCompositeApp deletes the CompositeApp from database func (v *CompositeAppClient) DeleteCompositeApp(name string, version string, p string) error { diff --git a/src/orchestrator/pkg/module/deployment_intent_groups.go b/src/orchestrator/pkg/module/deployment_intent_groups.go index 0decb68f..c7237032 100644 --- a/src/orchestrator/pkg/module/deployment_intent_groups.go +++ b/src/orchestrator/pkg/module/deployment_intent_groups.go @@ -64,6 +64,7 @@ type DeploymentIntentGroupManager interface { GetDeploymentIntentGroup(di string, p string, ca string, v string) (DeploymentIntentGroup, error) GetDeploymentIntentGroupContext(di string, p string, ca string, v string) (appcontext.AppContext, string, error) DeleteDeploymentIntentGroup(di string, p string, ca string, v string) error + GetAllDeploymentIntentGroups(p string, ca string, v string) ([]DeploymentIntentGroup, error) } // DeploymentIntentGroupKey consists of Name of the deployment group, project name, CompositeApp name, CompositeApp version @@ -106,7 +107,7 @@ func (c *DeploymentIntentGroupClient) CreateDeploymentIntentGroup(d DeploymentIn res, err := c.GetDeploymentIntentGroup(d.MetaData.Name, p, ca, v) if !reflect.DeepEqual(res, DeploymentIntentGroup{}) { - return DeploymentIntentGroup{}, pkgerrors.New("AppIntent already exists") + return DeploymentIntentGroup{}, pkgerrors.New("DeploymentIntent already exists") } //Check if project exists @@ -164,7 +165,47 @@ func (c *DeploymentIntentGroupClient) GetDeploymentIntentGroup(di string, p stri } -// GetDeploymentIntentGroup returns the DeploymentIntentGroup with a given name, project, compositeApp and version of compositeApp +// GetAllDeploymentIntentGroups returns all the deploymentIntentGroups under a specific project, compositeApp and version +func (c *DeploymentIntentGroupClient) GetAllDeploymentIntentGroups(p string, ca string, v string) ([]DeploymentIntentGroup, error) { + + key := DeploymentIntentGroupKey{ + Name: "", + Project: p, + CompositeApp: ca, + Version: v, + } + + //Check if project exists + _, err := NewProjectClient().GetProject(p) + if err != nil { + return []DeploymentIntentGroup{}, pkgerrors.Wrap(err, "Unable to find the project") + } + + //check if compositeApp exists + _, err = NewCompositeAppClient().GetCompositeApp(ca, v, p) + if err != nil { + return []DeploymentIntentGroup{}, pkgerrors.Wrap(err, "Unable to find the composite-app, check CompositeAppName and Version") + } + var diList []DeploymentIntentGroup + result, err := db.DBconn.Find(c.storeName, key, c.tagMetaData) + if err != nil { + return []DeploymentIntentGroup{}, pkgerrors.Wrap(err, "Get DeploymentIntentGroup error") + } + + for _, value := range result { + di := DeploymentIntentGroup{} + err = db.DBconn.Unmarshal(value, &di) + if err != nil { + return []DeploymentIntentGroup{}, pkgerrors.Wrap(err, "Unmarshaling DeploymentIntentGroup") + } + diList = append(diList, di) + } + + return diList, nil + +} + +// GetDeploymentIntentGroupContext returns the AppContent with a given DeploymentIntentname, project, compositeAppName and version of compositeApp func (c *DeploymentIntentGroupClient) GetDeploymentIntentGroupContext(di string, p string, ca string, v string) (appcontext.AppContext, string, error) { key := DeploymentIntentGroupKey{ diff --git a/src/orchestrator/pkg/module/generic_placement_intent.go b/src/orchestrator/pkg/module/generic_placement_intent.go index 73849474..fb00a6ab 100644 --- a/src/orchestrator/pkg/module/generic_placement_intent.go +++ b/src/orchestrator/pkg/module/generic_placement_intent.go @@ -50,6 +50,8 @@ type GenericPlacementIntentManager interface { compositeAppName string, version string) (GenericPlacementIntent, error) DeleteGenericPlacementIntent(intentName string, projectName string, compositeAppName string, version string) error + + GetAllGenericPlacementIntents(p string, ca string, v string) ([]GenericPlacementIntent, error) } // GenericPlacementIntentKey is used as the primary key @@ -148,6 +150,47 @@ func (c *GenericPlacementIntentClient) GetGenericPlacementIntent(i string, p str } +// GetAllGenericPlacementIntents returns all the generic placement intents for a given compsoite app name, composite app version and project. +func (c *GenericPlacementIntentClient) GetAllGenericPlacementIntents(p string, ca string, v string) ([]GenericPlacementIntent, error) { + + //Check if project exists + _, err := NewProjectClient().GetProject(p) + if err != nil { + return []GenericPlacementIntent{}, pkgerrors.Wrap(err, "Unable to find the project") + } + + // check if compositeApp exists + _, err = NewCompositeAppClient().GetCompositeApp(ca, v, p) + if err != nil { + return []GenericPlacementIntent{}, pkgerrors.Wrap(err, "Unable to find the composite-app, check compositeApp name and version") + } + + key := GenericPlacementIntentKey{ + Name: "", + Project: p, + CompositeApp: ca, + Version: v, + } + + var gpList []GenericPlacementIntent + values, err := db.DBconn.Find(c.storeName, key, c.tagMetaData) + if err != nil { + return []GenericPlacementIntent{}, pkgerrors.Wrap(err, "Getting GenericPlacementIntent") + } + + for _, value := range values { + gp := GenericPlacementIntent{} + err = db.DBconn.Unmarshal(value, &gp) + if err != nil { + return []GenericPlacementIntent{}, pkgerrors.Wrap(err, "Unmarshaling GenericPlacementIntent") + } + gpList = append(gpList, gp) + } + + return gpList, nil + +} + // DeleteGenericPlacementIntent the intent from the database func (c *GenericPlacementIntentClient) DeleteGenericPlacementIntent(i string, p string, ca string, v string) error { key := GenericPlacementIntentKey{ diff --git a/src/orchestrator/pkg/module/project.go b/src/orchestrator/pkg/module/project.go index a6f59254..02f6d827 100644 --- a/src/orchestrator/pkg/module/project.go +++ b/src/orchestrator/pkg/module/project.go @@ -58,6 +58,7 @@ type ProjectManager interface { CreateProject(pr Project) (Project, error) GetProject(name string) (Project, error) DeleteProject(name string) error + GetAllProjects() ([]Project, error) } // ProjectClient implements the ProjectManager @@ -123,6 +124,29 @@ func (v *ProjectClient) GetProject(name string) (Project, error) { return Project{}, pkgerrors.New("Error getting Project") } +// GetAllProjects returns all the projects +func (v *ProjectClient) GetAllProjects() ([]Project, error) { + key := ProjectKey{ + ProjectName: "", + } + + var res []Project + values, err := db.DBconn.Find(v.storeName, key, v.tagMeta) + if err != nil { + + } + + for _, value := range values { + p := Project{} + err = db.DBconn.Unmarshal(value, &p) + if err != nil { + return []Project{}, pkgerrors.Wrap(err, "Unmarshaling Project") + } + res = append(res, p) + } + return res, nil +} + // DeleteProject the Project from database func (v *ProjectClient) DeleteProject(name string) error { diff --git a/src/rsync/pkg/context/context.go b/src/rsync/pkg/context/context.go index 530802ab..cc7773b8 100644 --- a/src/rsync/pkg/context/context.go +++ b/src/rsync/pkg/context/context.go @@ -74,7 +74,7 @@ func terminateResource(ac appcontext.AppContext, c *kubeclient.Client, name stri } logutils.Info("Deleted::", logutils.Fields{ "cluster": cluster, - "resource": res, + "resource": name, }) return nil } @@ -124,7 +124,7 @@ func instantiateResource(ac appcontext.AppContext, c *kubeclient.Client, name st } logutils.Info("Installed::", logutils.Fields{ "cluster": cluster, - "resource": res, + "resource": name, }) return nil } |