-
Notifications
You must be signed in to change notification settings - Fork 59
/
connectionmethods.go
102 lines (95 loc) · 3.97 KB
/
connectionmethods.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//(C) Copyright [2020] Hewlett Packard Enterprise Development LP
//
//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 system
import (
"context"
"net/http"
"strings"
"github.com/ODIM-Project/ODIM/lib-utilities/common"
"github.com/ODIM-Project/ODIM/lib-utilities/config"
"github.com/ODIM-Project/ODIM/lib-utilities/errors"
l "github.com/ODIM-Project/ODIM/lib-utilities/logs"
aggregatorproto "github.com/ODIM-Project/ODIM/lib-utilities/proto/aggregator"
"github.com/ODIM-Project/ODIM/lib-utilities/response"
"github.com/ODIM-Project/ODIM/svc-aggregation/agmodel"
"github.com/ODIM-Project/ODIM/svc-aggregation/agresponse"
)
// GetAllConnectionMethods is the handler for getting the connection methods collection
func (e *ExternalInterface) GetAllConnectionMethods(ctx context.Context, req *aggregatorproto.AggregatorRequest) response.RPC {
connectionMethods, err := e.GetAllKeysFromTable("ConnectionMethod")
if err != nil {
l.LogWithFields(ctx).Error("error getting connection methods : " + err.Error())
errorMessage := err.Error()
return common.GeneralError(http.StatusServiceUnavailable, response.CouldNotEstablishConnection, errorMessage, []interface{}{config.Data.DBConf.OnDiskHost + ":" + config.Data.DBConf.OnDiskPort}, nil)
}
var members = make([]agresponse.ListMember, 0)
for i := 0; i < len(connectionMethods); i++ {
members = append(members, agresponse.ListMember{
OdataID: connectionMethods[i],
})
}
var resp = response.RPC{
StatusCode: http.StatusOK,
StatusMessage: response.Success,
}
commonResponse := response.Response{
OdataType: "#ConnectionMethodCollection.ConnectionMethodCollection",
OdataID: "/redfish/v1/AggregationService/ConnectionMethods",
OdataContext: "/redfish/v1/$metadata#ConnectionMethodCollection.ConnectionMethodCollection",
Name: "Connection Methods",
}
resp.Body = agresponse.List{
Response: commonResponse,
MembersCount: len(members),
Members: members,
}
return resp
}
// GetConnectionMethodInfo is the handler for getting the connection method
func (e *ExternalInterface) GetConnectionMethodInfo(ctx context.Context, req *aggregatorproto.AggregatorRequest) response.RPC {
connectionmethod, err := e.GetConnectionMethod(req.URL)
if err != nil {
l.LogWithFields(ctx).Error("error getting connectionmethod : " + err.Error())
errorMessage := err.Error()
if errors.DBKeyNotFound == err.ErrNo() {
return common.GeneralError(http.StatusNotFound, response.ResourceNotFound, err.Error(), []interface{}{"ConnectionMethod", req.URL}, nil)
}
return common.GeneralError(http.StatusInternalServerError, response.InternalError, errorMessage, nil, nil)
}
var data = strings.Split(req.URL, "/redfish/v1/AggregationService/ConnectionMethods/")
commonResponse := response.Response{
OdataType: "#ConnectionMethod.v1_0_0.ConnectionMethod",
OdataID: req.URL,
OdataContext: "/redfish/v1/$metadata#ConnectionMethod.v1_0_0.ConnectionMethod",
ID: data[1],
Name: "Connection Method",
}
var resp = response.RPC{
StatusCode: http.StatusOK,
StatusMessage: response.Success,
}
links := connectionmethod.Links
if len(links.AggregationSources) == 0 {
links = agmodel.Links{
AggregationSources: []agmodel.OdataID{},
}
}
resp.Body = agresponse.ConnectionMethodResponse{
Response: commonResponse,
ConnectionMethodType: connectionmethod.ConnectionMethodType,
ConnectionMethodVariant: connectionmethod.ConnectionMethodVariant,
Links: links,
}
return resp
}