blob: 621e72097a3d00658d56ec01ff17c4c94b67d44f [file] [log] [blame]
Maninder9a1bc0d2020-10-26 11:34:02 +05301/*
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
17package device
18
19import (
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
27func (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
41func (agent *Agent) stateChangeString(prevState *common.AdminState_Types, currState *common.AdminState_Types) string {
Maninder9a1bc0d2020-10-26 11:34:02 +053042 if prevState != nil && currState != nil && *prevState != *currState {
khenaidoodd3324d2021-04-27 16:22:55 -040043 return fmt.Sprintf("%s->%s", *prevState, *currState)
Maninder9a1bc0d2020-10-26 11:34:02 +053044 }
45 return ""
46}