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. |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 14 | */ |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 15 | // This implementation of database assumes that it is working for |
| 16 | // Open ONU adapter. Thus, it assumes some base path for all the |
| 17 | // database operations. For all database operations, the key passed is |
| 18 | // added to the database base path. |
| 19 | |
| 20 | package database |
| 21 | |
| 22 | import "fmt" |
| 23 | |
| 24 | const ( |
| 25 | // PresentVersion represnts the Present version |
| 26 | // Modify this as we give Major version releases |
| 27 | PresentVersion = "v1" |
| 28 | // PreviousVersion represnts the Previous version |
| 29 | PreviousVersion = "v1" |
| 30 | ) |
| 31 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 32 | // These are present path where different database elements are store in database |
| 33 | // In case any of these paths change, update the present and previous version |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 34 | const ( |
| 35 | BasePath string = "service/vgc/%s/" |
| 36 | ServicePath string = "services/" |
| 37 | DevicePath string = "devices/%s/" |
| 38 | DevicePortPath string = DevicePath + "ports/" |
| 39 | DeviceFlowPath string = DevicePath + "flows/" |
| 40 | DeviceGroupPath string = DevicePath + "groups/" |
| 41 | DeviceMeterPath string = DevicePath + "meters/" |
| 42 | VnetPath string = "vnets/" |
| 43 | VpvPath string = "vpvs/" |
| 44 | MvlanPath string = "mvlans/" |
| 45 | MeterPath string = "meters/" |
| 46 | IgmpConfPath string = "igmp/conf/" |
| 47 | IgmpGroupPath string = "igmp/groups/" |
| 48 | IgmpDevicePath string = "igmp/devices/" |
| 49 | IgmpChannelPath string = "igmp/channels/" |
| 50 | IgmpPortPath string = "igmp/ports/" |
| 51 | IgmpProfPath string = "igmp/prof/" |
| 52 | McastConfigPath string = "igmp/mcastconfig/" |
| 53 | MigrationInfoPath string = "data/migration/" |
| 54 | LogLevelPath string = "log-level/" |
| 55 | HealthPath string = "health/" |
| 56 | PonCounterPath string = "pon-counter/" |
| 57 | OltIgmpCounterPath string = "olt-igmp-counter/" |
| 58 | ChannelCounterPath string = "channel-counter/" |
| 59 | ServiceCounterPath string = "service-counter/" |
| 60 | NbDevicePath string = "nb-device/" |
| 61 | DeviceFlowHashPath string = DevicePath + "flowhash" |
| 62 | PortAlarmProfilePath string = "port-alarm-profile/" |
| 63 | PortAlarmDataPath string = DevicePortPath + "portalarmdata/" |
| 64 | SubAlarmDataPath string = DevicePath + "sub-alarm-data/" |
| 65 | ServicesMigrateReqPath string = DevicePath + "migrateServicesReq/" |
Tinoj Joseph | 4ead4e0 | 2023-01-30 03:12:44 +0530 | [diff] [blame] | 66 | OltFlowServicePath string = "olt-flow-service/" |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 67 | DeviceConfigPath string = "device-config/" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 68 | ) |
| 69 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 70 | // PresentVersionMap - map of present version for all database tables |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 71 | var PresentVersionMap = map[string]string{ |
| 72 | ServicePath: "v3", |
| 73 | DevicePath: "v1", |
| 74 | DevicePortPath: "v1", |
| 75 | DeviceFlowPath: "v1", |
| 76 | DeviceGroupPath: "v1", |
| 77 | DeviceMeterPath: "v1", |
| 78 | VnetPath: "v3", |
| 79 | VpvPath: "v3", |
| 80 | MvlanPath: "v3", |
| 81 | MeterPath: "v1", |
| 82 | IgmpConfPath: "v2", |
| 83 | IgmpGroupPath: "v1", |
| 84 | IgmpDevicePath: "v1", |
| 85 | IgmpChannelPath: "v1", |
| 86 | IgmpPortPath: "v1", |
| 87 | IgmpProfPath: "v1", |
| 88 | McastConfigPath: "v1", |
| 89 | MigrationInfoPath: "v1", |
| 90 | LogLevelPath: "v1", |
| 91 | HealthPath: "v1", |
| 92 | PonCounterPath: "v1", |
| 93 | OltIgmpCounterPath: "v1", |
| 94 | ChannelCounterPath: "v1", |
| 95 | ServiceCounterPath: "v1", |
| 96 | NbDevicePath: "v1", |
| 97 | DeviceFlowHashPath: "v1", |
| 98 | PortAlarmProfilePath: "v1", |
| 99 | PortAlarmDataPath: "v1", |
| 100 | SubAlarmDataPath: "v1", |
| 101 | ServicesMigrateReqPath: "v1", |
Tinoj Joseph | 4ead4e0 | 2023-01-30 03:12:44 +0530 | [diff] [blame] | 102 | OltFlowServicePath: "v1", |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 103 | DeviceConfigPath: "v1", |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 104 | } |
| 105 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 106 | // PreviousVersionMap - map of previous version for all database tables |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 107 | var PreviousVersionMap = map[string]string{ |
| 108 | ServicePath: "v2", |
| 109 | DevicePath: "v1", |
| 110 | DevicePortPath: "v1", |
| 111 | DeviceFlowPath: "v1", |
| 112 | DeviceGroupPath: "v1", |
| 113 | DeviceMeterPath: "v1", |
| 114 | VnetPath: "v2", |
| 115 | VpvPath: "v2", |
| 116 | MvlanPath: "v2", |
| 117 | MeterPath: "v1", |
| 118 | IgmpConfPath: "v1", |
| 119 | IgmpGroupPath: "v1", |
| 120 | IgmpDevicePath: "v1", |
| 121 | IgmpChannelPath: "v1", |
| 122 | IgmpPortPath: "v1", |
| 123 | IgmpProfPath: "v1", |
| 124 | McastConfigPath: "v1", |
| 125 | MigrationInfoPath: "v1", |
| 126 | LogLevelPath: "v1", |
| 127 | HealthPath: "v1", |
| 128 | PonCounterPath: "v1", |
| 129 | OltIgmpCounterPath: "v1", |
| 130 | ChannelCounterPath: "v1", |
| 131 | ServiceCounterPath: "v1", |
| 132 | NbDevicePath: "v1", |
| 133 | DeviceFlowHashPath: "v1", |
| 134 | PortAlarmProfilePath: "v1", |
| 135 | PortAlarmDataPath: "v1", |
| 136 | SubAlarmDataPath: "v1", |
| 137 | ServicesMigrateReqPath: "v1", |
Tinoj Joseph | 4ead4e0 | 2023-01-30 03:12:44 +0530 | [diff] [blame] | 138 | OltFlowServicePath: "v1", |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 139 | DeviceConfigPath: "v1", |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 140 | } |
| 141 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 142 | // DBVersionMap - Version of tables present in DB |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 143 | var DBVersionMap = PreviousVersionMap |
| 144 | |
| 145 | // GetModuleKeypath returns the DB keypath for particular module along with version |
| 146 | func GetModuleKeypath(key, ver string) string { |
| 147 | return fmt.Sprintf(BasePath, ver) + key |
| 148 | } |
| 149 | |
| 150 | // GetKeyPath returns the base path for the given key along with version |
| 151 | func GetKeyPath(key string) string { |
| 152 | return fmt.Sprintf(BasePath, PresentVersionMap[key]) + key |
| 153 | } |