diff --git a/application/src/main/resources/thingsboard.yml b/application/src/main/resources/thingsboard.yml index df60bbff4f..4ffa7f31d2 100644 --- a/application/src/main/resources/thingsboard.yml +++ b/application/src/main/resources/thingsboard.yml @@ -1318,6 +1318,8 @@ transport: ignore_type_cast_errors: "${SNMP_RESPONSE_IGNORE_TYPE_CAST_ERRORS:false}" # Thread pool size for scheduler that executes device querying tasks scheduler_thread_pool_size: "${SNMP_SCHEDULER_THREAD_POOL_SIZE:4}" + # Maximum number of retry attempts for a single SNMP devices batch during bootstrap. + batch_retries: "${SNMP_BOOTSTRAP_RETRIES:8}" stats: # Enable/Disable the collection of transport statistics enabled: "${TB_TRANSPORT_STATS_ENABLED:true}" diff --git a/common/transport/snmp/src/main/java/org/thingsboard/server/transport/snmp/SnmpTransportContext.java b/common/transport/snmp/src/main/java/org/thingsboard/server/transport/snmp/SnmpTransportContext.java index 56b4e00162..93ce3d1278 100644 --- a/common/transport/snmp/src/main/java/org/thingsboard/server/transport/snmp/SnmpTransportContext.java +++ b/common/transport/snmp/src/main/java/org/thingsboard/server/transport/snmp/SnmpTransportContext.java @@ -15,11 +15,14 @@ */ package org.thingsboard.server.transport.snmp; +import jakarta.annotation.PreDestroy; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; +import org.thingsboard.common.util.ThingsBoardThreadFactory; import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.DeviceProfile; import org.thingsboard.server.common.data.DeviceTransportType; @@ -53,9 +56,12 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentLinkedDeque; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; @TbSnmpTransportComponent @Component @@ -72,30 +78,52 @@ public class SnmpTransportContext extends TransportContext { private final SnmpAuthService snmpAuthService; private final Map sessions = new ConcurrentHashMap<>(); - private final Collection allSnmpDevicesIds = new ConcurrentLinkedDeque<>(); + private final Set allSnmpDevicesIds = ConcurrentHashMap.newKeySet(); + private final ExecutorService snmpExecutor = Executors.newSingleThreadExecutor(ThingsBoardThreadFactory.forName("snmp-bootstrap")); + + @Value("${transport.snmp.batch_retries}") + private int snmpBootstrapBatchRetries; @AfterStartUp(order = AfterStartUp.AFTER_TRANSPORT_SERVICE) public void fetchDevicesAndEstablishSessions() { - log.info("Initializing SNMP devices sessions"); + snmpExecutor.execute(this::bootstrapWithRetries); + } + private void bootstrapWithRetries() { + log.info("Initializing SNMP devices sessions"); int batchIndex = 0; int batchSize = 512; boolean nextBatchExists = true; while (nextBatchExists) { - TransportProtos.GetSnmpDevicesResponseMsg snmpDevicesResponse = protoEntityService.getSnmpDevicesIds(batchIndex, batchSize); - snmpDevicesResponse.getIdsList().stream() - .map(id -> new DeviceId(UUID.fromString(id))) - .peek(allSnmpDevicesIds::add) - .filter(deviceId -> balancingService.isManagedByCurrentTransport(deviceId.getId())) - .map(protoEntityService::getDeviceById) - .forEach(device -> getExecutor().execute(() -> establishDeviceSession(device))); - - nextBatchExists = snmpDevicesResponse.getHasNextPage(); - batchIndex++; + for (int attempt = 1; attempt <= snmpBootstrapBatchRetries; attempt++) { + try { + TransportProtos.GetSnmpDevicesResponseMsg snmpDevicesResponse = protoEntityService.getSnmpDevicesIds(batchIndex, batchSize); + snmpDevicesResponse.getIdsList().stream() + .map(id -> new DeviceId(UUID.fromString(id))) + .peek(allSnmpDevicesIds::add) + .filter(deviceId -> balancingService.isManagedByCurrentTransport(deviceId.getId())) + .map(protoEntityService::getDeviceById) + .forEach(device -> getExecutor().execute(() -> establishDeviceSession(device))); + nextBatchExists = snmpDevicesResponse.getHasNextPage(); + batchIndex++; + break; + } catch (Exception e) { + if (attempt >= snmpBootstrapBatchRetries) { + log.error("SNMP bootstrap: batch {} failed after {} attempts.", batchIndex, attempt, e); + return; + } + log.warn("SNMP bootstrap: batch {} attempt {}/{} failed.", batchIndex, attempt, snmpBootstrapBatchRetries, e); + try { + TimeUnit.SECONDS.sleep(10); + } catch (InterruptedException ex) { + log.warn("SNMP bootstrap interrupted. Stopping bootstrap task."); + return; + } + } + } } - - log.debug("Found all SNMP devices ids: {}", allSnmpDevicesIds); + log.debug("Found SNMP devices ids: {}", allSnmpDevicesIds); } private void establishDeviceSession(Device device) { @@ -300,4 +328,9 @@ public class SnmpTransportContext extends TransportContext { return sessions.values(); } + @PreDestroy + public void destroy() { + snmpExecutor.shutdown(); + } + } diff --git a/transport/snmp/src/main/resources/tb-snmp-transport.yml b/transport/snmp/src/main/resources/tb-snmp-transport.yml index 79aee31921..567654cce4 100644 --- a/transport/snmp/src/main/resources/tb-snmp-transport.yml +++ b/transport/snmp/src/main/resources/tb-snmp-transport.yml @@ -151,6 +151,8 @@ transport: ignore_type_cast_errors: "${SNMP_RESPONSE_IGNORE_TYPE_CAST_ERRORS:false}" # Thread pool size for scheduler that executes device querying tasks scheduler_thread_pool_size: "${SNMP_SCHEDULER_THREAD_POOL_SIZE:4}" + # Maximum number of retry attempts for a single SNMP devices batch during bootstrap. + batch_retries: "${SNMP_BOOTSTRAP_RETRIES:8}" sessions: # Session inactivity timeout is a global configuration parameter that defines how long the device transport session will be opened after the last message arrives from the device. # The parameter value is in milliseconds. diff --git a/ui-ngx/src/app/modules/home/components/github-badge/github-badge.component.html b/ui-ngx/src/app/modules/home/components/github-badge/github-badge.component.html index 6bcab29793..67ec4c7a7d 100644 --- a/ui-ngx/src/app/modules/home/components/github-badge/github-badge.component.html +++ b/ui-ngx/src/app/modules/home/components/github-badge/github-badge.component.html @@ -17,10 +17,19 @@ --> @if (githubStar > 0) {
- - mdi:github -
GitHubstar{{ githubStar | number }}
-
+
} diff --git a/ui-ngx/src/app/modules/home/components/github-badge/github-badge.component.scss b/ui-ngx/src/app/modules/home/components/github-badge/github-badge.component.scss index ee1d306f07..08e130f7ec 100644 --- a/ui-ngx/src/app/modules/home/components/github-badge/github-badge.component.scss +++ b/ui-ngx/src/app/modules/home/components/github-badge/github-badge.component.scss @@ -20,16 +20,31 @@ --mat-outlined-button-horizontal-padding: 8px; --mdc-outlined-button-container-height: 30px; --mdc-outlined-button-label-text-size: 12px; + --mat-outlined-button-hover-state-layer-opacity: 0; + --mat-icon-button-hover-state-layer-opacity: 0; - .mdc-button { - background-color: rgba(255, 255, 255, 0.12); + .group { + .mdc-button { + background-color: rgba(255, 255, 255, 0.12); + } &:hover { - background-color: rgba(255, 255, 255, 0.20); + .mdc-button { + background-color: rgba(255, 255, 255, 0.20); + } + } + + .mdc-icon-button { + background-color: #162C41; + + &:hover { + background-color: #DD2C00; + } } } .button-label { - margin-top: 1px; + height: 28px; + --mat-divider-color: var(--mdc-outlined-button-label-text-color); } } diff --git a/ui-ngx/src/app/modules/home/components/github-badge/github-badge.component.ts b/ui-ngx/src/app/modules/home/components/github-badge/github-badge.component.ts index da46d492c0..b561054d10 100644 --- a/ui-ngx/src/app/modules/home/components/github-badge/github-badge.component.ts +++ b/ui-ngx/src/app/modules/home/components/github-badge/github-badge.component.ts @@ -14,21 +14,66 @@ /// limitations under the License. /// -import { Component } from '@angular/core'; +import { Component, OnDestroy } from '@angular/core'; import { GitHubService } from '@core/http/git-hub.service'; +import { Store } from '@ngrx/store'; +import { selectAuthUser, selectIsAuthenticated } from '@core/auth/auth.selectors'; +import { distinctUntilChanged, filter, map, switchMap, take, takeUntil } from 'rxjs/operators'; +import { Authority } from '@shared/models/authority.enum'; +import { AppState } from '@core/core.state'; +import { LocalStorageService } from '@core/local-storage/local-storage.service'; +import { Subject } from 'rxjs'; + +const SETTINGS_KEY = 'HIDE_GITHUB_STAR_BUTTON'; @Component({ selector: 'tb-github-badge', templateUrl: './github-badge.component.html', styleUrl: './github-badge.component.scss' }) -export class GithubBadgeComponent { +export class GithubBadgeComponent implements OnDestroy { githubStar = 0; - constructor(private gitHubService: GitHubService) { - this.gitHubService.getGitHubStar().subscribe(star => { - this.githubStar = star; - }); + private stopWatch$ = new Subject(); + + constructor(private gitHubService: GitHubService, + private localStorageService: LocalStorageService, + private store: Store,) { + const hide = this.localStorageService.getItem(SETTINGS_KEY) ?? false; + + if (!hide) { + this.store.select(selectIsAuthenticated).pipe( + filter((data) => data), + switchMap(() => this.store.select(selectAuthUser).pipe(take(1))), + map((authUser) => { + return [Authority.TENANT_ADMIN, Authority.SYS_ADMIN].includes(authUser?.authority ?? Authority.ANONYMOUS) + }), + distinctUntilChanged(), + takeUntil(this.stopWatch$), + ).subscribe(value => { + if (value) { + this.gitHubService.getGitHubStar().subscribe(star => { + this.githubStar = star; + }); + } else { + this.githubStar = 0 + } + }); + } + } + + hideGithubStar($event: Event) { + $event?.stopPropagation(); + this.localStorageService.setItem(SETTINGS_KEY, true); + this.githubStar = 0; + + this.stopWatch$.next(); + this.stopWatch$.complete(); + } + + ngOnDestroy() { + this.stopWatch$.next(); + this.stopWatch$.complete(); } } diff --git a/ui-ngx/src/app/modules/home/pages/notification/recipient/recipient-notification-dialog.component.html b/ui-ngx/src/app/modules/home/pages/notification/recipient/recipient-notification-dialog.component.html index ff239f7155..95715bef87 100644 --- a/ui-ngx/src/app/modules/home/pages/notification/recipient/recipient-notification-dialog.component.html +++ b/ui-ngx/src/app/modules/home/pages/notification/recipient/recipient-notification-dialog.component.html @@ -92,6 +92,7 @@ 0) { this.modelValue = [...value]; - this.entityService.getEntities(this.entityType, value).subscribe( - (entities) => { - this.entities = entities; + this.entityService.getEntities(this.entityType, value) + .subscribe(resolvedEntities => { + this.entities = resolvedEntities; this.entityListFormGroup.get('entities').setValue(this.entities); - if (this.syncIdsWithDB && this.modelValue.length !== entities.length) { - this.modelValue = entities.map(entity => entity.id.id); + if (this.syncIdsWithDB && this.modelValue.length !== this.entities.length) { + this.modelValue = this.entities.map(entity => entity.id.id); + if (!this.modelValue.length) { + this.modelValue = null; + } this.propagateChange(this.modelValue); } - } - ); + }); } else { this.entities = []; this.entityListFormGroup.get('entities').setValue(this.entities); diff --git a/ui-ngx/src/styles.scss b/ui-ngx/src/styles.scss index 62cde47c86..66006ec701 100644 --- a/ui-ngx/src/styles.scss +++ b/ui-ngx/src/styles.scss @@ -902,9 +902,6 @@ pre.tb-highlight { &.tb-mat-12 { @include tb-mat-icon-size(12); } - &.tb-mat-14 { - @include tb-mat-icon-size(14); - } &.tb-mat-16 { @include tb-mat-icon-size(16); }