khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 1 | /* |
| 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 | */ |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 16 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 17 | package core |
| 18 | |
| 19 | import ( |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 20 | "context" |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 21 | "errors" |
David Bainbridge | fd27f4b | 2020-03-26 18:27:41 -0700 | [diff] [blame^] | 22 | "time" |
| 23 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 24 | "github.com/golang/protobuf/ptypes" |
| 25 | "github.com/golang/protobuf/ptypes/empty" |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 26 | "github.com/opencord/voltha-go/db/model" |
serkant.uluderya | 2ae470f | 2020-01-21 11:13:09 -0800 | [diff] [blame] | 27 | "github.com/opencord/voltha-lib-go/v3/pkg/kafka" |
| 28 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 29 | ic "github.com/opencord/voltha-protos/v3/go/inter_container" |
| 30 | "github.com/opencord/voltha-protos/v3/go/voltha" |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 31 | ) |
| 32 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 33 | // AdapterRequestHandlerProxy represent adapter request handler proxy attributes |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 34 | type AdapterRequestHandlerProxy struct { |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 35 | coreInstanceID string |
khenaidoo | de93b46 | 2019-02-13 22:17:21 -0500 | [diff] [blame] | 36 | deviceMgr *DeviceManager |
| 37 | lDeviceMgr *LogicalDeviceManager |
| 38 | adapterMgr *AdapterManager |
| 39 | localDataProxy *model.Proxy |
| 40 | clusterDataProxy *model.Proxy |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 41 | defaultRequestTimeout time.Duration |
| 42 | longRunningRequestTimeout time.Duration |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 43 | core *Core |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 44 | } |
| 45 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 46 | // NewAdapterRequestHandlerProxy assigns values for adapter request handler proxy attributes and returns the new instance |
| 47 | func NewAdapterRequestHandlerProxy(core *Core, coreInstanceID string, dMgr *DeviceManager, ldMgr *LogicalDeviceManager, |
David Bainbridge | fd27f4b | 2020-03-26 18:27:41 -0700 | [diff] [blame^] | 48 | aMgr *AdapterManager, cdProxy *model.Proxy, ldProxy *model.Proxy, longRunningRequestTimeout time.Duration, |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 49 | defaultRequestTimeout time.Duration) *AdapterRequestHandlerProxy { |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 50 | var proxy AdapterRequestHandlerProxy |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 51 | proxy.core = core |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 52 | proxy.coreInstanceID = coreInstanceID |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 53 | proxy.deviceMgr = dMgr |
| 54 | proxy.lDeviceMgr = ldMgr |
| 55 | proxy.clusterDataProxy = cdProxy |
| 56 | proxy.localDataProxy = ldProxy |
khenaidoo | 21d5115 | 2019-02-01 13:48:37 -0500 | [diff] [blame] | 57 | proxy.adapterMgr = aMgr |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 58 | proxy.defaultRequestTimeout = defaultRequestTimeout |
| 59 | proxy.longRunningRequestTimeout = longRunningRequestTimeout |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 60 | return &proxy |
| 61 | } |
| 62 | |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 63 | func (rhp *AdapterRequestHandlerProxy) Register(args []*ic.Argument) (*voltha.CoreInstance, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 64 | if len(args) < 3 { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 65 | logger.Warn("invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 66 | err := errors.New("invalid-number-of-args") |
| 67 | return nil, err |
| 68 | } |
| 69 | adapter := &voltha.Adapter{} |
khenaidoo | 91ecfd6 | 2018-11-04 17:13:42 -0500 | [diff] [blame] | 70 | deviceTypes := &voltha.DeviceTypes{} |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 71 | transactionID := &ic.StrType{} |
khenaidoo | 91ecfd6 | 2018-11-04 17:13:42 -0500 | [diff] [blame] | 72 | for _, arg := range args { |
| 73 | switch arg.Key { |
| 74 | case "adapter": |
| 75 | if err := ptypes.UnmarshalAny(arg.Value, adapter); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 76 | logger.Warnw("cannot-unmarshal-adapter", log.Fields{"error": err}) |
khenaidoo | 91ecfd6 | 2018-11-04 17:13:42 -0500 | [diff] [blame] | 77 | return nil, err |
| 78 | } |
| 79 | case "deviceTypes": |
| 80 | if err := ptypes.UnmarshalAny(arg.Value, deviceTypes); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 81 | logger.Warnw("cannot-unmarshal-device-types", log.Fields{"error": err}) |
khenaidoo | 91ecfd6 | 2018-11-04 17:13:42 -0500 | [diff] [blame] | 82 | return nil, err |
| 83 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 84 | case kafka.TransactionKey: |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 85 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 86 | logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 87 | return nil, err |
| 88 | } |
khenaidoo | 91ecfd6 | 2018-11-04 17:13:42 -0500 | [diff] [blame] | 89 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 90 | } |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 91 | logger.Debugw("Register", log.Fields{"adapter": *adapter, "device-types": deviceTypes, "transaction-id": transactionID.Val, "core-id": rhp.coreInstanceID}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 92 | |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 93 | return rhp.adapterMgr.registerAdapter(adapter, deviceTypes) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 94 | } |
| 95 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 96 | // GetDevice returns device info |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 97 | func (rhp *AdapterRequestHandlerProxy) GetDevice(args []*ic.Argument) (*voltha.Device, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 98 | if len(args) < 2 { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 99 | logger.Warn("invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 100 | err := errors.New("invalid-number-of-args") |
| 101 | return nil, err |
| 102 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 103 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 104 | pID := &voltha.ID{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 105 | transactionID := &ic.StrType{} |
| 106 | for _, arg := range args { |
| 107 | switch arg.Key { |
| 108 | case "device_id": |
| 109 | if err := ptypes.UnmarshalAny(arg.Value, pID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 110 | logger.Warnw("cannot-unmarshal-ID", log.Fields{"error": err}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 111 | return nil, err |
| 112 | } |
| 113 | case kafka.TransactionKey: |
| 114 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 115 | logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 116 | return nil, err |
| 117 | } |
| 118 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 119 | } |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 120 | logger.Debugw("GetDevice", log.Fields{"deviceID": pID.Id, "transactionID": transactionID.Val}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 121 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 122 | // Get the device via the device manager |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 123 | device, err := rhp.deviceMgr.GetDevice(context.TODO(), pID.Id) |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 124 | if err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 125 | logger.Debugw("get-device-failed", log.Fields{"deviceID": pID.Id, "error": err}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 126 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 127 | return device, err |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 128 | } |
| 129 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 130 | // DeviceUpdate updates device using adapter data |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 131 | func (rhp *AdapterRequestHandlerProxy) DeviceUpdate(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 132 | if len(args) < 2 { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 133 | logger.Warn("invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 134 | err := errors.New("invalid-number-of-args") |
| 135 | return nil, err |
| 136 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 137 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 138 | device := &voltha.Device{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 139 | transactionID := &ic.StrType{} |
| 140 | for _, arg := range args { |
| 141 | switch arg.Key { |
| 142 | case "device": |
| 143 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 144 | logger.Warnw("cannot-unmarshal-ID", log.Fields{"error": err}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 145 | return nil, err |
| 146 | } |
| 147 | case kafka.TransactionKey: |
| 148 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 149 | logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 150 | return nil, err |
| 151 | } |
| 152 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 153 | } |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 154 | logger.Debugw("DeviceUpdate", log.Fields{"deviceID": device.Id, "transactionID": transactionID.Val}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 155 | |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 156 | if err := rhp.deviceMgr.updateDeviceUsingAdapterData(context.TODO(), device); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 157 | logger.Debugw("unable-to-update-device-using-adapter-data", log.Fields{"error": err}) |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 158 | return nil, err |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 159 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 160 | return &empty.Empty{}, nil |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 161 | } |
| 162 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 163 | // GetChildDevice returns details of child device |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 164 | func (rhp *AdapterRequestHandlerProxy) GetChildDevice(args []*ic.Argument) (*voltha.Device, error) { |
Matt Jeanneret | 4e24195 | 2019-02-28 11:16:04 -0500 | [diff] [blame] | 165 | if len(args) < 3 { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 166 | logger.Warn("invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 167 | err := errors.New("invalid-number-of-args") |
| 168 | return nil, err |
| 169 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 170 | |
khenaidoo | 2c6f167 | 2018-09-20 23:14:41 -0400 | [diff] [blame] | 171 | pID := &voltha.ID{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 172 | transactionID := &ic.StrType{} |
Matt Jeanneret | 4e24195 | 2019-02-28 11:16:04 -0500 | [diff] [blame] | 173 | serialNumber := &ic.StrType{} |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 174 | onuID := &ic.IntType{} |
Matt Jeanneret | 4e24195 | 2019-02-28 11:16:04 -0500 | [diff] [blame] | 175 | parentPortNo := &ic.IntType{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 176 | for _, arg := range args { |
| 177 | switch arg.Key { |
| 178 | case "device_id": |
| 179 | if err := ptypes.UnmarshalAny(arg.Value, pID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 180 | logger.Warnw("cannot-unmarshal-ID", log.Fields{"error": err}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 181 | return nil, err |
| 182 | } |
Matt Jeanneret | 4e24195 | 2019-02-28 11:16:04 -0500 | [diff] [blame] | 183 | case "serial_number": |
| 184 | if err := ptypes.UnmarshalAny(arg.Value, serialNumber); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 185 | logger.Warnw("cannot-unmarshal-ID", log.Fields{"error": err}) |
Matt Jeanneret | 4e24195 | 2019-02-28 11:16:04 -0500 | [diff] [blame] | 186 | return nil, err |
| 187 | } |
| 188 | case "onu_id": |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 189 | if err := ptypes.UnmarshalAny(arg.Value, onuID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 190 | logger.Warnw("cannot-unmarshal-ID", log.Fields{"error": err}) |
Matt Jeanneret | 4e24195 | 2019-02-28 11:16:04 -0500 | [diff] [blame] | 191 | return nil, err |
| 192 | } |
| 193 | case "parent_port_no": |
| 194 | if err := ptypes.UnmarshalAny(arg.Value, parentPortNo); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 195 | logger.Warnw("cannot-unmarshal-ID", log.Fields{"error": err}) |
Matt Jeanneret | 4e24195 | 2019-02-28 11:16:04 -0500 | [diff] [blame] | 196 | return nil, err |
| 197 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 198 | case kafka.TransactionKey: |
| 199 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 200 | logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 201 | return nil, err |
| 202 | } |
| 203 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 204 | } |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 205 | logger.Debugw("GetChildDevice", log.Fields{"parentDeviceID": pID.Id, "args": args, "transactionID": transactionID.Val}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 206 | |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 207 | return rhp.deviceMgr.GetChildDevice(context.TODO(), pID.Id, serialNumber.Val, onuID.Val, parentPortNo.Val) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 208 | } |
| 209 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 210 | // GetChildDeviceWithProxyAddress returns details of child device with proxy address |
Matt Jeanneret | 2a20aaa | 2019-03-05 21:04:02 -0500 | [diff] [blame] | 211 | func (rhp *AdapterRequestHandlerProxy) GetChildDeviceWithProxyAddress(args []*ic.Argument) (*voltha.Device, error) { |
| 212 | if len(args) < 2 { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 213 | logger.Warn("invalid-number-of-args", log.Fields{"args": args}) |
Matt Jeanneret | 2a20aaa | 2019-03-05 21:04:02 -0500 | [diff] [blame] | 214 | err := errors.New("invalid-number-of-args") |
| 215 | return nil, err |
| 216 | } |
| 217 | |
| 218 | proxyAddress := &voltha.Device_ProxyAddress{} |
| 219 | transactionID := &ic.StrType{} |
| 220 | for _, arg := range args { |
| 221 | switch arg.Key { |
| 222 | case "proxy_address": |
| 223 | if err := ptypes.UnmarshalAny(arg.Value, proxyAddress); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 224 | logger.Warnw("cannot-unmarshal-proxy-address", log.Fields{"error": err}) |
Matt Jeanneret | 2a20aaa | 2019-03-05 21:04:02 -0500 | [diff] [blame] | 225 | return nil, err |
| 226 | } |
| 227 | case kafka.TransactionKey: |
| 228 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 229 | logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
Matt Jeanneret | 2a20aaa | 2019-03-05 21:04:02 -0500 | [diff] [blame] | 230 | return nil, err |
| 231 | } |
| 232 | } |
| 233 | } |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 234 | logger.Debugw("GetChildDeviceWithProxyAddress", log.Fields{"proxyAddress": proxyAddress, "transactionID": transactionID.Val}) |
Matt Jeanneret | 2a20aaa | 2019-03-05 21:04:02 -0500 | [diff] [blame] | 235 | |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 236 | return rhp.deviceMgr.GetChildDeviceWithProxyAddress(context.TODO(), proxyAddress) |
Matt Jeanneret | 2a20aaa | 2019-03-05 21:04:02 -0500 | [diff] [blame] | 237 | } |
| 238 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 239 | // GetPorts returns the ports information of the device based on the port type. |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 240 | func (rhp *AdapterRequestHandlerProxy) GetPorts(args []*ic.Argument) (*voltha.Ports, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 241 | if len(args) < 3 { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 242 | logger.Warn("invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 243 | err := errors.New("invalid-number-of-args") |
| 244 | return nil, err |
| 245 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 246 | deviceID := &voltha.ID{} |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 247 | pt := &ic.IntType{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 248 | transactionID := &ic.StrType{} |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 249 | for _, arg := range args { |
| 250 | switch arg.Key { |
| 251 | case "device_id": |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 252 | if err := ptypes.UnmarshalAny(arg.Value, deviceID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 253 | logger.Warnw("cannot-unmarshal-device-id", log.Fields{"error": err}) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 254 | return nil, err |
| 255 | } |
| 256 | case "port_type": |
| 257 | if err := ptypes.UnmarshalAny(arg.Value, pt); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 258 | logger.Warnw("cannot-unmarshal-porttype", log.Fields{"error": err}) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 259 | return nil, err |
| 260 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 261 | case kafka.TransactionKey: |
| 262 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 263 | logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 264 | return nil, err |
| 265 | } |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 266 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 267 | } |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 268 | logger.Debugw("GetPorts", log.Fields{"deviceID": deviceID.Id, "portype": pt.Val, "transactionID": transactionID.Val}) |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 269 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 270 | return rhp.deviceMgr.getPorts(context.TODO(), deviceID.Id, voltha.Port_PortType(pt.Val)) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 271 | } |
| 272 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 273 | // GetChildDevices gets all the child device IDs from the device passed as parameter |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 274 | func (rhp *AdapterRequestHandlerProxy) GetChildDevices(args []*ic.Argument) (*voltha.Devices, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 275 | if len(args) < 2 { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 276 | logger.Warn("invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 277 | err := errors.New("invalid-number-of-args") |
| 278 | return nil, err |
| 279 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 280 | |
khenaidoo | 2c6f167 | 2018-09-20 23:14:41 -0400 | [diff] [blame] | 281 | pID := &voltha.ID{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 282 | transactionID := &ic.StrType{} |
| 283 | for _, arg := range args { |
| 284 | switch arg.Key { |
| 285 | case "device_id": |
| 286 | if err := ptypes.UnmarshalAny(arg.Value, pID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 287 | logger.Warnw("cannot-unmarshal-ID", log.Fields{"error": err}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 288 | return nil, err |
| 289 | } |
| 290 | case kafka.TransactionKey: |
| 291 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 292 | logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 293 | return nil, err |
| 294 | } |
| 295 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 296 | } |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 297 | logger.Debugw("GetChildDevices", log.Fields{"deviceID": pID.Id, "transactionID": transactionID.Val}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 298 | |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 299 | return rhp.deviceMgr.getAllChildDevices(context.TODO(), pID.Id) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 300 | } |
| 301 | |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 302 | // ChildDeviceDetected is invoked when a child device is detected. The following parameters are expected: |
Matt Jeanneret | 4e24195 | 2019-02-28 11:16:04 -0500 | [diff] [blame] | 303 | // {parent_device_id, parent_port_no, child_device_type, channel_id, vendor_id, serial_number) |
Mahir Gunyel | 6deaa24 | 2019-06-27 04:53:33 -0700 | [diff] [blame] | 304 | func (rhp *AdapterRequestHandlerProxy) ChildDeviceDetected(args []*ic.Argument) (*voltha.Device, error) { |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 305 | if len(args) < 5 { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 306 | logger.Warn("invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 307 | err := errors.New("invalid-number-of-args") |
| 308 | return nil, err |
| 309 | } |
| 310 | |
| 311 | pID := &voltha.ID{} |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 312 | portNo := &ic.IntType{} |
| 313 | dt := &ic.StrType{} |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 314 | chnlID := &ic.IntType{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 315 | transactionID := &ic.StrType{} |
Matt Jeanneret | 4e24195 | 2019-02-28 11:16:04 -0500 | [diff] [blame] | 316 | serialNumber := &ic.StrType{} |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 317 | vendorID := &ic.StrType{} |
| 318 | onuID := &ic.IntType{} |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 319 | for _, arg := range args { |
| 320 | switch arg.Key { |
| 321 | case "parent_device_id": |
| 322 | if err := ptypes.UnmarshalAny(arg.Value, pID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 323 | logger.Warnw("cannot-unmarshal-parent-device-id", log.Fields{"error": err}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 324 | return nil, err |
| 325 | } |
| 326 | case "parent_port_no": |
| 327 | if err := ptypes.UnmarshalAny(arg.Value, portNo); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 328 | logger.Warnw("cannot-unmarshal-parent-port", log.Fields{"error": err}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 329 | return nil, err |
| 330 | } |
| 331 | case "child_device_type": |
| 332 | if err := ptypes.UnmarshalAny(arg.Value, dt); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 333 | logger.Warnw("cannot-unmarshal-child-device-type", log.Fields{"error": err}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 334 | return nil, err |
| 335 | } |
| 336 | case "channel_id": |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 337 | if err := ptypes.UnmarshalAny(arg.Value, chnlID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 338 | logger.Warnw("cannot-unmarshal-channel-id", log.Fields{"error": err}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 339 | return nil, err |
| 340 | } |
Matt Jeanneret | 4e24195 | 2019-02-28 11:16:04 -0500 | [diff] [blame] | 341 | case "vendor_id": |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 342 | if err := ptypes.UnmarshalAny(arg.Value, vendorID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 343 | logger.Warnw("cannot-unmarshal-vendor-id", log.Fields{"error": err}) |
Matt Jeanneret | 4e24195 | 2019-02-28 11:16:04 -0500 | [diff] [blame] | 344 | return nil, err |
| 345 | } |
| 346 | case "serial_number": |
| 347 | if err := ptypes.UnmarshalAny(arg.Value, serialNumber); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 348 | logger.Warnw("cannot-unmarshal-serial-number", log.Fields{"error": err}) |
Matt Jeanneret | 4e24195 | 2019-02-28 11:16:04 -0500 | [diff] [blame] | 349 | return nil, err |
| 350 | } |
| 351 | case "onu_id": |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 352 | if err := ptypes.UnmarshalAny(arg.Value, onuID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 353 | logger.Warnw("cannot-unmarshal-onu-id", log.Fields{"error": err}) |
Matt Jeanneret | 4e24195 | 2019-02-28 11:16:04 -0500 | [diff] [blame] | 354 | return nil, err |
| 355 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 356 | case kafka.TransactionKey: |
| 357 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 358 | logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 359 | return nil, err |
| 360 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 361 | } |
| 362 | } |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 363 | logger.Debugw("ChildDeviceDetected", log.Fields{"parentDeviceID": pID.Id, "parentPortNo": portNo.Val, |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 364 | "deviceType": dt.Val, "channelID": chnlID.Val, "serialNumber": serialNumber.Val, |
| 365 | "vendorID": vendorID.Val, "onuID": onuID.Val, "transactionID": transactionID.Val}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 366 | |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 367 | device, err := rhp.deviceMgr.childDeviceDetected(context.TODO(), pID.Id, portNo.Val, dt.Val, chnlID.Val, vendorID.Val, serialNumber.Val, onuID.Val) |
Mahir Gunyel | 6deaa24 | 2019-06-27 04:53:33 -0700 | [diff] [blame] | 368 | if err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 369 | logger.Debugw("child-detection-failed", log.Fields{"parentID": pID.Id, "onuID": onuID.Val, "error": err}) |
khenaidoo | 59ef7be | 2019-06-21 12:40:28 -0400 | [diff] [blame] | 370 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 371 | return device, err |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 372 | } |
| 373 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 374 | // DeviceStateUpdate updates device status |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 375 | func (rhp *AdapterRequestHandlerProxy) DeviceStateUpdate(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 376 | if len(args) < 3 { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 377 | logger.Warn("invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 378 | err := errors.New("invalid-number-of-args") |
| 379 | return nil, err |
| 380 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 381 | deviceID := &voltha.ID{} |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 382 | operStatus := &ic.IntType{} |
| 383 | connStatus := &ic.IntType{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 384 | transactionID := &ic.StrType{} |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 385 | for _, arg := range args { |
| 386 | switch arg.Key { |
| 387 | case "device_id": |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 388 | if err := ptypes.UnmarshalAny(arg.Value, deviceID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 389 | logger.Warnw("cannot-unmarshal-device-id", log.Fields{"error": err}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 390 | return nil, err |
| 391 | } |
| 392 | case "oper_status": |
| 393 | if err := ptypes.UnmarshalAny(arg.Value, operStatus); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 394 | logger.Warnw("cannot-unmarshal-operStatus", log.Fields{"error": err}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 395 | return nil, err |
| 396 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 397 | case "connect_status": |
| 398 | if err := ptypes.UnmarshalAny(arg.Value, connStatus); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 399 | logger.Warnw("cannot-unmarshal-connStatus", log.Fields{"error": err}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 400 | return nil, err |
| 401 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 402 | case kafka.TransactionKey: |
| 403 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 404 | logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 405 | return nil, err |
| 406 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 407 | } |
| 408 | } |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 409 | logger.Debugw("DeviceStateUpdate", log.Fields{"deviceID": deviceID.Id, "oper-status": operStatus, |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 410 | "conn-status": connStatus, "transactionID": transactionID.Val}) |
| 411 | |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 412 | if err := rhp.deviceMgr.updateDeviceStatus(context.TODO(), deviceID.Id, voltha.OperStatus_Types(operStatus.Val), |
| 413 | voltha.ConnectStatus_Types(connStatus.Val)); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 414 | logger.Debugw("unable-to-update-device-status", log.Fields{"error": err}) |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 415 | return nil, err |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 416 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 417 | return &empty.Empty{}, nil |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 418 | } |
| 419 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 420 | // ChildrenStateUpdate updates child device status |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 421 | func (rhp *AdapterRequestHandlerProxy) ChildrenStateUpdate(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 422 | if len(args) < 3 { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 423 | logger.Warn("invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 424 | err := errors.New("invalid-number-of-args") |
| 425 | return nil, err |
| 426 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 427 | deviceID := &voltha.ID{} |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 428 | operStatus := &ic.IntType{} |
| 429 | connStatus := &ic.IntType{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 430 | transactionID := &ic.StrType{} |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 431 | for _, arg := range args { |
| 432 | switch arg.Key { |
| 433 | case "device_id": |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 434 | if err := ptypes.UnmarshalAny(arg.Value, deviceID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 435 | logger.Warnw("cannot-unmarshal-device-id", log.Fields{"error": err}) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 436 | return nil, err |
| 437 | } |
| 438 | case "oper_status": |
| 439 | if err := ptypes.UnmarshalAny(arg.Value, operStatus); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 440 | logger.Warnw("cannot-unmarshal-operStatus", log.Fields{"error": err}) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 441 | return nil, err |
| 442 | } |
| 443 | case "connect_status": |
| 444 | if err := ptypes.UnmarshalAny(arg.Value, connStatus); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 445 | logger.Warnw("cannot-unmarshal-connStatus", log.Fields{"error": err}) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 446 | return nil, err |
| 447 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 448 | case kafka.TransactionKey: |
| 449 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 450 | logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 451 | return nil, err |
| 452 | } |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 453 | } |
| 454 | } |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 455 | logger.Debugw("ChildrenStateUpdate", log.Fields{"deviceID": deviceID.Id, "oper-status": operStatus, |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 456 | "conn-status": connStatus, "transactionID": transactionID.Val}) |
| 457 | |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 458 | // When the enum is not set (i.e. -1), Go still convert to the Enum type with the value being -1 |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 459 | if err := rhp.deviceMgr.updateChildrenStatus(context.TODO(), deviceID.Id, voltha.OperStatus_Types(operStatus.Val), |
| 460 | voltha.ConnectStatus_Types(connStatus.Val)); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 461 | logger.Debugw("unable-to-update-children-status", log.Fields{"error": err}) |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 462 | return nil, err |
| 463 | } |
| 464 | return &empty.Empty{}, nil |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 465 | } |
| 466 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 467 | // PortsStateUpdate updates the ports state related to the device |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 468 | func (rhp *AdapterRequestHandlerProxy) PortsStateUpdate(args []*ic.Argument) (*empty.Empty, error) { |
| 469 | if len(args) < 2 { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 470 | logger.Warn("invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 471 | err := errors.New("invalid-number-of-args") |
| 472 | return nil, err |
| 473 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 474 | deviceID := &voltha.ID{} |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 475 | operStatus := &ic.IntType{} |
| 476 | transactionID := &ic.StrType{} |
| 477 | for _, arg := range args { |
| 478 | switch arg.Key { |
| 479 | case "device_id": |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 480 | if err := ptypes.UnmarshalAny(arg.Value, deviceID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 481 | logger.Warnw("cannot-unmarshal-device-id", log.Fields{"error": err}) |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 482 | return nil, err |
| 483 | } |
| 484 | case "oper_status": |
| 485 | if err := ptypes.UnmarshalAny(arg.Value, operStatus); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 486 | logger.Warnw("cannot-unmarshal-operStatus", log.Fields{"error": err}) |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 487 | return nil, err |
| 488 | } |
| 489 | case kafka.TransactionKey: |
| 490 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 491 | logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 492 | return nil, err |
| 493 | } |
| 494 | } |
| 495 | } |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 496 | logger.Debugw("PortsStateUpdate", log.Fields{"deviceID": deviceID.Id, "operStatus": operStatus, "transactionID": transactionID.Val}) |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 497 | |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 498 | if err := rhp.deviceMgr.updatePortsState(context.TODO(), deviceID.Id, voltha.OperStatus_Types(operStatus.Val)); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 499 | logger.Debugw("unable-to-update-ports-state", log.Fields{"error": err}) |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 500 | return nil, err |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 501 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 502 | return &empty.Empty{}, nil |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 503 | } |
| 504 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 505 | // PortStateUpdate updates the port state of the device |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 506 | func (rhp *AdapterRequestHandlerProxy) PortStateUpdate(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 507 | if len(args) < 3 { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 508 | logger.Warn("invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 509 | err := errors.New("invalid-number-of-args") |
| 510 | return nil, err |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 511 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 512 | deviceID := &voltha.ID{} |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 513 | portType := &ic.IntType{} |
| 514 | portNo := &ic.IntType{} |
| 515 | operStatus := &ic.IntType{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 516 | transactionID := &ic.StrType{} |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 517 | for _, arg := range args { |
| 518 | switch arg.Key { |
| 519 | case "device_id": |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 520 | if err := ptypes.UnmarshalAny(arg.Value, deviceID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 521 | logger.Warnw("cannot-unmarshal-device-id", log.Fields{"error": err}) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 522 | return nil, err |
| 523 | } |
| 524 | case "oper_status": |
| 525 | if err := ptypes.UnmarshalAny(arg.Value, operStatus); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 526 | logger.Warnw("cannot-unmarshal-operStatus", log.Fields{"error": err}) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 527 | return nil, err |
| 528 | } |
| 529 | case "port_type": |
| 530 | if err := ptypes.UnmarshalAny(arg.Value, portType); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 531 | logger.Warnw("cannot-unmarshal-porttype", log.Fields{"error": err}) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 532 | return nil, err |
| 533 | } |
| 534 | case "port_no": |
| 535 | if err := ptypes.UnmarshalAny(arg.Value, portNo); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 536 | logger.Warnw("cannot-unmarshal-portno", log.Fields{"error": err}) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 537 | return nil, err |
| 538 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 539 | case kafka.TransactionKey: |
| 540 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 541 | logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 542 | return nil, err |
| 543 | } |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 544 | } |
| 545 | } |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 546 | logger.Debugw("PortStateUpdate", log.Fields{"deviceID": deviceID.Id, "operStatus": operStatus, |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 547 | "portType": portType, "portNo": portNo, "transactionID": transactionID.Val}) |
| 548 | |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 549 | if err := rhp.deviceMgr.updatePortState(context.TODO(), deviceID.Id, voltha.Port_PortType(portType.Val), uint32(portNo.Val), |
| 550 | voltha.OperStatus_Types(operStatus.Val)); err != nil { |
| 551 | // If the error doesn't change behavior and is essentially ignored, it is not an error, it is a |
| 552 | // warning. |
| 553 | // TODO: VOL-2707 |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 554 | logger.Debugw("unable-to-update-port-state", log.Fields{"error": err}) |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 555 | return nil, err |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 556 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 557 | return &empty.Empty{}, nil |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 558 | } |
| 559 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 560 | // DeleteAllPorts deletes all ports of device |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 561 | func (rhp *AdapterRequestHandlerProxy) DeleteAllPorts(args []*ic.Argument) (*empty.Empty, error) { |
| 562 | if len(args) < 3 { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 563 | logger.Warn("invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 564 | err := errors.New("invalid-number-of-args") |
| 565 | return nil, err |
| 566 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 567 | deviceID := &voltha.ID{} |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 568 | transactionID := &ic.StrType{} |
| 569 | for _, arg := range args { |
| 570 | switch arg.Key { |
| 571 | case "device_id": |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 572 | if err := ptypes.UnmarshalAny(arg.Value, deviceID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 573 | logger.Warnw("cannot-unmarshal-device-id", log.Fields{"error": err}) |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 574 | return nil, err |
| 575 | } |
| 576 | case kafka.TransactionKey: |
| 577 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 578 | logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 579 | return nil, err |
| 580 | } |
| 581 | } |
| 582 | } |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 583 | logger.Debugw("DeleteAllPorts", log.Fields{"deviceID": deviceID.Id, "transactionID": transactionID.Val}) |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 584 | |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 585 | if err := rhp.deviceMgr.deleteAllPorts(context.TODO(), deviceID.Id); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 586 | logger.Debugw("unable-to-delete-ports", log.Fields{"error": err}) |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 587 | return nil, err |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 588 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 589 | return &empty.Empty{}, nil |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 590 | } |
| 591 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 592 | // ChildDevicesLost indicates that a parent device is in a state (Disabled) where it cannot manage the child devices. |
| 593 | // This will trigger the Core to disable all the child devices. |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 594 | func (rhp *AdapterRequestHandlerProxy) ChildDevicesLost(args []*ic.Argument) (*empty.Empty, error) { |
| 595 | if len(args) < 2 { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 596 | logger.Warn("invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 597 | err := errors.New("invalid-number-of-args") |
| 598 | return nil, err |
| 599 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 600 | parentDeviceID := &voltha.ID{} |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 601 | transactionID := &ic.StrType{} |
| 602 | for _, arg := range args { |
| 603 | switch arg.Key { |
| 604 | case "parent_device_id": |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 605 | if err := ptypes.UnmarshalAny(arg.Value, parentDeviceID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 606 | logger.Warnw("cannot-unmarshal-device-id", log.Fields{"error": err}) |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 607 | return nil, err |
| 608 | } |
| 609 | case kafka.TransactionKey: |
| 610 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 611 | logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 612 | return nil, err |
| 613 | } |
| 614 | } |
| 615 | } |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 616 | logger.Debugw("ChildDevicesLost", log.Fields{"deviceID": parentDeviceID.Id, "transactionID": transactionID.Val}) |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 617 | |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 618 | if err := rhp.deviceMgr.childDevicesLost(context.TODO(), parentDeviceID.Id); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 619 | logger.Debugw("unable-to-disable-child-devices", log.Fields{"error": err}) |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 620 | return nil, err |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 621 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 622 | return &empty.Empty{}, nil |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 623 | } |
| 624 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 625 | // ChildDevicesDetected invoked by an adapter when child devices are found, typically after after a disable/enable sequence. |
| 626 | // This will trigger the Core to Enable all the child devices of that parent. |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 627 | func (rhp *AdapterRequestHandlerProxy) ChildDevicesDetected(args []*ic.Argument) (*empty.Empty, error) { |
| 628 | if len(args) < 2 { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 629 | logger.Warn("invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 630 | err := errors.New("invalid-number-of-args") |
| 631 | return nil, err |
| 632 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 633 | parentDeviceID := &voltha.ID{} |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 634 | transactionID := &ic.StrType{} |
| 635 | for _, arg := range args { |
| 636 | switch arg.Key { |
| 637 | case "parent_device_id": |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 638 | if err := ptypes.UnmarshalAny(arg.Value, parentDeviceID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 639 | logger.Warnw("cannot-unmarshal-device-id", log.Fields{"error": err}) |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 640 | return nil, err |
| 641 | } |
| 642 | case kafka.TransactionKey: |
| 643 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 644 | logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 645 | return nil, err |
| 646 | } |
| 647 | } |
| 648 | } |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 649 | logger.Debugw("ChildDevicesDetected", log.Fields{"deviceID": parentDeviceID.Id, "transactionID": transactionID.Val}) |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 650 | |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 651 | if err := rhp.deviceMgr.childDevicesDetected(context.TODO(), parentDeviceID.Id); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 652 | logger.Debugw("child-devices-detection-failed", log.Fields{"parentID": parentDeviceID.Id, "error": err}) |
khenaidoo | 59ef7be | 2019-06-21 12:40:28 -0400 | [diff] [blame] | 653 | return nil, err |
| 654 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 655 | return &empty.Empty{}, nil |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 656 | } |
| 657 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 658 | // PortCreated adds port to device |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 659 | func (rhp *AdapterRequestHandlerProxy) PortCreated(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 660 | if len(args) < 3 { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 661 | logger.Warn("invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 662 | err := errors.New("invalid-number-of-args") |
| 663 | return nil, err |
| 664 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 665 | deviceID := &voltha.ID{} |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 666 | port := &voltha.Port{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 667 | transactionID := &ic.StrType{} |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 668 | for _, arg := range args { |
| 669 | switch arg.Key { |
| 670 | case "device_id": |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 671 | if err := ptypes.UnmarshalAny(arg.Value, deviceID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 672 | logger.Warnw("cannot-unmarshal-device-id", log.Fields{"error": err}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 673 | return nil, err |
| 674 | } |
| 675 | case "port": |
| 676 | if err := ptypes.UnmarshalAny(arg.Value, port); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 677 | logger.Warnw("cannot-unmarshal-port", log.Fields{"error": err}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 678 | return nil, err |
| 679 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 680 | case kafka.TransactionKey: |
| 681 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 682 | logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 683 | return nil, err |
| 684 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 685 | } |
| 686 | } |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 687 | logger.Debugw("PortCreated", log.Fields{"deviceID": deviceID.Id, "port": port, "transactionID": transactionID.Val}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 688 | |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 689 | if err := rhp.deviceMgr.addPort(context.TODO(), deviceID.Id, port); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 690 | logger.Debugw("unable-to-add-port", log.Fields{"error": err}) |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 691 | return nil, err |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 692 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 693 | return &empty.Empty{}, nil |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 694 | } |
| 695 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 696 | // DevicePMConfigUpdate initializes the pm configs as defined by the adapter. |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 697 | func (rhp *AdapterRequestHandlerProxy) DevicePMConfigUpdate(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 698 | if len(args) < 2 { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 699 | logger.Warn("invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 700 | err := errors.New("invalid-number-of-args") |
| 701 | return nil, err |
| 702 | } |
| 703 | pmConfigs := &voltha.PmConfigs{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 704 | transactionID := &ic.StrType{} |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 705 | for _, arg := range args { |
| 706 | switch arg.Key { |
| 707 | case "device_pm_config": |
| 708 | if err := ptypes.UnmarshalAny(arg.Value, pmConfigs); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 709 | logger.Warnw("cannot-unmarshal-pm-config", log.Fields{"error": err}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 710 | return nil, err |
| 711 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 712 | case kafka.TransactionKey: |
| 713 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 714 | logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 715 | return nil, err |
| 716 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 717 | } |
| 718 | } |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 719 | logger.Debugw("DevicePMConfigUpdate", log.Fields{"deviceID": pmConfigs.Id, "configs": pmConfigs, |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 720 | "transactionID": transactionID.Val}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 721 | |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 722 | if err := rhp.deviceMgr.initPmConfigs(context.TODO(), pmConfigs.Id, pmConfigs); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 723 | logger.Debugw("unable-to-initialize-pm-configs", log.Fields{"error": err}) |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 724 | return nil, err |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 725 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 726 | return &empty.Empty{}, nil |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 727 | } |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 728 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 729 | // PacketIn sends the incoming packet of device |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 730 | func (rhp *AdapterRequestHandlerProxy) PacketIn(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 731 | if len(args) < 4 { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 732 | logger.Warn("invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 733 | err := errors.New("invalid-number-of-args") |
| 734 | return nil, err |
| 735 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 736 | deviceID := &voltha.ID{} |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 737 | portNo := &ic.IntType{} |
| 738 | packet := &ic.Packet{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 739 | transactionID := &ic.StrType{} |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 740 | for _, arg := range args { |
| 741 | switch arg.Key { |
| 742 | case "device_id": |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 743 | if err := ptypes.UnmarshalAny(arg.Value, deviceID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 744 | logger.Warnw("cannot-unmarshal-device-id", log.Fields{"error": err}) |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 745 | return nil, err |
| 746 | } |
| 747 | case "port": |
| 748 | if err := ptypes.UnmarshalAny(arg.Value, portNo); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 749 | logger.Warnw("cannot-unmarshal-port-no", log.Fields{"error": err}) |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 750 | return nil, err |
| 751 | } |
| 752 | case "packet": |
| 753 | if err := ptypes.UnmarshalAny(arg.Value, packet); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 754 | logger.Warnw("cannot-unmarshal-packet", log.Fields{"error": err}) |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 755 | return nil, err |
| 756 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 757 | case kafka.TransactionKey: |
| 758 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 759 | logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 760 | return nil, err |
| 761 | } |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 762 | } |
| 763 | } |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 764 | logger.Debugw("PacketIn", log.Fields{"deviceID": deviceID.Id, "port": portNo.Val, "packet": packet, |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 765 | "transactionID": transactionID.Val}) |
| 766 | |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 767 | if err := rhp.deviceMgr.PacketIn(context.TODO(), deviceID.Id, uint32(portNo.Val), transactionID.Val, packet.Payload); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 768 | logger.Debugw("unable-to-receive-packet-from-adapter", log.Fields{"error": err}) |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 769 | return nil, err |
| 770 | |
| 771 | } |
| 772 | return &empty.Empty{}, nil |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 773 | } |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 774 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 775 | // UpdateImageDownload updates image download |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 776 | func (rhp *AdapterRequestHandlerProxy) UpdateImageDownload(args []*ic.Argument) (*empty.Empty, error) { |
| 777 | if len(args) < 2 { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 778 | logger.Warn("invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 779 | err := errors.New("invalid-number-of-args") |
| 780 | return nil, err |
| 781 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 782 | deviceID := &voltha.ID{} |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 783 | img := &voltha.ImageDownload{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 784 | transactionID := &ic.StrType{} |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 785 | for _, arg := range args { |
| 786 | switch arg.Key { |
| 787 | case "device_id": |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 788 | if err := ptypes.UnmarshalAny(arg.Value, deviceID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 789 | logger.Warnw("cannot-unmarshal-device-id", log.Fields{"error": err}) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 790 | return nil, err |
| 791 | } |
| 792 | case "image_download": |
| 793 | if err := ptypes.UnmarshalAny(arg.Value, img); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 794 | logger.Warnw("cannot-unmarshal-imgaeDownload", log.Fields{"error": err}) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 795 | return nil, err |
| 796 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 797 | case kafka.TransactionKey: |
| 798 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 799 | logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 800 | return nil, err |
| 801 | } |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 802 | } |
| 803 | } |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 804 | logger.Debugw("UpdateImageDownload", log.Fields{"deviceID": deviceID.Id, "image-download": img, |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 805 | "transactionID": transactionID.Val}) |
| 806 | |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 807 | if err := rhp.deviceMgr.updateImageDownload(context.TODO(), deviceID.Id, img); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 808 | logger.Debugw("unable-to-update-image-download", log.Fields{"error": err}) |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 809 | return nil, err |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 810 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 811 | return &empty.Empty{}, nil |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 812 | } |
khenaidoo | ba6b6c4 | 2019-08-02 09:11:56 -0400 | [diff] [blame] | 813 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 814 | // ReconcileChildDevices reconciles child devices |
khenaidoo | ba6b6c4 | 2019-08-02 09:11:56 -0400 | [diff] [blame] | 815 | func (rhp *AdapterRequestHandlerProxy) ReconcileChildDevices(args []*ic.Argument) (*empty.Empty, error) { |
| 816 | if len(args) < 2 { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 817 | logger.Warn("invalid-number-of-args", log.Fields{"args": args}) |
khenaidoo | ba6b6c4 | 2019-08-02 09:11:56 -0400 | [diff] [blame] | 818 | err := errors.New("invalid-number-of-args") |
| 819 | return nil, err |
| 820 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 821 | parentDeviceID := &voltha.ID{} |
khenaidoo | ba6b6c4 | 2019-08-02 09:11:56 -0400 | [diff] [blame] | 822 | transactionID := &ic.StrType{} |
| 823 | for _, arg := range args { |
| 824 | switch arg.Key { |
| 825 | case "parent_device_id": |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 826 | if err := ptypes.UnmarshalAny(arg.Value, parentDeviceID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 827 | logger.Warnw("cannot-unmarshal-device-id", log.Fields{"error": err}) |
khenaidoo | ba6b6c4 | 2019-08-02 09:11:56 -0400 | [diff] [blame] | 828 | return nil, err |
| 829 | } |
| 830 | case kafka.TransactionKey: |
| 831 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 832 | logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
khenaidoo | ba6b6c4 | 2019-08-02 09:11:56 -0400 | [diff] [blame] | 833 | return nil, err |
| 834 | } |
| 835 | } |
| 836 | } |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 837 | logger.Debugw("ReconcileChildDevices", log.Fields{"deviceID": parentDeviceID.Id, "transactionID": transactionID.Val}) |
khenaidoo | ba6b6c4 | 2019-08-02 09:11:56 -0400 | [diff] [blame] | 838 | |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 839 | if err := rhp.deviceMgr.reconcileChildDevices(context.TODO(), parentDeviceID.Id); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 840 | logger.Debugw("unable-to-reconcile-child-devices", log.Fields{"error": err}) |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 841 | return nil, err |
khenaidoo | ba6b6c4 | 2019-08-02 09:11:56 -0400 | [diff] [blame] | 842 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 843 | return &empty.Empty{}, nil |
khenaidoo | ba6b6c4 | 2019-08-02 09:11:56 -0400 | [diff] [blame] | 844 | } |
Mahir Gunyel | fdee921 | 2019-10-16 16:52:21 -0700 | [diff] [blame] | 845 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 846 | // DeviceReasonUpdate updates device reason |
Mahir Gunyel | fdee921 | 2019-10-16 16:52:21 -0700 | [diff] [blame] | 847 | func (rhp *AdapterRequestHandlerProxy) DeviceReasonUpdate(args []*ic.Argument) (*empty.Empty, error) { |
| 848 | if len(args) < 2 { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 849 | logger.Warn("DeviceReasonUpdate: invalid-number-of-args", log.Fields{"args": args}) |
Mahir Gunyel | fdee921 | 2019-10-16 16:52:21 -0700 | [diff] [blame] | 850 | err := errors.New("DeviceReasonUpdate: invalid-number-of-args") |
| 851 | return nil, err |
| 852 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 853 | deviceID := &voltha.ID{} |
Mahir Gunyel | fdee921 | 2019-10-16 16:52:21 -0700 | [diff] [blame] | 854 | reason := &ic.StrType{} |
| 855 | transactionID := &ic.StrType{} |
| 856 | for _, arg := range args { |
| 857 | switch arg.Key { |
| 858 | case "device_id": |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 859 | if err := ptypes.UnmarshalAny(arg.Value, deviceID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 860 | logger.Warnw("cannot-unmarshal-device-id", log.Fields{"error": err}) |
Mahir Gunyel | fdee921 | 2019-10-16 16:52:21 -0700 | [diff] [blame] | 861 | return nil, err |
| 862 | } |
| 863 | case "device_reason": |
| 864 | if err := ptypes.UnmarshalAny(arg.Value, reason); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 865 | logger.Warnw("cannot-unmarshal-reason", log.Fields{"error": err}) |
Mahir Gunyel | fdee921 | 2019-10-16 16:52:21 -0700 | [diff] [blame] | 866 | return nil, err |
| 867 | } |
| 868 | case kafka.TransactionKey: |
| 869 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 870 | logger.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
Mahir Gunyel | fdee921 | 2019-10-16 16:52:21 -0700 | [diff] [blame] | 871 | return nil, err |
| 872 | } |
| 873 | } |
| 874 | } |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 875 | logger.Debugw("DeviceReasonUpdate", log.Fields{"deviceId": deviceID.Id, "reason": reason.Val, |
Mahir Gunyel | fdee921 | 2019-10-16 16:52:21 -0700 | [diff] [blame] | 876 | "transactionID": transactionID.Val}) |
| 877 | |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 878 | if err := rhp.deviceMgr.updateDeviceReason(context.TODO(), deviceID.Id, reason.Val); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 879 | logger.Debugw("unable-to-update-device-reason", log.Fields{"error": err}) |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 880 | return nil, err |
| 881 | |
Mahir Gunyel | fdee921 | 2019-10-16 16:52:21 -0700 | [diff] [blame] | 882 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 883 | return &empty.Empty{}, nil |
Mahir Gunyel | fdee921 | 2019-10-16 16:52:21 -0700 | [diff] [blame] | 884 | } |