Implement get the charts by name and version
Implemented the query to get the available charts details
for given xApp name and version.
Signed-off-by: subhash kumar singh <subh.singh@samsung.com>
Change-Id: I9eda1f0375130c9cdb42e3cb61c818f2f929440b
diff --git a/pkg/charts/chart_manager.go b/pkg/charts/chart_manager.go
index 0f6f7af..c0308dd 100644
--- a/pkg/charts/chart_manager.go
+++ b/pkg/charts/chart_manager.go
@@ -37,6 +37,7 @@
GetCharts() (string, error)
DownloadChart(string, string) (io.ReadCloser, error)
GetChartsByName(name string) ([]map[string]interface{}, error)
+ GetChartsByNameAndVersion(name, version string) (map[string]interface{}, error)
}
func NewChartmgr() IChartMgr {
@@ -112,3 +113,36 @@
}
return v, nil
}
+
+func (c *ChartMgr) GetChartsByNameAndVersion(name, version string) (map[string]interface{}, error) {
+ ricdms.Logger.Debug("Get Charts by name and version is invoked")
+
+ if name == "" || version == "" {
+ return make(map[string]interface{}, 0), fmt.Errorf("name or version is not provided")
+ }
+
+ URL := fmt.Sprintf(ricdms.Config.GetChartsByNameAndVersionURL, name, version)
+
+ response, err := http.Get(URL)
+ if err != nil {
+ ricdms.Logger.Debug("error in retrieving chart: %v", err)
+ return make(map[string]interface{}, 0), err
+ }
+
+ defer response.Body.Close()
+ data, err := ioutil.ReadAll(response.Body)
+
+ if err != nil {
+ ricdms.Logger.Debug("error in reading response: %v", err)
+ return make(map[string]interface{}, 0), err
+ }
+
+ v := make(map[string]interface{}, 0)
+ err = json.Unmarshal(data, &v)
+ if err != nil {
+ ricdms.Logger.Debug("error in parsing response: %v", err)
+ return make(map[string]interface{}, 0), err
+ }
+
+ return v, nil
+}