blob: a895c34ac7e414e4e4dbe13b3ec322adcfa5645d [file] [log] [blame]
Salman Siddiqui1cf95042020-11-19 00:42:56 +05301/*
2 * Copyright 2018-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
17package device
18
19import (
20 "context"
khenaidood948f772021-08-11 17:49:24 -040021
22 "github.com/opencord/voltha-lib-go/v7/pkg/log"
23 "github.com/opencord/voltha-protos/v5/go/extension"
Salman Siddiqui1cf95042020-11-19 00:42:56 +053024 "google.golang.org/grpc/codes"
25 "google.golang.org/grpc/status"
26)
27
28type ExtensionManager struct {
29 DeviceManager *Manager
30}
31
32func GetNewExtensionManager(deviceManager *Manager) *ExtensionManager {
33 return &ExtensionManager{DeviceManager: deviceManager}
34}
35
36func (e ExtensionManager) GetExtValue(ctx context.Context, request *extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) {
37 log.EnrichSpan(ctx, log.Fields{"device-id": request.TargetId})
38
39 logger.Debugw(ctx, "GetExtValue", log.Fields{"request": request})
40 agent := e.DeviceManager.getDeviceAgent(ctx, request.TargetId)
41 if agent == nil {
42 return nil, status.Errorf(codes.NotFound, "target-id %s", request.TargetId)
43 }
44
45 response, err := agent.getSingleValue(ctx, request)
46 if err != nil {
47 logger.Errorw(ctx, "Fail-to-get-single-value", log.Fields{"device-id": agent.deviceID, "error": err})
48 return nil, err
49 }
50
51 logger.Debugw(ctx, "GetExtValue response", log.Fields{"response": response})
52 return response, nil
53}
54
55func (e ExtensionManager) SetExtValue(ctx context.Context, request *extension.SingleSetValueRequest) (*extension.SingleSetValueResponse, error) {
56 log.EnrichSpan(ctx, log.Fields{"device-id": request.TargetId})
57
58 logger.Debugw(ctx, "SetExtValue", log.Fields{"request": request})
59 agent := e.DeviceManager.getDeviceAgent(ctx, request.TargetId)
60 if agent == nil {
61 return nil, status.Errorf(codes.NotFound, "target-id %s", request.TargetId)
62 }
63
64 response, err := agent.setSingleValue(ctx, request)
65 if err != nil {
66 logger.Errorw(ctx, "Fail-to-set-single-value", log.Fields{"device-id": agent.deviceID, "error": err})
67 return nil, err
68 }
69
70 logger.Debugw(ctx, "SetExtValue response", log.Fields{"response": response})
71 return response, nil
72}