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 application |
| 17 | |
| 18 | import ( |
| 19 | "context" |
| 20 | "encoding/json" |
| 21 | "errors" |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 22 | "fmt" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 23 | "sync" |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 24 | common "voltha-go-controller/internal/pkg/types" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 25 | |
| 26 | "github.com/google/gopacket/layers" |
| 27 | |
| 28 | "voltha-go-controller/database" |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 29 | "voltha-go-controller/log" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 30 | ) |
| 31 | |
| 32 | const ( |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 33 | // MigrationComplete Represents the Migration Complete |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 34 | MigrationComplete = "Completed" |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 35 | // MigrationInProgress Represents the Migration Inprogress |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 36 | MigrationInProgress = "InProgress" |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 37 | // MigrationFailed Represents the Migration Failed |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 38 | MigrationFailed = "Failed" |
| 39 | // StatusNone for no operations |
| 40 | StatusNone = "NONE" |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 41 | // ModuleToBeDeleted - module where old version is deleted |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 42 | ModuleToBeDeleted = "ModuleToBeDeleted" |
| 43 | ) |
| 44 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 45 | // DataMigration represents the Version and Status info for Major Version Upgrade. |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 46 | type DataMigration struct { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 47 | ModuleVer map[string]string // eg. "service": "v1" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 48 | Version string |
| 49 | Status string |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 50 | } |
| 51 | |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 52 | type paramsMigrationFunc func(context.Context, []byte) string |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 53 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 54 | // map to store conversion functions |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 55 | var migrationMap = map[string]paramsMigrationFunc{ |
| 56 | database.ServicePath: MigrateServices, |
| 57 | database.DevicePath: MigrateDevices, |
| 58 | database.DevicePortPath: MigrateDevicePorts, |
| 59 | database.DeviceFlowPath: MigrateDeviceFlows, |
| 60 | database.DeviceGroupPath: MigrateDeviceGroups, |
| 61 | database.DeviceMeterPath: MigrateDeviceMeters, |
| 62 | database.VnetPath: MigrateVnets, |
| 63 | database.VpvPath: MigrateVpvs, |
| 64 | database.MvlanPath: MigrateMvlans, |
| 65 | database.MeterPath: MigrateMeters, |
| 66 | database.IgmpConfPath: MigrateIgmpConfs, |
| 67 | database.IgmpGroupPath: MigrateIgmpGroups, |
| 68 | database.IgmpDevicePath: MigrateIgmpDevices, |
| 69 | database.IgmpChannelPath: MigrateIgmpChannels, |
| 70 | database.IgmpPortPath: MigrateIgmpPorts, |
| 71 | database.IgmpProfPath: MigrateIgmpProfs, |
| 72 | database.McastConfigPath: MigrateMcastConfs, |
| 73 | database.LogLevelPath: MigrateLogLevels, |
| 74 | database.HealthPath: MigrateHealth, |
| 75 | database.PonCounterPath: MigratePonCounters, |
| 76 | database.ChannelCounterPath: MigrateChannelCounters, |
| 77 | database.ServiceCounterPath: MigrateServiceCounters, |
| 78 | database.NbDevicePath: MigrateNbDevices, |
| 79 | database.DeviceFlowHashPath: MigrateDeviceFlowHash, |
| 80 | } |
| 81 | |
| 82 | // WriteToDb write a meter profile to DB |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 83 | func (md *DataMigration) WriteToDb(cntx context.Context) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 84 | b, err := json.Marshal(md) |
| 85 | if err != nil { |
| 86 | return err |
| 87 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 88 | if err1 := db.PutMigrationInfo(cntx, string(b)); err1 != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 89 | return err1 |
| 90 | } |
| 91 | return nil |
| 92 | } |
| 93 | |
| 94 | // DelFromDb delete a meter profile from DB |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 95 | func (md *DataMigration) DelFromDb(cntx context.Context) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 96 | logger.Debug(ctx, "Received Delete from Db") |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 97 | if err := db.DelMigrationInfo(cntx); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 98 | logger.Warnw(ctx, "DelMigrationInfo Failed", log.Fields{"Error": err}) |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | // GetMigrationInfo to get data migration info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 103 | func GetMigrationInfo(cntx context.Context, dmInfo *DataMigration) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 104 | logger.Debug(ctx, "Get Migration Info") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 105 | var migrationInfo string |
| 106 | var err error |
| 107 | if db == nil { |
| 108 | db = database.GetDatabase() |
| 109 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 110 | if migrationInfo, err = db.GetMigrationInfo(cntx); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 111 | return err |
| 112 | } |
| 113 | err = json.Unmarshal([]byte(migrationInfo), &dmInfo) |
| 114 | if err != nil { |
| 115 | logger.Warn(ctx, "Unmarshal of migrationinfo failed") |
| 116 | return err |
| 117 | } |
| 118 | return nil |
| 119 | } |
| 120 | |
| 121 | // CheckIfMigrationRequired Checks if Migration is Completed |
| 122 | // Only Data Migration and Reboot would be handled in the Below function |
| 123 | // When Roll back happens just Delete of DB keys has to happen |
| 124 | // which will be done once delete key request is received from MSM |
| 125 | func CheckIfMigrationRequired(ctx context.Context) bool { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 126 | logger.Debug(ctx, "Check If Migration Required") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 127 | Migrate := new(DataMigration) |
| 128 | var NoDataInDB bool |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 129 | err := GetMigrationInfo(ctx, Migrate) |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 130 | logger.Debugw(ctx, "Migration data", log.Fields{"DataMigration": Migrate}) |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 131 | // No DB entry represents N version Bring Up for the First time |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 132 | if err != nil { |
| 133 | NoDataInDB = true |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 134 | logger.Warn(ctx, "Failed to read the Migration Data from DB ") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 135 | } |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 136 | // Covers N version bringup and Reboot Scenarios |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 137 | if NoDataInDB { |
| 138 | logger.Info(ctx, "Data Migration Not Required") |
| 139 | Migrate.Version = database.PresentVersion |
| 140 | Migrate.Status = MigrationComplete |
| 141 | Migrate.ModuleVer = database.PresentVersionMap |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 142 | if err := Migrate.WriteToDb(ctx); err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 143 | logger.Warnw(ctx, "DB Write failed for Migration Path", log.Fields{"error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 144 | } |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 145 | // MigrateProbestatus has to be Updated to Complete when No Migration is Required |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 146 | logger.Debugw(ctx, "Migration Probe Status", log.Fields{"Migration Probe": Migrate.Status}) |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 147 | // probe.UpdateDBMigrationStatus(ctx, true) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 148 | return false |
| 149 | // Migration required when vgc moves to Higher Versions |
| 150 | } else if Migrate.ModuleVer == nil { |
| 151 | // This case will hit when DataMigration is present with old schema |
| 152 | // and DataMigration schema has changed. |
| 153 | // In this case compare previous and current version configured in the models. |
| 154 | for key, currVer := range database.PresentVersionMap { |
| 155 | if currVer > database.PreviousVersionMap[key] { |
| 156 | logger.Infow(ctx, "DB Migration needed for", log.Fields{"comp": key}) |
| 157 | return true |
| 158 | } |
| 159 | } |
| 160 | } else { |
| 161 | var isVersionChanged bool |
| 162 | // Compare the current version with previous version present in DB. |
| 163 | // This case will also hit in case of POD restart. |
| 164 | for key, currVer := range database.PresentVersionMap { |
| 165 | if dbVer := Migrate.ModuleVer[key]; dbVer != "" { |
| 166 | if currVer > dbVer { |
| 167 | logger.Infow(ctx, "DB Migration needed for", log.Fields{"comp": key}) |
| 168 | isVersionChanged = true |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | database.DBVersionMap = Migrate.ModuleVer // Store DB data |
| 173 | |
| 174 | if isVersionChanged { |
| 175 | return true |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | // In case Service Reboots/Rolls Back then Probe Success to MSM |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 180 | logger.Debugw(ctx, "Migration Probe Status", log.Fields{"Migration Probe": Migrate.Status}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 181 | //probe.UpdateDBMigrationStatus(ctx, true) |
| 182 | return false |
| 183 | } |
| 184 | |
| 185 | // InitiateDataMigration Migrates the DB data |
| 186 | // depending on the bool value returned by CheckIfMigrationDone |
| 187 | func InitiateDataMigration(ctx context.Context) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 188 | logger.Debug(ctx, "Initiate Data Migration") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 189 | var err error |
| 190 | Migrate := new(DataMigration) |
| 191 | var migrationWG sync.WaitGroup |
| 192 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 193 | // Keeping it outside to avoid race condition where the |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 194 | // wait check is reached before the go toutine for data migraiton is triggered |
| 195 | migrationWG.Add(1) |
| 196 | |
| 197 | go func() { |
| 198 | logger.Debug(ctx, "Started Go Routine for data migration") |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 199 | err = MigrateDBData(ctx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 200 | if err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 201 | logger.Errorw(ctx, "Failed to Migrate the Data", log.Fields{"error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 202 | Migrate.Status = MigrationFailed |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 203 | if err = Migrate.WriteToDb(ctx); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 204 | logger.Errorw(ctx, "DB Write failed to Migration Path", log.Fields{"error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | logger.Debug(ctx, "Completed Go Routine for data migration") |
| 208 | migrationWG.Done() |
| 209 | |
| 210 | Migrate.Version = database.PresentVersion |
| 211 | Migrate.Status = MigrationInProgress |
| 212 | Migrate.ModuleVer = database.PresentVersionMap |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 213 | if err = Migrate.WriteToDb(ctx); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 214 | logger.Errorw(ctx, "DB Write failed for Migration Path", log.Fields{"error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 215 | return |
| 216 | } |
| 217 | }() |
| 218 | // Failure Senario can be Exceptions, incase of panic Update the status as failed |
| 219 | defer func() { |
| 220 | if err := recover(); err != nil { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 221 | logger.Errorw(ctx, "Migration failure due to Exception happened", log.Fields{"reason": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 222 | Migrate.Status = MigrationFailed |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 223 | if err := Migrate.WriteToDb(ctx); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 224 | logger.Errorw(ctx, "DB Write failed for Migration Path", log.Fields{"error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 225 | } |
| 226 | //probe.UpdateDBMigrationStatus(ctx, false) |
| 227 | return |
| 228 | } |
| 229 | }() |
| 230 | // Wait for all the Db data migration to complete |
| 231 | migrationWG.Wait() |
| 232 | //probe.UpdateDBMigrationStatus(ctx, true) |
| 233 | Migrate.Status = MigrationComplete |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 234 | if err := Migrate.WriteToDb(ctx); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 235 | logger.Errorw(ctx, "DB Write failed for Migration Path", log.Fields{"error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 236 | } |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 237 | logger.Infow(ctx, "Migration completed successfully", log.Fields{"Status": Migrate.Status}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | // MigrateDBData to migrate database data |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 241 | func MigrateDBData(cntx context.Context) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 242 | logger.Debug(ctx, "Migrate DB Data") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 243 | var err error |
| 244 | for module, currentVersion := range database.PresentVersionMap { |
| 245 | if currentVersion == database.DBVersionMap[module] { |
| 246 | logger.Infow(ctx, "No Data Migration required for module", log.Fields{"Table": module, "Version": currentVersion}) |
| 247 | continue |
| 248 | } |
| 249 | |
| 250 | if _, ok := migrationMap[module]; ok { |
| 251 | switch module { |
| 252 | case database.DeviceFlowPath, |
| 253 | database.DevicePortPath, |
| 254 | database.DeviceMeterPath, |
| 255 | database.DeviceGroupPath, |
| 256 | database.DeviceFlowHashPath: |
| 257 | err = FetchAndMigrateDeviceDBData(module) |
| 258 | default: |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 259 | err = FetchAndMigrateDBData(cntx, module) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 260 | } |
| 261 | } else { |
| 262 | logger.Infow(ctx, "No Data Migration handling found for module", log.Fields{"Table": module, "Version": currentVersion}) |
| 263 | } |
| 264 | |
| 265 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 266 | return fmt.Errorf("error in data migration for module %s : %w", module, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | return nil |
| 270 | } |
| 271 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 272 | // FetchAndMigrateDeviceDBData fetchs the data from database and migrte the same to latest versions and store ot back ot database |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 273 | func FetchAndMigrateDeviceDBData(module string) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 274 | logger.Errorw(ctx, "Data Migration not implemented for Device DB Data", log.Fields{"Table": module}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 275 | return nil |
| 276 | } |
| 277 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 278 | // FetchAndMigrateDBData fetchs the data from database and migrte the same to latest versions and store ot back ot database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 279 | func FetchAndMigrateDBData(cntx context.Context, module string) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 280 | logger.Debugw(ctx, "Fetch And Migrate DB Data", log.Fields{"Module": module}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 281 | previousPath := database.GetModuleKeypath(module, database.PreviousVersionMap[module]) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 282 | dbPathKeysValueMap, err := db.List(cntx, previousPath) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 283 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 284 | logger.Warnw(ctx, "failed to Fetch the Keys from Redis", log.Fields{"error": err}) |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 285 | // No return required, Data might not be present in DB |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 286 | return nil |
| 287 | } |
| 288 | if len(dbPathKeysValueMap) == 0 { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 289 | logger.Warnw(ctx, "No data present in DB for the path", log.Fields{"dbPath": module}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 290 | return nil |
| 291 | } |
| 292 | |
| 293 | // Fetch each Path from previous version and store to present version after data migration changes |
| 294 | for hash, value := range dbPathKeysValueMap { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 295 | logger.Debugw(ctx, "DB path", log.Fields{"hash": hash}) |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 296 | // convert the value to a specific type based on the dbPath |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 297 | b, ok := value.Value.([]byte) |
| 298 | if !ok { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 299 | return errors.New("Error-in-migration, The value type is not []byt") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 300 | } |
| 301 | |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 302 | presentParams := migrationMap[module](cntx, b) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 303 | logger.Infow(ctx, "Migrated data", log.Fields{"presentParams": presentParams}) |
| 304 | if "" == presentParams { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 305 | return errors.New("Error-in-migration") |
| 306 | } else if ModuleToBeDeleted == presentParams { |
| 307 | return nil |
| 308 | } |
| 309 | presentPath := database.GetKeyPath(module) + hash |
| 310 | logger.Infow(ctx, "Before writing to DB", log.Fields{"presentParams": presentParams}) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 311 | if err := db.Put(cntx, presentPath, presentParams); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 312 | logger.Errorw(ctx, "Update Params failed", log.Fields{"key": presentPath, "presentparams": presentParams}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 313 | return err |
| 314 | } |
| 315 | } |
| 316 | return nil |
| 317 | } |
| 318 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 319 | // MigrateServices modifyies the old data as per current version requirement and updates the database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 320 | func MigrateServices(cntx context.Context, data []byte) string { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 321 | logger.Debug(ctx, "Migrate Services") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 322 | var vs VoltService |
| 323 | var updatedData, updatedData1 []byte |
| 324 | var vsmap map[string]interface{} |
| 325 | var err1 error |
| 326 | |
| 327 | err := json.Unmarshal(data, &vsmap) |
| 328 | if err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 329 | logger.Warnw(ctx, "Unmarshal of VPV failed", log.Fields{"error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 330 | return "" |
| 331 | } |
| 332 | // changes to handle change in data type of MacLearning parameter |
| 333 | if updatedData1, err1 = json.Marshal(&vsmap); err1 != nil { |
| 334 | logger.Warnw(ctx, "Marshal of Service failed", log.Fields{"Error": err1.Error()}) |
| 335 | return "" |
| 336 | } |
| 337 | |
| 338 | if err2 := json.Unmarshal(updatedData1, &vs); err != nil { |
| 339 | logger.Warnw(ctx, "Unmarshal-failed", log.Fields{"err": err2}) |
| 340 | return "" |
| 341 | } |
| 342 | |
| 343 | if vsmap["MacLearning"] == true { |
| 344 | vs.MacLearning = Learn |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 345 | } |
| 346 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 347 | // Migration |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 348 | vs.PendingFlows = make(map[string]bool) |
| 349 | vs.AssociatedFlows = make(map[string]bool) |
| 350 | vs.DeleteInProgress = false |
| 351 | vs.PonPort = 0xFF |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 352 | if updatedData, err = vs.JSONMarshal(); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 353 | logger.Warnw(ctx, "Marshal of Service failed", log.Fields{"Error": err.Error()}) |
| 354 | return "" |
| 355 | } |
| 356 | logger.Infow(ctx, "Service Migrated", log.Fields{"Service": vs.Name, "PresentVersion": database.PresentVersionMap[database.ServicePath]}) |
| 357 | return string(updatedData) |
| 358 | } |
| 359 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 360 | // MigrateDevices modifyies the old data as per current version requirement and updates the database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 361 | func MigrateDevices(cntx context.Context, data []byte) string { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 362 | logger.Error(ctx, "Data Migration not implemented for Devices") |
| 363 | return "" |
| 364 | } |
| 365 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 366 | // MigrateDevicePorts modifyies the old data as per current version requirement and updates the database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 367 | func MigrateDevicePorts(cntx context.Context, data []byte) string { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 368 | logger.Error(ctx, "Data Migration not implemented for Ports") |
| 369 | return "" |
| 370 | } |
| 371 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 372 | // MigrateDeviceFlows modifyies the old data as per current version requirement and updates the database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 373 | func MigrateDeviceFlows(cntx context.Context, data []byte) string { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 374 | logger.Error(ctx, "Data Migration not implemented for Flows") |
| 375 | return "" |
| 376 | } |
| 377 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 378 | // MigrateDeviceGroups modifyies the old data as per current version requirement and updates the database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 379 | func MigrateDeviceGroups(cntx context.Context, data []byte) string { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 380 | logger.Error(ctx, "Data Migration not implemented for Groups") |
| 381 | return "" |
| 382 | } |
| 383 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 384 | // MigrateDeviceMeters modifyies the old data as per current version requirement and updates the database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 385 | func MigrateDeviceMeters(cntx context.Context, data []byte) string { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 386 | logger.Error(ctx, "Data Migration not implemented for Meters") |
| 387 | return "" |
| 388 | } |
| 389 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 390 | // MigrateDeviceFlowHash modifyies the old data as per current version requirement and updates the database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 391 | func MigrateDeviceFlowHash(cntx context.Context, data []byte) string { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 392 | logger.Error(ctx, "Data Migration not implemented for FlowHash") |
| 393 | return "" |
| 394 | } |
| 395 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 396 | // MigrateVnets modifyies the old data as per current version requirement and updates the database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 397 | func MigrateVnets(cntx context.Context, data []byte) string { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 398 | logger.Debug(ctx, "Migrate Vnets") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 399 | var vnet VoltVnet |
| 400 | var updatedData []byte |
| 401 | |
| 402 | err := json.Unmarshal(data, &vnet) |
| 403 | if err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 404 | logger.Warnw(ctx, "Unmarshal of VNET failed", log.Fields{"error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 405 | return "" |
| 406 | } |
| 407 | |
| 408 | if vnet.SVlanTpid == 0 { |
| 409 | vnet.SVlanTpid = layers.EthernetTypeDot1Q |
| 410 | } |
| 411 | // MacLeanring parameter was not stored in vnets in 2.7 release. |
| 412 | if vnet.DhcpRelay || vnet.ArpLearning { |
| 413 | vnet.MacLearning = Learn |
| 414 | } else if !vnet.DhcpRelay && !vnet.ArpLearning { |
| 415 | vnet.MacLearning = MacLearningNone |
| 416 | } |
| 417 | vnet.PendingDeleteFlow = make(map[string]map[string]bool) |
| 418 | vnet.DeleteInProgress = false |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 419 | if updatedData, err = vnet.JSONMarshal(); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 420 | logger.Warnw(ctx, "Marshal of Vnet failed", log.Fields{"Error": err.Error()}) |
| 421 | return "" |
| 422 | } |
| 423 | logger.Infow(ctx, "Vnet Migrated", log.Fields{"Vnet Name": vnet.Name, "PresentVersion": database.PresentVersionMap[database.VnetPath]}) |
| 424 | return string(updatedData) |
| 425 | } |
| 426 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 427 | // MigrateVpvs modifyies the old data as per current version requirement and updates the database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 428 | func MigrateVpvs(cntx context.Context, data []byte) string { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 429 | logger.Debug(ctx, "Migrate Vpvs") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 430 | var vpv VoltPortVnet |
| 431 | var updatedData, updatedData1 []byte |
| 432 | var vpvmap map[string]interface{} |
| 433 | var err1 error |
| 434 | var usFlowsApplied, dsFlowsApplied bool |
| 435 | |
| 436 | err := json.Unmarshal(data, &vpvmap) |
| 437 | if err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 438 | logger.Warnw(ctx, "Unmarshal of VPV failed", log.Fields{"error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 439 | return "" |
| 440 | } |
| 441 | // changes to handle change in data type of MacLearning parameter |
| 442 | if updatedData1, err1 = json.Marshal(&vpvmap); err1 != nil { |
| 443 | logger.Warnw(ctx, "Marshal of Service failed", log.Fields{"Error": err1.Error()}) |
| 444 | return "" |
| 445 | } |
| 446 | |
| 447 | if err2 := json.Unmarshal(updatedData1, &vpv); err != nil { |
| 448 | logger.Warnw(ctx, "Unmarshal-failed", log.Fields{"err": err2}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | if vpvmap["MacLearning"] == true { |
| 452 | vpv.MacLearning = Learn |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 453 | } |
| 454 | if vpvmap["UsFlowsApplied"] == true { |
| 455 | usFlowsApplied = true |
| 456 | } |
| 457 | |
| 458 | if vpvmap["DsFlowsApplied"] == true { |
| 459 | dsFlowsApplied = true |
| 460 | } |
| 461 | |
| 462 | if usFlowsApplied && dsFlowsApplied { |
| 463 | vpv.FlowsApplied = true |
| 464 | } |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 465 | // Migration |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 466 | if vpv.SVlanTpid == 0 { |
| 467 | vpv.SVlanTpid = layers.EthernetTypeDot1Q |
| 468 | } |
| 469 | vpv.VnetName = VnetKey(vpv.SVlan, vpv.CVlan, vpv.UniVlan) |
| 470 | vpv.PendingDeleteFlow = make(map[string]bool) |
| 471 | vpv.PonPort = 0xFF |
| 472 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 473 | if updatedData, err = vpv.JSONMarshal(); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 474 | logger.Warnw(ctx, "Marshal of VPV failed", log.Fields{"Error": err.Error()}) |
| 475 | return "" |
| 476 | } |
| 477 | logger.Infow(ctx, "VPV Migrated", log.Fields{"Device": vpv.Device, "port": vpv.Port, "SVlan": vpv.SVlan, |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 478 | "CVlan": vpv.CVlan, "UniVlan": vpv.UniVlan, "PresentVersion": database.PresentVersionMap[database.VpvPath]}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 479 | return string(updatedData) |
| 480 | } |
| 481 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 482 | // MigrateMvlans modifyies the old data as per current version requirement and updates the database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 483 | func MigrateMvlans(cntx context.Context, data []byte) string { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 484 | logger.Debug(ctx, "Migrate Mvlans") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 485 | var mvp MvlanProfile |
| 486 | var updatedData []byte |
| 487 | |
| 488 | err := json.Unmarshal(data, &mvp) |
| 489 | if err != nil { |
| 490 | logger.Warn(ctx, "Unmarshal of VPV failed") |
| 491 | return "" |
| 492 | } |
| 493 | // Mvlan Migration |
| 494 | mvp.IgmpServVersion = make(map[string]*uint8) |
| 495 | for srNo := range mvp.DevicesList { |
| 496 | var servVersion uint8 |
| 497 | mvp.IgmpServVersion[srNo] = &servVersion |
| 498 | } |
| 499 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 500 | if updatedData, err = mvp.JSONMarshal(); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 501 | logger.Warnw(ctx, "Marshal of Mvlan Profile failed", log.Fields{"Error": err.Error()}) |
| 502 | return "" |
| 503 | } |
| 504 | logger.Infow(ctx, "Mvlan Profile Migrated", log.Fields{"MvlanProfileName": mvp.Name, "PresentVersion": database.PresentVersionMap[database.MvlanPath]}) |
| 505 | return string(updatedData) |
| 506 | } |
| 507 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 508 | // MigrateMeters modifyies the old data as per current version requirement and updates the database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 509 | func MigrateMeters(cntx context.Context, data []byte) string { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 510 | logger.Error(ctx, "Data Migration not implemented for Meters") |
| 511 | return "" |
| 512 | } |
| 513 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 514 | // MigrateIgmpConfs modifyies the old data as per current version requirement and updates the database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 515 | func MigrateIgmpConfs(cntx context.Context, data []byte) string { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 516 | logger.Debug(ctx, "Migrate IgmpConfs") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 517 | var igmpProfile IgmpProfile |
| 518 | |
| 519 | err := json.Unmarshal(data, &igmpProfile) |
| 520 | if err != nil { |
| 521 | logger.Warn(ctx, "Unmarshal of IGMP failed") |
| 522 | return "" |
| 523 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 524 | if err := igmpProfile.WriteToDb(cntx); err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 525 | logger.Warnw(ctx, "Igmp profile Write to DB failed", log.Fields{"profileID": igmpProfile.ProfileID}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | logger.Infow(ctx, "Igmp Conf Migrated", log.Fields{"Profile": igmpProfile, "PresentVersion": database.PresentVersionMap[database.VpvPath]}) |
| 529 | return ModuleToBeDeleted |
| 530 | } |
| 531 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 532 | // MigrateIgmpGroups modifyies the old data as per current version requirement and updates the database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 533 | func MigrateIgmpGroups(cntx context.Context, data []byte) string { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 534 | logger.Error(ctx, "Data Migration not implemented for IGMP Groups") |
| 535 | return "" |
| 536 | } |
| 537 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 538 | // MigrateIgmpDevices modifyies the old data as per current version requirement and updates the database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 539 | func MigrateIgmpDevices(cntx context.Context, data []byte) string { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 540 | logger.Error(ctx, "Data Migration not implemented for IGMP Device") |
| 541 | return "" |
| 542 | } |
| 543 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 544 | // MigrateIgmpChannels modifyies the old data as per current version requirement and updates the database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 545 | func MigrateIgmpChannels(cntx context.Context, data []byte) string { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 546 | logger.Error(ctx, "Data Migration not implemented for IGMP Channels") |
| 547 | return "" |
| 548 | } |
| 549 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 550 | // MigrateIgmpPorts modifyies the old data as per current version requirement and updates the database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 551 | func MigrateIgmpPorts(cntx context.Context, data []byte) string { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 552 | logger.Error(ctx, "Data Migration not implemented for IGMP Ports") |
| 553 | return "" |
| 554 | } |
| 555 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 556 | // MigrateIgmpProfs modifyies the old data as per current version requirement and updates the database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 557 | func MigrateIgmpProfs(cntx context.Context, data []byte) string { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 558 | logger.Error(ctx, "Data Migration not implemented for IGMP Profs") |
| 559 | return "" |
| 560 | } |
| 561 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 562 | // MigrateMcastConfs modifyies the old data as per current version requirement and updates the database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 563 | func MigrateMcastConfs(cntx context.Context, data []byte) string { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 564 | logger.Error(ctx, "Data Migration not implemented for Mcast Confs") |
| 565 | return "" |
| 566 | } |
| 567 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 568 | // MigrateLogLevels modifyies the old data as per current version requirement and updates the database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 569 | func MigrateLogLevels(cntx context.Context, data []byte) string { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 570 | logger.Error(ctx, "Data Migration not implemented for Log Levels") |
| 571 | return "" |
| 572 | } |
| 573 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 574 | // MigrateHealth modifyies the old data as per current version requirement and updates the database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 575 | func MigrateHealth(cntx context.Context, data []byte) string { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 576 | logger.Error(ctx, "Data Migration not implemented for Health") |
| 577 | return "" |
| 578 | } |
| 579 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 580 | // MigratePonCounters modifyies the old data as per current version requirement and updates the database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 581 | func MigratePonCounters(cntx context.Context, data []byte) string { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 582 | logger.Error(ctx, "Data Migration not implemented for Pon Counters") |
| 583 | return "" |
| 584 | } |
| 585 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 586 | // MigrateChannelCounters modifyies the old data as per current version requirement and updates the database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 587 | func MigrateChannelCounters(cntx context.Context, data []byte) string { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 588 | logger.Error(ctx, "Data Migration not implemented for Channel Counters") |
| 589 | return "" |
| 590 | } |
| 591 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 592 | // MigrateServiceCounters modifyies the old data as per current version requirement and updates the database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 593 | func MigrateServiceCounters(cntx context.Context, data []byte) string { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 594 | logger.Error(ctx, "Data Migration not implemented for Service Counters") |
| 595 | return "" |
| 596 | } |
| 597 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 598 | // MigrateNbDevices modifyies the old data as per current version requirement and updates the database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 599 | func MigrateNbDevices(cntx context.Context, data []byte) string { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 600 | logger.Error(ctx, "Data Migration not implemented for NB Devices") |
| 601 | return "" |
| 602 | } |
| 603 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 604 | // MigrateFlowHash modifyies the old data as per current version requirement and updates the database |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 605 | func MigrateFlowHash(data []byte) string { |
| 606 | logger.Error(ctx, "Data Migration not implemented for FLow Hash") |
| 607 | return "" |
| 608 | } |
| 609 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 610 | // DeleteDbPathKeys Deleted the paths from DB |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 611 | func DeleteDbPathKeys(cntx context.Context, keyPath string) error { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 612 | logger.Debugw(ctx, "Deleting paths for version", log.Fields{"Path": keyPath}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 613 | |
| 614 | // Delete all the keys |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 615 | err := db.DeleteAll(cntx, keyPath) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 616 | if err != nil && err.Error() != common.ErrEntryNotFound.Error() { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 617 | logger.Errorw(ctx, "Delete Key failed", log.Fields{"error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 618 | return err |
| 619 | } |
| 620 | return nil |
| 621 | } |