blob: b423b58afd96f519971c852a390cd01277b0ab99 [file] [log] [blame]
Naveen Sampath04696f72022-06-13 15:19:14 +05301/*
2* Copyright 2022-present Open Networking Foundation
3* Licensed under the Apache License, Version 2.0 (the "License");
4* you may not use this file except in compliance with the License.
5* You may obtain a copy of the License at
6*
7* http://www.apache.org/licenses/LICENSE-2.0
8*
9* Unless required by applicable law or agreed to in writing, software
10* distributed under the License is distributed on an "AS IS" BASIS,
11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12* See the License for the specific language governing permissions and
13* limitations under the License.
14 */
15
16package application
17
18import (
19 "context"
20 "encoding/json"
21 "errors"
22 "voltha-go-controller/internal/pkg/types"
23 "sync"
24
25 "github.com/google/gopacket/layers"
26
27 "voltha-go-controller/database"
Tinoj Joseph1d108322022-07-13 10:07:39 +053028 "voltha-go-controller/log"
Naveen Sampath04696f72022-06-13 15:19:14 +053029)
30
31const (
32 //MigrationComplete Represents the Migration Complete
33 MigrationComplete = "Completed"
34 //MigrationInProgress Represents the Migration Inprogress
35 MigrationInProgress = "InProgress"
36 //MigrationFailed Represents the Migration Failed
37 MigrationFailed = "Failed"
38 // StatusNone for no operations
39 StatusNone = "NONE"
40 //ModuleToBeDeleted - module where old version is deleted
41 ModuleToBeDeleted = "ModuleToBeDeleted"
42)
43
44//DataMigration represents the Verison and Status info for Major Version Upgrade.
45type DataMigration struct {
46 Version string
47 Status string
48 ModuleVer map[string]string // eg. "service": "v1"
49}
50
Tinoj Joseph07cc5372022-07-18 22:53:51 +053051type paramsMigrationFunc func(context.Context, []byte) string
Naveen Sampath04696f72022-06-13 15:19:14 +053052
53//map to store conversion functions
54var 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 Joseph07cc5372022-07-18 22:53:51 +053082func (md *DataMigration) WriteToDb(cntx context.Context) error {
Naveen Sampath04696f72022-06-13 15:19:14 +053083 b, err := json.Marshal(md)
84 if err != nil {
85 return err
86 }
Tinoj Joseph07cc5372022-07-18 22:53:51 +053087 if err1 := db.PutMigrationInfo(cntx, string(b)); err1 != nil {
Naveen Sampath04696f72022-06-13 15:19:14 +053088 return err1
89 }
90 return nil
91}
92
93// DelFromDb delete a meter profile from DB
Tinoj Joseph07cc5372022-07-18 22:53:51 +053094func (md *DataMigration) DelFromDb(cntx context.Context) {
95 if err := db.DelMigrationInfo(cntx); err != nil {
Naveen Sampath04696f72022-06-13 15:19:14 +053096 logger.Warnw(ctx, "DelMigrationInfo Failed", log.Fields{"Error": err})
97 }
98}
99
100// GetMigrationInfo to get data migration info
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530101func GetMigrationInfo(cntx context.Context, dmInfo *DataMigration) error {
Naveen Sampath04696f72022-06-13 15:19:14 +0530102 var migrationInfo string
103 var err error
104 if db == nil {
105 db = database.GetDatabase()
106 }
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530107 if migrationInfo, err = db.GetMigrationInfo(cntx); err != nil {
Naveen Sampath04696f72022-06-13 15:19:14 +0530108 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
122func CheckIfMigrationRequired(ctx context.Context) bool {
123 Migrate := new(DataMigration)
124 var NoDataInDB bool
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530125 err := GetMigrationInfo(ctx, Migrate)
Tinoj Joseph1d108322022-07-13 10:07:39 +0530126 logger.Debugw(ctx, "Migration data", log.Fields{"DataMigration": Migrate})
Naveen Sampath04696f72022-06-13 15:19:14 +0530127 // No DB entry represents N verison Bring Up for the First time
128 if err != nil {
129 NoDataInDB = true
130 logger.Error(ctx, "Failed to read the Migration Data from DB ")
131 }
132 // Covers N verison bringup and Reboot Senarios
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 Joseph07cc5372022-07-18 22:53:51 +0530138 if err := Migrate.WriteToDb(ctx); err != nil {
Tinoj Joseph1d108322022-07-13 10:07:39 +0530139 logger.Errorw(ctx, "DB Write failed for Migration Path", log.Fields{"error": err})
Naveen Sampath04696f72022-06-13 15:19:14 +0530140 }
141 //MigrateProbestatus has to be Updated to Complete when No Migration is Required
Tinoj Joseph1d108322022-07-13 10:07:39 +0530142 logger.Debugw(ctx, "Migration Probe Status", log.Fields{"Migration Probe": Migrate.Status})
Naveen Sampath04696f72022-06-13 15:19:14 +0530143 //probe.UpdateDBMigrationStatus(ctx, true)
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 Joseph1d108322022-07-13 10:07:39 +0530176 logger.Debugw(ctx, "Migration Probe Status", log.Fields{"Migration Probe": Migrate.Status})
Naveen Sampath04696f72022-06-13 15:19:14 +0530177 //probe.UpdateDBMigrationStatus(ctx, true)
178 return false
179}
180
181// InitiateDataMigration Migrates the DB data
182// depending on the bool value returned by CheckIfMigrationDone
183func InitiateDataMigration(ctx context.Context) {
184 var err error
185 Migrate := new(DataMigration)
186 var migrationWG sync.WaitGroup
187
188 //Keeping it outside to avoid race condition where the
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 Joseph07cc5372022-07-18 22:53:51 +0530194 err = MigrateDBData(ctx)
Naveen Sampath04696f72022-06-13 15:19:14 +0530195 if err != nil {
Tinoj Joseph1d108322022-07-13 10:07:39 +0530196 logger.Errorw(ctx, "Failed to Migrate the Data", log.Fields{"error": err})
Naveen Sampath04696f72022-06-13 15:19:14 +0530197 Migrate.Status = MigrationFailed
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530198 if err := Migrate.WriteToDb(ctx); err != nil {
Tinoj Joseph1d108322022-07-13 10:07:39 +0530199 logger.Errorw(ctx, "DB Write failed to Migration Path", log.Fields{"error": err})
Naveen Sampath04696f72022-06-13 15:19:14 +0530200 }
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 Joseph07cc5372022-07-18 22:53:51 +0530208 if err = Migrate.WriteToDb(ctx); err != nil {
Tinoj Joseph1d108322022-07-13 10:07:39 +0530209 logger.Errorw(ctx, "DB Write failed for Migration Path", log.Fields{"error": err})
Naveen Sampath04696f72022-06-13 15:19:14 +0530210 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 {
Tinoj Joseph1d108322022-07-13 10:07:39 +0530216 logger.Errorw(ctx, "Migration failure due to Exception happend", log.Fields{"reason": err})
Naveen Sampath04696f72022-06-13 15:19:14 +0530217 Migrate.Status = MigrationFailed
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530218 if err := Migrate.WriteToDb(ctx); err != nil {
Tinoj Joseph1d108322022-07-13 10:07:39 +0530219 logger.Errorw(ctx, "DB Write failed for Migration Path", log.Fields{"error": err})
Naveen Sampath04696f72022-06-13 15:19:14 +0530220 }
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 Joseph07cc5372022-07-18 22:53:51 +0530229 if err := Migrate.WriteToDb(ctx); err != nil {
Tinoj Joseph1d108322022-07-13 10:07:39 +0530230 logger.Errorw(ctx, "DB Write failed for Migration Path", log.Fields{"error": err})
Naveen Sampath04696f72022-06-13 15:19:14 +0530231 }
Tinoj Joseph1d108322022-07-13 10:07:39 +0530232 logger.Infow(ctx, "Migration completed successfully", log.Fields{"Status": Migrate.Status})
Naveen Sampath04696f72022-06-13 15:19:14 +0530233}
234
235// MigrateDBData to migrate database data
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530236func MigrateDBData(cntx context.Context) error {
Naveen Sampath04696f72022-06-13 15:19:14 +0530237
238 var err error
239 for module, currentVersion := range database.PresentVersionMap {
240 if currentVersion == database.DBVersionMap[module] {
241 logger.Infow(ctx, "No Data Migration required for module", log.Fields{"Table": module, "Version": currentVersion})
242 continue
243 }
244
245 if _, ok := migrationMap[module]; ok {
246 switch module {
247 case database.DeviceFlowPath,
248 database.DevicePortPath,
249 database.DeviceMeterPath,
250 database.DeviceGroupPath,
251 database.DeviceFlowHashPath:
252 err = FetchAndMigrateDeviceDBData(module)
253 default:
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530254 err = FetchAndMigrateDBData(cntx, module)
Naveen Sampath04696f72022-06-13 15:19:14 +0530255 }
256 } else {
257 logger.Infow(ctx, "No Data Migration handling found for module", log.Fields{"Table": module, "Version": currentVersion})
258 }
259
260 if err != nil {
261 logger.Errorw(ctx, "Error in data migration", log.Fields{"Module": module})
262 return err
263 }
264 }
265 return nil
266}
267
268//FetchAndMigrateDeviceDBData fetchs the data from database and migrte the same to latest versions and store ot back ot database
269func FetchAndMigrateDeviceDBData(module string) error {
270 logger.Error(ctx, "Data Migration not implemented for Device DB Data")
271 return nil
272}
273
274//FetchAndMigrateDBData fetchs the data from database and migrte the same to latest versions and store ot back ot database
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530275func FetchAndMigrateDBData(cntx context.Context, module string) error {
Naveen Sampath04696f72022-06-13 15:19:14 +0530276
277 previousPath := database.GetModuleKeypath(module, database.PreviousVersionMap[module])
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530278 dbPathKeysValueMap, err := db.List(cntx, previousPath)
Naveen Sampath04696f72022-06-13 15:19:14 +0530279 if err != nil {
Tinoj Joseph1d108322022-07-13 10:07:39 +0530280 logger.Errorw(ctx, "failed to Fetch the Keys from Redis", log.Fields{"error": err})
Naveen Sampath04696f72022-06-13 15:19:14 +0530281 //No return required, Data might not be present in DB
282 return nil
283 }
284 if len(dbPathKeysValueMap) == 0 {
Tinoj Joseph1d108322022-07-13 10:07:39 +0530285 logger.Debugw(ctx, "No data present in DB for the path", log.Fields{"dbPath": module})
Naveen Sampath04696f72022-06-13 15:19:14 +0530286 return nil
287 }
288
289 // Fetch each Path from previous version and store to present version after data migration changes
290 for hash, value := range dbPathKeysValueMap {
Tinoj Joseph1d108322022-07-13 10:07:39 +0530291 logger.Debugw(ctx, "DB path", log.Fields{"hash": hash})
Naveen Sampath04696f72022-06-13 15:19:14 +0530292 //convert the value to a specific type based on the dbPath
293 b, ok := value.Value.([]byte)
294 if !ok {
295 logger.Error(ctx, "The value type is not []byte")
296 return errors.New("Error-in-migration")
297 }
298
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530299 presentParams := migrationMap[module](cntx, b)
Naveen Sampath04696f72022-06-13 15:19:14 +0530300 logger.Infow(ctx, "Migrated data", log.Fields{"presentParams": presentParams})
301 if "" == presentParams {
302 logger.Error(ctx, "Error in migrating data\n")
303 return errors.New("Error-in-migration")
304 } else if ModuleToBeDeleted == presentParams {
305 return nil
306 }
307 presentPath := database.GetKeyPath(module) + hash
308 logger.Infow(ctx, "Before writing to DB", log.Fields{"presentParams": presentParams})
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530309 if err := db.Put(cntx, presentPath, presentParams); err != nil {
Tinoj Joseph1d108322022-07-13 10:07:39 +0530310 logger.Errorw(ctx, "Update Params failed", log.Fields{"key": presentPath, "presentparams": presentParams})
Naveen Sampath04696f72022-06-13 15:19:14 +0530311 return err
312 }
313 }
314 return nil
315}
316
317//MigrateServices modifyies the old data as per current version requirement and updates the database
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530318func MigrateServices(cntx context.Context, data []byte) string {
Naveen Sampath04696f72022-06-13 15:19:14 +0530319 var vs VoltService
320 var updatedData, updatedData1 []byte
321 var vsmap map[string]interface{}
322 var err1 error
323
324 err := json.Unmarshal(data, &vsmap)
325 if err != nil {
Tinoj Joseph1d108322022-07-13 10:07:39 +0530326 logger.Warnw(ctx, "Unmarshal of VPV failed", log.Fields{"error": err})
Naveen Sampath04696f72022-06-13 15:19:14 +0530327 return ""
328 }
329 // changes to handle change in data type of MacLearning parameter
330 if updatedData1, err1 = json.Marshal(&vsmap); err1 != nil {
331 logger.Warnw(ctx, "Marshal of Service failed", log.Fields{"Error": err1.Error()})
332 return ""
333 }
334
335 if err2 := json.Unmarshal(updatedData1, &vs); err != nil {
336 logger.Warnw(ctx, "Unmarshal-failed", log.Fields{"err": err2})
337 return ""
338 }
339
340 if vsmap["MacLearning"] == true {
341 vs.MacLearning = Learn
342
343 }
344
345 //Migration
346 vs.PendingFlows = make(map[string]bool)
347 vs.AssociatedFlows = make(map[string]bool)
348 vs.DeleteInProgress = false
349 vs.PonPort = 0xFF
Tinoj Josephc2ccd6b2022-07-19 04:32:15 +0530350 if updatedData, err = vs.JsonMarshal(); err != nil {
Naveen Sampath04696f72022-06-13 15:19:14 +0530351 logger.Warnw(ctx, "Marshal of Service failed", log.Fields{"Error": err.Error()})
352 return ""
353 }
354 logger.Infow(ctx, "Service Migrated", log.Fields{"Service": vs.Name, "PresentVersion": database.PresentVersionMap[database.ServicePath]})
355 return string(updatedData)
356}
357
358//MigrateDevices modifyies the old data as per current version requirement and updates the database
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530359func MigrateDevices(cntx context.Context, data []byte) string {
Naveen Sampath04696f72022-06-13 15:19:14 +0530360 logger.Error(ctx, "Data Migration not implemented for Devices")
361 return ""
362}
363
364//MigrateDevicePorts modifyies the old data as per current version requirement and updates the database
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530365func MigrateDevicePorts(cntx context.Context, data []byte) string {
Naveen Sampath04696f72022-06-13 15:19:14 +0530366 logger.Error(ctx, "Data Migration not implemented for Ports")
367 return ""
368}
369
370//MigrateDeviceFlows modifyies the old data as per current version requirement and updates the database
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530371func MigrateDeviceFlows(cntx context.Context, data []byte) string {
Naveen Sampath04696f72022-06-13 15:19:14 +0530372 logger.Error(ctx, "Data Migration not implemented for Flows")
373 return ""
374}
375
376//MigrateDeviceGroups modifyies the old data as per current version requirement and updates the database
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530377func MigrateDeviceGroups(cntx context.Context, data []byte) string {
Naveen Sampath04696f72022-06-13 15:19:14 +0530378 logger.Error(ctx, "Data Migration not implemented for Groups")
379 return ""
380}
381
382//MigrateDeviceMeters modifyies the old data as per current version requirement and updates the database
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530383func MigrateDeviceMeters(cntx context.Context, data []byte) string {
Naveen Sampath04696f72022-06-13 15:19:14 +0530384 logger.Error(ctx, "Data Migration not implemented for Meters")
385 return ""
386}
387
388//MigrateDeviceFlowHash modifyies the old data as per current version requirement and updates the database
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530389func MigrateDeviceFlowHash(cntx context.Context, data []byte) string {
Naveen Sampath04696f72022-06-13 15:19:14 +0530390 logger.Error(ctx, "Data Migration not implemented for FlowHash")
391 return ""
392}
393
394//MigrateVnets modifyies the old data as per current version requirement and updates the database
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530395func MigrateVnets(cntx context.Context, data []byte) string {
Naveen Sampath04696f72022-06-13 15:19:14 +0530396
397 var vnet VoltVnet
398 var updatedData []byte
399
400 err := json.Unmarshal(data, &vnet)
401 if err != nil {
Tinoj Joseph1d108322022-07-13 10:07:39 +0530402 logger.Warnw(ctx, "Unmarshal of VNET failed", log.Fields{"error": err})
Naveen Sampath04696f72022-06-13 15:19:14 +0530403 return ""
404 }
405
406 if vnet.SVlanTpid == 0 {
407 vnet.SVlanTpid = layers.EthernetTypeDot1Q
408 }
409 // MacLeanring parameter was not stored in vnets in 2.7 release.
410 if vnet.DhcpRelay || vnet.ArpLearning {
411 vnet.MacLearning = Learn
412 } else if !vnet.DhcpRelay && !vnet.ArpLearning {
413 vnet.MacLearning = MacLearningNone
414 }
415 vnet.PendingDeleteFlow = make(map[string]map[string]bool)
416 vnet.DeleteInProgress = false
Tinoj Josephc2ccd6b2022-07-19 04:32:15 +0530417 if updatedData, err = vnet.JsonMarshal(); err != nil {
Naveen Sampath04696f72022-06-13 15:19:14 +0530418 logger.Warnw(ctx, "Marshal of Vnet failed", log.Fields{"Error": err.Error()})
419 return ""
420 }
421 logger.Infow(ctx, "Vnet Migrated", log.Fields{"Vnet Name": vnet.Name, "PresentVersion": database.PresentVersionMap[database.VnetPath]})
422 return string(updatedData)
423}
424
425//MigrateVpvs modifyies the old data as per current version requirement and updates the database
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530426func MigrateVpvs(cntx context.Context, data []byte) string {
Naveen Sampath04696f72022-06-13 15:19:14 +0530427 var vpv VoltPortVnet
428 var updatedData, updatedData1 []byte
429 var vpvmap map[string]interface{}
430 var err1 error
431 var usFlowsApplied, dsFlowsApplied bool
432
433 err := json.Unmarshal(data, &vpvmap)
434 if err != nil {
Tinoj Joseph1d108322022-07-13 10:07:39 +0530435 logger.Warnw(ctx, "Unmarshal of VPV failed", log.Fields{"error": err})
Naveen Sampath04696f72022-06-13 15:19:14 +0530436 return ""
437 }
438 // changes to handle change in data type of MacLearning parameter
439 if updatedData1, err1 = json.Marshal(&vpvmap); err1 != nil {
440 logger.Warnw(ctx, "Marshal of Service failed", log.Fields{"Error": err1.Error()})
441 return ""
442 }
443
444 if err2 := json.Unmarshal(updatedData1, &vpv); err != nil {
445 logger.Warnw(ctx, "Unmarshal-failed", log.Fields{"err": err2})
446
447 }
448
449 if vpvmap["MacLearning"] == true {
450 vpv.MacLearning = Learn
451
452 }
453 if vpvmap["UsFlowsApplied"] == true {
454 usFlowsApplied = true
455 }
456
457 if vpvmap["DsFlowsApplied"] == true {
458 dsFlowsApplied = true
459 }
460
461 if usFlowsApplied && dsFlowsApplied {
462 vpv.FlowsApplied = true
463 }
464 //Migration
465 if vpv.SVlanTpid == 0 {
466 vpv.SVlanTpid = layers.EthernetTypeDot1Q
467 }
468 vpv.VnetName = VnetKey(vpv.SVlan, vpv.CVlan, vpv.UniVlan)
469 vpv.PendingDeleteFlow = make(map[string]bool)
470 vpv.PonPort = 0xFF
471
Tinoj Josephc2ccd6b2022-07-19 04:32:15 +0530472 if updatedData, err = vpv.JsonMarshal(); err != nil {
Naveen Sampath04696f72022-06-13 15:19:14 +0530473 logger.Warnw(ctx, "Marshal of VPV failed", log.Fields{"Error": err.Error()})
474 return ""
475 }
476 logger.Infow(ctx, "VPV Migrated", log.Fields{"Device": vpv.Device, "port": vpv.Port, "SVlan": vpv.SVlan,
477 "CVlan": vpv.CVlan, "UniVlan": vpv.UniVlan, "PresentVersion": database.PresentVersionMap[database.VpvPath]})
478 return string(updatedData)
479}
480
481//MigrateMvlans modifyies the old data as per current version requirement and updates the database
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530482func MigrateMvlans(cntx context.Context, data []byte) string {
Naveen Sampath04696f72022-06-13 15:19:14 +0530483 var mvp MvlanProfile
484 var updatedData []byte
485
486 err := json.Unmarshal(data, &mvp)
487 if err != nil {
488 logger.Warn(ctx, "Unmarshal of VPV failed")
489 return ""
490 }
491 // Mvlan Migration
492 mvp.IgmpServVersion = make(map[string]*uint8)
493 for srNo := range mvp.DevicesList {
494 var servVersion uint8
495 mvp.IgmpServVersion[srNo] = &servVersion
496 }
497
Tinoj Josephc2ccd6b2022-07-19 04:32:15 +0530498 if updatedData, err = mvp.JsonMarshal(); err != nil {
Naveen Sampath04696f72022-06-13 15:19:14 +0530499 logger.Warnw(ctx, "Marshal of Mvlan Profile failed", log.Fields{"Error": err.Error()})
500 return ""
501 }
502 logger.Infow(ctx, "Mvlan Profile Migrated", log.Fields{"MvlanProfileName": mvp.Name, "PresentVersion": database.PresentVersionMap[database.MvlanPath]})
503 return string(updatedData)
504}
505
506//MigrateMeters modifyies the old data as per current version requirement and updates the database
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530507func MigrateMeters(cntx context.Context, data []byte) string {
Naveen Sampath04696f72022-06-13 15:19:14 +0530508 logger.Error(ctx, "Data Migration not implemented for Meters")
509 return ""
510}
511
512//MigrateIgmpConfs modifyies the old data as per current version requirement and updates the database
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530513func MigrateIgmpConfs(cntx context.Context, data []byte) string {
Naveen Sampath04696f72022-06-13 15:19:14 +0530514 var igmpProfile IgmpProfile
515
516 err := json.Unmarshal(data, &igmpProfile)
517 if err != nil {
518 logger.Warn(ctx, "Unmarshal of IGMP failed")
519 return ""
520 }
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530521 if err := igmpProfile.WriteToDb(cntx); err != nil {
Naveen Sampath04696f72022-06-13 15:19:14 +0530522 logger.Errorw(ctx, "Igmp profile Write to DB failed", log.Fields{"profileID": igmpProfile.ProfileID})
523 }
524
525 logger.Infow(ctx, "Igmp Conf Migrated", log.Fields{"Profile": igmpProfile, "PresentVersion": database.PresentVersionMap[database.VpvPath]})
526 return ModuleToBeDeleted
527}
528
529//MigrateIgmpGroups modifyies the old data as per current version requirement and updates the database
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530530func MigrateIgmpGroups(cntx context.Context, data []byte) string {
Naveen Sampath04696f72022-06-13 15:19:14 +0530531 logger.Error(ctx, "Data Migration not implemented for IGMP Groups")
532 return ""
533}
534
535//MigrateIgmpDevices modifyies the old data as per current version requirement and updates the database
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530536func MigrateIgmpDevices(cntx context.Context, data []byte) string {
Naveen Sampath04696f72022-06-13 15:19:14 +0530537 logger.Error(ctx, "Data Migration not implemented for IGMP Device")
538 return ""
539}
540
541//MigrateIgmpChannels modifyies the old data as per current version requirement and updates the database
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530542func MigrateIgmpChannels(cntx context.Context, data []byte) string {
Naveen Sampath04696f72022-06-13 15:19:14 +0530543 logger.Error(ctx, "Data Migration not implemented for IGMP Channels")
544 return ""
545}
546
547//MigrateIgmpPorts modifyies the old data as per current version requirement and updates the database
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530548func MigrateIgmpPorts(cntx context.Context, data []byte) string {
Naveen Sampath04696f72022-06-13 15:19:14 +0530549 logger.Error(ctx, "Data Migration not implemented for IGMP Ports")
550 return ""
551}
552
553//MigrateIgmpProfs modifyies the old data as per current version requirement and updates the database
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530554func MigrateIgmpProfs(cntx context.Context, data []byte) string {
Naveen Sampath04696f72022-06-13 15:19:14 +0530555 logger.Error(ctx, "Data Migration not implemented for IGMP Profs")
556 return ""
557}
558
559//MigrateMcastConfs modifyies the old data as per current version requirement and updates the database
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530560func MigrateMcastConfs(cntx context.Context, data []byte) string {
Naveen Sampath04696f72022-06-13 15:19:14 +0530561 logger.Error(ctx, "Data Migration not implemented for Mcast Confs")
562 return ""
563}
564
565//MigrateLogLevels modifyies the old data as per current version requirement and updates the database
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530566func MigrateLogLevels(cntx context.Context, data []byte) string {
Naveen Sampath04696f72022-06-13 15:19:14 +0530567 logger.Error(ctx, "Data Migration not implemented for Log Levels")
568 return ""
569}
570
571//MigrateHealth modifyies the old data as per current version requirement and updates the database
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530572func MigrateHealth(cntx context.Context, data []byte) string {
Naveen Sampath04696f72022-06-13 15:19:14 +0530573 logger.Error(ctx, "Data Migration not implemented for Health")
574 return ""
575}
576
577//MigratePonCounters modifyies the old data as per current version requirement and updates the database
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530578func MigratePonCounters(cntx context.Context, data []byte) string {
Naveen Sampath04696f72022-06-13 15:19:14 +0530579 logger.Error(ctx, "Data Migration not implemented for Pon Counters")
580 return ""
581}
582
583//MigrateChannelCounters modifyies the old data as per current version requirement and updates the database
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530584func MigrateChannelCounters(cntx context.Context, data []byte) string {
Naveen Sampath04696f72022-06-13 15:19:14 +0530585 logger.Error(ctx, "Data Migration not implemented for Channel Counters")
586 return ""
587}
588
589//MigrateServiceCounters modifyies the old data as per current version requirement and updates the database
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530590func MigrateServiceCounters(cntx context.Context, data []byte) string {
Naveen Sampath04696f72022-06-13 15:19:14 +0530591 logger.Error(ctx, "Data Migration not implemented for Service Counters")
592 return ""
593}
594
595//MigrateNbDevices modifyies the old data as per current version requirement and updates the database
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530596func MigrateNbDevices(cntx context.Context, data []byte) string {
Naveen Sampath04696f72022-06-13 15:19:14 +0530597 logger.Error(ctx, "Data Migration not implemented for NB Devices")
598 return ""
599}
600
601//MigrateFlowHash modifyies the old data as per current version requirement and updates the database
602func MigrateFlowHash(data []byte) string {
603 logger.Error(ctx, "Data Migration not implemented for FLow Hash")
604 return ""
605}
606
607//DeleteDbPathKeys Deleted the paths from DB
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530608func DeleteDbPathKeys(cntx context.Context, keyPath string) error {
Tinoj Joseph1d108322022-07-13 10:07:39 +0530609 logger.Debugw(ctx, "Deleting paths for version", log.Fields{"Path": keyPath})
Naveen Sampath04696f72022-06-13 15:19:14 +0530610
611 // Delete all the keys
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530612 err := db.DeleteAll(cntx, keyPath)
Naveen Sampath04696f72022-06-13 15:19:14 +0530613 if err != nil && err.Error() != common.ErrEntryNotFound.Error() {
Tinoj Joseph1d108322022-07-13 10:07:39 +0530614 logger.Errorw(ctx, "Delete Key failed", log.Fields{"error": err})
Naveen Sampath04696f72022-06-13 15:19:14 +0530615 return err
616 }
617 return nil
618}