From 7fad29e05971c0ba8233aac3be2fefbcabbd42ea Mon Sep 17 00:00:00 2001 From: deaflynx Date: Wed, 22 Nov 2023 16:59:21 +0200 Subject: [PATCH] edge upgrade instructions ui implementation --- common/edge-api/src/main/proto/edge.proto | 1 + ui-ngx/src/app/core/http/edge.service.ts | 10 ++++-- .../edge-instructions-dialog.component.ts | 34 +++++++++++++++---- .../home/pages/edge/edge.component.html | 27 +++++++++++---- .../modules/home/pages/edge/edge.component.ts | 29 +++++++++++++++- .../pages/edge/edges-table-config.resolver.ts | 10 ++++-- ui-ngx/src/app/shared/models/edge.models.ts | 6 ++-- .../assets/locale/locale.constant-en_US.json | 1 + 8 files changed, 95 insertions(+), 23 deletions(-) diff --git a/common/edge-api/src/main/proto/edge.proto b/common/edge-api/src/main/proto/edge.proto index 71e84304ed..854ce29935 100644 --- a/common/edge-api/src/main/proto/edge.proto +++ b/common/edge-api/src/main/proto/edge.proto @@ -36,6 +36,7 @@ enum EdgeVersion { V_3_4_0 = 2; V_3_6_0 = 3; V_3_6_1 = 4; + V_3_6_2 = 5; } /** diff --git a/ui-ngx/src/app/core/http/edge.service.ts b/ui-ngx/src/app/core/http/edge.service.ts index aeb4f7d16b..6eb1e2f029 100644 --- a/ui-ngx/src/app/core/http/edge.service.ts +++ b/ui-ngx/src/app/core/http/edge.service.ts @@ -21,7 +21,7 @@ import { HttpClient } from '@angular/common/http'; import { PageLink, TimePageLink } from '@shared/models/page/page-link'; import { PageData } from '@shared/models/page/page-data'; import { EntitySubtype } from '@app/shared/models/entity-type.models'; -import { Edge, EdgeEvent, EdgeInfo, EdgeInstallInstructions, EdgeSearchQuery } from '@shared/models/edge.models'; +import { Edge, EdgeEvent, EdgeInfo, EdgeInstructions, EdgeSearchQuery } from '@shared/models/edge.models'; import { EntityId } from '@shared/models/id/entity-id'; import { BulkImportRequest, BulkImportResult } from '@home/components/import-export/import-export.models'; @@ -114,7 +114,11 @@ export class EdgeService { return this.http.post('/api/edge/bulk_import', entitiesData, defaultHttpOptionsFromConfig(config)); } - public getEdgeInstallInstructions(edgeId: string, method: string = 'ubuntu', config?: RequestConfig): Observable { - return this.http.get(`/api/edge/instructions/${edgeId}/${method}`, defaultHttpOptionsFromConfig(config)); + public getEdgeInstallInstructions(edgeId: string, method: string = 'ubuntu', config?: RequestConfig): Observable { + return this.http.get(`/api/edge/instructions/install/${edgeId}/${method}`, defaultHttpOptionsFromConfig(config)); + } + + public getEdgeUpgradeInstructions(edgeVersion: string, method: string = 'ubuntu', config?: RequestConfig): Observable { + return this.http.get(`/api/edge/instructions/upgrade/${edgeVersion}/${method}`, defaultHttpOptionsFromConfig(config)); } } diff --git a/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.ts b/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.ts index 99da1dfb14..c618df96bb 100644 --- a/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.ts @@ -21,12 +21,21 @@ import { AppState } from '@core/core.state'; import { Router } from '@angular/router'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { ActionPreferencesPutUserSettings } from '@core/auth/auth.actions'; -import { EdgeInfo, EdgeInstructionsMethod } from '@shared/models/edge.models'; +import { + EdgeInfo, + EdgeInstructions, + EdgeInstructionsMethod, + edgeVersionAttributeKey +} from '@shared/models/edge.models'; import { EdgeService } from '@core/http/edge.service'; +import { AttributeService } from '@core/http/attribute.service'; +import { AttributeScope } from '@shared/models/telemetry/telemetry.models'; +import { mergeMap, Observable } from 'rxjs'; export interface EdgeInstructionsDialogData { edge: EdgeInfo; afterAdd: boolean; + upgradeAvailable: boolean; } @Component({ @@ -49,6 +58,7 @@ export class EdgeInstructionsDialogComponent extends DialogComponent, + private attributeService: AttributeService, private edgeService: EdgeService) { super(store, router, dialogRef); @@ -85,12 +95,22 @@ export class EdgeInstructionsDialogComponent extends DialogComponent { - this.contentData[method] = res.installInstructions; - this.loadedInstructions = true; - } - ); + let edgeInstructions$: Observable; + if (this.data.upgradeAvailable) { + edgeInstructions$ = this.attributeService.getEntityAttributes(this.data.edge.id, AttributeScope.SERVER_SCOPE, [edgeVersionAttributeKey]) + .pipe(mergeMap(attributes => { + if (attributes.length) { + const edgeVersion = attributes[0].value; + return this.edgeService.getEdgeUpgradeInstructions(edgeVersion, method); + } + })); + } else { + edgeInstructions$ = this.edgeService.getEdgeInstallInstructions(this.data.edge.id.id, method); + } + edgeInstructions$.subscribe(res => { + this.contentData[method] = res.instructions; + this.loadedInstructions = true; + }); } } } diff --git a/ui-ngx/src/app/modules/home/pages/edge/edge.component.html b/ui-ngx/src/app/modules/home/pages/edge/edge.component.html index 9c9a78f91a..3d0baad650 100644 --- a/ui-ngx/src/app/modules/home/pages/edge/edge.component.html +++ b/ui-ngx/src/app/modules/home/pages/edge/edge.component.html @@ -114,13 +114,26 @@
- +
+ + + + + + +
diff --git a/ui-ngx/src/app/modules/home/pages/edge/edge.component.ts b/ui-ngx/src/app/modules/home/pages/edge/edge.component.ts index 78c8df6c08..b7cb2b1752 100644 --- a/ui-ngx/src/app/modules/home/pages/edge/edge.component.ts +++ b/ui-ngx/src/app/modules/home/pages/edge/edge.component.ts @@ -20,12 +20,15 @@ import { AppState } from '@core/core.state'; import { EntityComponent } from '@home/components/entity/entity.component'; import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms'; import { EntityType } from '@shared/models/entity-type.models'; -import { EdgeInfo } from '@shared/models/edge.models'; +import { EdgeInfo, edgeVersionAttributeKey } from '@shared/models/edge.models'; import { TranslateService } from '@ngx-translate/core'; import { NULL_UUID } from '@shared/models/id/has-uuid'; import { ActionNotificationShow } from '@core/notification/notification.actions'; import { generateSecret, guid } from '@core/utils'; import { EntityTableConfig } from '@home/models/entity/entities-table-config.models'; +import { environment as env } from '@env/environment'; +import { AttributeService } from '@core/http/attribute.service'; +import { AttributeScope } from '@shared/models/telemetry/telemetry.models'; @Component({ selector: 'tb-edge', @@ -37,9 +40,11 @@ export class EdgeComponent extends EntityComponent { entityType = EntityType; edgeScope: 'tenant' | 'customer' | 'customer_user'; + upgradeAvailable: boolean = false; constructor(protected store: Store, protected translate: TranslateService, + private attributeService: AttributeService, @Inject('entity') protected entityValue: EdgeInfo, @Inject('entitiesTableConfig') protected entitiesTableConfigValue: EntityTableConfig, public fb: UntypedFormBuilder, @@ -95,6 +100,7 @@ export class EdgeComponent extends EntityComponent { } }); this.generateRoutingKeyAndSecret(entity, this.entityForm); + this.checkEdgeVersion(); } updateFormState() { @@ -133,4 +139,25 @@ export class EdgeComponent extends EntityComponent { form.get('secret').patchValue(generateSecret(20), {emitEvent: false}); } } + + checkEdgeVersion() { + this.attributeService.getEntityAttributes(this.entity.id, AttributeScope.SERVER_SCOPE, [edgeVersionAttributeKey]) + .subscribe(attributes => { + if (attributes?.length) { + const edgeVersion = attributes[0].value; + const tbVersion = 'V_' + env.tbVersion.replaceAll('.', '_'); + this.upgradeAvailable = this.versionUpgradeSupported(edgeVersion) && (edgeVersion !== tbVersion); + } else { + this.upgradeAvailable = false; + } + } + ); + } + + private versionUpgradeSupported(edgeVersion: string): boolean { + const edgeVersionArray = edgeVersion.split('_'); + const major = parseInt(edgeVersionArray[1]); + const minor = parseInt(edgeVersionArray[2]); + return major >= 3 && minor >= 6; + } } diff --git a/ui-ngx/src/app/modules/home/pages/edge/edges-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/edge/edges-table-config.resolver.ts index 6a80388b52..fa08c0daa0 100644 --- a/ui-ngx/src/app/modules/home/pages/edge/edges-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/edge/edges-table-config.resolver.ts @@ -558,7 +558,7 @@ export class EdgesTableConfigResolver implements Resolve { if (afterAdd) { @@ -610,9 +611,12 @@ export class EdgesTableConfigResolver implements Resolve { body: string; } -export interface EdgeInstallInstructions { - installInstructions: string; +export interface EdgeInstructions { + instructions: string; } export enum EdgeInstructionsMethod { @@ -187,3 +187,5 @@ export enum EdgeInstructionsMethod { centos, docker } + +export const edgeVersionAttributeKey = 'edgeVersion'; diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 37bc5d449f..4bd0361c36 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -2017,6 +2017,7 @@ "sync-process-started-successfully": "Sync process started successfully!", "missing-related-rule-chains-title": "Edge has missing related rule chain(s)", "missing-related-rule-chains-text": "Assigned to edge rule chain(s) use rule nodes that forward message(s) to rule chain(s) that are not assigned to this edge.

List of missing rule chain(s):
{{missingRuleChains}}", + "upgrade-instructions": "Upgrade Instructions", "widget-datasource-error": "This widget supports only EDGE entity datasource" }, "edge-event": {