Maninder | 9a1bc0d | 2020-10-26 11:34:02 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021-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 device |
| 18 | |
| 19 | import ( |
| 20 | "context" |
| 21 | "fmt" |
| 22 | "github.com/opencord/voltha-go/rw_core/utils" |
| 23 | "github.com/opencord/voltha-lib-go/v4/pkg/log" |
| 24 | "github.com/opencord/voltha-protos/v4/go/common" |
| 25 | ) |
| 26 | |
| 27 | func (agent *Agent) logDeviceUpdate(ctx context.Context, operation string, prevState *common.AdminState_Types, currState *common.AdminState_Types, status *common.OperationResp, desc *string) { |
| 28 | logger.Debugw(ctx, "addDeviceUpdate", log.Fields{"device-id": agent.deviceID}) |
| 29 | |
| 30 | requestedBy := utils.GetFromTopicMetadataFromContext(ctx) |
| 31 | |
| 32 | if requestedBy == "" { |
| 33 | requestedBy = "NB" |
| 34 | } |
| 35 | |
| 36 | logger.Infow(ctx, "logDeviceUpdate", log.Fields{"device-update": operation, "device-update-id": agent.deviceID, |
| 37 | "requested-by": requestedBy, "state-change": agent.stateChangeString(prevState, currState), |
| 38 | "status": status.GetCode().String(), "description": desc}) |
| 39 | } |
| 40 | |
| 41 | func (agent *Agent) stateChangeString(prevState *common.AdminState_Types, currState *common.AdminState_Types) string { |
Maninder | 9a1bc0d | 2020-10-26 11:34:02 +0530 | [diff] [blame] | 42 | if prevState != nil && currState != nil && *prevState != *currState { |
khenaidoo | dd3324d | 2021-04-27 16:22:55 -0400 | [diff] [blame] | 43 | return fmt.Sprintf("%s->%s", *prevState, *currState) |
Maninder | 9a1bc0d | 2020-10-26 11:34:02 +0530 | [diff] [blame] | 44 | } |
| 45 | return "" |
| 46 | } |