blob: ddffac2b4a0ba88572f299c13780aac3beb117e9 [file] [log] [blame]
Naveen Sampath04696f72022-06-13 15:19:14 +05301/*
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
16package controller
17
18import (
19 "context"
20 "time"
21
22 "voltha-go-controller/internal/pkg/intf"
23 "voltha-go-controller/internal/pkg/vpagent"
24
Tinoj Joseph1d108322022-07-13 10:07:39 +053025 "voltha-go-controller/log"
Naveen Sampath04696f72022-06-13 15:19:14 +053026)
27
28// AddDeviceTask structure
29type AddDeviceTask struct {
Naveen Sampath04696f72022-06-13 15:19:14 +053030 ctx context.Context
31 config *intf.VPClientCfg
32 timestamp string
vinokuma926cb3e2023-03-29 11:41:06 +053033 taskID uint8
Naveen Sampath04696f72022-06-13 15:19:14 +053034}
35
36// NewAddDeviceTask is the constructor for AddDeviceTask
37func 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
46func (adt *AddDeviceTask) Name() string {
47 return "Add Device Task"
48}
49
50// TaskID returns task Id of the task
51func (adt *AddDeviceTask) TaskID() uint8 {
52 return adt.taskID
53}
54
55// Timestamp returns time stamp for the task
56func (adt *AddDeviceTask) Timestamp() string {
57 return adt.timestamp
58}
59
60// Stop to stop the task
61func (adt *AddDeviceTask) Stop() {
62}
63
64// Start to start the task
65func (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 Joseph07cc5372022-07-18 22:53:51 +053071 device := GetController().AddDevice(ctx, adt.config)
Naveen Sampath04696f72022-06-13 15:19:14 +053072 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}