34 changed files with 951 additions and 3 deletions
@ -0,0 +1,144 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.housekeeper; |
|||
|
|||
import com.datastax.oss.driver.api.core.uuid.Uuids; |
|||
import com.google.protobuf.ByteString; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.stereotype.Service; |
|||
import org.thingsboard.common.util.ThingsBoardThreadFactory; |
|||
import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; |
|||
import org.thingsboard.server.dao.housekeeper.HousekeeperService; |
|||
import org.thingsboard.server.dao.housekeeper.data.HousekeeperTask; |
|||
import org.thingsboard.server.dao.housekeeper.data.HousekeeperTaskType; |
|||
import org.thingsboard.server.gen.transport.TransportProtos.HousekeeperTaskProto; |
|||
import org.thingsboard.server.gen.transport.TransportProtos.ToHousekeeperServiceMsg; |
|||
import org.thingsboard.server.queue.TbQueueConsumer; |
|||
import org.thingsboard.server.queue.TbQueueProducer; |
|||
import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
|||
import org.thingsboard.server.queue.provider.TbCoreQueueFactory; |
|||
import org.thingsboard.server.queue.provider.TbQueueProducerProvider; |
|||
import org.thingsboard.server.queue.util.AfterStartUp; |
|||
import org.thingsboard.server.queue.util.DataDecodingEncodingService; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
import org.thingsboard.server.service.housekeeper.processor.HousekeeperTaskProcessor; |
|||
|
|||
import javax.annotation.PreDestroy; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.concurrent.ExecutorService; |
|||
import java.util.concurrent.Executors; |
|||
import java.util.stream.Collectors; |
|||
|
|||
@TbCoreComponent |
|||
@Service |
|||
@Slf4j |
|||
public class DefaultHousekeeperService implements HousekeeperService { |
|||
|
|||
private final Map<HousekeeperTaskType, HousekeeperTaskProcessor> taskProcessors; |
|||
|
|||
private final TbQueueConsumer<TbProtoQueueMsg<ToHousekeeperServiceMsg>> consumer; |
|||
private final TbQueueProducer<TbProtoQueueMsg<ToHousekeeperServiceMsg>> producer; |
|||
private final HousekeeperReprocessingService reprocessingService; |
|||
private final DataDecodingEncodingService dataDecodingEncodingService; |
|||
private final ExecutorService consumerExecutor = Executors.newSingleThreadExecutor(ThingsBoardThreadFactory.forName("housekeeper-consumer")); |
|||
|
|||
@Value("${queue.core.housekeeper.poll-interval-ms:10000}") |
|||
private int pollInterval; |
|||
|
|||
private boolean stopped; |
|||
|
|||
public DefaultHousekeeperService(HousekeeperReprocessingService reprocessingService, |
|||
TbCoreQueueFactory queueFactory, |
|||
TbQueueProducerProvider producerProvider, |
|||
DataDecodingEncodingService dataDecodingEncodingService, List<HousekeeperTaskProcessor> taskProcessors) { |
|||
this.consumer = queueFactory.createHousekeeperMsgConsumer(); |
|||
this.producer = producerProvider.getHousekeeperMsgProducer(); |
|||
this.reprocessingService = reprocessingService; |
|||
this.taskProcessors = taskProcessors.stream().collect(Collectors.toMap(HousekeeperTaskProcessor::getTaskType, p -> p)); |
|||
this.dataDecodingEncodingService = dataDecodingEncodingService; |
|||
} |
|||
|
|||
@AfterStartUp(order = AfterStartUp.REGULAR_SERVICE) |
|||
public void afterStartUp() { |
|||
consumer.subscribe(); |
|||
consumerExecutor.submit(() -> { |
|||
while (!stopped && !consumer.isStopped()) { |
|||
try { |
|||
List<TbProtoQueueMsg<ToHousekeeperServiceMsg>> msgs = consumer.poll(pollInterval); |
|||
if (msgs.isEmpty()) { |
|||
continue; |
|||
} |
|||
|
|||
for (TbProtoQueueMsg<ToHousekeeperServiceMsg> msg : msgs) { |
|||
try { |
|||
processTask(msg); |
|||
} catch (Exception e) { |
|||
log.error("Message processing failed", e); |
|||
} |
|||
} |
|||
consumer.commit(); |
|||
} catch (Throwable t) { |
|||
if (!consumer.isStopped()) { |
|||
log.warn("Failed to process messages from queue", t); |
|||
try { |
|||
Thread.sleep(pollInterval); |
|||
} catch (InterruptedException interruptedException) { |
|||
log.trace("Failed to wait until the server has capacity to handle new requests", interruptedException); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
}); |
|||
log.info("Started Housekeeper service"); |
|||
} |
|||
|
|||
protected void processTask(TbProtoQueueMsg<ToHousekeeperServiceMsg> msg) { |
|||
HousekeeperTask task = dataDecodingEncodingService.<HousekeeperTask>decode(msg.getValue().getTask().getValue().toByteArray()).get(); |
|||
HousekeeperTaskProcessor taskProcessor = taskProcessors.get(task.getTaskType()); |
|||
if (taskProcessor == null) { |
|||
log.error("Unsupported task type {}: {}", task.getTaskType(), task); |
|||
return; |
|||
} |
|||
|
|||
log.info("[{}] Processing task: {}", task.getTenantId(), task); |
|||
try { |
|||
taskProcessor.process(task); |
|||
} catch (Exception e) { |
|||
log.error("[{}] Task processing failed: {}", task.getTenantId(), task, e); |
|||
reprocessingService.submitForReprocessing(msg); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void submitTask(HousekeeperTask task) { |
|||
TopicPartitionInfo tpi = TopicPartitionInfo.builder().topic(producer.getDefaultTopic()).build(); |
|||
producer.send(tpi, new TbProtoQueueMsg<>(Uuids.timeBased(), ToHousekeeperServiceMsg.newBuilder() |
|||
.setTask(HousekeeperTaskProto.newBuilder() |
|||
.setValue(ByteString.copyFrom(dataDecodingEncodingService.encode(task))) |
|||
.build()) |
|||
.build()), null); |
|||
} |
|||
|
|||
@PreDestroy |
|||
private void stop() { |
|||
log.info("Stopped Housekeeper service"); |
|||
stopped = true; |
|||
consumer.unsubscribe(); |
|||
consumerExecutor.shutdownNow(); |
|||
} |
|||
} |
|||
@ -0,0 +1,134 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.housekeeper; |
|||
|
|||
import com.datastax.oss.driver.api.core.uuid.Uuids; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.context.annotation.Lazy; |
|||
import org.springframework.stereotype.Service; |
|||
import org.thingsboard.common.util.ThingsBoardThreadFactory; |
|||
import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; |
|||
import org.thingsboard.server.gen.transport.TransportProtos.ToHousekeeperServiceMsg; |
|||
import org.thingsboard.server.queue.TbQueueConsumer; |
|||
import org.thingsboard.server.queue.TbQueueMsgHeaders; |
|||
import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
|||
import org.thingsboard.server.queue.provider.TbCoreQueueFactory; |
|||
import org.thingsboard.server.queue.provider.TbQueueProducerProvider; |
|||
import org.thingsboard.server.queue.util.AfterStartUp; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
|
|||
import javax.annotation.PreDestroy; |
|||
import java.util.List; |
|||
import java.util.Optional; |
|||
import java.util.concurrent.ExecutorService; |
|||
import java.util.concurrent.Executors; |
|||
|
|||
import static org.thingsboard.server.queue.common.AbstractTbQueueTemplate.bytesToLong; |
|||
import static org.thingsboard.server.queue.common.AbstractTbQueueTemplate.longToBytes; |
|||
|
|||
@TbCoreComponent |
|||
@Service |
|||
@Slf4j |
|||
public class HousekeeperReprocessingService { |
|||
|
|||
private final DefaultHousekeeperService housekeeperService; |
|||
private final TbQueueProducerProvider producerProvider; |
|||
private final TbQueueConsumer<TbProtoQueueMsg<ToHousekeeperServiceMsg>> consumer; |
|||
private final ExecutorService consumerExecutor = Executors.newSingleThreadExecutor(ThingsBoardThreadFactory.forName("housekeeper-reprocessing-consumer")); |
|||
|
|||
@Value("${queue.core.housekeeper.poll-interval-ms:10000}") |
|||
private int pollInterval; |
|||
|
|||
private final long startTs = System.currentTimeMillis(); |
|||
private boolean stopped; |
|||
// todo: stats
|
|||
|
|||
public HousekeeperReprocessingService(@Lazy DefaultHousekeeperService housekeeperService, |
|||
TbCoreQueueFactory queueFactory, |
|||
TbQueueProducerProvider producerProvider) { |
|||
this.housekeeperService = housekeeperService; |
|||
this.consumer = queueFactory.createHousekeeperDelayedMsgConsumer(); |
|||
this.producerProvider = producerProvider; |
|||
} |
|||
|
|||
@AfterStartUp(order = AfterStartUp.REGULAR_SERVICE) |
|||
public void afterStartUp() { |
|||
consumer.subscribe(); |
|||
consumerExecutor.submit(() -> { |
|||
while (!stopped && !consumer.isStopped()) { |
|||
try { |
|||
List<TbProtoQueueMsg<ToHousekeeperServiceMsg>> msgs = consumer.poll(pollInterval); |
|||
if (msgs.isEmpty()) { |
|||
stop(); |
|||
return; |
|||
} |
|||
|
|||
for (TbProtoQueueMsg<ToHousekeeperServiceMsg> msg : msgs) { |
|||
long msgTs = Uuids.unixTimestamp(msg.getKey()); |
|||
if (msgTs >= startTs) { |
|||
stop(); |
|||
return; // fixme: we should commit already reprocessed messages
|
|||
} |
|||
|
|||
try { |
|||
reprocessTask(msg); |
|||
} catch (Exception e) { |
|||
log.error("Message processing failed", e); |
|||
} |
|||
} |
|||
consumer.commit(); |
|||
} catch (Throwable t) { |
|||
if (!consumer.isStopped()) { |
|||
log.warn("Failed to process messages from queue", t); |
|||
try { |
|||
Thread.sleep(pollInterval); |
|||
} catch (InterruptedException interruptedException) { |
|||
log.trace("Failed to wait until the server has capacity to handle new requests", interruptedException); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
}); |
|||
log.info("Started Housekeeper tasks reprocessing"); |
|||
} |
|||
|
|||
private void reprocessTask(TbProtoQueueMsg<ToHousekeeperServiceMsg> msg) { |
|||
housekeeperService.processTask(msg);// fixme: or should we submit to queue?
|
|||
} |
|||
|
|||
public void submitForReprocessing(TbProtoQueueMsg<ToHousekeeperServiceMsg> msg) { |
|||
TbQueueMsgHeaders msgHeaders = msg.getHeaders(); |
|||
long reprocessingAttempts = Optional.ofNullable(msgHeaders.get("reprocessingAttempts")) |
|||
.map(header -> bytesToLong(header)) |
|||
.orElse(0L); |
|||
reprocessingAttempts++; |
|||
msgHeaders.put("reprocessingAttempts", longToBytes(reprocessingAttempts)); |
|||
|
|||
var producer = producerProvider.getHousekeeperDelayedMsgProducer(); |
|||
TopicPartitionInfo tpi = TopicPartitionInfo.builder().topic(producer.getDefaultTopic()).build(); |
|||
producer.send(tpi, new TbProtoQueueMsg<>(Uuids.timeBased(), msg.getValue(), msgHeaders), null); |
|||
} |
|||
|
|||
@PreDestroy |
|||
private void stop() { |
|||
log.info("Stopped Housekeeper tasks reprocessing"); |
|||
stopped = true; |
|||
consumer.unsubscribe(); |
|||
consumerExecutor.shutdownNow(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.housekeeper.processor; |
|||
|
|||
import lombok.RequiredArgsConstructor; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.DataConstants; |
|||
import org.thingsboard.server.dao.attributes.AttributesService; |
|||
import org.thingsboard.server.dao.housekeeper.data.HousekeeperTask; |
|||
import org.thingsboard.server.dao.housekeeper.data.HousekeeperTaskType; |
|||
|
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class AttributesDeletionTaskProcessor implements HousekeeperTaskProcessor { |
|||
|
|||
private final AttributesService attributesService; |
|||
|
|||
@Override |
|||
public void process(HousekeeperTask task) throws Exception { |
|||
// attributesService.removeAll(task.getTenantId(), task.getEntityId(), DataConstants.CLIENT_SCOPE);
|
|||
} |
|||
|
|||
@Override |
|||
public HousekeeperTaskType getTaskType() { |
|||
return HousekeeperTaskType.DELETE_ATTRIBUTES; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.housekeeper.processor; |
|||
|
|||
import lombok.RequiredArgsConstructor; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.dao.housekeeper.data.HousekeeperTask; |
|||
import org.thingsboard.server.dao.housekeeper.data.HousekeeperTaskType; |
|||
|
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class EntityDeletionTaskProcessor implements HousekeeperTaskProcessor { |
|||
|
|||
@Override |
|||
public void process(HousekeeperTask task) throws Exception { |
|||
|
|||
} |
|||
|
|||
@Override |
|||
public HousekeeperTaskType getTaskType() { |
|||
return HousekeeperTaskType.DELETE_ENTITY; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.housekeeper.processor; |
|||
|
|||
import lombok.RequiredArgsConstructor; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.dao.event.EventService; |
|||
import org.thingsboard.server.dao.housekeeper.data.HousekeeperTask; |
|||
import org.thingsboard.server.dao.housekeeper.data.HousekeeperTaskType; |
|||
|
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class EventsDeletionTaskProcessor implements HousekeeperTaskProcessor { |
|||
private final EventService eventService; |
|||
|
|||
@Override |
|||
public void process(HousekeeperTask task) throws Exception { |
|||
eventService.removeEvents(task.getTenantId(), task.getEntityId(), null, 0L, System.currentTimeMillis()); |
|||
} |
|||
|
|||
@Override |
|||
public HousekeeperTaskType getTaskType() { |
|||
return HousekeeperTaskType.DELETE_EVENTS; |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.housekeeper.processor; |
|||
|
|||
import org.thingsboard.server.dao.housekeeper.data.HousekeeperTask; |
|||
import org.thingsboard.server.dao.housekeeper.data.HousekeeperTaskType; |
|||
|
|||
public interface HousekeeperTaskProcessor { |
|||
|
|||
void process(HousekeeperTask task) throws Exception; |
|||
|
|||
HousekeeperTaskType getTaskType(); |
|||
|
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.housekeeper.processor; |
|||
|
|||
import lombok.RequiredArgsConstructor; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.dao.housekeeper.data.HousekeeperTask; |
|||
import org.thingsboard.server.dao.housekeeper.data.HousekeeperTaskType; |
|||
import org.thingsboard.server.dao.timeseries.TimeseriesService; |
|||
|
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class TelemetryDeletionTaskProcessor implements HousekeeperTaskProcessor { |
|||
|
|||
private final TimeseriesService timeseriesService; |
|||
|
|||
@Override |
|||
public void process(HousekeeperTask task) throws Exception { |
|||
// timeseriesService.remove()
|
|||
// timeseriesService.removeAllLatest();
|
|||
} |
|||
|
|||
@Override |
|||
public HousekeeperTaskType getTaskType() { |
|||
return HousekeeperTaskType.DELETE_ATTRIBUTES; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.housekeeper; |
|||
|
|||
import org.thingsboard.server.dao.housekeeper.data.HousekeeperTask; |
|||
|
|||
public interface HousekeeperService { |
|||
|
|||
void submitTask(HousekeeperTask task); |
|||
|
|||
} |
|||
@ -0,0 +1,51 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.housekeeper.data; |
|||
|
|||
import lombok.Data; |
|||
import org.thingsboard.server.common.data.id.EntityId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/* |
|||
* on start, read the retry queue and put the messages back to main queue (save offset) |
|||
* */ |
|||
@Data |
|||
public class HousekeeperTask implements Serializable { |
|||
|
|||
private final TenantId tenantId; |
|||
private final EntityId entityId; |
|||
private final HousekeeperTaskType taskType; |
|||
|
|||
// maybe we should not delete relations asynchronously
|
|||
// public static HousekeeperTask deleteRelations(TenantId tenantId, EntityId entityId) {
|
|||
// return new HousekeeperTask(tenantId, entityId, HousekeeperTaskType.DELETE_RELATIONS);
|
|||
// }
|
|||
|
|||
public static HousekeeperTask deleteAttributes(TenantId tenantId, EntityId entityId) { |
|||
return new HousekeeperTask(tenantId, entityId, HousekeeperTaskType.DELETE_ATTRIBUTES); |
|||
} |
|||
|
|||
public static HousekeeperTask deleteTelemetry(TenantId tenantId, EntityId entityId) { |
|||
return new HousekeeperTask(tenantId, entityId, HousekeeperTaskType.DELETE_TELEMETRY); |
|||
} |
|||
|
|||
public static HousekeeperTask deleteEvents(TenantId tenantId, EntityId entityId) { |
|||
return new HousekeeperTask(tenantId, entityId, HousekeeperTaskType.DELETE_EVENTS); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.housekeeper.data; |
|||
|
|||
public enum HousekeeperTaskType { |
|||
DELETE_ENTITY, |
|||
DELETE_ATTRIBUTES, |
|||
DELETE_TELEMETRY, // maybe divide into latest and ts kv history?
|
|||
DELETE_EVENTS |
|||
} |
|||
Loading…
Reference in new issue