Showing
4 changed files
with
32 additions
and
18 deletions
... | ... | @@ -50,10 +50,6 @@ public class AlarmsCleanUpService { |
50 | 50 | |
51 | 51 | @Scheduled(initialDelayString = "${sql.ttl.alarms.checking_interval}", fixedDelayString = "${sql.ttl.alarms.checking_interval}") |
52 | 52 | public void cleanUp() { |
53 | - if (!partitionService.resolve(ServiceType.TB_CORE, TenantId.SYS_TENANT_ID, TenantId.SYS_TENANT_ID).isMyPartition()) { | |
54 | - return; | |
55 | - } | |
56 | - | |
57 | 53 | PageLink tenantsBatchRequest = new PageLink(65536, 0); |
58 | 54 | PageLink alarmsRemovalBatchRequest = new PageLink(removalBatchSize, 0); |
59 | 55 | long currentTime = System.currentTimeMillis(); |
... | ... | @@ -61,20 +57,22 @@ public class AlarmsCleanUpService { |
61 | 57 | PageData<TenantId> tenantsIds; |
62 | 58 | do { |
63 | 59 | tenantsIds = tenantDao.findTenantsIds(tenantsBatchRequest); |
64 | - tenantsIds.getData().forEach(tenantId -> { | |
65 | - Optional<DefaultTenantProfileConfiguration> tenantProfileConfiguration = tenantProfileCache.get(tenantId).getProfileConfiguration(); | |
66 | - if (tenantProfileConfiguration.isEmpty() || tenantProfileConfiguration.get().getAlarmsTtlDays() == 0) { | |
67 | - return; | |
68 | - } | |
60 | + tenantsIds.getData().stream() | |
61 | + .filter(tenantId -> partitionService.resolve(ServiceType.TB_CORE, tenantId, tenantId).isMyPartition()) | |
62 | + .forEach(tenantId -> { | |
63 | + Optional<DefaultTenantProfileConfiguration> tenantProfileConfiguration = tenantProfileCache.get(tenantId).getProfileConfiguration(); | |
64 | + if (tenantProfileConfiguration.isEmpty() || tenantProfileConfiguration.get().getAlarmsTtlDays() == 0) { | |
65 | + return; | |
66 | + } | |
69 | 67 | |
70 | - PageData<UUID> toRemove; | |
71 | - long outdatageTime = currentTime - TimeUnit.DAYS.toMillis(tenantProfileConfiguration.get().getAlarmsTtlDays()); | |
72 | - log.info("Cleaning up outdated alarms for tenant {}", tenantId); | |
73 | - do { | |
74 | - toRemove = alarmDao.findAlarmsIdsByEndTsBeforeAndTenantId(outdatageTime, tenantId, alarmsRemovalBatchRequest); | |
75 | - alarmDao.removeAllByIds(toRemove.getData()); | |
76 | - } while (toRemove.hasNext()); | |
77 | - }); | |
68 | + PageData<UUID> toRemove; | |
69 | + long outdatageTime = currentTime - TimeUnit.DAYS.toMillis(tenantProfileConfiguration.get().getAlarmsTtlDays()); | |
70 | + log.info("Cleaning up outdated alarms for tenant {}", tenantId); | |
71 | + do { | |
72 | + toRemove = alarmDao.findAlarmsIdsByEndTsBeforeAndTenantId(outdatageTime, tenantId, alarmsRemovalBatchRequest); | |
73 | + alarmDao.removeAllByIds(toRemove.getData()); | |
74 | + } while (toRemove.hasNext()); | |
75 | + }); | |
78 | 76 | |
79 | 77 | tenantsBatchRequest = tenantsBatchRequest.nextPageLink(); |
80 | 78 | } while (tenantsIds.hasNext()); | ... | ... |
... | ... | @@ -161,6 +161,18 @@ |
161 | 161 | </mat-error> |
162 | 162 | </mat-form-field> |
163 | 163 | <mat-form-field class="mat-block"> |
164 | + <mat-label translate>tenant-profile.alarms-ttl-days</mat-label> | |
165 | + <input matInput required min="0" step="1" | |
166 | + formControlName="alarmsTtlDays" | |
167 | + type="number"> | |
168 | + <mat-error *ngIf="defaultTenantProfileConfigurationFormGroup.get('alarmsTtlDays').hasError('required')"> | |
169 | + {{ 'tenant-profile.alarms-ttl-days-required' | translate}} | |
170 | + </mat-error> | |
171 | + <mat-error *ngIf="defaultTenantProfileConfigurationFormGroup.get('alarmsTtlDays').hasError('min')"> | |
172 | + {{ 'tenant-profile.alarms-ttl-days-days-range' | translate}} | |
173 | + </mat-error> | |
174 | + </mat-form-field> | |
175 | + <mat-form-field class="mat-block"> | |
164 | 176 | <mat-label translate>tenant-profile.max-rule-node-executions-per-message</mat-label> |
165 | 177 | <input matInput required min="0" step="1" |
166 | 178 | formControlName="maxRuleNodeExecutionsPerMessage" | ... | ... |
... | ... | @@ -74,7 +74,8 @@ export class DefaultTenantProfileConfigurationComponent implements ControlValueA |
74 | 74 | maxEmails: [null, [Validators.required, Validators.min(0)]], |
75 | 75 | maxSms: [null, [Validators.required, Validators.min(0)]], |
76 | 76 | maxCreatedAlarms: [null, [Validators.required, Validators.min(0)]], |
77 | - defaultStorageTtlDays: [null, [Validators.required, Validators.min(0)]] | |
77 | + defaultStorageTtlDays: [null, [Validators.required, Validators.min(0)]], | |
78 | + alarmsTtlDays: [null, [Validators.required, Validators.min(0)]] | |
78 | 79 | }); |
79 | 80 | this.defaultTenantProfileConfigurationFormGroup.valueChanges.subscribe(() => { |
80 | 81 | this.updateModel(); | ... | ... |
... | ... | @@ -2522,6 +2522,9 @@ |
2522 | 2522 | "default-storage-ttl-days": "Default storage TTL days (0 - unlimited)", |
2523 | 2523 | "default-storage-ttl-days-required": "Default storage TTL days is required.", |
2524 | 2524 | "default-storage-ttl-days-range": "Default storage TTL days can't be negative", |
2525 | + "alarms-ttl-days": "Alarms TTL days (0 - unlimited)", | |
2526 | + "alarms-ttl-days-required": "Alarms TTL days required", | |
2527 | + "alarms-ttl-days-days-range": "Alarms TTL days can't be negative", | |
2525 | 2528 | "max-rule-node-executions-per-message": "Maximum number of rule node executions per message (0 - unlimited)", |
2526 | 2529 | "max-rule-node-executions-per-message-required": "Maximum number of rule node executions per message is required.", |
2527 | 2530 | "max-rule-node-executions-per-message-range": "Maximum number of rule node executions per message can't be negative", | ... | ... |