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