Browse Source

Alarms TTL UI

pull/4627/head
Viacheslav Klimov 5 years ago
parent
commit
6c6f9b20ae
  1. 32
      application/src/main/java/org/thingsboard/server/service/ttl/alarms/AlarmsCleanUpService.java
  2. 12
      ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html
  3. 3
      ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.ts
  4. 3
      ui-ngx/src/assets/locale/locale.constant-en_US.json

32
application/src/main/java/org/thingsboard/server/service/ttl/alarms/AlarmsCleanUpService.java

@ -50,10 +50,6 @@ public class AlarmsCleanUpService {
@Scheduled(initialDelayString = "${sql.ttl.alarms.checking_interval}", fixedDelayString = "${sql.ttl.alarms.checking_interval}")
public void cleanUp() {
if (!partitionService.resolve(ServiceType.TB_CORE, TenantId.SYS_TENANT_ID, TenantId.SYS_TENANT_ID).isMyPartition()) {
return;
}
PageLink tenantsBatchRequest = new PageLink(65536, 0);
PageLink alarmsRemovalBatchRequest = new PageLink(removalBatchSize, 0);
long currentTime = System.currentTimeMillis();
@ -61,20 +57,22 @@ public class AlarmsCleanUpService {
PageData<TenantId> tenantsIds;
do {
tenantsIds = tenantDao.findTenantsIds(tenantsBatchRequest);
tenantsIds.getData().forEach(tenantId -> {
Optional<DefaultTenantProfileConfiguration> tenantProfileConfiguration = tenantProfileCache.get(tenantId).getProfileConfiguration();
if (tenantProfileConfiguration.isEmpty() || tenantProfileConfiguration.get().getAlarmsTtlDays() == 0) {
return;
}
tenantsIds.getData().stream()
.filter(tenantId -> partitionService.resolve(ServiceType.TB_CORE, tenantId, tenantId).isMyPartition())
.forEach(tenantId -> {
Optional<DefaultTenantProfileConfiguration> tenantProfileConfiguration = tenantProfileCache.get(tenantId).getProfileConfiguration();
if (tenantProfileConfiguration.isEmpty() || tenantProfileConfiguration.get().getAlarmsTtlDays() == 0) {
return;
}
PageData<UUID> toRemove;
long outdatageTime = currentTime - TimeUnit.DAYS.toMillis(tenantProfileConfiguration.get().getAlarmsTtlDays());
log.info("Cleaning up outdated alarms for tenant {}", tenantId);
do {
toRemove = alarmDao.findAlarmsIdsByEndTsBeforeAndTenantId(outdatageTime, tenantId, alarmsRemovalBatchRequest);
alarmDao.removeAllByIds(toRemove.getData());
} while (toRemove.hasNext());
});
PageData<UUID> toRemove;
long outdatageTime = currentTime - TimeUnit.DAYS.toMillis(tenantProfileConfiguration.get().getAlarmsTtlDays());
log.info("Cleaning up outdated alarms for tenant {}", tenantId);
do {
toRemove = alarmDao.findAlarmsIdsByEndTsBeforeAndTenantId(outdatageTime, tenantId, alarmsRemovalBatchRequest);
alarmDao.removeAllByIds(toRemove.getData());
} while (toRemove.hasNext());
});
tenantsBatchRequest = tenantsBatchRequest.nextPageLink();
} while (tenantsIds.hasNext());

12
ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html

@ -160,6 +160,18 @@
{{ 'tenant-profile.default-storage-ttl-days-range' | translate}}
</mat-error>
</mat-form-field>
<mat-form-field class="mat-block">
<mat-label translate>tenant-profile.alarms-ttl-days</mat-label>
<input matInput required min="0" step="1"
formControlName="alarmsTtlDays"
type="number">
<mat-error *ngIf="defaultTenantProfileConfigurationFormGroup.get('alarmsTtlDays').hasError('required')">
{{ 'tenant-profile.alarms-ttl-days-required' | translate}}
</mat-error>
<mat-error *ngIf="defaultTenantProfileConfigurationFormGroup.get('alarmsTtlDays').hasError('min')">
{{ 'tenant-profile.alarms-ttl-days-days-range' | translate}}
</mat-error>
</mat-form-field>
<mat-form-field class="mat-block">
<mat-label translate>tenant-profile.max-rule-node-executions-per-message</mat-label>
<input matInput required min="0" step="1"

3
ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.ts

@ -74,7 +74,8 @@ export class DefaultTenantProfileConfigurationComponent implements ControlValueA
maxEmails: [null, [Validators.required, Validators.min(0)]],
maxSms: [null, [Validators.required, Validators.min(0)]],
maxCreatedAlarms: [null, [Validators.required, Validators.min(0)]],
defaultStorageTtlDays: [null, [Validators.required, Validators.min(0)]]
defaultStorageTtlDays: [null, [Validators.required, Validators.min(0)]],
alarmsTtlDays: [null, [Validators.required, Validators.min(0)]]
});
this.defaultTenantProfileConfigurationFormGroup.valueChanges.subscribe(() => {
this.updateModel();

3
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -2522,6 +2522,9 @@
"default-storage-ttl-days": "Default storage TTL days (0 - unlimited)",
"default-storage-ttl-days-required": "Default storage TTL days is required.",
"default-storage-ttl-days-range": "Default storage TTL days can't be negative",
"alarms-ttl-days": "Alarms TTL days (0 - unlimited)",
"alarms-ttl-days-required": "Alarms TTL days required",
"alarms-ttl-days-days-range": "Alarms TTL days can't be negative",
"max-rule-node-executions-per-message": "Maximum number of rule node executions per message (0 - unlimited)",
"max-rule-node-executions-per-message-required": "Maximum number of rule node executions per message is required.",
"max-rule-node-executions-per-message-range": "Maximum number of rule node executions per message can't be negative",

Loading…
Cancel
Save