28 changed files with 141 additions and 206 deletions
@ -1,62 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2022 The Thingsboard Authors |
|
||||
* |
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||
* you may not use this file except in compliance with the License. |
|
||||
* You may obtain a copy of the License at |
|
||||
* |
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||
* |
|
||||
* Unless required by applicable law or agreed to in writing, software |
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||
* See the License for the specific language governing permissions and |
|
||||
* limitations under the License. |
|
||||
*/ |
|
||||
package org.thingsboard.server.service.ttl; |
|
||||
|
|
||||
import lombok.extern.slf4j.Slf4j; |
|
||||
import org.springframework.beans.factory.annotation.Value; |
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; |
|
||||
import org.springframework.scheduling.annotation.Scheduled; |
|
||||
import org.springframework.stereotype.Service; |
|
||||
import org.thingsboard.server.dao.alarm.AlarmCommentDao; |
|
||||
import org.thingsboard.server.dao.sqlts.insert.sql.SqlPartitioningRepository; |
|
||||
import org.thingsboard.server.queue.discovery.PartitionService; |
|
||||
|
|
||||
import java.util.concurrent.TimeUnit; |
|
||||
|
|
||||
import static org.thingsboard.server.dao.model.ModelConstants.ALARM_COMMENT_COLUMN_FAMILY_NAME; |
|
||||
import static org.thingsboard.server.dao.model.ModelConstants.AUDIT_LOG_COLUMN_FAMILY_NAME; |
|
||||
|
|
||||
@Service |
|
||||
@ConditionalOnExpression("${sql.ttl.alarm_comments.enabled:true} && ${sql.ttl.alarm_comments.ttl:0} > 0") |
|
||||
@Slf4j |
|
||||
public class AlarmCommentsCleanUpService extends AbstractCleanUpService { |
|
||||
|
|
||||
private final AlarmCommentDao alarmCommentDao; |
|
||||
private final SqlPartitioningRepository partitioningRepository; |
|
||||
|
|
||||
@Value("${sql.ttl.alarm_comments.ttl:0}") |
|
||||
private long ttlInSec; |
|
||||
@Value("${sql.alarm_comments.partition_size:168}") |
|
||||
private int partitionSizeInHours; |
|
||||
|
|
||||
public AlarmCommentsCleanUpService(PartitionService partitionService, AlarmCommentDao alarmCommentDao, SqlPartitioningRepository partitioningRepository) { |
|
||||
super(partitionService); |
|
||||
this.alarmCommentDao = alarmCommentDao; |
|
||||
this.partitioningRepository = partitioningRepository; |
|
||||
} |
|
||||
|
|
||||
@Scheduled(initialDelayString = "#{T(org.apache.commons.lang3.RandomUtils).nextLong(0, ${sql.ttl.alarm_comments.checking_interval_ms})}", |
|
||||
fixedDelayString = "${sql.ttl.alarm_comments.checking_interval_ms}") |
|
||||
public void cleanUp() { |
|
||||
long commentsExpTime = System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(ttlInSec); |
|
||||
if (isSystemTenantPartitionMine()) { |
|
||||
alarmCommentDao.cleanUpAlarmComments(commentsExpTime); |
|
||||
} else { |
|
||||
partitioningRepository.cleanupPartitionsCache(ALARM_COMMENT_COLUMN_FAMILY_NAME, commentsExpTime, TimeUnit.HOURS.toMillis(partitionSizeInHours)); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,36 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2022 The Thingsboard Authors |
|
||||
* |
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||
* you may not use this file except in compliance with the License. |
|
||||
* You may obtain a copy of the License at |
|
||||
* |
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||
* |
|
||||
* Unless required by applicable law or agreed to in writing, software |
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||
* See the License for the specific language governing permissions and |
|
||||
* limitations under the License. |
|
||||
*/ |
|
||||
package org.thingsboard.server.dao.alarm; |
|
||||
|
|
||||
import lombok.Data; |
|
||||
import org.thingsboard.server.common.data.alarm.AlarmComment; |
|
||||
|
|
||||
@Data |
|
||||
public class AlarmCommentOperationResult { |
|
||||
private final AlarmComment alarmComment; |
|
||||
private final boolean successful; |
|
||||
private final boolean created; |
|
||||
|
|
||||
public AlarmCommentOperationResult(AlarmComment alarmComment, boolean successful) { |
|
||||
this(alarmComment, successful, false); |
|
||||
} |
|
||||
|
|
||||
public AlarmCommentOperationResult(AlarmComment alarmComment, boolean successful, boolean created) { |
|
||||
this.alarmComment = alarmComment; |
|
||||
this.successful = successful; |
|
||||
this.created = created; |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,22 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2022 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.common.data.alarm; |
||||
|
|
||||
|
public enum AlarmCommentType { |
||||
|
|
||||
|
SYSTEM, OTHER; |
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue