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. |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 14 | */ |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 15 | |
| 16 | package controller |
| 17 | |
| 18 | import ( |
| 19 | "context" |
| 20 | "time" |
| 21 | |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 22 | "voltha-go-controller/log" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 23 | ) |
| 24 | |
| 25 | // PendingProfilesTask structure |
| 26 | type PendingProfilesTask struct { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 27 | ctx context.Context |
| 28 | device *Device |
| 29 | ts string |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 30 | taskID uint8 |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | // NewPendingProfilesTask is constructor for PendingProfilesTask |
| 34 | func 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 |
| 42 | func (ppt *PendingProfilesTask) Name() string { |
| 43 | return "Pending Profiles Task" |
| 44 | } |
| 45 | |
| 46 | // TaskID returns task id of the task |
| 47 | func (ppt *PendingProfilesTask) TaskID() uint8 { |
| 48 | return ppt.taskID |
| 49 | } |
| 50 | |
| 51 | // Timestamp returns timestamp of the task |
| 52 | func (ppt *PendingProfilesTask) Timestamp() string { |
| 53 | return ppt.ts |
| 54 | } |
| 55 | |
| 56 | // Stop to stop the task |
| 57 | func (ppt *PendingProfilesTask) Stop() { |
| 58 | } |
| 59 | |
| 60 | // Start is called by the framework and is responsible for implementing |
| 61 | // the actual task. |
| 62 | func (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 Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 72 | GetController().TriggerPendingProfileDeleteReq(ctx, ppt.device.ID) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 73 | 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 Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 77 | GetController().TriggerPendingMigrateServicesReq(ctx, ppt.device.ID) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 78 | 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 Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 84 | if err := ppt.UpdateMvlanProfiles(ctx); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 85 | 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 Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 95 | func (ppt *PendingProfilesTask) UpdateMvlanProfiles(cntx context.Context) error { |
| 96 | GetController().UpdateMvlanProfiles(cntx, ppt.device.ID) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 97 | return nil |
| 98 | } |