Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022-present Open Networking Foundation |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | package controller |
| 17 | |
| 18 | import ( |
| 19 | "context" |
| 20 | "time" |
| 21 | |
| 22 | "voltha-go-controller/internal/pkg/intf" |
| 23 | "voltha-go-controller/internal/pkg/vpagent" |
| 24 | |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 25 | "voltha-go-controller/log" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 26 | ) |
| 27 | |
| 28 | // AddDeviceTask structure |
| 29 | type AddDeviceTask struct { |
| 30 | taskID uint8 |
| 31 | ctx context.Context |
| 32 | config *intf.VPClientCfg |
| 33 | timestamp string |
| 34 | } |
| 35 | |
| 36 | // NewAddDeviceTask is the constructor for AddDeviceTask |
| 37 | func NewAddDeviceTask(config *intf.VPClientCfg) *AddDeviceTask { |
| 38 | var adt AddDeviceTask |
| 39 | adt.config = config |
| 40 | tstamp := (time.Now()).Format(time.RFC3339Nano) |
| 41 | adt.timestamp = tstamp |
| 42 | return &adt |
| 43 | } |
| 44 | |
| 45 | // Name returns name of the task |
| 46 | func (adt *AddDeviceTask) Name() string { |
| 47 | return "Add Device Task" |
| 48 | } |
| 49 | |
| 50 | // TaskID returns task Id of the task |
| 51 | func (adt *AddDeviceTask) TaskID() uint8 { |
| 52 | return adt.taskID |
| 53 | } |
| 54 | |
| 55 | // Timestamp returns time stamp for the task |
| 56 | func (adt *AddDeviceTask) Timestamp() string { |
| 57 | return adt.timestamp |
| 58 | } |
| 59 | |
| 60 | // Stop to stop the task |
| 61 | func (adt *AddDeviceTask) Stop() { |
| 62 | } |
| 63 | |
| 64 | // Start to start the task |
| 65 | func (adt *AddDeviceTask) Start(ctx context.Context, taskID uint8) error { |
| 66 | adt.taskID = taskID |
| 67 | adt.ctx = ctx |
| 68 | |
| 69 | logger.Infow(ctx, "Add Device Task Triggered", log.Fields{"Device": adt.config.DeviceID, "SerialNum": adt.config.SerialNum}) |
| 70 | |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 71 | device := GetController().AddDevice(ctx, adt.config) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 72 | vpagent.GetVPAgent().AddClientToClientMap(adt.config.DeviceID, device) |
| 73 | logger.Infow(ctx, "Add Device Task Completed", log.Fields{"Device": adt.config.DeviceID, "SerialNum": adt.config.SerialNum}) |
| 74 | |
| 75 | return nil |
| 76 | } |