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 | "title": "Firmware", | 2 | "title": "Firmware", |
3 | + "image": null, | ||
3 | "configuration": { | 4 | "configuration": { |
4 | "description": "", | 5 | "description": "", |
5 | "widgets": { | 6 | "widgets": { |
@@ -247,7 +248,7 @@ | @@ -247,7 +248,7 @@ | ||
247 | "name": "Edit firmware", | 248 | "name": "Edit firmware", |
248 | "icon": "edit", | 249 | "icon": "edit", |
249 | "type": "customPretty", | 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 | "customCss": "", | 252 | "customCss": "", |
252 | "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 | "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 | "customResources": [], | 254 | "customResources": [], |
@@ -257,7 +258,7 @@ | @@ -257,7 +258,7 @@ | ||
257 | "name": "Download firware", | 258 | "name": "Download firware", |
258 | "icon": "file_download", | 259 | "icon": "file_download", |
259 | "type": "custom", | 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 | "id": "12533058-42f6-e75f-620c-219c48d01ec0" | 262 | "id": "12533058-42f6-e75f-620c-219c48d01ec0" |
262 | }, | 263 | }, |
263 | { | 264 | { |
@@ -1021,7 +1022,7 @@ | @@ -1021,7 +1022,7 @@ | ||
1021 | "name": "Edit firmware", | 1022 | "name": "Edit firmware", |
1022 | "icon": "edit", | 1023 | "icon": "edit", |
1023 | "type": "customPretty", | 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 | "customCss": "", | 1026 | "customCss": "", |
1026 | "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 | "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 | "customResources": [], | 1028 | "customResources": [], |
@@ -1031,7 +1032,7 @@ | @@ -1031,7 +1032,7 @@ | ||
1031 | "name": "Download firware", | 1032 | "name": "Download firware", |
1032 | "icon": "file_download", | 1033 | "icon": "file_download", |
1033 | "type": "custom", | 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 | "id": "12533058-42f6-e75f-620c-219c48d01ec0" | 1036 | "id": "12533058-42f6-e75f-620c-219c48d01ec0" |
1036 | }, | 1037 | }, |
1037 | { | 1038 | { |
@@ -1297,7 +1298,7 @@ | @@ -1297,7 +1298,7 @@ | ||
1297 | "name": "Edit firmware", | 1298 | "name": "Edit firmware", |
1298 | "icon": "edit", | 1299 | "icon": "edit", |
1299 | "type": "customPretty", | 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 | "customCss": "", | 1302 | "customCss": "", |
1302 | "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 | "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 | "customResources": [], | 1304 | "customResources": [], |
@@ -1307,7 +1308,7 @@ | @@ -1307,7 +1308,7 @@ | ||
1307 | "name": "Download firware", | 1308 | "name": "Download firware", |
1308 | "icon": "file_download", | 1309 | "icon": "file_download", |
1309 | "type": "custom", | 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 | "id": "12533058-42f6-e75f-620c-219c48d01ec0" | 1312 | "id": "12533058-42f6-e75f-620c-219c48d01ec0" |
1312 | }, | 1313 | }, |
1313 | { | 1314 | { |
@@ -1573,7 +1574,7 @@ | @@ -1573,7 +1574,7 @@ | ||
1573 | "name": "Edit firmware", | 1574 | "name": "Edit firmware", |
1574 | "icon": "edit", | 1575 | "icon": "edit", |
1575 | "type": "customPretty", | 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 | "customCss": "", | 1578 | "customCss": "", |
1578 | "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 | "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 | "customResources": [], | 1580 | "customResources": [], |
@@ -1583,7 +1584,7 @@ | @@ -1583,7 +1584,7 @@ | ||
1583 | "name": "Download firware", | 1584 | "name": "Download firware", |
1584 | "icon": "file_download", | 1585 | "icon": "file_download", |
1585 | "type": "custom", | 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 | "id": "12533058-42f6-e75f-620c-219c48d01ec0" | 1588 | "id": "12533058-42f6-e75f-620c-219c48d01ec0" |
1588 | }, | 1589 | }, |
1589 | { | 1590 | { |
@@ -1849,7 +1850,7 @@ | @@ -1849,7 +1850,7 @@ | ||
1849 | "name": "Edit firmware", | 1850 | "name": "Edit firmware", |
1850 | "icon": "edit", | 1851 | "icon": "edit", |
1851 | "type": "customPretty", | 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 | "customCss": "", | 1854 | "customCss": "", |
1854 | "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 | "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 | "customResources": [], | 1856 | "customResources": [], |
@@ -1859,7 +1860,7 @@ | @@ -1859,7 +1860,7 @@ | ||
1859 | "name": "Download firware", | 1860 | "name": "Download firware", |
1860 | "icon": "file_download", | 1861 | "icon": "file_download", |
1861 | "type": "custom", | 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 | "id": "12533058-42f6-e75f-620c-219c48d01ec0" | 1864 | "id": "12533058-42f6-e75f-620c-219c48d01ec0" |
1864 | }, | 1865 | }, |
1865 | { | 1866 | { |
@@ -59,8 +59,8 @@ CREATE TABLE IF NOT EXISTS resource ( | @@ -59,8 +59,8 @@ CREATE TABLE IF NOT EXISTS resource ( | ||
59 | CONSTRAINT resource_unq_key UNIQUE (tenant_id, resource_type, resource_key) | 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 | created_time bigint NOT NULL, | 64 | created_time bigint NOT NULL, |
65 | tenant_id uuid NOT NULL, | 65 | tenant_id uuid NOT NULL, |
66 | device_profile_id uuid, | 66 | device_profile_id uuid, |
@@ -75,7 +75,7 @@ CREATE TABLE IF NOT EXISTS firmware ( | @@ -75,7 +75,7 @@ CREATE TABLE IF NOT EXISTS firmware ( | ||
75 | data_size bigint, | 75 | data_size bigint, |
76 | additional_info varchar, | 76 | additional_info varchar, |
77 | search_text varchar(255), | 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 | ALTER TABLE dashboard | 81 | ALTER TABLE dashboard |
@@ -101,13 +101,13 @@ DO $$ | @@ -101,13 +101,13 @@ DO $$ | ||
101 | IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'fk_firmware_device_profile') THEN | 101 | IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'fk_firmware_device_profile') THEN |
102 | ALTER TABLE device_profile | 102 | ALTER TABLE device_profile |
103 | ADD CONSTRAINT fk_firmware_device_profile | 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 | END IF; | 105 | END IF; |
106 | 106 | ||
107 | IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'fk_software_device_profile') THEN | 107 | IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'fk_software_device_profile') THEN |
108 | ALTER TABLE device_profile | 108 | ALTER TABLE device_profile |
109 | ADD CONSTRAINT fk_software_device_profile | 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 | END IF; | 111 | END IF; |
112 | 112 | ||
113 | IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'fk_default_dashboard_device_profile') THEN | 113 | IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'fk_default_dashboard_device_profile') THEN |
@@ -119,13 +119,13 @@ DO $$ | @@ -119,13 +119,13 @@ DO $$ | ||
119 | IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'fk_firmware_device') THEN | 119 | IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'fk_firmware_device') THEN |
120 | ALTER TABLE device | 120 | ALTER TABLE device |
121 | ADD CONSTRAINT fk_firmware_device | 121 | ADD CONSTRAINT fk_firmware_device |
122 | - FOREIGN KEY (firmware_id) REFERENCES firmware(id); | 122 | + FOREIGN KEY (firmware_id) REFERENCES ota_package(id); |
123 | END IF; | 123 | END IF; |
124 | 124 | ||
125 | IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'fk_software_device') THEN | 125 | IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'fk_software_device') THEN |
126 | ALTER TABLE device | 126 | ALTER TABLE device |
127 | ADD CONSTRAINT fk_software_device | 127 | ADD CONSTRAINT fk_software_device |
128 | - FOREIGN KEY (firmware_id) REFERENCES firmware(id); | 128 | + FOREIGN KEY (firmware_id) REFERENCES ota_package(id); |
129 | END IF; | 129 | END IF; |
130 | END; | 130 | END; |
131 | $$; | 131 | $$; |
@@ -39,8 +39,8 @@ import org.thingsboard.server.common.data.EdgeUtils; | @@ -39,8 +39,8 @@ import org.thingsboard.server.common.data.EdgeUtils; | ||
39 | import org.thingsboard.server.common.data.EntityType; | 39 | import org.thingsboard.server.common.data.EntityType; |
40 | import org.thingsboard.server.common.data.EntityView; | 40 | import org.thingsboard.server.common.data.EntityView; |
41 | import org.thingsboard.server.common.data.EntityViewInfo; | 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 | import org.thingsboard.server.common.data.HasName; | 44 | import org.thingsboard.server.common.data.HasName; |
45 | import org.thingsboard.server.common.data.HasTenantId; | 45 | import org.thingsboard.server.common.data.HasTenantId; |
46 | import org.thingsboard.server.common.data.TbResourceInfo; | 46 | import org.thingsboard.server.common.data.TbResourceInfo; |
@@ -70,7 +70,7 @@ import org.thingsboard.server.common.data.id.EdgeId; | @@ -70,7 +70,7 @@ import org.thingsboard.server.common.data.id.EdgeId; | ||
70 | import org.thingsboard.server.common.data.id.EntityId; | 70 | import org.thingsboard.server.common.data.id.EntityId; |
71 | import org.thingsboard.server.common.data.id.EntityIdFactory; | 71 | import org.thingsboard.server.common.data.id.EntityIdFactory; |
72 | import org.thingsboard.server.common.data.id.EntityViewId; | 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 | import org.thingsboard.server.common.data.id.TbResourceId; | 74 | import org.thingsboard.server.common.data.id.TbResourceId; |
75 | import org.thingsboard.server.common.data.id.RuleChainId; | 75 | import org.thingsboard.server.common.data.id.RuleChainId; |
76 | import org.thingsboard.server.common.data.id.RuleNodeId; | 76 | import org.thingsboard.server.common.data.id.RuleNodeId; |
@@ -110,7 +110,7 @@ import org.thingsboard.server.dao.edge.EdgeService; | @@ -110,7 +110,7 @@ import org.thingsboard.server.dao.edge.EdgeService; | ||
110 | import org.thingsboard.server.dao.entityview.EntityViewService; | 110 | import org.thingsboard.server.dao.entityview.EntityViewService; |
111 | import org.thingsboard.server.dao.exception.DataValidationException; | 111 | import org.thingsboard.server.dao.exception.DataValidationException; |
112 | import org.thingsboard.server.dao.exception.IncorrectParameterException; | 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 | import org.thingsboard.server.dao.model.ModelConstants; | 114 | import org.thingsboard.server.dao.model.ModelConstants; |
115 | import org.thingsboard.server.dao.oauth2.OAuth2ConfigTemplateService; | 115 | import org.thingsboard.server.dao.oauth2.OAuth2ConfigTemplateService; |
116 | import org.thingsboard.server.dao.oauth2.OAuth2Service; | 116 | import org.thingsboard.server.dao.oauth2.OAuth2Service; |
@@ -128,7 +128,7 @@ import org.thingsboard.server.queue.discovery.PartitionService; | @@ -128,7 +128,7 @@ import org.thingsboard.server.queue.discovery.PartitionService; | ||
128 | import org.thingsboard.server.queue.provider.TbQueueProducerProvider; | 128 | import org.thingsboard.server.queue.provider.TbQueueProducerProvider; |
129 | import org.thingsboard.server.queue.util.TbCoreComponent; | 129 | import org.thingsboard.server.queue.util.TbCoreComponent; |
130 | import org.thingsboard.server.service.component.ComponentDiscoveryService; | 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 | import org.thingsboard.server.service.edge.EdgeNotificationService; | 132 | import org.thingsboard.server.service.edge.EdgeNotificationService; |
133 | import org.thingsboard.server.service.edge.rpc.EdgeGrpcService; | 133 | import org.thingsboard.server.service.edge.rpc.EdgeGrpcService; |
134 | import org.thingsboard.server.service.edge.rpc.init.SyncEdgeService; | 134 | import org.thingsboard.server.service.edge.rpc.init.SyncEdgeService; |
@@ -250,10 +250,10 @@ public abstract class BaseController { | @@ -250,10 +250,10 @@ public abstract class BaseController { | ||
250 | protected TbResourceService resourceService; | 250 | protected TbResourceService resourceService; |
251 | 251 | ||
252 | @Autowired | 252 | @Autowired |
253 | - protected FirmwareService firmwareService; | 253 | + protected OtaPackageService otaPackageService; |
254 | 254 | ||
255 | @Autowired | 255 | @Autowired |
256 | - protected FirmwareStateService firmwareStateService; | 256 | + protected OtaPackageStateService otaPackageStateService; |
257 | 257 | ||
258 | @Autowired | 258 | @Autowired |
259 | protected TbQueueProducerProvider producerProvider; | 259 | protected TbQueueProducerProvider producerProvider; |
@@ -511,8 +511,8 @@ public abstract class BaseController { | @@ -511,8 +511,8 @@ public abstract class BaseController { | ||
511 | case TB_RESOURCE: | 511 | case TB_RESOURCE: |
512 | checkResourceId(new TbResourceId(entityId.getId()), operation); | 512 | checkResourceId(new TbResourceId(entityId.getId()), operation); |
513 | return; | 513 | return; |
514 | - case FIRMWARE: | ||
515 | - checkFirmwareId(new FirmwareId(entityId.getId()), operation); | 514 | + case OTA_PACKAGE: |
515 | + checkOtaPackageId(new OtaPackageId(entityId.getId()), operation); | ||
516 | return; | 516 | return; |
517 | default: | 517 | default: |
518 | throw new IllegalArgumentException("Unsupported entity type: " + entityId.getEntityType()); | 518 | throw new IllegalArgumentException("Unsupported entity type: " + entityId.getEntityType()); |
@@ -769,25 +769,25 @@ public abstract class BaseController { | @@ -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 | try { | 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 | } catch (Exception e) { | 779 | } catch (Exception e) { |
780 | throw handleException(e, false); | 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 | try { | 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 | } catch (Exception e) { | 791 | } catch (Exception e) { |
792 | throw handleException(e, false); | 792 | throw handleException(e, false); |
793 | } | 793 | } |
@@ -53,6 +53,7 @@ import org.thingsboard.server.common.data.id.DeviceId; | @@ -53,6 +53,7 @@ import org.thingsboard.server.common.data.id.DeviceId; | ||
53 | import org.thingsboard.server.common.data.id.DeviceProfileId; | 53 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
54 | import org.thingsboard.server.common.data.id.EdgeId; | 54 | import org.thingsboard.server.common.data.id.EdgeId; |
55 | import org.thingsboard.server.common.data.id.TenantId; | 55 | import org.thingsboard.server.common.data.id.TenantId; |
56 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | ||
56 | import org.thingsboard.server.common.data.page.PageData; | 57 | import org.thingsboard.server.common.data.page.PageData; |
57 | import org.thingsboard.server.common.data.page.PageLink; | 58 | import org.thingsboard.server.common.data.page.PageLink; |
58 | import org.thingsboard.server.common.data.page.TimePageLink; | 59 | import org.thingsboard.server.common.data.page.TimePageLink; |
@@ -75,6 +76,7 @@ import javax.annotation.Nullable; | @@ -75,6 +76,7 @@ import javax.annotation.Nullable; | ||
75 | import java.io.IOException; | 76 | import java.io.IOException; |
76 | import java.util.ArrayList; | 77 | import java.util.ArrayList; |
77 | import java.util.List; | 78 | import java.util.List; |
79 | +import java.util.UUID; | ||
78 | import java.util.stream.Collectors; | 80 | import java.util.stream.Collectors; |
79 | 81 | ||
80 | import static org.thingsboard.server.controller.EdgeController.EDGE_ID; | 82 | import static org.thingsboard.server.controller.EdgeController.EDGE_ID; |
@@ -153,7 +155,7 @@ public class DeviceController extends BaseController { | @@ -153,7 +155,7 @@ public class DeviceController extends BaseController { | ||
153 | deviceStateService.onDeviceUpdated(savedDevice); | 155 | deviceStateService.onDeviceUpdated(savedDevice); |
154 | } | 156 | } |
155 | 157 | ||
156 | - firmwareStateService.update(savedDevice, oldDevice); | 158 | + otaPackageStateService.update(savedDevice, oldDevice); |
157 | 159 | ||
158 | return savedDevice; | 160 | return savedDevice; |
159 | } catch (Exception e) { | 161 | } catch (Exception e) { |
@@ -778,4 +780,19 @@ public class DeviceController extends BaseController { | @@ -778,4 +780,19 @@ public class DeviceController extends BaseController { | ||
778 | throw handleException(e); | 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,7 +168,7 @@ public class DeviceProfileController extends BaseController { | ||
168 | null, | 168 | null, |
169 | created ? ActionType.ADDED : ActionType.UPDATED, null); | 169 | created ? ActionType.ADDED : ActionType.UPDATED, null); |
170 | 170 | ||
171 | - firmwareStateService.update(savedDeviceProfile, isFirmwareChanged, isSoftwareChanged); | 171 | + otaPackageStateService.update(savedDeviceProfile, isFirmwareChanged, isSoftwareChanged); |
172 | 172 | ||
173 | sendEntityNotificationMsg(getTenantId(), savedDeviceProfile.getId(), | 173 | sendEntityNotificationMsg(getTenantId(), savedDeviceProfile.getId(), |
174 | deviceProfile.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED); | 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,14 +30,14 @@ import org.springframework.web.bind.annotation.ResponseBody; | ||
30 | import org.springframework.web.bind.annotation.RestController; | 30 | import org.springframework.web.bind.annotation.RestController; |
31 | import org.springframework.web.multipart.MultipartFile; | 31 | import org.springframework.web.multipart.MultipartFile; |
32 | import org.thingsboard.server.common.data.EntityType; | 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 | import org.thingsboard.server.common.data.audit.ActionType; | 35 | import org.thingsboard.server.common.data.audit.ActionType; |
36 | import org.thingsboard.server.common.data.exception.ThingsboardException; | 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 | import org.thingsboard.server.common.data.id.DeviceProfileId; | 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 | import org.thingsboard.server.common.data.page.PageData; | 41 | import org.thingsboard.server.common.data.page.PageData; |
42 | import org.thingsboard.server.common.data.page.PageLink; | 42 | import org.thingsboard.server.common.data.page.PageLink; |
43 | import org.thingsboard.server.queue.util.TbCoreComponent; | 43 | import org.thingsboard.server.queue.util.TbCoreComponent; |
@@ -50,26 +50,26 @@ import java.nio.ByteBuffer; | @@ -50,26 +50,26 @@ import java.nio.ByteBuffer; | ||
50 | @RestController | 50 | @RestController |
51 | @TbCoreComponent | 51 | @TbCoreComponent |
52 | @RequestMapping("/api") | 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 | public static final String CHECKSUM_ALGORITHM = "checksumAlgorithm"; | 56 | public static final String CHECKSUM_ALGORITHM = "checksumAlgorithm"; |
57 | 57 | ||
58 | @PreAuthorize("hasAnyAuthority( 'TENANT_ADMIN')") | 58 | @PreAuthorize("hasAnyAuthority( 'TENANT_ADMIN')") |
59 | - @RequestMapping(value = "/firmware/{firmwareId}/download", method = RequestMethod.GET) | 59 | + @RequestMapping(value = "/otaPackage/{otaPackageId}/download", method = RequestMethod.GET) |
60 | @ResponseBody | 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 | try { | 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 | return ResponseEntity.ok() | 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 | .contentLength(resource.contentLength()) | 71 | .contentLength(resource.contentLength()) |
72 | - .contentType(parseMediaType(firmware.getContentType())) | 72 | + .contentType(parseMediaType(otaPackage.getContentType())) |
73 | .body(resource); | 73 | .body(resource); |
74 | } catch (Exception e) { | 74 | } catch (Exception e) { |
75 | throw handleException(e); | 75 | throw handleException(e); |
@@ -77,144 +77,144 @@ public class FirmwareController extends BaseController { | @@ -77,144 +77,144 @@ public class FirmwareController extends BaseController { | ||
77 | } | 77 | } |
78 | 78 | ||
79 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") | 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 | @ResponseBody | 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 | try { | 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 | } catch (Exception e) { | 87 | } catch (Exception e) { |
88 | throw handleException(e); | 88 | throw handleException(e); |
89 | } | 89 | } |
90 | } | 90 | } |
91 | 91 | ||
92 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')") | 92 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')") |
93 | - @RequestMapping(value = "/firmware/{firmwareId}", method = RequestMethod.GET) | 93 | + @RequestMapping(value = "/otaPackage/{otaPackageId}", method = RequestMethod.GET) |
94 | @ResponseBody | 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 | try { | 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 | } catch (Exception e) { | 100 | } catch (Exception e) { |
101 | throw handleException(e); | 101 | throw handleException(e); |
102 | } | 102 | } |
103 | } | 103 | } |
104 | 104 | ||
105 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')") | 105 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')") |
106 | - @RequestMapping(value = "/firmware", method = RequestMethod.POST) | 106 | + @RequestMapping(value = "/otaPackage", method = RequestMethod.POST) |
107 | @ResponseBody | 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 | try { | 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 | null, created ? ActionType.ADDED : ActionType.UPDATED, null); | 115 | null, created ? ActionType.ADDED : ActionType.UPDATED, null); |
116 | - return savedFirmwareInfo; | 116 | + return savedOtaPackageInfo; |
117 | } catch (Exception e) { | 117 | } catch (Exception e) { |
118 | - logEntityAction(emptyId(EntityType.FIRMWARE), firmwareInfo, | 118 | + logEntityAction(emptyId(EntityType.OTA_PACKAGE), otaPackageInfo, |
119 | null, created ? ActionType.ADDED : ActionType.UPDATED, e); | 119 | null, created ? ActionType.ADDED : ActionType.UPDATED, e); |
120 | throw handleException(e); | 120 | throw handleException(e); |
121 | } | 121 | } |
122 | } | 122 | } |
123 | 123 | ||
124 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')") | 124 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')") |
125 | - @RequestMapping(value = "/firmware/{firmwareId}", method = RequestMethod.POST) | 125 | + @RequestMapping(value = "/otaPackage/{otaPackageId}", method = RequestMethod.POST) |
126 | @ResponseBody | 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 | checkParameter(CHECKSUM_ALGORITHM, checksumAlgorithmStr); | 132 | checkParameter(CHECKSUM_ALGORITHM, checksumAlgorithmStr); |
133 | try { | 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 | ChecksumAlgorithm checksumAlgorithm = ChecksumAlgorithm.valueOf(checksumAlgorithmStr.toUpperCase()); | 146 | ChecksumAlgorithm checksumAlgorithm = ChecksumAlgorithm.valueOf(checksumAlgorithmStr.toUpperCase()); |
147 | 147 | ||
148 | byte[] bytes = file.getBytes(); | 148 | byte[] bytes = file.getBytes(); |
149 | if (StringUtils.isEmpty(checksum)) { | 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 | } catch (Exception e) { | 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 | throw handleException(e); | 164 | throw handleException(e); |
165 | } | 165 | } |
166 | } | 166 | } |
167 | 167 | ||
168 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") | 168 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") |
169 | - @RequestMapping(value = "/firmwares", method = RequestMethod.GET) | 169 | + @RequestMapping(value = "/otaPackages", method = RequestMethod.GET) |
170 | @ResponseBody | 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 | try { | 176 | try { |
177 | PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder); | 177 | PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder); |
178 | - return checkNotNull(firmwareService.findTenantFirmwaresByTenantId(getTenantId(), pageLink)); | 178 | + return checkNotNull(otaPackageService.findTenantOtaPackagesByTenantId(getTenantId(), pageLink)); |
179 | } catch (Exception e) { | 179 | } catch (Exception e) { |
180 | throw handleException(e); | 180 | throw handleException(e); |
181 | } | 181 | } |
182 | } | 182 | } |
183 | 183 | ||
184 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") | 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 | @ResponseBody | 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 | checkParameter("deviceProfileId", strDeviceProfileId); | 195 | checkParameter("deviceProfileId", strDeviceProfileId); |
196 | checkParameter("type", strType); | 196 | checkParameter("type", strType); |
197 | try { | 197 | try { |
198 | PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder); | 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 | } catch (Exception e) { | 201 | } catch (Exception e) { |
202 | throw handleException(e); | 202 | throw handleException(e); |
203 | } | 203 | } |
204 | } | 204 | } |
205 | 205 | ||
206 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')") | 206 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')") |
207 | - @RequestMapping(value = "/firmware/{firmwareId}", method = RequestMethod.DELETE) | 207 | + @RequestMapping(value = "/otaPackage/{otaPackageId}", method = RequestMethod.DELETE) |
208 | @ResponseBody | 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 | try { | 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 | } catch (Exception e) { | 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 | throw handleException(e); | 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,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.service.firmware; | 16 | +package org.thingsboard.server.service.ota; |
17 | 17 | ||
18 | import com.google.common.util.concurrent.FutureCallback; | 18 | import com.google.common.util.concurrent.FutureCallback; |
19 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
@@ -23,12 +23,9 @@ import org.thingsboard.rule.engine.api.msg.DeviceAttributesEventNotificationMsg; | @@ -23,12 +23,9 @@ import org.thingsboard.rule.engine.api.msg.DeviceAttributesEventNotificationMsg; | ||
23 | import org.thingsboard.server.common.data.DataConstants; | 23 | import org.thingsboard.server.common.data.DataConstants; |
24 | import org.thingsboard.server.common.data.Device; | 24 | import org.thingsboard.server.common.data.Device; |
25 | import org.thingsboard.server.common.data.DeviceProfile; | 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 | import org.thingsboard.server.common.data.id.DeviceId; | 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 | import org.thingsboard.server.common.data.id.TenantId; | 29 | import org.thingsboard.server.common.data.id.TenantId; |
33 | import org.thingsboard.server.common.data.kv.AttributeKey; | 30 | import org.thingsboard.server.common.data.kv.AttributeKey; |
34 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; | 31 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
@@ -37,13 +34,16 @@ import org.thingsboard.server.common.data.kv.BasicTsKvEntry; | @@ -37,13 +34,16 @@ import org.thingsboard.server.common.data.kv.BasicTsKvEntry; | ||
37 | import org.thingsboard.server.common.data.kv.LongDataEntry; | 34 | import org.thingsboard.server.common.data.kv.LongDataEntry; |
38 | import org.thingsboard.server.common.data.kv.StringDataEntry; | 35 | import org.thingsboard.server.common.data.kv.StringDataEntry; |
39 | import org.thingsboard.server.common.data.kv.TsKvEntry; | 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 | import org.thingsboard.server.common.data.page.PageData; | 40 | import org.thingsboard.server.common.data.page.PageData; |
41 | import org.thingsboard.server.common.data.page.PageLink; | 41 | import org.thingsboard.server.common.data.page.PageLink; |
42 | import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; | 42 | import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; |
43 | import org.thingsboard.server.dao.device.DeviceProfileService; | 43 | import org.thingsboard.server.dao.device.DeviceProfileService; |
44 | import org.thingsboard.server.dao.device.DeviceService; | 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 | import org.thingsboard.server.queue.TbQueueProducer; | 47 | import org.thingsboard.server.queue.TbQueueProducer; |
48 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 48 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
49 | import org.thingsboard.server.queue.provider.TbCoreQueueFactory; | 49 | import org.thingsboard.server.queue.provider.TbCoreQueueFactory; |
@@ -58,44 +58,43 @@ import java.util.List; | @@ -58,44 +58,43 @@ import java.util.List; | ||
58 | import java.util.Set; | 58 | import java.util.Set; |
59 | import java.util.UUID; | 59 | import java.util.UUID; |
60 | import java.util.function.Consumer; | 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 | @Slf4j | 75 | @Slf4j |
77 | @Service | 76 | @Service |
78 | @TbCoreComponent | 77 | @TbCoreComponent |
79 | -public class DefaultFirmwareStateService implements FirmwareStateService { | 78 | +public class DefaultOtaPackageStateService implements OtaPackageStateService { |
80 | 79 | ||
81 | private final TbClusterService tbClusterService; | 80 | private final TbClusterService tbClusterService; |
82 | - private final FirmwareService firmwareService; | 81 | + private final OtaPackageService otaPackageService; |
83 | private final DeviceService deviceService; | 82 | private final DeviceService deviceService; |
84 | private final DeviceProfileService deviceProfileService; | 83 | private final DeviceProfileService deviceProfileService; |
85 | private final RuleEngineTelemetryService telemetryService; | 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 | this.tbClusterService = tbClusterService; | 92 | this.tbClusterService = tbClusterService; |
94 | - this.firmwareService = firmwareService; | 93 | + this.otaPackageService = otaPackageService; |
95 | this.deviceService = deviceService; | 94 | this.deviceService = deviceService; |
96 | this.deviceProfileService = deviceProfileService; | 95 | this.deviceProfileService = deviceProfileService; |
97 | this.telemetryService = telemetryService; | 96 | this.telemetryService = telemetryService; |
98 | - this.fwStateMsgProducer = coreQueueFactory.createToFirmwareStateServiceMsgProducer(); | 97 | + this.otaPackageStateMsgProducer = coreQueueFactory.createToOtaPackageStateServiceMsgProducer(); |
99 | } | 98 | } |
100 | 99 | ||
101 | @Override | 100 | @Override |
@@ -105,14 +104,14 @@ public class DefaultFirmwareStateService implements FirmwareStateService { | @@ -105,14 +104,14 @@ public class DefaultFirmwareStateService implements FirmwareStateService { | ||
105 | } | 104 | } |
106 | 105 | ||
107 | private void updateFirmware(Device device, Device oldDevice) { | 106 | private void updateFirmware(Device device, Device oldDevice) { |
108 | - FirmwareId newFirmwareId = device.getFirmwareId(); | 107 | + OtaPackageId newFirmwareId = device.getFirmwareId(); |
109 | if (newFirmwareId == null) { | 108 | if (newFirmwareId == null) { |
110 | DeviceProfile newDeviceProfile = deviceProfileService.findDeviceProfileById(device.getTenantId(), device.getDeviceProfileId()); | 109 | DeviceProfile newDeviceProfile = deviceProfileService.findDeviceProfileById(device.getTenantId(), device.getDeviceProfileId()); |
111 | newFirmwareId = newDeviceProfile.getFirmwareId(); | 110 | newFirmwareId = newDeviceProfile.getFirmwareId(); |
112 | } | 111 | } |
113 | if (oldDevice != null) { | 112 | if (oldDevice != null) { |
114 | if (newFirmwareId != null) { | 113 | if (newFirmwareId != null) { |
115 | - FirmwareId oldFirmwareId = oldDevice.getFirmwareId(); | 114 | + OtaPackageId oldFirmwareId = oldDevice.getFirmwareId(); |
116 | if (oldFirmwareId == null) { | 115 | if (oldFirmwareId == null) { |
117 | DeviceProfile oldDeviceProfile = deviceProfileService.findDeviceProfileById(oldDevice.getTenantId(), oldDevice.getDeviceProfileId()); | 116 | DeviceProfile oldDeviceProfile = deviceProfileService.findDeviceProfileById(oldDevice.getTenantId(), oldDevice.getDeviceProfileId()); |
118 | oldFirmwareId = oldDeviceProfile.getFirmwareId(); | 117 | oldFirmwareId = oldDeviceProfile.getFirmwareId(); |
@@ -132,14 +131,14 @@ public class DefaultFirmwareStateService implements FirmwareStateService { | @@ -132,14 +131,14 @@ public class DefaultFirmwareStateService implements FirmwareStateService { | ||
132 | } | 131 | } |
133 | 132 | ||
134 | private void updateSoftware(Device device, Device oldDevice) { | 133 | private void updateSoftware(Device device, Device oldDevice) { |
135 | - FirmwareId newSoftwareId = device.getSoftwareId(); | 134 | + OtaPackageId newSoftwareId = device.getSoftwareId(); |
136 | if (newSoftwareId == null) { | 135 | if (newSoftwareId == null) { |
137 | DeviceProfile newDeviceProfile = deviceProfileService.findDeviceProfileById(device.getTenantId(), device.getDeviceProfileId()); | 136 | DeviceProfile newDeviceProfile = deviceProfileService.findDeviceProfileById(device.getTenantId(), device.getDeviceProfileId()); |
138 | newSoftwareId = newDeviceProfile.getSoftwareId(); | 137 | newSoftwareId = newDeviceProfile.getSoftwareId(); |
139 | } | 138 | } |
140 | if (oldDevice != null) { | 139 | if (oldDevice != null) { |
141 | if (newSoftwareId != null) { | 140 | if (newSoftwareId != null) { |
142 | - FirmwareId oldSoftwareId = oldDevice.getSoftwareId(); | 141 | + OtaPackageId oldSoftwareId = oldDevice.getSoftwareId(); |
143 | if (oldSoftwareId == null) { | 142 | if (oldSoftwareId == null) { |
144 | DeviceProfile oldDeviceProfile = deviceProfileService.findDeviceProfileById(oldDevice.getTenantId(), oldDevice.getDeviceProfileId()); | 143 | DeviceProfile oldDeviceProfile = deviceProfileService.findDeviceProfileById(oldDevice.getTenantId(), oldDevice.getDeviceProfileId()); |
145 | oldSoftwareId = oldDeviceProfile.getSoftwareId(); | 144 | oldSoftwareId = oldDeviceProfile.getSoftwareId(); |
@@ -170,33 +169,20 @@ public class DefaultFirmwareStateService implements FirmwareStateService { | @@ -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 | Consumer<Device> updateConsumer; | 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 | if (deviceProfile.getFirmwareId() != null) { | 175 | if (deviceProfile.getFirmwareId() != null) { |
190 | long ts = System.currentTimeMillis(); | 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 | } else { | 178 | } else { |
193 | - updateConsumer = d -> remove(d, firmwareType); | 179 | + updateConsumer = d -> remove(d, otaPackageType); |
194 | } | 180 | } |
195 | 181 | ||
196 | PageLink pageLink = new PageLink(100); | 182 | PageLink pageLink = new PageLink(100); |
197 | PageData<Device> pageData; | 183 | PageData<Device> pageData; |
198 | do { | 184 | do { |
199 | - pageData = getDevicesFunction.apply(pageLink); | 185 | + pageData = deviceService.findDevicesByTenantIdAndTypeAndEmptyOtaPackage(tenantId, deviceProfile.getId(), otaPackageType, pageLink); |
200 | pageData.getData().forEach(updateConsumer); | 186 | pageData.getData().forEach(updateConsumer); |
201 | 187 | ||
202 | if (pageData.hasNext()) { | 188 | if (pageData.hasNext()) { |
@@ -206,60 +192,60 @@ public class DefaultFirmwareStateService implements FirmwareStateService { | @@ -206,60 +192,60 @@ public class DefaultFirmwareStateService implements FirmwareStateService { | ||
206 | } | 192 | } |
207 | 193 | ||
208 | @Override | 194 | @Override |
209 | - public boolean process(ToFirmwareStateServiceMsg msg) { | 195 | + public boolean process(ToOtaPackageStateServiceMsg msg) { |
210 | boolean isSuccess = false; | 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 | DeviceId deviceId = new DeviceId(new UUID(msg.getDeviceIdMSB(), msg.getDeviceIdLSB())); | 198 | DeviceId deviceId = new DeviceId(new UUID(msg.getDeviceIdMSB(), msg.getDeviceIdLSB())); |
213 | TenantId tenantId = new TenantId(new UUID(msg.getTenantIdMSB(), msg.getTenantIdLSB())); | 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 | long ts = msg.getTs(); | 201 | long ts = msg.getTs(); |
216 | 202 | ||
217 | Device device = deviceService.findDeviceById(tenantId, deviceId); | 203 | Device device = deviceService.findDeviceById(tenantId, deviceId); |
218 | if (device == null) { | 204 | if (device == null) { |
219 | log.warn("[{}] [{}] Device was removed during firmware update msg was queued!", tenantId, deviceId); | 205 | log.warn("[{}] [{}] Device was removed during firmware update msg was queued!", tenantId, deviceId); |
220 | } else { | 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 | DeviceProfile deviceProfile = deviceProfileService.findDeviceProfileById(tenantId, device.getDeviceProfileId()); | 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 | isSuccess = true; | 215 | isSuccess = true; |
230 | } else { | 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 | return isSuccess; | 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 | .setTenantIdMSB(tenantId.getId().getMostSignificantBits()) | 225 | .setTenantIdMSB(tenantId.getId().getMostSignificantBits()) |
240 | .setTenantIdLSB(tenantId.getId().getLeastSignificantBits()) | 226 | .setTenantIdLSB(tenantId.getId().getLeastSignificantBits()) |
241 | .setDeviceIdMSB(deviceId.getId().getMostSignificantBits()) | 227 | .setDeviceIdMSB(deviceId.getId().getMostSignificantBits()) |
242 | .setDeviceIdLSB(deviceId.getId().getLeastSignificantBits()) | 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 | .setType(firmwareType.name()) | 231 | .setType(firmwareType.name()) |
246 | .setTs(ts) | 232 | .setTs(ts) |
247 | .build(); | 233 | .build(); |
248 | 234 | ||
249 | - FirmwareInfo firmware = firmwareService.findFirmwareInfoById(tenantId, firmwareId); | 235 | + OtaPackageInfo firmware = otaPackageService.findOtaPackageInfoById(tenantId, firmwareId); |
250 | if (firmware == null) { | 236 | if (firmware == null) { |
251 | log.warn("[{}] Failed to send firmware update because firmware was already deleted", firmwareId); | 237 | log.warn("[{}] Failed to send firmware update because firmware was already deleted", firmwareId); |
252 | return; | 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 | List<TsKvEntry> telemetry = new ArrayList<>(); | 244 | List<TsKvEntry> telemetry = new ArrayList<>(); |
259 | telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(getTargetTelemetryKey(firmware.getType(), TITLE), firmware.getTitle()))); | 245 | telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(getTargetTelemetryKey(firmware.getType(), TITLE), firmware.getTitle()))); |
260 | telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(getTargetTelemetryKey(firmware.getType(), VERSION), firmware.getVersion()))); | 246 | telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(getTargetTelemetryKey(firmware.getType(), VERSION), firmware.getVersion()))); |
261 | telemetry.add(new BasicTsKvEntry(ts, new LongDataEntry(getTargetTelemetryKey(firmware.getType(), TS), ts))); | 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 | telemetryService.saveAndNotify(tenantId, deviceId, telemetry, new FutureCallback<>() { | 250 | telemetryService.saveAndNotify(tenantId, deviceId, telemetry, new FutureCallback<>() { |
265 | @Override | 251 | @Override |
@@ -275,11 +261,11 @@ public class DefaultFirmwareStateService implements FirmwareStateService { | @@ -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 | TenantId tenantId = device.getTenantId(); | 265 | TenantId tenantId = device.getTenantId(); |
280 | DeviceId deviceId = device.getId(); | 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 | telemetryService.saveAndNotify(tenantId, deviceId, Collections.singletonList(status), new FutureCallback<>() { | 270 | telemetryService.saveAndNotify(tenantId, deviceId, Collections.singletonList(status), new FutureCallback<>() { |
285 | @Override | 271 | @Override |
@@ -313,14 +299,14 @@ public class DefaultFirmwareStateService implements FirmwareStateService { | @@ -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 | new FutureCallback<>() { | 304 | new FutureCallback<>() { |
319 | @Override | 305 | @Override |
320 | public void onSuccess(@Nullable Void tmp) { | 306 | public void onSuccess(@Nullable Void tmp) { |
321 | log.trace("[{}] Success remove target firmware attributes!", device.getId()); | 307 | log.trace("[{}] Success remove target firmware attributes!", device.getId()); |
322 | Set<AttributeKey> keysToNotify = new HashSet<>(); | 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 | tbClusterService.pushMsgToCore(DeviceAttributesEventNotificationMsg.onDelete(device.getTenantId(), device.getId(), keysToNotify), null); | 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,18 +13,18 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.service.firmware; | 16 | +package org.thingsboard.server.service.ota; |
17 | 17 | ||
18 | import org.thingsboard.server.common.data.Device; | 18 | import org.thingsboard.server.common.data.Device; |
19 | import org.thingsboard.server.common.data.DeviceProfile; | 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 | void update(Device device, Device oldDevice); | 24 | void update(Device device, Device oldDevice); |
25 | 25 | ||
26 | void update(DeviceProfile deviceProfile, boolean isFirmwareChanged, boolean isSoftwareChanged); | 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,7 +50,7 @@ import org.thingsboard.server.gen.transport.TransportProtos.TbSubscriptionCloseP | ||
50 | import org.thingsboard.server.gen.transport.TransportProtos.TbTimeSeriesUpdateProto; | 50 | import org.thingsboard.server.gen.transport.TransportProtos.TbTimeSeriesUpdateProto; |
51 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; | 51 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
52 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; | 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 | import org.thingsboard.server.gen.transport.TransportProtos.ToUsageStatsServiceMsg; | 54 | import org.thingsboard.server.gen.transport.TransportProtos.ToUsageStatsServiceMsg; |
55 | import org.thingsboard.server.gen.transport.TransportProtos.TransportToDeviceActorMsg; | 55 | import org.thingsboard.server.gen.transport.TransportProtos.TransportToDeviceActorMsg; |
56 | import org.thingsboard.server.queue.TbQueueConsumer; | 56 | import org.thingsboard.server.queue.TbQueueConsumer; |
@@ -60,7 +60,7 @@ import org.thingsboard.server.queue.provider.TbCoreQueueFactory; | @@ -60,7 +60,7 @@ import org.thingsboard.server.queue.provider.TbCoreQueueFactory; | ||
60 | import org.thingsboard.server.queue.util.TbCoreComponent; | 60 | import org.thingsboard.server.queue.util.TbCoreComponent; |
61 | import org.thingsboard.server.service.apiusage.TbApiUsageStateService; | 61 | import org.thingsboard.server.service.apiusage.TbApiUsageStateService; |
62 | import org.thingsboard.server.service.edge.EdgeNotificationService; | 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 | import org.thingsboard.server.service.profile.TbDeviceProfileCache; | 64 | import org.thingsboard.server.service.profile.TbDeviceProfileCache; |
65 | import org.thingsboard.server.service.queue.processing.AbstractConsumerService; | 65 | import org.thingsboard.server.service.queue.processing.AbstractConsumerService; |
66 | import org.thingsboard.server.service.queue.processing.IdMsgPair; | 66 | import org.thingsboard.server.service.queue.processing.IdMsgPair; |
@@ -75,7 +75,6 @@ import org.thingsboard.server.service.transport.msg.TransportToDeviceActorMsgWra | @@ -75,7 +75,6 @@ import org.thingsboard.server.service.transport.msg.TransportToDeviceActorMsgWra | ||
75 | 75 | ||
76 | import javax.annotation.PostConstruct; | 76 | import javax.annotation.PostConstruct; |
77 | import javax.annotation.PreDestroy; | 77 | import javax.annotation.PreDestroy; |
78 | -import java.util.ArrayList; | ||
79 | import java.util.List; | 78 | import java.util.List; |
80 | import java.util.Optional; | 79 | import java.util.Optional; |
81 | import java.util.UUID; | 80 | import java.util.UUID; |
@@ -101,9 +100,9 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore | @@ -101,9 +100,9 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore | ||
101 | @Value("${queue.core.stats.enabled:false}") | 100 | @Value("${queue.core.stats.enabled:false}") |
102 | private boolean statsEnabled; | 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 | private long firmwarePackInterval; | 104 | private long firmwarePackInterval; |
106 | - @Value("${queue.core.firmware.pack-size:100}") | 105 | + @Value("${queue.core.ota.pack-size:100}") |
107 | private int firmwarePackSize; | 106 | private int firmwarePackSize; |
108 | 107 | ||
109 | private final TbQueueConsumer<TbProtoQueueMsg<ToCoreMsg>> mainConsumer; | 108 | private final TbQueueConsumer<TbProtoQueueMsg<ToCoreMsg>> mainConsumer; |
@@ -113,10 +112,10 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore | @@ -113,10 +112,10 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore | ||
113 | private final SubscriptionManagerService subscriptionManagerService; | 112 | private final SubscriptionManagerService subscriptionManagerService; |
114 | private final TbCoreDeviceRpcService tbCoreDeviceRpcService; | 113 | private final TbCoreDeviceRpcService tbCoreDeviceRpcService; |
115 | private final EdgeNotificationService edgeNotificationService; | 114 | private final EdgeNotificationService edgeNotificationService; |
116 | - private final FirmwareStateService firmwareStateService; | 115 | + private final OtaPackageStateService firmwareStateService; |
117 | private final TbCoreConsumerStats stats; | 116 | private final TbCoreConsumerStats stats; |
118 | protected final TbQueueConsumer<TbProtoQueueMsg<ToUsageStatsServiceMsg>> usageStatsConsumer; | 117 | protected final TbQueueConsumer<TbProtoQueueMsg<ToUsageStatsServiceMsg>> usageStatsConsumer; |
119 | - private final TbQueueConsumer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> firmwareStatesConsumer; | 118 | + private final TbQueueConsumer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> firmwareStatesConsumer; |
120 | 119 | ||
121 | protected volatile ExecutorService usageStatsExecutor; | 120 | protected volatile ExecutorService usageStatsExecutor; |
122 | 121 | ||
@@ -135,11 +134,11 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore | @@ -135,11 +134,11 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore | ||
135 | TbTenantProfileCache tenantProfileCache, | 134 | TbTenantProfileCache tenantProfileCache, |
136 | TbApiUsageStateService apiUsageStateService, | 135 | TbApiUsageStateService apiUsageStateService, |
137 | EdgeNotificationService edgeNotificationService, | 136 | EdgeNotificationService edgeNotificationService, |
138 | - FirmwareStateService firmwareStateService) { | 137 | + OtaPackageStateService firmwareStateService) { |
139 | super(actorContext, encodingService, tenantProfileCache, deviceProfileCache, apiUsageStateService, tbCoreQueueFactory.createToCoreNotificationsMsgConsumer()); | 138 | super(actorContext, encodingService, tenantProfileCache, deviceProfileCache, apiUsageStateService, tbCoreQueueFactory.createToCoreNotificationsMsgConsumer()); |
140 | this.mainConsumer = tbCoreQueueFactory.createToCoreMsgConsumer(); | 139 | this.mainConsumer = tbCoreQueueFactory.createToCoreMsgConsumer(); |
141 | this.usageStatsConsumer = tbCoreQueueFactory.createToUsageStatsServiceMsgConsumer(); | 140 | this.usageStatsConsumer = tbCoreQueueFactory.createToUsageStatsServiceMsgConsumer(); |
142 | - this.firmwareStatesConsumer = tbCoreQueueFactory.createToFirmwareStateServiceMsgConsumer(); | 141 | + this.firmwareStatesConsumer = tbCoreQueueFactory.createToOtaPackageStateServiceMsgConsumer(); |
143 | this.stateService = stateService; | 142 | this.stateService = stateService; |
144 | this.localSubscriptionService = localSubscriptionService; | 143 | this.localSubscriptionService = localSubscriptionService; |
145 | this.subscriptionManagerService = subscriptionManagerService; | 144 | this.subscriptionManagerService = subscriptionManagerService; |
@@ -173,7 +172,7 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore | @@ -173,7 +172,7 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore | ||
173 | public void onApplicationEvent(ApplicationReadyEvent event) { | 172 | public void onApplicationEvent(ApplicationReadyEvent event) { |
174 | super.onApplicationEvent(event); | 173 | super.onApplicationEvent(event); |
175 | launchUsageStatsConsumer(); | 174 | launchUsageStatsConsumer(); |
176 | - launchFirmwareUpdateNotificationConsumer(); | 175 | + launchOtaPackageUpdateNotificationConsumer(); |
177 | } | 176 | } |
178 | 177 | ||
179 | @Override | 178 | @Override |
@@ -361,20 +360,20 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore | @@ -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 | long maxProcessingTimeoutPerRecord = firmwarePackInterval / firmwarePackSize; | 364 | long maxProcessingTimeoutPerRecord = firmwarePackInterval / firmwarePackSize; |
366 | firmwareStatesExecutor.submit(() -> { | 365 | firmwareStatesExecutor.submit(() -> { |
367 | while (!stopped) { | 366 | while (!stopped) { |
368 | try { | 367 | try { |
369 | - List<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> msgs = firmwareStatesConsumer.poll(getNotificationPollDuration()); | 368 | + List<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> msgs = firmwareStatesConsumer.poll(getNotificationPollDuration()); |
370 | if (msgs.isEmpty()) { | 369 | if (msgs.isEmpty()) { |
371 | continue; | 370 | continue; |
372 | } | 371 | } |
373 | long timeToSleep = maxProcessingTimeoutPerRecord; | 372 | long timeToSleep = maxProcessingTimeoutPerRecord; |
374 | - for (TbProtoQueueMsg<ToFirmwareStateServiceMsg> msg : msgs) { | 373 | + for (TbProtoQueueMsg<ToOtaPackageStateServiceMsg> msg : msgs) { |
375 | try { | 374 | try { |
376 | long startTime = System.currentTimeMillis(); | 375 | long startTime = System.currentTimeMillis(); |
377 | - boolean isSuccessUpdate = handleFirmwareUpdates(msg); | 376 | + boolean isSuccessUpdate = handleOtaPackageUpdates(msg); |
378 | long endTime = System.currentTimeMillis(); | 377 | long endTime = System.currentTimeMillis(); |
379 | long spentTime = endTime - startTime; | 378 | long spentTime = endTime - startTime; |
380 | timeToSleep = timeToSleep - spentTime; | 379 | timeToSleep = timeToSleep - spentTime; |
@@ -402,7 +401,7 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore | @@ -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,7 +409,7 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore | ||
410 | statsService.process(msg, callback); | 409 | statsService.process(msg, callback); |
411 | } | 410 | } |
412 | 411 | ||
413 | - private boolean handleFirmwareUpdates(TbProtoQueueMsg<ToFirmwareStateServiceMsg> msg) { | 412 | + private boolean handleOtaPackageUpdates(TbProtoQueueMsg<ToOtaPackageStateServiceMsg> msg) { |
414 | return firmwareStateService.process(msg.getValue()); | 413 | return firmwareStateService.process(msg.getValue()); |
415 | } | 414 | } |
416 | 415 |
@@ -30,7 +30,7 @@ import org.thingsboard.server.common.data.Customer; | @@ -30,7 +30,7 @@ import org.thingsboard.server.common.data.Customer; | ||
30 | import org.thingsboard.server.common.data.Device; | 30 | import org.thingsboard.server.common.data.Device; |
31 | import org.thingsboard.server.common.data.DeviceProfile; | 31 | import org.thingsboard.server.common.data.DeviceProfile; |
32 | import org.thingsboard.server.common.data.EntityView; | 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 | import org.thingsboard.server.common.data.TbResourceInfo; | 34 | import org.thingsboard.server.common.data.TbResourceInfo; |
35 | import org.thingsboard.server.common.data.Tenant; | 35 | import org.thingsboard.server.common.data.Tenant; |
36 | import org.thingsboard.server.common.data.User; | 36 | import org.thingsboard.server.common.data.User; |
@@ -46,7 +46,7 @@ import org.thingsboard.server.common.data.id.EdgeId; | @@ -46,7 +46,7 @@ import org.thingsboard.server.common.data.id.EdgeId; | ||
46 | import org.thingsboard.server.common.data.id.EntityId; | 46 | import org.thingsboard.server.common.data.id.EntityId; |
47 | import org.thingsboard.server.common.data.id.EntityIdFactory; | 47 | import org.thingsboard.server.common.data.id.EntityIdFactory; |
48 | import org.thingsboard.server.common.data.id.EntityViewId; | 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 | import org.thingsboard.server.common.data.id.RuleChainId; | 50 | import org.thingsboard.server.common.data.id.RuleChainId; |
51 | import org.thingsboard.server.common.data.id.RuleNodeId; | 51 | import org.thingsboard.server.common.data.id.RuleNodeId; |
52 | import org.thingsboard.server.common.data.id.TbResourceId; | 52 | import org.thingsboard.server.common.data.id.TbResourceId; |
@@ -63,7 +63,7 @@ import org.thingsboard.server.dao.device.DeviceService; | @@ -63,7 +63,7 @@ import org.thingsboard.server.dao.device.DeviceService; | ||
63 | import org.thingsboard.server.dao.edge.EdgeService; | 63 | import org.thingsboard.server.dao.edge.EdgeService; |
64 | import org.thingsboard.server.dao.entityview.EntityViewService; | 64 | import org.thingsboard.server.dao.entityview.EntityViewService; |
65 | import org.thingsboard.server.dao.exception.IncorrectParameterException; | 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 | import org.thingsboard.server.dao.resource.ResourceService; | 67 | import org.thingsboard.server.dao.resource.ResourceService; |
68 | import org.thingsboard.server.dao.rule.RuleChainService; | 68 | import org.thingsboard.server.dao.rule.RuleChainService; |
69 | import org.thingsboard.server.dao.tenant.TenantService; | 69 | import org.thingsboard.server.dao.tenant.TenantService; |
@@ -135,7 +135,7 @@ public class AccessValidator { | @@ -135,7 +135,7 @@ public class AccessValidator { | ||
135 | protected ResourceService resourceService; | 135 | protected ResourceService resourceService; |
136 | 136 | ||
137 | @Autowired | 137 | @Autowired |
138 | - protected FirmwareService firmwareService; | 138 | + protected OtaPackageService otaPackageService; |
139 | 139 | ||
140 | private ExecutorService executor; | 140 | private ExecutorService executor; |
141 | 141 | ||
@@ -232,8 +232,8 @@ public class AccessValidator { | @@ -232,8 +232,8 @@ public class AccessValidator { | ||
232 | case TB_RESOURCE: | 232 | case TB_RESOURCE: |
233 | validateResource(currentUser, operation, entityId, callback); | 233 | validateResource(currentUser, operation, entityId, callback); |
234 | return; | 234 | return; |
235 | - case FIRMWARE: | ||
236 | - validateFirmware(currentUser, operation, entityId, callback); | 235 | + case OTA_PACKAGE: |
236 | + validateOtaPackage(currentUser, operation, entityId, callback); | ||
237 | return; | 237 | return; |
238 | default: | 238 | default: |
239 | //TODO: add support of other entities | 239 | //TODO: add support of other entities |
@@ -300,20 +300,20 @@ public class AccessValidator { | @@ -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 | if (currentUser.isSystemAdmin()) { | 304 | if (currentUser.isSystemAdmin()) { |
305 | callback.onSuccess(ValidationResult.accessDenied(SYSTEM_ADMINISTRATOR_IS_NOT_ALLOWED_TO_PERFORM_THIS_OPERATION)); | 305 | callback.onSuccess(ValidationResult.accessDenied(SYSTEM_ADMINISTRATOR_IS_NOT_ALLOWED_TO_PERFORM_THIS_OPERATION)); |
306 | } else { | 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 | } else { | 310 | } else { |
311 | try { | 311 | try { |
312 | - accessControlService.checkPermission(currentUser, Resource.FIRMWARE, operation, entityId, firmware); | 312 | + accessControlService.checkPermission(currentUser, Resource.OTA_PACKAGE, operation, entityId, otaPackage); |
313 | } catch (ThingsboardException e) { | 313 | } catch (ThingsboardException e) { |
314 | callback.onSuccess(ValidationResult.accessDenied(e.getMessage())); | 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,7 +38,7 @@ public enum Resource { | ||
38 | DEVICE_PROFILE(EntityType.DEVICE_PROFILE), | 38 | DEVICE_PROFILE(EntityType.DEVICE_PROFILE), |
39 | API_USAGE_STATE(EntityType.API_USAGE_STATE), | 39 | API_USAGE_STATE(EntityType.API_USAGE_STATE), |
40 | TB_RESOURCE(EntityType.TB_RESOURCE), | 40 | TB_RESOURCE(EntityType.TB_RESOURCE), |
41 | - FIRMWARE(EntityType.FIRMWARE), | 41 | + OTA_PACKAGE(EntityType.OTA_PACKAGE), |
42 | EDGE(EntityType.EDGE); | 42 | EDGE(EntityType.EDGE); |
43 | 43 | ||
44 | private final EntityType entityType; | 44 | private final EntityType entityType; |
@@ -42,7 +42,7 @@ public class TenantAdminPermissions extends AbstractPermissions { | @@ -42,7 +42,7 @@ public class TenantAdminPermissions extends AbstractPermissions { | ||
42 | put(Resource.DEVICE_PROFILE, tenantEntityPermissionChecker); | 42 | put(Resource.DEVICE_PROFILE, tenantEntityPermissionChecker); |
43 | put(Resource.API_USAGE_STATE, tenantEntityPermissionChecker); | 43 | put(Resource.API_USAGE_STATE, tenantEntityPermissionChecker); |
44 | put(Resource.TB_RESOURCE, tbResourcePermissionChecker); | 44 | put(Resource.TB_RESOURCE, tbResourcePermissionChecker); |
45 | - put(Resource.FIRMWARE, tenantEntityPermissionChecker); | 45 | + put(Resource.OTA_PACKAGE, tenantEntityPermissionChecker); |
46 | put(Resource.EDGE, tenantEntityPermissionChecker); | 46 | put(Resource.EDGE, tenantEntityPermissionChecker); |
47 | } | 47 | } |
48 | 48 |
@@ -26,27 +26,27 @@ import lombok.extern.slf4j.Slf4j; | @@ -26,27 +26,27 @@ import lombok.extern.slf4j.Slf4j; | ||
26 | import org.springframework.stereotype.Service; | 26 | import org.springframework.stereotype.Service; |
27 | import org.springframework.util.StringUtils; | 27 | import org.springframework.util.StringUtils; |
28 | import org.thingsboard.common.util.JacksonUtil; | 28 | import org.thingsboard.common.util.JacksonUtil; |
29 | -import org.thingsboard.server.cache.firmware.FirmwareDataCache; | 29 | +import org.thingsboard.server.cache.ota.OtaPackageDataCache; |
30 | import org.thingsboard.server.common.data.ApiUsageState; | 30 | import org.thingsboard.server.common.data.ApiUsageState; |
31 | import org.thingsboard.server.common.data.DataConstants; | 31 | import org.thingsboard.server.common.data.DataConstants; |
32 | import org.thingsboard.server.common.data.Device; | 32 | import org.thingsboard.server.common.data.Device; |
33 | import org.thingsboard.server.common.data.DeviceProfile; | 33 | import org.thingsboard.server.common.data.DeviceProfile; |
34 | import org.thingsboard.server.common.data.DeviceTransportType; | 34 | import org.thingsboard.server.common.data.DeviceTransportType; |
35 | import org.thingsboard.server.common.data.EntityType; | 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 | import org.thingsboard.server.common.data.ResourceType; | 38 | import org.thingsboard.server.common.data.ResourceType; |
39 | import org.thingsboard.server.common.data.TbResource; | 39 | import org.thingsboard.server.common.data.TbResource; |
40 | import org.thingsboard.server.common.data.TenantProfile; | 40 | import org.thingsboard.server.common.data.TenantProfile; |
41 | import org.thingsboard.server.common.data.device.credentials.BasicMqttCredentials; | 41 | import org.thingsboard.server.common.data.device.credentials.BasicMqttCredentials; |
42 | import org.thingsboard.server.common.data.device.credentials.ProvisionDeviceCredentialsData; | 42 | import org.thingsboard.server.common.data.device.credentials.ProvisionDeviceCredentialsData; |
43 | import org.thingsboard.server.common.data.device.profile.ProvisionDeviceProfileCredentials; | 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 | import org.thingsboard.server.common.data.id.CustomerId; | 46 | import org.thingsboard.server.common.data.id.CustomerId; |
47 | import org.thingsboard.server.common.data.id.DeviceId; | 47 | import org.thingsboard.server.common.data.id.DeviceId; |
48 | import org.thingsboard.server.common.data.id.DeviceProfileId; | 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 | import org.thingsboard.server.common.data.id.TenantId; | 50 | import org.thingsboard.server.common.data.id.TenantId; |
51 | import org.thingsboard.server.common.data.page.PageData; | 51 | import org.thingsboard.server.common.data.page.PageData; |
52 | import org.thingsboard.server.common.data.page.PageLink; | 52 | import org.thingsboard.server.common.data.page.PageLink; |
@@ -64,7 +64,7 @@ import org.thingsboard.server.dao.device.DeviceService; | @@ -64,7 +64,7 @@ import org.thingsboard.server.dao.device.DeviceService; | ||
64 | import org.thingsboard.server.dao.device.provision.ProvisionFailedException; | 64 | import org.thingsboard.server.dao.device.provision.ProvisionFailedException; |
65 | import org.thingsboard.server.dao.device.provision.ProvisionRequest; | 65 | import org.thingsboard.server.dao.device.provision.ProvisionRequest; |
66 | import org.thingsboard.server.dao.device.provision.ProvisionResponse; | 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 | import org.thingsboard.server.dao.relation.RelationService; | 68 | import org.thingsboard.server.dao.relation.RelationService; |
69 | import org.thingsboard.server.dao.tenant.TbTenantProfileCache; | 69 | import org.thingsboard.server.dao.tenant.TbTenantProfileCache; |
70 | import org.thingsboard.server.gen.transport.TransportProtos; | 70 | import org.thingsboard.server.gen.transport.TransportProtos; |
@@ -124,8 +124,8 @@ public class DefaultTransportApiService implements TransportApiService { | @@ -124,8 +124,8 @@ public class DefaultTransportApiService implements TransportApiService { | ||
124 | private final DataDecodingEncodingService dataDecodingEncodingService; | 124 | private final DataDecodingEncodingService dataDecodingEncodingService; |
125 | private final DeviceProvisionService deviceProvisionService; | 125 | private final DeviceProvisionService deviceProvisionService; |
126 | private final TbResourceService resourceService; | 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 | private final ConcurrentMap<String, ReentrantLock> deviceCreationLocks = new ConcurrentHashMap<>(); | 130 | private final ConcurrentMap<String, ReentrantLock> deviceCreationLocks = new ConcurrentHashMap<>(); |
131 | 131 | ||
@@ -134,7 +134,7 @@ public class DefaultTransportApiService implements TransportApiService { | @@ -134,7 +134,7 @@ public class DefaultTransportApiService implements TransportApiService { | ||
134 | RelationService relationService, DeviceCredentialsService deviceCredentialsService, | 134 | RelationService relationService, DeviceCredentialsService deviceCredentialsService, |
135 | DeviceStateService deviceStateService, DbCallbackExecutorService dbCallbackExecutorService, | 135 | DeviceStateService deviceStateService, DbCallbackExecutorService dbCallbackExecutorService, |
136 | TbClusterService tbClusterService, DataDecodingEncodingService dataDecodingEncodingService, | 136 | TbClusterService tbClusterService, DataDecodingEncodingService dataDecodingEncodingService, |
137 | - DeviceProvisionService deviceProvisionService, TbResourceService resourceService, FirmwareService firmwareService, FirmwareDataCache firmwareDataCache) { | 137 | + DeviceProvisionService deviceProvisionService, TbResourceService resourceService, OtaPackageService otaPackageService, OtaPackageDataCache otaPackageDataCache) { |
138 | this.deviceProfileCache = deviceProfileCache; | 138 | this.deviceProfileCache = deviceProfileCache; |
139 | this.tenantProfileCache = tenantProfileCache; | 139 | this.tenantProfileCache = tenantProfileCache; |
140 | this.apiUsageStateService = apiUsageStateService; | 140 | this.apiUsageStateService = apiUsageStateService; |
@@ -147,8 +147,8 @@ public class DefaultTransportApiService implements TransportApiService { | @@ -147,8 +147,8 @@ public class DefaultTransportApiService implements TransportApiService { | ||
147 | this.dataDecodingEncodingService = dataDecodingEncodingService; | 147 | this.dataDecodingEncodingService = dataDecodingEncodingService; |
148 | this.deviceProvisionService = deviceProvisionService; | 148 | this.deviceProvisionService = deviceProvisionService; |
149 | this.resourceService = resourceService; | 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 | @Override | 154 | @Override |
@@ -184,8 +184,8 @@ public class DefaultTransportApiService implements TransportApiService { | @@ -184,8 +184,8 @@ public class DefaultTransportApiService implements TransportApiService { | ||
184 | result = handle(transportApiRequestMsg.getDeviceRequestMsg()); | 184 | result = handle(transportApiRequestMsg.getDeviceRequestMsg()); |
185 | } else if (transportApiRequestMsg.hasDeviceCredentialsRequestMsg()) { | 185 | } else if (transportApiRequestMsg.hasDeviceCredentialsRequestMsg()) { |
186 | result = handle(transportApiRequestMsg.getDeviceCredentialsRequestMsg()); | 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 | return Futures.transform(Optional.ofNullable(result).orElseGet(this::getEmptyTransportApiResponseFuture), | 191 | return Futures.transform(Optional.ofNullable(result).orElseGet(this::getEmptyTransportApiResponseFuture), |
@@ -511,50 +511,50 @@ public class DefaultTransportApiService implements TransportApiService { | @@ -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 | TenantId tenantId = new TenantId(new UUID(requestMsg.getTenantIdMSB(), requestMsg.getTenantIdLSB())); | 515 | TenantId tenantId = new TenantId(new UUID(requestMsg.getTenantIdMSB(), requestMsg.getTenantIdLSB())); |
516 | DeviceId deviceId = new DeviceId(new UUID(requestMsg.getDeviceIdMSB(), requestMsg.getDeviceIdLSB())); | 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 | Device device = deviceService.findDeviceById(tenantId, deviceId); | 518 | Device device = deviceService.findDeviceById(tenantId, deviceId); |
519 | 519 | ||
520 | if (device == null) { | 520 | if (device == null) { |
521 | return getEmptyTransportApiResponseFuture(); | 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 | DeviceProfile deviceProfile = deviceProfileCache.find(device.getDeviceProfileId()); | 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 | builder.setResponseStatus(TransportProtos.ResponseStatus.NOT_FOUND); | 533 | builder.setResponseStatus(TransportProtos.ResponseStatus.NOT_FOUND); |
534 | } else { | 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 | builder.setResponseStatus(TransportProtos.ResponseStatus.NOT_FOUND); | 538 | builder.setResponseStatus(TransportProtos.ResponseStatus.NOT_FOUND); |
539 | } else { | 539 | } else { |
540 | builder.setResponseStatus(TransportProtos.ResponseStatus.SUCCESS); | 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 | return Futures.immediateFuture( | 555 | return Futures.immediateFuture( |
556 | TransportApiResponseMsg.newBuilder() | 556 | TransportApiResponseMsg.newBuilder() |
557 | - .setFirmwareResponseMsg(builder.build()) | 557 | + .setOtaPackageResponseMsg(builder.build()) |
558 | .build()); | 558 | .build()); |
559 | } | 559 | } |
560 | 560 |
@@ -371,7 +371,10 @@ caffeine: | @@ -371,7 +371,10 @@ caffeine: | ||
371 | tokensOutdatageTime: | 371 | tokensOutdatageTime: |
372 | timeToLiveInMinutes: 20000 | 372 | timeToLiveInMinutes: 20000 |
373 | maxSize: 10000 | 373 | maxSize: 10000 |
374 | - firmwares: | 374 | + otaPackages: |
375 | + timeToLiveInMinutes: 60 | ||
376 | + maxSize: 10 | ||
377 | + otaPackagesData: | ||
375 | timeToLiveInMinutes: 60 | 378 | timeToLiveInMinutes: 60 |
376 | maxSize: 10 | 379 | maxSize: 10 |
377 | edges: | 380 | edges: |
@@ -497,7 +500,7 @@ audit-log: | @@ -497,7 +500,7 @@ audit-log: | ||
497 | "device_profile": "${AUDIT_LOG_MASK_DEVICE_PROFILE:W}" | 500 | "device_profile": "${AUDIT_LOG_MASK_DEVICE_PROFILE:W}" |
498 | "edge": "${AUDIT_LOG_MASK_EDGE:W}" | 501 | "edge": "${AUDIT_LOG_MASK_EDGE:W}" |
499 | "tb_resource": "${AUDIT_LOG_MASK_RESOURCE:W}" | 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 | sink: | 504 | sink: |
502 | # Type of external sink. possible options: none, elasticsearch | 505 | # Type of external sink. possible options: none, elasticsearch |
503 | type: "${AUDIT_LOG_SINK_TYPE:none}" | 506 | type: "${AUDIT_LOG_SINK_TYPE:none}" |
@@ -749,7 +752,7 @@ queue: | @@ -749,7 +752,7 @@ queue: | ||
749 | 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\";}" | 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 | security.protocol: "${TB_QUEUE_KAFKA_CONFLUENT_SECURITY_PROTOCOL:SASL_SSL}" | 753 | security.protocol: "${TB_QUEUE_KAFKA_CONFLUENT_SECURITY_PROTOCOL:SASL_SSL}" |
751 | consumer-properties-per-topic: | 754 | consumer-properties-per-topic: |
752 | - tb_firmware: | 755 | + tb_ota_package: |
753 | - key: max.poll.records | 756 | - key: max.poll.records |
754 | value: 10 | 757 | value: 10 |
755 | other: | 758 | other: |
@@ -759,7 +762,7 @@ queue: | @@ -759,7 +762,7 @@ queue: | ||
759 | transport-api: "${TB_QUEUE_KAFKA_TA_TOPIC_PROPERTIES:retention.ms:604800000;segment.bytes:26214400;retention.bytes:1048576000;partitions:1;min.insync.replicas:1}" | 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 | notifications: "${TB_QUEUE_KAFKA_NOTIFICATIONS_TOPIC_PROPERTIES:retention.ms:604800000;segment.bytes:26214400;retention.bytes:1048576000;partitions:1;min.insync.replicas:1}" | 763 | notifications: "${TB_QUEUE_KAFKA_NOTIFICATIONS_TOPIC_PROPERTIES:retention.ms:604800000;segment.bytes:26214400;retention.bytes:1048576000;partitions:1;min.insync.replicas:1}" |
761 | js-executor: "${TB_QUEUE_KAFKA_JE_TOPIC_PROPERTIES:retention.ms:604800000;segment.bytes:26214400;retention.bytes:104857600;partitions:100;min.insync.replicas:1}" | 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 | consumer-stats: | 766 | consumer-stats: |
764 | enabled: "${TB_QUEUE_KAFKA_CONSUMER_STATS_ENABLED:true}" | 767 | enabled: "${TB_QUEUE_KAFKA_CONSUMER_STATS_ENABLED:true}" |
765 | print-interval-ms: "${TB_QUEUE_KAFKA_CONSUMER_STATS_MIN_PRINT_INTERVAL_MS:60000}" | 768 | print-interval-ms: "${TB_QUEUE_KAFKA_CONSUMER_STATS_MIN_PRINT_INTERVAL_MS:60000}" |
@@ -830,10 +833,10 @@ queue: | @@ -830,10 +833,10 @@ queue: | ||
830 | poll-interval: "${TB_QUEUE_CORE_POLL_INTERVAL_MS:25}" | 833 | poll-interval: "${TB_QUEUE_CORE_POLL_INTERVAL_MS:25}" |
831 | partitions: "${TB_QUEUE_CORE_PARTITIONS:10}" | 834 | partitions: "${TB_QUEUE_CORE_PARTITIONS:10}" |
832 | pack-processing-timeout: "${TB_QUEUE_CORE_PACK_PROCESSING_TIMEOUT_MS:2000}" | 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 | usage-stats-topic: "${TB_QUEUE_US_TOPIC:tb_usage_stats}" | 840 | usage-stats-topic: "${TB_QUEUE_US_TOPIC:tb_usage_stats}" |
838 | stats: | 841 | stats: |
839 | enabled: "${TB_QUEUE_CORE_STATS_ENABLED:true}" | 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,11 +25,10 @@ import org.springframework.test.web.servlet.request.MockMultipartHttpServletRequ | ||
25 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | 25 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; |
26 | import org.thingsboard.common.util.JacksonUtil; | 26 | import org.thingsboard.common.util.JacksonUtil; |
27 | import org.thingsboard.server.common.data.DeviceProfile; | 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 | import org.thingsboard.server.common.data.Tenant; | 30 | import org.thingsboard.server.common.data.Tenant; |
31 | import org.thingsboard.server.common.data.User; | 31 | import org.thingsboard.server.common.data.User; |
32 | -import org.thingsboard.server.common.data.firmware.FirmwareType; | ||
33 | import org.thingsboard.server.common.data.id.DeviceProfileId; | 32 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
34 | import org.thingsboard.server.common.data.page.PageData; | 33 | import org.thingsboard.server.common.data.page.PageData; |
35 | import org.thingsboard.server.common.data.page.PageLink; | 34 | import org.thingsboard.server.common.data.page.PageLink; |
@@ -41,11 +40,11 @@ import java.util.Collections; | @@ -41,11 +40,11 @@ import java.util.Collections; | ||
41 | import java.util.List; | 40 | import java.util.List; |
42 | 41 | ||
43 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | 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 | public static final String TITLE = "My firmware"; | 49 | public static final String TITLE = "My firmware"; |
51 | private static final String FILE_NAME = "filename.txt"; | 50 | private static final String FILE_NAME = "filename.txt"; |
@@ -93,13 +92,13 @@ public abstract class BaseFirmwareControllerTest extends AbstractControllerTest | @@ -93,13 +92,13 @@ public abstract class BaseFirmwareControllerTest extends AbstractControllerTest | ||
93 | 92 | ||
94 | @Test | 93 | @Test |
95 | public void testSaveFirmware() throws Exception { | 94 | public void testSaveFirmware() throws Exception { |
96 | - FirmwareInfo firmwareInfo = new FirmwareInfo(); | 95 | + OtaPackageInfo firmwareInfo = new OtaPackageInfo(); |
97 | firmwareInfo.setDeviceProfileId(deviceProfileId); | 96 | firmwareInfo.setDeviceProfileId(deviceProfileId); |
98 | firmwareInfo.setType(FIRMWARE); | 97 | firmwareInfo.setType(FIRMWARE); |
99 | firmwareInfo.setTitle(TITLE); | 98 | firmwareInfo.setTitle(TITLE); |
100 | firmwareInfo.setVersion(VERSION); | 99 | firmwareInfo.setVersion(VERSION); |
101 | 100 | ||
102 | - FirmwareInfo savedFirmwareInfo = save(firmwareInfo); | 101 | + OtaPackageInfo savedFirmwareInfo = save(firmwareInfo); |
103 | 102 | ||
104 | Assert.assertNotNull(savedFirmwareInfo); | 103 | Assert.assertNotNull(savedFirmwareInfo); |
105 | Assert.assertNotNull(savedFirmwareInfo.getId()); | 104 | Assert.assertNotNull(savedFirmwareInfo.getId()); |
@@ -112,19 +111,19 @@ public abstract class BaseFirmwareControllerTest extends AbstractControllerTest | @@ -112,19 +111,19 @@ public abstract class BaseFirmwareControllerTest extends AbstractControllerTest | ||
112 | 111 | ||
113 | save(savedFirmwareInfo); | 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 | Assert.assertEquals(foundFirmwareInfo.getTitle(), savedFirmwareInfo.getTitle()); | 115 | Assert.assertEquals(foundFirmwareInfo.getTitle(), savedFirmwareInfo.getTitle()); |
117 | } | 116 | } |
118 | 117 | ||
119 | @Test | 118 | @Test |
120 | public void testSaveFirmwareData() throws Exception { | 119 | public void testSaveFirmwareData() throws Exception { |
121 | - FirmwareInfo firmwareInfo = new FirmwareInfo(); | 120 | + OtaPackageInfo firmwareInfo = new OtaPackageInfo(); |
122 | firmwareInfo.setDeviceProfileId(deviceProfileId); | 121 | firmwareInfo.setDeviceProfileId(deviceProfileId); |
123 | firmwareInfo.setType(FIRMWARE); | 122 | firmwareInfo.setType(FIRMWARE); |
124 | firmwareInfo.setTitle(TITLE); | 123 | firmwareInfo.setTitle(TITLE); |
125 | firmwareInfo.setVersion(VERSION); | 124 | firmwareInfo.setVersion(VERSION); |
126 | 125 | ||
127 | - FirmwareInfo savedFirmwareInfo = save(firmwareInfo); | 126 | + OtaPackageInfo savedFirmwareInfo = save(firmwareInfo); |
128 | 127 | ||
129 | Assert.assertNotNull(savedFirmwareInfo); | 128 | Assert.assertNotNull(savedFirmwareInfo); |
130 | Assert.assertNotNull(savedFirmwareInfo.getId()); | 129 | Assert.assertNotNull(savedFirmwareInfo.getId()); |
@@ -137,12 +136,12 @@ public abstract class BaseFirmwareControllerTest extends AbstractControllerTest | @@ -137,12 +136,12 @@ public abstract class BaseFirmwareControllerTest extends AbstractControllerTest | ||
137 | 136 | ||
138 | save(savedFirmwareInfo); | 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 | Assert.assertEquals(foundFirmwareInfo.getTitle(), savedFirmwareInfo.getTitle()); | 140 | Assert.assertEquals(foundFirmwareInfo.getTitle(), savedFirmwareInfo.getTitle()); |
142 | 141 | ||
143 | MockMultipartFile testData = new MockMultipartFile("file", FILE_NAME, CONTENT_TYPE, DATA.array()); | 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 | Assert.assertEquals(FILE_NAME, savedFirmware.getFileName()); | 146 | Assert.assertEquals(FILE_NAME, savedFirmware.getFileName()); |
148 | Assert.assertEquals(CONTENT_TYPE, savedFirmware.getContentType()); | 147 | Assert.assertEquals(CONTENT_TYPE, savedFirmware.getContentType()); |
@@ -150,97 +149,97 @@ public abstract class BaseFirmwareControllerTest extends AbstractControllerTest | @@ -150,97 +149,97 @@ public abstract class BaseFirmwareControllerTest extends AbstractControllerTest | ||
150 | 149 | ||
151 | @Test | 150 | @Test |
152 | public void testUpdateFirmwareFromDifferentTenant() throws Exception { | 151 | public void testUpdateFirmwareFromDifferentTenant() throws Exception { |
153 | - FirmwareInfo firmwareInfo = new FirmwareInfo(); | 152 | + OtaPackageInfo firmwareInfo = new OtaPackageInfo(); |
154 | firmwareInfo.setDeviceProfileId(deviceProfileId); | 153 | firmwareInfo.setDeviceProfileId(deviceProfileId); |
155 | firmwareInfo.setType(FIRMWARE); | 154 | firmwareInfo.setType(FIRMWARE); |
156 | firmwareInfo.setTitle(TITLE); | 155 | firmwareInfo.setTitle(TITLE); |
157 | firmwareInfo.setVersion(VERSION); | 156 | firmwareInfo.setVersion(VERSION); |
158 | 157 | ||
159 | - FirmwareInfo savedFirmwareInfo = save(firmwareInfo); | 158 | + OtaPackageInfo savedFirmwareInfo = save(firmwareInfo); |
160 | 159 | ||
161 | loginDifferentTenant(); | 160 | loginDifferentTenant(); |
162 | - doPost("/api/firmware", savedFirmwareInfo, FirmwareInfo.class, status().isForbidden()); | 161 | + doPost("/api/otaPackage", savedFirmwareInfo, OtaPackageInfo.class, status().isForbidden()); |
163 | deleteDifferentTenant(); | 162 | deleteDifferentTenant(); |
164 | } | 163 | } |
165 | 164 | ||
166 | @Test | 165 | @Test |
167 | public void testFindFirmwareInfoById() throws Exception { | 166 | public void testFindFirmwareInfoById() throws Exception { |
168 | - FirmwareInfo firmwareInfo = new FirmwareInfo(); | 167 | + OtaPackageInfo firmwareInfo = new OtaPackageInfo(); |
169 | firmwareInfo.setDeviceProfileId(deviceProfileId); | 168 | firmwareInfo.setDeviceProfileId(deviceProfileId); |
170 | firmwareInfo.setType(FIRMWARE); | 169 | firmwareInfo.setType(FIRMWARE); |
171 | firmwareInfo.setTitle(TITLE); | 170 | firmwareInfo.setTitle(TITLE); |
172 | firmwareInfo.setVersion(VERSION); | 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 | Assert.assertNotNull(foundFirmware); | 176 | Assert.assertNotNull(foundFirmware); |
178 | Assert.assertEquals(savedFirmwareInfo, foundFirmware); | 177 | Assert.assertEquals(savedFirmwareInfo, foundFirmware); |
179 | } | 178 | } |
180 | 179 | ||
181 | @Test | 180 | @Test |
182 | public void testFindFirmwareById() throws Exception { | 181 | public void testFindFirmwareById() throws Exception { |
183 | - FirmwareInfo firmwareInfo = new FirmwareInfo(); | 182 | + OtaPackageInfo firmwareInfo = new OtaPackageInfo(); |
184 | firmwareInfo.setDeviceProfileId(deviceProfileId); | 183 | firmwareInfo.setDeviceProfileId(deviceProfileId); |
185 | firmwareInfo.setType(FIRMWARE); | 184 | firmwareInfo.setType(FIRMWARE); |
186 | firmwareInfo.setTitle(TITLE); | 185 | firmwareInfo.setTitle(TITLE); |
187 | firmwareInfo.setVersion(VERSION); | 186 | firmwareInfo.setVersion(VERSION); |
188 | 187 | ||
189 | - FirmwareInfo savedFirmwareInfo = save(firmwareInfo); | 188 | + OtaPackageInfo savedFirmwareInfo = save(firmwareInfo); |
190 | 189 | ||
191 | MockMultipartFile testData = new MockMultipartFile("file", FILE_NAME, CONTENT_TYPE, DATA.array()); | 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 | Assert.assertNotNull(foundFirmware); | 195 | Assert.assertNotNull(foundFirmware); |
197 | Assert.assertEquals(savedFirmware, foundFirmware); | 196 | Assert.assertEquals(savedFirmware, foundFirmware); |
198 | } | 197 | } |
199 | 198 | ||
200 | @Test | 199 | @Test |
201 | public void testDeleteFirmware() throws Exception { | 200 | public void testDeleteFirmware() throws Exception { |
202 | - FirmwareInfo firmwareInfo = new FirmwareInfo(); | 201 | + OtaPackageInfo firmwareInfo = new OtaPackageInfo(); |
203 | firmwareInfo.setDeviceProfileId(deviceProfileId); | 202 | firmwareInfo.setDeviceProfileId(deviceProfileId); |
204 | firmwareInfo.setType(FIRMWARE); | 203 | firmwareInfo.setType(FIRMWARE); |
205 | firmwareInfo.setTitle(TITLE); | 204 | firmwareInfo.setTitle(TITLE); |
206 | firmwareInfo.setVersion(VERSION); | 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 | .andExpect(status().isOk()); | 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 | .andExpect(status().isNotFound()); | 213 | .andExpect(status().isNotFound()); |
215 | } | 214 | } |
216 | 215 | ||
217 | @Test | 216 | @Test |
218 | public void testFindTenantFirmwares() throws Exception { | 217 | public void testFindTenantFirmwares() throws Exception { |
219 | - List<FirmwareInfo> firmwares = new ArrayList<>(); | 218 | + List<OtaPackageInfo> otaPackages = new ArrayList<>(); |
220 | for (int i = 0; i < 165; i++) { | 219 | for (int i = 0; i < 165; i++) { |
221 | - FirmwareInfo firmwareInfo = new FirmwareInfo(); | 220 | + OtaPackageInfo firmwareInfo = new OtaPackageInfo(); |
222 | firmwareInfo.setDeviceProfileId(deviceProfileId); | 221 | firmwareInfo.setDeviceProfileId(deviceProfileId); |
223 | firmwareInfo.setType(FIRMWARE); | 222 | firmwareInfo.setType(FIRMWARE); |
224 | firmwareInfo.setTitle(TITLE); | 223 | firmwareInfo.setTitle(TITLE); |
225 | firmwareInfo.setVersion(VERSION + i); | 224 | firmwareInfo.setVersion(VERSION + i); |
226 | 225 | ||
227 | - FirmwareInfo savedFirmwareInfo = save(firmwareInfo); | 226 | + OtaPackageInfo savedFirmwareInfo = save(firmwareInfo); |
228 | 227 | ||
229 | if (i > 100) { | 228 | if (i > 100) { |
230 | MockMultipartFile testData = new MockMultipartFile("file", FILE_NAME, CONTENT_TYPE, DATA.array()); | 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 | } else { | 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 | PageLink pageLink = new PageLink(24); | 239 | PageLink pageLink = new PageLink(24); |
241 | - PageData<FirmwareInfo> pageData; | 240 | + PageData<OtaPackageInfo> pageData; |
242 | do { | 241 | do { |
243 | - pageData = doGetTypedWithPageLink("/api/firmwares?", | 242 | + pageData = doGetTypedWithPageLink("/api/otaPackages?", |
244 | new TypeReference<>() { | 243 | new TypeReference<>() { |
245 | }, pageLink); | 244 | }, pageLink); |
246 | loadedFirmwares.addAll(pageData.getData()); | 245 | loadedFirmwares.addAll(pageData.getData()); |
@@ -249,41 +248,41 @@ public abstract class BaseFirmwareControllerTest extends AbstractControllerTest | @@ -249,41 +248,41 @@ public abstract class BaseFirmwareControllerTest extends AbstractControllerTest | ||
249 | } | 248 | } |
250 | } while (pageData.hasNext()); | 249 | } while (pageData.hasNext()); |
251 | 250 | ||
252 | - Collections.sort(firmwares, idComparator); | 251 | + Collections.sort(otaPackages, idComparator); |
253 | Collections.sort(loadedFirmwares, idComparator); | 252 | Collections.sort(loadedFirmwares, idComparator); |
254 | 253 | ||
255 | - Assert.assertEquals(firmwares, loadedFirmwares); | 254 | + Assert.assertEquals(otaPackages, loadedFirmwares); |
256 | } | 255 | } |
257 | 256 | ||
258 | @Test | 257 | @Test |
259 | public void testFindTenantFirmwaresByHasData() throws Exception { | 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 | for (int i = 0; i < 165; i++) { | 262 | for (int i = 0; i < 165; i++) { |
264 | - FirmwareInfo firmwareInfo = new FirmwareInfo(); | 263 | + OtaPackageInfo firmwareInfo = new OtaPackageInfo(); |
265 | firmwareInfo.setDeviceProfileId(deviceProfileId); | 264 | firmwareInfo.setDeviceProfileId(deviceProfileId); |
266 | firmwareInfo.setType(FIRMWARE); | 265 | firmwareInfo.setType(FIRMWARE); |
267 | firmwareInfo.setTitle(TITLE); | 266 | firmwareInfo.setTitle(TITLE); |
268 | firmwareInfo.setVersion(VERSION + i); | 267 | firmwareInfo.setVersion(VERSION + i); |
269 | 268 | ||
270 | - FirmwareInfo savedFirmwareInfo = save(firmwareInfo); | 269 | + OtaPackageInfo savedFirmwareInfo = save(firmwareInfo); |
271 | 270 | ||
272 | if (i > 100) { | 271 | if (i > 100) { |
273 | MockMultipartFile testData = new MockMultipartFile("file", FILE_NAME, CONTENT_TYPE, DATA.array()); | 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 | } else { | 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 | PageLink pageLink = new PageLink(24); | 282 | PageLink pageLink = new PageLink(24); |
284 | - PageData<FirmwareInfo> pageData; | 283 | + PageData<OtaPackageInfo> pageData; |
285 | do { | 284 | do { |
286 | - pageData = doGetTypedWithPageLink("/api/firmwares/" + deviceProfileId.toString() + "/FIRMWARE/true?", | 285 | + pageData = doGetTypedWithPageLink("/api/otaPackages/" + deviceProfileId.toString() + "/FIRMWARE/true?", |
287 | new TypeReference<>() { | 286 | new TypeReference<>() { |
288 | }, pageLink); | 287 | }, pageLink); |
289 | loadedFirmwaresWithData.addAll(pageData.getData()); | 288 | loadedFirmwaresWithData.addAll(pageData.getData()); |
@@ -292,10 +291,10 @@ public abstract class BaseFirmwareControllerTest extends AbstractControllerTest | @@ -292,10 +291,10 @@ public abstract class BaseFirmwareControllerTest extends AbstractControllerTest | ||
292 | } | 291 | } |
293 | } while (pageData.hasNext()); | 292 | } while (pageData.hasNext()); |
294 | 293 | ||
295 | - List<FirmwareInfo> loadedFirmwaresWithoutData = new ArrayList<>(); | 294 | + List<OtaPackageInfo> loadedFirmwaresWithoutData = new ArrayList<>(); |
296 | pageLink = new PageLink(24); | 295 | pageLink = new PageLink(24); |
297 | do { | 296 | do { |
298 | - pageData = doGetTypedWithPageLink("/api/firmwares/" + deviceProfileId.toString() + "/FIRMWARE/false?", | 297 | + pageData = doGetTypedWithPageLink("/api/otaPackages/" + deviceProfileId.toString() + "/FIRMWARE/false?", |
299 | new TypeReference<>() { | 298 | new TypeReference<>() { |
300 | }, pageLink); | 299 | }, pageLink); |
301 | loadedFirmwaresWithoutData.addAll(pageData.getData()); | 300 | loadedFirmwaresWithoutData.addAll(pageData.getData()); |
@@ -304,25 +303,25 @@ public abstract class BaseFirmwareControllerTest extends AbstractControllerTest | @@ -304,25 +303,25 @@ public abstract class BaseFirmwareControllerTest extends AbstractControllerTest | ||
304 | } | 303 | } |
305 | } while (pageData.hasNext()); | 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 | Collections.sort(loadedFirmwaresWithData, idComparator); | 308 | Collections.sort(loadedFirmwaresWithData, idComparator); |
310 | Collections.sort(loadedFirmwaresWithoutData, idComparator); | 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 | MockMultipartHttpServletRequestBuilder postRequest = MockMvcRequestBuilders.multipart(urlTemplate, params); | 321 | MockMultipartHttpServletRequestBuilder postRequest = MockMvcRequestBuilders.multipart(urlTemplate, params); |
323 | postRequest.file(content); | 322 | postRequest.file(content); |
324 | setJwtToken(postRequest); | 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,9 +15,9 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.controller.sql; | 16 | package org.thingsboard.server.controller.sql; |
17 | 17 | ||
18 | -import org.thingsboard.server.controller.BaseFirmwareControllerTest; | 18 | +import org.thingsboard.server.controller.BaseOtaPackageControllerTest; |
19 | import org.thingsboard.server.dao.service.DaoSqlTest; | 19 | import org.thingsboard.server.dao.service.DaoSqlTest; |
20 | 20 | ||
21 | @DaoSqlTest | 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,19 +13,20 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.cache.firmware; | 16 | +package org.thingsboard.server.cache.ota; |
17 | 17 | ||
18 | import lombok.RequiredArgsConstructor; | 18 | import lombok.RequiredArgsConstructor; |
19 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | 19 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
20 | import org.springframework.cache.CacheManager; | 20 | import org.springframework.cache.CacheManager; |
21 | import org.springframework.stereotype.Service; | 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 | @Service | 26 | @Service |
26 | @ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "caffeine", matchIfMissing = true) | 27 | @ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "caffeine", matchIfMissing = true) |
27 | @RequiredArgsConstructor | 28 | @RequiredArgsConstructor |
28 | -public class CaffeineFirmwareCache implements FirmwareDataCache { | 29 | +public class CaffeineOtaPackageCache implements OtaPackageDataCache { |
29 | 30 | ||
30 | private final CacheManager cacheManager; | 31 | private final CacheManager cacheManager; |
31 | 32 | ||
@@ -36,7 +37,7 @@ public class CaffeineFirmwareCache implements FirmwareDataCache { | @@ -36,7 +37,7 @@ public class CaffeineFirmwareCache implements FirmwareDataCache { | ||
36 | 37 | ||
37 | @Override | 38 | @Override |
38 | public byte[] get(String key, int chunkSize, int chunk) { | 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 | if (chunkSize < 1) { | 42 | if (chunkSize < 1) { |
42 | return data; | 43 | return data; |
@@ -58,11 +59,11 @@ public class CaffeineFirmwareCache implements FirmwareDataCache { | @@ -58,11 +59,11 @@ public class CaffeineFirmwareCache implements FirmwareDataCache { | ||
58 | 59 | ||
59 | @Override | 60 | @Override |
60 | public void put(String key, byte[] value) { | 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 | @Override | 65 | @Override |
65 | public void evict(String key) { | 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,9 +13,9 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 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 | byte[] get(String key); | 20 | byte[] get(String key); |
21 | 21 | ||
@@ -25,8 +25,8 @@ public interface FirmwareDataCache { | @@ -25,8 +25,8 @@ public interface FirmwareDataCache { | ||
25 | 25 | ||
26 | void evict(String key); | 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 | return data != null && data.length > 0; | 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,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.cache.firmware; | 16 | +package org.thingsboard.server.cache.ota; |
17 | 17 | ||
18 | import lombok.RequiredArgsConstructor; | 18 | import lombok.RequiredArgsConstructor; |
19 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | 19 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
@@ -21,12 +21,13 @@ import org.springframework.data.redis.connection.RedisConnection; | @@ -21,12 +21,13 @@ import org.springframework.data.redis.connection.RedisConnection; | ||
21 | import org.springframework.data.redis.connection.RedisConnectionFactory; | 21 | import org.springframework.data.redis.connection.RedisConnectionFactory; |
22 | import org.springframework.stereotype.Service; | 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 | @Service | 27 | @Service |
27 | @ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "redis") | 28 | @ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "redis") |
28 | @RequiredArgsConstructor | 29 | @RequiredArgsConstructor |
29 | -public class RedisFirmwareDataCache implements FirmwareDataCache { | 30 | +public class RedisOtaPackageDataCache implements OtaPackageDataCache { |
30 | 31 | ||
31 | private final RedisConnectionFactory redisConnectionFactory; | 32 | private final RedisConnectionFactory redisConnectionFactory; |
32 | 33 | ||
@@ -39,30 +40,30 @@ public class RedisFirmwareDataCache implements FirmwareDataCache { | @@ -39,30 +40,30 @@ public class RedisFirmwareDataCache implements FirmwareDataCache { | ||
39 | public byte[] get(String key, int chunkSize, int chunk) { | 40 | public byte[] get(String key, int chunkSize, int chunk) { |
40 | try (RedisConnection connection = redisConnectionFactory.getConnection()) { | 41 | try (RedisConnection connection = redisConnectionFactory.getConnection()) { |
41 | if (chunkSize == 0) { | 42 | if (chunkSize == 0) { |
42 | - return connection.get(toFirmwareCacheKey(key)); | 43 | + return connection.get(toOtaPackageCacheKey(key)); |
43 | } | 44 | } |
44 | 45 | ||
45 | int startIndex = chunkSize * chunk; | 46 | int startIndex = chunkSize * chunk; |
46 | int endIndex = startIndex + chunkSize - 1; | 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 | @Override | 52 | @Override |
52 | public void put(String key, byte[] value) { | 53 | public void put(String key, byte[] value) { |
53 | try (RedisConnection connection = redisConnectionFactory.getConnection()) { | 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 | @Override | 59 | @Override |
59 | public void evict(String key) { | 60 | public void evict(String key) { |
60 | try (RedisConnection connection = redisConnectionFactory.getConnection()) { | 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,6 +27,7 @@ import org.thingsboard.server.common.data.id.DeviceId; | ||
27 | import org.thingsboard.server.common.data.id.DeviceProfileId; | 27 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
28 | import org.thingsboard.server.common.data.id.EdgeId; | 28 | import org.thingsboard.server.common.data.id.EdgeId; |
29 | import org.thingsboard.server.common.data.id.TenantId; | 29 | import org.thingsboard.server.common.data.id.TenantId; |
30 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | ||
30 | import org.thingsboard.server.common.data.page.PageData; | 31 | import org.thingsboard.server.common.data.page.PageData; |
31 | import org.thingsboard.server.common.data.page.PageLink; | 32 | import org.thingsboard.server.common.data.page.PageLink; |
32 | import org.thingsboard.server.common.data.security.DeviceCredentials; | 33 | import org.thingsboard.server.common.data.security.DeviceCredentials; |
@@ -63,9 +64,9 @@ public interface DeviceService { | @@ -63,9 +64,9 @@ public interface DeviceService { | ||
63 | 64 | ||
64 | PageData<Device> findDevicesByTenantIdAndType(TenantId tenantId, String type, PageLink pageLink); | 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 | PageData<DeviceInfo> findDeviceInfosByTenantIdAndType(TenantId tenantId, String type, PageLink pageLink); | 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,40 +13,40 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 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 com.google.common.util.concurrent.ListenableFuture; | 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 | import org.thingsboard.server.common.data.id.DeviceProfileId; | 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 | import org.thingsboard.server.common.data.id.TenantId; | 25 | import org.thingsboard.server.common.data.id.TenantId; |
26 | import org.thingsboard.server.common.data.page.PageData; | 26 | import org.thingsboard.server.common.data.page.PageData; |
27 | import org.thingsboard.server.common.data.page.PageLink; | 27 | import org.thingsboard.server.common.data.page.PageLink; |
28 | 28 | ||
29 | import java.nio.ByteBuffer; | 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 | String generateChecksum(ChecksumAlgorithm checksumAlgorithm, ByteBuffer data); | 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,5 +29,6 @@ public class CacheConstants { | ||
29 | public static final String DEVICE_PROFILE_CACHE = "deviceProfiles"; | 29 | public static final String DEVICE_PROFILE_CACHE = "deviceProfiles"; |
30 | public static final String ATTRIBUTES_CACHE = "attributes"; | 30 | public static final String ATTRIBUTES_CACHE = "attributes"; |
31 | public static final String TOKEN_OUTDATAGE_TIME_CACHE = "tokensOutdatageTime"; | 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,7 +23,7 @@ import org.thingsboard.server.common.data.device.data.DeviceData; | ||
23 | import org.thingsboard.server.common.data.id.CustomerId; | 23 | import org.thingsboard.server.common.data.id.CustomerId; |
24 | import org.thingsboard.server.common.data.id.DeviceId; | 24 | import org.thingsboard.server.common.data.id.DeviceId; |
25 | import org.thingsboard.server.common.data.id.DeviceProfileId; | 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 | import org.thingsboard.server.common.data.id.TenantId; | 27 | import org.thingsboard.server.common.data.id.TenantId; |
28 | import org.thingsboard.server.common.data.validation.NoXss; | 28 | import org.thingsboard.server.common.data.validation.NoXss; |
29 | 29 | ||
@@ -32,7 +32,7 @@ import java.io.IOException; | @@ -32,7 +32,7 @@ import java.io.IOException; | ||
32 | 32 | ||
33 | @EqualsAndHashCode(callSuper = true) | 33 | @EqualsAndHashCode(callSuper = true) |
34 | @Slf4j | 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 | private static final long serialVersionUID = 2807343040519543363L; | 37 | private static final long serialVersionUID = 2807343040519543363L; |
38 | 38 | ||
@@ -49,8 +49,8 @@ public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implemen | @@ -49,8 +49,8 @@ public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implemen | ||
49 | @JsonIgnore | 49 | @JsonIgnore |
50 | private byte[] deviceDataBytes; | 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 | public Device() { | 55 | public Device() { |
56 | super(); | 56 | super(); |
@@ -167,19 +167,19 @@ public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implemen | @@ -167,19 +167,19 @@ public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implemen | ||
167 | return getName(); | 167 | return getName(); |
168 | } | 168 | } |
169 | 169 | ||
170 | - public FirmwareId getFirmwareId() { | 170 | + public OtaPackageId getFirmwareId() { |
171 | return firmwareId; | 171 | return firmwareId; |
172 | } | 172 | } |
173 | 173 | ||
174 | - public void setFirmwareId(FirmwareId firmwareId) { | 174 | + public void setFirmwareId(OtaPackageId firmwareId) { |
175 | this.firmwareId = firmwareId; | 175 | this.firmwareId = firmwareId; |
176 | } | 176 | } |
177 | 177 | ||
178 | - public FirmwareId getSoftwareId() { | 178 | + public OtaPackageId getSoftwareId() { |
179 | return softwareId; | 179 | return softwareId; |
180 | } | 180 | } |
181 | 181 | ||
182 | - public void setSoftwareId(FirmwareId softwareId) { | 182 | + public void setSoftwareId(OtaPackageId softwareId) { |
183 | this.softwareId = softwareId; | 183 | this.softwareId = softwareId; |
184 | } | 184 | } |
185 | 185 |
@@ -23,7 +23,7 @@ import lombok.extern.slf4j.Slf4j; | @@ -23,7 +23,7 @@ import lombok.extern.slf4j.Slf4j; | ||
23 | import org.thingsboard.server.common.data.device.profile.DeviceProfileData; | 23 | import org.thingsboard.server.common.data.device.profile.DeviceProfileData; |
24 | import org.thingsboard.server.common.data.id.DashboardId; | 24 | import org.thingsboard.server.common.data.id.DashboardId; |
25 | import org.thingsboard.server.common.data.id.DeviceProfileId; | 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 | import org.thingsboard.server.common.data.id.RuleChainId; | 27 | import org.thingsboard.server.common.data.id.RuleChainId; |
28 | import org.thingsboard.server.common.data.id.TenantId; | 28 | import org.thingsboard.server.common.data.id.TenantId; |
29 | import org.thingsboard.server.common.data.validation.NoXss; | 29 | import org.thingsboard.server.common.data.validation.NoXss; |
@@ -37,7 +37,7 @@ import static org.thingsboard.server.common.data.SearchTextBasedWithAdditionalIn | @@ -37,7 +37,7 @@ import static org.thingsboard.server.common.data.SearchTextBasedWithAdditionalIn | ||
37 | @Data | 37 | @Data |
38 | @EqualsAndHashCode(callSuper = true) | 38 | @EqualsAndHashCode(callSuper = true) |
39 | @Slf4j | 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 | private TenantId tenantId; | 42 | private TenantId tenantId; |
43 | @NoXss | 43 | @NoXss |
@@ -60,9 +60,9 @@ public class DeviceProfile extends SearchTextBased<DeviceProfileId> implements H | @@ -60,9 +60,9 @@ public class DeviceProfile extends SearchTextBased<DeviceProfileId> implements H | ||
60 | @NoXss | 60 | @NoXss |
61 | private String provisionDeviceKey; | 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 | public DeviceProfile() { | 67 | public DeviceProfile() { |
68 | super(); | 68 | super(); |
@@ -19,5 +19,5 @@ package org.thingsboard.server.common.data; | @@ -19,5 +19,5 @@ package org.thingsboard.server.common.data; | ||
19 | * @author Andrew Shvayka | 19 | * @author Andrew Shvayka |
20 | */ | 20 | */ |
21 | public enum EntityType { | 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,11 +15,11 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.common.data; | 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,27 +17,27 @@ package org.thingsboard.server.common.data; | ||
17 | 17 | ||
18 | import lombok.Data; | 18 | import lombok.Data; |
19 | import lombok.EqualsAndHashCode; | 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 | import java.nio.ByteBuffer; | 22 | import java.nio.ByteBuffer; |
23 | 23 | ||
24 | @Data | 24 | @Data |
25 | @EqualsAndHashCode(callSuper = true) | 25 | @EqualsAndHashCode(callSuper = true) |
26 | -public class Firmware extends FirmwareInfo { | 26 | +public class OtaPackage extends OtaPackageInfo { |
27 | 27 | ||
28 | private static final long serialVersionUID = 3091601761339422546L; | 28 | private static final long serialVersionUID = 3091601761339422546L; |
29 | 29 | ||
30 | private transient ByteBuffer data; | 30 | private transient ByteBuffer data; |
31 | 31 | ||
32 | - public Firmware() { | 32 | + public OtaPackage() { |
33 | super(); | 33 | super(); |
34 | } | 34 | } |
35 | 35 | ||
36 | - public Firmware(FirmwareId id) { | 36 | + public OtaPackage(OtaPackageId id) { |
37 | super(id); | 37 | super(id); |
38 | } | 38 | } |
39 | 39 | ||
40 | - public Firmware(Firmware firmware) { | 40 | + public OtaPackage(OtaPackage firmware) { |
41 | super(firmware); | 41 | super(firmware); |
42 | this.data = firmware.getData(); | 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,22 +19,22 @@ import com.fasterxml.jackson.annotation.JsonIgnore; | ||
19 | import lombok.Data; | 19 | import lombok.Data; |
20 | import lombok.EqualsAndHashCode; | 20 | import lombok.EqualsAndHashCode; |
21 | import lombok.extern.slf4j.Slf4j; | 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 | import org.thingsboard.server.common.data.id.DeviceProfileId; | 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 | import org.thingsboard.server.common.data.id.TenantId; | 26 | import org.thingsboard.server.common.data.id.TenantId; |
27 | 27 | ||
28 | @Slf4j | 28 | @Slf4j |
29 | @Data | 29 | @Data |
30 | @EqualsAndHashCode(callSuper = true) | 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 | private static final long serialVersionUID = 3168391583570815419L; | 33 | private static final long serialVersionUID = 3168391583570815419L; |
34 | 34 | ||
35 | private TenantId tenantId; | 35 | private TenantId tenantId; |
36 | private DeviceProfileId deviceProfileId; | 36 | private DeviceProfileId deviceProfileId; |
37 | - private FirmwareType type; | 37 | + private OtaPackageType type; |
38 | private String title; | 38 | private String title; |
39 | private String version; | 39 | private String version; |
40 | private boolean hasData; | 40 | private boolean hasData; |
@@ -45,27 +45,27 @@ public class FirmwareInfo extends SearchTextBasedWithAdditionalInfo<FirmwareId> | @@ -45,27 +45,27 @@ public class FirmwareInfo extends SearchTextBasedWithAdditionalInfo<FirmwareId> | ||
45 | private Long dataSize; | 45 | private Long dataSize; |
46 | 46 | ||
47 | 47 | ||
48 | - public FirmwareInfo() { | 48 | + public OtaPackageInfo() { |
49 | super(); | 49 | super(); |
50 | } | 50 | } |
51 | 51 | ||
52 | - public FirmwareInfo(FirmwareId id) { | 52 | + public OtaPackageInfo(OtaPackageId id) { |
53 | super(id); | 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 | @Override | 71 | @Override |
@@ -71,8 +71,8 @@ public class EntityIdFactory { | @@ -71,8 +71,8 @@ public class EntityIdFactory { | ||
71 | return new ApiUsageStateId(uuid); | 71 | return new ApiUsageStateId(uuid); |
72 | case TB_RESOURCE: | 72 | case TB_RESOURCE: |
73 | return new TbResourceId(uuid); | 73 | return new TbResourceId(uuid); |
74 | - case FIRMWARE: | ||
75 | - return new FirmwareId(uuid); | 74 | + case OTA_PACKAGE: |
75 | + return new OtaPackageId(uuid); | ||
76 | case EDGE: | 76 | case EDGE: |
77 | return new EdgeId(uuid); | 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,23 +22,23 @@ import org.thingsboard.server.common.data.EntityType; | ||
22 | 22 | ||
23 | import java.util.UUID; | 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 | private static final long serialVersionUID = 1L; | 27 | private static final long serialVersionUID = 1L; |
28 | 28 | ||
29 | @JsonCreator | 29 | @JsonCreator |
30 | - public FirmwareId(@JsonProperty("id") UUID id) { | 30 | + public OtaPackageId(@JsonProperty("id") UUID id) { |
31 | super(id); | 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 | @JsonIgnore | 38 | @JsonIgnore |
39 | @Override | 39 | @Override |
40 | public EntityType getEntityType() { | 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,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 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 ChecksumAlgorithm { | 18 | public enum ChecksumAlgorithm { |
19 | MD5, | 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,18 +13,18 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 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 | import lombok.Getter; | 18 | import lombok.Getter; |
19 | 19 | ||
20 | -public enum FirmwareKey { | 20 | +public enum OtaPackageKey { |
21 | 21 | ||
22 | TITLE("title"), VERSION("version"), TS("ts"), STATE("state"), SIZE("size"), CHECKSUM("checksum"), CHECKSUM_ALGORITHM("checksum_algorithm"); | 22 | TITLE("title"), VERSION("version"), TS("ts"), STATE("state"), SIZE("size"), CHECKSUM("checksum"), CHECKSUM_ALGORITHM("checksum_algorithm"); |
23 | 23 | ||
24 | @Getter | 24 | @Getter |
25 | private final String value; | 25 | private final String value; |
26 | 26 | ||
27 | - FirmwareKey(String value) { | 27 | + OtaPackageKey(String value) { |
28 | this.value = value; | 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,18 +13,18 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 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 | import lombok.Getter; | 18 | import lombok.Getter; |
19 | 19 | ||
20 | -public enum FirmwareType { | 20 | +public enum OtaPackageType { |
21 | 21 | ||
22 | FIRMWARE("fw"), SOFTWARE("sw"); | 22 | FIRMWARE("fw"), SOFTWARE("sw"); |
23 | 23 | ||
24 | @Getter | 24 | @Getter |
25 | private final String keyPrefix; | 25 | private final String keyPrefix; |
26 | 26 | ||
27 | - FirmwareType(String keyPrefix) { | 27 | + OtaPackageType(String keyPrefix) { |
28 | this.keyPrefix = keyPrefix; | 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,8 +13,8 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 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 | QUEUED, INITIATED, DOWNLOADING, DOWNLOADED, VERIFIED, UPDATING, UPDATED, FAILED | 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,21 +13,19 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 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 | import lombok.extern.slf4j.Slf4j; | 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 | import java.util.ArrayList; | 22 | import java.util.ArrayList; |
23 | import java.util.Collections; | 23 | import java.util.Collections; |
24 | import java.util.List; | 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 | @Slf4j | 27 | @Slf4j |
30 | -public class FirmwareUtil { | 28 | +public class OtaPackageUtil { |
31 | 29 | ||
32 | public static final List<String> ALL_FW_ATTRIBUTE_KEYS; | 30 | public static final List<String> ALL_FW_ATTRIBUTE_KEYS; |
33 | 31 | ||
@@ -35,19 +33,19 @@ public class FirmwareUtil { | @@ -35,19 +33,19 @@ public class FirmwareUtil { | ||
35 | 33 | ||
36 | static { | 34 | static { |
37 | ALL_FW_ATTRIBUTE_KEYS = new ArrayList<>(); | 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 | ALL_SW_ATTRIBUTE_KEYS = new ArrayList<>(); | 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 | switch (firmwareType) { | 49 | switch (firmwareType) { |
52 | case FIRMWARE: | 50 | case FIRMWARE: |
53 | return ALL_FW_ATTRIBUTE_KEYS; | 51 | return ALL_FW_ATTRIBUTE_KEYS; |
@@ -57,35 +55,46 @@ public class FirmwareUtil { | @@ -57,35 +55,46 @@ public class FirmwareUtil { | ||
57 | return Collections.emptyList(); | 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 | return type.getKeyPrefix() + "_" + key.getValue(); | 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 | return getTelemetryKey("target_", type, key); | 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 | return getTelemetryKey("current_", type, key); | 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 | return prefix + type.getKeyPrefix() + "_" + key.getValue(); | 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 | return type.getKeyPrefix() + "_" + key.getValue(); | 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 | case FIRMWARE: | 80 | case FIRMWARE: |
83 | return entity.getFirmwareId(); | 81 | return entity.getFirmwareId(); |
84 | case SOFTWARE: | 82 | case SOFTWARE: |
85 | return entity.getSoftwareId(); | 83 | return entity.getSoftwareId(); |
86 | default: | 84 | default: |
87 | - log.warn("Unsupported firmware type: [{}]", firmwareType); | 85 | + log.warn("Unsupported ota package type: [{}]", type); |
88 | return null; | 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,7 +38,7 @@ public class TbKafkaTopicConfigs { | ||
38 | private String notificationsProperties; | 38 | private String notificationsProperties; |
39 | @Value("${queue.kafka.topic-properties.js-executor}") | 39 | @Value("${queue.kafka.topic-properties.js-executor}") |
40 | private String jsExecutorProperties; | 40 | private String jsExecutorProperties; |
41 | - @Value("${queue.kafka.topic-properties.fw-updates:}") | 41 | + @Value("${queue.kafka.topic-properties.ota-updates:}") |
42 | private String fwUpdatesProperties; | 42 | private String fwUpdatesProperties; |
43 | 43 | ||
44 | @Getter | 44 | @Getter |
@@ -187,14 +187,14 @@ public class AwsSqsMonolithQueueFactory implements TbCoreQueueFactory, TbRuleEng | @@ -187,14 +187,14 @@ public class AwsSqsMonolithQueueFactory implements TbCoreQueueFactory, TbRuleEng | ||
187 | } | 187 | } |
188 | 188 | ||
189 | @Override | 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 | @Override | 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 | @PreDestroy | 200 | @PreDestroy |
@@ -23,7 +23,7 @@ import org.thingsboard.server.common.msg.queue.ServiceType; | @@ -23,7 +23,7 @@ import org.thingsboard.server.common.msg.queue.ServiceType; | ||
23 | import org.thingsboard.server.gen.js.JsInvokeProtos; | 23 | import org.thingsboard.server.gen.js.JsInvokeProtos; |
24 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; | 24 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
25 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; | 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 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; | 27 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; |
28 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; | 28 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; |
29 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; | 29 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; |
@@ -177,14 +177,14 @@ public class AwsSqsTbCoreQueueFactory implements TbCoreQueueFactory { | @@ -177,14 +177,14 @@ public class AwsSqsTbCoreQueueFactory implements TbCoreQueueFactory { | ||
177 | } | 177 | } |
178 | 178 | ||
179 | @Override | 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 | @Override | 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 | @PreDestroy | 190 | @PreDestroy |
@@ -131,13 +131,13 @@ public class InMemoryMonolithQueueFactory implements TbCoreQueueFactory, TbRuleE | @@ -131,13 +131,13 @@ public class InMemoryMonolithQueueFactory implements TbCoreQueueFactory, TbRuleE | ||
131 | } | 131 | } |
132 | 132 | ||
133 | @Override | 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 | @Override | 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 | @Override | 143 | @Override |
@@ -23,7 +23,7 @@ import org.thingsboard.server.common.msg.queue.ServiceType; | @@ -23,7 +23,7 @@ import org.thingsboard.server.common.msg.queue.ServiceType; | ||
23 | import org.thingsboard.server.gen.js.JsInvokeProtos; | 23 | import org.thingsboard.server.gen.js.JsInvokeProtos; |
24 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; | 24 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
25 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; | 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 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; | 27 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; |
28 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; | 28 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; |
29 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; | 29 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; |
@@ -277,24 +277,24 @@ public class KafkaMonolithQueueFactory implements TbCoreQueueFactory, TbRuleEngi | @@ -277,24 +277,24 @@ public class KafkaMonolithQueueFactory implements TbCoreQueueFactory, TbRuleEngi | ||
277 | } | 277 | } |
278 | 278 | ||
279 | @Override | 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 | consumerBuilder.settings(kafkaSettings); | 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 | consumerBuilder.admin(fwUpdatesAdmin); | 287 | consumerBuilder.admin(fwUpdatesAdmin); |
288 | consumerBuilder.statsService(consumerStatsService); | 288 | consumerBuilder.statsService(consumerStatsService); |
289 | return consumerBuilder.build(); | 289 | return consumerBuilder.build(); |
290 | } | 290 | } |
291 | 291 | ||
292 | @Override | 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 | requestBuilder.settings(kafkaSettings); | 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 | requestBuilder.admin(fwUpdatesAdmin); | 298 | requestBuilder.admin(fwUpdatesAdmin); |
299 | return requestBuilder.build(); | 299 | return requestBuilder.build(); |
300 | } | 300 | } |
@@ -23,7 +23,7 @@ import org.thingsboard.server.common.msg.queue.ServiceType; | @@ -23,7 +23,7 @@ import org.thingsboard.server.common.msg.queue.ServiceType; | ||
23 | import org.thingsboard.server.gen.js.JsInvokeProtos; | 23 | import org.thingsboard.server.gen.js.JsInvokeProtos; |
24 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; | 24 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
25 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; | 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 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; | 27 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; |
28 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; | 28 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; |
29 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; | 29 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; |
@@ -245,24 +245,24 @@ public class KafkaTbCoreQueueFactory implements TbCoreQueueFactory { | @@ -245,24 +245,24 @@ public class KafkaTbCoreQueueFactory implements TbCoreQueueFactory { | ||
245 | } | 245 | } |
246 | 246 | ||
247 | @Override | 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 | consumerBuilder.settings(kafkaSettings); | 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 | consumerBuilder.admin(fwUpdatesAdmin); | 255 | consumerBuilder.admin(fwUpdatesAdmin); |
256 | consumerBuilder.statsService(consumerStatsService); | 256 | consumerBuilder.statsService(consumerStatsService); |
257 | return consumerBuilder.build(); | 257 | return consumerBuilder.build(); |
258 | } | 258 | } |
259 | 259 | ||
260 | @Override | 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 | requestBuilder.settings(kafkaSettings); | 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 | requestBuilder.admin(fwUpdatesAdmin); | 266 | requestBuilder.admin(fwUpdatesAdmin); |
267 | return requestBuilder.build(); | 267 | return requestBuilder.build(); |
268 | } | 268 | } |
@@ -22,9 +22,9 @@ import org.springframework.stereotype.Component; | @@ -22,9 +22,9 @@ import org.springframework.stereotype.Component; | ||
22 | import org.thingsboard.server.common.msg.queue.ServiceType; | 22 | import org.thingsboard.server.common.msg.queue.ServiceType; |
23 | import org.thingsboard.server.gen.js.JsInvokeProtos.RemoteJsRequest; | 23 | import org.thingsboard.server.gen.js.JsInvokeProtos.RemoteJsRequest; |
24 | import org.thingsboard.server.gen.js.JsInvokeProtos.RemoteJsResponse; | 24 | import org.thingsboard.server.gen.js.JsInvokeProtos.RemoteJsResponse; |
25 | -import org.thingsboard.server.gen.transport.TransportProtos.*; | ||
26 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; | 25 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
27 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; | 26 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; |
27 | +import org.thingsboard.server.gen.transport.TransportProtos.ToOtaPackageStateServiceMsg; | ||
28 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; | 28 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; |
29 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; | 29 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; |
30 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; | 30 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; |
@@ -192,14 +192,14 @@ public class PubSubMonolithQueueFactory implements TbCoreQueueFactory, TbRuleEng | @@ -192,14 +192,14 @@ public class PubSubMonolithQueueFactory implements TbCoreQueueFactory, TbRuleEng | ||
192 | } | 192 | } |
193 | 193 | ||
194 | @Override | 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 | @Override | 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 | @Override | 205 | @Override |
@@ -23,7 +23,7 @@ import org.thingsboard.server.common.msg.queue.ServiceType; | @@ -23,7 +23,7 @@ import org.thingsboard.server.common.msg.queue.ServiceType; | ||
23 | import org.thingsboard.server.gen.js.JsInvokeProtos; | 23 | import org.thingsboard.server.gen.js.JsInvokeProtos; |
24 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; | 24 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
25 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; | 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 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; | 27 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; |
28 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; | 28 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; |
29 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; | 29 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; |
@@ -166,14 +166,14 @@ public class PubSubTbCoreQueueFactory implements TbCoreQueueFactory { | @@ -166,14 +166,14 @@ public class PubSubTbCoreQueueFactory implements TbCoreQueueFactory { | ||
166 | } | 166 | } |
167 | 167 | ||
168 | @Override | 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 | @Override | 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 | @Override | 179 | @Override |
@@ -24,7 +24,7 @@ import org.thingsboard.server.gen.js.JsInvokeProtos.RemoteJsRequest; | @@ -24,7 +24,7 @@ import org.thingsboard.server.gen.js.JsInvokeProtos.RemoteJsRequest; | ||
24 | import org.thingsboard.server.gen.js.JsInvokeProtos.RemoteJsResponse; | 24 | import org.thingsboard.server.gen.js.JsInvokeProtos.RemoteJsResponse; |
25 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; | 25 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
26 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; | 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 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; | 28 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; |
29 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; | 29 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; |
30 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; | 30 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; |
@@ -190,14 +190,14 @@ public class RabbitMqMonolithQueueFactory implements TbCoreQueueFactory, TbRuleE | @@ -190,14 +190,14 @@ public class RabbitMqMonolithQueueFactory implements TbCoreQueueFactory, TbRuleE | ||
190 | } | 190 | } |
191 | 191 | ||
192 | @Override | 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 | @Override | 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 | @Override | 203 | @Override |
@@ -23,7 +23,7 @@ import org.thingsboard.server.common.msg.queue.ServiceType; | @@ -23,7 +23,7 @@ import org.thingsboard.server.common.msg.queue.ServiceType; | ||
23 | import org.thingsboard.server.gen.js.JsInvokeProtos; | 23 | import org.thingsboard.server.gen.js.JsInvokeProtos; |
24 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; | 24 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
25 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; | 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 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; | 27 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; |
28 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; | 28 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; |
29 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; | 29 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; |
@@ -172,14 +172,14 @@ public class RabbitMqTbCoreQueueFactory implements TbCoreQueueFactory { | @@ -172,14 +172,14 @@ public class RabbitMqTbCoreQueueFactory implements TbCoreQueueFactory { | ||
172 | } | 172 | } |
173 | 173 | ||
174 | @Override | 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 | @Override | 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 | @Override | 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,7 +23,7 @@ import org.thingsboard.server.common.msg.queue.ServiceType; | ||
23 | import org.thingsboard.server.gen.js.JsInvokeProtos; | 23 | import org.thingsboard.server.gen.js.JsInvokeProtos; |
24 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; | 24 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
25 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; | 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 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; | 27 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; |
28 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; | 28 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; |
29 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; | 29 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; |
@@ -189,14 +189,14 @@ public class ServiceBusMonolithQueueFactory implements TbCoreQueueFactory, TbRul | @@ -189,14 +189,14 @@ public class ServiceBusMonolithQueueFactory implements TbCoreQueueFactory, TbRul | ||
189 | } | 189 | } |
190 | 190 | ||
191 | @Override | 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 | @Override | 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 | @Override | 202 | @Override |
@@ -23,7 +23,7 @@ import org.thingsboard.server.common.msg.queue.ServiceType; | @@ -23,7 +23,7 @@ import org.thingsboard.server.common.msg.queue.ServiceType; | ||
23 | import org.thingsboard.server.gen.js.JsInvokeProtos; | 23 | import org.thingsboard.server.gen.js.JsInvokeProtos; |
24 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; | 24 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
25 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; | 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 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; | 27 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; |
28 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; | 28 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; |
29 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; | 29 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; |
@@ -172,14 +172,14 @@ public class ServiceBusTbCoreQueueFactory implements TbCoreQueueFactory { | @@ -172,14 +172,14 @@ public class ServiceBusTbCoreQueueFactory implements TbCoreQueueFactory { | ||
172 | } | 172 | } |
173 | 173 | ||
174 | @Override | 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 | @Override | 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 | @Override | 185 | @Override |
@@ -16,7 +16,7 @@ | @@ -16,7 +16,7 @@ | ||
16 | package org.thingsboard.server.queue.provider; | 16 | package org.thingsboard.server.queue.provider; |
17 | 17 | ||
18 | import org.thingsboard.server.gen.js.JsInvokeProtos; | 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 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; | 20 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
21 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; | 21 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; |
22 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; | 22 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; |
@@ -91,14 +91,14 @@ public interface TbCoreQueueFactory extends TbUsageStatsClientQueueFactory { | @@ -91,14 +91,14 @@ public interface TbCoreQueueFactory extends TbUsageStatsClientQueueFactory { | ||
91 | * | 91 | * |
92 | * @return | 92 | * @return |
93 | */ | 93 | */ |
94 | - TbQueueConsumer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> createToFirmwareStateServiceMsgConsumer(); | 94 | + TbQueueConsumer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> createToOtaPackageStateServiceMsgConsumer(); |
95 | 95 | ||
96 | /** | 96 | /** |
97 | * Used to consume messages about firmware update notifications by TB Core Service | 97 | * Used to consume messages about firmware update notifications by TB Core Service |
98 | * | 98 | * |
99 | * @return | 99 | * @return |
100 | */ | 100 | */ |
101 | - TbQueueProducer<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> createToFirmwareStateServiceMsgProducer(); | 101 | + TbQueueProducer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> createToOtaPackageStateServiceMsgProducer(); |
102 | 102 | ||
103 | /** | 103 | /** |
104 | * Used to consume high priority messages by TB Core Service | 104 | * Used to consume high priority messages by TB Core Service |
@@ -15,7 +15,6 @@ | @@ -15,7 +15,6 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.queue.provider; | 16 | package org.thingsboard.server.queue.provider; |
17 | 17 | ||
18 | -import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; | ||
19 | import org.springframework.stereotype.Service; | 18 | import org.springframework.stereotype.Service; |
20 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; | 19 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
21 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; | 20 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; |
@@ -25,11 +24,12 @@ import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; | @@ -25,11 +24,12 @@ import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; | ||
25 | import org.thingsboard.server.gen.transport.TransportProtos.ToUsageStatsServiceMsg; | 24 | import org.thingsboard.server.gen.transport.TransportProtos.ToUsageStatsServiceMsg; |
26 | import org.thingsboard.server.queue.TbQueueProducer; | 25 | import org.thingsboard.server.queue.TbQueueProducer; |
27 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 26 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
27 | +import org.thingsboard.server.queue.util.TbCoreComponent; | ||
28 | 28 | ||
29 | import javax.annotation.PostConstruct; | 29 | import javax.annotation.PostConstruct; |
30 | 30 | ||
31 | @Service | 31 | @Service |
32 | -@ConditionalOnExpression("'${service.type:null}'=='monolith' || '${service.type:null}'=='tb-core'") | 32 | +@TbCoreComponent |
33 | public class TbCoreQueueProducerProvider implements TbQueueProducerProvider { | 33 | public class TbCoreQueueProducerProvider implements TbQueueProducerProvider { |
34 | 34 | ||
35 | private final TbCoreQueueFactory tbQueueProvider; | 35 | private final TbCoreQueueFactory tbQueueProvider; |
@@ -26,8 +26,8 @@ public class TbQueueCoreSettings { | @@ -26,8 +26,8 @@ public class TbQueueCoreSettings { | ||
26 | @Value("${queue.core.topic}") | 26 | @Value("${queue.core.topic}") |
27 | private String topic; | 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 | @Value("${queue.core.usage-stats-topic:tb_usage_stats}") | 32 | @Value("${queue.core.usage-stats-topic:tb_usage_stats}") |
33 | private String usageStatsTopic; | 33 | private String usageStatsTopic; |
@@ -388,7 +388,7 @@ enum ResponseStatus { | @@ -388,7 +388,7 @@ enum ResponseStatus { | ||
388 | FAILURE = 3; | 388 | FAILURE = 3; |
389 | } | 389 | } |
390 | 390 | ||
391 | -message GetFirmwareRequestMsg { | 391 | +message GetOtaPackageRequestMsg { |
392 | int64 deviceIdMSB = 1; | 392 | int64 deviceIdMSB = 1; |
393 | int64 deviceIdLSB = 2; | 393 | int64 deviceIdLSB = 2; |
394 | int64 tenantIdMSB = 3; | 394 | int64 tenantIdMSB = 3; |
@@ -396,10 +396,10 @@ message GetFirmwareRequestMsg { | @@ -396,10 +396,10 @@ message GetFirmwareRequestMsg { | ||
396 | string type = 5; | 396 | string type = 5; |
397 | } | 397 | } |
398 | 398 | ||
399 | -message GetFirmwareResponseMsg { | 399 | +message GetOtaPackageResponseMsg { |
400 | ResponseStatus responseStatus = 1; | 400 | ResponseStatus responseStatus = 1; |
401 | - int64 firmwareIdMSB = 2; | ||
402 | - int64 firmwareIdLSB = 3; | 401 | + int64 otaPackageIdMSB = 2; |
402 | + int64 otaPackageIdLSB = 3; | ||
403 | string type = 4; | 403 | string type = 4; |
404 | string title = 5; | 404 | string title = 5; |
405 | string version = 6; | 405 | string version = 6; |
@@ -627,7 +627,7 @@ message TransportApiRequestMsg { | @@ -627,7 +627,7 @@ message TransportApiRequestMsg { | ||
627 | ProvisionDeviceRequestMsg provisionDeviceRequestMsg = 7; | 627 | ProvisionDeviceRequestMsg provisionDeviceRequestMsg = 7; |
628 | ValidateDeviceLwM2MCredentialsRequestMsg validateDeviceLwM2MCredentialsRequestMsg = 8; | 628 | ValidateDeviceLwM2MCredentialsRequestMsg validateDeviceLwM2MCredentialsRequestMsg = 8; |
629 | GetResourceRequestMsg resourceRequestMsg = 9; | 629 | GetResourceRequestMsg resourceRequestMsg = 9; |
630 | - GetFirmwareRequestMsg firmwareRequestMsg = 10; | 630 | + GetOtaPackageRequestMsg otaPackageRequestMsg = 10; |
631 | GetSnmpDevicesRequestMsg snmpDevicesRequestMsg = 11; | 631 | GetSnmpDevicesRequestMsg snmpDevicesRequestMsg = 11; |
632 | GetDeviceRequestMsg deviceRequestMsg = 12; | 632 | GetDeviceRequestMsg deviceRequestMsg = 12; |
633 | GetDeviceCredentialsRequestMsg deviceCredentialsRequestMsg = 13; | 633 | GetDeviceCredentialsRequestMsg deviceCredentialsRequestMsg = 13; |
@@ -642,7 +642,7 @@ message TransportApiResponseMsg { | @@ -642,7 +642,7 @@ message TransportApiResponseMsg { | ||
642 | GetSnmpDevicesResponseMsg snmpDevicesResponseMsg = 5; | 642 | GetSnmpDevicesResponseMsg snmpDevicesResponseMsg = 5; |
643 | LwM2MResponseMsg lwM2MResponseMsg = 6; | 643 | LwM2MResponseMsg lwM2MResponseMsg = 6; |
644 | GetResourceResponseMsg resourceResponseMsg = 7; | 644 | GetResourceResponseMsg resourceResponseMsg = 7; |
645 | - GetFirmwareResponseMsg firmwareResponseMsg = 8; | 645 | + GetOtaPackageResponseMsg otaPackageResponseMsg = 8; |
646 | GetDeviceResponseMsg deviceResponseMsg = 9; | 646 | GetDeviceResponseMsg deviceResponseMsg = 9; |
647 | GetDeviceCredentialsResponseMsg deviceCredentialsResponseMsg = 10; | 647 | GetDeviceCredentialsResponseMsg deviceCredentialsResponseMsg = 10; |
648 | } | 648 | } |
@@ -710,13 +710,13 @@ message ToUsageStatsServiceMsg { | @@ -710,13 +710,13 @@ message ToUsageStatsServiceMsg { | ||
710 | int64 customerIdLSB = 7; | 710 | int64 customerIdLSB = 7; |
711 | } | 711 | } |
712 | 712 | ||
713 | -message ToFirmwareStateServiceMsg { | 713 | +message ToOtaPackageStateServiceMsg { |
714 | int64 ts = 1; | 714 | int64 ts = 1; |
715 | int64 tenantIdMSB = 2; | 715 | int64 tenantIdMSB = 2; |
716 | int64 tenantIdLSB = 3; | 716 | int64 tenantIdLSB = 3; |
717 | int64 deviceIdMSB = 4; | 717 | int64 deviceIdMSB = 4; |
718 | int64 deviceIdLSB = 5; | 718 | int64 deviceIdLSB = 5; |
719 | - int64 firmwareIdMSB = 6; | ||
720 | - int64 firmwareIdLSB = 7; | 719 | + int64 otaPackageIdMSB = 6; |
720 | + int64 otaPackageIdLSB = 7; | ||
721 | string type = 8; | 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,7 +44,7 @@ import org.thingsboard.server.common.data.device.profile.DeviceProfileTransportC | ||
44 | import org.thingsboard.server.common.data.device.profile.JsonTransportPayloadConfiguration; | 44 | import org.thingsboard.server.common.data.device.profile.JsonTransportPayloadConfiguration; |
45 | import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration; | 45 | import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration; |
46 | import org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration; | 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 | import org.thingsboard.server.common.data.security.DeviceTokenCredentials; | 48 | import org.thingsboard.server.common.data.security.DeviceTokenCredentials; |
49 | import org.thingsboard.server.common.msg.session.FeatureType; | 49 | import org.thingsboard.server.common.msg.session.FeatureType; |
50 | import org.thingsboard.server.common.msg.session.SessionMsgType; | 50 | import org.thingsboard.server.common.msg.session.SessionMsgType; |
@@ -350,10 +350,10 @@ public class CoapTransportResource extends AbstractCoapTransportResource { | @@ -350,10 +350,10 @@ public class CoapTransportResource extends AbstractCoapTransportResource { | ||
350 | new CoapNoOpCallback(exchange)); | 350 | new CoapNoOpCallback(exchange)); |
351 | break; | 351 | break; |
352 | case GET_FIRMWARE_REQUEST: | 352 | case GET_FIRMWARE_REQUEST: |
353 | - getFirmwareCallback(sessionInfo, exchange, FirmwareType.FIRMWARE); | 353 | + getOtaPackageCallback(sessionInfo, exchange, OtaPackageType.FIRMWARE); |
354 | break; | 354 | break; |
355 | case GET_SOFTWARE_REQUEST: | 355 | case GET_SOFTWARE_REQUEST: |
356 | - getFirmwareCallback(sessionInfo, exchange, FirmwareType.SOFTWARE); | 356 | + getOtaPackageCallback(sessionInfo, exchange, OtaPackageType.SOFTWARE); |
357 | break; | 357 | break; |
358 | } | 358 | } |
359 | } catch (AdaptorException e) { | 359 | } catch (AdaptorException e) { |
@@ -366,14 +366,14 @@ public class CoapTransportResource extends AbstractCoapTransportResource { | @@ -366,14 +366,14 @@ public class CoapTransportResource extends AbstractCoapTransportResource { | ||
366 | return new UUID(sessionInfoProto.getSessionIdMSB(), sessionInfoProto.getSessionIdLSB()); | 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 | .setTenantIdMSB(sessionInfo.getTenantIdMSB()) | 371 | .setTenantIdMSB(sessionInfo.getTenantIdMSB()) |
372 | .setTenantIdLSB(sessionInfo.getTenantIdLSB()) | 372 | .setTenantIdLSB(sessionInfo.getTenantIdLSB()) |
373 | .setDeviceIdMSB(sessionInfo.getDeviceIdMSB()) | 373 | .setDeviceIdMSB(sessionInfo.getDeviceIdMSB()) |
374 | .setDeviceIdLSB(sessionInfo.getDeviceIdLSB()) | 374 | .setDeviceIdLSB(sessionInfo.getDeviceIdLSB()) |
375 | .setType(firmwareType.name()).build(); | 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 | private TransportProtos.SessionInfoProto lookupAsyncSessionInfo(String token) { | 379 | private TransportProtos.SessionInfoProto lookupAsyncSessionInfo(String token) { |
@@ -470,25 +470,25 @@ public class CoapTransportResource extends AbstractCoapTransportResource { | @@ -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 | private final CoapExchange exchange; | 474 | private final CoapExchange exchange; |
475 | 475 | ||
476 | - FirmwareCallback(CoapExchange exchange) { | 476 | + OtaPackageCallback(CoapExchange exchange) { |
477 | this.exchange = exchange; | 477 | this.exchange = exchange; |
478 | } | 478 | } |
479 | 479 | ||
480 | @Override | 480 | @Override |
481 | - public void onSuccess(TransportProtos.GetFirmwareResponseMsg msg) { | 481 | + public void onSuccess(TransportProtos.GetOtaPackageResponseMsg msg) { |
482 | String title = exchange.getQueryParameter("title"); | 482 | String title = exchange.getQueryParameter("title"); |
483 | String version = exchange.getQueryParameter("version"); | 483 | String version = exchange.getQueryParameter("version"); |
484 | if (msg.getResponseStatus().equals(TransportProtos.ResponseStatus.SUCCESS)) { | 484 | if (msg.getResponseStatus().equals(TransportProtos.ResponseStatus.SUCCESS)) { |
485 | if (msg.getTitle().equals(title) && msg.getVersion().equals(version)) { | 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 | String strChunkSize = exchange.getQueryParameter("size"); | 487 | String strChunkSize = exchange.getQueryParameter("size"); |
488 | String strChunk = exchange.getQueryParameter("chunk"); | 488 | String strChunk = exchange.getQueryParameter("chunk"); |
489 | int chunkSize = StringUtils.isEmpty(strChunkSize) ? 0 : Integer.parseInt(strChunkSize); | 489 | int chunkSize = StringUtils.isEmpty(strChunkSize) ? 0 : Integer.parseInt(strChunkSize); |
490 | int chunk = StringUtils.isEmpty(strChunk) ? 0 : Integer.parseInt(strChunk); | 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 | } else { | 492 | } else { |
493 | exchange.respond(CoAP.ResponseCode.BAD_REQUEST); | 493 | exchange.respond(CoAP.ResponseCode.BAD_REQUEST); |
494 | } | 494 | } |
@@ -34,7 +34,7 @@ import org.springframework.web.bind.annotation.RequestParam; | @@ -34,7 +34,7 @@ import org.springframework.web.bind.annotation.RequestParam; | ||
34 | import org.springframework.web.bind.annotation.RestController; | 34 | import org.springframework.web.bind.annotation.RestController; |
35 | import org.springframework.web.context.request.async.DeferredResult; | 35 | import org.springframework.web.context.request.async.DeferredResult; |
36 | import org.thingsboard.server.common.data.DeviceTransportType; | 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 | import org.thingsboard.server.common.data.TbTransportService; | 38 | import org.thingsboard.server.common.data.TbTransportService; |
39 | import org.thingsboard.server.common.data.id.DeviceId; | 39 | import org.thingsboard.server.common.data.id.DeviceId; |
40 | import org.thingsboard.server.common.transport.SessionMsgListener; | 40 | import org.thingsboard.server.common.transport.SessionMsgListener; |
@@ -213,7 +213,7 @@ public class DeviceApiController implements TbTransportService { | @@ -213,7 +213,7 @@ public class DeviceApiController implements TbTransportService { | ||
213 | @RequestParam(value = "version") String version, | 213 | @RequestParam(value = "version") String version, |
214 | @RequestParam(value = "size", required = false, defaultValue = "0") int size, | 214 | @RequestParam(value = "size", required = false, defaultValue = "0") int size, |
215 | @RequestParam(value = "chunk", required = false, defaultValue = "0") int chunk) { | 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 | @RequestMapping(value = "/{deviceToken}/software", method = RequestMethod.GET) | 219 | @RequestMapping(value = "/{deviceToken}/software", method = RequestMethod.GET) |
@@ -222,7 +222,7 @@ public class DeviceApiController implements TbTransportService { | @@ -222,7 +222,7 @@ public class DeviceApiController implements TbTransportService { | ||
222 | @RequestParam(value = "version") String version, | 222 | @RequestParam(value = "version") String version, |
223 | @RequestParam(value = "size", required = false, defaultValue = "0") int size, | 223 | @RequestParam(value = "size", required = false, defaultValue = "0") int size, |
224 | @RequestParam(value = "chunk", required = false, defaultValue = "0") int chunk) { | 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 | @RequestMapping(value = "/provision", method = RequestMethod.POST) | 228 | @RequestMapping(value = "/provision", method = RequestMethod.POST) |
@@ -233,17 +233,17 @@ public class DeviceApiController implements TbTransportService { | @@ -233,17 +233,17 @@ public class DeviceApiController implements TbTransportService { | ||
233 | return responseWriter; | 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 | DeferredResult<ResponseEntity> responseWriter = new DeferredResult<>(); | 237 | DeferredResult<ResponseEntity> responseWriter = new DeferredResult<>(); |
238 | transportContext.getTransportService().process(DeviceTransportType.DEFAULT, ValidateDeviceTokenRequestMsg.newBuilder().setToken(deviceToken).build(), | 238 | transportContext.getTransportService().process(DeviceTransportType.DEFAULT, ValidateDeviceTokenRequestMsg.newBuilder().setToken(deviceToken).build(), |
239 | new DeviceAuthCallback(transportContext, responseWriter, sessionInfo -> { | 239 | new DeviceAuthCallback(transportContext, responseWriter, sessionInfo -> { |
240 | - TransportProtos.GetFirmwareRequestMsg requestMsg = TransportProtos.GetFirmwareRequestMsg.newBuilder() | 240 | + TransportProtos.GetOtaPackageRequestMsg requestMsg = TransportProtos.GetOtaPackageRequestMsg.newBuilder() |
241 | .setTenantIdMSB(sessionInfo.getTenantIdMSB()) | 241 | .setTenantIdMSB(sessionInfo.getTenantIdMSB()) |
242 | .setTenantIdLSB(sessionInfo.getTenantIdLSB()) | 242 | .setTenantIdLSB(sessionInfo.getTenantIdLSB()) |
243 | .setDeviceIdMSB(sessionInfo.getDeviceIdMSB()) | 243 | .setDeviceIdMSB(sessionInfo.getDeviceIdMSB()) |
244 | .setDeviceIdLSB(sessionInfo.getDeviceIdLSB()) | 244 | .setDeviceIdLSB(sessionInfo.getDeviceIdLSB()) |
245 | .setType(firmwareType.name()).build(); | 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 | return responseWriter; | 248 | return responseWriter; |
249 | } | 249 | } |
@@ -294,14 +294,14 @@ public class DeviceApiController implements TbTransportService { | @@ -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 | private final DeferredResult<ResponseEntity> responseWriter; | 298 | private final DeferredResult<ResponseEntity> responseWriter; |
299 | private final String title; | 299 | private final String title; |
300 | private final String version; | 300 | private final String version; |
301 | private final int chuckSize; | 301 | private final int chuckSize; |
302 | private final int chuck; | 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 | this.responseWriter = responseWriter; | 305 | this.responseWriter = responseWriter; |
306 | this.title = title; | 306 | this.title = title; |
307 | this.version = version; | 307 | this.version = version; |
@@ -310,17 +310,17 @@ public class DeviceApiController implements TbTransportService { | @@ -310,17 +310,17 @@ public class DeviceApiController implements TbTransportService { | ||
310 | } | 310 | } |
311 | 311 | ||
312 | @Override | 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 | responseWriter.setResult(new ResponseEntity<>(HttpStatus.NOT_FOUND)); | 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 | ResponseEntity<ByteArrayResource> response = ResponseEntity.ok() | 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 | .contentLength(resource.contentLength()) | 322 | .contentLength(resource.contentLength()) |
323 | - .contentType(parseMediaType(firmwareResponseMsg.getContentType())) | 323 | + .contentType(parseMediaType(otaPackageResponseMsg.getContentType())) |
324 | .body(resource); | 324 | .body(resource); |
325 | responseWriter.setResult(response); | 325 | responseWriter.setResult(response); |
326 | } else { | 326 | } else { |
@@ -39,13 +39,13 @@ import org.springframework.context.annotation.Lazy; | @@ -39,13 +39,13 @@ import org.springframework.context.annotation.Lazy; | ||
39 | import org.springframework.stereotype.Service; | 39 | import org.springframework.stereotype.Service; |
40 | import org.thingsboard.common.util.JacksonUtil; | 40 | import org.thingsboard.common.util.JacksonUtil; |
41 | import org.thingsboard.common.util.ThingsBoardExecutors; | 41 | import org.thingsboard.common.util.ThingsBoardExecutors; |
42 | -import org.thingsboard.server.cache.firmware.FirmwareDataCache; | 42 | +import org.thingsboard.server.cache.ota.OtaPackageDataCache; |
43 | import org.thingsboard.server.common.data.Device; | 43 | import org.thingsboard.server.common.data.Device; |
44 | import org.thingsboard.server.common.data.DeviceProfile; | 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 | import org.thingsboard.server.common.transport.TransportService; | 49 | import org.thingsboard.server.common.transport.TransportService; |
50 | import org.thingsboard.server.common.transport.TransportServiceCallback; | 50 | import org.thingsboard.server.common.transport.TransportServiceCallback; |
51 | import org.thingsboard.server.common.transport.adaptor.AdaptorException; | 51 | import org.thingsboard.server.common.transport.adaptor.AdaptorException; |
@@ -87,8 +87,8 @@ import java.util.stream.Collectors; | @@ -87,8 +87,8 @@ import java.util.stream.Collectors; | ||
87 | 87 | ||
88 | import static org.eclipse.californium.core.coap.CoAP.ResponseCode.BAD_REQUEST; | 88 | import static org.eclipse.californium.core.coap.CoAP.ResponseCode.BAD_REQUEST; |
89 | import static org.eclipse.leshan.core.attributes.Attribute.OBJECT_VERSION; | 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 | import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH; | 92 | import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH; |
93 | import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportServerHelper.getValueFromKvProto; | 93 | import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportServerHelper.getValueFromKvProto; |
94 | import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.CLIENT_NOT_AUTHORIZED; | 94 | import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.CLIENT_NOT_AUTHORIZED; |
@@ -132,7 +132,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | @@ -132,7 +132,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | ||
132 | private final TransportService transportService; | 132 | private final TransportService transportService; |
133 | private final LwM2mTransportContext context; | 133 | private final LwM2mTransportContext context; |
134 | public final LwM2MTransportServerConfig config; | 134 | public final LwM2MTransportServerConfig config; |
135 | - public final FirmwareDataCache firmwareDataCache; | 135 | + public final OtaPackageDataCache otaPackageDataCache; |
136 | public final LwM2mTransportServerHelper helper; | 136 | public final LwM2mTransportServerHelper helper; |
137 | private final LwM2MJsonAdaptor adaptor; | 137 | private final LwM2MJsonAdaptor adaptor; |
138 | private final TbLwM2MDtlsSessionStore sessionStore; | 138 | private final TbLwM2MDtlsSessionStore sessionStore; |
@@ -143,14 +143,14 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | @@ -143,14 +143,14 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | ||
143 | public DefaultLwM2MTransportMsgHandler(TransportService transportService, LwM2MTransportServerConfig config, LwM2mTransportServerHelper helper, | 143 | public DefaultLwM2MTransportMsgHandler(TransportService transportService, LwM2MTransportServerConfig config, LwM2mTransportServerHelper helper, |
144 | LwM2mClientContext clientContext, | 144 | LwM2mClientContext clientContext, |
145 | @Lazy LwM2mTransportRequest lwM2mTransportRequest, | 145 | @Lazy LwM2mTransportRequest lwM2mTransportRequest, |
146 | - FirmwareDataCache firmwareDataCache, | 146 | + OtaPackageDataCache otaPackageDataCache, |
147 | LwM2mTransportContext context, LwM2MJsonAdaptor adaptor, TbLwM2MDtlsSessionStore sessionStore) { | 147 | LwM2mTransportContext context, LwM2MJsonAdaptor adaptor, TbLwM2MDtlsSessionStore sessionStore) { |
148 | this.transportService = transportService; | 148 | this.transportService = transportService; |
149 | this.config = config; | 149 | this.config = config; |
150 | this.helper = helper; | 150 | this.helper = helper; |
151 | this.clientContext = clientContext; | 151 | this.clientContext = clientContext; |
152 | this.lwM2mTransportRequest = lwM2mTransportRequest; | 152 | this.lwM2mTransportRequest = lwM2mTransportRequest; |
153 | - this.firmwareDataCache = firmwareDataCache; | 153 | + this.otaPackageDataCache = otaPackageDataCache; |
154 | this.context = context; | 154 | this.context = context; |
155 | this.adaptor = adaptor; | 155 | this.adaptor = adaptor; |
156 | this.rpcSubscriptions = new ConcurrentHashMap<>(); | 156 | this.rpcSubscriptions = new ConcurrentHashMap<>(); |
@@ -247,7 +247,6 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | @@ -247,7 +247,6 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | ||
247 | * @param observations - !!! Warn: if have not finishing unReg, then this operation will be finished on next Client`s connect | 247 | * @param observations - !!! Warn: if have not finishing unReg, then this operation will be finished on next Client`s connect |
248 | */ | 248 | */ |
249 | public void unReg(Registration registration, Collection<Observation> observations) { | 249 | public void unReg(Registration registration, Collection<Observation> observations) { |
250 | - log.error("Client unRegistration -> test", new RuntimeException()); | ||
251 | unRegistrationExecutor.submit(() -> { | 250 | unRegistrationExecutor.submit(() -> { |
252 | try { | 251 | try { |
253 | this.sendLogsToThingsboard(LOG_LW2M_INFO + ": Client unRegistration", registration.getId()); | 252 | this.sendLogsToThingsboard(LOG_LW2M_INFO + ": Client unRegistration", registration.getId()); |
@@ -357,14 +356,14 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | @@ -357,14 +356,14 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | ||
357 | String pathName = tsKvProto.getKv().getKey(); | 356 | String pathName = tsKvProto.getKv().getKey(); |
358 | String pathIdVer = this.getPresentPathIntoProfile(sessionInfo, pathName); | 357 | String pathIdVer = this.getPresentPathIntoProfile(sessionInfo, pathName); |
359 | Object valueNew = getValueFromKvProto(tsKvProto.getKv()); | 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 | && (!valueNew.equals(lwM2MClient.getFwUpdate().getCurrentVersion()))) | 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 | && (!valueNew.equals(lwM2MClient.getFwUpdate().getCurrentTitle())))) { | 362 | && (!valueNew.equals(lwM2MClient.getFwUpdate().getCurrentTitle())))) { |
364 | this.getInfoFirmwareUpdate(lwM2MClient); | 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 | && (!valueNew.equals(lwM2MClient.getSwUpdate().getCurrentVersion()))) | 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 | && (!valueNew.equals(lwM2MClient.getSwUpdate().getCurrentTitle())))) { | 367 | && (!valueNew.equals(lwM2MClient.getSwUpdate().getCurrentTitle())))) { |
369 | this.getInfoSoftwareUpdate(lwM2MClient); | 368 | this.getInfoSoftwareUpdate(lwM2MClient); |
370 | } | 369 | } |
@@ -391,7 +390,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | @@ -391,7 +390,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | ||
391 | msg.getSharedUpdatedList().forEach(tsKvProto -> { | 390 | msg.getSharedUpdatedList().forEach(tsKvProto -> { |
392 | String pathName = tsKvProto.getKv().getKey(); | 391 | String pathName = tsKvProto.getKv().getKey(); |
393 | Object valueNew = getValueFromKvProto(tsKvProto.getKv()); | 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 | lwM2MClient.getFwUpdate().setCurrentVersion((String) valueNew); | 394 | lwM2MClient.getFwUpdate().setCurrentVersion((String) valueNew); |
396 | } | 395 | } |
397 | }); | 396 | }); |
@@ -1344,18 +1343,18 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | @@ -1344,18 +1343,18 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | ||
1344 | if (lwM2MClient.getRegistration().getSupportedVersion(FW_ID) != null) { | 1343 | if (lwM2MClient.getRegistration().getSupportedVersion(FW_ID) != null) { |
1345 | SessionInfoProto sessionInfo = this.getSessionInfoOrCloseSession(lwM2MClient); | 1344 | SessionInfoProto sessionInfo = this.getSessionInfoOrCloseSession(lwM2MClient); |
1346 | if (sessionInfo != null) { | 1345 | if (sessionInfo != null) { |
1347 | - transportService.process(sessionInfo, createFirmwareRequestMsg(sessionInfo, FirmwareType.FIRMWARE.name()), | 1346 | + transportService.process(sessionInfo, createOtaPackageRequestMsg(sessionInfo, OtaPackageType.FIRMWARE.name()), |
1348 | new TransportServiceCallback<>() { | 1347 | new TransportServiceCallback<>() { |
1349 | @Override | 1348 | @Override |
1350 | - public void onSuccess(TransportProtos.GetFirmwareResponseMsg response) { | 1349 | + public void onSuccess(TransportProtos.GetOtaPackageResponseMsg response) { |
1351 | if (TransportProtos.ResponseStatus.SUCCESS.equals(response.getResponseStatus()) | 1350 | if (TransportProtos.ResponseStatus.SUCCESS.equals(response.getResponseStatus()) |
1352 | - && response.getType().equals(FirmwareType.FIRMWARE.name())) { | 1351 | + && response.getType().equals(OtaPackageType.FIRMWARE.name())) { |
1353 | lwM2MClient.getFwUpdate().setCurrentVersion(response.getVersion()); | 1352 | lwM2MClient.getFwUpdate().setCurrentVersion(response.getVersion()); |
1354 | lwM2MClient.getFwUpdate().setCurrentTitle(response.getTitle()); | 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 | lwM2MClient.getFwUpdate().sendReadObserveInfo(lwM2mTransportRequest); | 1355 | lwM2MClient.getFwUpdate().sendReadObserveInfo(lwM2mTransportRequest); |
1357 | } else { | 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,15 +1372,15 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | ||
1373 | SessionInfoProto sessionInfo = this.getSessionInfoOrCloseSession(lwM2MClient); | 1372 | SessionInfoProto sessionInfo = this.getSessionInfoOrCloseSession(lwM2MClient); |
1374 | if (sessionInfo != null) { | 1373 | if (sessionInfo != null) { |
1375 | DefaultLwM2MTransportMsgHandler serviceImpl = this; | 1374 | DefaultLwM2MTransportMsgHandler serviceImpl = this; |
1376 | - transportService.process(sessionInfo, createFirmwareRequestMsg(sessionInfo, FirmwareType.SOFTWARE.name()), | 1375 | + transportService.process(sessionInfo, createOtaPackageRequestMsg(sessionInfo, OtaPackageType.SOFTWARE.name()), |
1377 | new TransportServiceCallback<>() { | 1376 | new TransportServiceCallback<>() { |
1378 | @Override | 1377 | @Override |
1379 | - public void onSuccess(TransportProtos.GetFirmwareResponseMsg response) { | 1378 | + public void onSuccess(TransportProtos.GetOtaPackageResponseMsg response) { |
1380 | if (TransportProtos.ResponseStatus.SUCCESS.equals(response.getResponseStatus()) | 1379 | if (TransportProtos.ResponseStatus.SUCCESS.equals(response.getResponseStatus()) |
1381 | - && response.getType().equals(FirmwareType.SOFTWARE.name())) { | 1380 | + && response.getType().equals(OtaPackageType.SOFTWARE.name())) { |
1382 | lwM2MClient.getSwUpdate().setCurrentVersion(response.getVersion()); | 1381 | lwM2MClient.getSwUpdate().setCurrentVersion(response.getVersion()); |
1383 | lwM2MClient.getSwUpdate().setCurrentTitle(response.getTitle()); | 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 | lwM2MClient.getSwUpdate().sendReadObserveInfo(lwM2mTransportRequest); | 1384 | lwM2MClient.getSwUpdate().sendReadObserveInfo(lwM2mTransportRequest); |
1386 | } else { | 1385 | } else { |
1387 | log.trace("Software [{}] [{}]", lwM2MClient.getDeviceName(), response.getResponseStatus().toString()); | 1386 | log.trace("Software [{}] [{}]", lwM2MClient.getDeviceName(), response.getResponseStatus().toString()); |
@@ -1397,8 +1396,8 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler | @@ -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 | .setDeviceIdMSB(sessionInfo.getDeviceIdMSB()) | 1401 | .setDeviceIdMSB(sessionInfo.getDeviceIdMSB()) |
1403 | .setDeviceIdLSB(sessionInfo.getDeviceIdLSB()) | 1402 | .setDeviceIdLSB(sessionInfo.getDeviceIdLSB()) |
1404 | .setTenantIdMSB(sessionInfo.getTenantIdMSB()) | 1403 | .setTenantIdMSB(sessionInfo.getTenantIdMSB()) |
@@ -71,8 +71,8 @@ import java.util.stream.Collectors; | @@ -71,8 +71,8 @@ import java.util.stream.Collectors; | ||
71 | import static org.eclipse.californium.core.coap.CoAP.ResponseCode.CONTENT; | 71 | import static org.eclipse.californium.core.coap.CoAP.ResponseCode.CONTENT; |
72 | import static org.eclipse.leshan.core.ResponseCode.BAD_REQUEST; | 72 | import static org.eclipse.leshan.core.ResponseCode.BAD_REQUEST; |
73 | import static org.eclipse.leshan.core.ResponseCode.NOT_FOUND; | 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 | import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportServerHelper.getContentFormatByResourceModelType; | 76 | import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportServerHelper.getContentFormatByResourceModelType; |
77 | import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.DEFAULT_TIMEOUT; | 77 | import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.DEFAULT_TIMEOUT; |
78 | import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_PACKAGE_ID; | 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,10 +43,10 @@ import org.eclipse.leshan.server.registration.Registration; | ||
43 | import org.nustaq.serialization.FSTConfiguration; | 43 | import org.nustaq.serialization.FSTConfiguration; |
44 | import org.thingsboard.server.common.data.DeviceProfile; | 44 | import org.thingsboard.server.common.data.DeviceProfile; |
45 | import org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration; | 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 | import org.thingsboard.server.common.data.id.TenantId; | 50 | import org.thingsboard.server.common.data.id.TenantId; |
51 | import org.thingsboard.server.common.transport.TransportServiceCallback; | 51 | import org.thingsboard.server.common.transport.TransportServiceCallback; |
52 | import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient; | 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,12 +77,12 @@ import static org.eclipse.leshan.core.model.ResourceModel.Type.OBJLNK; | ||
77 | import static org.eclipse.leshan.core.model.ResourceModel.Type.OPAQUE; | 77 | import static org.eclipse.leshan.core.model.ResourceModel.Type.OPAQUE; |
78 | import static org.eclipse.leshan.core.model.ResourceModel.Type.STRING; | 78 | import static org.eclipse.leshan.core.model.ResourceModel.Type.STRING; |
79 | import static org.eclipse.leshan.core.model.ResourceModel.Type.TIME; | 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 | import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_KEY; | 86 | import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_KEY; |
87 | import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH; | 87 | import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH; |
88 | 88 | ||
@@ -139,7 +139,7 @@ public class LwM2mTransportUtil { | @@ -139,7 +139,7 @@ public class LwM2mTransportUtil { | ||
139 | public static final String ERROR_KEY = "error"; | 139 | public static final String ERROR_KEY = "error"; |
140 | public static final String METHOD_KEY = "methodName"; | 140 | public static final String METHOD_KEY = "methodName"; |
141 | 141 | ||
142 | - // FirmWare | 142 | + // Firmware |
143 | public static final String FW_UPDATE = "Firmware update"; | 143 | public static final String FW_UPDATE = "Firmware update"; |
144 | public static final Integer FW_ID = 5; | 144 | public static final Integer FW_ID = 5; |
145 | // Package W | 145 | // Package W |
@@ -155,7 +155,7 @@ public class LwM2mTransportUtil { | @@ -155,7 +155,7 @@ public class LwM2mTransportUtil { | ||
155 | // Update E | 155 | // Update E |
156 | public static final String FW_UPDATE_ID = "/5/0/2"; | 156 | public static final String FW_UPDATE_ID = "/5/0/2"; |
157 | 157 | ||
158 | - // SoftWare | 158 | + // Software |
159 | public static final String SW_UPDATE = "Software update"; | 159 | public static final String SW_UPDATE = "Software update"; |
160 | public static final Integer SW_ID = 9; | 160 | public static final Integer SW_ID = 9; |
161 | // Package W | 161 | // Package W |
@@ -354,7 +354,7 @@ public class LwM2mTransportUtil { | @@ -354,7 +354,7 @@ public class LwM2mTransportUtil { | ||
354 | * FirmwareUpdateStatus { | 354 | * FirmwareUpdateStatus { |
355 | * DOWNLOADING, DOWNLOADED, VERIFIED, UPDATING, UPDATED, FAILED | 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 | switch (updateResultFw) { | 358 | switch (updateResultFw) { |
359 | case INITIAL: | 359 | case INITIAL: |
360 | switch (stateFw) { | 360 | switch (stateFw) { |
@@ -500,7 +500,7 @@ public class LwM2mTransportUtil { | @@ -500,7 +500,7 @@ public class LwM2mTransportUtil { | ||
500 | * FirmwareUpdateStatus { | 500 | * FirmwareUpdateStatus { |
501 | * DOWNLOADING, DOWNLOADED, VERIFIED, UPDATING, UPDATED, FAILED | 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 | switch (updateResultSw) { | 504 | switch (updateResultSw) { |
505 | case INITIAL: | 505 | case INITIAL: |
506 | switch (updateStateSw) { | 506 | switch (updateStateSw) { |
@@ -932,15 +932,15 @@ public class LwM2mTransportUtil { | @@ -932,15 +932,15 @@ public class LwM2mTransportUtil { | ||
932 | } | 932 | } |
933 | 933 | ||
934 | public static boolean isFwSwWords (String pathName) { | 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,7 +31,7 @@ import org.eclipse.leshan.server.registration.Registration; | ||
31 | import org.eclipse.leshan.server.security.SecurityInfo; | 31 | import org.eclipse.leshan.server.security.SecurityInfo; |
32 | import org.thingsboard.server.common.data.Device; | 32 | import org.thingsboard.server.common.data.Device; |
33 | import org.thingsboard.server.common.data.DeviceProfile; | 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 | import org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse; | 35 | import org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse; |
36 | import org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto; | 36 | import org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto; |
37 | import org.thingsboard.server.gen.transport.TransportProtos.TsKvProto; | 37 | import org.thingsboard.server.gen.transport.TransportProtos.TsKvProto; |
@@ -120,8 +120,8 @@ public class LwM2mClient implements Cloneable { | @@ -120,8 +120,8 @@ public class LwM2mClient implements Cloneable { | ||
120 | this.init = false; | 120 | this.init = false; |
121 | this.queuedRequests = new ConcurrentLinkedQueue<>(); | 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 | if (this.credentials != null && this.credentials.hasDeviceInfo()) { | 125 | if (this.credentials != null && this.credentials.hasDeviceInfo()) { |
126 | this.session = createSession(nodeId, sessionId, credentials); | 126 | this.session = createSession(nodeId, sessionId, credentials); |
127 | this.deviceId = new UUID(session.getDeviceIdMSB(), session.getDeviceIdLSB()); | 127 | this.deviceId = new UUID(session.getDeviceIdMSB(), session.getDeviceIdLSB()); |
@@ -20,8 +20,8 @@ import lombok.Setter; | @@ -20,8 +20,8 @@ import lombok.Setter; | ||
20 | import lombok.extern.slf4j.Slf4j; | 20 | import lombok.extern.slf4j.Slf4j; |
21 | import org.apache.commons.lang3.StringUtils; | 21 | import org.apache.commons.lang3.StringUtils; |
22 | import org.eclipse.leshan.core.request.ContentFormat; | 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 | import org.thingsboard.server.gen.transport.TransportProtos; | 25 | import org.thingsboard.server.gen.transport.TransportProtos; |
26 | import org.thingsboard.server.transport.lwm2m.server.DefaultLwM2MTransportMsgHandler; | 26 | import org.thingsboard.server.transport.lwm2m.server.DefaultLwM2MTransportMsgHandler; |
27 | import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportRequest; | 27 | import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportRequest; |
@@ -32,11 +32,11 @@ import java.util.List; | @@ -32,11 +32,11 @@ import java.util.List; | ||
32 | import java.util.UUID; | 32 | import java.util.UUID; |
33 | import java.util.concurrent.CopyOnWriteArrayList; | 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 | import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_NAME_ID; | 40 | import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_NAME_ID; |
41 | import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_PACKAGE_ID; | 41 | import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_PACKAGE_ID; |
42 | import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_RESULT_ID; | 42 | import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_RESULT_ID; |
@@ -97,14 +97,14 @@ public class LwM2mFwSwUpdate { | @@ -97,14 +97,14 @@ public class LwM2mFwSwUpdate { | ||
97 | @Getter | 97 | @Getter |
98 | @Setter | 98 | @Setter |
99 | private volatile boolean infoFwSwUpdate = false; | 99 | private volatile boolean infoFwSwUpdate = false; |
100 | - private final FirmwareType type; | 100 | + private final OtaPackageType type; |
101 | @Getter | 101 | @Getter |
102 | LwM2mClient lwM2MClient; | 102 | LwM2mClient lwM2MClient; |
103 | @Getter | 103 | @Getter |
104 | @Setter | 104 | @Setter |
105 | private final List<String> pendingInfoRequestsStart; | 105 | private final List<String> pendingInfoRequestsStart; |
106 | 106 | ||
107 | - public LwM2mFwSwUpdate(LwM2mClient lwM2MClient, FirmwareType type) { | 107 | + public LwM2mFwSwUpdate(LwM2mClient lwM2MClient, OtaPackageType type) { |
108 | this.lwM2MClient = lwM2MClient; | 108 | this.lwM2MClient = lwM2MClient; |
109 | this.pendingInfoRequestsStart = new CopyOnWriteArrayList<>(); | 109 | this.pendingInfoRequestsStart = new CopyOnWriteArrayList<>(); |
110 | this.type = type; | 110 | this.type = type; |
@@ -139,7 +139,7 @@ public class LwM2mFwSwUpdate { | @@ -139,7 +139,7 @@ public class LwM2mFwSwUpdate { | ||
139 | } | 139 | } |
140 | if (this.pendingInfoRequestsStart.size() == 0) { | 140 | if (this.pendingInfoRequestsStart.size() == 0) { |
141 | this.infoFwSwUpdate = false; | 141 | this.infoFwSwUpdate = false; |
142 | - if (!FirmwareUpdateStatus.DOWNLOADING.name().equals(this.stateUpdate)) { | 142 | + if (!OtaPackageUpdateStatus.DOWNLOADING.name().equals(this.stateUpdate)) { |
143 | boolean conditionalStart = this.type.equals(FIRMWARE) ? this.conditionalFwUpdateStart() : | 143 | boolean conditionalStart = this.type.equals(FIRMWARE) ? this.conditionalFwUpdateStart() : |
144 | this.conditionalSwUpdateStart(); | 144 | this.conditionalSwUpdateStart(); |
145 | if (conditionalStart) { | 145 | if (conditionalStart) { |
@@ -154,12 +154,12 @@ public class LwM2mFwSwUpdate { | @@ -154,12 +154,12 @@ public class LwM2mFwSwUpdate { | ||
154 | * before operation Write: fw_state = DOWNLOADING | 154 | * before operation Write: fw_state = DOWNLOADING |
155 | */ | 155 | */ |
156 | private void writeFwSwWare(DefaultLwM2MTransportMsgHandler handler, LwM2mTransportRequest request) { | 156 | private void writeFwSwWare(DefaultLwM2MTransportMsgHandler handler, LwM2mTransportRequest request) { |
157 | - this.stateUpdate = FirmwareUpdateStatus.DOWNLOADING.name(); | 157 | + this.stateUpdate = OtaPackageUpdateStatus.DOWNLOADING.name(); |
158 | // this.observeStateUpdate(); | 158 | // this.observeStateUpdate(); |
159 | this.sendLogs(handler, WRITE_REPLACE.name(), LOG_LW2M_INFO, null); | 159 | this.sendLogs(handler, WRITE_REPLACE.name(), LOG_LW2M_INFO, null); |
160 | int chunkSize = 0; | 160 | int chunkSize = 0; |
161 | int chunk = 0; | 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 | String targetIdVer = convertPathFromObjectIdToIdVer(this.pathPackageId, this.lwM2MClient.getRegistration()); | 163 | String targetIdVer = convertPathFromObjectIdToIdVer(this.pathPackageId, this.lwM2MClient.getRegistration()); |
164 | request.sendAllRequest(lwM2MClient.getRegistration(), targetIdVer, WRITE_REPLACE, ContentFormat.OPAQUE.getName(), | 164 | request.sendAllRequest(lwM2MClient.getRegistration(), targetIdVer, WRITE_REPLACE, ContentFormat.OPAQUE.getName(), |
165 | firmwareChunk, handler.config.getTimeout(), null); | 165 | firmwareChunk, handler.config.getTimeout(), null); |
@@ -287,10 +287,10 @@ public class LwM2mFwSwUpdate { | @@ -287,10 +287,10 @@ public class LwM2mFwSwUpdate { | ||
287 | LwM2mTransportUtil.UpdateResultSw.fromUpdateResultSwByCode(updateResult.intValue()).type; | 287 | LwM2mTransportUtil.UpdateResultSw.fromUpdateResultSwByCode(updateResult.intValue()).type; |
288 | String key = splitCamelCaseString((String) this.lwM2MClient.getResourceNameByRezId(null, this.pathResultId)); | 288 | String key = splitCamelCaseString((String) this.lwM2MClient.getResourceNameByRezId(null, this.pathResultId)); |
289 | if (success) { | 289 | if (success) { |
290 | - this.stateUpdate = FirmwareUpdateStatus.UPDATED.name(); | 290 | + this.stateUpdate = OtaPackageUpdateStatus.UPDATED.name(); |
291 | this.sendLogs(handler, EXECUTE.name(), LOG_LW2M_INFO, null); | 291 | this.sendLogs(handler, EXECUTE.name(), LOG_LW2M_INFO, null); |
292 | } else { | 292 | } else { |
293 | - this.stateUpdate = FirmwareUpdateStatus.FAILED.name(); | 293 | + this.stateUpdate = OtaPackageUpdateStatus.FAILED.name(); |
294 | this.sendLogs(handler, EXECUTE.name(), LOG_LW2M_ERROR, value); | 294 | this.sendLogs(handler, EXECUTE.name(), LOG_LW2M_ERROR, value); |
295 | } | 295 | } |
296 | handler.helper.sendParametersOnThingsboardTelemetry( | 296 | handler.helper.sendParametersOnThingsboardTelemetry( |
@@ -337,23 +337,24 @@ public class TbLwM2mRedisRegistrationStore implements CaliforniumRegistrationSto | @@ -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 | private void removeAddrIndex(RedisConnection connection, Registration registration) { | 341 | private void removeAddrIndex(RedisConnection connection, Registration registration) { |
341 | // Watch the key to remove. | 342 | // Watch the key to remove. |
342 | byte[] regAddrKey = toRegAddrKey(registration.getSocketAddress()); | 343 | byte[] regAddrKey = toRegAddrKey(registration.getSocketAddress()); |
343 | - connection.watch(regAddrKey); | 344 | +// connection.watch(regAddrKey); |
344 | 345 | ||
345 | byte[] epFromAddr = connection.get(regAddrKey); | 346 | byte[] epFromAddr = connection.get(regAddrKey); |
346 | // Delete the key if needed. | 347 | // Delete the key if needed. |
347 | if (Arrays.equals(epFromAddr, registration.getEndpoint().getBytes(UTF_8))) { | 348 | if (Arrays.equals(epFromAddr, registration.getEndpoint().getBytes(UTF_8))) { |
348 | // Try to delete the key | 349 | // Try to delete the key |
349 | - connection.multi(); | 350 | +// connection.multi(); |
350 | connection.del(regAddrKey); | 351 | connection.del(regAddrKey); |
351 | - connection.exec(); | 352 | +// connection.exec(); |
352 | // if transaction failed this is not an issue as the socket address is probably reused and we don't neeed to | 353 | // if transaction failed this is not an issue as the socket address is probably reused and we don't neeed to |
353 | // delete it anymore. | 354 | // delete it anymore. |
354 | } else { | 355 | } else { |
355 | // the key must not be deleted. | 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,8 +47,8 @@ import org.thingsboard.server.common.data.DeviceProfile; | ||
47 | import org.thingsboard.server.common.data.DeviceTransportType; | 47 | import org.thingsboard.server.common.data.DeviceTransportType; |
48 | import org.thingsboard.server.common.data.TransportPayloadType; | 48 | import org.thingsboard.server.common.data.TransportPayloadType; |
49 | import org.thingsboard.server.common.data.device.profile.MqttTopics; | 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 | import org.thingsboard.server.common.msg.EncryptionUtil; | 52 | import org.thingsboard.server.common.msg.EncryptionUtil; |
53 | import org.thingsboard.server.common.msg.tools.TbRateLimitsException; | 53 | import org.thingsboard.server.common.msg.tools.TbRateLimitsException; |
54 | import org.thingsboard.server.common.transport.SessionMsgListener; | 54 | import org.thingsboard.server.common.transport.SessionMsgListener; |
@@ -126,8 +126,8 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement | @@ -126,8 +126,8 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement | ||
126 | private volatile InetSocketAddress address; | 126 | private volatile InetSocketAddress address; |
127 | private volatile GatewaySessionHandler gatewaySessionHandler; | 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 | MqttTransportHandler(MqttTransportContext context, SslHandler sslHandler) { | 132 | MqttTransportHandler(MqttTransportContext context, SslHandler sslHandler) { |
133 | this.sessionId = UUID.randomUUID(); | 133 | this.sessionId = UUID.randomUUID(); |
@@ -137,8 +137,8 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement | @@ -137,8 +137,8 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement | ||
137 | this.sslHandler = sslHandler; | 137 | this.sslHandler = sslHandler; |
138 | this.mqttQoSMap = new ConcurrentHashMap<>(); | 138 | this.mqttQoSMap = new ConcurrentHashMap<>(); |
139 | this.deviceSessionCtx = new DeviceSessionCtx(sessionId, mqttQoSMap, context); | 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 | @Override | 144 | @Override |
@@ -320,9 +320,9 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement | @@ -320,9 +320,9 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement | ||
320 | TransportProtos.ClaimDeviceMsg claimDeviceMsg = payloadAdaptor.convertToClaimDevice(deviceSessionCtx, mqttMsg); | 320 | TransportProtos.ClaimDeviceMsg claimDeviceMsg = payloadAdaptor.convertToClaimDevice(deviceSessionCtx, mqttMsg); |
321 | transportService.process(deviceSessionCtx.getSessionInfo(), claimDeviceMsg, getPubAckCallback(ctx, msgId, claimDeviceMsg)); | 321 | transportService.process(deviceSessionCtx.getSessionInfo(), claimDeviceMsg, getPubAckCallback(ctx, msgId, claimDeviceMsg)); |
322 | } else if ((fwMatcher = FW_REQUEST_PATTERN.matcher(topicName)).find()) { | 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 | } else if ((fwMatcher = SW_REQUEST_PATTERN.matcher(topicName)).find()) { | 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 | } else { | 326 | } else { |
327 | transportService.reportActivity(deviceSessionCtx.getSessionInfo()); | 327 | transportService.reportActivity(deviceSessionCtx.getSessionInfo()); |
328 | ack(ctx, msgId); | 328 | ack(ctx, msgId); |
@@ -334,38 +334,38 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement | @@ -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 | String payload = mqttMsg.content().toString(UTF8); | 338 | String payload = mqttMsg.content().toString(UTF8); |
339 | int chunkSize = StringUtils.isNotEmpty(payload) ? Integer.parseInt(payload) : 0; | 339 | int chunkSize = StringUtils.isNotEmpty(payload) ? Integer.parseInt(payload) : 0; |
340 | String requestId = fwMatcher.group("requestId"); | 340 | String requestId = fwMatcher.group("requestId"); |
341 | int chunk = Integer.parseInt(fwMatcher.group("chunk")); | 341 | int chunk = Integer.parseInt(fwMatcher.group("chunk")); |
342 | 342 | ||
343 | if (chunkSize > 0) { | 343 | if (chunkSize > 0) { |
344 | - this.fwChunkSizes.put(requestId, chunkSize); | 344 | + this.chunkSizes.put(requestId, chunkSize); |
345 | } else { | 345 | } else { |
346 | - chunkSize = fwChunkSizes.getOrDefault(requestId, 0); | 346 | + chunkSize = chunkSizes.getOrDefault(requestId, 0); |
347 | } | 347 | } |
348 | 348 | ||
349 | if (chunkSize > context.getMaxPayloadSize()) { | 349 | if (chunkSize > context.getMaxPayloadSize()) { |
350 | - sendFirmwareError(ctx, PAYLOAD_TOO_LARGE); | 350 | + sendOtaPackageError(ctx, PAYLOAD_TOO_LARGE); |
351 | return; | 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 | } else { | 358 | } else { |
359 | TransportProtos.SessionInfoProto sessionInfo = deviceSessionCtx.getSessionInfo(); | 359 | TransportProtos.SessionInfoProto sessionInfo = deviceSessionCtx.getSessionInfo(); |
360 | - TransportProtos.GetFirmwareRequestMsg getFirmwareRequestMsg = TransportProtos.GetFirmwareRequestMsg.newBuilder() | 360 | + TransportProtos.GetOtaPackageRequestMsg getOtaPackageRequestMsg = TransportProtos.GetOtaPackageRequestMsg.newBuilder() |
361 | .setDeviceIdMSB(sessionInfo.getDeviceIdMSB()) | 361 | .setDeviceIdMSB(sessionInfo.getDeviceIdMSB()) |
362 | .setDeviceIdLSB(sessionInfo.getDeviceIdLSB()) | 362 | .setDeviceIdLSB(sessionInfo.getDeviceIdLSB()) |
363 | .setTenantIdMSB(sessionInfo.getTenantIdMSB()) | 363 | .setTenantIdMSB(sessionInfo.getTenantIdMSB()) |
364 | .setTenantIdLSB(sessionInfo.getTenantIdLSB()) | 364 | .setTenantIdLSB(sessionInfo.getTenantIdLSB()) |
365 | .setType(type.name()) | 365 | .setType(type.name()) |
366 | .build(); | 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,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 | private final ChannelHandlerContext ctx; | 429 | private final ChannelHandlerContext ctx; |
430 | private final int msgId; | 430 | private final int msgId; |
431 | - private final TransportProtos.GetFirmwareRequestMsg msg; | 431 | + private final TransportProtos.GetOtaPackageRequestMsg msg; |
432 | private final String requestId; | 432 | private final String requestId; |
433 | private final int chunkSize; | 433 | private final int chunkSize; |
434 | private final int chunk; | 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 | this.ctx = ctx; | 437 | this.ctx = ctx; |
438 | this.msgId = msgId; | 438 | this.msgId = msgId; |
439 | this.msg = msg; | 439 | this.msg = msg; |
@@ -443,13 +443,13 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement | @@ -443,13 +443,13 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement | ||
443 | } | 443 | } |
444 | 444 | ||
445 | @Override | 445 | @Override |
446 | - public void onSuccess(TransportProtos.GetFirmwareResponseMsg response) { | 446 | + public void onSuccess(TransportProtos.GetOtaPackageResponseMsg response) { |
447 | if (TransportProtos.ResponseStatus.SUCCESS.equals(response.getResponseStatus())) { | 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 | } else { | 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,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 | log.trace("[{}] Send firmware [{}] to device!", sessionId, firmwareId); | 464 | log.trace("[{}] Send firmware [{}] to device!", sessionId, firmwareId); |
465 | ack(ctx, msgId); | 465 | ack(ctx, msgId); |
466 | try { | 466 | try { |
467 | - byte[] firmwareChunk = context.getFirmwareDataCache().get(firmwareId, chunkSize, chunk); | 467 | + byte[] firmwareChunk = context.getOtaPackageDataCache().get(firmwareId, chunkSize, chunk); |
468 | deviceSessionCtx.getPayloadAdaptor() | 468 | deviceSessionCtx.getPayloadAdaptor() |
469 | .convertToPublish(deviceSessionCtx, firmwareChunk, requestId, chunk, type) | 469 | .convertToPublish(deviceSessionCtx, firmwareChunk, requestId, chunk, type) |
470 | .ifPresent(deviceSessionCtx.getChannel()::writeAndFlush); | 470 | .ifPresent(deviceSessionCtx.getChannel()::writeAndFlush); |
@@ -473,7 +473,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement | @@ -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 | log.warn("[{}] {}", sessionId, error); | 477 | log.warn("[{}] {}", sessionId, error); |
478 | deviceSessionCtx.getChannel().writeAndFlush(deviceSessionCtx | 478 | deviceSessionCtx.getChannel().writeAndFlush(deviceSessionCtx |
479 | .getPayloadAdaptor() | 479 | .getPayloadAdaptor() |
@@ -30,7 +30,7 @@ import lombok.extern.slf4j.Slf4j; | @@ -30,7 +30,7 @@ import lombok.extern.slf4j.Slf4j; | ||
30 | import org.springframework.stereotype.Component; | 30 | import org.springframework.stereotype.Component; |
31 | import org.springframework.util.StringUtils; | 31 | import org.springframework.util.StringUtils; |
32 | import org.thingsboard.server.common.data.device.profile.MqttTopics; | 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 | import org.thingsboard.server.common.transport.adaptor.AdaptorException; | 34 | import org.thingsboard.server.common.transport.adaptor.AdaptorException; |
35 | import org.thingsboard.server.common.transport.adaptor.JsonConverter; | 35 | import org.thingsboard.server.common.transport.adaptor.JsonConverter; |
36 | import org.thingsboard.server.gen.transport.TransportProtos; | 36 | import org.thingsboard.server.gen.transport.TransportProtos; |
@@ -155,7 +155,7 @@ public class JsonMqttAdaptor implements MqttTransportAdaptor { | @@ -155,7 +155,7 @@ public class JsonMqttAdaptor implements MqttTransportAdaptor { | ||
155 | } | 155 | } |
156 | 156 | ||
157 | @Override | 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 | return Optional.of(createMqttPublishMsg(ctx, String.format(DEVICE_SOFTWARE_FIRMWARE_RESPONSES_TOPIC_FORMAT, firmwareType.getKeyPrefix(), requestId, chunk), firmwareChunk)); | 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,7 +23,7 @@ import io.netty.handler.codec.mqtt.MqttMessage; | ||
23 | import io.netty.handler.codec.mqtt.MqttMessageType; | 23 | import io.netty.handler.codec.mqtt.MqttMessageType; |
24 | import io.netty.handler.codec.mqtt.MqttPublishMessage; | 24 | import io.netty.handler.codec.mqtt.MqttPublishMessage; |
25 | import io.netty.handler.codec.mqtt.MqttPublishVariableHeader; | 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 | import org.thingsboard.server.common.transport.adaptor.AdaptorException; | 27 | import org.thingsboard.server.common.transport.adaptor.AdaptorException; |
28 | import org.thingsboard.server.gen.transport.TransportProtos.AttributeUpdateNotificationMsg; | 28 | import org.thingsboard.server.gen.transport.TransportProtos.AttributeUpdateNotificationMsg; |
29 | import org.thingsboard.server.gen.transport.TransportProtos.ClaimDeviceMsg; | 29 | import org.thingsboard.server.gen.transport.TransportProtos.ClaimDeviceMsg; |
@@ -78,7 +78,7 @@ public interface MqttTransportAdaptor { | @@ -78,7 +78,7 @@ public interface MqttTransportAdaptor { | ||
78 | 78 | ||
79 | Optional<MqttMessage> convertToPublish(MqttDeviceAwareSessionContext ctx, ProvisionDeviceResponseMsg provisionResponse) throws AdaptorException; | 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 | default MqttPublishMessage createMqttPublishMsg(MqttDeviceAwareSessionContext ctx, String topic, byte[] payloadInBytes) { | 83 | default MqttPublishMessage createMqttPublishMsg(MqttDeviceAwareSessionContext ctx, String topic, byte[] payloadInBytes) { |
84 | MqttFixedHeader mqttFixedHeader = | 84 | MqttFixedHeader mqttFixedHeader = |
@@ -28,7 +28,7 @@ import lombok.extern.slf4j.Slf4j; | @@ -28,7 +28,7 @@ import lombok.extern.slf4j.Slf4j; | ||
28 | import org.springframework.stereotype.Component; | 28 | import org.springframework.stereotype.Component; |
29 | import org.springframework.util.StringUtils; | 29 | import org.springframework.util.StringUtils; |
30 | import org.thingsboard.server.common.data.device.profile.MqttTopics; | 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 | import org.thingsboard.server.common.transport.adaptor.AdaptorException; | 32 | import org.thingsboard.server.common.transport.adaptor.AdaptorException; |
33 | import org.thingsboard.server.common.transport.adaptor.JsonConverter; | 33 | import org.thingsboard.server.common.transport.adaptor.JsonConverter; |
34 | import org.thingsboard.server.common.transport.adaptor.ProtoConverter; | 34 | import org.thingsboard.server.common.transport.adaptor.ProtoConverter; |
@@ -168,7 +168,7 @@ public class ProtoMqttAdaptor implements MqttTransportAdaptor { | @@ -168,7 +168,7 @@ public class ProtoMqttAdaptor implements MqttTransportAdaptor { | ||
168 | } | 168 | } |
169 | 169 | ||
170 | @Override | 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 | return Optional.of(createMqttPublishMsg(ctx, String.format(DEVICE_SOFTWARE_FIRMWARE_RESPONSES_TOPIC_FORMAT, firmwareType.getKeyPrefix(), requestId, chunk), firmwareChunk)); | 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,14 +21,13 @@ import lombok.Getter; | ||
21 | import lombok.extern.slf4j.Slf4j; | 21 | import lombok.extern.slf4j.Slf4j; |
22 | import org.springframework.beans.factory.annotation.Autowired; | 22 | import org.springframework.beans.factory.annotation.Autowired; |
23 | import org.thingsboard.common.util.ThingsBoardExecutors; | 23 | import org.thingsboard.common.util.ThingsBoardExecutors; |
24 | -import org.thingsboard.server.cache.firmware.FirmwareDataCache; | 24 | +import org.thingsboard.server.cache.ota.OtaPackageDataCache; |
25 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; | 25 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; |
26 | import org.thingsboard.server.queue.scheduler.SchedulerComponent; | 26 | import org.thingsboard.server.queue.scheduler.SchedulerComponent; |
27 | 27 | ||
28 | import javax.annotation.PostConstruct; | 28 | import javax.annotation.PostConstruct; |
29 | import javax.annotation.PreDestroy; | 29 | import javax.annotation.PreDestroy; |
30 | import java.util.concurrent.ExecutorService; | 30 | import java.util.concurrent.ExecutorService; |
31 | -import java.util.concurrent.Executors; | ||
32 | 31 | ||
33 | /** | 32 | /** |
34 | * Created by ashvayka on 15.10.18. | 33 | * Created by ashvayka on 15.10.18. |
@@ -53,7 +52,7 @@ public abstract class TransportContext { | @@ -53,7 +52,7 @@ public abstract class TransportContext { | ||
53 | 52 | ||
54 | @Getter | 53 | @Getter |
55 | @Autowired | 54 | @Autowired |
56 | - private FirmwareDataCache firmwareDataCache; | 55 | + private OtaPackageDataCache otaPackageDataCache; |
57 | 56 | ||
58 | @Autowired | 57 | @Autowired |
59 | private TransportResourceCache transportResourceCache; | 58 | private TransportResourceCache transportResourceCache; |
@@ -29,8 +29,8 @@ import org.thingsboard.server.gen.transport.TransportProtos.GetDeviceRequestMsg; | @@ -29,8 +29,8 @@ import org.thingsboard.server.gen.transport.TransportProtos.GetDeviceRequestMsg; | ||
29 | import org.thingsboard.server.gen.transport.TransportProtos.GetDeviceResponseMsg; | 29 | import org.thingsboard.server.gen.transport.TransportProtos.GetDeviceResponseMsg; |
30 | import org.thingsboard.server.gen.transport.TransportProtos.GetEntityProfileRequestMsg; | 30 | import org.thingsboard.server.gen.transport.TransportProtos.GetEntityProfileRequestMsg; |
31 | import org.thingsboard.server.gen.transport.TransportProtos.GetEntityProfileResponseMsg; | 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 | import org.thingsboard.server.gen.transport.TransportProtos.GetOrCreateDeviceFromGatewayRequestMsg; | 34 | import org.thingsboard.server.gen.transport.TransportProtos.GetOrCreateDeviceFromGatewayRequestMsg; |
35 | import org.thingsboard.server.gen.transport.TransportProtos.GetResourceRequestMsg; | 35 | import org.thingsboard.server.gen.transport.TransportProtos.GetResourceRequestMsg; |
36 | import org.thingsboard.server.gen.transport.TransportProtos.GetResourceResponseMsg; | 36 | import org.thingsboard.server.gen.transport.TransportProtos.GetResourceResponseMsg; |
@@ -115,7 +115,7 @@ public interface TransportService { | @@ -115,7 +115,7 @@ public interface TransportService { | ||
115 | 115 | ||
116 | void process(TransportToDeviceActorMsg msg, TransportServiceCallback<Void> callback); | 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 | SessionMetaData registerAsyncSession(SessionInfoProto sessionInfo, SessionMsgListener listener); | 120 | SessionMetaData registerAsyncSession(SessionInfoProto sessionInfo, SessionMsgListener listener); |
121 | 121 |
@@ -614,13 +614,13 @@ public class DefaultTransportService implements TransportService { | @@ -614,13 +614,13 @@ public class DefaultTransportService implements TransportService { | ||
614 | } | 614 | } |
615 | 615 | ||
616 | @Override | 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 | if (checkLimits(sessionInfo, msg, callback)) { | 618 | if (checkLimits(sessionInfo, msg, callback)) { |
619 | TbProtoQueueMsg<TransportProtos.TransportApiRequestMsg> protoMsg = | 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 | AsyncCallbackTemplate.withCallback(transportApiRequestTemplate.send(protoMsg), response -> { | 622 | AsyncCallbackTemplate.withCallback(transportApiRequestTemplate.send(protoMsg), response -> { |
623 | - callback.onSuccess(response.getValue().getFirmwareResponseMsg()); | 623 | + callback.onSuccess(response.getValue().getOtaPackageResponseMsg()); |
624 | }, callback::onError, transportCallbackExecutor); | 624 | }, callback::onError, transportCallbackExecutor); |
625 | } | 625 | } |
626 | } | 626 | } |
@@ -21,6 +21,7 @@ import org.thingsboard.server.common.data.DeviceInfo; | @@ -21,6 +21,7 @@ import org.thingsboard.server.common.data.DeviceInfo; | ||
21 | import org.thingsboard.server.common.data.DeviceTransportType; | 21 | import org.thingsboard.server.common.data.DeviceTransportType; |
22 | import org.thingsboard.server.common.data.EntitySubtype; | 22 | import org.thingsboard.server.common.data.EntitySubtype; |
23 | import org.thingsboard.server.common.data.id.TenantId; | 23 | import org.thingsboard.server.common.data.id.TenantId; |
24 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | ||
24 | import org.thingsboard.server.common.data.page.PageData; | 25 | import org.thingsboard.server.common.data.page.PageData; |
25 | import org.thingsboard.server.common.data.page.PageLink; | 26 | import org.thingsboard.server.common.data.page.PageLink; |
26 | import org.thingsboard.server.dao.Dao; | 27 | import org.thingsboard.server.dao.Dao; |
@@ -81,9 +82,12 @@ public interface DeviceDao extends Dao<Device>, TenantEntityDao { | @@ -81,9 +82,12 @@ public interface DeviceDao extends Dao<Device>, TenantEntityDao { | ||
81 | */ | 82 | */ |
82 | PageData<Device> findDevicesByTenantIdAndType(UUID tenantId, String type, PageLink pageLink); | 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 | * Find device infos by tenantId, type and page link. | 93 | * Find device infos by tenantId, type and page link. |
@@ -43,7 +43,7 @@ import org.thingsboard.server.common.data.DeviceProfileInfo; | @@ -43,7 +43,7 @@ import org.thingsboard.server.common.data.DeviceProfileInfo; | ||
43 | import org.thingsboard.server.common.data.DeviceProfileProvisionType; | 43 | import org.thingsboard.server.common.data.DeviceProfileProvisionType; |
44 | import org.thingsboard.server.common.data.DeviceProfileType; | 44 | import org.thingsboard.server.common.data.DeviceProfileType; |
45 | import org.thingsboard.server.common.data.DeviceTransportType; | 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 | import org.thingsboard.server.common.data.Tenant; | 47 | import org.thingsboard.server.common.data.Tenant; |
48 | import org.thingsboard.server.common.data.device.profile.CoapDeviceProfileTransportConfiguration; | 48 | import org.thingsboard.server.common.data.device.profile.CoapDeviceProfileTransportConfiguration; |
49 | import org.thingsboard.server.common.data.device.profile.CoapDeviceTypeConfiguration; | 49 | import org.thingsboard.server.common.data.device.profile.CoapDeviceTypeConfiguration; |
@@ -57,7 +57,7 @@ import org.thingsboard.server.common.data.device.profile.DisabledDeviceProfilePr | @@ -57,7 +57,7 @@ import org.thingsboard.server.common.data.device.profile.DisabledDeviceProfilePr | ||
57 | import org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration; | 57 | import org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration; |
58 | import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration; | 58 | import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration; |
59 | import org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration; | 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 | import org.thingsboard.server.common.data.id.DeviceProfileId; | 61 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
62 | import org.thingsboard.server.common.data.id.TenantId; | 62 | import org.thingsboard.server.common.data.id.TenantId; |
63 | import org.thingsboard.server.common.data.page.PageData; | 63 | import org.thingsboard.server.common.data.page.PageData; |
@@ -66,7 +66,7 @@ import org.thingsboard.server.common.data.rule.RuleChain; | @@ -66,7 +66,7 @@ import org.thingsboard.server.common.data.rule.RuleChain; | ||
66 | import org.thingsboard.server.dao.dashboard.DashboardService; | 66 | import org.thingsboard.server.dao.dashboard.DashboardService; |
67 | import org.thingsboard.server.dao.entity.AbstractEntityService; | 67 | import org.thingsboard.server.dao.entity.AbstractEntityService; |
68 | import org.thingsboard.server.dao.exception.DataValidationException; | 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 | import org.thingsboard.server.dao.rule.RuleChainService; | 70 | import org.thingsboard.server.dao.rule.RuleChainService; |
71 | import org.thingsboard.server.dao.service.DataValidator; | 71 | import org.thingsboard.server.dao.service.DataValidator; |
72 | import org.thingsboard.server.dao.service.PaginatedRemover; | 72 | import org.thingsboard.server.dao.service.PaginatedRemover; |
@@ -119,7 +119,7 @@ public class DeviceProfileServiceImpl extends AbstractEntityService implements D | @@ -119,7 +119,7 @@ public class DeviceProfileServiceImpl extends AbstractEntityService implements D | ||
119 | private CacheManager cacheManager; | 119 | private CacheManager cacheManager; |
120 | 120 | ||
121 | @Autowired | 121 | @Autowired |
122 | - private FirmwareService firmwareService; | 122 | + private OtaPackageService otaPackageService; |
123 | 123 | ||
124 | @Autowired | 124 | @Autowired |
125 | private RuleChainService ruleChainService; | 125 | private RuleChainService ruleChainService; |
@@ -427,11 +427,11 @@ public class DeviceProfileServiceImpl extends AbstractEntityService implements D | @@ -427,11 +427,11 @@ public class DeviceProfileServiceImpl extends AbstractEntityService implements D | ||
427 | } | 427 | } |
428 | 428 | ||
429 | if (deviceProfile.getFirmwareId() != null) { | 429 | if (deviceProfile.getFirmwareId() != null) { |
430 | - Firmware firmware = firmwareService.findFirmwareById(tenantId, deviceProfile.getFirmwareId()); | 430 | + OtaPackage firmware = otaPackageService.findOtaPackageById(tenantId, deviceProfile.getFirmwareId()); |
431 | if (firmware == null) { | 431 | if (firmware == null) { |
432 | throw new DataValidationException("Can't assign non-existent firmware!"); | 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 | throw new DataValidationException("Can't assign firmware with type: " + firmware.getType()); | 435 | throw new DataValidationException("Can't assign firmware with type: " + firmware.getType()); |
436 | } | 436 | } |
437 | if (firmware.getData() == null) { | 437 | if (firmware.getData() == null) { |
@@ -443,11 +443,11 @@ public class DeviceProfileServiceImpl extends AbstractEntityService implements D | @@ -443,11 +443,11 @@ public class DeviceProfileServiceImpl extends AbstractEntityService implements D | ||
443 | } | 443 | } |
444 | 444 | ||
445 | if (deviceProfile.getSoftwareId() != null) { | 445 | if (deviceProfile.getSoftwareId() != null) { |
446 | - Firmware software = firmwareService.findFirmwareById(tenantId, deviceProfile.getSoftwareId()); | 446 | + OtaPackage software = otaPackageService.findOtaPackageById(tenantId, deviceProfile.getSoftwareId()); |
447 | if (software == null) { | 447 | if (software == null) { |
448 | throw new DataValidationException("Can't assign non-existent software!"); | 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 | throw new DataValidationException("Can't assign software with type: " + software.getType()); | 451 | throw new DataValidationException("Can't assign software with type: " + software.getType()); |
452 | } | 452 | } |
453 | if (software.getData() == null) { | 453 | if (software.getData() == null) { |
@@ -41,7 +41,7 @@ import org.thingsboard.server.common.data.DeviceTransportType; | @@ -41,7 +41,7 @@ import org.thingsboard.server.common.data.DeviceTransportType; | ||
41 | import org.thingsboard.server.common.data.EntitySubtype; | 41 | import org.thingsboard.server.common.data.EntitySubtype; |
42 | import org.thingsboard.server.common.data.EntityType; | 42 | import org.thingsboard.server.common.data.EntityType; |
43 | import org.thingsboard.server.common.data.EntityView; | 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 | import org.thingsboard.server.common.data.Tenant; | 45 | import org.thingsboard.server.common.data.Tenant; |
46 | import org.thingsboard.server.common.data.device.DeviceSearchQuery; | 46 | import org.thingsboard.server.common.data.device.DeviceSearchQuery; |
47 | import org.thingsboard.server.common.data.device.credentials.BasicMqttCredentials; | 47 | import org.thingsboard.server.common.data.device.credentials.BasicMqttCredentials; |
@@ -54,13 +54,13 @@ import org.thingsboard.server.common.data.device.data.Lwm2mDeviceTransportConfig | @@ -54,13 +54,13 @@ import org.thingsboard.server.common.data.device.data.Lwm2mDeviceTransportConfig | ||
54 | import org.thingsboard.server.common.data.device.data.MqttDeviceTransportConfiguration; | 54 | import org.thingsboard.server.common.data.device.data.MqttDeviceTransportConfiguration; |
55 | import org.thingsboard.server.common.data.device.data.SnmpDeviceTransportConfiguration; | 55 | import org.thingsboard.server.common.data.device.data.SnmpDeviceTransportConfiguration; |
56 | import org.thingsboard.server.common.data.edge.Edge; | 56 | import org.thingsboard.server.common.data.edge.Edge; |
57 | -import org.thingsboard.server.common.data.firmware.FirmwareType; | ||
58 | import org.thingsboard.server.common.data.id.CustomerId; | 57 | import org.thingsboard.server.common.data.id.CustomerId; |
59 | import org.thingsboard.server.common.data.id.DeviceId; | 58 | import org.thingsboard.server.common.data.id.DeviceId; |
60 | import org.thingsboard.server.common.data.id.DeviceProfileId; | 59 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
61 | import org.thingsboard.server.common.data.id.EdgeId; | 60 | import org.thingsboard.server.common.data.id.EdgeId; |
62 | import org.thingsboard.server.common.data.id.EntityId; | 61 | import org.thingsboard.server.common.data.id.EntityId; |
63 | import org.thingsboard.server.common.data.id.TenantId; | 62 | import org.thingsboard.server.common.data.id.TenantId; |
63 | +import org.thingsboard.server.common.data.ota.OtaPackageType; | ||
64 | import org.thingsboard.server.common.data.page.PageData; | 64 | import org.thingsboard.server.common.data.page.PageData; |
65 | import org.thingsboard.server.common.data.page.PageLink; | 65 | import org.thingsboard.server.common.data.page.PageLink; |
66 | import org.thingsboard.server.common.data.relation.EntityRelation; | 66 | import org.thingsboard.server.common.data.relation.EntityRelation; |
@@ -76,7 +76,7 @@ import org.thingsboard.server.dao.device.provision.ProvisionResponseStatus; | @@ -76,7 +76,7 @@ import org.thingsboard.server.dao.device.provision.ProvisionResponseStatus; | ||
76 | import org.thingsboard.server.dao.entity.AbstractEntityService; | 76 | import org.thingsboard.server.dao.entity.AbstractEntityService; |
77 | import org.thingsboard.server.dao.event.EventService; | 77 | import org.thingsboard.server.dao.event.EventService; |
78 | import org.thingsboard.server.dao.exception.DataValidationException; | 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 | import org.thingsboard.server.dao.service.DataValidator; | 80 | import org.thingsboard.server.dao.service.DataValidator; |
81 | import org.thingsboard.server.dao.service.PaginatedRemover; | 81 | import org.thingsboard.server.dao.service.PaginatedRemover; |
82 | import org.thingsboard.server.dao.tenant.TbTenantProfileCache; | 82 | import org.thingsboard.server.dao.tenant.TbTenantProfileCache; |
@@ -138,7 +138,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | @@ -138,7 +138,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | ||
138 | private TbTenantProfileCache tenantProfileCache; | 138 | private TbTenantProfileCache tenantProfileCache; |
139 | 139 | ||
140 | @Autowired | 140 | @Autowired |
141 | - private FirmwareService firmwareService; | 141 | + private OtaPackageService otaPackageService; |
142 | 142 | ||
143 | @Override | 143 | @Override |
144 | public DeviceInfo findDeviceInfoById(TenantId tenantId, DeviceId deviceId) { | 144 | public DeviceInfo findDeviceInfoById(TenantId tenantId, DeviceId deviceId) { |
@@ -201,14 +201,12 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | @@ -201,14 +201,12 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | ||
201 | deviceCredentials.setDeviceId(savedDevice.getId()); | 201 | deviceCredentials.setDeviceId(savedDevice.getId()); |
202 | if (device.getId() == null) { | 202 | if (device.getId() == null) { |
203 | deviceCredentialsService.createDeviceCredentials(savedDevice.getTenantId(), deviceCredentials); | 203 | deviceCredentialsService.createDeviceCredentials(savedDevice.getTenantId(), deviceCredentials); |
204 | - } | ||
205 | - else { | 204 | + } else { |
206 | DeviceCredentials foundDeviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(device.getTenantId(), savedDevice.getId()); | 205 | DeviceCredentials foundDeviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(device.getTenantId(), savedDevice.getId()); |
207 | if (foundDeviceCredentials == null) { | 206 | if (foundDeviceCredentials == null) { |
208 | deviceCredentialsService.createDeviceCredentials(savedDevice.getTenantId(), deviceCredentials); | 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 | return savedDevice; | 212 | return savedDevice; |
@@ -364,21 +362,24 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | @@ -364,21 +362,24 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | ||
364 | } | 362 | } |
365 | 363 | ||
366 | @Override | 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 | validateId(tenantId, INCORRECT_TENANT_ID + tenantId); | 371 | validateId(tenantId, INCORRECT_TENANT_ID + tenantId); |
370 | - validateString(type, "Incorrect type " + type); | 372 | + validateId(tenantId, INCORRECT_DEVICE_PROFILE_ID + deviceProfileId); |
371 | validatePageLink(pageLink); | 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 | @Override | 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 | validateId(tenantId, INCORRECT_TENANT_ID + tenantId); | 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 | @Override | 385 | @Override |
@@ -708,11 +709,11 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | @@ -708,11 +709,11 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | ||
708 | .ifPresent(DeviceTransportConfiguration::validate); | 709 | .ifPresent(DeviceTransportConfiguration::validate); |
709 | 710 | ||
710 | if (device.getFirmwareId() != null) { | 711 | if (device.getFirmwareId() != null) { |
711 | - Firmware firmware = firmwareService.findFirmwareById(tenantId, device.getFirmwareId()); | 712 | + OtaPackage firmware = otaPackageService.findOtaPackageById(tenantId, device.getFirmwareId()); |
712 | if (firmware == null) { | 713 | if (firmware == null) { |
713 | throw new DataValidationException("Can't assign non-existent firmware!"); | 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 | throw new DataValidationException("Can't assign firmware with type: " + firmware.getType()); | 717 | throw new DataValidationException("Can't assign firmware with type: " + firmware.getType()); |
717 | } | 718 | } |
718 | if (firmware.getData() == null) { | 719 | if (firmware.getData() == null) { |
@@ -724,11 +725,11 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | @@ -724,11 +725,11 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | ||
724 | } | 725 | } |
725 | 726 | ||
726 | if (device.getSoftwareId() != null) { | 727 | if (device.getSoftwareId() != null) { |
727 | - Firmware software = firmwareService.findFirmwareById(tenantId, device.getSoftwareId()); | 728 | + OtaPackage software = otaPackageService.findOtaPackageById(tenantId, device.getSoftwareId()); |
728 | if (software == null) { | 729 | if (software == null) { |
729 | throw new DataValidationException("Can't assign non-existent software!"); | 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 | throw new DataValidationException("Can't assign software with type: " + software.getType()); | 733 | throw new DataValidationException("Can't assign software with type: " + software.getType()); |
733 | } | 734 | } |
734 | if (software.getData() == null) { | 735 | if (software.getData() == null) { |
@@ -32,7 +32,7 @@ import org.thingsboard.server.common.data.id.DeviceId; | @@ -32,7 +32,7 @@ import org.thingsboard.server.common.data.id.DeviceId; | ||
32 | import org.thingsboard.server.common.data.id.EdgeId; | 32 | import org.thingsboard.server.common.data.id.EdgeId; |
33 | import org.thingsboard.server.common.data.id.EntityId; | 33 | import org.thingsboard.server.common.data.id.EntityId; |
34 | import org.thingsboard.server.common.data.id.EntityViewId; | 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 | import org.thingsboard.server.common.data.id.RuleChainId; | 36 | import org.thingsboard.server.common.data.id.RuleChainId; |
37 | import org.thingsboard.server.common.data.id.TbResourceId; | 37 | import org.thingsboard.server.common.data.id.TbResourceId; |
38 | import org.thingsboard.server.common.data.id.TenantId; | 38 | import org.thingsboard.server.common.data.id.TenantId; |
@@ -49,7 +49,7 @@ import org.thingsboard.server.dao.dashboard.DashboardService; | @@ -49,7 +49,7 @@ import org.thingsboard.server.dao.dashboard.DashboardService; | ||
49 | import org.thingsboard.server.dao.device.DeviceService; | 49 | import org.thingsboard.server.dao.device.DeviceService; |
50 | import org.thingsboard.server.dao.entityview.EntityViewService; | 50 | import org.thingsboard.server.dao.entityview.EntityViewService; |
51 | import org.thingsboard.server.dao.exception.IncorrectParameterException; | 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 | import org.thingsboard.server.dao.resource.ResourceService; | 53 | import org.thingsboard.server.dao.resource.ResourceService; |
54 | import org.thingsboard.server.dao.rule.RuleChainService; | 54 | import org.thingsboard.server.dao.rule.RuleChainService; |
55 | import org.thingsboard.server.dao.tenant.TenantService; | 55 | import org.thingsboard.server.dao.tenant.TenantService; |
@@ -102,7 +102,7 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe | @@ -102,7 +102,7 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe | ||
102 | private ResourceService resourceService; | 102 | private ResourceService resourceService; |
103 | 103 | ||
104 | @Autowired | 104 | @Autowired |
105 | - private FirmwareService firmwareService; | 105 | + private OtaPackageService otaPackageService; |
106 | 106 | ||
107 | @Override | 107 | @Override |
108 | public void deleteEntityRelations(TenantId tenantId, EntityId entityId) { | 108 | public void deleteEntityRelations(TenantId tenantId, EntityId entityId) { |
@@ -167,8 +167,8 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe | @@ -167,8 +167,8 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe | ||
167 | case TB_RESOURCE: | 167 | case TB_RESOURCE: |
168 | hasName = resourceService.findResourceInfoByIdAsync(tenantId, new TbResourceId(entityId.getId())); | 168 | hasName = resourceService.findResourceInfoByIdAsync(tenantId, new TbResourceId(entityId.getId())); |
169 | break; | 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 | break; | 172 | break; |
173 | default: | 173 | default: |
174 | throw new IllegalStateException("Not Implemented!"); | 174 | throw new IllegalStateException("Not Implemented!"); |
@@ -192,7 +192,7 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe | @@ -192,7 +192,7 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe | ||
192 | case DEVICE_PROFILE: | 192 | case DEVICE_PROFILE: |
193 | case API_USAGE_STATE: | 193 | case API_USAGE_STATE: |
194 | case TB_RESOURCE: | 194 | case TB_RESOURCE: |
195 | - case FIRMWARE: | 195 | + case OTA_PACKAGE: |
196 | break; | 196 | break; |
197 | case CUSTOMER: | 197 | case CUSTOMER: |
198 | hasCustomerId = () -> new CustomerId(entityId.getId()); | 198 | hasCustomerId = () -> new CustomerId(entityId.getId()); |
@@ -479,22 +479,21 @@ public class ModelConstants { | @@ -479,22 +479,21 @@ public class ModelConstants { | ||
479 | public static final String RESOURCE_DATA_COLUMN = "data"; | 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 | * Edge constants. | 499 | * Edge constants. |
@@ -28,7 +28,7 @@ import org.thingsboard.server.common.data.device.data.DeviceData; | @@ -28,7 +28,7 @@ import org.thingsboard.server.common.data.device.data.DeviceData; | ||
28 | import org.thingsboard.server.common.data.id.CustomerId; | 28 | import org.thingsboard.server.common.data.id.CustomerId; |
29 | import org.thingsboard.server.common.data.id.DeviceId; | 29 | import org.thingsboard.server.common.data.id.DeviceId; |
30 | import org.thingsboard.server.common.data.id.DeviceProfileId; | 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 | import org.thingsboard.server.common.data.id.TenantId; | 32 | import org.thingsboard.server.common.data.id.TenantId; |
33 | import org.thingsboard.server.dao.model.BaseSqlEntity; | 33 | import org.thingsboard.server.dao.model.BaseSqlEntity; |
34 | import org.thingsboard.server.dao.model.ModelConstants; | 34 | import org.thingsboard.server.dao.model.ModelConstants; |
@@ -154,10 +154,10 @@ public abstract class AbstractDeviceEntity<T extends Device> extends BaseSqlEnti | @@ -154,10 +154,10 @@ public abstract class AbstractDeviceEntity<T extends Device> extends BaseSqlEnti | ||
154 | device.setDeviceProfileId(new DeviceProfileId(deviceProfileId)); | 154 | device.setDeviceProfileId(new DeviceProfileId(deviceProfileId)); |
155 | } | 155 | } |
156 | if (firmwareId != null) { | 156 | if (firmwareId != null) { |
157 | - device.setFirmwareId(new FirmwareId(firmwareId)); | 157 | + device.setFirmwareId(new OtaPackageId(firmwareId)); |
158 | } | 158 | } |
159 | if (softwareId != null) { | 159 | if (softwareId != null) { |
160 | - device.setSoftwareId(new FirmwareId(softwareId)); | 160 | + device.setSoftwareId(new OtaPackageId(softwareId)); |
161 | } | 161 | } |
162 | device.setDeviceData(JacksonUtil.convertValue(deviceData, DeviceData.class)); | 162 | device.setDeviceData(JacksonUtil.convertValue(deviceData, DeviceData.class)); |
163 | device.setName(name); | 163 | device.setName(name); |
@@ -29,7 +29,7 @@ import org.thingsboard.server.common.data.DeviceTransportType; | @@ -29,7 +29,7 @@ import org.thingsboard.server.common.data.DeviceTransportType; | ||
29 | import org.thingsboard.server.common.data.device.profile.DeviceProfileData; | 29 | import org.thingsboard.server.common.data.device.profile.DeviceProfileData; |
30 | import org.thingsboard.server.common.data.id.DashboardId; | 30 | import org.thingsboard.server.common.data.id.DashboardId; |
31 | import org.thingsboard.server.common.data.id.DeviceProfileId; | 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 | import org.thingsboard.server.common.data.id.RuleChainId; | 33 | import org.thingsboard.server.common.data.id.RuleChainId; |
34 | import org.thingsboard.server.common.data.id.TenantId; | 34 | import org.thingsboard.server.common.data.id.TenantId; |
35 | import org.thingsboard.server.dao.model.BaseSqlEntity; | 35 | import org.thingsboard.server.dao.model.BaseSqlEntity; |
@@ -178,11 +178,11 @@ public final class DeviceProfileEntity extends BaseSqlEntity<DeviceProfile> impl | @@ -178,11 +178,11 @@ public final class DeviceProfileEntity extends BaseSqlEntity<DeviceProfile> impl | ||
178 | deviceProfile.setProvisionDeviceKey(provisionDeviceKey); | 178 | deviceProfile.setProvisionDeviceKey(provisionDeviceKey); |
179 | 179 | ||
180 | if (firmwareId != null) { | 180 | if (firmwareId != null) { |
181 | - deviceProfile.setFirmwareId(new FirmwareId(firmwareId)); | 181 | + deviceProfile.setFirmwareId(new OtaPackageId(firmwareId)); |
182 | } | 182 | } |
183 | 183 | ||
184 | if (softwareId != null) { | 184 | if (softwareId != null) { |
185 | - deviceProfile.setSoftwareId(new FirmwareId(softwareId)); | 185 | + deviceProfile.setSoftwareId(new OtaPackageId(softwareId)); |
186 | } | 186 | } |
187 | 187 | ||
188 | return deviceProfile; | 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,11 +20,11 @@ import lombok.Data; | ||
20 | import lombok.EqualsAndHashCode; | 20 | import lombok.EqualsAndHashCode; |
21 | import org.hibernate.annotations.Type; | 21 | import org.hibernate.annotations.Type; |
22 | import org.hibernate.annotations.TypeDef; | 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 | import org.thingsboard.server.common.data.id.DeviceProfileId; | 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 | import org.thingsboard.server.common.data.id.TenantId; | 28 | import org.thingsboard.server.common.data.id.TenantId; |
29 | import org.thingsboard.server.dao.model.BaseSqlEntity; | 29 | import org.thingsboard.server.dao.model.BaseSqlEntity; |
30 | import org.thingsboard.server.dao.model.ModelConstants; | 30 | import org.thingsboard.server.dao.model.ModelConstants; |
@@ -40,75 +40,75 @@ import javax.persistence.Table; | @@ -40,75 +40,75 @@ import javax.persistence.Table; | ||
40 | import java.nio.ByteBuffer; | 40 | import java.nio.ByteBuffer; |
41 | import java.util.UUID; | 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 | import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY; | 55 | import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY; |
56 | 56 | ||
57 | @Data | 57 | @Data |
58 | @EqualsAndHashCode(callSuper = true) | 58 | @EqualsAndHashCode(callSuper = true) |
59 | @Entity | 59 | @Entity |
60 | @TypeDef(name = "json", typeClass = JsonStringType.class) | 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 | private UUID tenantId; | 65 | private UUID tenantId; |
66 | 66 | ||
67 | - @Column(name = FIRMWARE_DEVICE_PROFILE_ID_COLUMN) | 67 | + @Column(name = OTA_PACKAGE_DEVICE_PROFILE_ID_COLUMN) |
68 | private UUID deviceProfileId; | 68 | private UUID deviceProfileId; |
69 | 69 | ||
70 | @Enumerated(EnumType.STRING) | 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 | private String title; | 75 | private String title; |
76 | 76 | ||
77 | - @Column(name = FIRMWARE_VERSION_COLUMN) | 77 | + @Column(name = OTA_PACKAGE_VERSION_COLUMN) |
78 | private String version; | 78 | private String version; |
79 | 79 | ||
80 | - @Column(name = FIRMWARE_FILE_NAME_COLUMN) | 80 | + @Column(name = OTA_PACKAGE_FILE_NAME_COLUMN) |
81 | private String fileName; | 81 | private String fileName; |
82 | 82 | ||
83 | - @Column(name = FIRMWARE_CONTENT_TYPE_COLUMN) | 83 | + @Column(name = OTA_PACKAGE_CONTENT_TYPE_COLUMN) |
84 | private String contentType; | 84 | private String contentType; |
85 | 85 | ||
86 | @Enumerated(EnumType.STRING) | 86 | @Enumerated(EnumType.STRING) |
87 | - @Column(name = FIRMWARE_CHECKSUM_ALGORITHM_COLUMN) | 87 | + @Column(name = OTA_PACKAGE_CHECKSUM_ALGORITHM_COLUMN) |
88 | private ChecksumAlgorithm checksumAlgorithm; | 88 | private ChecksumAlgorithm checksumAlgorithm; |
89 | 89 | ||
90 | - @Column(name = FIRMWARE_CHECKSUM_COLUMN) | 90 | + @Column(name = OTA_PACKAGE_CHECKSUM_COLUMN) |
91 | private String checksum; | 91 | private String checksum; |
92 | 92 | ||
93 | @Lob | 93 | @Lob |
94 | - @Column(name = FIRMWARE_DATA_COLUMN, columnDefinition = "BINARY") | 94 | + @Column(name = OTA_PACKAGE_DATA_COLUMN, columnDefinition = "BINARY") |
95 | private byte[] data; | 95 | private byte[] data; |
96 | 96 | ||
97 | - @Column(name = FIRMWARE_DATA_SIZE_COLUMN) | 97 | + @Column(name = OTA_PACKAGE_DATA_SIZE_COLUMN) |
98 | private Long dataSize; | 98 | private Long dataSize; |
99 | 99 | ||
100 | @Type(type = "json") | 100 | @Type(type = "json") |
101 | - @Column(name = ModelConstants.FIRMWARE_ADDITIONAL_INFO_COLUMN) | 101 | + @Column(name = ModelConstants.OTA_PACKAGE_ADDITIONAL_INFO_COLUMN) |
102 | private JsonNode additionalInfo; | 102 | private JsonNode additionalInfo; |
103 | 103 | ||
104 | @Column(name = SEARCH_TEXT_PROPERTY) | 104 | @Column(name = SEARCH_TEXT_PROPERTY) |
105 | private String searchText; | 105 | private String searchText; |
106 | 106 | ||
107 | - public FirmwareEntity() { | 107 | + public OtaPackageEntity() { |
108 | super(); | 108 | super(); |
109 | } | 109 | } |
110 | 110 | ||
111 | - public FirmwareEntity(Firmware firmware) { | 111 | + public OtaPackageEntity(OtaPackage firmware) { |
112 | this.createdTime = firmware.getCreatedTime(); | 112 | this.createdTime = firmware.getCreatedTime(); |
113 | this.setUuid(firmware.getUuidId()); | 113 | this.setUuid(firmware.getUuidId()); |
114 | this.tenantId = firmware.getTenantId().getId(); | 114 | this.tenantId = firmware.getTenantId().getId(); |
@@ -138,8 +138,8 @@ public class FirmwareEntity extends BaseSqlEntity<Firmware> implements SearchTex | @@ -138,8 +138,8 @@ public class FirmwareEntity extends BaseSqlEntity<Firmware> implements SearchTex | ||
138 | } | 138 | } |
139 | 139 | ||
140 | @Override | 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 | firmware.setCreatedTime(createdTime); | 143 | firmware.setCreatedTime(createdTime); |
144 | firmware.setTenantId(new TenantId(tenantId)); | 144 | firmware.setTenantId(new TenantId(tenantId)); |
145 | if (deviceProfileId != null) { | 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,11 +21,11 @@ import lombok.EqualsAndHashCode; | ||
21 | import org.hibernate.annotations.Type; | 21 | import org.hibernate.annotations.Type; |
22 | import org.hibernate.annotations.TypeDef; | 22 | import org.hibernate.annotations.TypeDef; |
23 | import org.thingsboard.common.util.JacksonUtil; | 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 | import org.thingsboard.server.common.data.id.DeviceProfileId; | 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 | import org.thingsboard.server.common.data.id.TenantId; | 29 | import org.thingsboard.server.common.data.id.TenantId; |
30 | import org.thingsboard.server.dao.model.BaseSqlEntity; | 30 | import org.thingsboard.server.dao.model.BaseSqlEntity; |
31 | import org.thingsboard.server.dao.model.ModelConstants; | 31 | import org.thingsboard.server.dao.model.ModelConstants; |
@@ -40,60 +40,60 @@ import javax.persistence.Table; | @@ -40,60 +40,60 @@ import javax.persistence.Table; | ||
40 | import javax.persistence.Transient; | 40 | import javax.persistence.Transient; |
41 | import java.util.UUID; | 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 | import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY; | 54 | import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY; |
55 | 55 | ||
56 | @Data | 56 | @Data |
57 | @EqualsAndHashCode(callSuper = true) | 57 | @EqualsAndHashCode(callSuper = true) |
58 | @Entity | 58 | @Entity |
59 | @TypeDef(name = "json", typeClass = JsonStringType.class) | 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 | private UUID tenantId; | 64 | private UUID tenantId; |
65 | 65 | ||
66 | - @Column(name = FIRMWARE_DEVICE_PROFILE_ID_COLUMN) | 66 | + @Column(name = OTA_PACKAGE_DEVICE_PROFILE_ID_COLUMN) |
67 | private UUID deviceProfileId; | 67 | private UUID deviceProfileId; |
68 | 68 | ||
69 | @Enumerated(EnumType.STRING) | 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 | private String title; | 74 | private String title; |
75 | 75 | ||
76 | - @Column(name = FIRMWARE_VERSION_COLUMN) | 76 | + @Column(name = OTA_PACKAGE_VERSION_COLUMN) |
77 | private String version; | 77 | private String version; |
78 | 78 | ||
79 | - @Column(name = FIRMWARE_FILE_NAME_COLUMN) | 79 | + @Column(name = OTA_PACKAGE_FILE_NAME_COLUMN) |
80 | private String fileName; | 80 | private String fileName; |
81 | 81 | ||
82 | - @Column(name = FIRMWARE_CONTENT_TYPE_COLUMN) | 82 | + @Column(name = OTA_PACKAGE_CONTENT_TYPE_COLUMN) |
83 | private String contentType; | 83 | private String contentType; |
84 | 84 | ||
85 | @Enumerated(EnumType.STRING) | 85 | @Enumerated(EnumType.STRING) |
86 | - @Column(name = FIRMWARE_CHECKSUM_ALGORITHM_COLUMN) | 86 | + @Column(name = OTA_PACKAGE_CHECKSUM_ALGORITHM_COLUMN) |
87 | private ChecksumAlgorithm checksumAlgorithm; | 87 | private ChecksumAlgorithm checksumAlgorithm; |
88 | 88 | ||
89 | - @Column(name = FIRMWARE_CHECKSUM_COLUMN) | 89 | + @Column(name = OTA_PACKAGE_CHECKSUM_COLUMN) |
90 | private String checksum; | 90 | private String checksum; |
91 | 91 | ||
92 | - @Column(name = FIRMWARE_DATA_SIZE_COLUMN) | 92 | + @Column(name = OTA_PACKAGE_DATA_SIZE_COLUMN) |
93 | private Long dataSize; | 93 | private Long dataSize; |
94 | 94 | ||
95 | @Type(type = "json") | 95 | @Type(type = "json") |
96 | - @Column(name = ModelConstants.FIRMWARE_ADDITIONAL_INFO_COLUMN) | 96 | + @Column(name = ModelConstants.OTA_PACKAGE_ADDITIONAL_INFO_COLUMN) |
97 | private JsonNode additionalInfo; | 97 | private JsonNode additionalInfo; |
98 | 98 | ||
99 | @Column(name = SEARCH_TEXT_PROPERTY) | 99 | @Column(name = SEARCH_TEXT_PROPERTY) |
@@ -102,11 +102,11 @@ public class FirmwareInfoEntity extends BaseSqlEntity<FirmwareInfo> implements S | @@ -102,11 +102,11 @@ public class FirmwareInfoEntity extends BaseSqlEntity<FirmwareInfo> implements S | ||
102 | @Transient | 102 | @Transient |
103 | private boolean hasData; | 103 | private boolean hasData; |
104 | 104 | ||
105 | - public FirmwareInfoEntity() { | 105 | + public OtaPackageInfoEntity() { |
106 | super(); | 106 | super(); |
107 | } | 107 | } |
108 | 108 | ||
109 | - public FirmwareInfoEntity(FirmwareInfo firmware) { | 109 | + public OtaPackageInfoEntity(OtaPackageInfo firmware) { |
110 | this.createdTime = firmware.getCreatedTime(); | 110 | this.createdTime = firmware.getCreatedTime(); |
111 | this.setUuid(firmware.getUuidId()); | 111 | this.setUuid(firmware.getUuidId()); |
112 | this.tenantId = firmware.getTenantId().getId(); | 112 | this.tenantId = firmware.getTenantId().getId(); |
@@ -124,9 +124,9 @@ public class FirmwareInfoEntity extends BaseSqlEntity<FirmwareInfo> implements S | @@ -124,9 +124,9 @@ public class FirmwareInfoEntity extends BaseSqlEntity<FirmwareInfo> implements S | ||
124 | this.additionalInfo = firmware.getAdditionalInfo(); | 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 | this.id = id; | 130 | this.id = id; |
131 | this.createdTime = createdTime; | 131 | this.createdTime = createdTime; |
132 | this.tenantId = tenantId; | 132 | this.tenantId = tenantId; |
@@ -154,8 +154,8 @@ public class FirmwareInfoEntity extends BaseSqlEntity<FirmwareInfo> implements S | @@ -154,8 +154,8 @@ public class FirmwareInfoEntity extends BaseSqlEntity<FirmwareInfo> implements S | ||
154 | } | 154 | } |
155 | 155 | ||
156 | @Override | 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 | firmware.setCreatedTime(createdTime); | 159 | firmware.setCreatedTime(createdTime); |
160 | firmware.setTenantId(new TenantId(tenantId)); | 160 | firmware.setTenantId(new TenantId(tenantId)); |
161 | if (deviceProfileId != null) { | 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,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 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 com.google.common.hash.HashFunction; | 18 | import com.google.common.hash.HashFunction; |
19 | import com.google.common.hash.Hashing; | 19 | import com.google.common.hash.Hashing; |
@@ -26,17 +26,15 @@ import org.springframework.cache.Cache; | @@ -26,17 +26,15 @@ import org.springframework.cache.Cache; | ||
26 | import org.springframework.cache.CacheManager; | 26 | import org.springframework.cache.CacheManager; |
27 | import org.springframework.cache.annotation.Cacheable; | 27 | import org.springframework.cache.annotation.Cacheable; |
28 | import org.springframework.stereotype.Service; | 28 | import org.springframework.stereotype.Service; |
29 | -import org.thingsboard.server.cache.firmware.FirmwareDataCache; | 29 | +import org.thingsboard.server.cache.ota.OtaPackageDataCache; |
30 | import org.thingsboard.server.common.data.DeviceProfile; | 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 | import org.thingsboard.server.common.data.Tenant; | 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 | import org.thingsboard.server.common.data.id.DeviceProfileId; | 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 | import org.thingsboard.server.common.data.id.TenantId; | 38 | import org.thingsboard.server.common.data.id.TenantId; |
41 | import org.thingsboard.server.common.data.page.PageData; | 39 | import org.thingsboard.server.common.data.page.PageData; |
42 | import org.thingsboard.server.common.data.page.PageLink; | 40 | import org.thingsboard.server.common.data.page.PageLink; |
@@ -46,49 +44,45 @@ import org.thingsboard.server.dao.service.DataValidator; | @@ -46,49 +44,45 @@ import org.thingsboard.server.dao.service.DataValidator; | ||
46 | import org.thingsboard.server.dao.service.PaginatedRemover; | 44 | import org.thingsboard.server.dao.service.PaginatedRemover; |
47 | import org.thingsboard.server.dao.tenant.TenantDao; | 45 | import org.thingsboard.server.dao.tenant.TenantDao; |
48 | 46 | ||
49 | -import java.lang.reflect.InvocationTargetException; | ||
50 | -import java.lang.reflect.Method; | ||
51 | import java.nio.ByteBuffer; | 47 | import java.nio.ByteBuffer; |
52 | -import java.util.ArrayList; | ||
53 | -import java.util.Arrays; | ||
54 | import java.util.Collections; | 48 | import java.util.Collections; |
55 | import java.util.List; | 49 | import java.util.List; |
56 | import java.util.Optional; | 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 | import static org.thingsboard.server.dao.service.Validator.validateId; | 53 | import static org.thingsboard.server.dao.service.Validator.validateId; |
60 | import static org.thingsboard.server.dao.service.Validator.validatePageLink; | 54 | import static org.thingsboard.server.dao.service.Validator.validatePageLink; |
61 | 55 | ||
62 | @Service | 56 | @Service |
63 | @Slf4j | 57 | @Slf4j |
64 | @RequiredArgsConstructor | 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 | public static final String INCORRECT_TENANT_ID = "Incorrect tenantId "; | 61 | public static final String INCORRECT_TENANT_ID = "Incorrect tenantId "; |
68 | 62 | ||
69 | private final TenantDao tenantDao; | 63 | private final TenantDao tenantDao; |
70 | private final DeviceProfileDao deviceProfileDao; | 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 | private final CacheManager cacheManager; | 67 | private final CacheManager cacheManager; |
74 | - private final FirmwareDataCache firmwareDataCache; | 68 | + private final OtaPackageDataCache otaPackageDataCache; |
75 | 69 | ||
76 | @Override | 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 | try { | 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 | } catch (Exception t) { | 82 | } catch (Exception t) { |
89 | ConstraintViolationException e = extractConstraintViolationException(t).orElse(null); | 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 | } else { | 86 | } else { |
93 | throw t; | 87 | throw t; |
94 | } | 88 | } |
@@ -96,21 +90,21 @@ public class BaseFirmwareService implements FirmwareService { | @@ -96,21 +90,21 @@ public class BaseFirmwareService implements FirmwareService { | ||
96 | } | 90 | } |
97 | 91 | ||
98 | @Override | 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 | try { | 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 | } catch (Exception t) { | 104 | } catch (Exception t) { |
111 | ConstraintViolationException e = extractConstraintViolationException(t).orElse(null); | 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 | } else { | 108 | } else { |
115 | throw t; | 109 | throw t; |
116 | } | 110 | } |
@@ -120,7 +114,7 @@ public class BaseFirmwareService implements FirmwareService { | @@ -120,7 +114,7 @@ public class BaseFirmwareService implements FirmwareService { | ||
120 | @Override | 114 | @Override |
121 | public String generateChecksum(ChecksumAlgorithm checksumAlgorithm, ByteBuffer data) { | 115 | public String generateChecksum(ChecksumAlgorithm checksumAlgorithm, ByteBuffer data) { |
122 | if (data == null || !data.hasArray() || data.array().length == 0) { | 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 | return getHashFunction(checksumAlgorithm).hashBytes(data.array()).toString(); | 120 | return getHashFunction(checksumAlgorithm).hashBytes(data.array()).toString(); |
@@ -148,58 +142,58 @@ public class BaseFirmwareService implements FirmwareService { | @@ -148,58 +142,58 @@ public class BaseFirmwareService implements FirmwareService { | ||
148 | } | 142 | } |
149 | 143 | ||
150 | @Override | 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 | @Override | 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 | @Override | 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 | @Override | 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 | validateId(tenantId, INCORRECT_TENANT_ID + tenantId); | 169 | validateId(tenantId, INCORRECT_TENANT_ID + tenantId); |
176 | validatePageLink(pageLink); | 170 | validatePageLink(pageLink); |
177 | - return firmwareInfoDao.findFirmwareInfoByTenantId(tenantId, pageLink); | 171 | + return otaPackageInfoDao.findOtaPackageInfoByTenantId(tenantId, pageLink); |
178 | } | 172 | } |
179 | 173 | ||
180 | @Override | 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 | validateId(tenantId, INCORRECT_TENANT_ID + tenantId); | 177 | validateId(tenantId, INCORRECT_TENANT_ID + tenantId); |
184 | validatePageLink(pageLink); | 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 | @Override | 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 | try { | 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 | } catch (Exception t) { | 191 | } catch (Exception t) { |
198 | ConstraintViolationException e = extractConstraintViolationException(t).orElse(null); | 192 | ConstraintViolationException e = extractConstraintViolationException(t).orElse(null); |
199 | if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("fk_firmware_device")) { | 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 | } else if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("fk_firmware_device_profile")) { | 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 | } else if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("fk_software_device")) { | 197 | } else if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("fk_software_device")) { |
204 | throw new DataValidationException("The software referenced by the devices cannot be deleted!"); | 198 | throw new DataValidationException("The software referenced by the devices cannot be deleted!"); |
205 | } else if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("fk_software_device_profile")) { | 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,154 +205,147 @@ public class BaseFirmwareService implements FirmwareService { | ||
211 | } | 205 | } |
212 | 206 | ||
213 | @Override | 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 | validateId(tenantId, INCORRECT_TENANT_ID + tenantId); | 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 | @Override | 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 | @Override | 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 | @Override | 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 | String currentChecksum; | 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 | @Override | 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 | } else { | 311 | } else { |
325 | - Tenant tenant = tenantDao.findById(firmwareInfo.getTenantId(), firmwareInfo.getTenantId().getId()); | 312 | + Tenant tenant = tenantDao.findById(otaPackageInfo.getTenantId(), otaPackageInfo.getTenantId().getId()); |
326 | if (tenant == null) { | 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 | if (deviceProfile == null) { | 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 | throw new DataValidationException("Type should be specified!"); | 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 | new PaginatedRemover<>() { | 339 | new PaginatedRemover<>() { |
353 | 340 | ||
354 | @Override | 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 | @Override | 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,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,11 +13,11 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 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 | import org.thingsboard.server.dao.Dao; | 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,25 +13,23 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 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 | import org.thingsboard.server.common.data.id.DeviceProfileId; | 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 | import org.thingsboard.server.common.data.id.TenantId; | 22 | import org.thingsboard.server.common.data.id.TenantId; |
23 | import org.thingsboard.server.common.data.page.PageData; | 23 | import org.thingsboard.server.common.data.page.PageData; |
24 | import org.thingsboard.server.common.data.page.PageLink; | 24 | import org.thingsboard.server.common.data.page.PageLink; |
25 | import org.thingsboard.server.dao.Dao; | 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,23 +96,35 @@ public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntit | ||
96 | Pageable pageable); | 96 | Pageable pageable); |
97 | 97 | ||
98 | @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " + | 98 | @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " + |
99 | - "AND d.type = :type " + | 99 | + "AND d.deviceProfileId = :deviceProfileId " + |
100 | "AND d.firmwareId = null " + | 100 | "AND d.firmwareId = null " + |
101 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") | 101 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
102 | Page<DeviceEntity> findByTenantIdAndTypeAndFirmwareIdIsNull(@Param("tenantId") UUID tenantId, | 102 | Page<DeviceEntity> findByTenantIdAndTypeAndFirmwareIdIsNull(@Param("tenantId") UUID tenantId, |
103 | - @Param("type") String type, | 103 | + @Param("deviceProfileId") UUID deviceProfileId, |
104 | @Param("textSearch") String textSearch, | 104 | @Param("textSearch") String textSearch, |
105 | Pageable pageable); | 105 | Pageable pageable); |
106 | 106 | ||
107 | @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " + | 107 | @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " + |
108 | - "AND d.type = :type " + | 108 | + "AND d.deviceProfileId = :deviceProfileId " + |
109 | "AND d.softwareId = null " + | 109 | "AND d.softwareId = null " + |
110 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") | 110 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
111 | Page<DeviceEntity> findByTenantIdAndTypeAndSoftwareIdIsNull(@Param("tenantId") UUID tenantId, | 111 | Page<DeviceEntity> findByTenantIdAndTypeAndSoftwareIdIsNull(@Param("tenantId") UUID tenantId, |
112 | - @Param("type") String type, | 112 | + @Param("deviceProfileId") UUID deviceProfileId, |
113 | @Param("textSearch") String textSearch, | 113 | @Param("textSearch") String textSearch, |
114 | Pageable pageable); | 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 | @Query("SELECT new org.thingsboard.server.dao.model.sql.DeviceInfoEntity(d, c.title, c.additionalInfo, p.name) " + | 128 | @Query("SELECT new org.thingsboard.server.dao.model.sql.DeviceInfoEntity(d, c.title, c.additionalInfo, p.name) " + |
117 | "FROM DeviceEntity d " + | 129 | "FROM DeviceEntity d " + |
118 | "LEFT JOIN CustomerEntity c on c.id = d.customerId " + | 130 | "LEFT JOIN CustomerEntity c on c.id = d.customerId " + |
@@ -18,6 +18,8 @@ package org.thingsboard.server.dao.sql.device; | @@ -18,6 +18,8 @@ package org.thingsboard.server.dao.sql.device; | ||
18 | import com.google.common.util.concurrent.ListenableFuture; | 18 | import com.google.common.util.concurrent.ListenableFuture; |
19 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
20 | import org.springframework.beans.factory.annotation.Autowired; | 20 | import org.springframework.beans.factory.annotation.Autowired; |
21 | +import org.springframework.data.domain.Page; | ||
22 | +import org.springframework.data.domain.Pageable; | ||
21 | import org.springframework.data.repository.CrudRepository; | 23 | import org.springframework.data.repository.CrudRepository; |
22 | import org.springframework.stereotype.Component; | 24 | import org.springframework.stereotype.Component; |
23 | import org.springframework.util.StringUtils; | 25 | import org.springframework.util.StringUtils; |
@@ -27,6 +29,8 @@ import org.thingsboard.server.common.data.DeviceTransportType; | @@ -27,6 +29,8 @@ import org.thingsboard.server.common.data.DeviceTransportType; | ||
27 | import org.thingsboard.server.common.data.EntitySubtype; | 29 | import org.thingsboard.server.common.data.EntitySubtype; |
28 | import org.thingsboard.server.common.data.EntityType; | 30 | import org.thingsboard.server.common.data.EntityType; |
29 | import org.thingsboard.server.common.data.id.TenantId; | 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 | import org.thingsboard.server.common.data.page.PageData; | 34 | import org.thingsboard.server.common.data.page.PageData; |
31 | import org.thingsboard.server.common.data.page.PageLink; | 35 | import org.thingsboard.server.common.data.page.PageLink; |
32 | import org.thingsboard.server.dao.DaoUtil; | 36 | import org.thingsboard.server.dao.DaoUtil; |
@@ -155,23 +159,27 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | @@ -155,23 +159,27 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | ||
155 | } | 159 | } |
156 | 160 | ||
157 | @Override | 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 | @Override | 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 | @Override | 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,34 +13,34 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 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 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | import org.springframework.beans.factory.annotation.Autowired; | 19 | import org.springframework.beans.factory.annotation.Autowired; |
20 | import org.springframework.data.repository.CrudRepository; | 20 | import org.springframework.data.repository.CrudRepository; |
21 | import org.springframework.stereotype.Component; | 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 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; | 25 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
26 | 26 | ||
27 | import java.util.UUID; | 27 | import java.util.UUID; |
28 | 28 | ||
29 | @Slf4j | 29 | @Slf4j |
30 | @Component | 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 | @Autowired | 33 | @Autowired |
34 | - private FirmwareRepository firmwareRepository; | 34 | + private OtaPackageRepository otaPackageRepository; |
35 | 35 | ||
36 | @Override | 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 | @Override | 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 | } |