blob: c972e9f4504541d8f3abc216db8c60be1c169850 [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.
vinokuma926cb3e2023-03-29 11:41:06 +053014 */
Naveen Sampath04696f72022-06-13 15:19:14 +053015
16package controller
17
18import (
19 "context"
20 "time"
21
Tinoj Joseph1d108322022-07-13 10:07:39 +053022 "voltha-go-controller/log"
Naveen Sampath04696f72022-06-13 15:19:14 +053023)
24
25// PendingProfilesTask structure
26type PendingProfilesTask struct {
Naveen Sampath04696f72022-06-13 15:19:14 +053027 ctx context.Context
28 device *Device
29 ts string
vinokuma926cb3e2023-03-29 11:41:06 +053030 taskID uint8
Naveen Sampath04696f72022-06-13 15:19:14 +053031}
32
33// NewPendingProfilesTask is constructor for PendingProfilesTask
34func NewPendingProfilesTask(device *Device) *PendingProfilesTask {
35 var ppt PendingProfilesTask
36 ppt.device = device
37 ppt.ts = (time.Now()).Format(time.RFC3339Nano)
38 return &ppt
39}
40
41// Name returns name of the task
42func (ppt *PendingProfilesTask) Name() string {
43 return "Pending Profiles Task"
44}
45
46// TaskID returns task id of the task
47func (ppt *PendingProfilesTask) TaskID() uint8 {
48 return ppt.taskID
49}
50
51// Timestamp returns timestamp of the task
52func (ppt *PendingProfilesTask) Timestamp() string {
53 return ppt.ts
54}
55
56// Stop to stop the task
57func (ppt *PendingProfilesTask) Stop() {
58}
59
60// Start is called by the framework and is responsible for implementing
61// the actual task.
62func (ppt *PendingProfilesTask) Start(ctx context.Context, taskID uint8) error {
63 logger.Warnw(ctx, "Pending Profiles Task Triggered", log.Fields{"Context": ctx, "taskID": taskID, "Device": ppt.device.ID})
64 ppt.taskID = taskID
65 ppt.ctx = ctx
66 var errInfo error
67
68 GetController().SetAuditFlags(ppt.device)
69
70 //Trigger Pending Service Delete Tasks
71 logger.Warnw(ctx, "Pending Service Delete Task Triggered", log.Fields{"Device": ppt.device.ID})
Tinoj Joseph07cc5372022-07-18 22:53:51 +053072 GetController().TriggerPendingProfileDeleteReq(ctx, ppt.device.ID)
Naveen Sampath04696f72022-06-13 15:19:14 +053073 logger.Warnw(ctx, "Pending Service Delete Task Completed", log.Fields{"Device": ppt.device.ID})
74
75 //Trigger Pending Migrate Services Tasks
76 logger.Warnw(ctx, "Pending Migrate Services Task Triggered", log.Fields{"Device": ppt.device.ID})
Tinoj Joseph07cc5372022-07-18 22:53:51 +053077 GetController().TriggerPendingMigrateServicesReq(ctx, ppt.device.ID)
Naveen Sampath04696f72022-06-13 15:19:14 +053078 logger.Warnw(ctx, "Pending Migrate Services Task Completed", log.Fields{"Device": ppt.device.ID})
79
80 GetController().ResetAuditFlags(ppt.device)
81
82 // Updating Mvlan Profile
83 logger.Warnw(ctx, "Pending Update Mvlan Task Triggered", log.Fields{"Device": ppt.device.ID})
Tinoj Joseph07cc5372022-07-18 22:53:51 +053084 if err := ppt.UpdateMvlanProfiles(ctx); err != nil {
Naveen Sampath04696f72022-06-13 15:19:14 +053085 logger.Errorw(ctx, "Update Mvlan Profile Failed", log.Fields{"Reason": err.Error()})
86 errInfo = err
87 }
88 logger.Warnw(ctx, "Pending Update Mvlan Task Completed", log.Fields{"Device": ppt.device.ID})
89
90 logger.Warnw(ctx, "Pending Profiles Task Completed", log.Fields{"Context": ctx, "taskID": taskID, "Device": ppt.device.ID})
91 return errInfo
92}
93
94// UpdateMvlanProfiles to update the mvlan profiles
Tinoj Joseph07cc5372022-07-18 22:53:51 +053095func (ppt *PendingProfilesTask) UpdateMvlanProfiles(cntx context.Context) error {
96 GetController().UpdateMvlanProfiles(cntx, ppt.device.ID)
Naveen Sampath04696f72022-06-13 15:19:14 +053097 return nil
98}