Commit e47e36f140408f24a56a7012ab46ed926c74f7e5
Committed by
GitHub
Merge pull request #4671 from YevhenBondarenko/feature/ota-package
Feature/ota package
Showing
81 changed files
with
1033 additions
and
1007 deletions
Too many changes to show.
To preserve performance only 81 of 119 files are displayed.
1 | 1 | { |
2 | 2 | "title": "Firmware", |
3 | + "image": null, | |
3 | 4 | "configuration": { |
4 | 5 | "description": "", |
5 | 6 | "widgets": { |
... | ... | @@ -247,7 +248,7 @@ |
247 | 248 | "name": "Edit firmware", |
248 | 249 | "icon": "edit", |
249 | 250 | "type": "customPretty", |
250 | - "customHtml": "<form #editEntityForm=\"ngForm\" [formGroup]=\"editEntityFormGroup\"\n (ngSubmit)=\"save()\" class=\"edit-entity-form\">\n <mat-toolbar fxLayout=\"row\" color=\"primary\">\n <h2>Edit firmware {{entityName}}</h2>\n <span fxFlex></span>\n <button mat-icon-button (click)=\"cancel()\" type=\"button\">\n <mat-icon class=\"material-icons\">close</mat-icon>\n </button>\n </mat-toolbar>\n <mat-progress-bar color=\"warn\" mode=\"indeterminate\" *ngIf=\"isLoading$ | async\">\n </mat-progress-bar>\n <div style=\"height: 4px;\" *ngIf=\"!(isLoading$ | async)\"></div>\n <div *ngIf=\"entity.deviceProfileId\" mat-dialog-content fxLayout=\"column\">\n <tb-firmware-autocomplete\n [useFullEntityId]=\"true\"\n [deviceProfileId]=\"entity.deviceProfileId.id\"\n formControlName=\"firmwareId\">\n </tb-firmware-autocomplete>\n </div>\n <div mat-dialog-actions fxLayout=\"row\" fxLayoutAlign=\"end center\">\n <button mat-button color=\"primary\"\n type=\"button\"\n [disabled]=\"(isLoading$ | async)\"\n (click)=\"cancel()\" cdkFocusInitial>\n Cancel\n </button>\n <button mat-button mat-raised-button color=\"primary\"\n type=\"submit\"\n [disabled]=\"(isLoading$ | async) || editEntityForm.invalid || !editEntityForm.dirty\">\n Save\n </button>\n </div>\n</form>", | |
251 | + "customHtml": "<form #editEntityForm=\"ngForm\" [formGroup]=\"editEntityFormGroup\"\n (ngSubmit)=\"save()\" class=\"edit-entity-form\">\n <mat-toolbar fxLayout=\"row\" color=\"primary\">\n <h2>Edit firmware {{entityName}}</h2>\n <span fxFlex></span>\n <button mat-icon-button (click)=\"cancel()\" type=\"button\">\n <mat-icon class=\"material-icons\">close</mat-icon>\n </button>\n </mat-toolbar>\n <mat-progress-bar color=\"warn\" mode=\"indeterminate\" *ngIf=\"isLoading$ | async\">\n </mat-progress-bar>\n <div style=\"height: 4px;\" *ngIf=\"!(isLoading$ | async)\"></div>\n <div *ngIf=\"entity.deviceProfileId\" mat-dialog-content fxLayout=\"column\">\n <tb-ota-package-autocomplete\n [useFullEntityId]=\"true\"\n [deviceProfileId]=\"entity.deviceProfileId.id\"\n formControlName=\"firmwareId\">\n </tb-ota-package-autocomplete>\n </div>\n <div mat-dialog-actions fxLayout=\"row\" fxLayoutAlign=\"end center\">\n <button mat-button color=\"primary\"\n type=\"button\"\n [disabled]=\"(isLoading$ | async)\"\n (click)=\"cancel()\" cdkFocusInitial>\n Cancel\n </button>\n <button mat-button mat-raised-button color=\"primary\"\n type=\"submit\"\n [disabled]=\"(isLoading$ | async) || editEntityForm.invalid || !editEntityForm.dirty\">\n Save\n </button>\n </div>\n</form>", | |
251 | 252 | "customCss": "", |
252 | 253 | "customFunction": "let $injector = widgetContext.$scope.$injector;\nlet customDialog = $injector.get(widgetContext.servicesMap.get('customDialog'));\nlet entityService = $injector.get(widgetContext.servicesMap.get('entityService'));\nlet deviceService = $injector.get(widgetContext.servicesMap.get('deviceService'));\n\nopenEditEntityDialog();\n\nfunction openEditEntityDialog() {\n customDialog.customDialog(htmlTemplate, EditEntityDialogController).subscribe();\n}\n\nfunction EditEntityDialogController(instance) {\n let vm = instance;\n\n vm.entityName = entityName;\n vm.entity = {};\n\n vm.editEntityFormGroup = vm.fb.group({\n firmwareId: [null]\n });\n\n getEntityInfo();\n\n vm.cancel = function() {\n vm.dialogRef.close(null);\n };\n\n vm.save = function() {\n vm.editEntityFormGroup.markAsPristine();\n saveEntity().subscribe(\n function () {\n // widgetContext.updateAliases();\n vm.dialogRef.close(null);\n }\n );\n };\n\n\n function getEntityInfo() {\n entityService.getEntity(entityId.entityType, entityId.id).subscribe(\n function (data) {\n vm.entity = data;\n vm.editEntityFormGroup.patchValue({\n firmwareId: vm.entity.firmwareId\n }, {emitEvent: false});\n }\n );\n }\n\n function saveEntity() {\n const formValues = vm.editEntityFormGroup.value;\n vm.entity.firmwareId = formValues.firmwareId;\n return deviceService.saveDevice(vm.entity);\n }\n}", |
253 | 254 | "customResources": [], |
... | ... | @@ -257,7 +258,7 @@ |
257 | 258 | "name": "Download firware", |
258 | 259 | "icon": "file_download", |
259 | 260 | "type": "custom", |
260 | - "customFunction": "let $injector = widgetContext.$scope.$injector;\nlet entityService = $injector.get(widgetContext.servicesMap.get('entityService'));\nlet firmwareService = $injector.get(widgetContext.servicesMap.get('firmwareService'));\nlet deviceProfileService = $injector.get(widgetContext.servicesMap.get('deviceProfileService'));\n\ngetDeviceFirmware();\n\nfunction getDeviceFirmware() {\n entityService.getEntity(entityId.entityType, entityId.id).subscribe(\n function (data) {\n if (data.firmwareId !== null) {\n firmwareService.downloadFirmware(data.firmwareId.id).subscribe(); \n } else {\n deviceProfileService.getDeviceProfile(data.deviceProfileId.id).subscribe(\n function (deviceProfile) {\n if (deviceProfile.firmwareId !== null) {\n firmwareService.downloadFirmware(deviceProfile.firmwareId.id).subscribe();\n } else {\n widgetContext.showToast('warn', 'Device ' + entityName +' has not firmware set.', 2000, 'top');\n\n }\n });\n }\n }\n );\n}", | |
261 | + "customFunction": "let $injector = widgetContext.$scope.$injector;\nlet entityService = $injector.get(widgetContext.servicesMap.get('entityService'));\nlet otaPackageService = $injector.get(widgetContext.servicesMap.get('otaPackageService'));\nlet deviceProfileService = $injector.get(widgetContext.servicesMap.get('deviceProfileService'));\n\ngetDeviceFirmware();\n\nfunction getDeviceFirmware() {\n entityService.getEntity(entityId.entityType, entityId.id).subscribe(\n function (data) {\n if (data.firmwareId !== null) {\n otaPackageService.downloadOtaPackage(data.firmwareId.id).subscribe(); \n } else {\n deviceProfileService.getDeviceProfile(data.deviceProfileId.id).subscribe(\n function (deviceProfile) {\n if (deviceProfile.firmwareId !== null) {\n otaPackageService.downloadOtaPackage(deviceProfile.firmwareId.id).subscribe();\n } else {\n widgetContext.showToast('warn', 'Device ' + entityName +' has not firmware set.', 2000, 'top');\n\n }\n });\n }\n }\n );\n}", | |
261 | 262 | "id": "12533058-42f6-e75f-620c-219c48d01ec0" |
262 | 263 | }, |
263 | 264 | { |
... | ... | @@ -1021,7 +1022,7 @@ |
1021 | 1022 | "name": "Edit firmware", |
1022 | 1023 | "icon": "edit", |
1023 | 1024 | "type": "customPretty", |
1024 | - "customHtml": "<form #editEntityForm=\"ngForm\" [formGroup]=\"editEntityFormGroup\"\n (ngSubmit)=\"save()\" class=\"edit-entity-form\">\n <mat-toolbar fxLayout=\"row\" color=\"primary\">\n <h2>Edit firmware {{entityName}}</h2>\n <span fxFlex></span>\n <button mat-icon-button (click)=\"cancel()\" type=\"button\">\n <mat-icon class=\"material-icons\">close</mat-icon>\n </button>\n </mat-toolbar>\n <mat-progress-bar color=\"warn\" mode=\"indeterminate\" *ngIf=\"isLoading$ | async\">\n </mat-progress-bar>\n <div style=\"height: 4px;\" *ngIf=\"!(isLoading$ | async)\"></div>\n <div mat-dialog-content fxLayout=\"column\">\n <tb-firmware-autocomplete\n [useFullEntityId]=\"true\"\n formControlName=\"firmwareId\">\n </tb-firmware-autocomplete>\n </div>\n <div mat-dialog-actions fxLayout=\"row\" fxLayoutAlign=\"end center\">\n <button mat-button color=\"primary\"\n type=\"button\"\n [disabled]=\"(isLoading$ | async)\"\n (click)=\"cancel()\" cdkFocusInitial>\n Cancel\n </button>\n <button mat-button mat-raised-button color=\"primary\"\n type=\"submit\"\n [disabled]=\"(isLoading$ | async) || editEntityForm.invalid || !editEntityForm.dirty\">\n Save\n </button>\n </div>\n</form>", | |
1025 | + "customHtml": "<form #editEntityForm=\"ngForm\" [formGroup]=\"editEntityFormGroup\"\n (ngSubmit)=\"save()\" class=\"edit-entity-form\">\n <mat-toolbar fxLayout=\"row\" color=\"primary\">\n <h2>Edit firmware {{entityName}}</h2>\n <span fxFlex></span>\n <button mat-icon-button (click)=\"cancel()\" type=\"button\">\n <mat-icon class=\"material-icons\">close</mat-icon>\n </button>\n </mat-toolbar>\n <mat-progress-bar color=\"warn\" mode=\"indeterminate\" *ngIf=\"isLoading$ | async\">\n </mat-progress-bar>\n <div style=\"height: 4px;\" *ngIf=\"!(isLoading$ | async)\"></div>\n <div *ngIf=\"entity.deviceProfileId\" mat-dialog-content fxLayout=\"column\">\n <tb-ota-package-autocomplete\n [useFullEntityId]=\"true\"\n [deviceProfileId]=\"entity.deviceProfileId.id\"\n formControlName=\"firmwareId\">\n </tb-ota-package-autocomplete>\n </div>\n <div mat-dialog-actions fxLayout=\"row\" fxLayoutAlign=\"end center\">\n <button mat-button color=\"primary\"\n type=\"button\"\n [disabled]=\"(isLoading$ | async)\"\n (click)=\"cancel()\" cdkFocusInitial>\n Cancel\n </button>\n <button mat-button mat-raised-button color=\"primary\"\n type=\"submit\"\n [disabled]=\"(isLoading$ | async) || editEntityForm.invalid || !editEntityForm.dirty\">\n Save\n </button>\n </div>\n</form>", | |
1025 | 1026 | "customCss": "", |
1026 | 1027 | "customFunction": "let $injector = widgetContext.$scope.$injector;\nlet customDialog = $injector.get(widgetContext.servicesMap.get('customDialog'));\nlet entityService = $injector.get(widgetContext.servicesMap.get('entityService'));\nlet deviceService = $injector.get(widgetContext.servicesMap.get('deviceService'));\n\nopenEditEntityDialog();\n\nfunction openEditEntityDialog() {\n customDialog.customDialog(htmlTemplate, EditEntityDialogController).subscribe();\n}\n\nfunction EditEntityDialogController(instance) {\n let vm = instance;\n\n vm.entityName = entityName;\n vm.entity = {};\n\n vm.editEntityFormGroup = vm.fb.group({\n firmwareId: [null]\n });\n\n getEntityInfo();\n\n vm.cancel = function() {\n vm.dialogRef.close(null);\n };\n\n vm.save = function() {\n vm.editEntityFormGroup.markAsPristine();\n saveEntity().subscribe(\n function () {\n // widgetContext.updateAliases();\n vm.dialogRef.close(null);\n }\n );\n };\n\n\n function getEntityInfo() {\n entityService.getEntity(entityId.entityType, entityId.id).subscribe(\n function (data) {\n vm.entity = data;\n vm.editEntityFormGroup.patchValue({\n firmwareId: vm.entity.firmwareId\n }, {emitEvent: false});\n }\n );\n }\n\n function saveEntity() {\n const formValues = vm.editEntityFormGroup.value;\n vm.entity.firmwareId = formValues.firmwareId;\n return deviceService.saveDevice(vm.entity);\n }\n}", |
1027 | 1028 | "customResources": [], |
... | ... | @@ -1031,7 +1032,7 @@ |
1031 | 1032 | "name": "Download firware", |
1032 | 1033 | "icon": "file_download", |
1033 | 1034 | "type": "custom", |
1034 | - "customFunction": "let $injector = widgetContext.$scope.$injector;\nlet entityService = $injector.get(widgetContext.servicesMap.get('entityService'));\nlet firmwareService = $injector.get(widgetContext.servicesMap.get('firmwareService'));\nlet deviceProfileService = $injector.get(widgetContext.servicesMap.get('deviceProfileService'));\n\ngetDeviceFirmware();\n\nfunction getDeviceFirmware() {\n entityService.getEntity(entityId.entityType, entityId.id).subscribe(\n function (data) {\n if (data.firmwareId !== null) {\n firmwareService.downloadFirmware(data.firmwareId.id).subscribe(); \n } else {\n deviceProfileService.getDeviceProfile(data.deviceProfileId.id).subscribe(\n function (deviceProfile) {\n if (deviceProfile.firmwareId !== null) {\n firmwareService.downloadFirmware(deviceProfile.firmwareId.id).subscribe();\n } else {\n widgetContext.showToast('warn', 'Device ' + entityName +' has not firmware set.', 2000, 'top');\n\n }\n });\n }\n }\n );\n}", | |
1035 | + "customFunction": "let $injector = widgetContext.$scope.$injector;\nlet entityService = $injector.get(widgetContext.servicesMap.get('entityService'));\nlet otaPackageService = $injector.get(widgetContext.servicesMap.get('otaPackageService'));\nlet deviceProfileService = $injector.get(widgetContext.servicesMap.get('deviceProfileService'));\n\ngetDeviceFirmware();\n\nfunction getDeviceFirmware() {\n entityService.getEntity(entityId.entityType, entityId.id).subscribe(\n function (data) {\n if (data.firmwareId !== null) {\n otaPackageService.downloadOtaPackage(data.firmwareId.id).subscribe(); \n } else {\n deviceProfileService.getDeviceProfile(data.deviceProfileId.id).subscribe(\n function (deviceProfile) {\n if (deviceProfile.firmwareId !== null) {\n otaPackageService.downloadOtaPackage(deviceProfile.firmwareId.id).subscribe();\n } else {\n widgetContext.showToast('warn', 'Device ' + entityName +' has not firmware set.', 2000, 'top');\n\n }\n });\n }\n }\n );\n}", | |
1035 | 1036 | "id": "12533058-42f6-e75f-620c-219c48d01ec0" |
1036 | 1037 | }, |
1037 | 1038 | { |
... | ... | @@ -1297,7 +1298,7 @@ |
1297 | 1298 | "name": "Edit firmware", |
1298 | 1299 | "icon": "edit", |
1299 | 1300 | "type": "customPretty", |
1300 | - "customHtml": "<form #editEntityForm=\"ngForm\" [formGroup]=\"editEntityFormGroup\"\n (ngSubmit)=\"save()\" class=\"edit-entity-form\">\n <mat-toolbar fxLayout=\"row\" color=\"primary\">\n <h2>Edit firmware {{entityName}}</h2>\n <span fxFlex></span>\n <button mat-icon-button (click)=\"cancel()\" type=\"button\">\n <mat-icon class=\"material-icons\">close</mat-icon>\n </button>\n </mat-toolbar>\n <mat-progress-bar color=\"warn\" mode=\"indeterminate\" *ngIf=\"isLoading$ | async\">\n </mat-progress-bar>\n <div style=\"height: 4px;\" *ngIf=\"!(isLoading$ | async)\"></div>\n <div mat-dialog-content fxLayout=\"column\">\n <tb-firmware-autocomplete\n [useFullEntityId]=\"true\"\n formControlName=\"firmwareId\">\n </tb-firmware-autocomplete>\n </div>\n <div mat-dialog-actions fxLayout=\"row\" fxLayoutAlign=\"end center\">\n <button mat-button color=\"primary\"\n type=\"button\"\n [disabled]=\"(isLoading$ | async)\"\n (click)=\"cancel()\" cdkFocusInitial>\n Cancel\n </button>\n <button mat-button mat-raised-button color=\"primary\"\n type=\"submit\"\n [disabled]=\"(isLoading$ | async) || editEntityForm.invalid || !editEntityForm.dirty\">\n Save\n </button>\n </div>\n</form>", | |
1301 | + "customHtml": "<form #editEntityForm=\"ngForm\" [formGroup]=\"editEntityFormGroup\"\n (ngSubmit)=\"save()\" class=\"edit-entity-form\">\n <mat-toolbar fxLayout=\"row\" color=\"primary\">\n <h2>Edit firmware {{entityName}}</h2>\n <span fxFlex></span>\n <button mat-icon-button (click)=\"cancel()\" type=\"button\">\n <mat-icon class=\"material-icons\">close</mat-icon>\n </button>\n </mat-toolbar>\n <mat-progress-bar color=\"warn\" mode=\"indeterminate\" *ngIf=\"isLoading$ | async\">\n </mat-progress-bar>\n <div style=\"height: 4px;\" *ngIf=\"!(isLoading$ | async)\"></div>\n <div *ngIf=\"entity.deviceProfileId\" mat-dialog-content fxLayout=\"column\">\n <tb-ota-package-autocomplete\n [useFullEntityId]=\"true\"\n [deviceProfileId]=\"entity.deviceProfileId.id\"\n formControlName=\"firmwareId\">\n </tb-ota-package-autocomplete>\n </div>\n <div mat-dialog-actions fxLayout=\"row\" fxLayoutAlign=\"end center\">\n <button mat-button color=\"primary\"\n type=\"button\"\n [disabled]=\"(isLoading$ | async)\"\n (click)=\"cancel()\" cdkFocusInitial>\n Cancel\n </button>\n <button mat-button mat-raised-button color=\"primary\"\n type=\"submit\"\n [disabled]=\"(isLoading$ | async) || editEntityForm.invalid || !editEntityForm.dirty\">\n Save\n </button>\n </div>\n</form>", | |
1301 | 1302 | "customCss": "", |
1302 | 1303 | "customFunction": "let $injector = widgetContext.$scope.$injector;\nlet customDialog = $injector.get(widgetContext.servicesMap.get('customDialog'));\nlet entityService = $injector.get(widgetContext.servicesMap.get('entityService'));\nlet deviceService = $injector.get(widgetContext.servicesMap.get('deviceService'));\n\nopenEditEntityDialog();\n\nfunction openEditEntityDialog() {\n customDialog.customDialog(htmlTemplate, EditEntityDialogController).subscribe();\n}\n\nfunction EditEntityDialogController(instance) {\n let vm = instance;\n\n vm.entityName = entityName;\n vm.entity = {};\n\n vm.editEntityFormGroup = vm.fb.group({\n firmwareId: [null]\n });\n\n getEntityInfo();\n\n vm.cancel = function() {\n vm.dialogRef.close(null);\n };\n\n vm.save = function() {\n vm.editEntityFormGroup.markAsPristine();\n saveEntity().subscribe(\n function () {\n // widgetContext.updateAliases();\n vm.dialogRef.close(null);\n }\n );\n };\n\n\n function getEntityInfo() {\n entityService.getEntity(entityId.entityType, entityId.id).subscribe(\n function (data) {\n vm.entity = data;\n vm.editEntityFormGroup.patchValue({\n firmwareId: vm.entity.firmwareId\n }, {emitEvent: false});\n }\n );\n }\n\n function saveEntity() {\n const formValues = vm.editEntityFormGroup.value;\n vm.entity.firmwareId = formValues.firmwareId;\n return deviceService.saveDevice(vm.entity);\n }\n}", |
1303 | 1304 | "customResources": [], |
... | ... | @@ -1307,7 +1308,7 @@ |
1307 | 1308 | "name": "Download firware", |
1308 | 1309 | "icon": "file_download", |
1309 | 1310 | "type": "custom", |
1310 | - "customFunction": "let $injector = widgetContext.$scope.$injector;\nlet entityService = $injector.get(widgetContext.servicesMap.get('entityService'));\nlet firmwareService = $injector.get(widgetContext.servicesMap.get('firmwareService'));\nlet deviceProfileService = $injector.get(widgetContext.servicesMap.get('deviceProfileService'));\n\ngetDeviceFirmware();\n\nfunction getDeviceFirmware() {\n entityService.getEntity(entityId.entityType, entityId.id).subscribe(\n function (data) {\n if (data.firmwareId !== null) {\n firmwareService.downloadFirmware(data.firmwareId.id).subscribe(); \n } else {\n deviceProfileService.getDeviceProfile(data.deviceProfileId.id).subscribe(\n function (deviceProfile) {\n if (deviceProfile.firmwareId !== null) {\n firmwareService.downloadFirmware(deviceProfile.firmwareId.id).subscribe();\n } else {\n widgetContext.showToast('warn', 'Device ' + entityName +' has not firmware set.', 2000, 'top');\n\n }\n });\n }\n }\n );\n}", | |
1311 | + "customFunction": "let $injector = widgetContext.$scope.$injector;\nlet entityService = $injector.get(widgetContext.servicesMap.get('entityService'));\nlet otaPackageService = $injector.get(widgetContext.servicesMap.get('otaPackageService'));\nlet deviceProfileService = $injector.get(widgetContext.servicesMap.get('deviceProfileService'));\n\ngetDeviceFirmware();\n\nfunction getDeviceFirmware() {\n entityService.getEntity(entityId.entityType, entityId.id).subscribe(\n function (data) {\n if (data.firmwareId !== null) {\n otaPackageService.downloadOtaPackage(data.firmwareId.id).subscribe(); \n } else {\n deviceProfileService.getDeviceProfile(data.deviceProfileId.id).subscribe(\n function (deviceProfile) {\n if (deviceProfile.firmwareId !== null) {\n otaPackageService.downloadOtaPackage(deviceProfile.firmwareId.id).subscribe();\n } else {\n widgetContext.showToast('warn', 'Device ' + entityName +' has not firmware set.', 2000, 'top');\n\n }\n });\n }\n }\n );\n}", | |
1311 | 1312 | "id": "12533058-42f6-e75f-620c-219c48d01ec0" |
1312 | 1313 | }, |
1313 | 1314 | { |
... | ... | @@ -1573,7 +1574,7 @@ |
1573 | 1574 | "name": "Edit firmware", |
1574 | 1575 | "icon": "edit", |
1575 | 1576 | "type": "customPretty", |
1576 | - "customHtml": "<form #editEntityForm=\"ngForm\" [formGroup]=\"editEntityFormGroup\"\n (ngSubmit)=\"save()\" class=\"edit-entity-form\">\n <mat-toolbar fxLayout=\"row\" color=\"primary\">\n <h2>Edit firmware {{entityName}}</h2>\n <span fxFlex></span>\n <button mat-icon-button (click)=\"cancel()\" type=\"button\">\n <mat-icon class=\"material-icons\">close</mat-icon>\n </button>\n </mat-toolbar>\n <mat-progress-bar color=\"warn\" mode=\"indeterminate\" *ngIf=\"isLoading$ | async\">\n </mat-progress-bar>\n <div style=\"height: 4px;\" *ngIf=\"!(isLoading$ | async)\"></div>\n <div mat-dialog-content fxLayout=\"column\">\n <tb-firmware-autocomplete\n [useFullEntityId]=\"true\"\n formControlName=\"firmwareId\">\n </tb-firmware-autocomplete>\n </div>\n <div mat-dialog-actions fxLayout=\"row\" fxLayoutAlign=\"end center\">\n <button mat-button color=\"primary\"\n type=\"button\"\n [disabled]=\"(isLoading$ | async)\"\n (click)=\"cancel()\" cdkFocusInitial>\n Cancel\n </button>\n <button mat-button mat-raised-button color=\"primary\"\n type=\"submit\"\n [disabled]=\"(isLoading$ | async) || editEntityForm.invalid || !editEntityForm.dirty\">\n Save\n </button>\n </div>\n</form>", | |
1577 | + "customHtml": "<form #editEntityForm=\"ngForm\" [formGroup]=\"editEntityFormGroup\"\n (ngSubmit)=\"save()\" class=\"edit-entity-form\">\n <mat-toolbar fxLayout=\"row\" color=\"primary\">\n <h2>Edit firmware {{entityName}}</h2>\n <span fxFlex></span>\n <button mat-icon-button (click)=\"cancel()\" type=\"button\">\n <mat-icon class=\"material-icons\">close</mat-icon>\n </button>\n </mat-toolbar>\n <mat-progress-bar color=\"warn\" mode=\"indeterminate\" *ngIf=\"isLoading$ | async\">\n </mat-progress-bar>\n <div style=\"height: 4px;\" *ngIf=\"!(isLoading$ | async)\"></div>\n <div *ngIf=\"entity.deviceProfileId\" mat-dialog-content fxLayout=\"column\">\n <tb-ota-package-autocomplete\n [useFullEntityId]=\"true\"\n [deviceProfileId]=\"entity.deviceProfileId.id\"\n formControlName=\"firmwareId\">\n </tb-ota-package-autocomplete>\n </div>\n <div mat-dialog-actions fxLayout=\"row\" fxLayoutAlign=\"end center\">\n <button mat-button color=\"primary\"\n type=\"button\"\n [disabled]=\"(isLoading$ | async)\"\n (click)=\"cancel()\" cdkFocusInitial>\n Cancel\n </button>\n <button mat-button mat-raised-button color=\"primary\"\n type=\"submit\"\n [disabled]=\"(isLoading$ | async) || editEntityForm.invalid || !editEntityForm.dirty\">\n Save\n </button>\n </div>\n</form>", | |
1577 | 1578 | "customCss": "", |
1578 | 1579 | "customFunction": "let $injector = widgetContext.$scope.$injector;\nlet customDialog = $injector.get(widgetContext.servicesMap.get('customDialog'));\nlet entityService = $injector.get(widgetContext.servicesMap.get('entityService'));\nlet deviceService = $injector.get(widgetContext.servicesMap.get('deviceService'));\n\nopenEditEntityDialog();\n\nfunction openEditEntityDialog() {\n customDialog.customDialog(htmlTemplate, EditEntityDialogController).subscribe();\n}\n\nfunction EditEntityDialogController(instance) {\n let vm = instance;\n\n vm.entityName = entityName;\n vm.entity = {};\n\n vm.editEntityFormGroup = vm.fb.group({\n firmwareId: [null]\n });\n\n getEntityInfo();\n\n vm.cancel = function() {\n vm.dialogRef.close(null);\n };\n\n vm.save = function() {\n vm.editEntityFormGroup.markAsPristine();\n saveEntity().subscribe(\n function () {\n // widgetContext.updateAliases();\n vm.dialogRef.close(null);\n }\n );\n };\n\n\n function getEntityInfo() {\n entityService.getEntity(entityId.entityType, entityId.id).subscribe(\n function (data) {\n vm.entity = data;\n vm.editEntityFormGroup.patchValue({\n firmwareId: vm.entity.firmwareId\n }, {emitEvent: false});\n }\n );\n }\n\n function saveEntity() {\n const formValues = vm.editEntityFormGroup.value;\n vm.entity.firmwareId = formValues.firmwareId;\n return deviceService.saveDevice(vm.entity);\n }\n}", |
1579 | 1580 | "customResources": [], |
... | ... | @@ -1583,7 +1584,7 @@ |
1583 | 1584 | "name": "Download firware", |
1584 | 1585 | "icon": "file_download", |
1585 | 1586 | "type": "custom", |
1586 | - "customFunction": "let $injector = widgetContext.$scope.$injector;\nlet entityService = $injector.get(widgetContext.servicesMap.get('entityService'));\nlet firmwareService = $injector.get(widgetContext.servicesMap.get('firmwareService'));\nlet deviceProfileService = $injector.get(widgetContext.servicesMap.get('deviceProfileService'));\n\ngetDeviceFirmware();\n\nfunction getDeviceFirmware() {\n entityService.getEntity(entityId.entityType, entityId.id).subscribe(\n function (data) {\n if (data.firmwareId !== null) {\n firmwareService.downloadFirmware(data.firmwareId.id).subscribe(); \n } else {\n deviceProfileService.getDeviceProfile(data.deviceProfileId.id).subscribe(\n function (deviceProfile) {\n if (deviceProfile.firmwareId !== null) {\n firmwareService.downloadFirmware(deviceProfile.firmwareId.id).subscribe();\n } else {\n widgetContext.showToast('warn', 'Device ' + entityName +' has not firmware set.', 2000, 'top');\n\n }\n });\n }\n }\n );\n}", | |
1587 | + "customFunction": "let $injector = widgetContext.$scope.$injector;\nlet entityService = $injector.get(widgetContext.servicesMap.get('entityService'));\nlet otaPackageService = $injector.get(widgetContext.servicesMap.get('otaPackageService'));\nlet deviceProfileService = $injector.get(widgetContext.servicesMap.get('deviceProfileService'));\n\ngetDeviceFirmware();\n\nfunction getDeviceFirmware() {\n entityService.getEntity(entityId.entityType, entityId.id).subscribe(\n function (data) {\n if (data.firmwareId !== null) {\n otaPackageService.downloadOtaPackage(data.firmwareId.id).subscribe(); \n } else {\n deviceProfileService.getDeviceProfile(data.deviceProfileId.id).subscribe(\n function (deviceProfile) {\n if (deviceProfile.firmwareId !== null) {\n otaPackageService.downloadOtaPackage(deviceProfile.firmwareId.id).subscribe();\n } else {\n widgetContext.showToast('warn', 'Device ' + entityName +' has not firmware set.', 2000, 'top');\n\n }\n });\n }\n }\n );\n}", | |
1587 | 1588 | "id": "12533058-42f6-e75f-620c-219c48d01ec0" |
1588 | 1589 | }, |
1589 | 1590 | { |
... | ... | @@ -1849,7 +1850,7 @@ |
1849 | 1850 | "name": "Edit firmware", |
1850 | 1851 | "icon": "edit", |
1851 | 1852 | "type": "customPretty", |
1852 | - "customHtml": "<form #editEntityForm=\"ngForm\" [formGroup]=\"editEntityFormGroup\"\n (ngSubmit)=\"save()\" class=\"edit-entity-form\">\n <mat-toolbar fxLayout=\"row\" color=\"primary\">\n <h2>Edit firmware {{entityName}}</h2>\n <span fxFlex></span>\n <button mat-icon-button (click)=\"cancel()\" type=\"button\">\n <mat-icon class=\"material-icons\">close</mat-icon>\n </button>\n </mat-toolbar>\n <mat-progress-bar color=\"warn\" mode=\"indeterminate\" *ngIf=\"isLoading$ | async\">\n </mat-progress-bar>\n <div style=\"height: 4px;\" *ngIf=\"!(isLoading$ | async)\"></div>\n <div mat-dialog-content fxLayout=\"column\">\n <tb-firmware-autocomplete\n [useFullEntityId]=\"true\"\n formControlName=\"firmwareId\">\n </tb-firmware-autocomplete>\n </div>\n <div mat-dialog-actions fxLayout=\"row\" fxLayoutAlign=\"end center\">\n <button mat-button color=\"primary\"\n type=\"button\"\n [disabled]=\"(isLoading$ | async)\"\n (click)=\"cancel()\" cdkFocusInitial>\n Cancel\n </button>\n <button mat-button mat-raised-button color=\"primary\"\n type=\"submit\"\n [disabled]=\"(isLoading$ | async) || editEntityForm.invalid || !editEntityForm.dirty\">\n Save\n </button>\n </div>\n</form>", | |
1853 | + "customHtml": "<form #editEntityForm=\"ngForm\" [formGroup]=\"editEntityFormGroup\"\n (ngSubmit)=\"save()\" class=\"edit-entity-form\">\n <mat-toolbar fxLayout=\"row\" color=\"primary\">\n <h2>Edit firmware {{entityName}}</h2>\n <span fxFlex></span>\n <button mat-icon-button (click)=\"cancel()\" type=\"button\">\n <mat-icon class=\"material-icons\">close</mat-icon>\n </button>\n </mat-toolbar>\n <mat-progress-bar color=\"warn\" mode=\"indeterminate\" *ngIf=\"isLoading$ | async\">\n </mat-progress-bar>\n <div style=\"height: 4px;\" *ngIf=\"!(isLoading$ | async)\"></div>\n <div *ngIf=\"entity.deviceProfileId\" mat-dialog-content fxLayout=\"column\">\n <tb-ota-package-autocomplete\n [useFullEntityId]=\"true\"\n [deviceProfileId]=\"entity.deviceProfileId.id\"\n formControlName=\"firmwareId\">\n </tb-ota-package-autocomplete>\n </div>\n <div mat-dialog-actions fxLayout=\"row\" fxLayoutAlign=\"end center\">\n <button mat-button color=\"primary\"\n type=\"button\"\n [disabled]=\"(isLoading$ | async)\"\n (click)=\"cancel()\" cdkFocusInitial>\n Cancel\n </button>\n <button mat-button mat-raised-button color=\"primary\"\n type=\"submit\"\n [disabled]=\"(isLoading$ | async) || editEntityForm.invalid || !editEntityForm.dirty\">\n Save\n </button>\n </div>\n</form>", | |
1853 | 1854 | "customCss": "", |
1854 | 1855 | "customFunction": "let $injector = widgetContext.$scope.$injector;\nlet customDialog = $injector.get(widgetContext.servicesMap.get('customDialog'));\nlet entityService = $injector.get(widgetContext.servicesMap.get('entityService'));\nlet deviceService = $injector.get(widgetContext.servicesMap.get('deviceService'));\n\nopenEditEntityDialog();\n\nfunction openEditEntityDialog() {\n customDialog.customDialog(htmlTemplate, EditEntityDialogController).subscribe();\n}\n\nfunction EditEntityDialogController(instance) {\n let vm = instance;\n\n vm.entityName = entityName;\n vm.entity = {};\n\n vm.editEntityFormGroup = vm.fb.group({\n firmwareId: [null]\n });\n\n getEntityInfo();\n\n vm.cancel = function() {\n vm.dialogRef.close(null);\n };\n\n vm.save = function() {\n vm.editEntityFormGroup.markAsPristine();\n saveEntity().subscribe(\n function () {\n // widgetContext.updateAliases();\n vm.dialogRef.close(null);\n }\n );\n };\n\n\n function getEntityInfo() {\n entityService.getEntity(entityId.entityType, entityId.id).subscribe(\n function (data) {\n vm.entity = data;\n vm.editEntityFormGroup.patchValue({\n firmwareId: vm.entity.firmwareId\n }, {emitEvent: false});\n }\n );\n }\n\n function saveEntity() {\n const formValues = vm.editEntityFormGroup.value;\n vm.entity.firmwareId = formValues.firmwareId;\n return deviceService.saveDevice(vm.entity);\n }\n}", |
1855 | 1856 | "customResources": [], |
... | ... | @@ -1859,7 +1860,7 @@ |
1859 | 1860 | "name": "Download firware", |
1860 | 1861 | "icon": "file_download", |
1861 | 1862 | "type": "custom", |
1862 | - "customFunction": "let $injector = widgetContext.$scope.$injector;\nlet entityService = $injector.get(widgetContext.servicesMap.get('entityService'));\nlet firmwareService = $injector.get(widgetContext.servicesMap.get('firmwareService'));\nlet deviceProfileService = $injector.get(widgetContext.servicesMap.get('deviceProfileService'));\n\ngetDeviceFirmware();\n\nfunction getDeviceFirmware() {\n entityService.getEntity(entityId.entityType, entityId.id).subscribe(\n function (data) {\n if (data.firmwareId !== null) {\n firmwareService.downloadFirmware(data.firmwareId.id).subscribe(); \n } else {\n deviceProfileService.getDeviceProfile(data.deviceProfileId.id).subscribe(\n function (deviceProfile) {\n if (deviceProfile.firmwareId !== null) {\n firmwareService.downloadFirmware(deviceProfile.firmwareId.id).subscribe();\n } else {\n widgetContext.showToast('warn', 'Device ' + entityName +' has not firmware set.', 2000, 'top');\n\n }\n });\n }\n }\n );\n}", | |
1863 | + "customFunction": "let $injector = widgetContext.$scope.$injector;\nlet entityService = $injector.get(widgetContext.servicesMap.get('entityService'));\nlet otaPackageService = $injector.get(widgetContext.servicesMap.get('otaPackageService'));\nlet deviceProfileService = $injector.get(widgetContext.servicesMap.get('deviceProfileService'));\n\ngetDeviceFirmware();\n\nfunction getDeviceFirmware() {\n entityService.getEntity(entityId.entityType, entityId.id).subscribe(\n function (data) {\n if (data.firmwareId !== null) {\n otaPackageService.downloadOtaPackage(data.firmwareId.id).subscribe(); \n } else {\n deviceProfileService.getDeviceProfile(data.deviceProfileId.id).subscribe(\n function (deviceProfile) {\n if (deviceProfile.firmwareId !== null) {\n otaPackageService.downloadOtaPackage(deviceProfile.firmwareId.id).subscribe();\n } else {\n widgetContext.showToast('warn', 'Device ' + entityName +' has not firmware set.', 2000, 'top');\n\n }\n });\n }\n }\n );\n}", | |
1863 | 1864 | "id": "12533058-42f6-e75f-620c-219c48d01ec0" |
1864 | 1865 | }, |
1865 | 1866 | { | ... | ... |
... | ... | @@ -59,8 +59,8 @@ CREATE TABLE IF NOT EXISTS resource ( |
59 | 59 | CONSTRAINT resource_unq_key UNIQUE (tenant_id, resource_type, resource_key) |
60 | 60 | ); |
61 | 61 | |
62 | -CREATE TABLE IF NOT EXISTS firmware ( | |
63 | - id uuid NOT NULL CONSTRAINT firmware_pkey PRIMARY KEY, | |
62 | +CREATE TABLE IF NOT EXISTS ota_package ( | |
63 | + id uuid NOT NULL CONSTRAINT ota_package_pkey PRIMARY KEY, | |
64 | 64 | created_time bigint NOT NULL, |
65 | 65 | tenant_id uuid NOT NULL, |
66 | 66 | device_profile_id uuid, |
... | ... | @@ -75,7 +75,7 @@ CREATE TABLE IF NOT EXISTS firmware ( |
75 | 75 | data_size bigint, |
76 | 76 | additional_info varchar, |
77 | 77 | search_text varchar(255), |
78 | - CONSTRAINT firmware_tenant_title_version_unq_key UNIQUE (tenant_id, title, version) | |
78 | + CONSTRAINT ota_package_tenant_title_version_unq_key UNIQUE (tenant_id, title, version) | |
79 | 79 | ); |
80 | 80 | |
81 | 81 | ALTER TABLE dashboard |
... | ... | @@ -101,13 +101,13 @@ DO $$ |
101 | 101 | IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'fk_firmware_device_profile') THEN |
102 | 102 | ALTER TABLE device_profile |
103 | 103 | ADD CONSTRAINT fk_firmware_device_profile |
104 | - FOREIGN KEY (firmware_id) REFERENCES firmware(id); | |
104 | + FOREIGN KEY (firmware_id) REFERENCES ota_package(id); | |
105 | 105 | END IF; |
106 | 106 | |
107 | 107 | IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'fk_software_device_profile') THEN |
108 | 108 | ALTER TABLE device_profile |
109 | 109 | ADD CONSTRAINT fk_software_device_profile |
110 | - FOREIGN KEY (firmware_id) REFERENCES firmware(id); | |
110 | + FOREIGN KEY (firmware_id) REFERENCES ota_package(id); | |
111 | 111 | END IF; |
112 | 112 | |
113 | 113 | IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'fk_default_dashboard_device_profile') THEN |
... | ... | @@ -119,13 +119,13 @@ DO $$ |
119 | 119 | IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'fk_firmware_device') THEN |
120 | 120 | ALTER TABLE device |
121 | 121 | ADD CONSTRAINT fk_firmware_device |
122 | - FOREIGN KEY (firmware_id) REFERENCES firmware(id); | |
122 | + FOREIGN KEY (firmware_id) REFERENCES ota_package(id); | |
123 | 123 | END IF; |
124 | 124 | |
125 | 125 | IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'fk_software_device') THEN |
126 | 126 | ALTER TABLE device |
127 | 127 | ADD CONSTRAINT fk_software_device |
128 | - FOREIGN KEY (firmware_id) REFERENCES firmware(id); | |
128 | + FOREIGN KEY (firmware_id) REFERENCES ota_package(id); | |
129 | 129 | END IF; |
130 | 130 | END; |
131 | 131 | $$; | ... | ... |
... | ... | @@ -39,8 +39,8 @@ import org.thingsboard.server.common.data.EdgeUtils; |
39 | 39 | import org.thingsboard.server.common.data.EntityType; |
40 | 40 | import org.thingsboard.server.common.data.EntityView; |
41 | 41 | import org.thingsboard.server.common.data.EntityViewInfo; |
42 | -import org.thingsboard.server.common.data.Firmware; | |
43 | -import org.thingsboard.server.common.data.FirmwareInfo; | |
42 | +import org.thingsboard.server.common.data.OtaPackage; | |
43 | +import org.thingsboard.server.common.data.OtaPackageInfo; | |
44 | 44 | import org.thingsboard.server.common.data.HasName; |
45 | 45 | import org.thingsboard.server.common.data.HasTenantId; |
46 | 46 | import org.thingsboard.server.common.data.TbResourceInfo; |
... | ... | @@ -70,7 +70,7 @@ import org.thingsboard.server.common.data.id.EdgeId; |
70 | 70 | import org.thingsboard.server.common.data.id.EntityId; |
71 | 71 | import org.thingsboard.server.common.data.id.EntityIdFactory; |
72 | 72 | import org.thingsboard.server.common.data.id.EntityViewId; |
73 | -import org.thingsboard.server.common.data.id.FirmwareId; | |
73 | +import org.thingsboard.server.common.data.id.OtaPackageId; | |
74 | 74 | import org.thingsboard.server.common.data.id.TbResourceId; |
75 | 75 | import org.thingsboard.server.common.data.id.RuleChainId; |
76 | 76 | import org.thingsboard.server.common.data.id.RuleNodeId; |
... | ... | @@ -110,7 +110,7 @@ import org.thingsboard.server.dao.edge.EdgeService; |
110 | 110 | import org.thingsboard.server.dao.entityview.EntityViewService; |
111 | 111 | import org.thingsboard.server.dao.exception.DataValidationException; |
112 | 112 | import org.thingsboard.server.dao.exception.IncorrectParameterException; |
113 | -import org.thingsboard.server.dao.firmware.FirmwareService; | |
113 | +import org.thingsboard.server.dao.ota.OtaPackageService; | |
114 | 114 | import org.thingsboard.server.dao.model.ModelConstants; |
115 | 115 | import org.thingsboard.server.dao.oauth2.OAuth2ConfigTemplateService; |
116 | 116 | import org.thingsboard.server.dao.oauth2.OAuth2Service; |
... | ... | @@ -128,7 +128,7 @@ import org.thingsboard.server.queue.discovery.PartitionService; |
128 | 128 | import org.thingsboard.server.queue.provider.TbQueueProducerProvider; |
129 | 129 | import org.thingsboard.server.queue.util.TbCoreComponent; |
130 | 130 | import org.thingsboard.server.service.component.ComponentDiscoveryService; |
131 | -import org.thingsboard.server.service.firmware.FirmwareStateService; | |
131 | +import org.thingsboard.server.service.ota.OtaPackageStateService; | |
132 | 132 | import org.thingsboard.server.service.edge.EdgeNotificationService; |
133 | 133 | import org.thingsboard.server.service.edge.rpc.EdgeGrpcService; |
134 | 134 | import org.thingsboard.server.service.edge.rpc.init.SyncEdgeService; |
... | ... | @@ -250,10 +250,10 @@ public abstract class BaseController { |
250 | 250 | protected TbResourceService resourceService; |
251 | 251 | |
252 | 252 | @Autowired |
253 | - protected FirmwareService firmwareService; | |
253 | + protected OtaPackageService otaPackageService; | |
254 | 254 | |
255 | 255 | @Autowired |
256 | - protected FirmwareStateService firmwareStateService; | |
256 | + protected OtaPackageStateService otaPackageStateService; | |
257 | 257 | |
258 | 258 | @Autowired |
259 | 259 | protected TbQueueProducerProvider producerProvider; |
... | ... | @@ -511,8 +511,8 @@ public abstract class BaseController { |
511 | 511 | case TB_RESOURCE: |
512 | 512 | checkResourceId(new TbResourceId(entityId.getId()), operation); |
513 | 513 | return; |
514 | - case FIRMWARE: | |
515 | - checkFirmwareId(new FirmwareId(entityId.getId()), operation); | |
514 | + case OTA_PACKAGE: | |
515 | + checkOtaPackageId(new OtaPackageId(entityId.getId()), operation); | |
516 | 516 | return; |
517 | 517 | default: |
518 | 518 | throw new IllegalArgumentException("Unsupported entity type: " + entityId.getEntityType()); |
... | ... | @@ -769,25 +769,25 @@ public abstract class BaseController { |
769 | 769 | } |
770 | 770 | } |
771 | 771 | |
772 | - Firmware checkFirmwareId(FirmwareId firmwareId, Operation operation) throws ThingsboardException { | |
772 | + OtaPackage checkOtaPackageId(OtaPackageId otaPackageId, Operation operation) throws ThingsboardException { | |
773 | 773 | try { |
774 | - validateId(firmwareId, "Incorrect firmwareId " + firmwareId); | |
775 | - Firmware firmware = firmwareService.findFirmwareById(getCurrentUser().getTenantId(), firmwareId); | |
776 | - checkNotNull(firmware); | |
777 | - accessControlService.checkPermission(getCurrentUser(), Resource.FIRMWARE, operation, firmwareId, firmware); | |
778 | - return firmware; | |
774 | + validateId(otaPackageId, "Incorrect otaPackageId " + otaPackageId); | |
775 | + OtaPackage otaPackage = otaPackageService.findOtaPackageById(getCurrentUser().getTenantId(), otaPackageId); | |
776 | + checkNotNull(otaPackage); | |
777 | + accessControlService.checkPermission(getCurrentUser(), Resource.OTA_PACKAGE, operation, otaPackageId, otaPackage); | |
778 | + return otaPackage; | |
779 | 779 | } catch (Exception e) { |
780 | 780 | throw handleException(e, false); |
781 | 781 | } |
782 | 782 | } |
783 | 783 | |
784 | - FirmwareInfo checkFirmwareInfoId(FirmwareId firmwareId, Operation operation) throws ThingsboardException { | |
784 | + OtaPackageInfo checkOtaPackageInfoId(OtaPackageId otaPackageId, Operation operation) throws ThingsboardException { | |
785 | 785 | try { |
786 | - validateId(firmwareId, "Incorrect firmwareId " + firmwareId); | |
787 | - FirmwareInfo firmwareInfo = firmwareService.findFirmwareInfoById(getCurrentUser().getTenantId(), firmwareId); | |
788 | - checkNotNull(firmwareInfo); | |
789 | - accessControlService.checkPermission(getCurrentUser(), Resource.FIRMWARE, operation, firmwareId, firmwareInfo); | |
790 | - return firmwareInfo; | |
786 | + validateId(otaPackageId, "Incorrect otaPackageId " + otaPackageId); | |
787 | + OtaPackageInfo otaPackageIn = otaPackageService.findOtaPackageInfoById(getCurrentUser().getTenantId(), otaPackageId); | |
788 | + checkNotNull(otaPackageIn); | |
789 | + accessControlService.checkPermission(getCurrentUser(), Resource.OTA_PACKAGE, operation, otaPackageId, otaPackageIn); | |
790 | + return otaPackageIn; | |
791 | 791 | } catch (Exception e) { |
792 | 792 | throw handleException(e, false); |
793 | 793 | } | ... | ... |
... | ... | @@ -53,6 +53,7 @@ import org.thingsboard.server.common.data.id.DeviceId; |
53 | 53 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
54 | 54 | import org.thingsboard.server.common.data.id.EdgeId; |
55 | 55 | import org.thingsboard.server.common.data.id.TenantId; |
56 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | |
56 | 57 | import org.thingsboard.server.common.data.page.PageData; |
57 | 58 | import org.thingsboard.server.common.data.page.PageLink; |
58 | 59 | import org.thingsboard.server.common.data.page.TimePageLink; |
... | ... | @@ -75,6 +76,7 @@ import javax.annotation.Nullable; |
75 | 76 | import java.io.IOException; |
76 | 77 | import java.util.ArrayList; |
77 | 78 | import java.util.List; |
79 | +import java.util.UUID; | |
78 | 80 | import java.util.stream.Collectors; |
79 | 81 | |
80 | 82 | import static org.thingsboard.server.controller.EdgeController.EDGE_ID; |
... | ... | @@ -153,7 +155,7 @@ public class DeviceController extends BaseController { |
153 | 155 | deviceStateService.onDeviceUpdated(savedDevice); |
154 | 156 | } |
155 | 157 | |
156 | - firmwareStateService.update(savedDevice, oldDevice); | |
158 | + otaPackageStateService.update(savedDevice, oldDevice); | |
157 | 159 | |
158 | 160 | return savedDevice; |
159 | 161 | } catch (Exception e) { |
... | ... | @@ -778,4 +780,19 @@ public class DeviceController extends BaseController { |
778 | 780 | throw handleException(e); |
779 | 781 | } |
780 | 782 | } |
783 | + | |
784 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") | |
785 | + @RequestMapping(value = "/devices/count/{otaPackageType}", method = RequestMethod.GET) | |
786 | + @ResponseBody | |
787 | + public Long countDevicesByTenantIdAndDeviceProfileIdAndEmptyOtaPackage(@PathVariable("otaPackageType") String otaPackageType, | |
788 | + @RequestParam String deviceProfileId) throws ThingsboardException { | |
789 | + checkParameter("OtaPackageType", otaPackageType); | |
790 | + checkParameter("DeviceProfileId", deviceProfileId); | |
791 | + try { | |
792 | + return deviceService.countDevicesByTenantIdAndDeviceProfileIdAndEmptyOtaPackage( | |
793 | + getCurrentUser().getTenantId(), new DeviceProfileId(UUID.fromString(deviceProfileId)), OtaPackageType.valueOf(otaPackageType)); | |
794 | + } catch (Exception e) { | |
795 | + throw handleException(e); | |
796 | + } | |
797 | + } | |
781 | 798 | } | ... | ... |
... | ... | @@ -168,7 +168,7 @@ public class DeviceProfileController extends BaseController { |
168 | 168 | null, |
169 | 169 | created ? ActionType.ADDED : ActionType.UPDATED, null); |
170 | 170 | |
171 | - firmwareStateService.update(savedDeviceProfile, isFirmwareChanged, isSoftwareChanged); | |
171 | + otaPackageStateService.update(savedDeviceProfile, isFirmwareChanged, isSoftwareChanged); | |
172 | 172 | |
173 | 173 | sendEntityNotificationMsg(getTenantId(), savedDeviceProfile.getId(), |
174 | 174 | deviceProfile.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED); | ... | ... |
application/src/main/java/org/thingsboard/server/controller/OtaPackageController.java
renamed from
application/src/main/java/org/thingsboard/server/controller/FirmwareController.java
... | ... | @@ -30,14 +30,14 @@ import org.springframework.web.bind.annotation.ResponseBody; |
30 | 30 | import org.springframework.web.bind.annotation.RestController; |
31 | 31 | import org.springframework.web.multipart.MultipartFile; |
32 | 32 | import org.thingsboard.server.common.data.EntityType; |
33 | -import org.thingsboard.server.common.data.Firmware; | |
34 | -import org.thingsboard.server.common.data.FirmwareInfo; | |
33 | +import org.thingsboard.server.common.data.OtaPackage; | |
34 | +import org.thingsboard.server.common.data.OtaPackageInfo; | |
35 | 35 | import org.thingsboard.server.common.data.audit.ActionType; |
36 | 36 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
37 | -import org.thingsboard.server.common.data.firmware.ChecksumAlgorithm; | |
38 | -import org.thingsboard.server.common.data.firmware.FirmwareType; | |
37 | +import org.thingsboard.server.common.data.ota.ChecksumAlgorithm; | |
38 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | |
39 | 39 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
40 | -import org.thingsboard.server.common.data.id.FirmwareId; | |
40 | +import org.thingsboard.server.common.data.id.OtaPackageId; | |
41 | 41 | import org.thingsboard.server.common.data.page.PageData; |
42 | 42 | import org.thingsboard.server.common.data.page.PageLink; |
43 | 43 | import org.thingsboard.server.queue.util.TbCoreComponent; |
... | ... | @@ -50,26 +50,26 @@ import java.nio.ByteBuffer; |
50 | 50 | @RestController |
51 | 51 | @TbCoreComponent |
52 | 52 | @RequestMapping("/api") |
53 | -public class FirmwareController extends BaseController { | |
53 | +public class OtaPackageController extends BaseController { | |
54 | 54 | |
55 | - public static final String FIRMWARE_ID = "firmwareId"; | |
55 | + public static final String OTA_PACKAGE_ID = "otaPackageId"; | |
56 | 56 | public static final String CHECKSUM_ALGORITHM = "checksumAlgorithm"; |
57 | 57 | |
58 | 58 | @PreAuthorize("hasAnyAuthority( 'TENANT_ADMIN')") |
59 | - @RequestMapping(value = "/firmware/{firmwareId}/download", method = RequestMethod.GET) | |
59 | + @RequestMapping(value = "/otaPackage/{otaPackageId}/download", method = RequestMethod.GET) | |
60 | 60 | @ResponseBody |
61 | - public ResponseEntity<org.springframework.core.io.Resource> downloadFirmware(@PathVariable(FIRMWARE_ID) String strFirmwareId) throws ThingsboardException { | |
62 | - checkParameter(FIRMWARE_ID, strFirmwareId); | |
61 | + public ResponseEntity<org.springframework.core.io.Resource> downloadOtaPackage(@PathVariable(OTA_PACKAGE_ID) String strOtaPackageId) throws ThingsboardException { | |
62 | + checkParameter(OTA_PACKAGE_ID, strOtaPackageId); | |
63 | 63 | try { |
64 | - FirmwareId firmwareId = new FirmwareId(toUUID(strFirmwareId)); | |
65 | - Firmware firmware = checkFirmwareId(firmwareId, Operation.READ); | |
64 | + OtaPackageId otaPackageId = new OtaPackageId(toUUID(strOtaPackageId)); | |
65 | + OtaPackage otaPackage = checkOtaPackageId(otaPackageId, Operation.READ); | |
66 | 66 | |
67 | - ByteArrayResource resource = new ByteArrayResource(firmware.getData().array()); | |
67 | + ByteArrayResource resource = new ByteArrayResource(otaPackage.getData().array()); | |
68 | 68 | return ResponseEntity.ok() |
69 | - .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + firmware.getFileName()) | |
70 | - .header("x-filename", firmware.getFileName()) | |
69 | + .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + otaPackage.getFileName()) | |
70 | + .header("x-filename", otaPackage.getFileName()) | |
71 | 71 | .contentLength(resource.contentLength()) |
72 | - .contentType(parseMediaType(firmware.getContentType())) | |
72 | + .contentType(parseMediaType(otaPackage.getContentType())) | |
73 | 73 | .body(resource); |
74 | 74 | } catch (Exception e) { |
75 | 75 | throw handleException(e); |
... | ... | @@ -77,144 +77,144 @@ public class FirmwareController extends BaseController { |
77 | 77 | } |
78 | 78 | |
79 | 79 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") |
80 | - @RequestMapping(value = "/firmware/info/{firmwareId}", method = RequestMethod.GET) | |
80 | + @RequestMapping(value = "/otaPackage/info/{otaPackageId}", method = RequestMethod.GET) | |
81 | 81 | @ResponseBody |
82 | - public FirmwareInfo getFirmwareInfoById(@PathVariable(FIRMWARE_ID) String strFirmwareId) throws ThingsboardException { | |
83 | - checkParameter(FIRMWARE_ID, strFirmwareId); | |
82 | + public OtaPackageInfo getOtaPackageInfoById(@PathVariable(OTA_PACKAGE_ID) String strOtaPackageId) throws ThingsboardException { | |
83 | + checkParameter(OTA_PACKAGE_ID, strOtaPackageId); | |
84 | 84 | try { |
85 | - FirmwareId firmwareId = new FirmwareId(toUUID(strFirmwareId)); | |
86 | - return checkNotNull(firmwareService.findFirmwareInfoById(getTenantId(), firmwareId)); | |
85 | + OtaPackageId otaPackageId = new OtaPackageId(toUUID(strOtaPackageId)); | |
86 | + return checkNotNull(otaPackageService.findOtaPackageInfoById(getTenantId(), otaPackageId)); | |
87 | 87 | } catch (Exception e) { |
88 | 88 | throw handleException(e); |
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
92 | 92 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')") |
93 | - @RequestMapping(value = "/firmware/{firmwareId}", method = RequestMethod.GET) | |
93 | + @RequestMapping(value = "/otaPackage/{otaPackageId}", method = RequestMethod.GET) | |
94 | 94 | @ResponseBody |
95 | - public Firmware getFirmwareById(@PathVariable(FIRMWARE_ID) String strFirmwareId) throws ThingsboardException { | |
96 | - checkParameter(FIRMWARE_ID, strFirmwareId); | |
95 | + public OtaPackage getOtaPackageById(@PathVariable(OTA_PACKAGE_ID) String strOtaPackageId) throws ThingsboardException { | |
96 | + checkParameter(OTA_PACKAGE_ID, strOtaPackageId); | |
97 | 97 | try { |
98 | - FirmwareId firmwareId = new FirmwareId(toUUID(strFirmwareId)); | |
99 | - return checkFirmwareId(firmwareId, Operation.READ); | |
98 | + OtaPackageId otaPackageId = new OtaPackageId(toUUID(strOtaPackageId)); | |
99 | + return checkOtaPackageId(otaPackageId, Operation.READ); | |
100 | 100 | } catch (Exception e) { |
101 | 101 | throw handleException(e); |
102 | 102 | } |
103 | 103 | } |
104 | 104 | |
105 | 105 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')") |
106 | - @RequestMapping(value = "/firmware", method = RequestMethod.POST) | |
106 | + @RequestMapping(value = "/otaPackage", method = RequestMethod.POST) | |
107 | 107 | @ResponseBody |
108 | - public FirmwareInfo saveFirmwareInfo(@RequestBody FirmwareInfo firmwareInfo) throws ThingsboardException { | |
109 | - boolean created = firmwareInfo.getId() == null; | |
108 | + public OtaPackageInfo saveOtaPackageInfo(@RequestBody OtaPackageInfo otaPackageInfo) throws ThingsboardException { | |
109 | + boolean created = otaPackageInfo.getId() == null; | |
110 | 110 | try { |
111 | - firmwareInfo.setTenantId(getTenantId()); | |
112 | - checkEntity(firmwareInfo.getId(), firmwareInfo, Resource.FIRMWARE); | |
113 | - FirmwareInfo savedFirmwareInfo = firmwareService.saveFirmwareInfo(firmwareInfo); | |
114 | - logEntityAction(savedFirmwareInfo.getId(), savedFirmwareInfo, | |
111 | + otaPackageInfo.setTenantId(getTenantId()); | |
112 | + checkEntity(otaPackageInfo.getId(), otaPackageInfo, Resource.OTA_PACKAGE); | |
113 | + OtaPackageInfo savedOtaPackageInfo = otaPackageService.saveOtaPackageInfo(otaPackageInfo); | |
114 | + logEntityAction(savedOtaPackageInfo.getId(), savedOtaPackageInfo, | |
115 | 115 | null, created ? ActionType.ADDED : ActionType.UPDATED, null); |
116 | - return savedFirmwareInfo; | |
116 | + return savedOtaPackageInfo; | |
117 | 117 | } catch (Exception e) { |
118 | - logEntityAction(emptyId(EntityType.FIRMWARE), firmwareInfo, | |
118 | + logEntityAction(emptyId(EntityType.OTA_PACKAGE), otaPackageInfo, | |
119 | 119 | null, created ? ActionType.ADDED : ActionType.UPDATED, e); |
120 | 120 | throw handleException(e); |
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
124 | 124 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')") |
125 | - @RequestMapping(value = "/firmware/{firmwareId}", method = RequestMethod.POST) | |
125 | + @RequestMapping(value = "/otaPackage/{otaPackageId}", method = RequestMethod.POST) | |
126 | 126 | @ResponseBody |
127 | - public Firmware saveFirmwareData(@PathVariable(FIRMWARE_ID) String strFirmwareId, | |
128 | - @RequestParam(required = false) String checksum, | |
129 | - @RequestParam(CHECKSUM_ALGORITHM) String checksumAlgorithmStr, | |
130 | - @RequestBody MultipartFile file) throws ThingsboardException { | |
131 | - checkParameter(FIRMWARE_ID, strFirmwareId); | |
127 | + public OtaPackage saveOtaPackageData(@PathVariable(OTA_PACKAGE_ID) String strOtaPackageId, | |
128 | + @RequestParam(required = false) String checksum, | |
129 | + @RequestParam(CHECKSUM_ALGORITHM) String checksumAlgorithmStr, | |
130 | + @RequestBody MultipartFile file) throws ThingsboardException { | |
131 | + checkParameter(OTA_PACKAGE_ID, strOtaPackageId); | |
132 | 132 | checkParameter(CHECKSUM_ALGORITHM, checksumAlgorithmStr); |
133 | 133 | try { |
134 | - FirmwareId firmwareId = new FirmwareId(toUUID(strFirmwareId)); | |
135 | - FirmwareInfo info = checkFirmwareInfoId(firmwareId, Operation.READ); | |
136 | - | |
137 | - Firmware firmware = new Firmware(firmwareId); | |
138 | - firmware.setCreatedTime(info.getCreatedTime()); | |
139 | - firmware.setTenantId(getTenantId()); | |
140 | - firmware.setDeviceProfileId(info.getDeviceProfileId()); | |
141 | - firmware.setType(info.getType()); | |
142 | - firmware.setTitle(info.getTitle()); | |
143 | - firmware.setVersion(info.getVersion()); | |
144 | - firmware.setAdditionalInfo(info.getAdditionalInfo()); | |
134 | + OtaPackageId otaPackageId = new OtaPackageId(toUUID(strOtaPackageId)); | |
135 | + OtaPackageInfo info = checkOtaPackageInfoId(otaPackageId, Operation.READ); | |
136 | + | |
137 | + OtaPackage otaPackage = new OtaPackage(otaPackageId); | |
138 | + otaPackage.setCreatedTime(info.getCreatedTime()); | |
139 | + otaPackage.setTenantId(getTenantId()); | |
140 | + otaPackage.setDeviceProfileId(info.getDeviceProfileId()); | |
141 | + otaPackage.setType(info.getType()); | |
142 | + otaPackage.setTitle(info.getTitle()); | |
143 | + otaPackage.setVersion(info.getVersion()); | |
144 | + otaPackage.setAdditionalInfo(info.getAdditionalInfo()); | |
145 | 145 | |
146 | 146 | ChecksumAlgorithm checksumAlgorithm = ChecksumAlgorithm.valueOf(checksumAlgorithmStr.toUpperCase()); |
147 | 147 | |
148 | 148 | byte[] bytes = file.getBytes(); |
149 | 149 | if (StringUtils.isEmpty(checksum)) { |
150 | - checksum = firmwareService.generateChecksum(checksumAlgorithm, ByteBuffer.wrap(bytes)); | |
150 | + checksum = otaPackageService.generateChecksum(checksumAlgorithm, ByteBuffer.wrap(bytes)); | |
151 | 151 | } |
152 | 152 | |
153 | - firmware.setChecksumAlgorithm(checksumAlgorithm); | |
154 | - firmware.setChecksum(checksum); | |
155 | - firmware.setFileName(file.getOriginalFilename()); | |
156 | - firmware.setContentType(file.getContentType()); | |
157 | - firmware.setData(ByteBuffer.wrap(bytes)); | |
158 | - firmware.setDataSize((long) bytes.length); | |
159 | - Firmware savedFirmware = firmwareService.saveFirmware(firmware); | |
160 | - logEntityAction(savedFirmware.getId(), savedFirmware, null, ActionType.UPDATED, null); | |
161 | - return savedFirmware; | |
153 | + otaPackage.setChecksumAlgorithm(checksumAlgorithm); | |
154 | + otaPackage.setChecksum(checksum); | |
155 | + otaPackage.setFileName(file.getOriginalFilename()); | |
156 | + otaPackage.setContentType(file.getContentType()); | |
157 | + otaPackage.setData(ByteBuffer.wrap(bytes)); | |
158 | + otaPackage.setDataSize((long) bytes.length); | |
159 | + OtaPackage savedOtaPackage = otaPackageService.saveOtaPackage(otaPackage); | |
160 | + logEntityAction(savedOtaPackage.getId(), savedOtaPackage, null, ActionType.UPDATED, null); | |
161 | + return savedOtaPackage; | |
162 | 162 | } catch (Exception e) { |
163 | - logEntityAction(emptyId(EntityType.FIRMWARE), null, null, ActionType.UPDATED, e, strFirmwareId); | |
163 | + logEntityAction(emptyId(EntityType.OTA_PACKAGE), null, null, ActionType.UPDATED, e, strOtaPackageId); | |
164 | 164 | throw handleException(e); |
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
168 | 168 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") |
169 | - @RequestMapping(value = "/firmwares", method = RequestMethod.GET) | |
169 | + @RequestMapping(value = "/otaPackages", method = RequestMethod.GET) | |
170 | 170 | @ResponseBody |
171 | - public PageData<FirmwareInfo> getFirmwares(@RequestParam int pageSize, | |
172 | - @RequestParam int page, | |
173 | - @RequestParam(required = false) String textSearch, | |
174 | - @RequestParam(required = false) String sortProperty, | |
175 | - @RequestParam(required = false) String sortOrder) throws ThingsboardException { | |
171 | + public PageData<OtaPackageInfo> getOtaPackages(@RequestParam int pageSize, | |
172 | + @RequestParam int page, | |
173 | + @RequestParam(required = false) String textSearch, | |
174 | + @RequestParam(required = false) String sortProperty, | |
175 | + @RequestParam(required = false) String sortOrder) throws ThingsboardException { | |
176 | 176 | try { |
177 | 177 | PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder); |
178 | - return checkNotNull(firmwareService.findTenantFirmwaresByTenantId(getTenantId(), pageLink)); | |
178 | + return checkNotNull(otaPackageService.findTenantOtaPackagesByTenantId(getTenantId(), pageLink)); | |
179 | 179 | } catch (Exception e) { |
180 | 180 | throw handleException(e); |
181 | 181 | } |
182 | 182 | } |
183 | 183 | |
184 | 184 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") |
185 | - @RequestMapping(value = "/firmwares/{deviceProfileId}/{type}/{hasData}", method = RequestMethod.GET) | |
185 | + @RequestMapping(value = "/otaPackages/{deviceProfileId}/{type}/{hasData}", method = RequestMethod.GET) | |
186 | 186 | @ResponseBody |
187 | - public PageData<FirmwareInfo> getFirmwares(@PathVariable("deviceProfileId") String strDeviceProfileId, | |
188 | - @PathVariable("type") String strType, | |
189 | - @PathVariable("hasData") boolean hasData, | |
190 | - @RequestParam int pageSize, | |
191 | - @RequestParam int page, | |
192 | - @RequestParam(required = false) String textSearch, | |
193 | - @RequestParam(required = false) String sortProperty, | |
194 | - @RequestParam(required = false) String sortOrder) throws ThingsboardException { | |
187 | + public PageData<OtaPackageInfo> getOtaPackages(@PathVariable("deviceProfileId") String strDeviceProfileId, | |
188 | + @PathVariable("type") String strType, | |
189 | + @PathVariable("hasData") boolean hasData, | |
190 | + @RequestParam int pageSize, | |
191 | + @RequestParam int page, | |
192 | + @RequestParam(required = false) String textSearch, | |
193 | + @RequestParam(required = false) String sortProperty, | |
194 | + @RequestParam(required = false) String sortOrder) throws ThingsboardException { | |
195 | 195 | checkParameter("deviceProfileId", strDeviceProfileId); |
196 | 196 | checkParameter("type", strType); |
197 | 197 | try { |
198 | 198 | PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder); |
199 | - return checkNotNull(firmwareService.findTenantFirmwaresByTenantIdAndDeviceProfileIdAndTypeAndHasData(getTenantId(), | |
200 | - new DeviceProfileId(toUUID(strDeviceProfileId)), FirmwareType.valueOf(strType), hasData, pageLink)); | |
199 | + return checkNotNull(otaPackageService.findTenantOtaPackagesByTenantIdAndDeviceProfileIdAndTypeAndHasData(getTenantId(), | |
200 | + new DeviceProfileId(toUUID(strDeviceProfileId)), OtaPackageType.valueOf(strType), hasData, pageLink)); | |
201 | 201 | } catch (Exception e) { |
202 | 202 | throw handleException(e); |
203 | 203 | } |
204 | 204 | } |
205 | 205 | |
206 | 206 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')") |
207 | - @RequestMapping(value = "/firmware/{firmwareId}", method = RequestMethod.DELETE) | |
207 | + @RequestMapping(value = "/otaPackage/{otaPackageId}", method = RequestMethod.DELETE) | |
208 | 208 | @ResponseBody |
209 | - public void deleteFirmware(@PathVariable("firmwareId") String strFirmwareId) throws ThingsboardException { | |
210 | - checkParameter(FIRMWARE_ID, strFirmwareId); | |
209 | + public void deleteOtaPackage(@PathVariable("otaPackageId") String strOtaPackageId) throws ThingsboardException { | |
210 | + checkParameter(OTA_PACKAGE_ID, strOtaPackageId); | |
211 | 211 | try { |
212 | - FirmwareId firmwareId = new FirmwareId(toUUID(strFirmwareId)); | |
213 | - FirmwareInfo info = checkFirmwareInfoId(firmwareId, Operation.DELETE); | |
214 | - firmwareService.deleteFirmware(getTenantId(), firmwareId); | |
215 | - logEntityAction(firmwareId, info, null, ActionType.DELETED, null, strFirmwareId); | |
212 | + OtaPackageId otaPackageId = new OtaPackageId(toUUID(strOtaPackageId)); | |
213 | + OtaPackageInfo info = checkOtaPackageInfoId(otaPackageId, Operation.DELETE); | |
214 | + otaPackageService.deleteOtaPackage(getTenantId(), otaPackageId); | |
215 | + logEntityAction(otaPackageId, info, null, ActionType.DELETED, null, strOtaPackageId); | |
216 | 216 | } catch (Exception e) { |
217 | - logEntityAction(emptyId(EntityType.FIRMWARE), null, null, ActionType.DELETED, e, strFirmwareId); | |
217 | + logEntityAction(emptyId(EntityType.OTA_PACKAGE), null, null, ActionType.DELETED, e, strOtaPackageId); | |
218 | 218 | throw handleException(e); |
219 | 219 | } |
220 | 220 | } | ... | ... |
application/src/main/java/org/thingsboard/server/service/ota/DefaultOtaPackageStateService.java
renamed from
application/src/main/java/org/thingsboard/server/service/firmware/DefaultFirmwareStateService.java
... | ... | @@ -13,7 +13,7 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.service.firmware; | |
16 | +package org.thingsboard.server.service.ota; | |
17 | 17 | |
18 | 18 | import com.google.common.util.concurrent.FutureCallback; |
19 | 19 | import lombok.extern.slf4j.Slf4j; |
... | ... | @@ -23,12 +23,9 @@ import org.thingsboard.rule.engine.api.msg.DeviceAttributesEventNotificationMsg; |
23 | 23 | import org.thingsboard.server.common.data.DataConstants; |
24 | 24 | import org.thingsboard.server.common.data.Device; |
25 | 25 | import org.thingsboard.server.common.data.DeviceProfile; |
26 | -import org.thingsboard.server.common.data.FirmwareInfo; | |
27 | -import org.thingsboard.server.common.data.firmware.FirmwareType; | |
28 | -import org.thingsboard.server.common.data.firmware.FirmwareUpdateStatus; | |
29 | -import org.thingsboard.server.common.data.firmware.FirmwareUtil; | |
26 | +import org.thingsboard.server.common.data.OtaPackageInfo; | |
30 | 27 | import org.thingsboard.server.common.data.id.DeviceId; |
31 | -import org.thingsboard.server.common.data.id.FirmwareId; | |
28 | +import org.thingsboard.server.common.data.id.OtaPackageId; | |
32 | 29 | import org.thingsboard.server.common.data.id.TenantId; |
33 | 30 | import org.thingsboard.server.common.data.kv.AttributeKey; |
34 | 31 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
... | ... | @@ -37,13 +34,16 @@ import org.thingsboard.server.common.data.kv.BasicTsKvEntry; |
37 | 34 | import org.thingsboard.server.common.data.kv.LongDataEntry; |
38 | 35 | import org.thingsboard.server.common.data.kv.StringDataEntry; |
39 | 36 | import org.thingsboard.server.common.data.kv.TsKvEntry; |
37 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | |
38 | +import org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus; | |
39 | +import org.thingsboard.server.common.data.ota.OtaPackageUtil; | |
40 | 40 | import org.thingsboard.server.common.data.page.PageData; |
41 | 41 | import org.thingsboard.server.common.data.page.PageLink; |
42 | 42 | import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; |
43 | 43 | import org.thingsboard.server.dao.device.DeviceProfileService; |
44 | 44 | import org.thingsboard.server.dao.device.DeviceService; |
45 | -import org.thingsboard.server.dao.firmware.FirmwareService; | |
46 | -import org.thingsboard.server.gen.transport.TransportProtos.ToFirmwareStateServiceMsg; | |
45 | +import org.thingsboard.server.dao.ota.OtaPackageService; | |
46 | +import org.thingsboard.server.gen.transport.TransportProtos.ToOtaPackageStateServiceMsg; | |
47 | 47 | import org.thingsboard.server.queue.TbQueueProducer; |
48 | 48 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
49 | 49 | import org.thingsboard.server.queue.provider.TbCoreQueueFactory; |
... | ... | @@ -58,44 +58,43 @@ import java.util.List; |
58 | 58 | import java.util.Set; |
59 | 59 | import java.util.UUID; |
60 | 60 | import java.util.function.Consumer; |
61 | -import java.util.function.Function; | |
62 | - | |
63 | -import static org.thingsboard.server.common.data.firmware.FirmwareKey.CHECKSUM; | |
64 | -import static org.thingsboard.server.common.data.firmware.FirmwareKey.CHECKSUM_ALGORITHM; | |
65 | -import static org.thingsboard.server.common.data.firmware.FirmwareKey.SIZE; | |
66 | -import static org.thingsboard.server.common.data.firmware.FirmwareKey.STATE; | |
67 | -import static org.thingsboard.server.common.data.firmware.FirmwareKey.TITLE; | |
68 | -import static org.thingsboard.server.common.data.firmware.FirmwareKey.TS; | |
69 | -import static org.thingsboard.server.common.data.firmware.FirmwareKey.VERSION; | |
70 | -import static org.thingsboard.server.common.data.firmware.FirmwareType.FIRMWARE; | |
71 | -import static org.thingsboard.server.common.data.firmware.FirmwareType.SOFTWARE; | |
72 | -import static org.thingsboard.server.common.data.firmware.FirmwareUtil.getAttributeKey; | |
73 | -import static org.thingsboard.server.common.data.firmware.FirmwareUtil.getTargetTelemetryKey; | |
74 | -import static org.thingsboard.server.common.data.firmware.FirmwareUtil.getTelemetryKey; | |
61 | + | |
62 | +import static org.thingsboard.server.common.data.ota.OtaPackageKey.CHECKSUM; | |
63 | +import static org.thingsboard.server.common.data.ota.OtaPackageKey.CHECKSUM_ALGORITHM; | |
64 | +import static org.thingsboard.server.common.data.ota.OtaPackageKey.SIZE; | |
65 | +import static org.thingsboard.server.common.data.ota.OtaPackageKey.STATE; | |
66 | +import static org.thingsboard.server.common.data.ota.OtaPackageKey.TITLE; | |
67 | +import static org.thingsboard.server.common.data.ota.OtaPackageKey.TS; | |
68 | +import static org.thingsboard.server.common.data.ota.OtaPackageKey.VERSION; | |
69 | +import static org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE; | |
70 | +import static org.thingsboard.server.common.data.ota.OtaPackageType.SOFTWARE; | |
71 | +import static org.thingsboard.server.common.data.ota.OtaPackageUtil.getAttributeKey; | |
72 | +import static org.thingsboard.server.common.data.ota.OtaPackageUtil.getTargetTelemetryKey; | |
73 | +import static org.thingsboard.server.common.data.ota.OtaPackageUtil.getTelemetryKey; | |
75 | 74 | |
76 | 75 | @Slf4j |
77 | 76 | @Service |
78 | 77 | @TbCoreComponent |
79 | -public class DefaultFirmwareStateService implements FirmwareStateService { | |
78 | +public class DefaultOtaPackageStateService implements OtaPackageStateService { | |
80 | 79 | |
81 | 80 | private final TbClusterService tbClusterService; |
82 | - private final FirmwareService firmwareService; | |
81 | + private final OtaPackageService otaPackageService; | |
83 | 82 | private final DeviceService deviceService; |
84 | 83 | private final DeviceProfileService deviceProfileService; |
85 | 84 | private final RuleEngineTelemetryService telemetryService; |
86 | - private final TbQueueProducer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> fwStateMsgProducer; | |
85 | + private final TbQueueProducer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> otaPackageStateMsgProducer; | |
87 | 86 | |
88 | - public DefaultFirmwareStateService(TbClusterService tbClusterService, FirmwareService firmwareService, | |
89 | - DeviceService deviceService, | |
90 | - DeviceProfileService deviceProfileService, | |
91 | - RuleEngineTelemetryService telemetryService, | |
92 | - TbCoreQueueFactory coreQueueFactory) { | |
87 | + public DefaultOtaPackageStateService(TbClusterService tbClusterService, OtaPackageService otaPackageService, | |
88 | + DeviceService deviceService, | |
89 | + DeviceProfileService deviceProfileService, | |
90 | + RuleEngineTelemetryService telemetryService, | |
91 | + TbCoreQueueFactory coreQueueFactory) { | |
93 | 92 | this.tbClusterService = tbClusterService; |
94 | - this.firmwareService = firmwareService; | |
93 | + this.otaPackageService = otaPackageService; | |
95 | 94 | this.deviceService = deviceService; |
96 | 95 | this.deviceProfileService = deviceProfileService; |
97 | 96 | this.telemetryService = telemetryService; |
98 | - this.fwStateMsgProducer = coreQueueFactory.createToFirmwareStateServiceMsgProducer(); | |
97 | + this.otaPackageStateMsgProducer = coreQueueFactory.createToOtaPackageStateServiceMsgProducer(); | |
99 | 98 | } |
100 | 99 | |
101 | 100 | @Override |
... | ... | @@ -105,14 +104,14 @@ public class DefaultFirmwareStateService implements FirmwareStateService { |
105 | 104 | } |
106 | 105 | |
107 | 106 | private void updateFirmware(Device device, Device oldDevice) { |
108 | - FirmwareId newFirmwareId = device.getFirmwareId(); | |
107 | + OtaPackageId newFirmwareId = device.getFirmwareId(); | |
109 | 108 | if (newFirmwareId == null) { |
110 | 109 | DeviceProfile newDeviceProfile = deviceProfileService.findDeviceProfileById(device.getTenantId(), device.getDeviceProfileId()); |
111 | 110 | newFirmwareId = newDeviceProfile.getFirmwareId(); |
112 | 111 | } |
113 | 112 | if (oldDevice != null) { |
114 | 113 | if (newFirmwareId != null) { |
115 | - FirmwareId oldFirmwareId = oldDevice.getFirmwareId(); | |
114 | + OtaPackageId oldFirmwareId = oldDevice.getFirmwareId(); | |
116 | 115 | if (oldFirmwareId == null) { |
117 | 116 | DeviceProfile oldDeviceProfile = deviceProfileService.findDeviceProfileById(oldDevice.getTenantId(), oldDevice.getDeviceProfileId()); |
118 | 117 | oldFirmwareId = oldDeviceProfile.getFirmwareId(); |
... | ... | @@ -132,14 +131,14 @@ public class DefaultFirmwareStateService implements FirmwareStateService { |
132 | 131 | } |
133 | 132 | |
134 | 133 | private void updateSoftware(Device device, Device oldDevice) { |
135 | - FirmwareId newSoftwareId = device.getSoftwareId(); | |
134 | + OtaPackageId newSoftwareId = device.getSoftwareId(); | |
136 | 135 | if (newSoftwareId == null) { |
137 | 136 | DeviceProfile newDeviceProfile = deviceProfileService.findDeviceProfileById(device.getTenantId(), device.getDeviceProfileId()); |
138 | 137 | newSoftwareId = newDeviceProfile.getSoftwareId(); |
139 | 138 | } |
140 | 139 | if (oldDevice != null) { |
141 | 140 | if (newSoftwareId != null) { |
142 | - FirmwareId oldSoftwareId = oldDevice.getSoftwareId(); | |
141 | + OtaPackageId oldSoftwareId = oldDevice.getSoftwareId(); | |
143 | 142 | if (oldSoftwareId == null) { |
144 | 143 | DeviceProfile oldDeviceProfile = deviceProfileService.findDeviceProfileById(oldDevice.getTenantId(), oldDevice.getDeviceProfileId()); |
145 | 144 | oldSoftwareId = oldDeviceProfile.getSoftwareId(); |
... | ... | @@ -170,33 +169,20 @@ public class DefaultFirmwareStateService implements FirmwareStateService { |
170 | 169 | } |
171 | 170 | } |
172 | 171 | |
173 | - private void update(TenantId tenantId, DeviceProfile deviceProfile, FirmwareType firmwareType) { | |
174 | - Function<PageLink, PageData<Device>> getDevicesFunction; | |
172 | + private void update(TenantId tenantId, DeviceProfile deviceProfile, OtaPackageType otaPackageType) { | |
175 | 173 | Consumer<Device> updateConsumer; |
176 | 174 | |
177 | - switch (firmwareType) { | |
178 | - case FIRMWARE: | |
179 | - getDevicesFunction = pl -> deviceService.findDevicesByTenantIdAndTypeAndEmptyFirmware(tenantId, deviceProfile.getName(), pl); | |
180 | - break; | |
181 | - case SOFTWARE: | |
182 | - getDevicesFunction = pl -> deviceService.findDevicesByTenantIdAndTypeAndEmptySoftware(tenantId, deviceProfile.getName(), pl); | |
183 | - break; | |
184 | - default: | |
185 | - log.warn("Unsupported firmware type: [{}]", firmwareType); | |
186 | - return; | |
187 | - } | |
188 | - | |
189 | 175 | if (deviceProfile.getFirmwareId() != null) { |
190 | 176 | long ts = System.currentTimeMillis(); |
191 | - updateConsumer = d -> send(d.getTenantId(), d.getId(), deviceProfile.getFirmwareId(), ts, firmwareType); | |
177 | + updateConsumer = d -> send(d.getTenantId(), d.getId(), deviceProfile.getFirmwareId(), ts, otaPackageType); | |
192 | 178 | } else { |
193 | - updateConsumer = d -> remove(d, firmwareType); | |
179 | + updateConsumer = d -> remove(d, otaPackageType); | |
194 | 180 | } |
195 | 181 | |
196 | 182 | PageLink pageLink = new PageLink(100); |
197 | 183 | PageData<Device> pageData; |
198 | 184 | do { |
199 | - pageData = getDevicesFunction.apply(pageLink); | |
185 | + pageData = deviceService.findDevicesByTenantIdAndTypeAndEmptyOtaPackage(tenantId, deviceProfile.getId(), otaPackageType, pageLink); | |
200 | 186 | pageData.getData().forEach(updateConsumer); |
201 | 187 | |
202 | 188 | if (pageData.hasNext()) { |
... | ... | @@ -206,60 +192,60 @@ public class DefaultFirmwareStateService implements FirmwareStateService { |
206 | 192 | } |
207 | 193 | |
208 | 194 | @Override |
209 | - public boolean process(ToFirmwareStateServiceMsg msg) { | |
195 | + public boolean process(ToOtaPackageStateServiceMsg msg) { | |
210 | 196 | boolean isSuccess = false; |
211 | - FirmwareId targetFirmwareId = new FirmwareId(new UUID(msg.getFirmwareIdMSB(), msg.getFirmwareIdLSB())); | |
197 | + OtaPackageId targetOtaPackageId = new OtaPackageId(new UUID(msg.getOtaPackageIdMSB(), msg.getOtaPackageIdLSB())); | |
212 | 198 | DeviceId deviceId = new DeviceId(new UUID(msg.getDeviceIdMSB(), msg.getDeviceIdLSB())); |
213 | 199 | TenantId tenantId = new TenantId(new UUID(msg.getTenantIdMSB(), msg.getTenantIdLSB())); |
214 | - FirmwareType firmwareType = FirmwareType.valueOf(msg.getType()); | |
200 | + OtaPackageType firmwareType = OtaPackageType.valueOf(msg.getType()); | |
215 | 201 | long ts = msg.getTs(); |
216 | 202 | |
217 | 203 | Device device = deviceService.findDeviceById(tenantId, deviceId); |
218 | 204 | if (device == null) { |
219 | 205 | log.warn("[{}] [{}] Device was removed during firmware update msg was queued!", tenantId, deviceId); |
220 | 206 | } else { |
221 | - FirmwareId currentFirmwareId = FirmwareUtil.getFirmwareId(device, firmwareType); | |
222 | - if (currentFirmwareId == null) { | |
207 | + OtaPackageId currentOtaPackageId = OtaPackageUtil.getOtaPackageId(device, firmwareType); | |
208 | + if (currentOtaPackageId == null) { | |
223 | 209 | DeviceProfile deviceProfile = deviceProfileService.findDeviceProfileById(tenantId, device.getDeviceProfileId()); |
224 | - currentFirmwareId = FirmwareUtil.getFirmwareId(deviceProfile, firmwareType); | |
210 | + currentOtaPackageId = OtaPackageUtil.getOtaPackageId(deviceProfile, firmwareType); | |
225 | 211 | } |
226 | 212 | |
227 | - if (targetFirmwareId.equals(currentFirmwareId)) { | |
228 | - update(device, firmwareService.findFirmwareInfoById(device.getTenantId(), targetFirmwareId), ts); | |
213 | + if (targetOtaPackageId.equals(currentOtaPackageId)) { | |
214 | + update(device, otaPackageService.findOtaPackageInfoById(device.getTenantId(), targetOtaPackageId), ts); | |
229 | 215 | isSuccess = true; |
230 | 216 | } else { |
231 | - log.warn("[{}] [{}] Can`t update firmware for the device, target firmwareId: [{}], current firmwareId: [{}]!", tenantId, deviceId, targetFirmwareId, currentFirmwareId); | |
217 | + log.warn("[{}] [{}] Can`t update firmware for the device, target firmwareId: [{}], current firmwareId: [{}]!", tenantId, deviceId, targetOtaPackageId, currentOtaPackageId); | |
232 | 218 | } |
233 | 219 | } |
234 | 220 | return isSuccess; |
235 | 221 | } |
236 | 222 | |
237 | - private void send(TenantId tenantId, DeviceId deviceId, FirmwareId firmwareId, long ts, FirmwareType firmwareType) { | |
238 | - ToFirmwareStateServiceMsg msg = ToFirmwareStateServiceMsg.newBuilder() | |
223 | + private void send(TenantId tenantId, DeviceId deviceId, OtaPackageId firmwareId, long ts, OtaPackageType firmwareType) { | |
224 | + ToOtaPackageStateServiceMsg msg = ToOtaPackageStateServiceMsg.newBuilder() | |
239 | 225 | .setTenantIdMSB(tenantId.getId().getMostSignificantBits()) |
240 | 226 | .setTenantIdLSB(tenantId.getId().getLeastSignificantBits()) |
241 | 227 | .setDeviceIdMSB(deviceId.getId().getMostSignificantBits()) |
242 | 228 | .setDeviceIdLSB(deviceId.getId().getLeastSignificantBits()) |
243 | - .setFirmwareIdMSB(firmwareId.getId().getMostSignificantBits()) | |
244 | - .setFirmwareIdLSB(firmwareId.getId().getLeastSignificantBits()) | |
229 | + .setOtaPackageIdMSB(firmwareId.getId().getMostSignificantBits()) | |
230 | + .setOtaPackageIdLSB(firmwareId.getId().getLeastSignificantBits()) | |
245 | 231 | .setType(firmwareType.name()) |
246 | 232 | .setTs(ts) |
247 | 233 | .build(); |
248 | 234 | |
249 | - FirmwareInfo firmware = firmwareService.findFirmwareInfoById(tenantId, firmwareId); | |
235 | + OtaPackageInfo firmware = otaPackageService.findOtaPackageInfoById(tenantId, firmwareId); | |
250 | 236 | if (firmware == null) { |
251 | 237 | log.warn("[{}] Failed to send firmware update because firmware was already deleted", firmwareId); |
252 | 238 | return; |
253 | 239 | } |
254 | 240 | |
255 | - TopicPartitionInfo tpi = new TopicPartitionInfo(fwStateMsgProducer.getDefaultTopic(), null, null, false); | |
256 | - fwStateMsgProducer.send(tpi, new TbProtoQueueMsg<>(UUID.randomUUID(), msg), null); | |
241 | + TopicPartitionInfo tpi = new TopicPartitionInfo(otaPackageStateMsgProducer.getDefaultTopic(), null, null, false); | |
242 | + otaPackageStateMsgProducer.send(tpi, new TbProtoQueueMsg<>(UUID.randomUUID(), msg), null); | |
257 | 243 | |
258 | 244 | List<TsKvEntry> telemetry = new ArrayList<>(); |
259 | 245 | telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(getTargetTelemetryKey(firmware.getType(), TITLE), firmware.getTitle()))); |
260 | 246 | telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(getTargetTelemetryKey(firmware.getType(), VERSION), firmware.getVersion()))); |
261 | 247 | telemetry.add(new BasicTsKvEntry(ts, new LongDataEntry(getTargetTelemetryKey(firmware.getType(), TS), ts))); |
262 | - telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(getTelemetryKey(firmware.getType(), STATE), FirmwareUpdateStatus.QUEUED.name()))); | |
248 | + telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(getTelemetryKey(firmware.getType(), STATE), OtaPackageUpdateStatus.QUEUED.name()))); | |
263 | 249 | |
264 | 250 | telemetryService.saveAndNotify(tenantId, deviceId, telemetry, new FutureCallback<>() { |
265 | 251 | @Override |
... | ... | @@ -275,11 +261,11 @@ public class DefaultFirmwareStateService implements FirmwareStateService { |
275 | 261 | } |
276 | 262 | |
277 | 263 | |
278 | - private void update(Device device, FirmwareInfo firmware, long ts) { | |
264 | + private void update(Device device, OtaPackageInfo firmware, long ts) { | |
279 | 265 | TenantId tenantId = device.getTenantId(); |
280 | 266 | DeviceId deviceId = device.getId(); |
281 | 267 | |
282 | - BasicTsKvEntry status = new BasicTsKvEntry(System.currentTimeMillis(), new StringDataEntry(getTelemetryKey(firmware.getType(), STATE), FirmwareUpdateStatus.INITIATED.name())); | |
268 | + BasicTsKvEntry status = new BasicTsKvEntry(System.currentTimeMillis(), new StringDataEntry(getTelemetryKey(firmware.getType(), STATE), OtaPackageUpdateStatus.INITIATED.name())); | |
283 | 269 | |
284 | 270 | telemetryService.saveAndNotify(tenantId, deviceId, Collections.singletonList(status), new FutureCallback<>() { |
285 | 271 | @Override |
... | ... | @@ -313,14 +299,14 @@ public class DefaultFirmwareStateService implements FirmwareStateService { |
313 | 299 | }); |
314 | 300 | } |
315 | 301 | |
316 | - private void remove(Device device, FirmwareType firmwareType) { | |
317 | - telemetryService.deleteAndNotify(device.getTenantId(), device.getId(), DataConstants.SHARED_SCOPE, FirmwareUtil.getAttributeKeys(firmwareType), | |
302 | + private void remove(Device device, OtaPackageType firmwareType) { | |
303 | + telemetryService.deleteAndNotify(device.getTenantId(), device.getId(), DataConstants.SHARED_SCOPE, OtaPackageUtil.getAttributeKeys(firmwareType), | |
318 | 304 | new FutureCallback<>() { |
319 | 305 | @Override |
320 | 306 | public void onSuccess(@Nullable Void tmp) { |
321 | 307 | log.trace("[{}] Success remove target firmware attributes!", device.getId()); |
322 | 308 | Set<AttributeKey> keysToNotify = new HashSet<>(); |
323 | - FirmwareUtil.ALL_FW_ATTRIBUTE_KEYS.forEach(key -> keysToNotify.add(new AttributeKey(DataConstants.SHARED_SCOPE, key))); | |
309 | + OtaPackageUtil.ALL_FW_ATTRIBUTE_KEYS.forEach(key -> keysToNotify.add(new AttributeKey(DataConstants.SHARED_SCOPE, key))); | |
324 | 310 | tbClusterService.pushMsgToCore(DeviceAttributesEventNotificationMsg.onDelete(device.getTenantId(), device.getId(), keysToNotify), null); |
325 | 311 | } |
326 | 312 | ... | ... |
application/src/main/java/org/thingsboard/server/service/ota/OtaPackageStateService.java
renamed from
application/src/main/java/org/thingsboard/server/service/firmware/FirmwareStateService.java
... | ... | @@ -13,18 +13,18 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.service.firmware; | |
16 | +package org.thingsboard.server.service.ota; | |
17 | 17 | |
18 | 18 | import org.thingsboard.server.common.data.Device; |
19 | 19 | import org.thingsboard.server.common.data.DeviceProfile; |
20 | -import org.thingsboard.server.gen.transport.TransportProtos.ToFirmwareStateServiceMsg; | |
20 | +import org.thingsboard.server.gen.transport.TransportProtos.ToOtaPackageStateServiceMsg; | |
21 | 21 | |
22 | -public interface FirmwareStateService { | |
22 | +public interface OtaPackageStateService { | |
23 | 23 | |
24 | 24 | void update(Device device, Device oldDevice); |
25 | 25 | |
26 | 26 | void update(DeviceProfile deviceProfile, boolean isFirmwareChanged, boolean isSoftwareChanged); |
27 | 27 | |
28 | - boolean process(ToFirmwareStateServiceMsg msg); | |
28 | + boolean process(ToOtaPackageStateServiceMsg msg); | |
29 | 29 | |
30 | 30 | } | ... | ... |
... | ... | @@ -50,7 +50,7 @@ import org.thingsboard.server.gen.transport.TransportProtos.TbSubscriptionCloseP |
50 | 50 | import org.thingsboard.server.gen.transport.TransportProtos.TbTimeSeriesUpdateProto; |
51 | 51 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
52 | 52 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; |
53 | -import org.thingsboard.server.gen.transport.TransportProtos.ToFirmwareStateServiceMsg; | |
53 | +import org.thingsboard.server.gen.transport.TransportProtos.ToOtaPackageStateServiceMsg; | |
54 | 54 | import org.thingsboard.server.gen.transport.TransportProtos.ToUsageStatsServiceMsg; |
55 | 55 | import org.thingsboard.server.gen.transport.TransportProtos.TransportToDeviceActorMsg; |
56 | 56 | import org.thingsboard.server.queue.TbQueueConsumer; |
... | ... | @@ -60,7 +60,7 @@ import org.thingsboard.server.queue.provider.TbCoreQueueFactory; |
60 | 60 | import org.thingsboard.server.queue.util.TbCoreComponent; |
61 | 61 | import org.thingsboard.server.service.apiusage.TbApiUsageStateService; |
62 | 62 | import org.thingsboard.server.service.edge.EdgeNotificationService; |
63 | -import org.thingsboard.server.service.firmware.FirmwareStateService; | |
63 | +import org.thingsboard.server.service.ota.OtaPackageStateService; | |
64 | 64 | import org.thingsboard.server.service.profile.TbDeviceProfileCache; |
65 | 65 | import org.thingsboard.server.service.queue.processing.AbstractConsumerService; |
66 | 66 | import org.thingsboard.server.service.queue.processing.IdMsgPair; |
... | ... | @@ -75,7 +75,6 @@ import org.thingsboard.server.service.transport.msg.TransportToDeviceActorMsgWra |
75 | 75 | |
76 | 76 | import javax.annotation.PostConstruct; |
77 | 77 | import javax.annotation.PreDestroy; |
78 | -import java.util.ArrayList; | |
79 | 78 | import java.util.List; |
80 | 79 | import java.util.Optional; |
81 | 80 | import java.util.UUID; |
... | ... | @@ -101,9 +100,9 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore |
101 | 100 | @Value("${queue.core.stats.enabled:false}") |
102 | 101 | private boolean statsEnabled; |
103 | 102 | |
104 | - @Value("${queue.core.firmware.pack-interval-ms:60000}") | |
103 | + @Value("${queue.core.ota.pack-interval-ms:60000}") | |
105 | 104 | private long firmwarePackInterval; |
106 | - @Value("${queue.core.firmware.pack-size:100}") | |
105 | + @Value("${queue.core.ota.pack-size:100}") | |
107 | 106 | private int firmwarePackSize; |
108 | 107 | |
109 | 108 | private final TbQueueConsumer<TbProtoQueueMsg<ToCoreMsg>> mainConsumer; |
... | ... | @@ -113,10 +112,10 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore |
113 | 112 | private final SubscriptionManagerService subscriptionManagerService; |
114 | 113 | private final TbCoreDeviceRpcService tbCoreDeviceRpcService; |
115 | 114 | private final EdgeNotificationService edgeNotificationService; |
116 | - private final FirmwareStateService firmwareStateService; | |
115 | + private final OtaPackageStateService firmwareStateService; | |
117 | 116 | private final TbCoreConsumerStats stats; |
118 | 117 | protected final TbQueueConsumer<TbProtoQueueMsg<ToUsageStatsServiceMsg>> usageStatsConsumer; |
119 | - private final TbQueueConsumer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> firmwareStatesConsumer; | |
118 | + private final TbQueueConsumer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> firmwareStatesConsumer; | |
120 | 119 | |
121 | 120 | protected volatile ExecutorService usageStatsExecutor; |
122 | 121 | |
... | ... | @@ -135,11 +134,11 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore |
135 | 134 | TbTenantProfileCache tenantProfileCache, |
136 | 135 | TbApiUsageStateService apiUsageStateService, |
137 | 136 | EdgeNotificationService edgeNotificationService, |
138 | - FirmwareStateService firmwareStateService) { | |
137 | + OtaPackageStateService firmwareStateService) { | |
139 | 138 | super(actorContext, encodingService, tenantProfileCache, deviceProfileCache, apiUsageStateService, tbCoreQueueFactory.createToCoreNotificationsMsgConsumer()); |
140 | 139 | this.mainConsumer = tbCoreQueueFactory.createToCoreMsgConsumer(); |
141 | 140 | this.usageStatsConsumer = tbCoreQueueFactory.createToUsageStatsServiceMsgConsumer(); |
142 | - this.firmwareStatesConsumer = tbCoreQueueFactory.createToFirmwareStateServiceMsgConsumer(); | |
141 | + this.firmwareStatesConsumer = tbCoreQueueFactory.createToOtaPackageStateServiceMsgConsumer(); | |
143 | 142 | this.stateService = stateService; |
144 | 143 | this.localSubscriptionService = localSubscriptionService; |
145 | 144 | this.subscriptionManagerService = subscriptionManagerService; |
... | ... | @@ -173,7 +172,7 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore |
173 | 172 | public void onApplicationEvent(ApplicationReadyEvent event) { |
174 | 173 | super.onApplicationEvent(event); |
175 | 174 | launchUsageStatsConsumer(); |
176 | - launchFirmwareUpdateNotificationConsumer(); | |
175 | + launchOtaPackageUpdateNotificationConsumer(); | |
177 | 176 | } |
178 | 177 | |
179 | 178 | @Override |
... | ... | @@ -361,20 +360,20 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore |
361 | 360 | }); |
362 | 361 | } |
363 | 362 | |
364 | - private void launchFirmwareUpdateNotificationConsumer() { | |
363 | + private void launchOtaPackageUpdateNotificationConsumer() { | |
365 | 364 | long maxProcessingTimeoutPerRecord = firmwarePackInterval / firmwarePackSize; |
366 | 365 | firmwareStatesExecutor.submit(() -> { |
367 | 366 | while (!stopped) { |
368 | 367 | try { |
369 | - List<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> msgs = firmwareStatesConsumer.poll(getNotificationPollDuration()); | |
368 | + List<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> msgs = firmwareStatesConsumer.poll(getNotificationPollDuration()); | |
370 | 369 | if (msgs.isEmpty()) { |
371 | 370 | continue; |
372 | 371 | } |
373 | 372 | long timeToSleep = maxProcessingTimeoutPerRecord; |
374 | - for (TbProtoQueueMsg<ToFirmwareStateServiceMsg> msg : msgs) { | |
373 | + for (TbProtoQueueMsg<ToOtaPackageStateServiceMsg> msg : msgs) { | |
375 | 374 | try { |
376 | 375 | long startTime = System.currentTimeMillis(); |
377 | - boolean isSuccessUpdate = handleFirmwareUpdates(msg); | |
376 | + boolean isSuccessUpdate = handleOtaPackageUpdates(msg); | |
378 | 377 | long endTime = System.currentTimeMillis(); |
379 | 378 | long spentTime = endTime - startTime; |
380 | 379 | timeToSleep = timeToSleep - spentTime; |
... | ... | @@ -402,7 +401,7 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore |
402 | 401 | } |
403 | 402 | } |
404 | 403 | } |
405 | - log.info("TB Firmware States Consumer stopped."); | |
404 | + log.info("TB Ota Package States Consumer stopped."); | |
406 | 405 | }); |
407 | 406 | } |
408 | 407 | |
... | ... | @@ -410,7 +409,7 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore |
410 | 409 | statsService.process(msg, callback); |
411 | 410 | } |
412 | 411 | |
413 | - private boolean handleFirmwareUpdates(TbProtoQueueMsg<ToFirmwareStateServiceMsg> msg) { | |
412 | + private boolean handleOtaPackageUpdates(TbProtoQueueMsg<ToOtaPackageStateServiceMsg> msg) { | |
414 | 413 | return firmwareStateService.process(msg.getValue()); |
415 | 414 | } |
416 | 415 | ... | ... |
... | ... | @@ -30,7 +30,7 @@ import org.thingsboard.server.common.data.Customer; |
30 | 30 | import org.thingsboard.server.common.data.Device; |
31 | 31 | import org.thingsboard.server.common.data.DeviceProfile; |
32 | 32 | import org.thingsboard.server.common.data.EntityView; |
33 | -import org.thingsboard.server.common.data.FirmwareInfo; | |
33 | +import org.thingsboard.server.common.data.OtaPackageInfo; | |
34 | 34 | import org.thingsboard.server.common.data.TbResourceInfo; |
35 | 35 | import org.thingsboard.server.common.data.Tenant; |
36 | 36 | import org.thingsboard.server.common.data.User; |
... | ... | @@ -46,7 +46,7 @@ import org.thingsboard.server.common.data.id.EdgeId; |
46 | 46 | import org.thingsboard.server.common.data.id.EntityId; |
47 | 47 | import org.thingsboard.server.common.data.id.EntityIdFactory; |
48 | 48 | import org.thingsboard.server.common.data.id.EntityViewId; |
49 | -import org.thingsboard.server.common.data.id.FirmwareId; | |
49 | +import org.thingsboard.server.common.data.id.OtaPackageId; | |
50 | 50 | import org.thingsboard.server.common.data.id.RuleChainId; |
51 | 51 | import org.thingsboard.server.common.data.id.RuleNodeId; |
52 | 52 | import org.thingsboard.server.common.data.id.TbResourceId; |
... | ... | @@ -63,7 +63,7 @@ import org.thingsboard.server.dao.device.DeviceService; |
63 | 63 | import org.thingsboard.server.dao.edge.EdgeService; |
64 | 64 | import org.thingsboard.server.dao.entityview.EntityViewService; |
65 | 65 | import org.thingsboard.server.dao.exception.IncorrectParameterException; |
66 | -import org.thingsboard.server.dao.firmware.FirmwareService; | |
66 | +import org.thingsboard.server.dao.ota.OtaPackageService; | |
67 | 67 | import org.thingsboard.server.dao.resource.ResourceService; |
68 | 68 | import org.thingsboard.server.dao.rule.RuleChainService; |
69 | 69 | import org.thingsboard.server.dao.tenant.TenantService; |
... | ... | @@ -135,7 +135,7 @@ public class AccessValidator { |
135 | 135 | protected ResourceService resourceService; |
136 | 136 | |
137 | 137 | @Autowired |
138 | - protected FirmwareService firmwareService; | |
138 | + protected OtaPackageService otaPackageService; | |
139 | 139 | |
140 | 140 | private ExecutorService executor; |
141 | 141 | |
... | ... | @@ -232,8 +232,8 @@ public class AccessValidator { |
232 | 232 | case TB_RESOURCE: |
233 | 233 | validateResource(currentUser, operation, entityId, callback); |
234 | 234 | return; |
235 | - case FIRMWARE: | |
236 | - validateFirmware(currentUser, operation, entityId, callback); | |
235 | + case OTA_PACKAGE: | |
236 | + validateOtaPackage(currentUser, operation, entityId, callback); | |
237 | 237 | return; |
238 | 238 | default: |
239 | 239 | //TODO: add support of other entities |
... | ... | @@ -300,20 +300,20 @@ public class AccessValidator { |
300 | 300 | } |
301 | 301 | } |
302 | 302 | |
303 | - private void validateFirmware(final SecurityUser currentUser, Operation operation, EntityId entityId, FutureCallback<ValidationResult> callback) { | |
303 | + private void validateOtaPackage(final SecurityUser currentUser, Operation operation, EntityId entityId, FutureCallback<ValidationResult> callback) { | |
304 | 304 | if (currentUser.isSystemAdmin()) { |
305 | 305 | callback.onSuccess(ValidationResult.accessDenied(SYSTEM_ADMINISTRATOR_IS_NOT_ALLOWED_TO_PERFORM_THIS_OPERATION)); |
306 | 306 | } else { |
307 | - FirmwareInfo firmware = firmwareService.findFirmwareInfoById(currentUser.getTenantId(), new FirmwareId(entityId.getId())); | |
308 | - if (firmware == null) { | |
309 | - callback.onSuccess(ValidationResult.entityNotFound("Firmware with requested id wasn't found!")); | |
307 | + OtaPackageInfo otaPackage = otaPackageService.findOtaPackageInfoById(currentUser.getTenantId(), new OtaPackageId(entityId.getId())); | |
308 | + if (otaPackage == null) { | |
309 | + callback.onSuccess(ValidationResult.entityNotFound("OtaPackage with requested id wasn't found!")); | |
310 | 310 | } else { |
311 | 311 | try { |
312 | - accessControlService.checkPermission(currentUser, Resource.FIRMWARE, operation, entityId, firmware); | |
312 | + accessControlService.checkPermission(currentUser, Resource.OTA_PACKAGE, operation, entityId, otaPackage); | |
313 | 313 | } catch (ThingsboardException e) { |
314 | 314 | callback.onSuccess(ValidationResult.accessDenied(e.getMessage())); |
315 | 315 | } |
316 | - callback.onSuccess(ValidationResult.ok(firmware)); | |
316 | + callback.onSuccess(ValidationResult.ok(otaPackage)); | |
317 | 317 | } |
318 | 318 | } |
319 | 319 | } | ... | ... |
... | ... | @@ -38,7 +38,7 @@ public enum Resource { |
38 | 38 | DEVICE_PROFILE(EntityType.DEVICE_PROFILE), |
39 | 39 | API_USAGE_STATE(EntityType.API_USAGE_STATE), |
40 | 40 | TB_RESOURCE(EntityType.TB_RESOURCE), |
41 | - FIRMWARE(EntityType.FIRMWARE), | |
41 | + OTA_PACKAGE(EntityType.OTA_PACKAGE), | |
42 | 42 | EDGE(EntityType.EDGE); |
43 | 43 | |
44 | 44 | private final EntityType entityType; | ... | ... |
... | ... | @@ -42,7 +42,7 @@ public class TenantAdminPermissions extends AbstractPermissions { |
42 | 42 | put(Resource.DEVICE_PROFILE, tenantEntityPermissionChecker); |
43 | 43 | put(Resource.API_USAGE_STATE, tenantEntityPermissionChecker); |
44 | 44 | put(Resource.TB_RESOURCE, tbResourcePermissionChecker); |
45 | - put(Resource.FIRMWARE, tenantEntityPermissionChecker); | |
45 | + put(Resource.OTA_PACKAGE, tenantEntityPermissionChecker); | |
46 | 46 | put(Resource.EDGE, tenantEntityPermissionChecker); |
47 | 47 | } |
48 | 48 | ... | ... |
... | ... | @@ -26,27 +26,27 @@ import lombok.extern.slf4j.Slf4j; |
26 | 26 | import org.springframework.stereotype.Service; |
27 | 27 | import org.springframework.util.StringUtils; |
28 | 28 | import org.thingsboard.common.util.JacksonUtil; |
29 | -import org.thingsboard.server.cache.firmware.FirmwareDataCache; | |
29 | +import org.thingsboard.server.cache.ota.OtaPackageDataCache; | |
30 | 30 | import org.thingsboard.server.common.data.ApiUsageState; |
31 | 31 | import org.thingsboard.server.common.data.DataConstants; |
32 | 32 | import org.thingsboard.server.common.data.Device; |
33 | 33 | import org.thingsboard.server.common.data.DeviceProfile; |
34 | 34 | import org.thingsboard.server.common.data.DeviceTransportType; |
35 | 35 | import org.thingsboard.server.common.data.EntityType; |
36 | -import org.thingsboard.server.common.data.Firmware; | |
37 | -import org.thingsboard.server.common.data.FirmwareInfo; | |
36 | +import org.thingsboard.server.common.data.OtaPackage; | |
37 | +import org.thingsboard.server.common.data.OtaPackageInfo; | |
38 | 38 | import org.thingsboard.server.common.data.ResourceType; |
39 | 39 | import org.thingsboard.server.common.data.TbResource; |
40 | 40 | import org.thingsboard.server.common.data.TenantProfile; |
41 | 41 | import org.thingsboard.server.common.data.device.credentials.BasicMqttCredentials; |
42 | 42 | import org.thingsboard.server.common.data.device.credentials.ProvisionDeviceCredentialsData; |
43 | 43 | import org.thingsboard.server.common.data.device.profile.ProvisionDeviceProfileCredentials; |
44 | -import org.thingsboard.server.common.data.firmware.FirmwareType; | |
45 | -import org.thingsboard.server.common.data.firmware.FirmwareUtil; | |
44 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | |
45 | +import org.thingsboard.server.common.data.ota.OtaPackageUtil; | |
46 | 46 | import org.thingsboard.server.common.data.id.CustomerId; |
47 | 47 | import org.thingsboard.server.common.data.id.DeviceId; |
48 | 48 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
49 | -import org.thingsboard.server.common.data.id.FirmwareId; | |
49 | +import org.thingsboard.server.common.data.id.OtaPackageId; | |
50 | 50 | import org.thingsboard.server.common.data.id.TenantId; |
51 | 51 | import org.thingsboard.server.common.data.page.PageData; |
52 | 52 | import org.thingsboard.server.common.data.page.PageLink; |
... | ... | @@ -64,7 +64,7 @@ import org.thingsboard.server.dao.device.DeviceService; |
64 | 64 | import org.thingsboard.server.dao.device.provision.ProvisionFailedException; |
65 | 65 | import org.thingsboard.server.dao.device.provision.ProvisionRequest; |
66 | 66 | import org.thingsboard.server.dao.device.provision.ProvisionResponse; |
67 | -import org.thingsboard.server.dao.firmware.FirmwareService; | |
67 | +import org.thingsboard.server.dao.ota.OtaPackageService; | |
68 | 68 | import org.thingsboard.server.dao.relation.RelationService; |
69 | 69 | import org.thingsboard.server.dao.tenant.TbTenantProfileCache; |
70 | 70 | import org.thingsboard.server.gen.transport.TransportProtos; |
... | ... | @@ -124,8 +124,8 @@ public class DefaultTransportApiService implements TransportApiService { |
124 | 124 | private final DataDecodingEncodingService dataDecodingEncodingService; |
125 | 125 | private final DeviceProvisionService deviceProvisionService; |
126 | 126 | private final TbResourceService resourceService; |
127 | - private final FirmwareService firmwareService; | |
128 | - private final FirmwareDataCache firmwareDataCache; | |
127 | + private final OtaPackageService otaPackageService; | |
128 | + private final OtaPackageDataCache otaPackageDataCache; | |
129 | 129 | |
130 | 130 | private final ConcurrentMap<String, ReentrantLock> deviceCreationLocks = new ConcurrentHashMap<>(); |
131 | 131 | |
... | ... | @@ -134,7 +134,7 @@ public class DefaultTransportApiService implements TransportApiService { |
134 | 134 | RelationService relationService, DeviceCredentialsService deviceCredentialsService, |
135 | 135 | DeviceStateService deviceStateService, DbCallbackExecutorService dbCallbackExecutorService, |
136 | 136 | TbClusterService tbClusterService, DataDecodingEncodingService dataDecodingEncodingService, |
137 | - DeviceProvisionService deviceProvisionService, TbResourceService resourceService, FirmwareService firmwareService, FirmwareDataCache firmwareDataCache) { | |
137 | + DeviceProvisionService deviceProvisionService, TbResourceService resourceService, OtaPackageService otaPackageService, OtaPackageDataCache otaPackageDataCache) { | |
138 | 138 | this.deviceProfileCache = deviceProfileCache; |
139 | 139 | this.tenantProfileCache = tenantProfileCache; |
140 | 140 | this.apiUsageStateService = apiUsageStateService; |
... | ... | @@ -147,8 +147,8 @@ public class DefaultTransportApiService implements TransportApiService { |
147 | 147 | this.dataDecodingEncodingService = dataDecodingEncodingService; |
148 | 148 | this.deviceProvisionService = deviceProvisionService; |
149 | 149 | this.resourceService = resourceService; |
150 | - this.firmwareService = firmwareService; | |
151 | - this.firmwareDataCache = firmwareDataCache; | |
150 | + this.otaPackageService = otaPackageService; | |
151 | + this.otaPackageDataCache = otaPackageDataCache; | |
152 | 152 | } |
153 | 153 | |
154 | 154 | @Override |
... | ... | @@ -184,8 +184,8 @@ public class DefaultTransportApiService implements TransportApiService { |
184 | 184 | result = handle(transportApiRequestMsg.getDeviceRequestMsg()); |
185 | 185 | } else if (transportApiRequestMsg.hasDeviceCredentialsRequestMsg()) { |
186 | 186 | result = handle(transportApiRequestMsg.getDeviceCredentialsRequestMsg()); |
187 | - } else if (transportApiRequestMsg.hasFirmwareRequestMsg()) { | |
188 | - result = handle(transportApiRequestMsg.getFirmwareRequestMsg()); | |
187 | + } else if (transportApiRequestMsg.hasOtaPackageRequestMsg()) { | |
188 | + result = handle(transportApiRequestMsg.getOtaPackageRequestMsg()); | |
189 | 189 | } |
190 | 190 | |
191 | 191 | return Futures.transform(Optional.ofNullable(result).orElseGet(this::getEmptyTransportApiResponseFuture), |
... | ... | @@ -511,50 +511,50 @@ public class DefaultTransportApiService implements TransportApiService { |
511 | 511 | } |
512 | 512 | } |
513 | 513 | |
514 | - private ListenableFuture<TransportApiResponseMsg> handle(TransportProtos.GetFirmwareRequestMsg requestMsg) { | |
514 | + private ListenableFuture<TransportApiResponseMsg> handle(TransportProtos.GetOtaPackageRequestMsg requestMsg) { | |
515 | 515 | TenantId tenantId = new TenantId(new UUID(requestMsg.getTenantIdMSB(), requestMsg.getTenantIdLSB())); |
516 | 516 | DeviceId deviceId = new DeviceId(new UUID(requestMsg.getDeviceIdMSB(), requestMsg.getDeviceIdLSB())); |
517 | - FirmwareType firmwareType = FirmwareType.valueOf(requestMsg.getType()); | |
517 | + OtaPackageType otaPackageType = OtaPackageType.valueOf(requestMsg.getType()); | |
518 | 518 | Device device = deviceService.findDeviceById(tenantId, deviceId); |
519 | 519 | |
520 | 520 | if (device == null) { |
521 | 521 | return getEmptyTransportApiResponseFuture(); |
522 | 522 | } |
523 | 523 | |
524 | - FirmwareId firmwareId = FirmwareUtil.getFirmwareId(device, firmwareType); | |
525 | - if (firmwareId == null) { | |
524 | + OtaPackageId otaPackageId = OtaPackageUtil.getOtaPackageId(device, otaPackageType); | |
525 | + if (otaPackageId == null) { | |
526 | 526 | DeviceProfile deviceProfile = deviceProfileCache.find(device.getDeviceProfileId()); |
527 | - firmwareId = FirmwareUtil.getFirmwareId(deviceProfile, firmwareType); | |
527 | + otaPackageId = OtaPackageUtil.getOtaPackageId(deviceProfile, otaPackageType); | |
528 | 528 | } |
529 | 529 | |
530 | - TransportProtos.GetFirmwareResponseMsg.Builder builder = TransportProtos.GetFirmwareResponseMsg.newBuilder(); | |
530 | + TransportProtos.GetOtaPackageResponseMsg.Builder builder = TransportProtos.GetOtaPackageResponseMsg.newBuilder(); | |
531 | 531 | |
532 | - if (firmwareId == null) { | |
532 | + if (otaPackageId == null) { | |
533 | 533 | builder.setResponseStatus(TransportProtos.ResponseStatus.NOT_FOUND); |
534 | 534 | } else { |
535 | - FirmwareInfo firmwareInfo = firmwareService.findFirmwareInfoById(tenantId, firmwareId); | |
535 | + OtaPackageInfo otaPackageInfo = otaPackageService.findOtaPackageInfoById(tenantId, otaPackageId); | |
536 | 536 | |
537 | - if (firmwareInfo == null) { | |
537 | + if (otaPackageInfo == null) { | |
538 | 538 | builder.setResponseStatus(TransportProtos.ResponseStatus.NOT_FOUND); |
539 | 539 | } else { |
540 | 540 | builder.setResponseStatus(TransportProtos.ResponseStatus.SUCCESS); |
541 | - builder.setFirmwareIdMSB(firmwareId.getId().getMostSignificantBits()); | |
542 | - builder.setFirmwareIdLSB(firmwareId.getId().getLeastSignificantBits()); | |
543 | - builder.setType(firmwareInfo.getType().name()); | |
544 | - builder.setTitle(firmwareInfo.getTitle()); | |
545 | - builder.setVersion(firmwareInfo.getVersion()); | |
546 | - builder.setFileName(firmwareInfo.getFileName()); | |
547 | - builder.setContentType(firmwareInfo.getContentType()); | |
548 | - if (!firmwareDataCache.has(firmwareId.toString())) { | |
549 | - Firmware firmware = firmwareService.findFirmwareById(tenantId, firmwareId); | |
550 | - firmwareDataCache.put(firmwareId.toString(), firmware.getData().array()); | |
541 | + builder.setOtaPackageIdMSB(otaPackageId.getId().getMostSignificantBits()); | |
542 | + builder.setOtaPackageIdLSB(otaPackageId.getId().getLeastSignificantBits()); | |
543 | + builder.setType(otaPackageInfo.getType().name()); | |
544 | + builder.setTitle(otaPackageInfo.getTitle()); | |
545 | + builder.setVersion(otaPackageInfo.getVersion()); | |
546 | + builder.setFileName(otaPackageInfo.getFileName()); | |
547 | + builder.setContentType(otaPackageInfo.getContentType()); | |
548 | + if (!otaPackageDataCache.has(otaPackageId.toString())) { | |
549 | + OtaPackage otaPackage = otaPackageService.findOtaPackageById(tenantId, otaPackageId); | |
550 | + otaPackageDataCache.put(otaPackageId.toString(), otaPackage.getData().array()); | |
551 | 551 | } |
552 | 552 | } |
553 | 553 | } |
554 | 554 | |
555 | 555 | return Futures.immediateFuture( |
556 | 556 | TransportApiResponseMsg.newBuilder() |
557 | - .setFirmwareResponseMsg(builder.build()) | |
557 | + .setOtaPackageResponseMsg(builder.build()) | |
558 | 558 | .build()); |
559 | 559 | } |
560 | 560 | ... | ... |
... | ... | @@ -371,7 +371,10 @@ caffeine: |
371 | 371 | tokensOutdatageTime: |
372 | 372 | timeToLiveInMinutes: 20000 |
373 | 373 | maxSize: 10000 |
374 | - firmwares: | |
374 | + otaPackages: | |
375 | + timeToLiveInMinutes: 60 | |
376 | + maxSize: 10 | |
377 | + otaPackagesData: | |
375 | 378 | timeToLiveInMinutes: 60 |
376 | 379 | maxSize: 10 |
377 | 380 | edges: |
... | ... | @@ -497,7 +500,7 @@ audit-log: |
497 | 500 | "device_profile": "${AUDIT_LOG_MASK_DEVICE_PROFILE:W}" |
498 | 501 | "edge": "${AUDIT_LOG_MASK_EDGE:W}" |
499 | 502 | "tb_resource": "${AUDIT_LOG_MASK_RESOURCE:W}" |
500 | - "firmware": "${AUDIT_LOG_MASK_FIRMWARE:W}" | |
503 | + "ota_package": "${AUDIT_LOG_MASK_OTA_PACKAGE:W}" | |
501 | 504 | sink: |
502 | 505 | # Type of external sink. possible options: none, elasticsearch |
503 | 506 | type: "${AUDIT_LOG_SINK_TYPE:none}" |
... | ... | @@ -749,7 +752,7 @@ queue: |
749 | 752 | sasl.config: "${TB_QUEUE_KAFKA_CONFLUENT_SASL_JAAS_CONFIG:org.apache.kafka.common.security.plain.PlainLoginModule required username=\"CLUSTER_API_KEY\" password=\"CLUSTER_API_SECRET\";}" |
750 | 753 | security.protocol: "${TB_QUEUE_KAFKA_CONFLUENT_SECURITY_PROTOCOL:SASL_SSL}" |
751 | 754 | consumer-properties-per-topic: |
752 | - tb_firmware: | |
755 | + tb_ota_package: | |
753 | 756 | - key: max.poll.records |
754 | 757 | value: 10 |
755 | 758 | other: |
... | ... | @@ -759,7 +762,7 @@ queue: |
759 | 762 | transport-api: "${TB_QUEUE_KAFKA_TA_TOPIC_PROPERTIES:retention.ms:604800000;segment.bytes:26214400;retention.bytes:1048576000;partitions:1;min.insync.replicas:1}" |
760 | 763 | notifications: "${TB_QUEUE_KAFKA_NOTIFICATIONS_TOPIC_PROPERTIES:retention.ms:604800000;segment.bytes:26214400;retention.bytes:1048576000;partitions:1;min.insync.replicas:1}" |
761 | 764 | js-executor: "${TB_QUEUE_KAFKA_JE_TOPIC_PROPERTIES:retention.ms:604800000;segment.bytes:26214400;retention.bytes:104857600;partitions:100;min.insync.replicas:1}" |
762 | - fw-updates: "${TB_QUEUE_KAFKA_FW_TOPIC_PROPERTIES:retention.ms:604800000;segment.bytes:26214400;retention.bytes:1048576000;partitions:10;min.insync.replicas:1}" | |
765 | + ota-updates: "${TB_QUEUE_KAFKA_OTA_TOPIC_PROPERTIES:retention.ms:604800000;segment.bytes:26214400;retention.bytes:1048576000;partitions:10;min.insync.replicas:1}" | |
763 | 766 | consumer-stats: |
764 | 767 | enabled: "${TB_QUEUE_KAFKA_CONSUMER_STATS_ENABLED:true}" |
765 | 768 | print-interval-ms: "${TB_QUEUE_KAFKA_CONSUMER_STATS_MIN_PRINT_INTERVAL_MS:60000}" |
... | ... | @@ -830,10 +833,10 @@ queue: |
830 | 833 | poll-interval: "${TB_QUEUE_CORE_POLL_INTERVAL_MS:25}" |
831 | 834 | partitions: "${TB_QUEUE_CORE_PARTITIONS:10}" |
832 | 835 | pack-processing-timeout: "${TB_QUEUE_CORE_PACK_PROCESSING_TIMEOUT_MS:2000}" |
833 | - firmware: | |
834 | - topic: "${TB_QUEUE_CORE_FW_TOPIC:tb_firmware}" | |
835 | - pack-interval-ms: "${TB_QUEUE_CORE_FW_PACK_INTERVAL_MS:60000}" | |
836 | - pack-size: "${TB_QUEUE_CORE_FW_PACK_SIZE:100}" | |
836 | + ota: | |
837 | + topic: "${TB_QUEUE_CORE_OTA_TOPIC:tb_ota_package}" | |
838 | + pack-interval-ms: "${TB_QUEUE_CORE_OTA_PACK_INTERVAL_MS:60000}" | |
839 | + pack-size: "${TB_QUEUE_CORE_OTA_PACK_SIZE:100}" | |
837 | 840 | usage-stats-topic: "${TB_QUEUE_US_TOPIC:tb_usage_stats}" |
838 | 841 | stats: |
839 | 842 | enabled: "${TB_QUEUE_CORE_STATS_ENABLED:true}" | ... | ... |
application/src/test/java/org/thingsboard/server/controller/BaseOtaPackageControllerTest.java
renamed from
application/src/test/java/org/thingsboard/server/controller/BaseFirmwareControllerTest.java
... | ... | @@ -25,11 +25,10 @@ import org.springframework.test.web.servlet.request.MockMultipartHttpServletRequ |
25 | 25 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; |
26 | 26 | import org.thingsboard.common.util.JacksonUtil; |
27 | 27 | import org.thingsboard.server.common.data.DeviceProfile; |
28 | -import org.thingsboard.server.common.data.Firmware; | |
29 | -import org.thingsboard.server.common.data.FirmwareInfo; | |
28 | +import org.thingsboard.server.common.data.OtaPackage; | |
29 | +import org.thingsboard.server.common.data.OtaPackageInfo; | |
30 | 30 | import org.thingsboard.server.common.data.Tenant; |
31 | 31 | import org.thingsboard.server.common.data.User; |
32 | -import org.thingsboard.server.common.data.firmware.FirmwareType; | |
33 | 32 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
34 | 33 | import org.thingsboard.server.common.data.page.PageData; |
35 | 34 | import org.thingsboard.server.common.data.page.PageLink; |
... | ... | @@ -41,11 +40,11 @@ import java.util.Collections; |
41 | 40 | import java.util.List; |
42 | 41 | |
43 | 42 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
44 | -import static org.thingsboard.server.common.data.firmware.FirmwareType.FIRMWARE; | |
43 | +import static org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE; | |
45 | 44 | |
46 | -public abstract class BaseFirmwareControllerTest extends AbstractControllerTest { | |
45 | +public abstract class BaseOtaPackageControllerTest extends AbstractControllerTest { | |
47 | 46 | |
48 | - private IdComparator<FirmwareInfo> idComparator = new IdComparator<>(); | |
47 | + private IdComparator<OtaPackageInfo> idComparator = new IdComparator<>(); | |
49 | 48 | |
50 | 49 | public static final String TITLE = "My firmware"; |
51 | 50 | private static final String FILE_NAME = "filename.txt"; |
... | ... | @@ -93,13 +92,13 @@ public abstract class BaseFirmwareControllerTest extends AbstractControllerTest |
93 | 92 | |
94 | 93 | @Test |
95 | 94 | public void testSaveFirmware() throws Exception { |
96 | - FirmwareInfo firmwareInfo = new FirmwareInfo(); | |
95 | + OtaPackageInfo firmwareInfo = new OtaPackageInfo(); | |
97 | 96 | firmwareInfo.setDeviceProfileId(deviceProfileId); |
98 | 97 | firmwareInfo.setType(FIRMWARE); |
99 | 98 | firmwareInfo.setTitle(TITLE); |
100 | 99 | firmwareInfo.setVersion(VERSION); |
101 | 100 | |
102 | - FirmwareInfo savedFirmwareInfo = save(firmwareInfo); | |
101 | + OtaPackageInfo savedFirmwareInfo = save(firmwareInfo); | |
103 | 102 | |
104 | 103 | Assert.assertNotNull(savedFirmwareInfo); |
105 | 104 | Assert.assertNotNull(savedFirmwareInfo.getId()); |
... | ... | @@ -112,19 +111,19 @@ public abstract class BaseFirmwareControllerTest extends AbstractControllerTest |
112 | 111 | |
113 | 112 | save(savedFirmwareInfo); |
114 | 113 | |
115 | - FirmwareInfo foundFirmwareInfo = doGet("/api/firmware/info/" + savedFirmwareInfo.getId().getId().toString(), FirmwareInfo.class); | |
114 | + OtaPackageInfo foundFirmwareInfo = doGet("/api/otaPackage/info/" + savedFirmwareInfo.getId().getId().toString(), OtaPackageInfo.class); | |
116 | 115 | Assert.assertEquals(foundFirmwareInfo.getTitle(), savedFirmwareInfo.getTitle()); |
117 | 116 | } |
118 | 117 | |
119 | 118 | @Test |
120 | 119 | public void testSaveFirmwareData() throws Exception { |
121 | - FirmwareInfo firmwareInfo = new FirmwareInfo(); | |
120 | + OtaPackageInfo firmwareInfo = new OtaPackageInfo(); | |
122 | 121 | firmwareInfo.setDeviceProfileId(deviceProfileId); |
123 | 122 | firmwareInfo.setType(FIRMWARE); |
124 | 123 | firmwareInfo.setTitle(TITLE); |
125 | 124 | firmwareInfo.setVersion(VERSION); |
126 | 125 | |
127 | - FirmwareInfo savedFirmwareInfo = save(firmwareInfo); | |
126 | + OtaPackageInfo savedFirmwareInfo = save(firmwareInfo); | |
128 | 127 | |
129 | 128 | Assert.assertNotNull(savedFirmwareInfo); |
130 | 129 | Assert.assertNotNull(savedFirmwareInfo.getId()); |
... | ... | @@ -137,12 +136,12 @@ public abstract class BaseFirmwareControllerTest extends AbstractControllerTest |
137 | 136 | |
138 | 137 | save(savedFirmwareInfo); |
139 | 138 | |
140 | - FirmwareInfo foundFirmwareInfo = doGet("/api/firmware/info/" + savedFirmwareInfo.getId().getId().toString(), FirmwareInfo.class); | |
139 | + OtaPackageInfo foundFirmwareInfo = doGet("/api/otaPackage/info/" + savedFirmwareInfo.getId().getId().toString(), OtaPackageInfo.class); | |
141 | 140 | Assert.assertEquals(foundFirmwareInfo.getTitle(), savedFirmwareInfo.getTitle()); |
142 | 141 | |
143 | 142 | MockMultipartFile testData = new MockMultipartFile("file", FILE_NAME, CONTENT_TYPE, DATA.array()); |
144 | 143 | |
145 | - Firmware savedFirmware = savaData("/api/firmware/" + savedFirmwareInfo.getId().getId().toString() + "?checksum={checksum}&checksumAlgorithm={checksumAlgorithm}", testData, CHECKSUM, CHECKSUM_ALGORITHM); | |
144 | + OtaPackage savedFirmware = savaData("/api/otaPackage/" + savedFirmwareInfo.getId().getId().toString() + "?checksum={checksum}&checksumAlgorithm={checksumAlgorithm}", testData, CHECKSUM, CHECKSUM_ALGORITHM); | |
146 | 145 | |
147 | 146 | Assert.assertEquals(FILE_NAME, savedFirmware.getFileName()); |
148 | 147 | Assert.assertEquals(CONTENT_TYPE, savedFirmware.getContentType()); |
... | ... | @@ -150,97 +149,97 @@ public abstract class BaseFirmwareControllerTest extends AbstractControllerTest |
150 | 149 | |
151 | 150 | @Test |
152 | 151 | public void testUpdateFirmwareFromDifferentTenant() throws Exception { |
153 | - FirmwareInfo firmwareInfo = new FirmwareInfo(); | |
152 | + OtaPackageInfo firmwareInfo = new OtaPackageInfo(); | |
154 | 153 | firmwareInfo.setDeviceProfileId(deviceProfileId); |
155 | 154 | firmwareInfo.setType(FIRMWARE); |
156 | 155 | firmwareInfo.setTitle(TITLE); |
157 | 156 | firmwareInfo.setVersion(VERSION); |
158 | 157 | |
159 | - FirmwareInfo savedFirmwareInfo = save(firmwareInfo); | |
158 | + OtaPackageInfo savedFirmwareInfo = save(firmwareInfo); | |
160 | 159 | |
161 | 160 | loginDifferentTenant(); |
162 | - doPost("/api/firmware", savedFirmwareInfo, FirmwareInfo.class, status().isForbidden()); | |
161 | + doPost("/api/otaPackage", savedFirmwareInfo, OtaPackageInfo.class, status().isForbidden()); | |
163 | 162 | deleteDifferentTenant(); |
164 | 163 | } |
165 | 164 | |
166 | 165 | @Test |
167 | 166 | public void testFindFirmwareInfoById() throws Exception { |
168 | - FirmwareInfo firmwareInfo = new FirmwareInfo(); | |
167 | + OtaPackageInfo firmwareInfo = new OtaPackageInfo(); | |
169 | 168 | firmwareInfo.setDeviceProfileId(deviceProfileId); |
170 | 169 | firmwareInfo.setType(FIRMWARE); |
171 | 170 | firmwareInfo.setTitle(TITLE); |
172 | 171 | firmwareInfo.setVersion(VERSION); |
173 | 172 | |
174 | - FirmwareInfo savedFirmwareInfo = save(firmwareInfo); | |
173 | + OtaPackageInfo savedFirmwareInfo = save(firmwareInfo); | |
175 | 174 | |
176 | - FirmwareInfo foundFirmware = doGet("/api/firmware/info/" + savedFirmwareInfo.getId().getId().toString(), FirmwareInfo.class); | |
175 | + OtaPackageInfo foundFirmware = doGet("/api/otaPackage/info/" + savedFirmwareInfo.getId().getId().toString(), OtaPackageInfo.class); | |
177 | 176 | Assert.assertNotNull(foundFirmware); |
178 | 177 | Assert.assertEquals(savedFirmwareInfo, foundFirmware); |
179 | 178 | } |
180 | 179 | |
181 | 180 | @Test |
182 | 181 | public void testFindFirmwareById() throws Exception { |
183 | - FirmwareInfo firmwareInfo = new FirmwareInfo(); | |
182 | + OtaPackageInfo firmwareInfo = new OtaPackageInfo(); | |
184 | 183 | firmwareInfo.setDeviceProfileId(deviceProfileId); |
185 | 184 | firmwareInfo.setType(FIRMWARE); |
186 | 185 | firmwareInfo.setTitle(TITLE); |
187 | 186 | firmwareInfo.setVersion(VERSION); |
188 | 187 | |
189 | - FirmwareInfo savedFirmwareInfo = save(firmwareInfo); | |
188 | + OtaPackageInfo savedFirmwareInfo = save(firmwareInfo); | |
190 | 189 | |
191 | 190 | MockMultipartFile testData = new MockMultipartFile("file", FILE_NAME, CONTENT_TYPE, DATA.array()); |
192 | 191 | |
193 | - Firmware savedFirmware = savaData("/api/firmware/" + savedFirmwareInfo.getId().getId().toString() + "?checksum={checksum}&checksumAlgorithm={checksumAlgorithm}", testData, CHECKSUM, CHECKSUM_ALGORITHM); | |
192 | + OtaPackage savedFirmware = savaData("/api/otaPackage/" + savedFirmwareInfo.getId().getId().toString() + "?checksum={checksum}&checksumAlgorithm={checksumAlgorithm}", testData, CHECKSUM, CHECKSUM_ALGORITHM); | |
194 | 193 | |
195 | - Firmware foundFirmware = doGet("/api/firmware/" + savedFirmwareInfo.getId().getId().toString(), Firmware.class); | |
194 | + OtaPackage foundFirmware = doGet("/api/otaPackage/" + savedFirmwareInfo.getId().getId().toString(), OtaPackage.class); | |
196 | 195 | Assert.assertNotNull(foundFirmware); |
197 | 196 | Assert.assertEquals(savedFirmware, foundFirmware); |
198 | 197 | } |
199 | 198 | |
200 | 199 | @Test |
201 | 200 | public void testDeleteFirmware() throws Exception { |
202 | - FirmwareInfo firmwareInfo = new FirmwareInfo(); | |
201 | + OtaPackageInfo firmwareInfo = new OtaPackageInfo(); | |
203 | 202 | firmwareInfo.setDeviceProfileId(deviceProfileId); |
204 | 203 | firmwareInfo.setType(FIRMWARE); |
205 | 204 | firmwareInfo.setTitle(TITLE); |
206 | 205 | firmwareInfo.setVersion(VERSION); |
207 | 206 | |
208 | - FirmwareInfo savedFirmwareInfo = save(firmwareInfo); | |
207 | + OtaPackageInfo savedFirmwareInfo = save(firmwareInfo); | |
209 | 208 | |
210 | - doDelete("/api/firmware/" + savedFirmwareInfo.getId().getId().toString()) | |
209 | + doDelete("/api/otaPackage/" + savedFirmwareInfo.getId().getId().toString()) | |
211 | 210 | .andExpect(status().isOk()); |
212 | 211 | |
213 | - doGet("/api/firmware/info/" + savedFirmwareInfo.getId().getId().toString()) | |
212 | + doGet("/api/otaPackage/info/" + savedFirmwareInfo.getId().getId().toString()) | |
214 | 213 | .andExpect(status().isNotFound()); |
215 | 214 | } |
216 | 215 | |
217 | 216 | @Test |
218 | 217 | public void testFindTenantFirmwares() throws Exception { |
219 | - List<FirmwareInfo> firmwares = new ArrayList<>(); | |
218 | + List<OtaPackageInfo> otaPackages = new ArrayList<>(); | |
220 | 219 | for (int i = 0; i < 165; i++) { |
221 | - FirmwareInfo firmwareInfo = new FirmwareInfo(); | |
220 | + OtaPackageInfo firmwareInfo = new OtaPackageInfo(); | |
222 | 221 | firmwareInfo.setDeviceProfileId(deviceProfileId); |
223 | 222 | firmwareInfo.setType(FIRMWARE); |
224 | 223 | firmwareInfo.setTitle(TITLE); |
225 | 224 | firmwareInfo.setVersion(VERSION + i); |
226 | 225 | |
227 | - FirmwareInfo savedFirmwareInfo = save(firmwareInfo); | |
226 | + OtaPackageInfo savedFirmwareInfo = save(firmwareInfo); | |
228 | 227 | |
229 | 228 | if (i > 100) { |
230 | 229 | MockMultipartFile testData = new MockMultipartFile("file", FILE_NAME, CONTENT_TYPE, DATA.array()); |
231 | 230 | |
232 | - Firmware savedFirmware = savaData("/api/firmware/" + savedFirmwareInfo.getId().getId().toString() + "?checksum={checksum}&checksumAlgorithm={checksumAlgorithm}", testData, CHECKSUM, CHECKSUM_ALGORITHM); | |
233 | - firmwares.add(new FirmwareInfo(savedFirmware)); | |
231 | + OtaPackage savedFirmware = savaData("/api/otaPackage/" + savedFirmwareInfo.getId().getId().toString() + "?checksum={checksum}&checksumAlgorithm={checksumAlgorithm}", testData, CHECKSUM, CHECKSUM_ALGORITHM); | |
232 | + otaPackages.add(new OtaPackageInfo(savedFirmware)); | |
234 | 233 | } else { |
235 | - firmwares.add(savedFirmwareInfo); | |
234 | + otaPackages.add(savedFirmwareInfo); | |
236 | 235 | } |
237 | 236 | } |
238 | 237 | |
239 | - List<FirmwareInfo> loadedFirmwares = new ArrayList<>(); | |
238 | + List<OtaPackageInfo> loadedFirmwares = new ArrayList<>(); | |
240 | 239 | PageLink pageLink = new PageLink(24); |
241 | - PageData<FirmwareInfo> pageData; | |
240 | + PageData<OtaPackageInfo> pageData; | |
242 | 241 | do { |
243 | - pageData = doGetTypedWithPageLink("/api/firmwares?", | |
242 | + pageData = doGetTypedWithPageLink("/api/otaPackages?", | |
244 | 243 | new TypeReference<>() { |
245 | 244 | }, pageLink); |
246 | 245 | loadedFirmwares.addAll(pageData.getData()); |
... | ... | @@ -249,41 +248,41 @@ public abstract class BaseFirmwareControllerTest extends AbstractControllerTest |
249 | 248 | } |
250 | 249 | } while (pageData.hasNext()); |
251 | 250 | |
252 | - Collections.sort(firmwares, idComparator); | |
251 | + Collections.sort(otaPackages, idComparator); | |
253 | 252 | Collections.sort(loadedFirmwares, idComparator); |
254 | 253 | |
255 | - Assert.assertEquals(firmwares, loadedFirmwares); | |
254 | + Assert.assertEquals(otaPackages, loadedFirmwares); | |
256 | 255 | } |
257 | 256 | |
258 | 257 | @Test |
259 | 258 | public void testFindTenantFirmwaresByHasData() throws Exception { |
260 | - List<FirmwareInfo> firmwaresWithData = new ArrayList<>(); | |
261 | - List<FirmwareInfo> firmwaresWithoutData = new ArrayList<>(); | |
259 | + List<OtaPackageInfo> otaPackagesWithData = new ArrayList<>(); | |
260 | + List<OtaPackageInfo> otaPackagesWithoutData = new ArrayList<>(); | |
262 | 261 | |
263 | 262 | for (int i = 0; i < 165; i++) { |
264 | - FirmwareInfo firmwareInfo = new FirmwareInfo(); | |
263 | + OtaPackageInfo firmwareInfo = new OtaPackageInfo(); | |
265 | 264 | firmwareInfo.setDeviceProfileId(deviceProfileId); |
266 | 265 | firmwareInfo.setType(FIRMWARE); |
267 | 266 | firmwareInfo.setTitle(TITLE); |
268 | 267 | firmwareInfo.setVersion(VERSION + i); |
269 | 268 | |
270 | - FirmwareInfo savedFirmwareInfo = save(firmwareInfo); | |
269 | + OtaPackageInfo savedFirmwareInfo = save(firmwareInfo); | |
271 | 270 | |
272 | 271 | if (i > 100) { |
273 | 272 | MockMultipartFile testData = new MockMultipartFile("file", FILE_NAME, CONTENT_TYPE, DATA.array()); |
274 | 273 | |
275 | - Firmware savedFirmware = savaData("/api/firmware/" + savedFirmwareInfo.getId().getId().toString() + "?checksum={checksum}&checksumAlgorithm={checksumAlgorithm}", testData, CHECKSUM, CHECKSUM_ALGORITHM); | |
276 | - firmwaresWithData.add(new FirmwareInfo(savedFirmware)); | |
274 | + OtaPackage savedFirmware = savaData("/api/otaPackage/" + savedFirmwareInfo.getId().getId().toString() + "?checksum={checksum}&checksumAlgorithm={checksumAlgorithm}", testData, CHECKSUM, CHECKSUM_ALGORITHM); | |
275 | + otaPackagesWithData.add(new OtaPackageInfo(savedFirmware)); | |
277 | 276 | } else { |
278 | - firmwaresWithoutData.add(savedFirmwareInfo); | |
277 | + otaPackagesWithoutData.add(savedFirmwareInfo); | |
279 | 278 | } |
280 | 279 | } |
281 | 280 | |
282 | - List<FirmwareInfo> loadedFirmwaresWithData = new ArrayList<>(); | |
281 | + List<OtaPackageInfo> loadedFirmwaresWithData = new ArrayList<>(); | |
283 | 282 | PageLink pageLink = new PageLink(24); |
284 | - PageData<FirmwareInfo> pageData; | |
283 | + PageData<OtaPackageInfo> pageData; | |
285 | 284 | do { |
286 | - pageData = doGetTypedWithPageLink("/api/firmwares/" + deviceProfileId.toString() + "/FIRMWARE/true?", | |
285 | + pageData = doGetTypedWithPageLink("/api/otaPackages/" + deviceProfileId.toString() + "/FIRMWARE/true?", | |
287 | 286 | new TypeReference<>() { |
288 | 287 | }, pageLink); |
289 | 288 | loadedFirmwaresWithData.addAll(pageData.getData()); |
... | ... | @@ -292,10 +291,10 @@ public abstract class BaseFirmwareControllerTest extends AbstractControllerTest |
292 | 291 | } |
293 | 292 | } while (pageData.hasNext()); |
294 | 293 | |
295 | - List<FirmwareInfo> loadedFirmwaresWithoutData = new ArrayList<>(); | |
294 | + List<OtaPackageInfo> loadedFirmwaresWithoutData = new ArrayList<>(); | |
296 | 295 | pageLink = new PageLink(24); |
297 | 296 | do { |
298 | - pageData = doGetTypedWithPageLink("/api/firmwares/" + deviceProfileId.toString() + "/FIRMWARE/false?", | |
297 | + pageData = doGetTypedWithPageLink("/api/otaPackages/" + deviceProfileId.toString() + "/FIRMWARE/false?", | |
299 | 298 | new TypeReference<>() { |
300 | 299 | }, pageLink); |
301 | 300 | loadedFirmwaresWithoutData.addAll(pageData.getData()); |
... | ... | @@ -304,25 +303,25 @@ public abstract class BaseFirmwareControllerTest extends AbstractControllerTest |
304 | 303 | } |
305 | 304 | } while (pageData.hasNext()); |
306 | 305 | |
307 | - Collections.sort(firmwaresWithData, idComparator); | |
308 | - Collections.sort(firmwaresWithoutData, idComparator); | |
306 | + Collections.sort(otaPackagesWithData, idComparator); | |
307 | + Collections.sort(otaPackagesWithoutData, idComparator); | |
309 | 308 | Collections.sort(loadedFirmwaresWithData, idComparator); |
310 | 309 | Collections.sort(loadedFirmwaresWithoutData, idComparator); |
311 | 310 | |
312 | - Assert.assertEquals(firmwaresWithData, loadedFirmwaresWithData); | |
313 | - Assert.assertEquals(firmwaresWithoutData, loadedFirmwaresWithoutData); | |
311 | + Assert.assertEquals(otaPackagesWithData, loadedFirmwaresWithData); | |
312 | + Assert.assertEquals(otaPackagesWithoutData, loadedFirmwaresWithoutData); | |
314 | 313 | } |
315 | 314 | |
316 | 315 | |
317 | - private FirmwareInfo save(FirmwareInfo firmwareInfo) throws Exception { | |
318 | - return doPost("/api/firmware", firmwareInfo, FirmwareInfo.class); | |
316 | + private OtaPackageInfo save(OtaPackageInfo firmwareInfo) throws Exception { | |
317 | + return doPost("/api/otaPackage", firmwareInfo, OtaPackageInfo.class); | |
319 | 318 | } |
320 | 319 | |
321 | - protected Firmware savaData(String urlTemplate, MockMultipartFile content, String... params) throws Exception { | |
320 | + protected OtaPackage savaData(String urlTemplate, MockMultipartFile content, String... params) throws Exception { | |
322 | 321 | MockMultipartHttpServletRequestBuilder postRequest = MockMvcRequestBuilders.multipart(urlTemplate, params); |
323 | 322 | postRequest.file(content); |
324 | 323 | setJwtToken(postRequest); |
325 | - return readResponse(mockMvc.perform(postRequest).andExpect(status().isOk()), Firmware.class); | |
324 | + return readResponse(mockMvc.perform(postRequest).andExpect(status().isOk()), OtaPackage.class); | |
326 | 325 | } |
327 | 326 | |
328 | 327 | } | ... | ... |
application/src/test/java/org/thingsboard/server/controller/sql/OtaPackageControllerSqlTest.java
renamed from
application/src/test/java/org/thingsboard/server/controller/sql/FirmwareControllerSqlTest.java
... | ... | @@ -15,9 +15,9 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.controller.sql; |
17 | 17 | |
18 | -import org.thingsboard.server.controller.BaseFirmwareControllerTest; | |
18 | +import org.thingsboard.server.controller.BaseOtaPackageControllerTest; | |
19 | 19 | import org.thingsboard.server.dao.service.DaoSqlTest; |
20 | 20 | |
21 | 21 | @DaoSqlTest |
22 | -public class FirmwareControllerSqlTest extends BaseFirmwareControllerTest { | |
22 | +public class OtaPackageControllerSqlTest extends BaseOtaPackageControllerTest { | |
23 | 23 | } | ... | ... |
common/cache/src/main/java/org/thingsboard/server/cache/ota/CaffeineOtaPackageCache.java
renamed from
common/cache/src/main/java/org/thingsboard/server/cache/firmware/CaffeineFirmwareCache.java
... | ... | @@ -13,19 +13,20 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.cache.firmware; | |
16 | +package org.thingsboard.server.cache.ota; | |
17 | 17 | |
18 | 18 | import lombok.RequiredArgsConstructor; |
19 | 19 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
20 | 20 | import org.springframework.cache.CacheManager; |
21 | 21 | import org.springframework.stereotype.Service; |
22 | 22 | |
23 | -import static org.thingsboard.server.common.data.CacheConstants.FIRMWARE_CACHE; | |
23 | +import static org.thingsboard.server.common.data.CacheConstants.OTA_PACKAGE_CACHE; | |
24 | +import static org.thingsboard.server.common.data.CacheConstants.OTA_PACKAGE_DATA_CACHE; | |
24 | 25 | |
25 | 26 | @Service |
26 | 27 | @ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "caffeine", matchIfMissing = true) |
27 | 28 | @RequiredArgsConstructor |
28 | -public class CaffeineFirmwareCache implements FirmwareDataCache { | |
29 | +public class CaffeineOtaPackageCache implements OtaPackageDataCache { | |
29 | 30 | |
30 | 31 | private final CacheManager cacheManager; |
31 | 32 | |
... | ... | @@ -36,7 +37,7 @@ public class CaffeineFirmwareCache implements FirmwareDataCache { |
36 | 37 | |
37 | 38 | @Override |
38 | 39 | public byte[] get(String key, int chunkSize, int chunk) { |
39 | - byte[] data = cacheManager.getCache(FIRMWARE_CACHE).get(key, byte[].class); | |
40 | + byte[] data = cacheManager.getCache(OTA_PACKAGE_DATA_CACHE).get(key, byte[].class); | |
40 | 41 | |
41 | 42 | if (chunkSize < 1) { |
42 | 43 | return data; |
... | ... | @@ -58,11 +59,11 @@ public class CaffeineFirmwareCache implements FirmwareDataCache { |
58 | 59 | |
59 | 60 | @Override |
60 | 61 | public void put(String key, byte[] value) { |
61 | - cacheManager.getCache(FIRMWARE_CACHE).putIfAbsent(key, value); | |
62 | + cacheManager.getCache(OTA_PACKAGE_DATA_CACHE).putIfAbsent(key, value); | |
62 | 63 | } |
63 | 64 | |
64 | 65 | @Override |
65 | 66 | public void evict(String key) { |
66 | - cacheManager.getCache(FIRMWARE_CACHE).evict(key); | |
67 | + cacheManager.getCache(OTA_PACKAGE_DATA_CACHE).evict(key); | |
67 | 68 | } |
68 | 69 | } | ... | ... |
common/cache/src/main/java/org/thingsboard/server/cache/ota/OtaPackageDataCache.java
renamed from
common/cache/src/main/java/org/thingsboard/server/cache/firmware/FirmwareDataCache.java
... | ... | @@ -13,9 +13,9 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.cache.firmware; | |
16 | +package org.thingsboard.server.cache.ota; | |
17 | 17 | |
18 | -public interface FirmwareDataCache { | |
18 | +public interface OtaPackageDataCache { | |
19 | 19 | |
20 | 20 | byte[] get(String key); |
21 | 21 | |
... | ... | @@ -25,8 +25,8 @@ public interface FirmwareDataCache { |
25 | 25 | |
26 | 26 | void evict(String key); |
27 | 27 | |
28 | - default boolean has(String firmwareId) { | |
29 | - byte[] data = get(firmwareId, 1, 0); | |
28 | + default boolean has(String otaPackageId) { | |
29 | + byte[] data = get(otaPackageId, 1, 0); | |
30 | 30 | return data != null && data.length > 0; |
31 | 31 | } |
32 | 32 | } | ... | ... |
common/cache/src/main/java/org/thingsboard/server/cache/ota/RedisOtaPackageDataCache.java
renamed from
common/cache/src/main/java/org/thingsboard/server/cache/firmware/RedisFirmwareDataCache.java
... | ... | @@ -13,7 +13,7 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.cache.firmware; | |
16 | +package org.thingsboard.server.cache.ota; | |
17 | 17 | |
18 | 18 | import lombok.RequiredArgsConstructor; |
19 | 19 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
... | ... | @@ -21,12 +21,13 @@ import org.springframework.data.redis.connection.RedisConnection; |
21 | 21 | import org.springframework.data.redis.connection.RedisConnectionFactory; |
22 | 22 | import org.springframework.stereotype.Service; |
23 | 23 | |
24 | -import static org.thingsboard.server.common.data.CacheConstants.FIRMWARE_CACHE; | |
24 | +import static org.thingsboard.server.common.data.CacheConstants.OTA_PACKAGE_CACHE; | |
25 | +import static org.thingsboard.server.common.data.CacheConstants.OTA_PACKAGE_DATA_CACHE; | |
25 | 26 | |
26 | 27 | @Service |
27 | 28 | @ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "redis") |
28 | 29 | @RequiredArgsConstructor |
29 | -public class RedisFirmwareDataCache implements FirmwareDataCache { | |
30 | +public class RedisOtaPackageDataCache implements OtaPackageDataCache { | |
30 | 31 | |
31 | 32 | private final RedisConnectionFactory redisConnectionFactory; |
32 | 33 | |
... | ... | @@ -39,30 +40,30 @@ public class RedisFirmwareDataCache implements FirmwareDataCache { |
39 | 40 | public byte[] get(String key, int chunkSize, int chunk) { |
40 | 41 | try (RedisConnection connection = redisConnectionFactory.getConnection()) { |
41 | 42 | if (chunkSize == 0) { |
42 | - return connection.get(toFirmwareCacheKey(key)); | |
43 | + return connection.get(toOtaPackageCacheKey(key)); | |
43 | 44 | } |
44 | 45 | |
45 | 46 | int startIndex = chunkSize * chunk; |
46 | 47 | int endIndex = startIndex + chunkSize - 1; |
47 | - return connection.getRange(toFirmwareCacheKey(key), startIndex, endIndex); | |
48 | + return connection.getRange(toOtaPackageCacheKey(key), startIndex, endIndex); | |
48 | 49 | } |
49 | 50 | } |
50 | 51 | |
51 | 52 | @Override |
52 | 53 | public void put(String key, byte[] value) { |
53 | 54 | try (RedisConnection connection = redisConnectionFactory.getConnection()) { |
54 | - connection.set(toFirmwareCacheKey(key), value); | |
55 | + connection.set(toOtaPackageCacheKey(key), value); | |
55 | 56 | } |
56 | 57 | } |
57 | 58 | |
58 | 59 | @Override |
59 | 60 | public void evict(String key) { |
60 | 61 | try (RedisConnection connection = redisConnectionFactory.getConnection()) { |
61 | - connection.del(toFirmwareCacheKey(key)); | |
62 | + connection.del(toOtaPackageCacheKey(key)); | |
62 | 63 | } |
63 | 64 | } |
64 | 65 | |
65 | - private byte[] toFirmwareCacheKey(String key) { | |
66 | - return String.format("%s::%s", FIRMWARE_CACHE, key).getBytes(); | |
66 | + private byte[] toOtaPackageCacheKey(String key) { | |
67 | + return String.format("%s::%s", OTA_PACKAGE_DATA_CACHE, key).getBytes(); | |
67 | 68 | } |
68 | 69 | } | ... | ... |
... | ... | @@ -27,6 +27,7 @@ import org.thingsboard.server.common.data.id.DeviceId; |
27 | 27 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
28 | 28 | import org.thingsboard.server.common.data.id.EdgeId; |
29 | 29 | import org.thingsboard.server.common.data.id.TenantId; |
30 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | |
30 | 31 | import org.thingsboard.server.common.data.page.PageData; |
31 | 32 | import org.thingsboard.server.common.data.page.PageLink; |
32 | 33 | import org.thingsboard.server.common.data.security.DeviceCredentials; |
... | ... | @@ -63,9 +64,9 @@ public interface DeviceService { |
63 | 64 | |
64 | 65 | PageData<Device> findDevicesByTenantIdAndType(TenantId tenantId, String type, PageLink pageLink); |
65 | 66 | |
66 | - PageData<Device> findDevicesByTenantIdAndTypeAndEmptyFirmware(TenantId tenantId, String type, PageLink pageLink); | |
67 | + PageData<Device> findDevicesByTenantIdAndTypeAndEmptyOtaPackage(TenantId tenantId, DeviceProfileId deviceProfileId, OtaPackageType type, PageLink pageLink); | |
67 | 68 | |
68 | - PageData<Device> findDevicesByTenantIdAndTypeAndEmptySoftware(TenantId tenantId, String type, PageLink pageLink); | |
69 | + Long countDevicesByTenantIdAndDeviceProfileIdAndEmptyOtaPackage(TenantId tenantId, DeviceProfileId deviceProfileId, OtaPackageType otaPackageType); | |
69 | 70 | |
70 | 71 | PageData<DeviceInfo> findDeviceInfosByTenantIdAndType(TenantId tenantId, String type, PageLink pageLink); |
71 | 72 | ... | ... |
common/dao-api/src/main/java/org/thingsboard/server/dao/ota/OtaPackageService.java
renamed from
common/dao-api/src/main/java/org/thingsboard/server/dao/firmware/FirmwareService.java
... | ... | @@ -13,40 +13,40 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.dao.firmware; | |
16 | +package org.thingsboard.server.dao.ota; | |
17 | 17 | |
18 | 18 | import com.google.common.util.concurrent.ListenableFuture; |
19 | -import org.thingsboard.server.common.data.Firmware; | |
20 | -import org.thingsboard.server.common.data.FirmwareInfo; | |
21 | -import org.thingsboard.server.common.data.firmware.ChecksumAlgorithm; | |
22 | -import org.thingsboard.server.common.data.firmware.FirmwareType; | |
19 | +import org.thingsboard.server.common.data.OtaPackage; | |
20 | +import org.thingsboard.server.common.data.OtaPackageInfo; | |
21 | +import org.thingsboard.server.common.data.ota.ChecksumAlgorithm; | |
22 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | |
23 | 23 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
24 | -import org.thingsboard.server.common.data.id.FirmwareId; | |
24 | +import org.thingsboard.server.common.data.id.OtaPackageId; | |
25 | 25 | import org.thingsboard.server.common.data.id.TenantId; |
26 | 26 | import org.thingsboard.server.common.data.page.PageData; |
27 | 27 | import org.thingsboard.server.common.data.page.PageLink; |
28 | 28 | |
29 | 29 | import java.nio.ByteBuffer; |
30 | 30 | |
31 | -public interface FirmwareService { | |
31 | +public interface OtaPackageService { | |
32 | 32 | |
33 | - FirmwareInfo saveFirmwareInfo(FirmwareInfo firmwareInfo); | |
33 | + OtaPackageInfo saveOtaPackageInfo(OtaPackageInfo otaPackageInfo); | |
34 | 34 | |
35 | - Firmware saveFirmware(Firmware firmware); | |
35 | + OtaPackage saveOtaPackage(OtaPackage otaPackage); | |
36 | 36 | |
37 | 37 | String generateChecksum(ChecksumAlgorithm checksumAlgorithm, ByteBuffer data); |
38 | 38 | |
39 | - Firmware findFirmwareById(TenantId tenantId, FirmwareId firmwareId); | |
39 | + OtaPackage findOtaPackageById(TenantId tenantId, OtaPackageId otaPackageId); | |
40 | 40 | |
41 | - FirmwareInfo findFirmwareInfoById(TenantId tenantId, FirmwareId firmwareId); | |
41 | + OtaPackageInfo findOtaPackageInfoById(TenantId tenantId, OtaPackageId otaPackageId); | |
42 | 42 | |
43 | - ListenableFuture<FirmwareInfo> findFirmwareInfoByIdAsync(TenantId tenantId, FirmwareId firmwareId); | |
43 | + ListenableFuture<OtaPackageInfo> findOtaPackageInfoByIdAsync(TenantId tenantId, OtaPackageId otaPackageId); | |
44 | 44 | |
45 | - PageData<FirmwareInfo> findTenantFirmwaresByTenantId(TenantId tenantId, PageLink pageLink); | |
45 | + PageData<OtaPackageInfo> findTenantOtaPackagesByTenantId(TenantId tenantId, PageLink pageLink); | |
46 | 46 | |
47 | - PageData<FirmwareInfo> findTenantFirmwaresByTenantIdAndDeviceProfileIdAndTypeAndHasData(TenantId tenantId, DeviceProfileId deviceProfileId, FirmwareType firmwareType, boolean hasData, PageLink pageLink); | |
47 | + PageData<OtaPackageInfo> findTenantOtaPackagesByTenantIdAndDeviceProfileIdAndTypeAndHasData(TenantId tenantId, DeviceProfileId deviceProfileId, OtaPackageType otaPackageType, boolean hasData, PageLink pageLink); | |
48 | 48 | |
49 | - void deleteFirmware(TenantId tenantId, FirmwareId firmwareId); | |
49 | + void deleteOtaPackage(TenantId tenantId, OtaPackageId otaPackageId); | |
50 | 50 | |
51 | - void deleteFirmwaresByTenantId(TenantId tenantId); | |
51 | + void deleteOtaPackagesByTenantId(TenantId tenantId); | |
52 | 52 | } | ... | ... |
... | ... | @@ -29,5 +29,6 @@ public class CacheConstants { |
29 | 29 | public static final String DEVICE_PROFILE_CACHE = "deviceProfiles"; |
30 | 30 | public static final String ATTRIBUTES_CACHE = "attributes"; |
31 | 31 | public static final String TOKEN_OUTDATAGE_TIME_CACHE = "tokensOutdatageTime"; |
32 | - public static final String FIRMWARE_CACHE = "firmwares"; | |
32 | + public static final String OTA_PACKAGE_CACHE = "otaPackages"; | |
33 | + public static final String OTA_PACKAGE_DATA_CACHE = "otaPackagesData"; | |
33 | 34 | } | ... | ... |
... | ... | @@ -23,7 +23,7 @@ import org.thingsboard.server.common.data.device.data.DeviceData; |
23 | 23 | import org.thingsboard.server.common.data.id.CustomerId; |
24 | 24 | import org.thingsboard.server.common.data.id.DeviceId; |
25 | 25 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
26 | -import org.thingsboard.server.common.data.id.FirmwareId; | |
26 | +import org.thingsboard.server.common.data.id.OtaPackageId; | |
27 | 27 | import org.thingsboard.server.common.data.id.TenantId; |
28 | 28 | import org.thingsboard.server.common.data.validation.NoXss; |
29 | 29 | |
... | ... | @@ -32,7 +32,7 @@ import java.io.IOException; |
32 | 32 | |
33 | 33 | @EqualsAndHashCode(callSuper = true) |
34 | 34 | @Slf4j |
35 | -public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implements HasName, HasTenantId, HasCustomerId, HasFirmware { | |
35 | +public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implements HasName, HasTenantId, HasCustomerId, HasOtaPackage { | |
36 | 36 | |
37 | 37 | private static final long serialVersionUID = 2807343040519543363L; |
38 | 38 | |
... | ... | @@ -49,8 +49,8 @@ public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implemen |
49 | 49 | @JsonIgnore |
50 | 50 | private byte[] deviceDataBytes; |
51 | 51 | |
52 | - private FirmwareId firmwareId; | |
53 | - private FirmwareId softwareId; | |
52 | + private OtaPackageId firmwareId; | |
53 | + private OtaPackageId softwareId; | |
54 | 54 | |
55 | 55 | public Device() { |
56 | 56 | super(); |
... | ... | @@ -167,19 +167,19 @@ public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implemen |
167 | 167 | return getName(); |
168 | 168 | } |
169 | 169 | |
170 | - public FirmwareId getFirmwareId() { | |
170 | + public OtaPackageId getFirmwareId() { | |
171 | 171 | return firmwareId; |
172 | 172 | } |
173 | 173 | |
174 | - public void setFirmwareId(FirmwareId firmwareId) { | |
174 | + public void setFirmwareId(OtaPackageId firmwareId) { | |
175 | 175 | this.firmwareId = firmwareId; |
176 | 176 | } |
177 | 177 | |
178 | - public FirmwareId getSoftwareId() { | |
178 | + public OtaPackageId getSoftwareId() { | |
179 | 179 | return softwareId; |
180 | 180 | } |
181 | 181 | |
182 | - public void setSoftwareId(FirmwareId softwareId) { | |
182 | + public void setSoftwareId(OtaPackageId softwareId) { | |
183 | 183 | this.softwareId = softwareId; |
184 | 184 | } |
185 | 185 | ... | ... |
... | ... | @@ -23,7 +23,7 @@ import lombok.extern.slf4j.Slf4j; |
23 | 23 | import org.thingsboard.server.common.data.device.profile.DeviceProfileData; |
24 | 24 | import org.thingsboard.server.common.data.id.DashboardId; |
25 | 25 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
26 | -import org.thingsboard.server.common.data.id.FirmwareId; | |
26 | +import org.thingsboard.server.common.data.id.OtaPackageId; | |
27 | 27 | import org.thingsboard.server.common.data.id.RuleChainId; |
28 | 28 | import org.thingsboard.server.common.data.id.TenantId; |
29 | 29 | import org.thingsboard.server.common.data.validation.NoXss; |
... | ... | @@ -37,7 +37,7 @@ import static org.thingsboard.server.common.data.SearchTextBasedWithAdditionalIn |
37 | 37 | @Data |
38 | 38 | @EqualsAndHashCode(callSuper = true) |
39 | 39 | @Slf4j |
40 | -public class DeviceProfile extends SearchTextBased<DeviceProfileId> implements HasName, HasTenantId, HasFirmware { | |
40 | +public class DeviceProfile extends SearchTextBased<DeviceProfileId> implements HasName, HasTenantId, HasOtaPackage { | |
41 | 41 | |
42 | 42 | private TenantId tenantId; |
43 | 43 | @NoXss |
... | ... | @@ -60,9 +60,9 @@ public class DeviceProfile extends SearchTextBased<DeviceProfileId> implements H |
60 | 60 | @NoXss |
61 | 61 | private String provisionDeviceKey; |
62 | 62 | |
63 | - private FirmwareId firmwareId; | |
63 | + private OtaPackageId firmwareId; | |
64 | 64 | |
65 | - private FirmwareId softwareId; | |
65 | + private OtaPackageId softwareId; | |
66 | 66 | |
67 | 67 | public DeviceProfile() { |
68 | 68 | super(); | ... | ... |
... | ... | @@ -19,5 +19,5 @@ package org.thingsboard.server.common.data; |
19 | 19 | * @author Andrew Shvayka |
20 | 20 | */ |
21 | 21 | public enum EntityType { |
22 | - TENANT, CUSTOMER, USER, DASHBOARD, ASSET, DEVICE, ALARM, RULE_CHAIN, RULE_NODE, ENTITY_VIEW, WIDGETS_BUNDLE, WIDGET_TYPE, TENANT_PROFILE, DEVICE_PROFILE, API_USAGE_STATE, TB_RESOURCE, FIRMWARE, EDGE; | |
22 | + TENANT, CUSTOMER, USER, DASHBOARD, ASSET, DEVICE, ALARM, RULE_CHAIN, RULE_NODE, ENTITY_VIEW, WIDGETS_BUNDLE, WIDGET_TYPE, TENANT_PROFILE, DEVICE_PROFILE, API_USAGE_STATE, TB_RESOURCE, OTA_PACKAGE, EDGE; | |
23 | 23 | } | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/HasOtaPackage.java
renamed from
common/data/src/main/java/org/thingsboard/server/common/data/HasFirmware.java
... | ... | @@ -15,11 +15,11 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.common.data; |
17 | 17 | |
18 | -import org.thingsboard.server.common.data.id.FirmwareId; | |
18 | +import org.thingsboard.server.common.data.id.OtaPackageId; | |
19 | 19 | |
20 | -public interface HasFirmware { | |
20 | +public interface HasOtaPackage { | |
21 | 21 | |
22 | - FirmwareId getFirmwareId(); | |
22 | + OtaPackageId getFirmwareId(); | |
23 | 23 | |
24 | - FirmwareId getSoftwareId(); | |
24 | + OtaPackageId getSoftwareId(); | |
25 | 25 | } | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/OtaPackage.java
renamed from
common/data/src/main/java/org/thingsboard/server/common/data/Firmware.java
... | ... | @@ -17,27 +17,27 @@ package org.thingsboard.server.common.data; |
17 | 17 | |
18 | 18 | import lombok.Data; |
19 | 19 | import lombok.EqualsAndHashCode; |
20 | -import org.thingsboard.server.common.data.id.FirmwareId; | |
20 | +import org.thingsboard.server.common.data.id.OtaPackageId; | |
21 | 21 | |
22 | 22 | import java.nio.ByteBuffer; |
23 | 23 | |
24 | 24 | @Data |
25 | 25 | @EqualsAndHashCode(callSuper = true) |
26 | -public class Firmware extends FirmwareInfo { | |
26 | +public class OtaPackage extends OtaPackageInfo { | |
27 | 27 | |
28 | 28 | private static final long serialVersionUID = 3091601761339422546L; |
29 | 29 | |
30 | 30 | private transient ByteBuffer data; |
31 | 31 | |
32 | - public Firmware() { | |
32 | + public OtaPackage() { | |
33 | 33 | super(); |
34 | 34 | } |
35 | 35 | |
36 | - public Firmware(FirmwareId id) { | |
36 | + public OtaPackage(OtaPackageId id) { | |
37 | 37 | super(id); |
38 | 38 | } |
39 | 39 | |
40 | - public Firmware(Firmware firmware) { | |
40 | + public OtaPackage(OtaPackage firmware) { | |
41 | 41 | super(firmware); |
42 | 42 | this.data = firmware.getData(); |
43 | 43 | } | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/OtaPackageInfo.java
renamed from
common/data/src/main/java/org/thingsboard/server/common/data/FirmwareInfo.java
... | ... | @@ -19,22 +19,22 @@ import com.fasterxml.jackson.annotation.JsonIgnore; |
19 | 19 | import lombok.Data; |
20 | 20 | import lombok.EqualsAndHashCode; |
21 | 21 | import lombok.extern.slf4j.Slf4j; |
22 | -import org.thingsboard.server.common.data.firmware.ChecksumAlgorithm; | |
23 | -import org.thingsboard.server.common.data.firmware.FirmwareType; | |
22 | +import org.thingsboard.server.common.data.ota.ChecksumAlgorithm; | |
23 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | |
24 | 24 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
25 | -import org.thingsboard.server.common.data.id.FirmwareId; | |
25 | +import org.thingsboard.server.common.data.id.OtaPackageId; | |
26 | 26 | import org.thingsboard.server.common.data.id.TenantId; |
27 | 27 | |
28 | 28 | @Slf4j |
29 | 29 | @Data |
30 | 30 | @EqualsAndHashCode(callSuper = true) |
31 | -public class FirmwareInfo extends SearchTextBasedWithAdditionalInfo<FirmwareId> implements HasName, HasTenantId { | |
31 | +public class OtaPackageInfo extends SearchTextBasedWithAdditionalInfo<OtaPackageId> implements HasName, HasTenantId { | |
32 | 32 | |
33 | 33 | private static final long serialVersionUID = 3168391583570815419L; |
34 | 34 | |
35 | 35 | private TenantId tenantId; |
36 | 36 | private DeviceProfileId deviceProfileId; |
37 | - private FirmwareType type; | |
37 | + private OtaPackageType type; | |
38 | 38 | private String title; |
39 | 39 | private String version; |
40 | 40 | private boolean hasData; |
... | ... | @@ -45,27 +45,27 @@ public class FirmwareInfo extends SearchTextBasedWithAdditionalInfo<FirmwareId> |
45 | 45 | private Long dataSize; |
46 | 46 | |
47 | 47 | |
48 | - public FirmwareInfo() { | |
48 | + public OtaPackageInfo() { | |
49 | 49 | super(); |
50 | 50 | } |
51 | 51 | |
52 | - public FirmwareInfo(FirmwareId id) { | |
52 | + public OtaPackageInfo(OtaPackageId id) { | |
53 | 53 | super(id); |
54 | 54 | } |
55 | 55 | |
56 | - public FirmwareInfo(FirmwareInfo firmwareInfo) { | |
57 | - super(firmwareInfo); | |
58 | - this.tenantId = firmwareInfo.getTenantId(); | |
59 | - this.deviceProfileId = firmwareInfo.getDeviceProfileId(); | |
60 | - this.type = firmwareInfo.getType(); | |
61 | - this.title = firmwareInfo.getTitle(); | |
62 | - this.version = firmwareInfo.getVersion(); | |
63 | - this.hasData = firmwareInfo.isHasData(); | |
64 | - this.fileName = firmwareInfo.getFileName(); | |
65 | - this.contentType = firmwareInfo.getContentType(); | |
66 | - this.checksumAlgorithm = firmwareInfo.getChecksumAlgorithm(); | |
67 | - this.checksum = firmwareInfo.getChecksum(); | |
68 | - this.dataSize = firmwareInfo.getDataSize(); | |
56 | + public OtaPackageInfo(OtaPackageInfo otaPackageInfo) { | |
57 | + super(otaPackageInfo); | |
58 | + this.tenantId = otaPackageInfo.getTenantId(); | |
59 | + this.deviceProfileId = otaPackageInfo.getDeviceProfileId(); | |
60 | + this.type = otaPackageInfo.getType(); | |
61 | + this.title = otaPackageInfo.getTitle(); | |
62 | + this.version = otaPackageInfo.getVersion(); | |
63 | + this.hasData = otaPackageInfo.isHasData(); | |
64 | + this.fileName = otaPackageInfo.getFileName(); | |
65 | + this.contentType = otaPackageInfo.getContentType(); | |
66 | + this.checksumAlgorithm = otaPackageInfo.getChecksumAlgorithm(); | |
67 | + this.checksum = otaPackageInfo.getChecksum(); | |
68 | + this.dataSize = otaPackageInfo.getDataSize(); | |
69 | 69 | } |
70 | 70 | |
71 | 71 | @Override | ... | ... |
... | ... | @@ -71,8 +71,8 @@ public class EntityIdFactory { |
71 | 71 | return new ApiUsageStateId(uuid); |
72 | 72 | case TB_RESOURCE: |
73 | 73 | return new TbResourceId(uuid); |
74 | - case FIRMWARE: | |
75 | - return new FirmwareId(uuid); | |
74 | + case OTA_PACKAGE: | |
75 | + return new OtaPackageId(uuid); | |
76 | 76 | case EDGE: |
77 | 77 | return new EdgeId(uuid); |
78 | 78 | } | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/id/OtaPackageId.java
renamed from
common/data/src/main/java/org/thingsboard/server/common/data/id/FirmwareId.java
... | ... | @@ -22,23 +22,23 @@ import org.thingsboard.server.common.data.EntityType; |
22 | 22 | |
23 | 23 | import java.util.UUID; |
24 | 24 | |
25 | -public class FirmwareId extends UUIDBased implements EntityId { | |
25 | +public class OtaPackageId extends UUIDBased implements EntityId { | |
26 | 26 | |
27 | 27 | private static final long serialVersionUID = 1L; |
28 | 28 | |
29 | 29 | @JsonCreator |
30 | - public FirmwareId(@JsonProperty("id") UUID id) { | |
30 | + public OtaPackageId(@JsonProperty("id") UUID id) { | |
31 | 31 | super(id); |
32 | 32 | } |
33 | 33 | |
34 | - public static FirmwareId fromString(String firmwareId) { | |
35 | - return new FirmwareId(UUID.fromString(firmwareId)); | |
34 | + public static OtaPackageId fromString(String firmwareId) { | |
35 | + return new OtaPackageId(UUID.fromString(firmwareId)); | |
36 | 36 | } |
37 | 37 | |
38 | 38 | @JsonIgnore |
39 | 39 | @Override |
40 | 40 | public EntityType getEntityType() { |
41 | - return EntityType.FIRMWARE; | |
41 | + return EntityType.OTA_PACKAGE; | |
42 | 42 | } |
43 | 43 | |
44 | 44 | } | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/ota/ChecksumAlgorithm.java
renamed from
common/data/src/main/java/org/thingsboard/server/common/data/firmware/ChecksumAlgorithm.java
... | ... | @@ -13,7 +13,7 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.common.data.firmware; | |
16 | +package org.thingsboard.server.common.data.ota; | |
17 | 17 | |
18 | 18 | public enum ChecksumAlgorithm { |
19 | 19 | MD5, | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/ota/OtaPackageKey.java
renamed from
common/data/src/main/java/org/thingsboard/server/common/data/firmware/FirmwareKey.java
... | ... | @@ -13,18 +13,18 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.common.data.firmware; | |
16 | +package org.thingsboard.server.common.data.ota; | |
17 | 17 | |
18 | 18 | import lombok.Getter; |
19 | 19 | |
20 | -public enum FirmwareKey { | |
20 | +public enum OtaPackageKey { | |
21 | 21 | |
22 | 22 | TITLE("title"), VERSION("version"), TS("ts"), STATE("state"), SIZE("size"), CHECKSUM("checksum"), CHECKSUM_ALGORITHM("checksum_algorithm"); |
23 | 23 | |
24 | 24 | @Getter |
25 | 25 | private final String value; |
26 | 26 | |
27 | - FirmwareKey(String value) { | |
27 | + OtaPackageKey(String value) { | |
28 | 28 | this.value = value; |
29 | 29 | } |
30 | 30 | } | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/ota/OtaPackageType.java
renamed from
common/data/src/main/java/org/thingsboard/server/common/data/firmware/FirmwareType.java
... | ... | @@ -13,18 +13,18 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.common.data.firmware; | |
16 | +package org.thingsboard.server.common.data.ota; | |
17 | 17 | |
18 | 18 | import lombok.Getter; |
19 | 19 | |
20 | -public enum FirmwareType { | |
20 | +public enum OtaPackageType { | |
21 | 21 | |
22 | 22 | FIRMWARE("fw"), SOFTWARE("sw"); |
23 | 23 | |
24 | 24 | @Getter |
25 | 25 | private final String keyPrefix; |
26 | 26 | |
27 | - FirmwareType(String keyPrefix) { | |
27 | + OtaPackageType(String keyPrefix) { | |
28 | 28 | this.keyPrefix = keyPrefix; |
29 | 29 | } |
30 | 30 | } | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/ota/OtaPackageUpdateStatus.java
renamed from
common/data/src/main/java/org/thingsboard/server/common/data/firmware/FirmwareUpdateStatus.java
... | ... | @@ -13,8 +13,8 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.common.data.firmware; | |
16 | +package org.thingsboard.server.common.data.ota; | |
17 | 17 | |
18 | -public enum FirmwareUpdateStatus { | |
18 | +public enum OtaPackageUpdateStatus { | |
19 | 19 | QUEUED, INITIATED, DOWNLOADING, DOWNLOADED, VERIFIED, UPDATING, UPDATED, FAILED |
20 | 20 | } | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/ota/OtaPackageUtil.java
renamed from
common/data/src/main/java/org/thingsboard/server/common/data/firmware/FirmwareUtil.java
... | ... | @@ -13,21 +13,19 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.common.data.firmware; | |
16 | +package org.thingsboard.server.common.data.ota; | |
17 | 17 | |
18 | 18 | import lombok.extern.slf4j.Slf4j; |
19 | -import org.thingsboard.server.common.data.HasFirmware; | |
20 | -import org.thingsboard.server.common.data.id.FirmwareId; | |
19 | +import org.thingsboard.server.common.data.HasOtaPackage; | |
20 | +import org.thingsboard.server.common.data.id.OtaPackageId; | |
21 | 21 | |
22 | 22 | import java.util.ArrayList; |
23 | 23 | import java.util.Collections; |
24 | 24 | import java.util.List; |
25 | - | |
26 | -import static org.thingsboard.server.common.data.firmware.FirmwareType.FIRMWARE; | |
27 | -import static org.thingsboard.server.common.data.firmware.FirmwareType.SOFTWARE; | |
25 | +import java.util.function.Supplier; | |
28 | 26 | |
29 | 27 | @Slf4j |
30 | -public class FirmwareUtil { | |
28 | +public class OtaPackageUtil { | |
31 | 29 | |
32 | 30 | public static final List<String> ALL_FW_ATTRIBUTE_KEYS; |
33 | 31 | |
... | ... | @@ -35,19 +33,19 @@ public class FirmwareUtil { |
35 | 33 | |
36 | 34 | static { |
37 | 35 | ALL_FW_ATTRIBUTE_KEYS = new ArrayList<>(); |
38 | - for (FirmwareKey key : FirmwareKey.values()) { | |
39 | - ALL_FW_ATTRIBUTE_KEYS.add(getAttributeKey(FIRMWARE, key)); | |
36 | + for (OtaPackageKey key : OtaPackageKey.values()) { | |
37 | + ALL_FW_ATTRIBUTE_KEYS.add(getAttributeKey(OtaPackageType.FIRMWARE, key)); | |
40 | 38 | |
41 | 39 | } |
42 | 40 | |
43 | 41 | ALL_SW_ATTRIBUTE_KEYS = new ArrayList<>(); |
44 | - for (FirmwareKey key : FirmwareKey.values()) { | |
45 | - ALL_SW_ATTRIBUTE_KEYS.add(getAttributeKey(SOFTWARE, key)); | |
42 | + for (OtaPackageKey key : OtaPackageKey.values()) { | |
43 | + ALL_SW_ATTRIBUTE_KEYS.add(getAttributeKey(OtaPackageType.SOFTWARE, key)); | |
46 | 44 | |
47 | 45 | } |
48 | 46 | } |
49 | 47 | |
50 | - public static List<String> getAttributeKeys(FirmwareType firmwareType) { | |
48 | + public static List<String> getAttributeKeys(OtaPackageType firmwareType) { | |
51 | 49 | switch (firmwareType) { |
52 | 50 | case FIRMWARE: |
53 | 51 | return ALL_FW_ATTRIBUTE_KEYS; |
... | ... | @@ -57,35 +55,46 @@ public class FirmwareUtil { |
57 | 55 | return Collections.emptyList(); |
58 | 56 | } |
59 | 57 | |
60 | - public static String getAttributeKey(FirmwareType type, FirmwareKey key) { | |
58 | + public static String getAttributeKey(OtaPackageType type, OtaPackageKey key) { | |
61 | 59 | return type.getKeyPrefix() + "_" + key.getValue(); |
62 | 60 | } |
63 | 61 | |
64 | - public static String getTargetTelemetryKey(FirmwareType type, FirmwareKey key) { | |
62 | + public static String getTargetTelemetryKey(OtaPackageType type, OtaPackageKey key) { | |
65 | 63 | return getTelemetryKey("target_", type, key); |
66 | 64 | } |
67 | 65 | |
68 | - public static String getCurrentTelemetryKey(FirmwareType type, FirmwareKey key) { | |
66 | + public static String getCurrentTelemetryKey(OtaPackageType type, OtaPackageKey key) { | |
69 | 67 | return getTelemetryKey("current_", type, key); |
70 | 68 | } |
71 | 69 | |
72 | - private static String getTelemetryKey(String prefix, FirmwareType type, FirmwareKey key) { | |
70 | + private static String getTelemetryKey(String prefix, OtaPackageType type, OtaPackageKey key) { | |
73 | 71 | return prefix + type.getKeyPrefix() + "_" + key.getValue(); |
74 | 72 | } |
75 | 73 | |
76 | - public static String getTelemetryKey(FirmwareType type, FirmwareKey key) { | |
74 | + public static String getTelemetryKey(OtaPackageType type, OtaPackageKey key) { | |
77 | 75 | return type.getKeyPrefix() + "_" + key.getValue(); |
78 | 76 | } |
79 | 77 | |
80 | - public static FirmwareId getFirmwareId(HasFirmware entity, FirmwareType firmwareType) { | |
81 | - switch (firmwareType) { | |
78 | + public static OtaPackageId getOtaPackageId(HasOtaPackage entity, OtaPackageType type) { | |
79 | + switch (type) { | |
82 | 80 | case FIRMWARE: |
83 | 81 | return entity.getFirmwareId(); |
84 | 82 | case SOFTWARE: |
85 | 83 | return entity.getSoftwareId(); |
86 | 84 | default: |
87 | - log.warn("Unsupported firmware type: [{}]", firmwareType); | |
85 | + log.warn("Unsupported ota package type: [{}]", type); | |
88 | 86 | return null; |
89 | 87 | } |
90 | 88 | } |
89 | + | |
90 | + public static <T> T getByOtaPackageType(Supplier<T> firmwareSupplier, Supplier<T> softwareSupplier, OtaPackageType type) { | |
91 | + switch (type) { | |
92 | + case FIRMWARE: | |
93 | + return firmwareSupplier.get(); | |
94 | + case SOFTWARE: | |
95 | + return softwareSupplier.get(); | |
96 | + default: | |
97 | + throw new RuntimeException("Unsupported OtaPackage type: " + type); | |
98 | + } | |
99 | + } | |
91 | 100 | } | ... | ... |
... | ... | @@ -38,7 +38,7 @@ public class TbKafkaTopicConfigs { |
38 | 38 | private String notificationsProperties; |
39 | 39 | @Value("${queue.kafka.topic-properties.js-executor}") |
40 | 40 | private String jsExecutorProperties; |
41 | - @Value("${queue.kafka.topic-properties.fw-updates:}") | |
41 | + @Value("${queue.kafka.topic-properties.ota-updates:}") | |
42 | 42 | private String fwUpdatesProperties; |
43 | 43 | |
44 | 44 | @Getter | ... | ... |
... | ... | @@ -187,14 +187,14 @@ public class AwsSqsMonolithQueueFactory implements TbCoreQueueFactory, TbRuleEng |
187 | 187 | } |
188 | 188 | |
189 | 189 | @Override |
190 | - public TbQueueConsumer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> createToFirmwareStateServiceMsgConsumer() { | |
191 | - return new TbAwsSqsConsumerTemplate<>(transportApiAdmin, sqsSettings, coreSettings.getFirmwareTopic(), | |
192 | - msg -> new TbProtoQueueMsg<>(msg.getKey(), ToFirmwareStateServiceMsg.parseFrom(msg.getData()), msg.getHeaders())); | |
190 | + public TbQueueConsumer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> createToOtaPackageStateServiceMsgConsumer() { | |
191 | + return new TbAwsSqsConsumerTemplate<>(transportApiAdmin, sqsSettings, coreSettings.getOtaPackageTopic(), | |
192 | + msg -> new TbProtoQueueMsg<>(msg.getKey(), ToOtaPackageStateServiceMsg.parseFrom(msg.getData()), msg.getHeaders())); | |
193 | 193 | } |
194 | 194 | |
195 | 195 | @Override |
196 | - public TbQueueProducer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> createToFirmwareStateServiceMsgProducer() { | |
197 | - return new TbAwsSqsProducerTemplate<>(coreAdmin, sqsSettings, coreSettings.getFirmwareTopic()); | |
196 | + public TbQueueProducer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> createToOtaPackageStateServiceMsgProducer() { | |
197 | + return new TbAwsSqsProducerTemplate<>(coreAdmin, sqsSettings, coreSettings.getOtaPackageTopic()); | |
198 | 198 | } |
199 | 199 | |
200 | 200 | @PreDestroy | ... | ... |
... | ... | @@ -23,7 +23,7 @@ import org.thingsboard.server.common.msg.queue.ServiceType; |
23 | 23 | import org.thingsboard.server.gen.js.JsInvokeProtos; |
24 | 24 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
25 | 25 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; |
26 | -import org.thingsboard.server.gen.transport.TransportProtos.ToFirmwareStateServiceMsg; | |
26 | +import org.thingsboard.server.gen.transport.TransportProtos.ToOtaPackageStateServiceMsg; | |
27 | 27 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; |
28 | 28 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; |
29 | 29 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; |
... | ... | @@ -177,14 +177,14 @@ public class AwsSqsTbCoreQueueFactory implements TbCoreQueueFactory { |
177 | 177 | } |
178 | 178 | |
179 | 179 | @Override |
180 | - public TbQueueConsumer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> createToFirmwareStateServiceMsgConsumer() { | |
181 | - return new TbAwsSqsConsumerTemplate<>(transportApiAdmin, sqsSettings, coreSettings.getFirmwareTopic(), | |
182 | - msg -> new TbProtoQueueMsg<>(msg.getKey(), ToFirmwareStateServiceMsg.parseFrom(msg.getData()), msg.getHeaders())); | |
180 | + public TbQueueConsumer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> createToOtaPackageStateServiceMsgConsumer() { | |
181 | + return new TbAwsSqsConsumerTemplate<>(transportApiAdmin, sqsSettings, coreSettings.getOtaPackageTopic(), | |
182 | + msg -> new TbProtoQueueMsg<>(msg.getKey(), ToOtaPackageStateServiceMsg.parseFrom(msg.getData()), msg.getHeaders())); | |
183 | 183 | } |
184 | 184 | |
185 | 185 | @Override |
186 | - public TbQueueProducer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> createToFirmwareStateServiceMsgProducer() { | |
187 | - return new TbAwsSqsProducerTemplate<>(coreAdmin, sqsSettings, coreSettings.getFirmwareTopic()); | |
186 | + public TbQueueProducer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> createToOtaPackageStateServiceMsgProducer() { | |
187 | + return new TbAwsSqsProducerTemplate<>(coreAdmin, sqsSettings, coreSettings.getOtaPackageTopic()); | |
188 | 188 | } |
189 | 189 | |
190 | 190 | @PreDestroy | ... | ... |
... | ... | @@ -131,13 +131,13 @@ public class InMemoryMonolithQueueFactory implements TbCoreQueueFactory, TbRuleE |
131 | 131 | } |
132 | 132 | |
133 | 133 | @Override |
134 | - public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.ToFirmwareStateServiceMsg>> createToFirmwareStateServiceMsgConsumer() { | |
135 | - return new InMemoryTbQueueConsumer<>(coreSettings.getFirmwareTopic()); | |
134 | + public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.ToOtaPackageStateServiceMsg>> createToOtaPackageStateServiceMsgConsumer() { | |
135 | + return new InMemoryTbQueueConsumer<>(coreSettings.getOtaPackageTopic()); | |
136 | 136 | } |
137 | 137 | |
138 | 138 | @Override |
139 | - public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToFirmwareStateServiceMsg>> createToFirmwareStateServiceMsgProducer() { | |
140 | - return new InMemoryTbQueueProducer<>(coreSettings.getFirmwareTopic()); | |
139 | + public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToOtaPackageStateServiceMsg>> createToOtaPackageStateServiceMsgProducer() { | |
140 | + return new InMemoryTbQueueProducer<>(coreSettings.getOtaPackageTopic()); | |
141 | 141 | } |
142 | 142 | |
143 | 143 | @Override | ... | ... |
... | ... | @@ -23,7 +23,7 @@ import org.thingsboard.server.common.msg.queue.ServiceType; |
23 | 23 | import org.thingsboard.server.gen.js.JsInvokeProtos; |
24 | 24 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
25 | 25 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; |
26 | -import org.thingsboard.server.gen.transport.TransportProtos.ToFirmwareStateServiceMsg; | |
26 | +import org.thingsboard.server.gen.transport.TransportProtos.ToOtaPackageStateServiceMsg; | |
27 | 27 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; |
28 | 28 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; |
29 | 29 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; |
... | ... | @@ -277,24 +277,24 @@ public class KafkaMonolithQueueFactory implements TbCoreQueueFactory, TbRuleEngi |
277 | 277 | } |
278 | 278 | |
279 | 279 | @Override |
280 | - public TbQueueConsumer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> createToFirmwareStateServiceMsgConsumer() { | |
281 | - TbKafkaConsumerTemplate.TbKafkaConsumerTemplateBuilder<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> consumerBuilder = TbKafkaConsumerTemplate.builder(); | |
280 | + public TbQueueConsumer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> createToOtaPackageStateServiceMsgConsumer() { | |
281 | + TbKafkaConsumerTemplate.TbKafkaConsumerTemplateBuilder<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> consumerBuilder = TbKafkaConsumerTemplate.builder(); | |
282 | 282 | consumerBuilder.settings(kafkaSettings); |
283 | - consumerBuilder.topic(coreSettings.getFirmwareTopic()); | |
284 | - consumerBuilder.clientId("monolith-fw-consumer-" + serviceInfoProvider.getServiceId()); | |
285 | - consumerBuilder.groupId("monolith-fw-consumer"); | |
286 | - consumerBuilder.decoder(msg -> new TbProtoQueueMsg<>(msg.getKey(), ToFirmwareStateServiceMsg.parseFrom(msg.getData()), msg.getHeaders())); | |
283 | + consumerBuilder.topic(coreSettings.getOtaPackageTopic()); | |
284 | + consumerBuilder.clientId("monolith-ota-consumer-" + serviceInfoProvider.getServiceId()); | |
285 | + consumerBuilder.groupId("monolith-ota-consumer"); | |
286 | + consumerBuilder.decoder(msg -> new TbProtoQueueMsg<>(msg.getKey(), ToOtaPackageStateServiceMsg.parseFrom(msg.getData()), msg.getHeaders())); | |
287 | 287 | consumerBuilder.admin(fwUpdatesAdmin); |
288 | 288 | consumerBuilder.statsService(consumerStatsService); |
289 | 289 | return consumerBuilder.build(); |
290 | 290 | } |
291 | 291 | |
292 | 292 | @Override |
293 | - public TbQueueProducer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> createToFirmwareStateServiceMsgProducer() { | |
294 | - TbKafkaProducerTemplate.TbKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> requestBuilder = TbKafkaProducerTemplate.builder(); | |
293 | + public TbQueueProducer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> createToOtaPackageStateServiceMsgProducer() { | |
294 | + TbKafkaProducerTemplate.TbKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> requestBuilder = TbKafkaProducerTemplate.builder(); | |
295 | 295 | requestBuilder.settings(kafkaSettings); |
296 | - requestBuilder.clientId("monolith-fw-producer-" + serviceInfoProvider.getServiceId()); | |
297 | - requestBuilder.defaultTopic(coreSettings.getFirmwareTopic()); | |
296 | + requestBuilder.clientId("monolith-ota-producer-" + serviceInfoProvider.getServiceId()); | |
297 | + requestBuilder.defaultTopic(coreSettings.getOtaPackageTopic()); | |
298 | 298 | requestBuilder.admin(fwUpdatesAdmin); |
299 | 299 | return requestBuilder.build(); |
300 | 300 | } | ... | ... |
... | ... | @@ -23,7 +23,7 @@ import org.thingsboard.server.common.msg.queue.ServiceType; |
23 | 23 | import org.thingsboard.server.gen.js.JsInvokeProtos; |
24 | 24 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
25 | 25 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; |
26 | -import org.thingsboard.server.gen.transport.TransportProtos.ToFirmwareStateServiceMsg; | |
26 | +import org.thingsboard.server.gen.transport.TransportProtos.ToOtaPackageStateServiceMsg; | |
27 | 27 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; |
28 | 28 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; |
29 | 29 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; |
... | ... | @@ -245,24 +245,24 @@ public class KafkaTbCoreQueueFactory implements TbCoreQueueFactory { |
245 | 245 | } |
246 | 246 | |
247 | 247 | @Override |
248 | - public TbQueueConsumer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> createToFirmwareStateServiceMsgConsumer() { | |
249 | - TbKafkaConsumerTemplate.TbKafkaConsumerTemplateBuilder<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> consumerBuilder = TbKafkaConsumerTemplate.builder(); | |
248 | + public TbQueueConsumer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> createToOtaPackageStateServiceMsgConsumer() { | |
249 | + TbKafkaConsumerTemplate.TbKafkaConsumerTemplateBuilder<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> consumerBuilder = TbKafkaConsumerTemplate.builder(); | |
250 | 250 | consumerBuilder.settings(kafkaSettings); |
251 | - consumerBuilder.topic(coreSettings.getFirmwareTopic()); | |
252 | - consumerBuilder.clientId("tb-core-fw-consumer-" + serviceInfoProvider.getServiceId()); | |
253 | - consumerBuilder.groupId("tb-core-fw-consumer"); | |
254 | - consumerBuilder.decoder(msg -> new TbProtoQueueMsg<>(msg.getKey(), ToFirmwareStateServiceMsg.parseFrom(msg.getData()), msg.getHeaders())); | |
251 | + consumerBuilder.topic(coreSettings.getOtaPackageTopic()); | |
252 | + consumerBuilder.clientId("tb-core-ota-consumer-" + serviceInfoProvider.getServiceId()); | |
253 | + consumerBuilder.groupId("tb-core-ota-consumer"); | |
254 | + consumerBuilder.decoder(msg -> new TbProtoQueueMsg<>(msg.getKey(), ToOtaPackageStateServiceMsg.parseFrom(msg.getData()), msg.getHeaders())); | |
255 | 255 | consumerBuilder.admin(fwUpdatesAdmin); |
256 | 256 | consumerBuilder.statsService(consumerStatsService); |
257 | 257 | return consumerBuilder.build(); |
258 | 258 | } |
259 | 259 | |
260 | 260 | @Override |
261 | - public TbQueueProducer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> createToFirmwareStateServiceMsgProducer() { | |
262 | - TbKafkaProducerTemplate.TbKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> requestBuilder = TbKafkaProducerTemplate.builder(); | |
261 | + public TbQueueProducer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> createToOtaPackageStateServiceMsgProducer() { | |
262 | + TbKafkaProducerTemplate.TbKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> requestBuilder = TbKafkaProducerTemplate.builder(); | |
263 | 263 | requestBuilder.settings(kafkaSettings); |
264 | - requestBuilder.clientId("tb-core-fw-producer-" + serviceInfoProvider.getServiceId()); | |
265 | - requestBuilder.defaultTopic(coreSettings.getFirmwareTopic()); | |
264 | + requestBuilder.clientId("tb-core-ota-producer-" + serviceInfoProvider.getServiceId()); | |
265 | + requestBuilder.defaultTopic(coreSettings.getOtaPackageTopic()); | |
266 | 266 | requestBuilder.admin(fwUpdatesAdmin); |
267 | 267 | return requestBuilder.build(); |
268 | 268 | } | ... | ... |
... | ... | @@ -22,9 +22,9 @@ import org.springframework.stereotype.Component; |
22 | 22 | import org.thingsboard.server.common.msg.queue.ServiceType; |
23 | 23 | import org.thingsboard.server.gen.js.JsInvokeProtos.RemoteJsRequest; |
24 | 24 | import org.thingsboard.server.gen.js.JsInvokeProtos.RemoteJsResponse; |
25 | -import org.thingsboard.server.gen.transport.TransportProtos.*; | |
26 | 25 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
27 | 26 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; |
27 | +import org.thingsboard.server.gen.transport.TransportProtos.ToOtaPackageStateServiceMsg; | |
28 | 28 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; |
29 | 29 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; |
30 | 30 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; |
... | ... | @@ -192,14 +192,14 @@ public class PubSubMonolithQueueFactory implements TbCoreQueueFactory, TbRuleEng |
192 | 192 | } |
193 | 193 | |
194 | 194 | @Override |
195 | - public TbQueueConsumer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> createToFirmwareStateServiceMsgConsumer() { | |
196 | - return new TbPubSubConsumerTemplate<>(coreAdmin, pubSubSettings, coreSettings.getFirmwareTopic(), | |
197 | - msg -> new TbProtoQueueMsg<>(msg.getKey(), ToFirmwareStateServiceMsg.parseFrom(msg.getData()), msg.getHeaders())); | |
195 | + public TbQueueConsumer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> createToOtaPackageStateServiceMsgConsumer() { | |
196 | + return new TbPubSubConsumerTemplate<>(coreAdmin, pubSubSettings, coreSettings.getOtaPackageTopic(), | |
197 | + msg -> new TbProtoQueueMsg<>(msg.getKey(), ToOtaPackageStateServiceMsg.parseFrom(msg.getData()), msg.getHeaders())); | |
198 | 198 | } |
199 | 199 | |
200 | 200 | @Override |
201 | - public TbQueueProducer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> createToFirmwareStateServiceMsgProducer() { | |
202 | - return new TbPubSubProducerTemplate<>(coreAdmin, pubSubSettings, coreSettings.getFirmwareTopic()); | |
201 | + public TbQueueProducer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> createToOtaPackageStateServiceMsgProducer() { | |
202 | + return new TbPubSubProducerTemplate<>(coreAdmin, pubSubSettings, coreSettings.getOtaPackageTopic()); | |
203 | 203 | } |
204 | 204 | |
205 | 205 | @Override | ... | ... |
... | ... | @@ -23,7 +23,7 @@ import org.thingsboard.server.common.msg.queue.ServiceType; |
23 | 23 | import org.thingsboard.server.gen.js.JsInvokeProtos; |
24 | 24 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
25 | 25 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; |
26 | -import org.thingsboard.server.gen.transport.TransportProtos.ToFirmwareStateServiceMsg; | |
26 | +import org.thingsboard.server.gen.transport.TransportProtos.ToOtaPackageStateServiceMsg; | |
27 | 27 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; |
28 | 28 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; |
29 | 29 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; |
... | ... | @@ -166,14 +166,14 @@ public class PubSubTbCoreQueueFactory implements TbCoreQueueFactory { |
166 | 166 | } |
167 | 167 | |
168 | 168 | @Override |
169 | - public TbQueueConsumer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> createToFirmwareStateServiceMsgConsumer() { | |
170 | - return new TbPubSubConsumerTemplate<>(coreAdmin, pubSubSettings, coreSettings.getFirmwareTopic(), | |
171 | - msg -> new TbProtoQueueMsg<>(msg.getKey(), ToFirmwareStateServiceMsg.parseFrom(msg.getData()), msg.getHeaders())); | |
169 | + public TbQueueConsumer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> createToOtaPackageStateServiceMsgConsumer() { | |
170 | + return new TbPubSubConsumerTemplate<>(coreAdmin, pubSubSettings, coreSettings.getOtaPackageTopic(), | |
171 | + msg -> new TbProtoQueueMsg<>(msg.getKey(), ToOtaPackageStateServiceMsg.parseFrom(msg.getData()), msg.getHeaders())); | |
172 | 172 | } |
173 | 173 | |
174 | 174 | @Override |
175 | - public TbQueueProducer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> createToFirmwareStateServiceMsgProducer() { | |
176 | - return new TbPubSubProducerTemplate<>(coreAdmin, pubSubSettings, coreSettings.getFirmwareTopic()); | |
175 | + public TbQueueProducer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> createToOtaPackageStateServiceMsgProducer() { | |
176 | + return new TbPubSubProducerTemplate<>(coreAdmin, pubSubSettings, coreSettings.getOtaPackageTopic()); | |
177 | 177 | } |
178 | 178 | |
179 | 179 | @Override | ... | ... |
... | ... | @@ -24,7 +24,7 @@ import org.thingsboard.server.gen.js.JsInvokeProtos.RemoteJsRequest; |
24 | 24 | import org.thingsboard.server.gen.js.JsInvokeProtos.RemoteJsResponse; |
25 | 25 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
26 | 26 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; |
27 | -import org.thingsboard.server.gen.transport.TransportProtos.ToFirmwareStateServiceMsg; | |
27 | +import org.thingsboard.server.gen.transport.TransportProtos.ToOtaPackageStateServiceMsg; | |
28 | 28 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; |
29 | 29 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; |
30 | 30 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; |
... | ... | @@ -190,14 +190,14 @@ public class RabbitMqMonolithQueueFactory implements TbCoreQueueFactory, TbRuleE |
190 | 190 | } |
191 | 191 | |
192 | 192 | @Override |
193 | - public TbQueueConsumer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> createToFirmwareStateServiceMsgConsumer() { | |
194 | - return new TbRabbitMqConsumerTemplate<>(coreAdmin, rabbitMqSettings, coreSettings.getFirmwareTopic(), | |
195 | - msg -> new TbProtoQueueMsg<>(msg.getKey(), ToFirmwareStateServiceMsg.parseFrom(msg.getData()), msg.getHeaders())); | |
193 | + public TbQueueConsumer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> createToOtaPackageStateServiceMsgConsumer() { | |
194 | + return new TbRabbitMqConsumerTemplate<>(coreAdmin, rabbitMqSettings, coreSettings.getOtaPackageTopic(), | |
195 | + msg -> new TbProtoQueueMsg<>(msg.getKey(), ToOtaPackageStateServiceMsg.parseFrom(msg.getData()), msg.getHeaders())); | |
196 | 196 | } |
197 | 197 | |
198 | 198 | @Override |
199 | - public TbQueueProducer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> createToFirmwareStateServiceMsgProducer() { | |
200 | - return new TbRabbitMqProducerTemplate<>(coreAdmin, rabbitMqSettings, coreSettings.getFirmwareTopic()); | |
199 | + public TbQueueProducer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> createToOtaPackageStateServiceMsgProducer() { | |
200 | + return new TbRabbitMqProducerTemplate<>(coreAdmin, rabbitMqSettings, coreSettings.getOtaPackageTopic()); | |
201 | 201 | } |
202 | 202 | |
203 | 203 | @Override | ... | ... |
... | ... | @@ -23,7 +23,7 @@ import org.thingsboard.server.common.msg.queue.ServiceType; |
23 | 23 | import org.thingsboard.server.gen.js.JsInvokeProtos; |
24 | 24 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
25 | 25 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; |
26 | -import org.thingsboard.server.gen.transport.TransportProtos.ToFirmwareStateServiceMsg; | |
26 | +import org.thingsboard.server.gen.transport.TransportProtos.ToOtaPackageStateServiceMsg; | |
27 | 27 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; |
28 | 28 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; |
29 | 29 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; |
... | ... | @@ -172,14 +172,14 @@ public class RabbitMqTbCoreQueueFactory implements TbCoreQueueFactory { |
172 | 172 | } |
173 | 173 | |
174 | 174 | @Override |
175 | - public TbQueueConsumer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> createToFirmwareStateServiceMsgConsumer() { | |
176 | - return new TbRabbitMqConsumerTemplate<>(coreAdmin, rabbitMqSettings, coreSettings.getFirmwareTopic(), | |
177 | - msg -> new TbProtoQueueMsg<>(msg.getKey(), ToFirmwareStateServiceMsg.parseFrom(msg.getData()), msg.getHeaders())); | |
175 | + public TbQueueConsumer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> createToOtaPackageStateServiceMsgConsumer() { | |
176 | + return new TbRabbitMqConsumerTemplate<>(coreAdmin, rabbitMqSettings, coreSettings.getOtaPackageTopic(), | |
177 | + msg -> new TbProtoQueueMsg<>(msg.getKey(), ToOtaPackageStateServiceMsg.parseFrom(msg.getData()), msg.getHeaders())); | |
178 | 178 | } |
179 | 179 | |
180 | 180 | @Override |
181 | - public TbQueueProducer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> createToFirmwareStateServiceMsgProducer() { | |
182 | - return new TbRabbitMqProducerTemplate<>(coreAdmin, rabbitMqSettings, coreSettings.getFirmwareTopic()); | |
181 | + public TbQueueProducer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> createToOtaPackageStateServiceMsgProducer() { | |
182 | + return new TbRabbitMqProducerTemplate<>(coreAdmin, rabbitMqSettings, coreSettings.getOtaPackageTopic()); | |
183 | 183 | } |
184 | 184 | |
185 | 185 | @Override | ... | ... |
common/queue/src/main/java/org/thingsboard/server/queue/provider/ServiceBusMonolithQueueFactory.java
... | ... | @@ -23,7 +23,7 @@ import org.thingsboard.server.common.msg.queue.ServiceType; |
23 | 23 | import org.thingsboard.server.gen.js.JsInvokeProtos; |
24 | 24 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
25 | 25 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; |
26 | -import org.thingsboard.server.gen.transport.TransportProtos.ToFirmwareStateServiceMsg; | |
26 | +import org.thingsboard.server.gen.transport.TransportProtos.ToOtaPackageStateServiceMsg; | |
27 | 27 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; |
28 | 28 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; |
29 | 29 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; |
... | ... | @@ -189,14 +189,14 @@ public class ServiceBusMonolithQueueFactory implements TbCoreQueueFactory, TbRul |
189 | 189 | } |
190 | 190 | |
191 | 191 | @Override |
192 | - public TbQueueConsumer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> createToFirmwareStateServiceMsgConsumer() { | |
193 | - return new TbServiceBusConsumerTemplate<>(coreAdmin, serviceBusSettings, coreSettings.getFirmwareTopic(), | |
194 | - msg -> new TbProtoQueueMsg<>(msg.getKey(), ToFirmwareStateServiceMsg.parseFrom(msg.getData()), msg.getHeaders())); | |
192 | + public TbQueueConsumer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> createToOtaPackageStateServiceMsgConsumer() { | |
193 | + return new TbServiceBusConsumerTemplate<>(coreAdmin, serviceBusSettings, coreSettings.getOtaPackageTopic(), | |
194 | + msg -> new TbProtoQueueMsg<>(msg.getKey(), ToOtaPackageStateServiceMsg.parseFrom(msg.getData()), msg.getHeaders())); | |
195 | 195 | } |
196 | 196 | |
197 | 197 | @Override |
198 | - public TbQueueProducer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> createToFirmwareStateServiceMsgProducer() { | |
199 | - return new TbServiceBusProducerTemplate<>(coreAdmin, serviceBusSettings, coreSettings.getFirmwareTopic()); | |
198 | + public TbQueueProducer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> createToOtaPackageStateServiceMsgProducer() { | |
199 | + return new TbServiceBusProducerTemplate<>(coreAdmin, serviceBusSettings, coreSettings.getOtaPackageTopic()); | |
200 | 200 | } |
201 | 201 | |
202 | 202 | @Override | ... | ... |
... | ... | @@ -23,7 +23,7 @@ import org.thingsboard.server.common.msg.queue.ServiceType; |
23 | 23 | import org.thingsboard.server.gen.js.JsInvokeProtos; |
24 | 24 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
25 | 25 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; |
26 | -import org.thingsboard.server.gen.transport.TransportProtos.ToFirmwareStateServiceMsg; | |
26 | +import org.thingsboard.server.gen.transport.TransportProtos.ToOtaPackageStateServiceMsg; | |
27 | 27 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; |
28 | 28 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; |
29 | 29 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; |
... | ... | @@ -172,14 +172,14 @@ public class ServiceBusTbCoreQueueFactory implements TbCoreQueueFactory { |
172 | 172 | } |
173 | 173 | |
174 | 174 | @Override |
175 | - public TbQueueConsumer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> createToFirmwareStateServiceMsgConsumer() { | |
176 | - return new TbServiceBusConsumerTemplate<>(coreAdmin, serviceBusSettings, coreSettings.getFirmwareTopic(), | |
177 | - msg -> new TbProtoQueueMsg<>(msg.getKey(), ToFirmwareStateServiceMsg.parseFrom(msg.getData()), msg.getHeaders())); | |
175 | + public TbQueueConsumer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> createToOtaPackageStateServiceMsgConsumer() { | |
176 | + return new TbServiceBusConsumerTemplate<>(coreAdmin, serviceBusSettings, coreSettings.getOtaPackageTopic(), | |
177 | + msg -> new TbProtoQueueMsg<>(msg.getKey(), ToOtaPackageStateServiceMsg.parseFrom(msg.getData()), msg.getHeaders())); | |
178 | 178 | } |
179 | 179 | |
180 | 180 | @Override |
181 | - public TbQueueProducer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> createToFirmwareStateServiceMsgProducer() { | |
182 | - return new TbServiceBusProducerTemplate<>(coreAdmin, serviceBusSettings, coreSettings.getFirmwareTopic()); | |
181 | + public TbQueueProducer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> createToOtaPackageStateServiceMsgProducer() { | |
182 | + return new TbServiceBusProducerTemplate<>(coreAdmin, serviceBusSettings, coreSettings.getOtaPackageTopic()); | |
183 | 183 | } |
184 | 184 | |
185 | 185 | @Override | ... | ... |
... | ... | @@ -16,7 +16,7 @@ |
16 | 16 | package org.thingsboard.server.queue.provider; |
17 | 17 | |
18 | 18 | import org.thingsboard.server.gen.js.JsInvokeProtos; |
19 | -import org.thingsboard.server.gen.transport.TransportProtos.ToFirmwareStateServiceMsg; | |
19 | +import org.thingsboard.server.gen.transport.TransportProtos.ToOtaPackageStateServiceMsg; | |
20 | 20 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
21 | 21 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; |
22 | 22 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; |
... | ... | @@ -91,14 +91,14 @@ public interface TbCoreQueueFactory extends TbUsageStatsClientQueueFactory { |
91 | 91 | * |
92 | 92 | * @return |
93 | 93 | */ |
94 | - TbQueueConsumer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> createToFirmwareStateServiceMsgConsumer(); | |
94 | + TbQueueConsumer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> createToOtaPackageStateServiceMsgConsumer(); | |
95 | 95 | |
96 | 96 | /** |
97 | 97 | * Used to consume messages about firmware update notifications by TB Core Service |
98 | 98 | * |
99 | 99 | * @return |
100 | 100 | */ |
101 | - TbQueueProducer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> createToFirmwareStateServiceMsgProducer(); | |
101 | + TbQueueProducer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> createToOtaPackageStateServiceMsgProducer(); | |
102 | 102 | |
103 | 103 | /** |
104 | 104 | * Used to consume high priority messages by TB Core Service | ... | ... |
... | ... | @@ -15,7 +15,6 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.queue.provider; |
17 | 17 | |
18 | -import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; | |
19 | 18 | import org.springframework.stereotype.Service; |
20 | 19 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
21 | 20 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; |
... | ... | @@ -25,11 +24,12 @@ import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; |
25 | 24 | import org.thingsboard.server.gen.transport.TransportProtos.ToUsageStatsServiceMsg; |
26 | 25 | import org.thingsboard.server.queue.TbQueueProducer; |
27 | 26 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
27 | +import org.thingsboard.server.queue.util.TbCoreComponent; | |
28 | 28 | |
29 | 29 | import javax.annotation.PostConstruct; |
30 | 30 | |
31 | 31 | @Service |
32 | -@ConditionalOnExpression("'${service.type:null}'=='monolith' || '${service.type:null}'=='tb-core'") | |
32 | +@TbCoreComponent | |
33 | 33 | public class TbCoreQueueProducerProvider implements TbQueueProducerProvider { |
34 | 34 | |
35 | 35 | private final TbCoreQueueFactory tbQueueProvider; | ... | ... |
... | ... | @@ -26,8 +26,8 @@ public class TbQueueCoreSettings { |
26 | 26 | @Value("${queue.core.topic}") |
27 | 27 | private String topic; |
28 | 28 | |
29 | - @Value("${queue.core.firmware.topic:tb_firmware}") | |
30 | - private String firmwareTopic; | |
29 | + @Value("${queue.core.ota.topic:tb_ota_package}") | |
30 | + private String otaPackageTopic; | |
31 | 31 | |
32 | 32 | @Value("${queue.core.usage-stats-topic:tb_usage_stats}") |
33 | 33 | private String usageStatsTopic; | ... | ... |
... | ... | @@ -388,7 +388,7 @@ enum ResponseStatus { |
388 | 388 | FAILURE = 3; |
389 | 389 | } |
390 | 390 | |
391 | -message GetFirmwareRequestMsg { | |
391 | +message GetOtaPackageRequestMsg { | |
392 | 392 | int64 deviceIdMSB = 1; |
393 | 393 | int64 deviceIdLSB = 2; |
394 | 394 | int64 tenantIdMSB = 3; |
... | ... | @@ -396,10 +396,10 @@ message GetFirmwareRequestMsg { |
396 | 396 | string type = 5; |
397 | 397 | } |
398 | 398 | |
399 | -message GetFirmwareResponseMsg { | |
399 | +message GetOtaPackageResponseMsg { | |
400 | 400 | ResponseStatus responseStatus = 1; |
401 | - int64 firmwareIdMSB = 2; | |
402 | - int64 firmwareIdLSB = 3; | |
401 | + int64 otaPackageIdMSB = 2; | |
402 | + int64 otaPackageIdLSB = 3; | |
403 | 403 | string type = 4; |
404 | 404 | string title = 5; |
405 | 405 | string version = 6; |
... | ... | @@ -627,7 +627,7 @@ message TransportApiRequestMsg { |
627 | 627 | ProvisionDeviceRequestMsg provisionDeviceRequestMsg = 7; |
628 | 628 | ValidateDeviceLwM2MCredentialsRequestMsg validateDeviceLwM2MCredentialsRequestMsg = 8; |
629 | 629 | GetResourceRequestMsg resourceRequestMsg = 9; |
630 | - GetFirmwareRequestMsg firmwareRequestMsg = 10; | |
630 | + GetOtaPackageRequestMsg otaPackageRequestMsg = 10; | |
631 | 631 | GetSnmpDevicesRequestMsg snmpDevicesRequestMsg = 11; |
632 | 632 | GetDeviceRequestMsg deviceRequestMsg = 12; |
633 | 633 | GetDeviceCredentialsRequestMsg deviceCredentialsRequestMsg = 13; |
... | ... | @@ -642,7 +642,7 @@ message TransportApiResponseMsg { |
642 | 642 | GetSnmpDevicesResponseMsg snmpDevicesResponseMsg = 5; |
643 | 643 | LwM2MResponseMsg lwM2MResponseMsg = 6; |
644 | 644 | GetResourceResponseMsg resourceResponseMsg = 7; |
645 | - GetFirmwareResponseMsg firmwareResponseMsg = 8; | |
645 | + GetOtaPackageResponseMsg otaPackageResponseMsg = 8; | |
646 | 646 | GetDeviceResponseMsg deviceResponseMsg = 9; |
647 | 647 | GetDeviceCredentialsResponseMsg deviceCredentialsResponseMsg = 10; |
648 | 648 | } |
... | ... | @@ -710,13 +710,13 @@ message ToUsageStatsServiceMsg { |
710 | 710 | int64 customerIdLSB = 7; |
711 | 711 | } |
712 | 712 | |
713 | -message ToFirmwareStateServiceMsg { | |
713 | +message ToOtaPackageStateServiceMsg { | |
714 | 714 | int64 ts = 1; |
715 | 715 | int64 tenantIdMSB = 2; |
716 | 716 | int64 tenantIdLSB = 3; |
717 | 717 | int64 deviceIdMSB = 4; |
718 | 718 | int64 deviceIdLSB = 5; |
719 | - int64 firmwareIdMSB = 6; | |
720 | - int64 firmwareIdLSB = 7; | |
719 | + int64 otaPackageIdMSB = 6; | |
720 | + int64 otaPackageIdLSB = 7; | |
721 | 721 | string type = 8; |
722 | 722 | } | ... | ... |
common/transport/coap/src/main/java/org/thingsboard/server/transport/coap/CoapTransportResource.java
... | ... | @@ -44,7 +44,7 @@ import org.thingsboard.server.common.data.device.profile.DeviceProfileTransportC |
44 | 44 | import org.thingsboard.server.common.data.device.profile.JsonTransportPayloadConfiguration; |
45 | 45 | import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration; |
46 | 46 | import org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration; |
47 | -import org.thingsboard.server.common.data.firmware.FirmwareType; | |
47 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | |
48 | 48 | import org.thingsboard.server.common.data.security.DeviceTokenCredentials; |
49 | 49 | import org.thingsboard.server.common.msg.session.FeatureType; |
50 | 50 | import org.thingsboard.server.common.msg.session.SessionMsgType; |
... | ... | @@ -350,10 +350,10 @@ public class CoapTransportResource extends AbstractCoapTransportResource { |
350 | 350 | new CoapNoOpCallback(exchange)); |
351 | 351 | break; |
352 | 352 | case GET_FIRMWARE_REQUEST: |
353 | - getFirmwareCallback(sessionInfo, exchange, FirmwareType.FIRMWARE); | |
353 | + getOtaPackageCallback(sessionInfo, exchange, OtaPackageType.FIRMWARE); | |
354 | 354 | break; |
355 | 355 | case GET_SOFTWARE_REQUEST: |
356 | - getFirmwareCallback(sessionInfo, exchange, FirmwareType.SOFTWARE); | |
356 | + getOtaPackageCallback(sessionInfo, exchange, OtaPackageType.SOFTWARE); | |
357 | 357 | break; |
358 | 358 | } |
359 | 359 | } catch (AdaptorException e) { |
... | ... | @@ -366,14 +366,14 @@ public class CoapTransportResource extends AbstractCoapTransportResource { |
366 | 366 | return new UUID(sessionInfoProto.getSessionIdMSB(), sessionInfoProto.getSessionIdLSB()); |
367 | 367 | } |
368 | 368 | |
369 | - private void getFirmwareCallback(TransportProtos.SessionInfoProto sessionInfo, CoapExchange exchange, FirmwareType firmwareType) { | |
370 | - TransportProtos.GetFirmwareRequestMsg requestMsg = TransportProtos.GetFirmwareRequestMsg.newBuilder() | |
369 | + private void getOtaPackageCallback(TransportProtos.SessionInfoProto sessionInfo, CoapExchange exchange, OtaPackageType firmwareType) { | |
370 | + TransportProtos.GetOtaPackageRequestMsg requestMsg = TransportProtos.GetOtaPackageRequestMsg.newBuilder() | |
371 | 371 | .setTenantIdMSB(sessionInfo.getTenantIdMSB()) |
372 | 372 | .setTenantIdLSB(sessionInfo.getTenantIdLSB()) |
373 | 373 | .setDeviceIdMSB(sessionInfo.getDeviceIdMSB()) |
374 | 374 | .setDeviceIdLSB(sessionInfo.getDeviceIdLSB()) |
375 | 375 | .setType(firmwareType.name()).build(); |
376 | - transportContext.getTransportService().process(sessionInfo, requestMsg, new FirmwareCallback(exchange)); | |
376 | + transportContext.getTransportService().process(sessionInfo, requestMsg, new OtaPackageCallback(exchange)); | |
377 | 377 | } |
378 | 378 | |
379 | 379 | private TransportProtos.SessionInfoProto lookupAsyncSessionInfo(String token) { |
... | ... | @@ -470,25 +470,25 @@ public class CoapTransportResource extends AbstractCoapTransportResource { |
470 | 470 | } |
471 | 471 | } |
472 | 472 | |
473 | - private class FirmwareCallback implements TransportServiceCallback<TransportProtos.GetFirmwareResponseMsg> { | |
473 | + private class OtaPackageCallback implements TransportServiceCallback<TransportProtos.GetOtaPackageResponseMsg> { | |
474 | 474 | private final CoapExchange exchange; |
475 | 475 | |
476 | - FirmwareCallback(CoapExchange exchange) { | |
476 | + OtaPackageCallback(CoapExchange exchange) { | |
477 | 477 | this.exchange = exchange; |
478 | 478 | } |
479 | 479 | |
480 | 480 | @Override |
481 | - public void onSuccess(TransportProtos.GetFirmwareResponseMsg msg) { | |
481 | + public void onSuccess(TransportProtos.GetOtaPackageResponseMsg msg) { | |
482 | 482 | String title = exchange.getQueryParameter("title"); |
483 | 483 | String version = exchange.getQueryParameter("version"); |
484 | 484 | if (msg.getResponseStatus().equals(TransportProtos.ResponseStatus.SUCCESS)) { |
485 | 485 | if (msg.getTitle().equals(title) && msg.getVersion().equals(version)) { |
486 | - String firmwareId = new UUID(msg.getFirmwareIdMSB(), msg.getFirmwareIdLSB()).toString(); | |
486 | + String firmwareId = new UUID(msg.getOtaPackageIdMSB(), msg.getOtaPackageIdLSB()).toString(); | |
487 | 487 | String strChunkSize = exchange.getQueryParameter("size"); |
488 | 488 | String strChunk = exchange.getQueryParameter("chunk"); |
489 | 489 | int chunkSize = StringUtils.isEmpty(strChunkSize) ? 0 : Integer.parseInt(strChunkSize); |
490 | 490 | int chunk = StringUtils.isEmpty(strChunk) ? 0 : Integer.parseInt(strChunk); |
491 | - exchange.respond(CoAP.ResponseCode.CONTENT, transportContext.getFirmwareDataCache().get(firmwareId, chunkSize, chunk)); | |
491 | + exchange.respond(CoAP.ResponseCode.CONTENT, transportContext.getOtaPackageDataCache().get(firmwareId, chunkSize, chunk)); | |
492 | 492 | } else { |
493 | 493 | exchange.respond(CoAP.ResponseCode.BAD_REQUEST); |
494 | 494 | } | ... | ... |
... | ... | @@ -34,7 +34,7 @@ import org.springframework.web.bind.annotation.RequestParam; |
34 | 34 | import org.springframework.web.bind.annotation.RestController; |
35 | 35 | import org.springframework.web.context.request.async.DeferredResult; |
36 | 36 | import org.thingsboard.server.common.data.DeviceTransportType; |
37 | -import org.thingsboard.server.common.data.firmware.FirmwareType; | |
37 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | |
38 | 38 | import org.thingsboard.server.common.data.TbTransportService; |
39 | 39 | import org.thingsboard.server.common.data.id.DeviceId; |
40 | 40 | import org.thingsboard.server.common.transport.SessionMsgListener; |
... | ... | @@ -213,7 +213,7 @@ public class DeviceApiController implements TbTransportService { |
213 | 213 | @RequestParam(value = "version") String version, |
214 | 214 | @RequestParam(value = "size", required = false, defaultValue = "0") int size, |
215 | 215 | @RequestParam(value = "chunk", required = false, defaultValue = "0") int chunk) { |
216 | - return getFirmwareCallback(deviceToken, title, version, size, chunk, FirmwareType.FIRMWARE); | |
216 | + return getOtaPackageCallback(deviceToken, title, version, size, chunk, OtaPackageType.FIRMWARE); | |
217 | 217 | } |
218 | 218 | |
219 | 219 | @RequestMapping(value = "/{deviceToken}/software", method = RequestMethod.GET) |
... | ... | @@ -222,7 +222,7 @@ public class DeviceApiController implements TbTransportService { |
222 | 222 | @RequestParam(value = "version") String version, |
223 | 223 | @RequestParam(value = "size", required = false, defaultValue = "0") int size, |
224 | 224 | @RequestParam(value = "chunk", required = false, defaultValue = "0") int chunk) { |
225 | - return getFirmwareCallback(deviceToken, title, version, size, chunk, FirmwareType.SOFTWARE); | |
225 | + return getOtaPackageCallback(deviceToken, title, version, size, chunk, OtaPackageType.SOFTWARE); | |
226 | 226 | } |
227 | 227 | |
228 | 228 | @RequestMapping(value = "/provision", method = RequestMethod.POST) |
... | ... | @@ -233,17 +233,17 @@ public class DeviceApiController implements TbTransportService { |
233 | 233 | return responseWriter; |
234 | 234 | } |
235 | 235 | |
236 | - private DeferredResult<ResponseEntity> getFirmwareCallback(String deviceToken, String title, String version, int size, int chunk, FirmwareType firmwareType) { | |
236 | + private DeferredResult<ResponseEntity> getOtaPackageCallback(String deviceToken, String title, String version, int size, int chunk, OtaPackageType firmwareType) { | |
237 | 237 | DeferredResult<ResponseEntity> responseWriter = new DeferredResult<>(); |
238 | 238 | transportContext.getTransportService().process(DeviceTransportType.DEFAULT, ValidateDeviceTokenRequestMsg.newBuilder().setToken(deviceToken).build(), |
239 | 239 | new DeviceAuthCallback(transportContext, responseWriter, sessionInfo -> { |
240 | - TransportProtos.GetFirmwareRequestMsg requestMsg = TransportProtos.GetFirmwareRequestMsg.newBuilder() | |
240 | + TransportProtos.GetOtaPackageRequestMsg requestMsg = TransportProtos.GetOtaPackageRequestMsg.newBuilder() | |
241 | 241 | .setTenantIdMSB(sessionInfo.getTenantIdMSB()) |
242 | 242 | .setTenantIdLSB(sessionInfo.getTenantIdLSB()) |
243 | 243 | .setDeviceIdMSB(sessionInfo.getDeviceIdMSB()) |
244 | 244 | .setDeviceIdLSB(sessionInfo.getDeviceIdLSB()) |
245 | 245 | .setType(firmwareType.name()).build(); |
246 | - transportContext.getTransportService().process(sessionInfo, requestMsg, new GetFirmwareCallback(responseWriter, title, version, size, chunk)); | |
246 | + transportContext.getTransportService().process(sessionInfo, requestMsg, new GetOtaPackageCallback(responseWriter, title, version, size, chunk)); | |
247 | 247 | })); |
248 | 248 | return responseWriter; |
249 | 249 | } |
... | ... | @@ -294,14 +294,14 @@ public class DeviceApiController implements TbTransportService { |
294 | 294 | } |
295 | 295 | } |
296 | 296 | |
297 | - private class GetFirmwareCallback implements TransportServiceCallback<TransportProtos.GetFirmwareResponseMsg> { | |
297 | + private class GetOtaPackageCallback implements TransportServiceCallback<TransportProtos.GetOtaPackageResponseMsg> { | |
298 | 298 | private final DeferredResult<ResponseEntity> responseWriter; |
299 | 299 | private final String title; |
300 | 300 | private final String version; |
301 | 301 | private final int chuckSize; |
302 | 302 | private final int chuck; |
303 | 303 | |
304 | - GetFirmwareCallback(DeferredResult<ResponseEntity> responseWriter, String title, String version, int chuckSize, int chuck) { | |
304 | + GetOtaPackageCallback(DeferredResult<ResponseEntity> responseWriter, String title, String version, int chuckSize, int chuck) { | |
305 | 305 | this.responseWriter = responseWriter; |
306 | 306 | this.title = title; |
307 | 307 | this.version = version; |
... | ... | @@ -310,17 +310,17 @@ public class DeviceApiController implements TbTransportService { |
310 | 310 | } |
311 | 311 | |
312 | 312 | @Override |
313 | - public void onSuccess(TransportProtos.GetFirmwareResponseMsg firmwareResponseMsg) { | |
314 | - if (!TransportProtos.ResponseStatus.SUCCESS.equals(firmwareResponseMsg.getResponseStatus())) { | |
313 | + public void onSuccess(TransportProtos.GetOtaPackageResponseMsg otaPackageResponseMsg) { | |
314 | + if (!TransportProtos.ResponseStatus.SUCCESS.equals(otaPackageResponseMsg.getResponseStatus())) { | |
315 | 315 | responseWriter.setResult(new ResponseEntity<>(HttpStatus.NOT_FOUND)); |
316 | - } else if (title.equals(firmwareResponseMsg.getTitle()) && version.equals(firmwareResponseMsg.getVersion())) { | |
317 | - String firmwareId = new UUID(firmwareResponseMsg.getFirmwareIdMSB(), firmwareResponseMsg.getFirmwareIdLSB()).toString(); | |
318 | - ByteArrayResource resource = new ByteArrayResource(transportContext.getFirmwareDataCache().get(firmwareId, chuckSize, chuck)); | |
316 | + } else if (title.equals(otaPackageResponseMsg.getTitle()) && version.equals(otaPackageResponseMsg.getVersion())) { | |
317 | + String otaPackageId = new UUID(otaPackageResponseMsg.getOtaPackageIdMSB(), otaPackageResponseMsg.getOtaPackageIdLSB()).toString(); | |
318 | + ByteArrayResource resource = new ByteArrayResource(transportContext.getOtaPackageDataCache().get(otaPackageId, chuckSize, chuck)); | |
319 | 319 | ResponseEntity<ByteArrayResource> response = ResponseEntity.ok() |
320 | - .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + firmwareResponseMsg.getFileName()) | |
321 | - .header("x-filename", firmwareResponseMsg.getFileName()) | |
320 | + .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + otaPackageResponseMsg.getFileName()) | |
321 | + .header("x-filename", otaPackageResponseMsg.getFileName()) | |
322 | 322 | .contentLength(resource.contentLength()) |
323 | - .contentType(parseMediaType(firmwareResponseMsg.getContentType())) | |
323 | + .contentType(parseMediaType(otaPackageResponseMsg.getContentType())) | |
324 | 324 | .body(resource); |
325 | 325 | responseWriter.setResult(response); |
326 | 326 | } else { | ... | ... |
... | ... | @@ -39,13 +39,13 @@ import org.springframework.context.annotation.Lazy; |
39 | 39 | import org.springframework.stereotype.Service; |
40 | 40 | import org.thingsboard.common.util.JacksonUtil; |
41 | 41 | import org.thingsboard.common.util.ThingsBoardExecutors; |
42 | -import org.thingsboard.server.cache.firmware.FirmwareDataCache; | |
42 | +import org.thingsboard.server.cache.ota.OtaPackageDataCache; | |
43 | 43 | import org.thingsboard.server.common.data.Device; |
44 | 44 | import org.thingsboard.server.common.data.DeviceProfile; |
45 | -import org.thingsboard.server.common.data.firmware.FirmwareKey; | |
46 | -import org.thingsboard.server.common.data.firmware.FirmwareType; | |
47 | -import org.thingsboard.server.common.data.firmware.FirmwareUtil; | |
48 | -import org.thingsboard.server.common.data.id.FirmwareId; | |
45 | +import org.thingsboard.server.common.data.ota.OtaPackageKey; | |
46 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | |
47 | +import org.thingsboard.server.common.data.ota.OtaPackageUtil; | |
48 | +import org.thingsboard.server.common.data.id.OtaPackageId; | |
49 | 49 | import org.thingsboard.server.common.transport.TransportService; |
50 | 50 | import org.thingsboard.server.common.transport.TransportServiceCallback; |
51 | 51 | import org.thingsboard.server.common.transport.adaptor.AdaptorException; |
... | ... | @@ -87,8 +87,8 @@ import java.util.stream.Collectors; |
87 | 87 | |
88 | 88 | import static org.eclipse.californium.core.coap.CoAP.ResponseCode.BAD_REQUEST; |
89 | 89 | import static org.eclipse.leshan.core.attributes.Attribute.OBJECT_VERSION; |
90 | -import static org.thingsboard.server.common.data.firmware.FirmwareUpdateStatus.DOWNLOADED; | |
91 | -import static org.thingsboard.server.common.data.firmware.FirmwareUpdateStatus.UPDATING; | |
90 | +import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.DOWNLOADED; | |
91 | +import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.UPDATING; | |
92 | 92 | import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH; |
93 | 93 | import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportServerHelper.getValueFromKvProto; |
94 | 94 | import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.CLIENT_NOT_AUTHORIZED; |
... | ... | @@ -132,7 +132,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
132 | 132 | private final TransportService transportService; |
133 | 133 | private final LwM2mTransportContext context; |
134 | 134 | public final LwM2MTransportServerConfig config; |
135 | - public final FirmwareDataCache firmwareDataCache; | |
135 | + public final OtaPackageDataCache otaPackageDataCache; | |
136 | 136 | public final LwM2mTransportServerHelper helper; |
137 | 137 | private final LwM2MJsonAdaptor adaptor; |
138 | 138 | private final TbLwM2MDtlsSessionStore sessionStore; |
... | ... | @@ -143,14 +143,14 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
143 | 143 | public DefaultLwM2MTransportMsgHandler(TransportService transportService, LwM2MTransportServerConfig config, LwM2mTransportServerHelper helper, |
144 | 144 | LwM2mClientContext clientContext, |
145 | 145 | @Lazy LwM2mTransportRequest lwM2mTransportRequest, |
146 | - FirmwareDataCache firmwareDataCache, | |
146 | + OtaPackageDataCache otaPackageDataCache, | |
147 | 147 | LwM2mTransportContext context, LwM2MJsonAdaptor adaptor, TbLwM2MDtlsSessionStore sessionStore) { |
148 | 148 | this.transportService = transportService; |
149 | 149 | this.config = config; |
150 | 150 | this.helper = helper; |
151 | 151 | this.clientContext = clientContext; |
152 | 152 | this.lwM2mTransportRequest = lwM2mTransportRequest; |
153 | - this.firmwareDataCache = firmwareDataCache; | |
153 | + this.otaPackageDataCache = otaPackageDataCache; | |
154 | 154 | this.context = context; |
155 | 155 | this.adaptor = adaptor; |
156 | 156 | this.rpcSubscriptions = new ConcurrentHashMap<>(); |
... | ... | @@ -247,7 +247,6 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
247 | 247 | * @param observations - !!! Warn: if have not finishing unReg, then this operation will be finished on next Client`s connect |
248 | 248 | */ |
249 | 249 | public void unReg(Registration registration, Collection<Observation> observations) { |
250 | - log.error("Client unRegistration -> test", new RuntimeException()); | |
251 | 250 | unRegistrationExecutor.submit(() -> { |
252 | 251 | try { |
253 | 252 | this.sendLogsToThingsboard(LOG_LW2M_INFO + ": Client unRegistration", registration.getId()); |
... | ... | @@ -357,14 +356,14 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
357 | 356 | String pathName = tsKvProto.getKv().getKey(); |
358 | 357 | String pathIdVer = this.getPresentPathIntoProfile(sessionInfo, pathName); |
359 | 358 | Object valueNew = getValueFromKvProto(tsKvProto.getKv()); |
360 | - if ((FirmwareUtil.getAttributeKey(FirmwareType.FIRMWARE, FirmwareKey.VERSION).equals(pathName) | |
359 | + if ((OtaPackageUtil.getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.VERSION).equals(pathName) | |
361 | 360 | && (!valueNew.equals(lwM2MClient.getFwUpdate().getCurrentVersion()))) |
362 | - || (FirmwareUtil.getAttributeKey(FirmwareType.FIRMWARE, FirmwareKey.TITLE).equals(pathName) | |
361 | + || (OtaPackageUtil.getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.TITLE).equals(pathName) | |
363 | 362 | && (!valueNew.equals(lwM2MClient.getFwUpdate().getCurrentTitle())))) { |
364 | 363 | this.getInfoFirmwareUpdate(lwM2MClient); |
365 | - } else if ((FirmwareUtil.getAttributeKey(FirmwareType.SOFTWARE, FirmwareKey.VERSION).equals(pathName) | |
364 | + } else if ((OtaPackageUtil.getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.VERSION).equals(pathName) | |
366 | 365 | && (!valueNew.equals(lwM2MClient.getSwUpdate().getCurrentVersion()))) |
367 | - || (FirmwareUtil.getAttributeKey(FirmwareType.SOFTWARE, FirmwareKey.TITLE).equals(pathName) | |
366 | + || (OtaPackageUtil.getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.TITLE).equals(pathName) | |
368 | 367 | && (!valueNew.equals(lwM2MClient.getSwUpdate().getCurrentTitle())))) { |
369 | 368 | this.getInfoSoftwareUpdate(lwM2MClient); |
370 | 369 | } |
... | ... | @@ -391,7 +390,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
391 | 390 | msg.getSharedUpdatedList().forEach(tsKvProto -> { |
392 | 391 | String pathName = tsKvProto.getKv().getKey(); |
393 | 392 | Object valueNew = getValueFromKvProto(tsKvProto.getKv()); |
394 | - if (FirmwareUtil.getAttributeKey(FirmwareType.FIRMWARE, FirmwareKey.VERSION).equals(pathName) && !valueNew.equals(lwM2MClient.getFwUpdate().getCurrentVersion())) { | |
393 | + if (OtaPackageUtil.getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.VERSION).equals(pathName) && !valueNew.equals(lwM2MClient.getFwUpdate().getCurrentVersion())) { | |
395 | 394 | lwM2MClient.getFwUpdate().setCurrentVersion((String) valueNew); |
396 | 395 | } |
397 | 396 | }); |
... | ... | @@ -1344,18 +1343,18 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
1344 | 1343 | if (lwM2MClient.getRegistration().getSupportedVersion(FW_ID) != null) { |
1345 | 1344 | SessionInfoProto sessionInfo = this.getSessionInfoOrCloseSession(lwM2MClient); |
1346 | 1345 | if (sessionInfo != null) { |
1347 | - transportService.process(sessionInfo, createFirmwareRequestMsg(sessionInfo, FirmwareType.FIRMWARE.name()), | |
1346 | + transportService.process(sessionInfo, createOtaPackageRequestMsg(sessionInfo, OtaPackageType.FIRMWARE.name()), | |
1348 | 1347 | new TransportServiceCallback<>() { |
1349 | 1348 | @Override |
1350 | - public void onSuccess(TransportProtos.GetFirmwareResponseMsg response) { | |
1349 | + public void onSuccess(TransportProtos.GetOtaPackageResponseMsg response) { | |
1351 | 1350 | if (TransportProtos.ResponseStatus.SUCCESS.equals(response.getResponseStatus()) |
1352 | - && response.getType().equals(FirmwareType.FIRMWARE.name())) { | |
1351 | + && response.getType().equals(OtaPackageType.FIRMWARE.name())) { | |
1353 | 1352 | lwM2MClient.getFwUpdate().setCurrentVersion(response.getVersion()); |
1354 | 1353 | lwM2MClient.getFwUpdate().setCurrentTitle(response.getTitle()); |
1355 | - lwM2MClient.getFwUpdate().setCurrentId(new FirmwareId(new UUID(response.getFirmwareIdMSB(), response.getFirmwareIdLSB())).getId()); | |
1354 | + lwM2MClient.getFwUpdate().setCurrentId(new OtaPackageId(new UUID(response.getOtaPackageIdMSB(), response.getOtaPackageIdLSB())).getId()); | |
1356 | 1355 | lwM2MClient.getFwUpdate().sendReadObserveInfo(lwM2mTransportRequest); |
1357 | 1356 | } else { |
1358 | - log.trace("Firmware [{}] [{}]", lwM2MClient.getDeviceName(), response.getResponseStatus().toString()); | |
1357 | + log.trace("OtaPackage [{}] [{}]", lwM2MClient.getDeviceName(), response.getResponseStatus().toString()); | |
1359 | 1358 | } |
1360 | 1359 | } |
1361 | 1360 | |
... | ... | @@ -1373,15 +1372,15 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
1373 | 1372 | SessionInfoProto sessionInfo = this.getSessionInfoOrCloseSession(lwM2MClient); |
1374 | 1373 | if (sessionInfo != null) { |
1375 | 1374 | DefaultLwM2MTransportMsgHandler serviceImpl = this; |
1376 | - transportService.process(sessionInfo, createFirmwareRequestMsg(sessionInfo, FirmwareType.SOFTWARE.name()), | |
1375 | + transportService.process(sessionInfo, createOtaPackageRequestMsg(sessionInfo, OtaPackageType.SOFTWARE.name()), | |
1377 | 1376 | new TransportServiceCallback<>() { |
1378 | 1377 | @Override |
1379 | - public void onSuccess(TransportProtos.GetFirmwareResponseMsg response) { | |
1378 | + public void onSuccess(TransportProtos.GetOtaPackageResponseMsg response) { | |
1380 | 1379 | if (TransportProtos.ResponseStatus.SUCCESS.equals(response.getResponseStatus()) |
1381 | - && response.getType().equals(FirmwareType.SOFTWARE.name())) { | |
1380 | + && response.getType().equals(OtaPackageType.SOFTWARE.name())) { | |
1382 | 1381 | lwM2MClient.getSwUpdate().setCurrentVersion(response.getVersion()); |
1383 | 1382 | lwM2MClient.getSwUpdate().setCurrentTitle(response.getTitle()); |
1384 | - lwM2MClient.getSwUpdate().setCurrentId(new FirmwareId(new UUID(response.getFirmwareIdMSB(), response.getFirmwareIdLSB())).getId()); | |
1383 | + lwM2MClient.getSwUpdate().setCurrentId(new OtaPackageId(new UUID(response.getOtaPackageIdMSB(), response.getOtaPackageIdLSB())).getId()); | |
1385 | 1384 | lwM2MClient.getSwUpdate().sendReadObserveInfo(lwM2mTransportRequest); |
1386 | 1385 | } else { |
1387 | 1386 | log.trace("Software [{}] [{}]", lwM2MClient.getDeviceName(), response.getResponseStatus().toString()); |
... | ... | @@ -1397,8 +1396,8 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
1397 | 1396 | } |
1398 | 1397 | } |
1399 | 1398 | |
1400 | - private TransportProtos.GetFirmwareRequestMsg createFirmwareRequestMsg(SessionInfoProto sessionInfo, String nameFwSW) { | |
1401 | - return TransportProtos.GetFirmwareRequestMsg.newBuilder() | |
1399 | + private TransportProtos.GetOtaPackageRequestMsg createOtaPackageRequestMsg(SessionInfoProto sessionInfo, String nameFwSW) { | |
1400 | + return TransportProtos.GetOtaPackageRequestMsg.newBuilder() | |
1402 | 1401 | .setDeviceIdMSB(sessionInfo.getDeviceIdMSB()) |
1403 | 1402 | .setDeviceIdLSB(sessionInfo.getDeviceIdLSB()) |
1404 | 1403 | .setTenantIdMSB(sessionInfo.getTenantIdMSB()) | ... | ... |
... | ... | @@ -71,8 +71,8 @@ import java.util.stream.Collectors; |
71 | 71 | import static org.eclipse.californium.core.coap.CoAP.ResponseCode.CONTENT; |
72 | 72 | import static org.eclipse.leshan.core.ResponseCode.BAD_REQUEST; |
73 | 73 | import static org.eclipse.leshan.core.ResponseCode.NOT_FOUND; |
74 | -import static org.thingsboard.server.common.data.firmware.FirmwareUpdateStatus.DOWNLOADED; | |
75 | -import static org.thingsboard.server.common.data.firmware.FirmwareUpdateStatus.FAILED; | |
74 | +import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.DOWNLOADED; | |
75 | +import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.FAILED; | |
76 | 76 | import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportServerHelper.getContentFormatByResourceModelType; |
77 | 77 | import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.DEFAULT_TIMEOUT; |
78 | 78 | import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_PACKAGE_ID; | ... | ... |
... | ... | @@ -43,10 +43,10 @@ import org.eclipse.leshan.server.registration.Registration; |
43 | 43 | import org.nustaq.serialization.FSTConfiguration; |
44 | 44 | import org.thingsboard.server.common.data.DeviceProfile; |
45 | 45 | import org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration; |
46 | -import org.thingsboard.server.common.data.firmware.FirmwareKey; | |
47 | -import org.thingsboard.server.common.data.firmware.FirmwareType; | |
48 | -import org.thingsboard.server.common.data.firmware.FirmwareUpdateStatus; | |
49 | -import org.thingsboard.server.common.data.firmware.FirmwareUtil; | |
46 | +import org.thingsboard.server.common.data.ota.OtaPackageKey; | |
47 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | |
48 | +import org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus; | |
49 | +import org.thingsboard.server.common.data.ota.OtaPackageUtil; | |
50 | 50 | import org.thingsboard.server.common.data.id.TenantId; |
51 | 51 | import org.thingsboard.server.common.transport.TransportServiceCallback; |
52 | 52 | import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient; |
... | ... | @@ -77,12 +77,12 @@ import static org.eclipse.leshan.core.model.ResourceModel.Type.OBJLNK; |
77 | 77 | import static org.eclipse.leshan.core.model.ResourceModel.Type.OPAQUE; |
78 | 78 | import static org.eclipse.leshan.core.model.ResourceModel.Type.STRING; |
79 | 79 | import static org.eclipse.leshan.core.model.ResourceModel.Type.TIME; |
80 | -import static org.thingsboard.server.common.data.firmware.FirmwareUpdateStatus.DOWNLOADED; | |
81 | -import static org.thingsboard.server.common.data.firmware.FirmwareUpdateStatus.DOWNLOADING; | |
82 | -import static org.thingsboard.server.common.data.firmware.FirmwareUpdateStatus.FAILED; | |
83 | -import static org.thingsboard.server.common.data.firmware.FirmwareUpdateStatus.UPDATED; | |
84 | -import static org.thingsboard.server.common.data.firmware.FirmwareUpdateStatus.UPDATING; | |
85 | -import static org.thingsboard.server.common.data.firmware.FirmwareUpdateStatus.VERIFIED; | |
80 | +import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.DOWNLOADED; | |
81 | +import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.DOWNLOADING; | |
82 | +import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.FAILED; | |
83 | +import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.UPDATED; | |
84 | +import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.UPDATING; | |
85 | +import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.VERIFIED; | |
86 | 86 | import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_KEY; |
87 | 87 | import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH; |
88 | 88 | |
... | ... | @@ -139,7 +139,7 @@ public class LwM2mTransportUtil { |
139 | 139 | public static final String ERROR_KEY = "error"; |
140 | 140 | public static final String METHOD_KEY = "methodName"; |
141 | 141 | |
142 | - // FirmWare | |
142 | + // Firmware | |
143 | 143 | public static final String FW_UPDATE = "Firmware update"; |
144 | 144 | public static final Integer FW_ID = 5; |
145 | 145 | // Package W |
... | ... | @@ -155,7 +155,7 @@ public class LwM2mTransportUtil { |
155 | 155 | // Update E |
156 | 156 | public static final String FW_UPDATE_ID = "/5/0/2"; |
157 | 157 | |
158 | - // SoftWare | |
158 | + // Software | |
159 | 159 | public static final String SW_UPDATE = "Software update"; |
160 | 160 | public static final Integer SW_ID = 9; |
161 | 161 | // Package W |
... | ... | @@ -354,7 +354,7 @@ public class LwM2mTransportUtil { |
354 | 354 | * FirmwareUpdateStatus { |
355 | 355 | * DOWNLOADING, DOWNLOADED, VERIFIED, UPDATING, UPDATED, FAILED |
356 | 356 | */ |
357 | - public static FirmwareUpdateStatus EqualsFwSateToFirmwareUpdateStatus(StateFw stateFw, UpdateResultFw updateResultFw) { | |
357 | + public static OtaPackageUpdateStatus EqualsFwSateToFirmwareUpdateStatus(StateFw stateFw, UpdateResultFw updateResultFw) { | |
358 | 358 | switch (updateResultFw) { |
359 | 359 | case INITIAL: |
360 | 360 | switch (stateFw) { |
... | ... | @@ -500,7 +500,7 @@ public class LwM2mTransportUtil { |
500 | 500 | * FirmwareUpdateStatus { |
501 | 501 | * DOWNLOADING, DOWNLOADED, VERIFIED, UPDATING, UPDATED, FAILED |
502 | 502 | */ |
503 | - public static FirmwareUpdateStatus EqualsSwSateToFirmwareUpdateStatus(UpdateStateSw updateStateSw, UpdateResultSw updateResultSw) { | |
503 | + public static OtaPackageUpdateStatus EqualsSwSateToFirmwareUpdateStatus(UpdateStateSw updateStateSw, UpdateResultSw updateResultSw) { | |
504 | 504 | switch (updateResultSw) { |
505 | 505 | case INITIAL: |
506 | 506 | switch (updateStateSw) { |
... | ... | @@ -932,15 +932,15 @@ public class LwM2mTransportUtil { |
932 | 932 | } |
933 | 933 | |
934 | 934 | public static boolean isFwSwWords (String pathName) { |
935 | - return FirmwareUtil.getAttributeKey(FirmwareType.FIRMWARE, FirmwareKey.VERSION).equals(pathName) | |
936 | - || FirmwareUtil.getAttributeKey(FirmwareType.FIRMWARE, FirmwareKey.TITLE).equals(pathName) | |
937 | - || FirmwareUtil.getAttributeKey(FirmwareType.FIRMWARE, FirmwareKey.CHECKSUM).equals(pathName) | |
938 | - || FirmwareUtil.getAttributeKey(FirmwareType.FIRMWARE, FirmwareKey.CHECKSUM_ALGORITHM).equals(pathName) | |
939 | - || FirmwareUtil.getAttributeKey(FirmwareType.FIRMWARE, FirmwareKey.SIZE).equals(pathName) | |
940 | - || FirmwareUtil.getAttributeKey(FirmwareType.SOFTWARE, FirmwareKey.VERSION).equals(pathName) | |
941 | - || FirmwareUtil.getAttributeKey(FirmwareType.SOFTWARE, FirmwareKey.TITLE).equals(pathName) | |
942 | - || FirmwareUtil.getAttributeKey(FirmwareType.SOFTWARE, FirmwareKey.CHECKSUM).equals(pathName) | |
943 | - || FirmwareUtil.getAttributeKey(FirmwareType.SOFTWARE, FirmwareKey.CHECKSUM_ALGORITHM).equals(pathName) | |
944 | - || FirmwareUtil.getAttributeKey(FirmwareType.SOFTWARE, FirmwareKey.SIZE).equals(pathName); | |
935 | + return OtaPackageUtil.getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.VERSION).equals(pathName) | |
936 | + || OtaPackageUtil.getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.TITLE).equals(pathName) | |
937 | + || OtaPackageUtil.getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.CHECKSUM).equals(pathName) | |
938 | + || OtaPackageUtil.getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.CHECKSUM_ALGORITHM).equals(pathName) | |
939 | + || OtaPackageUtil.getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.SIZE).equals(pathName) | |
940 | + || OtaPackageUtil.getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.VERSION).equals(pathName) | |
941 | + || OtaPackageUtil.getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.TITLE).equals(pathName) | |
942 | + || OtaPackageUtil.getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.CHECKSUM).equals(pathName) | |
943 | + || OtaPackageUtil.getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.CHECKSUM_ALGORITHM).equals(pathName) | |
944 | + || OtaPackageUtil.getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.SIZE).equals(pathName); | |
945 | 945 | } |
946 | 946 | } | ... | ... |
... | ... | @@ -31,7 +31,7 @@ import org.eclipse.leshan.server.registration.Registration; |
31 | 31 | import org.eclipse.leshan.server.security.SecurityInfo; |
32 | 32 | import org.thingsboard.server.common.data.Device; |
33 | 33 | import org.thingsboard.server.common.data.DeviceProfile; |
34 | -import org.thingsboard.server.common.data.firmware.FirmwareType; | |
34 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | |
35 | 35 | import org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse; |
36 | 36 | import org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto; |
37 | 37 | import org.thingsboard.server.gen.transport.TransportProtos.TsKvProto; |
... | ... | @@ -120,8 +120,8 @@ public class LwM2mClient implements Cloneable { |
120 | 120 | this.init = false; |
121 | 121 | this.queuedRequests = new ConcurrentLinkedQueue<>(); |
122 | 122 | |
123 | - this.fwUpdate = new LwM2mFwSwUpdate(this, FirmwareType.FIRMWARE); | |
124 | - this.swUpdate = new LwM2mFwSwUpdate(this, FirmwareType.SOFTWARE); | |
123 | + this.fwUpdate = new LwM2mFwSwUpdate(this, OtaPackageType.FIRMWARE); | |
124 | + this.swUpdate = new LwM2mFwSwUpdate(this, OtaPackageType.SOFTWARE); | |
125 | 125 | if (this.credentials != null && this.credentials.hasDeviceInfo()) { |
126 | 126 | this.session = createSession(nodeId, sessionId, credentials); |
127 | 127 | this.deviceId = new UUID(session.getDeviceIdMSB(), session.getDeviceIdLSB()); | ... | ... |
... | ... | @@ -20,8 +20,8 @@ import lombok.Setter; |
20 | 20 | import lombok.extern.slf4j.Slf4j; |
21 | 21 | import org.apache.commons.lang3.StringUtils; |
22 | 22 | import org.eclipse.leshan.core.request.ContentFormat; |
23 | -import org.thingsboard.server.common.data.firmware.FirmwareType; | |
24 | -import org.thingsboard.server.common.data.firmware.FirmwareUpdateStatus; | |
23 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | |
24 | +import org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus; | |
25 | 25 | import org.thingsboard.server.gen.transport.TransportProtos; |
26 | 26 | import org.thingsboard.server.transport.lwm2m.server.DefaultLwM2MTransportMsgHandler; |
27 | 27 | import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportRequest; |
... | ... | @@ -32,11 +32,11 @@ import java.util.List; |
32 | 32 | import java.util.UUID; |
33 | 33 | import java.util.concurrent.CopyOnWriteArrayList; |
34 | 34 | |
35 | -import static org.thingsboard.server.common.data.firmware.FirmwareKey.STATE; | |
36 | -import static org.thingsboard.server.common.data.firmware.FirmwareType.FIRMWARE; | |
37 | -import static org.thingsboard.server.common.data.firmware.FirmwareType.SOFTWARE; | |
38 | -import static org.thingsboard.server.common.data.firmware.FirmwareUpdateStatus.UPDATING; | |
39 | -import static org.thingsboard.server.common.data.firmware.FirmwareUtil.getAttributeKey; | |
35 | +import static org.thingsboard.server.common.data.ota.OtaPackageKey.STATE; | |
36 | +import static org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE; | |
37 | +import static org.thingsboard.server.common.data.ota.OtaPackageType.SOFTWARE; | |
38 | +import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.UPDATING; | |
39 | +import static org.thingsboard.server.common.data.ota.OtaPackageUtil.getAttributeKey; | |
40 | 40 | import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_NAME_ID; |
41 | 41 | import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_PACKAGE_ID; |
42 | 42 | import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_RESULT_ID; |
... | ... | @@ -97,14 +97,14 @@ public class LwM2mFwSwUpdate { |
97 | 97 | @Getter |
98 | 98 | @Setter |
99 | 99 | private volatile boolean infoFwSwUpdate = false; |
100 | - private final FirmwareType type; | |
100 | + private final OtaPackageType type; | |
101 | 101 | @Getter |
102 | 102 | LwM2mClient lwM2MClient; |
103 | 103 | @Getter |
104 | 104 | @Setter |
105 | 105 | private final List<String> pendingInfoRequestsStart; |
106 | 106 | |
107 | - public LwM2mFwSwUpdate(LwM2mClient lwM2MClient, FirmwareType type) { | |
107 | + public LwM2mFwSwUpdate(LwM2mClient lwM2MClient, OtaPackageType type) { | |
108 | 108 | this.lwM2MClient = lwM2MClient; |
109 | 109 | this.pendingInfoRequestsStart = new CopyOnWriteArrayList<>(); |
110 | 110 | this.type = type; |
... | ... | @@ -139,7 +139,7 @@ public class LwM2mFwSwUpdate { |
139 | 139 | } |
140 | 140 | if (this.pendingInfoRequestsStart.size() == 0) { |
141 | 141 | this.infoFwSwUpdate = false; |
142 | - if (!FirmwareUpdateStatus.DOWNLOADING.name().equals(this.stateUpdate)) { | |
142 | + if (!OtaPackageUpdateStatus.DOWNLOADING.name().equals(this.stateUpdate)) { | |
143 | 143 | boolean conditionalStart = this.type.equals(FIRMWARE) ? this.conditionalFwUpdateStart() : |
144 | 144 | this.conditionalSwUpdateStart(); |
145 | 145 | if (conditionalStart) { |
... | ... | @@ -154,12 +154,12 @@ public class LwM2mFwSwUpdate { |
154 | 154 | * before operation Write: fw_state = DOWNLOADING |
155 | 155 | */ |
156 | 156 | private void writeFwSwWare(DefaultLwM2MTransportMsgHandler handler, LwM2mTransportRequest request) { |
157 | - this.stateUpdate = FirmwareUpdateStatus.DOWNLOADING.name(); | |
157 | + this.stateUpdate = OtaPackageUpdateStatus.DOWNLOADING.name(); | |
158 | 158 | // this.observeStateUpdate(); |
159 | 159 | this.sendLogs(handler, WRITE_REPLACE.name(), LOG_LW2M_INFO, null); |
160 | 160 | int chunkSize = 0; |
161 | 161 | int chunk = 0; |
162 | - byte[] firmwareChunk = handler.firmwareDataCache.get(this.currentId.toString(), chunkSize, chunk); | |
162 | + byte[] firmwareChunk = handler.otaPackageDataCache.get(this.currentId.toString(), chunkSize, chunk); | |
163 | 163 | String targetIdVer = convertPathFromObjectIdToIdVer(this.pathPackageId, this.lwM2MClient.getRegistration()); |
164 | 164 | request.sendAllRequest(lwM2MClient.getRegistration(), targetIdVer, WRITE_REPLACE, ContentFormat.OPAQUE.getName(), |
165 | 165 | firmwareChunk, handler.config.getTimeout(), null); |
... | ... | @@ -287,10 +287,10 @@ public class LwM2mFwSwUpdate { |
287 | 287 | LwM2mTransportUtil.UpdateResultSw.fromUpdateResultSwByCode(updateResult.intValue()).type; |
288 | 288 | String key = splitCamelCaseString((String) this.lwM2MClient.getResourceNameByRezId(null, this.pathResultId)); |
289 | 289 | if (success) { |
290 | - this.stateUpdate = FirmwareUpdateStatus.UPDATED.name(); | |
290 | + this.stateUpdate = OtaPackageUpdateStatus.UPDATED.name(); | |
291 | 291 | this.sendLogs(handler, EXECUTE.name(), LOG_LW2M_INFO, null); |
292 | 292 | } else { |
293 | - this.stateUpdate = FirmwareUpdateStatus.FAILED.name(); | |
293 | + this.stateUpdate = OtaPackageUpdateStatus.FAILED.name(); | |
294 | 294 | this.sendLogs(handler, EXECUTE.name(), LOG_LW2M_ERROR, value); |
295 | 295 | } |
296 | 296 | handler.helper.sendParametersOnThingsboardTelemetry( | ... | ... |
... | ... | @@ -337,23 +337,24 @@ public class TbLwM2mRedisRegistrationStore implements CaliforniumRegistrationSto |
337 | 337 | } |
338 | 338 | } |
339 | 339 | |
340 | + //TODO: JedisCluster didn't implement Transaction, maybe should use some advanced key creation strategies | |
340 | 341 | private void removeAddrIndex(RedisConnection connection, Registration registration) { |
341 | 342 | // Watch the key to remove. |
342 | 343 | byte[] regAddrKey = toRegAddrKey(registration.getSocketAddress()); |
343 | - connection.watch(regAddrKey); | |
344 | +// connection.watch(regAddrKey); | |
344 | 345 | |
345 | 346 | byte[] epFromAddr = connection.get(regAddrKey); |
346 | 347 | // Delete the key if needed. |
347 | 348 | if (Arrays.equals(epFromAddr, registration.getEndpoint().getBytes(UTF_8))) { |
348 | 349 | // Try to delete the key |
349 | - connection.multi(); | |
350 | +// connection.multi(); | |
350 | 351 | connection.del(regAddrKey); |
351 | - connection.exec(); | |
352 | +// connection.exec(); | |
352 | 353 | // if transaction failed this is not an issue as the socket address is probably reused and we don't neeed to |
353 | 354 | // delete it anymore. |
354 | 355 | } else { |
355 | 356 | // the key must not be deleted. |
356 | - connection.unwatch(); | |
357 | +// connection.unwatch(); | |
357 | 358 | } |
358 | 359 | } |
359 | 360 | ... | ... |
... | ... | @@ -47,8 +47,8 @@ import org.thingsboard.server.common.data.DeviceProfile; |
47 | 47 | import org.thingsboard.server.common.data.DeviceTransportType; |
48 | 48 | import org.thingsboard.server.common.data.TransportPayloadType; |
49 | 49 | import org.thingsboard.server.common.data.device.profile.MqttTopics; |
50 | -import org.thingsboard.server.common.data.firmware.FirmwareType; | |
51 | -import org.thingsboard.server.common.data.id.FirmwareId; | |
50 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | |
51 | +import org.thingsboard.server.common.data.id.OtaPackageId; | |
52 | 52 | import org.thingsboard.server.common.msg.EncryptionUtil; |
53 | 53 | import org.thingsboard.server.common.msg.tools.TbRateLimitsException; |
54 | 54 | import org.thingsboard.server.common.transport.SessionMsgListener; |
... | ... | @@ -126,8 +126,8 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement |
126 | 126 | private volatile InetSocketAddress address; |
127 | 127 | private volatile GatewaySessionHandler gatewaySessionHandler; |
128 | 128 | |
129 | - private final ConcurrentHashMap<String, String> fwSessions; | |
130 | - private final ConcurrentHashMap<String, Integer> fwChunkSizes; | |
129 | + private final ConcurrentHashMap<String, String> otaPackSessions; | |
130 | + private final ConcurrentHashMap<String, Integer> chunkSizes; | |
131 | 131 | |
132 | 132 | MqttTransportHandler(MqttTransportContext context, SslHandler sslHandler) { |
133 | 133 | this.sessionId = UUID.randomUUID(); |
... | ... | @@ -137,8 +137,8 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement |
137 | 137 | this.sslHandler = sslHandler; |
138 | 138 | this.mqttQoSMap = new ConcurrentHashMap<>(); |
139 | 139 | this.deviceSessionCtx = new DeviceSessionCtx(sessionId, mqttQoSMap, context); |
140 | - this.fwSessions = new ConcurrentHashMap<>(); | |
141 | - this.fwChunkSizes = new ConcurrentHashMap<>(); | |
140 | + this.otaPackSessions = new ConcurrentHashMap<>(); | |
141 | + this.chunkSizes = new ConcurrentHashMap<>(); | |
142 | 142 | } |
143 | 143 | |
144 | 144 | @Override |
... | ... | @@ -320,9 +320,9 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement |
320 | 320 | TransportProtos.ClaimDeviceMsg claimDeviceMsg = payloadAdaptor.convertToClaimDevice(deviceSessionCtx, mqttMsg); |
321 | 321 | transportService.process(deviceSessionCtx.getSessionInfo(), claimDeviceMsg, getPubAckCallback(ctx, msgId, claimDeviceMsg)); |
322 | 322 | } else if ((fwMatcher = FW_REQUEST_PATTERN.matcher(topicName)).find()) { |
323 | - getFirmwareCallback(ctx, mqttMsg, msgId, fwMatcher, FirmwareType.FIRMWARE); | |
323 | + getOtaPackageCallback(ctx, mqttMsg, msgId, fwMatcher, OtaPackageType.FIRMWARE); | |
324 | 324 | } else if ((fwMatcher = SW_REQUEST_PATTERN.matcher(topicName)).find()) { |
325 | - getFirmwareCallback(ctx, mqttMsg, msgId, fwMatcher, FirmwareType.SOFTWARE); | |
325 | + getOtaPackageCallback(ctx, mqttMsg, msgId, fwMatcher, OtaPackageType.SOFTWARE); | |
326 | 326 | } else { |
327 | 327 | transportService.reportActivity(deviceSessionCtx.getSessionInfo()); |
328 | 328 | ack(ctx, msgId); |
... | ... | @@ -334,38 +334,38 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement |
334 | 334 | } |
335 | 335 | } |
336 | 336 | |
337 | - private void getFirmwareCallback(ChannelHandlerContext ctx, MqttPublishMessage mqttMsg, int msgId, Matcher fwMatcher, FirmwareType type) { | |
337 | + private void getOtaPackageCallback(ChannelHandlerContext ctx, MqttPublishMessage mqttMsg, int msgId, Matcher fwMatcher, OtaPackageType type) { | |
338 | 338 | String payload = mqttMsg.content().toString(UTF8); |
339 | 339 | int chunkSize = StringUtils.isNotEmpty(payload) ? Integer.parseInt(payload) : 0; |
340 | 340 | String requestId = fwMatcher.group("requestId"); |
341 | 341 | int chunk = Integer.parseInt(fwMatcher.group("chunk")); |
342 | 342 | |
343 | 343 | if (chunkSize > 0) { |
344 | - this.fwChunkSizes.put(requestId, chunkSize); | |
344 | + this.chunkSizes.put(requestId, chunkSize); | |
345 | 345 | } else { |
346 | - chunkSize = fwChunkSizes.getOrDefault(requestId, 0); | |
346 | + chunkSize = chunkSizes.getOrDefault(requestId, 0); | |
347 | 347 | } |
348 | 348 | |
349 | 349 | if (chunkSize > context.getMaxPayloadSize()) { |
350 | - sendFirmwareError(ctx, PAYLOAD_TOO_LARGE); | |
350 | + sendOtaPackageError(ctx, PAYLOAD_TOO_LARGE); | |
351 | 351 | return; |
352 | 352 | } |
353 | 353 | |
354 | - String firmwareId = fwSessions.get(requestId); | |
354 | + String otaPackageId = otaPackSessions.get(requestId); | |
355 | 355 | |
356 | - if (firmwareId != null) { | |
357 | - sendFirmware(ctx, mqttMsg.variableHeader().packetId(), firmwareId, requestId, chunkSize, chunk, type); | |
356 | + if (otaPackageId != null) { | |
357 | + sendOtaPackage(ctx, mqttMsg.variableHeader().packetId(), otaPackageId, requestId, chunkSize, chunk, type); | |
358 | 358 | } else { |
359 | 359 | TransportProtos.SessionInfoProto sessionInfo = deviceSessionCtx.getSessionInfo(); |
360 | - TransportProtos.GetFirmwareRequestMsg getFirmwareRequestMsg = TransportProtos.GetFirmwareRequestMsg.newBuilder() | |
360 | + TransportProtos.GetOtaPackageRequestMsg getOtaPackageRequestMsg = TransportProtos.GetOtaPackageRequestMsg.newBuilder() | |
361 | 361 | .setDeviceIdMSB(sessionInfo.getDeviceIdMSB()) |
362 | 362 | .setDeviceIdLSB(sessionInfo.getDeviceIdLSB()) |
363 | 363 | .setTenantIdMSB(sessionInfo.getTenantIdMSB()) |
364 | 364 | .setTenantIdLSB(sessionInfo.getTenantIdLSB()) |
365 | 365 | .setType(type.name()) |
366 | 366 | .build(); |
367 | - transportService.process(deviceSessionCtx.getSessionInfo(), getFirmwareRequestMsg, | |
368 | - new FirmwareCallback(ctx, msgId, getFirmwareRequestMsg, requestId, chunkSize, chunk)); | |
367 | + transportService.process(deviceSessionCtx.getSessionInfo(), getOtaPackageRequestMsg, | |
368 | + new OtaPackageCallback(ctx, msgId, getOtaPackageRequestMsg, requestId, chunkSize, chunk)); | |
369 | 369 | } |
370 | 370 | } |
371 | 371 | |
... | ... | @@ -425,15 +425,15 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement |
425 | 425 | } |
426 | 426 | } |
427 | 427 | |
428 | - private class FirmwareCallback implements TransportServiceCallback<TransportProtos.GetFirmwareResponseMsg> { | |
428 | + private class OtaPackageCallback implements TransportServiceCallback<TransportProtos.GetOtaPackageResponseMsg> { | |
429 | 429 | private final ChannelHandlerContext ctx; |
430 | 430 | private final int msgId; |
431 | - private final TransportProtos.GetFirmwareRequestMsg msg; | |
431 | + private final TransportProtos.GetOtaPackageRequestMsg msg; | |
432 | 432 | private final String requestId; |
433 | 433 | private final int chunkSize; |
434 | 434 | private final int chunk; |
435 | 435 | |
436 | - FirmwareCallback(ChannelHandlerContext ctx, int msgId, TransportProtos.GetFirmwareRequestMsg msg, String requestId, int chunkSize, int chunk) { | |
436 | + OtaPackageCallback(ChannelHandlerContext ctx, int msgId, TransportProtos.GetOtaPackageRequestMsg msg, String requestId, int chunkSize, int chunk) { | |
437 | 437 | this.ctx = ctx; |
438 | 438 | this.msgId = msgId; |
439 | 439 | this.msg = msg; |
... | ... | @@ -443,13 +443,13 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement |
443 | 443 | } |
444 | 444 | |
445 | 445 | @Override |
446 | - public void onSuccess(TransportProtos.GetFirmwareResponseMsg response) { | |
446 | + public void onSuccess(TransportProtos.GetOtaPackageResponseMsg response) { | |
447 | 447 | if (TransportProtos.ResponseStatus.SUCCESS.equals(response.getResponseStatus())) { |
448 | - FirmwareId firmwareId = new FirmwareId(new UUID(response.getFirmwareIdMSB(), response.getFirmwareIdLSB())); | |
449 | - fwSessions.put(requestId, firmwareId.toString()); | |
450 | - sendFirmware(ctx, msgId, firmwareId.toString(), requestId, chunkSize, chunk, FirmwareType.valueOf(response.getType())); | |
448 | + OtaPackageId firmwareId = new OtaPackageId(new UUID(response.getOtaPackageIdMSB(), response.getOtaPackageIdLSB())); | |
449 | + otaPackSessions.put(requestId, firmwareId.toString()); | |
450 | + sendOtaPackage(ctx, msgId, firmwareId.toString(), requestId, chunkSize, chunk, OtaPackageType.valueOf(response.getType())); | |
451 | 451 | } else { |
452 | - sendFirmwareError(ctx, response.getResponseStatus().toString()); | |
452 | + sendOtaPackageError(ctx, response.getResponseStatus().toString()); | |
453 | 453 | } |
454 | 454 | } |
455 | 455 | |
... | ... | @@ -460,11 +460,11 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement |
460 | 460 | } |
461 | 461 | } |
462 | 462 | |
463 | - private void sendFirmware(ChannelHandlerContext ctx, int msgId, String firmwareId, String requestId, int chunkSize, int chunk, FirmwareType type) { | |
463 | + private void sendOtaPackage(ChannelHandlerContext ctx, int msgId, String firmwareId, String requestId, int chunkSize, int chunk, OtaPackageType type) { | |
464 | 464 | log.trace("[{}] Send firmware [{}] to device!", sessionId, firmwareId); |
465 | 465 | ack(ctx, msgId); |
466 | 466 | try { |
467 | - byte[] firmwareChunk = context.getFirmwareDataCache().get(firmwareId, chunkSize, chunk); | |
467 | + byte[] firmwareChunk = context.getOtaPackageDataCache().get(firmwareId, chunkSize, chunk); | |
468 | 468 | deviceSessionCtx.getPayloadAdaptor() |
469 | 469 | .convertToPublish(deviceSessionCtx, firmwareChunk, requestId, chunk, type) |
470 | 470 | .ifPresent(deviceSessionCtx.getChannel()::writeAndFlush); |
... | ... | @@ -473,7 +473,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement |
473 | 473 | } |
474 | 474 | } |
475 | 475 | |
476 | - private void sendFirmwareError(ChannelHandlerContext ctx, String error) { | |
476 | + private void sendOtaPackageError(ChannelHandlerContext ctx, String error) { | |
477 | 477 | log.warn("[{}] {}", sessionId, error); |
478 | 478 | deviceSessionCtx.getChannel().writeAndFlush(deviceSessionCtx |
479 | 479 | .getPayloadAdaptor() | ... | ... |
... | ... | @@ -30,7 +30,7 @@ import lombok.extern.slf4j.Slf4j; |
30 | 30 | import org.springframework.stereotype.Component; |
31 | 31 | import org.springframework.util.StringUtils; |
32 | 32 | import org.thingsboard.server.common.data.device.profile.MqttTopics; |
33 | -import org.thingsboard.server.common.data.firmware.FirmwareType; | |
33 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | |
34 | 34 | import org.thingsboard.server.common.transport.adaptor.AdaptorException; |
35 | 35 | import org.thingsboard.server.common.transport.adaptor.JsonConverter; |
36 | 36 | import org.thingsboard.server.gen.transport.TransportProtos; |
... | ... | @@ -155,7 +155,7 @@ public class JsonMqttAdaptor implements MqttTransportAdaptor { |
155 | 155 | } |
156 | 156 | |
157 | 157 | @Override |
158 | - public Optional<MqttMessage> convertToPublish(MqttDeviceAwareSessionContext ctx, byte[] firmwareChunk, String requestId, int chunk, FirmwareType firmwareType) { | |
158 | + public Optional<MqttMessage> convertToPublish(MqttDeviceAwareSessionContext ctx, byte[] firmwareChunk, String requestId, int chunk, OtaPackageType firmwareType) { | |
159 | 159 | return Optional.of(createMqttPublishMsg(ctx, String.format(DEVICE_SOFTWARE_FIRMWARE_RESPONSES_TOPIC_FORMAT, firmwareType.getKeyPrefix(), requestId, chunk), firmwareChunk)); |
160 | 160 | } |
161 | 161 | ... | ... |
... | ... | @@ -23,7 +23,7 @@ import io.netty.handler.codec.mqtt.MqttMessage; |
23 | 23 | import io.netty.handler.codec.mqtt.MqttMessageType; |
24 | 24 | import io.netty.handler.codec.mqtt.MqttPublishMessage; |
25 | 25 | import io.netty.handler.codec.mqtt.MqttPublishVariableHeader; |
26 | -import org.thingsboard.server.common.data.firmware.FirmwareType; | |
26 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | |
27 | 27 | import org.thingsboard.server.common.transport.adaptor.AdaptorException; |
28 | 28 | import org.thingsboard.server.gen.transport.TransportProtos.AttributeUpdateNotificationMsg; |
29 | 29 | import org.thingsboard.server.gen.transport.TransportProtos.ClaimDeviceMsg; |
... | ... | @@ -78,7 +78,7 @@ public interface MqttTransportAdaptor { |
78 | 78 | |
79 | 79 | Optional<MqttMessage> convertToPublish(MqttDeviceAwareSessionContext ctx, ProvisionDeviceResponseMsg provisionResponse) throws AdaptorException; |
80 | 80 | |
81 | - Optional<MqttMessage> convertToPublish(MqttDeviceAwareSessionContext ctx, byte[] firmwareChunk, String requestId, int chunk, FirmwareType firmwareType) throws AdaptorException; | |
81 | + Optional<MqttMessage> convertToPublish(MqttDeviceAwareSessionContext ctx, byte[] firmwareChunk, String requestId, int chunk, OtaPackageType firmwareType) throws AdaptorException; | |
82 | 82 | |
83 | 83 | default MqttPublishMessage createMqttPublishMsg(MqttDeviceAwareSessionContext ctx, String topic, byte[] payloadInBytes) { |
84 | 84 | MqttFixedHeader mqttFixedHeader = | ... | ... |
... | ... | @@ -28,7 +28,7 @@ import lombok.extern.slf4j.Slf4j; |
28 | 28 | import org.springframework.stereotype.Component; |
29 | 29 | import org.springframework.util.StringUtils; |
30 | 30 | import org.thingsboard.server.common.data.device.profile.MqttTopics; |
31 | -import org.thingsboard.server.common.data.firmware.FirmwareType; | |
31 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | |
32 | 32 | import org.thingsboard.server.common.transport.adaptor.AdaptorException; |
33 | 33 | import org.thingsboard.server.common.transport.adaptor.JsonConverter; |
34 | 34 | import org.thingsboard.server.common.transport.adaptor.ProtoConverter; |
... | ... | @@ -168,7 +168,7 @@ public class ProtoMqttAdaptor implements MqttTransportAdaptor { |
168 | 168 | } |
169 | 169 | |
170 | 170 | @Override |
171 | - public Optional<MqttMessage> convertToPublish(MqttDeviceAwareSessionContext ctx, byte[] firmwareChunk, String requestId, int chunk, FirmwareType firmwareType) throws AdaptorException { | |
171 | + public Optional<MqttMessage> convertToPublish(MqttDeviceAwareSessionContext ctx, byte[] firmwareChunk, String requestId, int chunk, OtaPackageType firmwareType) throws AdaptorException { | |
172 | 172 | return Optional.of(createMqttPublishMsg(ctx, String.format(DEVICE_SOFTWARE_FIRMWARE_RESPONSES_TOPIC_FORMAT, firmwareType.getKeyPrefix(), requestId, chunk), firmwareChunk)); |
173 | 173 | } |
174 | 174 | ... | ... |
... | ... | @@ -21,14 +21,13 @@ import lombok.Getter; |
21 | 21 | import lombok.extern.slf4j.Slf4j; |
22 | 22 | import org.springframework.beans.factory.annotation.Autowired; |
23 | 23 | import org.thingsboard.common.util.ThingsBoardExecutors; |
24 | -import org.thingsboard.server.cache.firmware.FirmwareDataCache; | |
24 | +import org.thingsboard.server.cache.ota.OtaPackageDataCache; | |
25 | 25 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; |
26 | 26 | import org.thingsboard.server.queue.scheduler.SchedulerComponent; |
27 | 27 | |
28 | 28 | import javax.annotation.PostConstruct; |
29 | 29 | import javax.annotation.PreDestroy; |
30 | 30 | import java.util.concurrent.ExecutorService; |
31 | -import java.util.concurrent.Executors; | |
32 | 31 | |
33 | 32 | /** |
34 | 33 | * Created by ashvayka on 15.10.18. |
... | ... | @@ -53,7 +52,7 @@ public abstract class TransportContext { |
53 | 52 | |
54 | 53 | @Getter |
55 | 54 | @Autowired |
56 | - private FirmwareDataCache firmwareDataCache; | |
55 | + private OtaPackageDataCache otaPackageDataCache; | |
57 | 56 | |
58 | 57 | @Autowired |
59 | 58 | private TransportResourceCache transportResourceCache; | ... | ... |
... | ... | @@ -29,8 +29,8 @@ import org.thingsboard.server.gen.transport.TransportProtos.GetDeviceRequestMsg; |
29 | 29 | import org.thingsboard.server.gen.transport.TransportProtos.GetDeviceResponseMsg; |
30 | 30 | import org.thingsboard.server.gen.transport.TransportProtos.GetEntityProfileRequestMsg; |
31 | 31 | import org.thingsboard.server.gen.transport.TransportProtos.GetEntityProfileResponseMsg; |
32 | -import org.thingsboard.server.gen.transport.TransportProtos.GetFirmwareRequestMsg; | |
33 | -import org.thingsboard.server.gen.transport.TransportProtos.GetFirmwareResponseMsg; | |
32 | +import org.thingsboard.server.gen.transport.TransportProtos.GetOtaPackageRequestMsg; | |
33 | +import org.thingsboard.server.gen.transport.TransportProtos.GetOtaPackageResponseMsg; | |
34 | 34 | import org.thingsboard.server.gen.transport.TransportProtos.GetOrCreateDeviceFromGatewayRequestMsg; |
35 | 35 | import org.thingsboard.server.gen.transport.TransportProtos.GetResourceRequestMsg; |
36 | 36 | import org.thingsboard.server.gen.transport.TransportProtos.GetResourceResponseMsg; |
... | ... | @@ -115,7 +115,7 @@ public interface TransportService { |
115 | 115 | |
116 | 116 | void process(TransportToDeviceActorMsg msg, TransportServiceCallback<Void> callback); |
117 | 117 | |
118 | - void process(SessionInfoProto sessionInfoProto, GetFirmwareRequestMsg msg, TransportServiceCallback<GetFirmwareResponseMsg> callback); | |
118 | + void process(SessionInfoProto sessionInfoProto, GetOtaPackageRequestMsg msg, TransportServiceCallback<GetOtaPackageResponseMsg> callback); | |
119 | 119 | |
120 | 120 | SessionMetaData registerAsyncSession(SessionInfoProto sessionInfo, SessionMsgListener listener); |
121 | 121 | ... | ... |
... | ... | @@ -614,13 +614,13 @@ public class DefaultTransportService implements TransportService { |
614 | 614 | } |
615 | 615 | |
616 | 616 | @Override |
617 | - public void process(TransportProtos.SessionInfoProto sessionInfo, TransportProtos.GetFirmwareRequestMsg msg, TransportServiceCallback<TransportProtos.GetFirmwareResponseMsg> callback) { | |
617 | + public void process(TransportProtos.SessionInfoProto sessionInfo, TransportProtos.GetOtaPackageRequestMsg msg, TransportServiceCallback<TransportProtos.GetOtaPackageResponseMsg> callback) { | |
618 | 618 | if (checkLimits(sessionInfo, msg, callback)) { |
619 | 619 | TbProtoQueueMsg<TransportProtos.TransportApiRequestMsg> protoMsg = |
620 | - new TbProtoQueueMsg<>(UUID.randomUUID(), TransportProtos.TransportApiRequestMsg.newBuilder().setFirmwareRequestMsg(msg).build()); | |
620 | + new TbProtoQueueMsg<>(UUID.randomUUID(), TransportProtos.TransportApiRequestMsg.newBuilder().setOtaPackageRequestMsg(msg).build()); | |
621 | 621 | |
622 | 622 | AsyncCallbackTemplate.withCallback(transportApiRequestTemplate.send(protoMsg), response -> { |
623 | - callback.onSuccess(response.getValue().getFirmwareResponseMsg()); | |
623 | + callback.onSuccess(response.getValue().getOtaPackageResponseMsg()); | |
624 | 624 | }, callback::onError, transportCallbackExecutor); |
625 | 625 | } |
626 | 626 | } | ... | ... |
... | ... | @@ -21,6 +21,7 @@ import org.thingsboard.server.common.data.DeviceInfo; |
21 | 21 | import org.thingsboard.server.common.data.DeviceTransportType; |
22 | 22 | import org.thingsboard.server.common.data.EntitySubtype; |
23 | 23 | import org.thingsboard.server.common.data.id.TenantId; |
24 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | |
24 | 25 | import org.thingsboard.server.common.data.page.PageData; |
25 | 26 | import org.thingsboard.server.common.data.page.PageLink; |
26 | 27 | import org.thingsboard.server.dao.Dao; |
... | ... | @@ -81,9 +82,12 @@ public interface DeviceDao extends Dao<Device>, TenantEntityDao { |
81 | 82 | */ |
82 | 83 | PageData<Device> findDevicesByTenantIdAndType(UUID tenantId, String type, PageLink pageLink); |
83 | 84 | |
84 | - PageData<Device> findDevicesByTenantIdAndTypeAndEmptyFirmware(UUID tenantId, String type, PageLink pageLink); | |
85 | + PageData<Device> findDevicesByTenantIdAndTypeAndEmptyOtaPackage(UUID tenantId, | |
86 | + UUID deviceProfileId, | |
87 | + OtaPackageType type, | |
88 | + PageLink pageLink); | |
85 | 89 | |
86 | - PageData<Device> findDevicesByTenantIdAndTypeAndEmptySoftware(UUID tenantId, String type, PageLink pageLink); | |
90 | + Long countDevicesByTenantIdAndDeviceProfileIdAndEmptyOtaPackage(UUID tenantId, UUID deviceProfileId, OtaPackageType otaPackageType); | |
87 | 91 | |
88 | 92 | /** |
89 | 93 | * Find device infos by tenantId, type and page link. | ... | ... |
... | ... | @@ -43,7 +43,7 @@ import org.thingsboard.server.common.data.DeviceProfileInfo; |
43 | 43 | import org.thingsboard.server.common.data.DeviceProfileProvisionType; |
44 | 44 | import org.thingsboard.server.common.data.DeviceProfileType; |
45 | 45 | import org.thingsboard.server.common.data.DeviceTransportType; |
46 | -import org.thingsboard.server.common.data.Firmware; | |
46 | +import org.thingsboard.server.common.data.OtaPackage; | |
47 | 47 | import org.thingsboard.server.common.data.Tenant; |
48 | 48 | import org.thingsboard.server.common.data.device.profile.CoapDeviceProfileTransportConfiguration; |
49 | 49 | import org.thingsboard.server.common.data.device.profile.CoapDeviceTypeConfiguration; |
... | ... | @@ -57,7 +57,7 @@ import org.thingsboard.server.common.data.device.profile.DisabledDeviceProfilePr |
57 | 57 | import org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration; |
58 | 58 | import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration; |
59 | 59 | import org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration; |
60 | -import org.thingsboard.server.common.data.firmware.FirmwareType; | |
60 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | |
61 | 61 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
62 | 62 | import org.thingsboard.server.common.data.id.TenantId; |
63 | 63 | import org.thingsboard.server.common.data.page.PageData; |
... | ... | @@ -66,7 +66,7 @@ import org.thingsboard.server.common.data.rule.RuleChain; |
66 | 66 | import org.thingsboard.server.dao.dashboard.DashboardService; |
67 | 67 | import org.thingsboard.server.dao.entity.AbstractEntityService; |
68 | 68 | import org.thingsboard.server.dao.exception.DataValidationException; |
69 | -import org.thingsboard.server.dao.firmware.FirmwareService; | |
69 | +import org.thingsboard.server.dao.ota.OtaPackageService; | |
70 | 70 | import org.thingsboard.server.dao.rule.RuleChainService; |
71 | 71 | import org.thingsboard.server.dao.service.DataValidator; |
72 | 72 | import org.thingsboard.server.dao.service.PaginatedRemover; |
... | ... | @@ -119,7 +119,7 @@ public class DeviceProfileServiceImpl extends AbstractEntityService implements D |
119 | 119 | private CacheManager cacheManager; |
120 | 120 | |
121 | 121 | @Autowired |
122 | - private FirmwareService firmwareService; | |
122 | + private OtaPackageService otaPackageService; | |
123 | 123 | |
124 | 124 | @Autowired |
125 | 125 | private RuleChainService ruleChainService; |
... | ... | @@ -427,11 +427,11 @@ public class DeviceProfileServiceImpl extends AbstractEntityService implements D |
427 | 427 | } |
428 | 428 | |
429 | 429 | if (deviceProfile.getFirmwareId() != null) { |
430 | - Firmware firmware = firmwareService.findFirmwareById(tenantId, deviceProfile.getFirmwareId()); | |
430 | + OtaPackage firmware = otaPackageService.findOtaPackageById(tenantId, deviceProfile.getFirmwareId()); | |
431 | 431 | if (firmware == null) { |
432 | 432 | throw new DataValidationException("Can't assign non-existent firmware!"); |
433 | 433 | } |
434 | - if (!firmware.getType().equals(FirmwareType.FIRMWARE)) { | |
434 | + if (!firmware.getType().equals(OtaPackageType.FIRMWARE)) { | |
435 | 435 | throw new DataValidationException("Can't assign firmware with type: " + firmware.getType()); |
436 | 436 | } |
437 | 437 | if (firmware.getData() == null) { |
... | ... | @@ -443,11 +443,11 @@ public class DeviceProfileServiceImpl extends AbstractEntityService implements D |
443 | 443 | } |
444 | 444 | |
445 | 445 | if (deviceProfile.getSoftwareId() != null) { |
446 | - Firmware software = firmwareService.findFirmwareById(tenantId, deviceProfile.getSoftwareId()); | |
446 | + OtaPackage software = otaPackageService.findOtaPackageById(tenantId, deviceProfile.getSoftwareId()); | |
447 | 447 | if (software == null) { |
448 | 448 | throw new DataValidationException("Can't assign non-existent software!"); |
449 | 449 | } |
450 | - if (!software.getType().equals(FirmwareType.SOFTWARE)) { | |
450 | + if (!software.getType().equals(OtaPackageType.SOFTWARE)) { | |
451 | 451 | throw new DataValidationException("Can't assign software with type: " + software.getType()); |
452 | 452 | } |
453 | 453 | if (software.getData() == null) { | ... | ... |
... | ... | @@ -41,7 +41,7 @@ import org.thingsboard.server.common.data.DeviceTransportType; |
41 | 41 | import org.thingsboard.server.common.data.EntitySubtype; |
42 | 42 | import org.thingsboard.server.common.data.EntityType; |
43 | 43 | import org.thingsboard.server.common.data.EntityView; |
44 | -import org.thingsboard.server.common.data.Firmware; | |
44 | +import org.thingsboard.server.common.data.OtaPackage; | |
45 | 45 | import org.thingsboard.server.common.data.Tenant; |
46 | 46 | import org.thingsboard.server.common.data.device.DeviceSearchQuery; |
47 | 47 | import org.thingsboard.server.common.data.device.credentials.BasicMqttCredentials; |
... | ... | @@ -54,13 +54,13 @@ import org.thingsboard.server.common.data.device.data.Lwm2mDeviceTransportConfig |
54 | 54 | import org.thingsboard.server.common.data.device.data.MqttDeviceTransportConfiguration; |
55 | 55 | import org.thingsboard.server.common.data.device.data.SnmpDeviceTransportConfiguration; |
56 | 56 | import org.thingsboard.server.common.data.edge.Edge; |
57 | -import org.thingsboard.server.common.data.firmware.FirmwareType; | |
58 | 57 | import org.thingsboard.server.common.data.id.CustomerId; |
59 | 58 | import org.thingsboard.server.common.data.id.DeviceId; |
60 | 59 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
61 | 60 | import org.thingsboard.server.common.data.id.EdgeId; |
62 | 61 | import org.thingsboard.server.common.data.id.EntityId; |
63 | 62 | import org.thingsboard.server.common.data.id.TenantId; |
63 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | |
64 | 64 | import org.thingsboard.server.common.data.page.PageData; |
65 | 65 | import org.thingsboard.server.common.data.page.PageLink; |
66 | 66 | import org.thingsboard.server.common.data.relation.EntityRelation; |
... | ... | @@ -76,7 +76,7 @@ import org.thingsboard.server.dao.device.provision.ProvisionResponseStatus; |
76 | 76 | import org.thingsboard.server.dao.entity.AbstractEntityService; |
77 | 77 | import org.thingsboard.server.dao.event.EventService; |
78 | 78 | import org.thingsboard.server.dao.exception.DataValidationException; |
79 | -import org.thingsboard.server.dao.firmware.FirmwareService; | |
79 | +import org.thingsboard.server.dao.ota.OtaPackageService; | |
80 | 80 | import org.thingsboard.server.dao.service.DataValidator; |
81 | 81 | import org.thingsboard.server.dao.service.PaginatedRemover; |
82 | 82 | import org.thingsboard.server.dao.tenant.TbTenantProfileCache; |
... | ... | @@ -138,7 +138,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe |
138 | 138 | private TbTenantProfileCache tenantProfileCache; |
139 | 139 | |
140 | 140 | @Autowired |
141 | - private FirmwareService firmwareService; | |
141 | + private OtaPackageService otaPackageService; | |
142 | 142 | |
143 | 143 | @Override |
144 | 144 | public DeviceInfo findDeviceInfoById(TenantId tenantId, DeviceId deviceId) { |
... | ... | @@ -201,14 +201,12 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe |
201 | 201 | deviceCredentials.setDeviceId(savedDevice.getId()); |
202 | 202 | if (device.getId() == null) { |
203 | 203 | deviceCredentialsService.createDeviceCredentials(savedDevice.getTenantId(), deviceCredentials); |
204 | - } | |
205 | - else { | |
204 | + } else { | |
206 | 205 | DeviceCredentials foundDeviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(device.getTenantId(), savedDevice.getId()); |
207 | 206 | if (foundDeviceCredentials == null) { |
208 | 207 | deviceCredentialsService.createDeviceCredentials(savedDevice.getTenantId(), deviceCredentials); |
209 | - } | |
210 | - else { | |
211 | - deviceCredentialsService.updateDeviceCredentials(device.getTenantId(), deviceCredentials); | |
208 | + } else { | |
209 | + deviceCredentialsService.updateDeviceCredentials(device.getTenantId(), deviceCredentials); | |
212 | 210 | } |
213 | 211 | } |
214 | 212 | return savedDevice; |
... | ... | @@ -364,21 +362,24 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe |
364 | 362 | } |
365 | 363 | |
366 | 364 | @Override |
367 | - public PageData<Device> findDevicesByTenantIdAndTypeAndEmptyFirmware(TenantId tenantId, String type, PageLink pageLink) { | |
368 | - log.trace("Executing findDevicesByTenantIdAndTypeAndEmptyFirmware, tenantId [{}], type [{}], pageLink [{}]", tenantId, type, pageLink); | |
365 | + public PageData<Device> findDevicesByTenantIdAndTypeAndEmptyOtaPackage(TenantId tenantId, | |
366 | + DeviceProfileId deviceProfileId, | |
367 | + OtaPackageType type, | |
368 | + PageLink pageLink) { | |
369 | + log.trace("Executing findDevicesByTenantIdAndTypeAndEmptyOtaPackage, tenantId [{}], deviceProfileId [{}], type [{}], pageLink [{}]", | |
370 | + tenantId, deviceProfileId, type, pageLink); | |
369 | 371 | validateId(tenantId, INCORRECT_TENANT_ID + tenantId); |
370 | - validateString(type, "Incorrect type " + type); | |
372 | + validateId(tenantId, INCORRECT_DEVICE_PROFILE_ID + deviceProfileId); | |
371 | 373 | validatePageLink(pageLink); |
372 | - return deviceDao.findDevicesByTenantIdAndTypeAndEmptyFirmware(tenantId.getId(), type, pageLink); | |
374 | + return deviceDao.findDevicesByTenantIdAndTypeAndEmptyOtaPackage(tenantId.getId(), deviceProfileId.getId(), type, pageLink); | |
373 | 375 | } |
374 | 376 | |
375 | 377 | @Override |
376 | - public PageData<Device> findDevicesByTenantIdAndTypeAndEmptySoftware(TenantId tenantId, String type, PageLink pageLink) { | |
377 | - log.trace("Executing findDevicesByTenantIdAndTypeAndEmptySoftware, tenantId [{}], type [{}], pageLink [{}]", tenantId, type, pageLink); | |
378 | + public Long countDevicesByTenantIdAndDeviceProfileIdAndEmptyOtaPackage(TenantId tenantId, DeviceProfileId deviceProfileId, OtaPackageType type) { | |
379 | + log.trace("Executing countDevicesByTenantIdAndDeviceProfileIdAndEmptyOtaPackage, tenantId [{}], deviceProfileId [{}], type [{}]", tenantId, deviceProfileId, type); | |
378 | 380 | validateId(tenantId, INCORRECT_TENANT_ID + tenantId); |
379 | - validateString(type, "Incorrect type " + type); | |
380 | - validatePageLink(pageLink); | |
381 | - return deviceDao.findDevicesByTenantIdAndTypeAndEmptySoftware(tenantId.getId(), type, pageLink); | |
381 | + validateId(tenantId, INCORRECT_DEVICE_PROFILE_ID + deviceProfileId); | |
382 | + return deviceDao.countDevicesByTenantIdAndDeviceProfileIdAndEmptyOtaPackage(tenantId.getId(), deviceProfileId.getId(), type); | |
382 | 383 | } |
383 | 384 | |
384 | 385 | @Override |
... | ... | @@ -708,11 +709,11 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe |
708 | 709 | .ifPresent(DeviceTransportConfiguration::validate); |
709 | 710 | |
710 | 711 | if (device.getFirmwareId() != null) { |
711 | - Firmware firmware = firmwareService.findFirmwareById(tenantId, device.getFirmwareId()); | |
712 | + OtaPackage firmware = otaPackageService.findOtaPackageById(tenantId, device.getFirmwareId()); | |
712 | 713 | if (firmware == null) { |
713 | 714 | throw new DataValidationException("Can't assign non-existent firmware!"); |
714 | 715 | } |
715 | - if (!firmware.getType().equals(FirmwareType.FIRMWARE)) { | |
716 | + if (!firmware.getType().equals(OtaPackageType.FIRMWARE)) { | |
716 | 717 | throw new DataValidationException("Can't assign firmware with type: " + firmware.getType()); |
717 | 718 | } |
718 | 719 | if (firmware.getData() == null) { |
... | ... | @@ -724,11 +725,11 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe |
724 | 725 | } |
725 | 726 | |
726 | 727 | if (device.getSoftwareId() != null) { |
727 | - Firmware software = firmwareService.findFirmwareById(tenantId, device.getSoftwareId()); | |
728 | + OtaPackage software = otaPackageService.findOtaPackageById(tenantId, device.getSoftwareId()); | |
728 | 729 | if (software == null) { |
729 | 730 | throw new DataValidationException("Can't assign non-existent software!"); |
730 | 731 | } |
731 | - if (!software.getType().equals(FirmwareType.SOFTWARE)) { | |
732 | + if (!software.getType().equals(OtaPackageType.SOFTWARE)) { | |
732 | 733 | throw new DataValidationException("Can't assign software with type: " + software.getType()); |
733 | 734 | } |
734 | 735 | if (software.getData() == null) { | ... | ... |
... | ... | @@ -32,7 +32,7 @@ import org.thingsboard.server.common.data.id.DeviceId; |
32 | 32 | import org.thingsboard.server.common.data.id.EdgeId; |
33 | 33 | import org.thingsboard.server.common.data.id.EntityId; |
34 | 34 | import org.thingsboard.server.common.data.id.EntityViewId; |
35 | -import org.thingsboard.server.common.data.id.FirmwareId; | |
35 | +import org.thingsboard.server.common.data.id.OtaPackageId; | |
36 | 36 | import org.thingsboard.server.common.data.id.RuleChainId; |
37 | 37 | import org.thingsboard.server.common.data.id.TbResourceId; |
38 | 38 | import org.thingsboard.server.common.data.id.TenantId; |
... | ... | @@ -49,7 +49,7 @@ import org.thingsboard.server.dao.dashboard.DashboardService; |
49 | 49 | import org.thingsboard.server.dao.device.DeviceService; |
50 | 50 | import org.thingsboard.server.dao.entityview.EntityViewService; |
51 | 51 | import org.thingsboard.server.dao.exception.IncorrectParameterException; |
52 | -import org.thingsboard.server.dao.firmware.FirmwareService; | |
52 | +import org.thingsboard.server.dao.ota.OtaPackageService; | |
53 | 53 | import org.thingsboard.server.dao.resource.ResourceService; |
54 | 54 | import org.thingsboard.server.dao.rule.RuleChainService; |
55 | 55 | import org.thingsboard.server.dao.tenant.TenantService; |
... | ... | @@ -102,7 +102,7 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe |
102 | 102 | private ResourceService resourceService; |
103 | 103 | |
104 | 104 | @Autowired |
105 | - private FirmwareService firmwareService; | |
105 | + private OtaPackageService otaPackageService; | |
106 | 106 | |
107 | 107 | @Override |
108 | 108 | public void deleteEntityRelations(TenantId tenantId, EntityId entityId) { |
... | ... | @@ -167,8 +167,8 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe |
167 | 167 | case TB_RESOURCE: |
168 | 168 | hasName = resourceService.findResourceInfoByIdAsync(tenantId, new TbResourceId(entityId.getId())); |
169 | 169 | break; |
170 | - case FIRMWARE: | |
171 | - hasName = firmwareService.findFirmwareInfoByIdAsync(tenantId, new FirmwareId(entityId.getId())); | |
170 | + case OTA_PACKAGE: | |
171 | + hasName = otaPackageService.findOtaPackageInfoByIdAsync(tenantId, new OtaPackageId(entityId.getId())); | |
172 | 172 | break; |
173 | 173 | default: |
174 | 174 | throw new IllegalStateException("Not Implemented!"); |
... | ... | @@ -192,7 +192,7 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe |
192 | 192 | case DEVICE_PROFILE: |
193 | 193 | case API_USAGE_STATE: |
194 | 194 | case TB_RESOURCE: |
195 | - case FIRMWARE: | |
195 | + case OTA_PACKAGE: | |
196 | 196 | break; |
197 | 197 | case CUSTOMER: |
198 | 198 | hasCustomerId = () -> new CustomerId(entityId.getId()); | ... | ... |
... | ... | @@ -479,22 +479,21 @@ public class ModelConstants { |
479 | 479 | public static final String RESOURCE_DATA_COLUMN = "data"; |
480 | 480 | |
481 | 481 | /** |
482 | - * Firmware constants. | |
483 | - */ | |
484 | - public static final String FIRMWARE_TABLE_NAME = "firmware"; | |
485 | - public static final String FIRMWARE_TENANT_ID_COLUMN = TENANT_ID_COLUMN; | |
486 | - public static final String FIRMWARE_DEVICE_PROFILE_ID_COLUMN = "device_profile_id"; | |
487 | - public static final String FIRMWARE_TYPE_COLUMN = "type"; | |
488 | - public static final String FIRMWARE_TITLE_COLUMN = TITLE_PROPERTY; | |
489 | - public static final String FIRMWARE_VERSION_COLUMN = "version"; | |
490 | - public static final String FIRMWARE_FILE_NAME_COLUMN = "file_name"; | |
491 | - public static final String FIRMWARE_CONTENT_TYPE_COLUMN = "content_type"; | |
492 | - public static final String FIRMWARE_CHECKSUM_ALGORITHM_COLUMN = "checksum_algorithm"; | |
493 | - public static final String FIRMWARE_CHECKSUM_COLUMN = "checksum"; | |
494 | - public static final String FIRMWARE_DATA_COLUMN = "data"; | |
495 | - public static final String FIRMWARE_DATA_SIZE_COLUMN = "data_size"; | |
496 | - public static final String FIRMWARE_ADDITIONAL_INFO_COLUMN = ADDITIONAL_INFO_PROPERTY; | |
497 | - public static final String FIRMWARE_HAS_DATA_PROPERTY = "has_data"; | |
482 | + * Ota Package constants. | |
483 | + */ | |
484 | + public static final String OTA_PACKAGE_TABLE_NAME = "ota_package"; | |
485 | + public static final String OTA_PACKAGE_TENANT_ID_COLUMN = TENANT_ID_COLUMN; | |
486 | + public static final String OTA_PACKAGE_DEVICE_PROFILE_ID_COLUMN = "device_profile_id"; | |
487 | + public static final String OTA_PACKAGE_TYPE_COLUMN = "type"; | |
488 | + public static final String OTA_PACKAGE_TILE_COLUMN = TITLE_PROPERTY; | |
489 | + public static final String OTA_PACKAGE_VERSION_COLUMN = "version"; | |
490 | + public static final String OTA_PACKAGE_FILE_NAME_COLUMN = "file_name"; | |
491 | + public static final String OTA_PACKAGE_CONTENT_TYPE_COLUMN = "content_type"; | |
492 | + public static final String OTA_PACKAGE_CHECKSUM_ALGORITHM_COLUMN = "checksum_algorithm"; | |
493 | + public static final String OTA_PACKAGE_CHECKSUM_COLUMN = "checksum"; | |
494 | + public static final String OTA_PACKAGE_DATA_COLUMN = "data"; | |
495 | + public static final String OTA_PACKAGE_DATA_SIZE_COLUMN = "data_size"; | |
496 | + public static final String OTA_PACKAGE_ADDITIONAL_INFO_COLUMN = ADDITIONAL_INFO_PROPERTY; | |
498 | 497 | |
499 | 498 | /** |
500 | 499 | * Edge constants. | ... | ... |
... | ... | @@ -28,7 +28,7 @@ import org.thingsboard.server.common.data.device.data.DeviceData; |
28 | 28 | import org.thingsboard.server.common.data.id.CustomerId; |
29 | 29 | import org.thingsboard.server.common.data.id.DeviceId; |
30 | 30 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
31 | -import org.thingsboard.server.common.data.id.FirmwareId; | |
31 | +import org.thingsboard.server.common.data.id.OtaPackageId; | |
32 | 32 | import org.thingsboard.server.common.data.id.TenantId; |
33 | 33 | import org.thingsboard.server.dao.model.BaseSqlEntity; |
34 | 34 | import org.thingsboard.server.dao.model.ModelConstants; |
... | ... | @@ -154,10 +154,10 @@ public abstract class AbstractDeviceEntity<T extends Device> extends BaseSqlEnti |
154 | 154 | device.setDeviceProfileId(new DeviceProfileId(deviceProfileId)); |
155 | 155 | } |
156 | 156 | if (firmwareId != null) { |
157 | - device.setFirmwareId(new FirmwareId(firmwareId)); | |
157 | + device.setFirmwareId(new OtaPackageId(firmwareId)); | |
158 | 158 | } |
159 | 159 | if (softwareId != null) { |
160 | - device.setSoftwareId(new FirmwareId(softwareId)); | |
160 | + device.setSoftwareId(new OtaPackageId(softwareId)); | |
161 | 161 | } |
162 | 162 | device.setDeviceData(JacksonUtil.convertValue(deviceData, DeviceData.class)); |
163 | 163 | device.setName(name); | ... | ... |
... | ... | @@ -29,7 +29,7 @@ import org.thingsboard.server.common.data.DeviceTransportType; |
29 | 29 | import org.thingsboard.server.common.data.device.profile.DeviceProfileData; |
30 | 30 | import org.thingsboard.server.common.data.id.DashboardId; |
31 | 31 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
32 | -import org.thingsboard.server.common.data.id.FirmwareId; | |
32 | +import org.thingsboard.server.common.data.id.OtaPackageId; | |
33 | 33 | import org.thingsboard.server.common.data.id.RuleChainId; |
34 | 34 | import org.thingsboard.server.common.data.id.TenantId; |
35 | 35 | import org.thingsboard.server.dao.model.BaseSqlEntity; |
... | ... | @@ -178,11 +178,11 @@ public final class DeviceProfileEntity extends BaseSqlEntity<DeviceProfile> impl |
178 | 178 | deviceProfile.setProvisionDeviceKey(provisionDeviceKey); |
179 | 179 | |
180 | 180 | if (firmwareId != null) { |
181 | - deviceProfile.setFirmwareId(new FirmwareId(firmwareId)); | |
181 | + deviceProfile.setFirmwareId(new OtaPackageId(firmwareId)); | |
182 | 182 | } |
183 | 183 | |
184 | 184 | if (softwareId != null) { |
185 | - deviceProfile.setSoftwareId(new FirmwareId(softwareId)); | |
185 | + deviceProfile.setSoftwareId(new OtaPackageId(softwareId)); | |
186 | 186 | } |
187 | 187 | |
188 | 188 | return deviceProfile; | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/model/sql/OtaPackageEntity.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/model/sql/FirmwareEntity.java
... | ... | @@ -20,11 +20,11 @@ import lombok.Data; |
20 | 20 | import lombok.EqualsAndHashCode; |
21 | 21 | import org.hibernate.annotations.Type; |
22 | 22 | import org.hibernate.annotations.TypeDef; |
23 | -import org.thingsboard.server.common.data.Firmware; | |
24 | -import org.thingsboard.server.common.data.firmware.ChecksumAlgorithm; | |
25 | -import org.thingsboard.server.common.data.firmware.FirmwareType; | |
23 | +import org.thingsboard.server.common.data.OtaPackage; | |
24 | +import org.thingsboard.server.common.data.ota.ChecksumAlgorithm; | |
25 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | |
26 | 26 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
27 | -import org.thingsboard.server.common.data.id.FirmwareId; | |
27 | +import org.thingsboard.server.common.data.id.OtaPackageId; | |
28 | 28 | import org.thingsboard.server.common.data.id.TenantId; |
29 | 29 | import org.thingsboard.server.dao.model.BaseSqlEntity; |
30 | 30 | import org.thingsboard.server.dao.model.ModelConstants; |
... | ... | @@ -40,75 +40,75 @@ import javax.persistence.Table; |
40 | 40 | import java.nio.ByteBuffer; |
41 | 41 | import java.util.UUID; |
42 | 42 | |
43 | -import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_CHECKSUM_ALGORITHM_COLUMN; | |
44 | -import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_CHECKSUM_COLUMN; | |
45 | -import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_CONTENT_TYPE_COLUMN; | |
46 | -import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_DATA_COLUMN; | |
47 | -import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_DATA_SIZE_COLUMN; | |
48 | -import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_DEVICE_PROFILE_ID_COLUMN; | |
49 | -import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_FILE_NAME_COLUMN; | |
50 | -import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_TABLE_NAME; | |
51 | -import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_TENANT_ID_COLUMN; | |
52 | -import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_TITLE_COLUMN; | |
53 | -import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_TYPE_COLUMN; | |
54 | -import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_VERSION_COLUMN; | |
43 | +import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_CHECKSUM_ALGORITHM_COLUMN; | |
44 | +import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_CHECKSUM_COLUMN; | |
45 | +import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_CONTENT_TYPE_COLUMN; | |
46 | +import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_DATA_COLUMN; | |
47 | +import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_DATA_SIZE_COLUMN; | |
48 | +import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_DEVICE_PROFILE_ID_COLUMN; | |
49 | +import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_FILE_NAME_COLUMN; | |
50 | +import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TABLE_NAME; | |
51 | +import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TENANT_ID_COLUMN; | |
52 | +import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TILE_COLUMN; | |
53 | +import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TYPE_COLUMN; | |
54 | +import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_VERSION_COLUMN; | |
55 | 55 | import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY; |
56 | 56 | |
57 | 57 | @Data |
58 | 58 | @EqualsAndHashCode(callSuper = true) |
59 | 59 | @Entity |
60 | 60 | @TypeDef(name = "json", typeClass = JsonStringType.class) |
61 | -@Table(name = FIRMWARE_TABLE_NAME) | |
62 | -public class FirmwareEntity extends BaseSqlEntity<Firmware> implements SearchTextEntity<Firmware> { | |
61 | +@Table(name = OTA_PACKAGE_TABLE_NAME) | |
62 | +public class OtaPackageEntity extends BaseSqlEntity<OtaPackage> implements SearchTextEntity<OtaPackage> { | |
63 | 63 | |
64 | - @Column(name = FIRMWARE_TENANT_ID_COLUMN) | |
64 | + @Column(name = OTA_PACKAGE_TENANT_ID_COLUMN) | |
65 | 65 | private UUID tenantId; |
66 | 66 | |
67 | - @Column(name = FIRMWARE_DEVICE_PROFILE_ID_COLUMN) | |
67 | + @Column(name = OTA_PACKAGE_DEVICE_PROFILE_ID_COLUMN) | |
68 | 68 | private UUID deviceProfileId; |
69 | 69 | |
70 | 70 | @Enumerated(EnumType.STRING) |
71 | - @Column(name = FIRMWARE_TYPE_COLUMN) | |
72 | - private FirmwareType type; | |
71 | + @Column(name = OTA_PACKAGE_TYPE_COLUMN) | |
72 | + private OtaPackageType type; | |
73 | 73 | |
74 | - @Column(name = FIRMWARE_TITLE_COLUMN) | |
74 | + @Column(name = OTA_PACKAGE_TILE_COLUMN) | |
75 | 75 | private String title; |
76 | 76 | |
77 | - @Column(name = FIRMWARE_VERSION_COLUMN) | |
77 | + @Column(name = OTA_PACKAGE_VERSION_COLUMN) | |
78 | 78 | private String version; |
79 | 79 | |
80 | - @Column(name = FIRMWARE_FILE_NAME_COLUMN) | |
80 | + @Column(name = OTA_PACKAGE_FILE_NAME_COLUMN) | |
81 | 81 | private String fileName; |
82 | 82 | |
83 | - @Column(name = FIRMWARE_CONTENT_TYPE_COLUMN) | |
83 | + @Column(name = OTA_PACKAGE_CONTENT_TYPE_COLUMN) | |
84 | 84 | private String contentType; |
85 | 85 | |
86 | 86 | @Enumerated(EnumType.STRING) |
87 | - @Column(name = FIRMWARE_CHECKSUM_ALGORITHM_COLUMN) | |
87 | + @Column(name = OTA_PACKAGE_CHECKSUM_ALGORITHM_COLUMN) | |
88 | 88 | private ChecksumAlgorithm checksumAlgorithm; |
89 | 89 | |
90 | - @Column(name = FIRMWARE_CHECKSUM_COLUMN) | |
90 | + @Column(name = OTA_PACKAGE_CHECKSUM_COLUMN) | |
91 | 91 | private String checksum; |
92 | 92 | |
93 | 93 | @Lob |
94 | - @Column(name = FIRMWARE_DATA_COLUMN, columnDefinition = "BINARY") | |
94 | + @Column(name = OTA_PACKAGE_DATA_COLUMN, columnDefinition = "BINARY") | |
95 | 95 | private byte[] data; |
96 | 96 | |
97 | - @Column(name = FIRMWARE_DATA_SIZE_COLUMN) | |
97 | + @Column(name = OTA_PACKAGE_DATA_SIZE_COLUMN) | |
98 | 98 | private Long dataSize; |
99 | 99 | |
100 | 100 | @Type(type = "json") |
101 | - @Column(name = ModelConstants.FIRMWARE_ADDITIONAL_INFO_COLUMN) | |
101 | + @Column(name = ModelConstants.OTA_PACKAGE_ADDITIONAL_INFO_COLUMN) | |
102 | 102 | private JsonNode additionalInfo; |
103 | 103 | |
104 | 104 | @Column(name = SEARCH_TEXT_PROPERTY) |
105 | 105 | private String searchText; |
106 | 106 | |
107 | - public FirmwareEntity() { | |
107 | + public OtaPackageEntity() { | |
108 | 108 | super(); |
109 | 109 | } |
110 | 110 | |
111 | - public FirmwareEntity(Firmware firmware) { | |
111 | + public OtaPackageEntity(OtaPackage firmware) { | |
112 | 112 | this.createdTime = firmware.getCreatedTime(); |
113 | 113 | this.setUuid(firmware.getUuidId()); |
114 | 114 | this.tenantId = firmware.getTenantId().getId(); |
... | ... | @@ -138,8 +138,8 @@ public class FirmwareEntity extends BaseSqlEntity<Firmware> implements SearchTex |
138 | 138 | } |
139 | 139 | |
140 | 140 | @Override |
141 | - public Firmware toData() { | |
142 | - Firmware firmware = new Firmware(new FirmwareId(id)); | |
141 | + public OtaPackage toData() { | |
142 | + OtaPackage firmware = new OtaPackage(new OtaPackageId(id)); | |
143 | 143 | firmware.setCreatedTime(createdTime); |
144 | 144 | firmware.setTenantId(new TenantId(tenantId)); |
145 | 145 | if (deviceProfileId != null) { | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/model/sql/OtaPackageInfoEntity.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/model/sql/FirmwareInfoEntity.java
... | ... | @@ -21,11 +21,11 @@ import lombok.EqualsAndHashCode; |
21 | 21 | import org.hibernate.annotations.Type; |
22 | 22 | import org.hibernate.annotations.TypeDef; |
23 | 23 | import org.thingsboard.common.util.JacksonUtil; |
24 | -import org.thingsboard.server.common.data.FirmwareInfo; | |
25 | -import org.thingsboard.server.common.data.firmware.ChecksumAlgorithm; | |
26 | -import org.thingsboard.server.common.data.firmware.FirmwareType; | |
24 | +import org.thingsboard.server.common.data.OtaPackageInfo; | |
25 | +import org.thingsboard.server.common.data.ota.ChecksumAlgorithm; | |
26 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | |
27 | 27 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
28 | -import org.thingsboard.server.common.data.id.FirmwareId; | |
28 | +import org.thingsboard.server.common.data.id.OtaPackageId; | |
29 | 29 | import org.thingsboard.server.common.data.id.TenantId; |
30 | 30 | import org.thingsboard.server.dao.model.BaseSqlEntity; |
31 | 31 | import org.thingsboard.server.dao.model.ModelConstants; |
... | ... | @@ -40,60 +40,60 @@ import javax.persistence.Table; |
40 | 40 | import javax.persistence.Transient; |
41 | 41 | import java.util.UUID; |
42 | 42 | |
43 | -import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_CHECKSUM_ALGORITHM_COLUMN; | |
44 | -import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_CHECKSUM_COLUMN; | |
45 | -import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_CONTENT_TYPE_COLUMN; | |
46 | -import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_DATA_SIZE_COLUMN; | |
47 | -import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_DEVICE_PROFILE_ID_COLUMN; | |
48 | -import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_FILE_NAME_COLUMN; | |
49 | -import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_TABLE_NAME; | |
50 | -import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_TENANT_ID_COLUMN; | |
51 | -import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_TITLE_COLUMN; | |
52 | -import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_TYPE_COLUMN; | |
53 | -import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_VERSION_COLUMN; | |
43 | +import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_CHECKSUM_ALGORITHM_COLUMN; | |
44 | +import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_CHECKSUM_COLUMN; | |
45 | +import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_CONTENT_TYPE_COLUMN; | |
46 | +import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_DATA_SIZE_COLUMN; | |
47 | +import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_DEVICE_PROFILE_ID_COLUMN; | |
48 | +import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_FILE_NAME_COLUMN; | |
49 | +import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TABLE_NAME; | |
50 | +import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TENANT_ID_COLUMN; | |
51 | +import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TILE_COLUMN; | |
52 | +import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TYPE_COLUMN; | |
53 | +import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_VERSION_COLUMN; | |
54 | 54 | import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY; |
55 | 55 | |
56 | 56 | @Data |
57 | 57 | @EqualsAndHashCode(callSuper = true) |
58 | 58 | @Entity |
59 | 59 | @TypeDef(name = "json", typeClass = JsonStringType.class) |
60 | -@Table(name = FIRMWARE_TABLE_NAME) | |
61 | -public class FirmwareInfoEntity extends BaseSqlEntity<FirmwareInfo> implements SearchTextEntity<FirmwareInfo> { | |
60 | +@Table(name = OTA_PACKAGE_TABLE_NAME) | |
61 | +public class OtaPackageInfoEntity extends BaseSqlEntity<OtaPackageInfo> implements SearchTextEntity<OtaPackageInfo> { | |
62 | 62 | |
63 | - @Column(name = FIRMWARE_TENANT_ID_COLUMN) | |
63 | + @Column(name = OTA_PACKAGE_TENANT_ID_COLUMN) | |
64 | 64 | private UUID tenantId; |
65 | 65 | |
66 | - @Column(name = FIRMWARE_DEVICE_PROFILE_ID_COLUMN) | |
66 | + @Column(name = OTA_PACKAGE_DEVICE_PROFILE_ID_COLUMN) | |
67 | 67 | private UUID deviceProfileId; |
68 | 68 | |
69 | 69 | @Enumerated(EnumType.STRING) |
70 | - @Column(name = FIRMWARE_TYPE_COLUMN) | |
71 | - private FirmwareType type; | |
70 | + @Column(name = OTA_PACKAGE_TYPE_COLUMN) | |
71 | + private OtaPackageType type; | |
72 | 72 | |
73 | - @Column(name = FIRMWARE_TITLE_COLUMN) | |
73 | + @Column(name = OTA_PACKAGE_TILE_COLUMN) | |
74 | 74 | private String title; |
75 | 75 | |
76 | - @Column(name = FIRMWARE_VERSION_COLUMN) | |
76 | + @Column(name = OTA_PACKAGE_VERSION_COLUMN) | |
77 | 77 | private String version; |
78 | 78 | |
79 | - @Column(name = FIRMWARE_FILE_NAME_COLUMN) | |
79 | + @Column(name = OTA_PACKAGE_FILE_NAME_COLUMN) | |
80 | 80 | private String fileName; |
81 | 81 | |
82 | - @Column(name = FIRMWARE_CONTENT_TYPE_COLUMN) | |
82 | + @Column(name = OTA_PACKAGE_CONTENT_TYPE_COLUMN) | |
83 | 83 | private String contentType; |
84 | 84 | |
85 | 85 | @Enumerated(EnumType.STRING) |
86 | - @Column(name = FIRMWARE_CHECKSUM_ALGORITHM_COLUMN) | |
86 | + @Column(name = OTA_PACKAGE_CHECKSUM_ALGORITHM_COLUMN) | |
87 | 87 | private ChecksumAlgorithm checksumAlgorithm; |
88 | 88 | |
89 | - @Column(name = FIRMWARE_CHECKSUM_COLUMN) | |
89 | + @Column(name = OTA_PACKAGE_CHECKSUM_COLUMN) | |
90 | 90 | private String checksum; |
91 | 91 | |
92 | - @Column(name = FIRMWARE_DATA_SIZE_COLUMN) | |
92 | + @Column(name = OTA_PACKAGE_DATA_SIZE_COLUMN) | |
93 | 93 | private Long dataSize; |
94 | 94 | |
95 | 95 | @Type(type = "json") |
96 | - @Column(name = ModelConstants.FIRMWARE_ADDITIONAL_INFO_COLUMN) | |
96 | + @Column(name = ModelConstants.OTA_PACKAGE_ADDITIONAL_INFO_COLUMN) | |
97 | 97 | private JsonNode additionalInfo; |
98 | 98 | |
99 | 99 | @Column(name = SEARCH_TEXT_PROPERTY) |
... | ... | @@ -102,11 +102,11 @@ public class FirmwareInfoEntity extends BaseSqlEntity<FirmwareInfo> implements S |
102 | 102 | @Transient |
103 | 103 | private boolean hasData; |
104 | 104 | |
105 | - public FirmwareInfoEntity() { | |
105 | + public OtaPackageInfoEntity() { | |
106 | 106 | super(); |
107 | 107 | } |
108 | 108 | |
109 | - public FirmwareInfoEntity(FirmwareInfo firmware) { | |
109 | + public OtaPackageInfoEntity(OtaPackageInfo firmware) { | |
110 | 110 | this.createdTime = firmware.getCreatedTime(); |
111 | 111 | this.setUuid(firmware.getUuidId()); |
112 | 112 | this.tenantId = firmware.getTenantId().getId(); |
... | ... | @@ -124,9 +124,9 @@ public class FirmwareInfoEntity extends BaseSqlEntity<FirmwareInfo> implements S |
124 | 124 | this.additionalInfo = firmware.getAdditionalInfo(); |
125 | 125 | } |
126 | 126 | |
127 | - public FirmwareInfoEntity(UUID id, long createdTime, UUID tenantId, UUID deviceProfileId, FirmwareType type, String title, String version, | |
128 | - String fileName, String contentType, ChecksumAlgorithm checksumAlgorithm, String checksum, Long dataSize, | |
129 | - Object additionalInfo, boolean hasData) { | |
127 | + public OtaPackageInfoEntity(UUID id, long createdTime, UUID tenantId, UUID deviceProfileId, OtaPackageType type, String title, String version, | |
128 | + String fileName, String contentType, ChecksumAlgorithm checksumAlgorithm, String checksum, Long dataSize, | |
129 | + Object additionalInfo, boolean hasData) { | |
130 | 130 | this.id = id; |
131 | 131 | this.createdTime = createdTime; |
132 | 132 | this.tenantId = tenantId; |
... | ... | @@ -154,8 +154,8 @@ public class FirmwareInfoEntity extends BaseSqlEntity<FirmwareInfo> implements S |
154 | 154 | } |
155 | 155 | |
156 | 156 | @Override |
157 | - public FirmwareInfo toData() { | |
158 | - FirmwareInfo firmware = new FirmwareInfo(new FirmwareId(id)); | |
157 | + public OtaPackageInfo toData() { | |
158 | + OtaPackageInfo firmware = new OtaPackageInfo(new OtaPackageId(id)); | |
159 | 159 | firmware.setCreatedTime(createdTime); |
160 | 160 | firmware.setTenantId(new TenantId(tenantId)); |
161 | 161 | if (deviceProfileId != null) { | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/ota/BaseOtaPackageService.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/firmware/BaseFirmwareService.java
... | ... | @@ -13,7 +13,7 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.dao.firmware; | |
16 | +package org.thingsboard.server.dao.ota; | |
17 | 17 | |
18 | 18 | import com.google.common.hash.HashFunction; |
19 | 19 | import com.google.common.hash.Hashing; |
... | ... | @@ -26,17 +26,15 @@ import org.springframework.cache.Cache; |
26 | 26 | import org.springframework.cache.CacheManager; |
27 | 27 | import org.springframework.cache.annotation.Cacheable; |
28 | 28 | import org.springframework.stereotype.Service; |
29 | -import org.thingsboard.server.cache.firmware.FirmwareDataCache; | |
29 | +import org.thingsboard.server.cache.ota.OtaPackageDataCache; | |
30 | 30 | import org.thingsboard.server.common.data.DeviceProfile; |
31 | -import org.thingsboard.server.common.data.Firmware; | |
32 | -import org.thingsboard.server.common.data.FirmwareInfo; | |
31 | +import org.thingsboard.server.common.data.OtaPackage; | |
32 | +import org.thingsboard.server.common.data.OtaPackageInfo; | |
33 | 33 | import org.thingsboard.server.common.data.Tenant; |
34 | -import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; | |
35 | -import org.thingsboard.server.common.data.exception.ThingsboardException; | |
36 | -import org.thingsboard.server.common.data.firmware.ChecksumAlgorithm; | |
37 | -import org.thingsboard.server.common.data.firmware.FirmwareType; | |
34 | +import org.thingsboard.server.common.data.ota.ChecksumAlgorithm; | |
35 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | |
38 | 36 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
39 | -import org.thingsboard.server.common.data.id.FirmwareId; | |
37 | +import org.thingsboard.server.common.data.id.OtaPackageId; | |
40 | 38 | import org.thingsboard.server.common.data.id.TenantId; |
41 | 39 | import org.thingsboard.server.common.data.page.PageData; |
42 | 40 | import org.thingsboard.server.common.data.page.PageLink; |
... | ... | @@ -46,49 +44,45 @@ import org.thingsboard.server.dao.service.DataValidator; |
46 | 44 | import org.thingsboard.server.dao.service.PaginatedRemover; |
47 | 45 | import org.thingsboard.server.dao.tenant.TenantDao; |
48 | 46 | |
49 | -import java.lang.reflect.InvocationTargetException; | |
50 | -import java.lang.reflect.Method; | |
51 | 47 | import java.nio.ByteBuffer; |
52 | -import java.util.ArrayList; | |
53 | -import java.util.Arrays; | |
54 | 48 | import java.util.Collections; |
55 | 49 | import java.util.List; |
56 | 50 | import java.util.Optional; |
57 | 51 | |
58 | -import static org.thingsboard.server.common.data.CacheConstants.FIRMWARE_CACHE; | |
52 | +import static org.thingsboard.server.common.data.CacheConstants.OTA_PACKAGE_CACHE; | |
59 | 53 | import static org.thingsboard.server.dao.service.Validator.validateId; |
60 | 54 | import static org.thingsboard.server.dao.service.Validator.validatePageLink; |
61 | 55 | |
62 | 56 | @Service |
63 | 57 | @Slf4j |
64 | 58 | @RequiredArgsConstructor |
65 | -public class BaseFirmwareService implements FirmwareService { | |
66 | - public static final String INCORRECT_FIRMWARE_ID = "Incorrect firmwareId "; | |
59 | +public class BaseOtaPackageService implements OtaPackageService { | |
60 | + public static final String INCORRECT_OTA_PACKAGE_ID = "Incorrect otaPackageId "; | |
67 | 61 | public static final String INCORRECT_TENANT_ID = "Incorrect tenantId "; |
68 | 62 | |
69 | 63 | private final TenantDao tenantDao; |
70 | 64 | private final DeviceProfileDao deviceProfileDao; |
71 | - private final FirmwareDao firmwareDao; | |
72 | - private final FirmwareInfoDao firmwareInfoDao; | |
65 | + private final OtaPackageDao otaPackageDao; | |
66 | + private final OtaPackageInfoDao otaPackageInfoDao; | |
73 | 67 | private final CacheManager cacheManager; |
74 | - private final FirmwareDataCache firmwareDataCache; | |
68 | + private final OtaPackageDataCache otaPackageDataCache; | |
75 | 69 | |
76 | 70 | @Override |
77 | - public FirmwareInfo saveFirmwareInfo(FirmwareInfo firmwareInfo) { | |
78 | - log.trace("Executing saveFirmwareInfo [{}]", firmwareInfo); | |
79 | - firmwareInfoValidator.validate(firmwareInfo, FirmwareInfo::getTenantId); | |
71 | + public OtaPackageInfo saveOtaPackageInfo(OtaPackageInfo otaPackageInfo) { | |
72 | + log.trace("Executing saveOtaPackageInfo [{}]", otaPackageInfo); | |
73 | + otaPackageInfoValidator.validate(otaPackageInfo, OtaPackageInfo::getTenantId); | |
80 | 74 | try { |
81 | - FirmwareId firmwareId = firmwareInfo.getId(); | |
82 | - if (firmwareId != null) { | |
83 | - Cache cache = cacheManager.getCache(FIRMWARE_CACHE); | |
84 | - cache.evict(toFirmwareInfoKey(firmwareId)); | |
85 | - firmwareDataCache.evict(firmwareId.toString()); | |
75 | + OtaPackageId otaPackageId = otaPackageInfo.getId(); | |
76 | + if (otaPackageId != null) { | |
77 | + Cache cache = cacheManager.getCache(OTA_PACKAGE_CACHE); | |
78 | + cache.evict(toOtaPackageInfoKey(otaPackageId)); | |
79 | + otaPackageDataCache.evict(otaPackageId.toString()); | |
86 | 80 | } |
87 | - return firmwareInfoDao.save(firmwareInfo.getTenantId(), firmwareInfo); | |
81 | + return otaPackageInfoDao.save(otaPackageInfo.getTenantId(), otaPackageInfo); | |
88 | 82 | } catch (Exception t) { |
89 | 83 | ConstraintViolationException e = extractConstraintViolationException(t).orElse(null); |
90 | - if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("firmware_tenant_title_version_unq_key")) { | |
91 | - throw new DataValidationException("Firmware with such title and version already exists!"); | |
84 | + if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("ota_package_tenant_title_version_unq_key")) { | |
85 | + throw new DataValidationException("OtaPackage with such title and version already exists!"); | |
92 | 86 | } else { |
93 | 87 | throw t; |
94 | 88 | } |
... | ... | @@ -96,21 +90,21 @@ public class BaseFirmwareService implements FirmwareService { |
96 | 90 | } |
97 | 91 | |
98 | 92 | @Override |
99 | - public Firmware saveFirmware(Firmware firmware) { | |
100 | - log.trace("Executing saveFirmware [{}]", firmware); | |
101 | - firmwareValidator.validate(firmware, FirmwareInfo::getTenantId); | |
93 | + public OtaPackage saveOtaPackage(OtaPackage otaPackage) { | |
94 | + log.trace("Executing saveOtaPackage [{}]", otaPackage); | |
95 | + otaPackageValidator.validate(otaPackage, OtaPackageInfo::getTenantId); | |
102 | 96 | try { |
103 | - FirmwareId firmwareId = firmware.getId(); | |
104 | - if (firmwareId != null) { | |
105 | - Cache cache = cacheManager.getCache(FIRMWARE_CACHE); | |
106 | - cache.evict(toFirmwareInfoKey(firmwareId)); | |
107 | - firmwareDataCache.evict(firmwareId.toString()); | |
97 | + OtaPackageId otaPackageId = otaPackage.getId(); | |
98 | + if (otaPackageId != null) { | |
99 | + Cache cache = cacheManager.getCache(OTA_PACKAGE_CACHE); | |
100 | + cache.evict(toOtaPackageInfoKey(otaPackageId)); | |
101 | + otaPackageDataCache.evict(otaPackageId.toString()); | |
108 | 102 | } |
109 | - return firmwareDao.save(firmware.getTenantId(), firmware); | |
103 | + return otaPackageDao.save(otaPackage.getTenantId(), otaPackage); | |
110 | 104 | } catch (Exception t) { |
111 | 105 | ConstraintViolationException e = extractConstraintViolationException(t).orElse(null); |
112 | - if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("firmware_tenant_title_version_unq_key")) { | |
113 | - throw new DataValidationException("Firmware with such title and version already exists!"); | |
106 | + if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("ota_package_tenant_title_version_unq_key")) { | |
107 | + throw new DataValidationException("OtaPackage with such title and version already exists!"); | |
114 | 108 | } else { |
115 | 109 | throw t; |
116 | 110 | } |
... | ... | @@ -120,7 +114,7 @@ public class BaseFirmwareService implements FirmwareService { |
120 | 114 | @Override |
121 | 115 | public String generateChecksum(ChecksumAlgorithm checksumAlgorithm, ByteBuffer data) { |
122 | 116 | if (data == null || !data.hasArray() || data.array().length == 0) { |
123 | - throw new DataValidationException("Firmware data should be specified!"); | |
117 | + throw new DataValidationException("OtaPackage data should be specified!"); | |
124 | 118 | } |
125 | 119 | |
126 | 120 | return getHashFunction(checksumAlgorithm).hashBytes(data.array()).toString(); |
... | ... | @@ -148,58 +142,58 @@ public class BaseFirmwareService implements FirmwareService { |
148 | 142 | } |
149 | 143 | |
150 | 144 | @Override |
151 | - public Firmware findFirmwareById(TenantId tenantId, FirmwareId firmwareId) { | |
152 | - log.trace("Executing findFirmwareById [{}]", firmwareId); | |
153 | - validateId(firmwareId, INCORRECT_FIRMWARE_ID + firmwareId); | |
154 | - return firmwareDao.findById(tenantId, firmwareId.getId()); | |
145 | + public OtaPackage findOtaPackageById(TenantId tenantId, OtaPackageId otaPackageId) { | |
146 | + log.trace("Executing findOtaPackageById [{}]", otaPackageId); | |
147 | + validateId(otaPackageId, INCORRECT_OTA_PACKAGE_ID + otaPackageId); | |
148 | + return otaPackageDao.findById(tenantId, otaPackageId.getId()); | |
155 | 149 | } |
156 | 150 | |
157 | 151 | @Override |
158 | - @Cacheable(cacheNames = FIRMWARE_CACHE, key = "{#firmwareId}") | |
159 | - public FirmwareInfo findFirmwareInfoById(TenantId tenantId, FirmwareId firmwareId) { | |
160 | - log.trace("Executing findFirmwareInfoById [{}]", firmwareId); | |
161 | - validateId(firmwareId, INCORRECT_FIRMWARE_ID + firmwareId); | |
162 | - return firmwareInfoDao.findById(tenantId, firmwareId.getId()); | |
152 | + @Cacheable(cacheNames = OTA_PACKAGE_CACHE, key = "{#otaPackageId}") | |
153 | + public OtaPackageInfo findOtaPackageInfoById(TenantId tenantId, OtaPackageId otaPackageId) { | |
154 | + log.trace("Executing findOtaPackageInfoById [{}]", otaPackageId); | |
155 | + validateId(otaPackageId, INCORRECT_OTA_PACKAGE_ID + otaPackageId); | |
156 | + return otaPackageInfoDao.findById(tenantId, otaPackageId.getId()); | |
163 | 157 | } |
164 | 158 | |
165 | 159 | @Override |
166 | - public ListenableFuture<FirmwareInfo> findFirmwareInfoByIdAsync(TenantId tenantId, FirmwareId firmwareId) { | |
167 | - log.trace("Executing findFirmwareInfoByIdAsync [{}]", firmwareId); | |
168 | - validateId(firmwareId, INCORRECT_FIRMWARE_ID + firmwareId); | |
169 | - return firmwareInfoDao.findByIdAsync(tenantId, firmwareId.getId()); | |
160 | + public ListenableFuture<OtaPackageInfo> findOtaPackageInfoByIdAsync(TenantId tenantId, OtaPackageId otaPackageId) { | |
161 | + log.trace("Executing findOtaPackageInfoByIdAsync [{}]", otaPackageId); | |
162 | + validateId(otaPackageId, INCORRECT_OTA_PACKAGE_ID + otaPackageId); | |
163 | + return otaPackageInfoDao.findByIdAsync(tenantId, otaPackageId.getId()); | |
170 | 164 | } |
171 | 165 | |
172 | 166 | @Override |
173 | - public PageData<FirmwareInfo> findTenantFirmwaresByTenantId(TenantId tenantId, PageLink pageLink) { | |
174 | - log.trace("Executing findTenantFirmwaresByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink); | |
167 | + public PageData<OtaPackageInfo> findTenantOtaPackagesByTenantId(TenantId tenantId, PageLink pageLink) { | |
168 | + log.trace("Executing findTenantOtaPackagesByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink); | |
175 | 169 | validateId(tenantId, INCORRECT_TENANT_ID + tenantId); |
176 | 170 | validatePageLink(pageLink); |
177 | - return firmwareInfoDao.findFirmwareInfoByTenantId(tenantId, pageLink); | |
171 | + return otaPackageInfoDao.findOtaPackageInfoByTenantId(tenantId, pageLink); | |
178 | 172 | } |
179 | 173 | |
180 | 174 | @Override |
181 | - public PageData<FirmwareInfo> findTenantFirmwaresByTenantIdAndDeviceProfileIdAndTypeAndHasData(TenantId tenantId, DeviceProfileId deviceProfileId, FirmwareType firmwareType, boolean hasData, PageLink pageLink) { | |
182 | - log.trace("Executing findTenantFirmwaresByTenantIdAndHasData, tenantId [{}], hasData [{}] pageLink [{}]", tenantId, hasData, pageLink); | |
175 | + public PageData<OtaPackageInfo> findTenantOtaPackagesByTenantIdAndDeviceProfileIdAndTypeAndHasData(TenantId tenantId, DeviceProfileId deviceProfileId, OtaPackageType otaPackageType, boolean hasData, PageLink pageLink) { | |
176 | + log.trace("Executing findTenantOtaPackagesByTenantIdAndHasData, tenantId [{}], hasData [{}] pageLink [{}]", tenantId, hasData, pageLink); | |
183 | 177 | validateId(tenantId, INCORRECT_TENANT_ID + tenantId); |
184 | 178 | validatePageLink(pageLink); |
185 | - return firmwareInfoDao.findFirmwareInfoByTenantIdAndDeviceProfileIdAndTypeAndHasData(tenantId, deviceProfileId, firmwareType, hasData, pageLink); | |
179 | + return otaPackageInfoDao.findOtaPackageInfoByTenantIdAndDeviceProfileIdAndTypeAndHasData(tenantId, deviceProfileId, otaPackageType, hasData, pageLink); | |
186 | 180 | } |
187 | 181 | |
188 | 182 | @Override |
189 | - public void deleteFirmware(TenantId tenantId, FirmwareId firmwareId) { | |
190 | - log.trace("Executing deleteFirmware [{}]", firmwareId); | |
191 | - validateId(firmwareId, INCORRECT_FIRMWARE_ID + firmwareId); | |
183 | + public void deleteOtaPackage(TenantId tenantId, OtaPackageId otaPackageId) { | |
184 | + log.trace("Executing deleteOtaPackage [{}]", otaPackageId); | |
185 | + validateId(otaPackageId, INCORRECT_OTA_PACKAGE_ID + otaPackageId); | |
192 | 186 | try { |
193 | - Cache cache = cacheManager.getCache(FIRMWARE_CACHE); | |
194 | - cache.evict(toFirmwareInfoKey(firmwareId)); | |
195 | - firmwareDataCache.evict(firmwareId.toString()); | |
196 | - firmwareDao.removeById(tenantId, firmwareId.getId()); | |
187 | + Cache cache = cacheManager.getCache(OTA_PACKAGE_CACHE); | |
188 | + cache.evict(toOtaPackageInfoKey(otaPackageId)); | |
189 | + otaPackageDataCache.evict(otaPackageId.toString()); | |
190 | + otaPackageDao.removeById(tenantId, otaPackageId.getId()); | |
197 | 191 | } catch (Exception t) { |
198 | 192 | ConstraintViolationException e = extractConstraintViolationException(t).orElse(null); |
199 | 193 | if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("fk_firmware_device")) { |
200 | - throw new DataValidationException("The firmware referenced by the devices cannot be deleted!"); | |
194 | + throw new DataValidationException("The otaPackage referenced by the devices cannot be deleted!"); | |
201 | 195 | } else if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("fk_firmware_device_profile")) { |
202 | - throw new DataValidationException("The firmware referenced by the device profile cannot be deleted!"); | |
196 | + throw new DataValidationException("The otaPackage referenced by the device profile cannot be deleted!"); | |
203 | 197 | } else if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("fk_software_device")) { |
204 | 198 | throw new DataValidationException("The software referenced by the devices cannot be deleted!"); |
205 | 199 | } else if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("fk_software_device_profile")) { |
... | ... | @@ -211,154 +205,147 @@ public class BaseFirmwareService implements FirmwareService { |
211 | 205 | } |
212 | 206 | |
213 | 207 | @Override |
214 | - public void deleteFirmwaresByTenantId(TenantId tenantId) { | |
215 | - log.trace("Executing deleteFirmwaresByTenantId, tenantId [{}]", tenantId); | |
208 | + public void deleteOtaPackagesByTenantId(TenantId tenantId) { | |
209 | + log.trace("Executing deleteOtaPackagesByTenantId, tenantId [{}]", tenantId); | |
216 | 210 | validateId(tenantId, INCORRECT_TENANT_ID + tenantId); |
217 | - tenantFirmwareRemover.removeEntities(tenantId, tenantId); | |
211 | + tenantOtaPackageRemover.removeEntities(tenantId, tenantId); | |
218 | 212 | } |
219 | 213 | |
220 | - private DataValidator<FirmwareInfo> firmwareInfoValidator = new DataValidator<>() { | |
214 | + private DataValidator<OtaPackageInfo> otaPackageInfoValidator = new DataValidator<>() { | |
221 | 215 | |
222 | 216 | @Override |
223 | - protected void validateDataImpl(TenantId tenantId, FirmwareInfo firmwareInfo) { | |
224 | - validateImpl(firmwareInfo); | |
217 | + protected void validateDataImpl(TenantId tenantId, OtaPackageInfo otaPackageInfo) { | |
218 | + validateImpl(otaPackageInfo); | |
225 | 219 | } |
226 | 220 | |
227 | 221 | @Override |
228 | - protected void validateUpdate(TenantId tenantId, FirmwareInfo firmware) { | |
229 | - FirmwareInfo firmwareOld = firmwareInfoDao.findById(tenantId, firmware.getUuidId()); | |
230 | - | |
231 | - validateUpdateDeviceProfile(firmware, firmwareOld); | |
232 | - BaseFirmwareService.validateUpdate(firmware, firmwareOld); | |
222 | + protected void validateUpdate(TenantId tenantId, OtaPackageInfo otaPackage) { | |
223 | + OtaPackageInfo otaPackageOld = otaPackageInfoDao.findById(tenantId, otaPackage.getUuidId()); | |
224 | + BaseOtaPackageService.validateUpdate(otaPackage, otaPackageOld); | |
233 | 225 | } |
234 | 226 | }; |
235 | 227 | |
236 | - private DataValidator<Firmware> firmwareValidator = new DataValidator<>() { | |
228 | + private DataValidator<OtaPackage> otaPackageValidator = new DataValidator<>() { | |
237 | 229 | |
238 | 230 | @Override |
239 | - protected void validateDataImpl(TenantId tenantId, Firmware firmware) { | |
240 | - validateImpl(firmware); | |
231 | + protected void validateDataImpl(TenantId tenantId, OtaPackage otaPackage) { | |
232 | + validateImpl(otaPackage); | |
241 | 233 | |
242 | - if (StringUtils.isEmpty(firmware.getFileName())) { | |
243 | - throw new DataValidationException("Firmware file name should be specified!"); | |
234 | + if (StringUtils.isEmpty(otaPackage.getFileName())) { | |
235 | + throw new DataValidationException("OtaPackage file name should be specified!"); | |
244 | 236 | } |
245 | 237 | |
246 | - if (StringUtils.isEmpty(firmware.getContentType())) { | |
247 | - throw new DataValidationException("Firmware content type should be specified!"); | |
238 | + if (StringUtils.isEmpty(otaPackage.getContentType())) { | |
239 | + throw new DataValidationException("OtaPackage content type should be specified!"); | |
248 | 240 | } |
249 | 241 | |
250 | - if (firmware.getChecksumAlgorithm() == null) { | |
251 | - throw new DataValidationException("Firmware checksum algorithm should be specified!"); | |
242 | + if (otaPackage.getChecksumAlgorithm() == null) { | |
243 | + throw new DataValidationException("OtaPackage checksum algorithm should be specified!"); | |
252 | 244 | } |
253 | - if (StringUtils.isEmpty(firmware.getChecksum())) { | |
254 | - throw new DataValidationException("Firmware checksum should be specified!"); | |
245 | + if (StringUtils.isEmpty(otaPackage.getChecksum())) { | |
246 | + throw new DataValidationException("OtaPackage checksum should be specified!"); | |
255 | 247 | } |
256 | 248 | |
257 | 249 | String currentChecksum; |
258 | 250 | |
259 | - currentChecksum = generateChecksum(firmware.getChecksumAlgorithm(), firmware.getData()); | |
251 | + currentChecksum = generateChecksum(otaPackage.getChecksumAlgorithm(), otaPackage.getData()); | |
260 | 252 | |
261 | - if (!currentChecksum.equals(firmware.getChecksum())) { | |
262 | - throw new DataValidationException("Wrong firmware file!"); | |
253 | + if (!currentChecksum.equals(otaPackage.getChecksum())) { | |
254 | + throw new DataValidationException("Wrong otaPackage file!"); | |
263 | 255 | } |
264 | 256 | } |
265 | 257 | |
266 | 258 | @Override |
267 | - protected void validateUpdate(TenantId tenantId, Firmware firmware) { | |
268 | - Firmware firmwareOld = firmwareDao.findById(tenantId, firmware.getUuidId()); | |
259 | + protected void validateUpdate(TenantId tenantId, OtaPackage otaPackage) { | |
260 | + OtaPackage otaPackageOld = otaPackageDao.findById(tenantId, otaPackage.getUuidId()); | |
269 | 261 | |
270 | - validateUpdateDeviceProfile(firmware, firmwareOld); | |
271 | - BaseFirmwareService.validateUpdate(firmware, firmwareOld); | |
262 | + BaseOtaPackageService.validateUpdate(otaPackage, otaPackageOld); | |
272 | 263 | |
273 | - if (firmwareOld.getData() != null && !firmwareOld.getData().equals(firmware.getData())) { | |
274 | - throw new DataValidationException("Updating firmware data is prohibited!"); | |
264 | + if (otaPackageOld.getData() != null && !otaPackageOld.getData().equals(otaPackage.getData())) { | |
265 | + throw new DataValidationException("Updating otaPackage data is prohibited!"); | |
275 | 266 | } |
276 | 267 | } |
277 | 268 | }; |
278 | 269 | |
279 | - private void validateUpdateDeviceProfile(FirmwareInfo firmware, FirmwareInfo firmwareOld) { | |
280 | - if (firmwareOld.getDeviceProfileId() != null && !firmwareOld.getDeviceProfileId().equals(firmware.getDeviceProfileId())) { | |
281 | - if (firmwareInfoDao.isFirmwareUsed(firmwareOld.getId(), firmware.getType(), firmwareOld.getDeviceProfileId())) { | |
282 | - throw new DataValidationException("Can`t update deviceProfileId because firmware is already in use!"); | |
283 | - } | |
270 | + private static void validateUpdate(OtaPackageInfo otaPackage, OtaPackageInfo otaPackageOld) { | |
271 | + if (!otaPackageOld.getType().equals(otaPackage.getType())) { | |
272 | + throw new DataValidationException("Updating type is prohibited!"); | |
284 | 273 | } |
285 | - } | |
286 | 274 | |
287 | - private static void validateUpdate(FirmwareInfo firmware, FirmwareInfo firmwareOld) { | |
288 | - if (!firmwareOld.getType().equals(firmware.getType())) { | |
289 | - throw new DataValidationException("Updating type is prohibited!"); | |
275 | + if (!otaPackageOld.getTitle().equals(otaPackage.getTitle())) { | |
276 | + throw new DataValidationException("Updating otaPackage title is prohibited!"); | |
290 | 277 | } |
291 | 278 | |
292 | - if (!firmwareOld.getTitle().equals(firmware.getTitle())) { | |
293 | - throw new DataValidationException("Updating firmware title is prohibited!"); | |
279 | + if (!otaPackageOld.getVersion().equals(otaPackage.getVersion())) { | |
280 | + throw new DataValidationException("Updating otaPackage version is prohibited!"); | |
294 | 281 | } |
295 | 282 | |
296 | - if (!firmwareOld.getVersion().equals(firmware.getVersion())) { | |
297 | - throw new DataValidationException("Updating firmware version is prohibited!"); | |
283 | + if (!otaPackageOld.getDeviceProfileId().equals(otaPackage.getDeviceProfileId())) { | |
284 | + throw new DataValidationException("Updating otaPackage deviceProfile is prohibited!"); | |
298 | 285 | } |
299 | 286 | |
300 | - if (firmwareOld.getFileName() != null && !firmwareOld.getFileName().equals(firmware.getFileName())) { | |
301 | - throw new DataValidationException("Updating firmware file name is prohibited!"); | |
287 | + if (otaPackageOld.getFileName() != null && !otaPackageOld.getFileName().equals(otaPackage.getFileName())) { | |
288 | + throw new DataValidationException("Updating otaPackage file name is prohibited!"); | |
302 | 289 | } |
303 | 290 | |
304 | - if (firmwareOld.getContentType() != null && !firmwareOld.getContentType().equals(firmware.getContentType())) { | |
305 | - throw new DataValidationException("Updating firmware content type is prohibited!"); | |
291 | + if (otaPackageOld.getContentType() != null && !otaPackageOld.getContentType().equals(otaPackage.getContentType())) { | |
292 | + throw new DataValidationException("Updating otaPackage content type is prohibited!"); | |
306 | 293 | } |
307 | 294 | |
308 | - if (firmwareOld.getChecksumAlgorithm() != null && !firmwareOld.getChecksumAlgorithm().equals(firmware.getChecksumAlgorithm())) { | |
309 | - throw new DataValidationException("Updating firmware content type is prohibited!"); | |
295 | + if (otaPackageOld.getChecksumAlgorithm() != null && !otaPackageOld.getChecksumAlgorithm().equals(otaPackage.getChecksumAlgorithm())) { | |
296 | + throw new DataValidationException("Updating otaPackage content type is prohibited!"); | |
310 | 297 | } |
311 | 298 | |
312 | - if (firmwareOld.getChecksum() != null && !firmwareOld.getChecksum().equals(firmware.getChecksum())) { | |
313 | - throw new DataValidationException("Updating firmware content type is prohibited!"); | |
299 | + if (otaPackageOld.getChecksum() != null && !otaPackageOld.getChecksum().equals(otaPackage.getChecksum())) { | |
300 | + throw new DataValidationException("Updating otaPackage content type is prohibited!"); | |
314 | 301 | } |
315 | 302 | |
316 | - if (firmwareOld.getDataSize() != null && !firmwareOld.getDataSize().equals(firmware.getDataSize())) { | |
317 | - throw new DataValidationException("Updating firmware data size is prohibited!"); | |
303 | + if (otaPackageOld.getDataSize() != null && !otaPackageOld.getDataSize().equals(otaPackage.getDataSize())) { | |
304 | + throw new DataValidationException("Updating otaPackage data size is prohibited!"); | |
318 | 305 | } |
319 | 306 | } |
320 | 307 | |
321 | - private void validateImpl(FirmwareInfo firmwareInfo) { | |
322 | - if (firmwareInfo.getTenantId() == null) { | |
323 | - throw new DataValidationException("Firmware should be assigned to tenant!"); | |
308 | + private void validateImpl(OtaPackageInfo otaPackageInfo) { | |
309 | + if (otaPackageInfo.getTenantId() == null) { | |
310 | + throw new DataValidationException("OtaPackage should be assigned to tenant!"); | |
324 | 311 | } else { |
325 | - Tenant tenant = tenantDao.findById(firmwareInfo.getTenantId(), firmwareInfo.getTenantId().getId()); | |
312 | + Tenant tenant = tenantDao.findById(otaPackageInfo.getTenantId(), otaPackageInfo.getTenantId().getId()); | |
326 | 313 | if (tenant == null) { |
327 | - throw new DataValidationException("Firmware is referencing to non-existent tenant!"); | |
314 | + throw new DataValidationException("OtaPackage is referencing to non-existent tenant!"); | |
328 | 315 | } |
329 | 316 | } |
330 | 317 | |
331 | - if (firmwareInfo.getDeviceProfileId() != null) { | |
332 | - DeviceProfile deviceProfile = deviceProfileDao.findById(firmwareInfo.getTenantId(), firmwareInfo.getDeviceProfileId().getId()); | |
318 | + if (otaPackageInfo.getDeviceProfileId() != null) { | |
319 | + DeviceProfile deviceProfile = deviceProfileDao.findById(otaPackageInfo.getTenantId(), otaPackageInfo.getDeviceProfileId().getId()); | |
333 | 320 | if (deviceProfile == null) { |
334 | - throw new DataValidationException("Firmware is referencing to non-existent device profile!"); | |
321 | + throw new DataValidationException("OtaPackage is referencing to non-existent device profile!"); | |
335 | 322 | } |
336 | 323 | } |
337 | 324 | |
338 | - if (firmwareInfo.getType() == null) { | |
325 | + if (otaPackageInfo.getType() == null) { | |
339 | 326 | throw new DataValidationException("Type should be specified!"); |
340 | 327 | } |
341 | 328 | |
342 | - if (StringUtils.isEmpty(firmwareInfo.getTitle())) { | |
343 | - throw new DataValidationException("Firmware title should be specified!"); | |
329 | + if (StringUtils.isEmpty(otaPackageInfo.getTitle())) { | |
330 | + throw new DataValidationException("OtaPackage title should be specified!"); | |
344 | 331 | } |
345 | 332 | |
346 | - if (StringUtils.isEmpty(firmwareInfo.getVersion())) { | |
347 | - throw new DataValidationException("Firmware version should be specified!"); | |
333 | + if (StringUtils.isEmpty(otaPackageInfo.getVersion())) { | |
334 | + throw new DataValidationException("OtaPackage version should be specified!"); | |
348 | 335 | } |
349 | 336 | } |
350 | 337 | |
351 | - private PaginatedRemover<TenantId, FirmwareInfo> tenantFirmwareRemover = | |
338 | + private PaginatedRemover<TenantId, OtaPackageInfo> tenantOtaPackageRemover = | |
352 | 339 | new PaginatedRemover<>() { |
353 | 340 | |
354 | 341 | @Override |
355 | - protected PageData<FirmwareInfo> findEntities(TenantId tenantId, TenantId id, PageLink pageLink) { | |
356 | - return firmwareInfoDao.findFirmwareInfoByTenantId(id, pageLink); | |
342 | + protected PageData<OtaPackageInfo> findEntities(TenantId tenantId, TenantId id, PageLink pageLink) { | |
343 | + return otaPackageInfoDao.findOtaPackageInfoByTenantId(id, pageLink); | |
357 | 344 | } |
358 | 345 | |
359 | 346 | @Override |
360 | - protected void removeEntity(TenantId tenantId, FirmwareInfo entity) { | |
361 | - deleteFirmware(tenantId, entity.getId()); | |
347 | + protected void removeEntity(TenantId tenantId, OtaPackageInfo entity) { | |
348 | + deleteOtaPackage(tenantId, entity.getId()); | |
362 | 349 | } |
363 | 350 | }; |
364 | 351 | |
... | ... | @@ -372,8 +359,8 @@ public class BaseFirmwareService implements FirmwareService { |
372 | 359 | } |
373 | 360 | } |
374 | 361 | |
375 | - private static List<FirmwareId> toFirmwareInfoKey(FirmwareId firmwareId) { | |
376 | - return Collections.singletonList(firmwareId); | |
362 | + private static List<OtaPackageId> toOtaPackageInfoKey(OtaPackageId otaPackageId) { | |
363 | + return Collections.singletonList(otaPackageId); | |
377 | 364 | } |
378 | 365 | |
379 | 366 | } | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/ota/OtaPackageDao.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/firmware/FirmwareDao.java
... | ... | @@ -13,11 +13,11 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.dao.firmware; | |
16 | +package org.thingsboard.server.dao.ota; | |
17 | 17 | |
18 | -import org.thingsboard.server.common.data.Firmware; | |
18 | +import org.thingsboard.server.common.data.OtaPackage; | |
19 | 19 | import org.thingsboard.server.dao.Dao; |
20 | 20 | |
21 | -public interface FirmwareDao extends Dao<Firmware> { | |
21 | +public interface OtaPackageDao extends Dao<OtaPackage> { | |
22 | 22 | |
23 | 23 | } | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/ota/OtaPackageInfoDao.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/firmware/FirmwareInfoDao.java
... | ... | @@ -13,25 +13,23 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.dao.firmware; | |
16 | +package org.thingsboard.server.dao.ota; | |
17 | 17 | |
18 | -import org.thingsboard.server.common.data.FirmwareInfo; | |
19 | -import org.thingsboard.server.common.data.firmware.FirmwareType; | |
18 | +import org.thingsboard.server.common.data.OtaPackageInfo; | |
19 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | |
20 | 20 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
21 | -import org.thingsboard.server.common.data.id.FirmwareId; | |
21 | +import org.thingsboard.server.common.data.id.OtaPackageId; | |
22 | 22 | import org.thingsboard.server.common.data.id.TenantId; |
23 | 23 | import org.thingsboard.server.common.data.page.PageData; |
24 | 24 | import org.thingsboard.server.common.data.page.PageLink; |
25 | 25 | import org.thingsboard.server.dao.Dao; |
26 | 26 | |
27 | -import java.util.UUID; | |
27 | +public interface OtaPackageInfoDao extends Dao<OtaPackageInfo> { | |
28 | 28 | |
29 | -public interface FirmwareInfoDao extends Dao<FirmwareInfo> { | |
29 | + PageData<OtaPackageInfo> findOtaPackageInfoByTenantId(TenantId tenantId, PageLink pageLink); | |
30 | 30 | |
31 | - PageData<FirmwareInfo> findFirmwareInfoByTenantId(TenantId tenantId, PageLink pageLink); | |
31 | + PageData<OtaPackageInfo> findOtaPackageInfoByTenantIdAndDeviceProfileIdAndTypeAndHasData(TenantId tenantId, DeviceProfileId deviceProfileId, OtaPackageType otaPackageType, boolean hasData, PageLink pageLink); | |
32 | 32 | |
33 | - PageData<FirmwareInfo> findFirmwareInfoByTenantIdAndDeviceProfileIdAndTypeAndHasData(TenantId tenantId, DeviceProfileId deviceProfileId, FirmwareType firmwareType, boolean hasData, PageLink pageLink); | |
34 | - | |
35 | - boolean isFirmwareUsed(FirmwareId firmwareId, FirmwareType type, DeviceProfileId deviceProfileId); | |
33 | + boolean isOtaPackageUsed(OtaPackageId otaPackageId, OtaPackageType otaPackageType, DeviceProfileId deviceProfileId); | |
36 | 34 | |
37 | 35 | } | ... | ... |
... | ... | @@ -96,23 +96,35 @@ public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntit |
96 | 96 | Pageable pageable); |
97 | 97 | |
98 | 98 | @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " + |
99 | - "AND d.type = :type " + | |
99 | + "AND d.deviceProfileId = :deviceProfileId " + | |
100 | 100 | "AND d.firmwareId = null " + |
101 | 101 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
102 | 102 | Page<DeviceEntity> findByTenantIdAndTypeAndFirmwareIdIsNull(@Param("tenantId") UUID tenantId, |
103 | - @Param("type") String type, | |
103 | + @Param("deviceProfileId") UUID deviceProfileId, | |
104 | 104 | @Param("textSearch") String textSearch, |
105 | 105 | Pageable pageable); |
106 | 106 | |
107 | 107 | @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " + |
108 | - "AND d.type = :type " + | |
108 | + "AND d.deviceProfileId = :deviceProfileId " + | |
109 | 109 | "AND d.softwareId = null " + |
110 | 110 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
111 | 111 | Page<DeviceEntity> findByTenantIdAndTypeAndSoftwareIdIsNull(@Param("tenantId") UUID tenantId, |
112 | - @Param("type") String type, | |
112 | + @Param("deviceProfileId") UUID deviceProfileId, | |
113 | 113 | @Param("textSearch") String textSearch, |
114 | 114 | Pageable pageable); |
115 | 115 | |
116 | + @Query("SELECT count(*) FROM DeviceEntity d WHERE d.tenantId = :tenantId " + | |
117 | + "AND d.deviceProfileId = :deviceProfileId " + | |
118 | + "AND d.firmwareId = null") | |
119 | + Long countByTenantIdAndDeviceProfileIdAndFirmwareIdIsNull(@Param("tenantId") UUID tenantId, | |
120 | + @Param("deviceProfileId") UUID deviceProfileId); | |
121 | + | |
122 | + @Query("SELECT count(*) FROM DeviceEntity d WHERE d.tenantId = :tenantId " + | |
123 | + "AND d.deviceProfileId = :deviceProfileId " + | |
124 | + "AND d.softwareId = null") | |
125 | + Long countByTenantIdAndDeviceProfileIdAndSoftwareIdIsNull(@Param("tenantId") UUID tenantId, | |
126 | + @Param("deviceProfileId") UUID deviceProfileId); | |
127 | + | |
116 | 128 | @Query("SELECT new org.thingsboard.server.dao.model.sql.DeviceInfoEntity(d, c.title, c.additionalInfo, p.name) " + |
117 | 129 | "FROM DeviceEntity d " + |
118 | 130 | "LEFT JOIN CustomerEntity c on c.id = d.customerId " + | ... | ... |
... | ... | @@ -18,6 +18,8 @@ package org.thingsboard.server.dao.sql.device; |
18 | 18 | import com.google.common.util.concurrent.ListenableFuture; |
19 | 19 | import lombok.extern.slf4j.Slf4j; |
20 | 20 | import org.springframework.beans.factory.annotation.Autowired; |
21 | +import org.springframework.data.domain.Page; | |
22 | +import org.springframework.data.domain.Pageable; | |
21 | 23 | import org.springframework.data.repository.CrudRepository; |
22 | 24 | import org.springframework.stereotype.Component; |
23 | 25 | import org.springframework.util.StringUtils; |
... | ... | @@ -27,6 +29,8 @@ import org.thingsboard.server.common.data.DeviceTransportType; |
27 | 29 | import org.thingsboard.server.common.data.EntitySubtype; |
28 | 30 | import org.thingsboard.server.common.data.EntityType; |
29 | 31 | import org.thingsboard.server.common.data.id.TenantId; |
32 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | |
33 | +import org.thingsboard.server.common.data.ota.OtaPackageUtil; | |
30 | 34 | import org.thingsboard.server.common.data.page.PageData; |
31 | 35 | import org.thingsboard.server.common.data.page.PageLink; |
32 | 36 | import org.thingsboard.server.dao.DaoUtil; |
... | ... | @@ -155,23 +159,27 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> |
155 | 159 | } |
156 | 160 | |
157 | 161 | @Override |
158 | - public PageData<Device> findDevicesByTenantIdAndTypeAndEmptyFirmware(UUID tenantId, String type, PageLink pageLink) { | |
159 | - return DaoUtil.toPageData( | |
160 | - deviceRepository.findByTenantIdAndTypeAndFirmwareIdIsNull( | |
161 | - tenantId, | |
162 | - type, | |
163 | - Objects.toString(pageLink.getTextSearch(), ""), | |
164 | - DaoUtil.toPageable(pageLink))); | |
162 | + public PageData<Device> findDevicesByTenantIdAndTypeAndEmptyOtaPackage(UUID tenantId, | |
163 | + UUID deviceProfileId, | |
164 | + OtaPackageType type, | |
165 | + PageLink pageLink) { | |
166 | + Pageable pageable = DaoUtil.toPageable(pageLink); | |
167 | + String searchText = Objects.toString(pageLink.getTextSearch(), ""); | |
168 | + Page<DeviceEntity> page = OtaPackageUtil.getByOtaPackageType( | |
169 | + () -> deviceRepository.findByTenantIdAndTypeAndFirmwareIdIsNull(tenantId, deviceProfileId, searchText, pageable), | |
170 | + () -> deviceRepository.findByTenantIdAndTypeAndSoftwareIdIsNull(tenantId, deviceProfileId, searchText, pageable), | |
171 | + type | |
172 | + ); | |
173 | + return DaoUtil.toPageData(page); | |
165 | 174 | } |
166 | 175 | |
167 | 176 | @Override |
168 | - public PageData<Device> findDevicesByTenantIdAndTypeAndEmptySoftware(UUID tenantId, String type, PageLink pageLink) { | |
169 | - return DaoUtil.toPageData( | |
170 | - deviceRepository.findByTenantIdAndTypeAndSoftwareIdIsNull( | |
171 | - tenantId, | |
172 | - type, | |
173 | - Objects.toString(pageLink.getTextSearch(), ""), | |
174 | - DaoUtil.toPageable(pageLink))); | |
177 | + public Long countDevicesByTenantIdAndDeviceProfileIdAndEmptyOtaPackage(UUID tenantId, UUID deviceProfileId, OtaPackageType type) { | |
178 | + return OtaPackageUtil.getByOtaPackageType( | |
179 | + () -> deviceRepository.countByTenantIdAndDeviceProfileIdAndFirmwareIdIsNull(tenantId, deviceProfileId), | |
180 | + () -> deviceRepository.countByTenantIdAndDeviceProfileIdAndSoftwareIdIsNull(tenantId, deviceProfileId), | |
181 | + type | |
182 | + ); | |
175 | 183 | } |
176 | 184 | |
177 | 185 | @Override | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/sql/ota/JpaOtaPackageDao.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/sql/firmware/JpaFirmwareDao.java
... | ... | @@ -13,34 +13,34 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.dao.sql.firmware; | |
16 | +package org.thingsboard.server.dao.sql.ota; | |
17 | 17 | |
18 | 18 | import lombok.extern.slf4j.Slf4j; |
19 | 19 | import org.springframework.beans.factory.annotation.Autowired; |
20 | 20 | import org.springframework.data.repository.CrudRepository; |
21 | 21 | import org.springframework.stereotype.Component; |
22 | -import org.thingsboard.server.common.data.Firmware; | |
23 | -import org.thingsboard.server.dao.firmware.FirmwareDao; | |
24 | -import org.thingsboard.server.dao.model.sql.FirmwareEntity; | |
22 | +import org.thingsboard.server.common.data.OtaPackage; | |
23 | +import org.thingsboard.server.dao.ota.OtaPackageDao; | |
24 | +import org.thingsboard.server.dao.model.sql.OtaPackageEntity; | |
25 | 25 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
26 | 26 | |
27 | 27 | import java.util.UUID; |
28 | 28 | |
29 | 29 | @Slf4j |
30 | 30 | @Component |
31 | -public class JpaFirmwareDao extends JpaAbstractSearchTextDao<FirmwareEntity, Firmware> implements FirmwareDao { | |
31 | +public class JpaOtaPackageDao extends JpaAbstractSearchTextDao<OtaPackageEntity, OtaPackage> implements OtaPackageDao { | |
32 | 32 | |
33 | 33 | @Autowired |
34 | - private FirmwareRepository firmwareRepository; | |
34 | + private OtaPackageRepository otaPackageRepository; | |
35 | 35 | |
36 | 36 | @Override |
37 | - protected Class<FirmwareEntity> getEntityClass() { | |
38 | - return FirmwareEntity.class; | |
37 | + protected Class<OtaPackageEntity> getEntityClass() { | |
38 | + return OtaPackageEntity.class; | |
39 | 39 | } |
40 | 40 | |
41 | 41 | @Override |
42 | - protected CrudRepository<FirmwareEntity, UUID> getCrudRepository() { | |
43 | - return firmwareRepository; | |
42 | + protected CrudRepository<OtaPackageEntity, UUID> getCrudRepository() { | |
43 | + return otaPackageRepository; | |
44 | 44 | } |
45 | 45 | |
46 | 46 | } | ... | ... |