blob: ab0c51784676bdb842074a99fb50883601725bcc [file] [log] [blame]
Prince Pereirac1c21d62021-04-22 08:38:15 +00001/*
2 * Copyright 2020-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17// Package nbi holds rpc server apis implemented
18package nbi
19
20import (
21 "context"
22
23 "github.com/opencord/device-management-interface/go/dmi"
24 "github.com/opencord/voltha-lib-go/v4/pkg/log"
25)
26
27// errRespStartManagingDevice represents the func to construct error response for rpc StartManagingDevice
28func errRespStartManagingDevice(ctx context.Context, req *dmi.ModifiableComponent, reason dmi.StartManagingDeviceResponse_Reason, err error) *dmi.StartManagingDeviceResponse {
29 resp := new(dmi.StartManagingDeviceResponse)
30 resp.Status = dmi.Status_ERROR_STATUS
31 resp.Reason = reason
32 resp.ReasonDetail = err.Error()
33 logger.Errorw(ctx, "StartManagingDevice-on-grpc-server-failed", log.Fields{"req": req, "resp": resp, "error": err})
34 return resp
35}
36
37// errRespStopManagingDevice represents the func to construct error response for rpc StopManagingDevice
38func errRespStopManagingDevice(ctx context.Context, req *dmi.StopManagingDeviceRequest, reason dmi.StopManagingDeviceResponse_Reason, err error) *dmi.StopManagingDeviceResponse {
39 resp := new(dmi.StopManagingDeviceResponse)
40 resp.Status = dmi.Status_ERROR_STATUS
41 resp.Reason = reason
42 resp.ReasonDetail = err.Error()
43 logger.Errorw(ctx, "StopManagingDevice-on-grpc-server-failed", log.Fields{"req": req, "resp": resp, "error": err})
44 return resp
45}
46
47// errRespGetPhysicatInventory represents the func to construct error response for rpc GetPhysicatInventory
48func errRespGetPhysicatInventory(ctx context.Context, req *dmi.PhysicalInventoryRequest, reason dmi.PhysicalInventoryResponse_Reason, err error) *dmi.PhysicalInventoryResponse {
49 resp := new(dmi.PhysicalInventoryResponse)
50 resp.Status = dmi.Status_ERROR_STATUS
51 resp.Reason = reason
52 resp.ReasonDetail = err.Error()
53 logger.Errorw(ctx, "GetPhysicatInventory-on-grpc-server-failed", log.Fields{"req": req, "resp": resp, "error": err})
54 return resp
55}
56
57// errRespGetHWComponentInfo represents the func to construct error response for rpc GetHWComponentInfo
58func errRespGetHWComponentInfo(ctx context.Context, req *dmi.HWComponentInfoGetRequest, reason dmi.HWComponentInfoGetResponse_Reason, err error) *dmi.HWComponentInfoGetResponse {
59 resp := new(dmi.HWComponentInfoGetResponse)
60 resp.Status = dmi.Status_ERROR_STATUS
61 resp.Reason = reason
62 resp.ReasonDetail = err.Error()
63 logger.Errorw(ctx, "GetHWComponentInfo-on-grpc-server-failed", log.Fields{"req": req, "resp": resp, "error": err})
64 return resp
65}
66
67// errRespSetHWComponentInfo represents the func to construct error response for rpc SetHWComponentInfo
68func errRespSetHWComponentInfo(ctx context.Context, req *dmi.HWComponentInfoSetRequest, reason dmi.HWComponentInfoSetResponse_Reason, err error) *dmi.HWComponentInfoSetResponse {
69 resp := new(dmi.HWComponentInfoSetResponse)
70 resp.Status = dmi.Status_ERROR_STATUS
71 resp.Reason = reason
72 resp.ReasonDetail = err.Error()
73 logger.Errorw(ctx, "SetHWComponentInfo-on-grpc-server-failed", log.Fields{"req": req, "resp": resp, "error": err})
74 return resp
75}
76
77// errRespSetLoggingEndpoint represents the func to construct error response for rpc SetLoggingEndpoint
78func errRespSetLoggingEndpoint(ctx context.Context, req *dmi.SetLoggingEndpointRequest, reason dmi.SetRemoteEndpointResponse_Reason, err error) *dmi.SetRemoteEndpointResponse {
79 resp := new(dmi.SetRemoteEndpointResponse)
80 resp.Status = dmi.Status_ERROR_STATUS
81 resp.Reason = reason
82 resp.ReasonDetail = err.Error()
83 logger.Errorw(ctx, "SetLoggingEndpoint-on-grpc-server-failed", log.Fields{"req": req, "resp": resp, "error": err})
84 return resp
85}
86
87// errRespGetLoggingEndpoint represents the func to construct error response for rpc GetLoggingEndpoint
88func errRespGetLoggingEndpoint(ctx context.Context, req *dmi.HardwareID, reason dmi.GetLoggingEndpointResponse_Reason, err error) *dmi.GetLoggingEndpointResponse {
89 resp := new(dmi.GetLoggingEndpointResponse)
90 resp.Status = dmi.Status_ERROR_STATUS
91 resp.Reason = reason
92 resp.ReasonDetail = err.Error()
93 logger.Errorw(ctx, "GetLoggingEndpoint-on-grpc-server-failed", log.Fields{"req": req, "resp": resp, "error": err})
94 return resp
95}
96
97// errRespGetLoggableEntities represents the func to construct error response for rpc GetLoggableEntities
98func errRespGetLoggableEntities(ctx context.Context, req *dmi.GetLoggableEntitiesRequest, reason dmi.GetLogLevelResponse_Reason, err error) *dmi.GetLogLevelResponse {
99 resp := new(dmi.GetLogLevelResponse)
100 resp.DeviceUuid = req.DeviceUuid
101 resp.Status = dmi.Status_ERROR_STATUS
102 resp.Reason = reason
103 resp.ReasonDetail = err.Error()
104 logger.Errorw(ctx, "GetLoggableEntities-on-grpc-server-failed", log.Fields{"req": req, "resp": resp, "error": err})
105 return resp
106}
107
108// errRespSetLogLevel represents the func to construct error response for rpc SetLogLevel
109func errRespSetLogLevel(ctx context.Context, req *dmi.SetLogLevelRequest, reason dmi.SetLogLevelResponse_Reason, err error) *dmi.SetLogLevelResponse {
110 resp := new(dmi.SetLogLevelResponse)
111 resp.DeviceUuid = req.DeviceUuid
112 resp.Status = dmi.Status_ERROR_STATUS
113 resp.Reason = reason
114 resp.ReasonDetail = err.Error()
115 logger.Errorw(ctx, "SetLogLevel-on-grpc-server-failed", log.Fields{"req": req, "resp": resp, "error": err})
116 return resp
117}
118
119// errRespGetLogLevel represents the func to construct error response for rpc GetLogLevel
120func errRespGetLogLevel(ctx context.Context, req *dmi.GetLogLevelRequest, reason dmi.GetLogLevelResponse_Reason, err error) *dmi.GetLogLevelResponse {
121 resp := new(dmi.GetLogLevelResponse)
122 resp.DeviceUuid = req.DeviceUuid
123 resp.Status = dmi.Status_ERROR_STATUS
124 resp.Reason = reason
125 resp.ReasonDetail = err.Error()
126 logger.Errorw(ctx, "GetLogLevel-on-grpc-server-failed", log.Fields{"req": req, "resp": resp, "error": err})
127 return resp
128}