committed by
GitHub
70 changed files with 3044 additions and 1036 deletions
@ -0,0 +1,230 @@ |
|||
-- |
|||
-- 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. |
|||
-- |
|||
|
|||
CREATE TABLE IF NOT EXISTS rule_node_debug_event ( |
|||
id uuid NOT NULL, |
|||
tenant_id uuid NOT NULL , |
|||
ts bigint NOT NULL, |
|||
entity_id uuid NOT NULL, |
|||
service_id varchar, |
|||
e_type varchar, |
|||
e_entity_id uuid, |
|||
e_entity_type varchar, |
|||
e_msg_id uuid, |
|||
e_msg_type varchar, |
|||
e_data_type varchar, |
|||
e_relation_type varchar, |
|||
e_data varchar, |
|||
e_metadata varchar, |
|||
e_error varchar |
|||
) PARTITION BY RANGE (ts); |
|||
|
|||
CREATE TABLE IF NOT EXISTS rule_chain_debug_event ( |
|||
id uuid NOT NULL, |
|||
tenant_id uuid NOT NULL, |
|||
ts bigint NOT NULL, |
|||
entity_id uuid NOT NULL, |
|||
service_id varchar NOT NULL, |
|||
e_message varchar, |
|||
e_error varchar |
|||
) PARTITION BY RANGE (ts); |
|||
|
|||
CREATE TABLE IF NOT EXISTS stats_event ( |
|||
id uuid NOT NULL, |
|||
tenant_id uuid NOT NULL, |
|||
ts bigint NOT NULL, |
|||
entity_id uuid NOT NULL, |
|||
service_id varchar NOT NULL, |
|||
e_messages_processed bigint NOT NULL, |
|||
e_errors_occurred bigint NOT NULL |
|||
) PARTITION BY RANGE (ts); |
|||
|
|||
CREATE TABLE IF NOT EXISTS lc_event ( |
|||
id uuid NOT NULL, |
|||
tenant_id uuid NOT NULL, |
|||
ts bigint NOT NULL, |
|||
entity_id uuid NOT NULL, |
|||
service_id varchar NOT NULL, |
|||
e_type varchar NOT NULL, |
|||
e_success boolean NOT NULL, |
|||
e_error varchar |
|||
) PARTITION BY RANGE (ts); |
|||
|
|||
CREATE TABLE IF NOT EXISTS error_event ( |
|||
id uuid NOT NULL, |
|||
tenant_id uuid NOT NULL, |
|||
ts bigint NOT NULL, |
|||
entity_id uuid NOT NULL, |
|||
service_id varchar NOT NULL, |
|||
e_method varchar NOT NULL, |
|||
e_error varchar |
|||
) PARTITION BY RANGE (ts); |
|||
|
|||
CREATE INDEX IF NOT EXISTS idx_rule_node_debug_event_main |
|||
ON rule_node_debug_event (tenant_id ASC, entity_id ASC, ts DESC NULLS LAST) WITH (FILLFACTOR=95); |
|||
|
|||
CREATE INDEX IF NOT EXISTS idx_rule_chain_debug_event_main |
|||
ON rule_chain_debug_event (tenant_id ASC, entity_id ASC, ts DESC NULLS LAST) WITH (FILLFACTOR=95); |
|||
|
|||
CREATE INDEX IF NOT EXISTS idx_stats_event_main |
|||
ON stats_event (tenant_id ASC, entity_id ASC, ts DESC NULLS LAST) WITH (FILLFACTOR=95); |
|||
|
|||
CREATE INDEX IF NOT EXISTS idx_lc_event_main |
|||
ON lc_event (tenant_id ASC, entity_id ASC, ts DESC NULLS LAST) WITH (FILLFACTOR=95); |
|||
|
|||
CREATE INDEX IF NOT EXISTS idx_error_event_main |
|||
ON error_event (tenant_id ASC, entity_id ASC, ts DESC NULLS LAST) WITH (FILLFACTOR=95); |
|||
|
|||
CREATE OR REPLACE FUNCTION to_safe_json(p_json text) RETURNS json |
|||
LANGUAGE plpgsql AS |
|||
$$ |
|||
BEGIN |
|||
return REPLACE(p_json, '\u0000', '' )::json; |
|||
EXCEPTION |
|||
WHEN OTHERS THEN |
|||
return '{}'::json; |
|||
END; |
|||
$$; |
|||
|
|||
-- Useful to migrate old events to the new table structure; |
|||
CREATE OR REPLACE PROCEDURE migrate_regular_events(IN start_ts_in_ms bigint, IN end_ts_in_ms bigint, IN partition_size_in_hours int) |
|||
LANGUAGE plpgsql AS |
|||
$$ |
|||
DECLARE |
|||
partition_size_in_ms bigint; |
|||
p record; |
|||
table_name varchar; |
|||
BEGIN |
|||
partition_size_in_ms = partition_size_in_hours * 3600 * 1000; |
|||
|
|||
FOR p IN SELECT DISTINCT event_type as event_type, (created_time - created_time % partition_size_in_ms) as partition_ts FROM event e WHERE e.event_type in ('STATS', 'LC_EVENT', 'ERROR') and ts >= start_ts_in_ms and ts < end_ts_in_ms |
|||
LOOP |
|||
IF p.event_type = 'STATS' THEN |
|||
table_name := 'stats_event'; |
|||
ELSEIF p.event_type = 'LC_EVENT' THEN |
|||
table_name := 'lc_event'; |
|||
ELSEIF p.event_type = 'ERROR' THEN |
|||
table_name := 'error_event'; |
|||
END IF; |
|||
RAISE NOTICE '[%] Partition to create : [%-%]', table_name, p.partition_ts, (p.partition_ts + partition_size_in_ms); |
|||
EXECUTE format('CREATE TABLE IF NOT EXISTS %s_%s PARTITION OF %s FOR VALUES FROM ( %s ) TO ( %s )', table_name, p.partition_ts, table_name, p.partition_ts, (p.partition_ts + partition_size_in_ms)); |
|||
END LOOP; |
|||
|
|||
INSERT INTO stats_event |
|||
SELECT id, |
|||
tenant_id, |
|||
ts, |
|||
entity_id, |
|||
body ->> 'server', |
|||
(body ->> 'messagesProcessed')::bigint, |
|||
(body ->> 'errorsOccurred')::bigint |
|||
FROM |
|||
(select id, tenant_id, ts, entity_id, to_safe_json(body) as body |
|||
FROM event WHERE ts >= start_ts_in_ms and ts < end_ts_in_ms AND event_type = 'STATS' AND to_safe_json(body) ->> 'server' IS NOT NULL |
|||
) safe_event |
|||
ON CONFLICT DO NOTHING; |
|||
|
|||
INSERT INTO lc_event |
|||
SELECT id, |
|||
tenant_id, |
|||
ts, |
|||
entity_id, |
|||
body ->> 'server', |
|||
body ->> 'event', |
|||
(body ->> 'success')::boolean, |
|||
body ->> 'error' |
|||
FROM |
|||
(select id, tenant_id, ts, entity_id, to_safe_json(body) as body |
|||
FROM event WHERE ts >= start_ts_in_ms and ts < end_ts_in_ms AND event_type = 'LC_EVENT' AND to_safe_json(body) ->> 'server' IS NOT NULL |
|||
) safe_event |
|||
ON CONFLICT DO NOTHING; |
|||
|
|||
INSERT INTO error_event |
|||
SELECT id, |
|||
tenant_id, |
|||
ts, |
|||
entity_id, |
|||
body ->> 'server', |
|||
body ->> 'method', |
|||
body ->> 'error' |
|||
FROM |
|||
(select id, tenant_id, ts, entity_id, to_safe_json(body) as body |
|||
FROM event WHERE ts >= start_ts_in_ms and ts < end_ts_in_ms AND event_type = 'ERROR' AND to_safe_json(body) ->> 'server' IS NOT NULL |
|||
) safe_event |
|||
ON CONFLICT DO NOTHING; |
|||
|
|||
END |
|||
$$; |
|||
|
|||
-- Useful to migrate old debug events to the new table structure; |
|||
CREATE OR REPLACE PROCEDURE migrate_debug_events(IN start_ts_in_ms bigint, IN end_ts_in_ms bigint, IN partition_size_in_hours int) |
|||
LANGUAGE plpgsql AS |
|||
$$ |
|||
DECLARE |
|||
partition_size_in_ms bigint; |
|||
p record; |
|||
table_name varchar; |
|||
BEGIN |
|||
partition_size_in_ms = partition_size_in_hours * 3600 * 1000; |
|||
|
|||
FOR p IN SELECT DISTINCT event_type as event_type, (created_time - created_time % partition_size_in_ms) as partition_ts FROM event e WHERE e.event_type in ('DEBUG_RULE_NODE', 'DEBUG_RULE_CHAIN') and ts >= start_ts_in_ms and ts < end_ts_in_ms |
|||
LOOP |
|||
IF p.event_type = 'DEBUG_RULE_NODE' THEN |
|||
table_name := 'rule_node_debug_event'; |
|||
ELSEIF p.event_type = 'DEBUG_RULE_CHAIN' THEN |
|||
table_name := 'rule_chain_debug_event'; |
|||
END IF; |
|||
RAISE NOTICE '[%] Partition to create : [%-%]', table_name, p.partition_ts, (p.partition_ts + partition_size_in_ms); |
|||
EXECUTE format('CREATE TABLE IF NOT EXISTS %s_%s PARTITION OF %s FOR VALUES FROM ( %s ) TO ( %s )', table_name, p.partition_ts, table_name, p.partition_ts, (p.partition_ts + partition_size_in_ms)); |
|||
END LOOP; |
|||
|
|||
INSERT INTO rule_node_debug_event |
|||
SELECT id, |
|||
tenant_id, |
|||
ts, |
|||
entity_id, |
|||
body ->> 'server', |
|||
body ->> 'type', |
|||
(body ->> 'entityId')::uuid, |
|||
body ->> 'entityName', |
|||
(body ->> 'msgId')::uuid, |
|||
body ->> 'msgType', |
|||
body ->> 'dataType', |
|||
body ->> 'relationType', |
|||
body ->> 'data', |
|||
body ->> 'metadata', |
|||
body ->> 'error' |
|||
FROM |
|||
(select id, tenant_id, ts, entity_id, to_safe_json(body) as body |
|||
FROM event WHERE ts >= start_ts_in_ms and ts < end_ts_in_ms AND event_type = 'DEBUG_RULE_NODE' AND to_safe_json(body) ->> 'server' IS NOT NULL |
|||
) safe_event |
|||
ON CONFLICT DO NOTHING; |
|||
|
|||
INSERT INTO rule_chain_debug_event |
|||
SELECT id, |
|||
tenant_id, |
|||
ts, |
|||
entity_id, |
|||
body ->> 'server', |
|||
body ->> 'message', |
|||
body ->> 'error' |
|||
FROM |
|||
(select id, tenant_id, ts, entity_id, to_safe_json(body) as body |
|||
FROM event WHERE ts >= start_ts_in_ms and ts < end_ts_in_ms AND event_type = 'DEBUG_RULE_CHAIN' AND to_safe_json(body) ->> 'server' IS NOT NULL |
|||
) safe_event |
|||
ON CONFLICT DO NOTHING; |
|||
END |
|||
$$; |
|||
@ -0,0 +1,47 @@ |
|||
/** |
|||
* 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.event; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
import org.springframework.data.domain.Page; |
|||
import org.springframework.data.repository.query.Param; |
|||
import org.thingsboard.server.common.data.StringUtils; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
@Data |
|||
@ApiModel |
|||
public abstract class DebugEventFilter implements EventFilter { |
|||
|
|||
@ApiModelProperty(position = 1, value = "String value representing the server name, identifier or ip address where the platform is running", example = "ip-172-31-24-152") |
|||
protected String server; |
|||
@ApiModelProperty(position = 10, value = "Boolean value to filter the errors", allowableValues = "false, true") |
|||
protected boolean isError; |
|||
@ApiModelProperty(position = 11, value = "The case insensitive 'contains' filter based on error message", example = "not present in the DB") |
|||
protected String errorStr; |
|||
|
|||
public void setIsError(boolean isError) { |
|||
this.isError = isError; |
|||
} |
|||
|
|||
@Override |
|||
public boolean isNotEmpty() { |
|||
return !StringUtils.isEmpty(server) || isError || !StringUtils.isEmpty(errorStr); |
|||
} |
|||
|
|||
} |
|||
@ -1,26 +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.common.data.event; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
|
|||
@ApiModel |
|||
public class DebugRuleNodeEventFilter extends DebugEvent { |
|||
@Override |
|||
public EventType getEventType() { |
|||
return EventType.DEBUG_RULE_NODE; |
|||
} |
|||
} |
|||
@ -0,0 +1,66 @@ |
|||
/** |
|||
* 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.event; |
|||
|
|||
import com.fasterxml.jackson.databind.node.ObjectNode; |
|||
import lombok.Builder; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
import org.thingsboard.server.common.data.EventInfo; |
|||
import org.thingsboard.server.common.data.id.EntityId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
@ToString |
|||
@EqualsAndHashCode(callSuper = true) |
|||
public class ErrorEvent extends Event { |
|||
|
|||
private static final long serialVersionUID = 960461434033192571L; |
|||
|
|||
@Builder |
|||
private ErrorEvent(TenantId tenantId, UUID entityId, String serviceId, UUID id, long ts, String method, String error) { |
|||
super(tenantId, entityId, serviceId, id, ts); |
|||
this.method = method; |
|||
this.error = error; |
|||
} |
|||
|
|||
@Getter |
|||
@Setter |
|||
private String method; |
|||
@Getter |
|||
@Setter |
|||
private String error; |
|||
|
|||
@Override |
|||
public EventType getType() { |
|||
return EventType.ERROR; |
|||
} |
|||
|
|||
@Override |
|||
public EventInfo toInfo(EntityType entityType) { |
|||
EventInfo eventInfo = super.toInfo(entityType); |
|||
var json = (ObjectNode) eventInfo.getBody(); |
|||
json.put("method", method); |
|||
if (error != null) { |
|||
json.put("error", error); |
|||
} |
|||
return eventInfo; |
|||
} |
|||
} |
|||
@ -0,0 +1,71 @@ |
|||
/** |
|||
* 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.event; |
|||
|
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
import com.fasterxml.jackson.databind.node.ObjectNode; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import org.thingsboard.server.common.data.BaseData; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
import org.thingsboard.server.common.data.EventInfo; |
|||
import org.thingsboard.server.common.data.id.EntityIdFactory; |
|||
import org.thingsboard.server.common.data.id.EventId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
@Data |
|||
@EqualsAndHashCode(callSuper = true) |
|||
public abstract class Event extends BaseData<EventId> { |
|||
|
|||
protected static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); |
|||
|
|||
protected final TenantId tenantId; |
|||
protected final UUID entityId; |
|||
protected final String serviceId; |
|||
|
|||
public Event(TenantId tenantId, UUID entityId, String serviceId, UUID id, long ts) { |
|||
super(); |
|||
if (id != null) { |
|||
this.id = new EventId(id); |
|||
} |
|||
this.tenantId = tenantId != null ? tenantId : TenantId.SYS_TENANT_ID; |
|||
this.entityId = entityId; |
|||
this.serviceId = serviceId; |
|||
this.createdTime = ts; |
|||
} |
|||
|
|||
public abstract EventType getType(); |
|||
|
|||
public EventInfo toInfo(EntityType entityType) { |
|||
EventInfo eventInfo = new EventInfo(); |
|||
eventInfo.setTenantId(tenantId); |
|||
eventInfo.setEntityId(EntityIdFactory.getByTypeAndUuid(entityType, entityId)); |
|||
eventInfo.setType(getType().getOldName()); |
|||
eventInfo.setId(id); |
|||
eventInfo.setUid(id.toString()); |
|||
eventInfo.setCreatedTime(createdTime); |
|||
eventInfo.setBody(OBJECT_MAPPER.createObjectNode().put("server", getServiceId())); |
|||
return eventInfo; |
|||
} |
|||
|
|||
protected static void putNotNull(ObjectNode json, String key, String value) { |
|||
if (value != null) { |
|||
json.put(key, value); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,74 @@ |
|||
/** |
|||
* 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.event; |
|||
|
|||
import com.fasterxml.jackson.databind.node.ObjectNode; |
|||
import lombok.Builder; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
import lombok.ToString; |
|||
import org.jetbrains.annotations.NotNull; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
import org.thingsboard.server.common.data.EventInfo; |
|||
import org.thingsboard.server.common.data.id.EntityId; |
|||
import org.thingsboard.server.common.data.id.EntityIdFactory; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
@ToString |
|||
@EqualsAndHashCode(callSuper = true) |
|||
public class LifecycleEvent extends Event { |
|||
|
|||
private static final long serialVersionUID = -3247420461850911549L; |
|||
|
|||
@Builder |
|||
private LifecycleEvent(TenantId tenantId, UUID entityId, String serviceId, |
|||
UUID id, long ts, |
|||
String lcEventType, boolean success, String error) { |
|||
super(tenantId, entityId, serviceId, id, ts); |
|||
this.lcEventType = lcEventType; |
|||
this.success = success; |
|||
this.error = error; |
|||
} |
|||
|
|||
@Getter |
|||
private final String lcEventType; |
|||
@Getter |
|||
private final boolean success; |
|||
@Getter |
|||
@Setter |
|||
private String error; |
|||
|
|||
@Override |
|||
public EventType getType() { |
|||
return EventType.LC_EVENT; |
|||
} |
|||
|
|||
@Override |
|||
public EventInfo toInfo(EntityType entityType) { |
|||
EventInfo eventInfo = super.toInfo(entityType); |
|||
var json = (ObjectNode) eventInfo.getBody(); |
|||
json.put("event", lcEventType) |
|||
.put("success", success); |
|||
if (error != null) { |
|||
json.put("error", error); |
|||
} |
|||
return eventInfo; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,63 @@ |
|||
/** |
|||
* 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.event; |
|||
|
|||
import com.fasterxml.jackson.databind.node.ObjectNode; |
|||
import lombok.Builder; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
import org.thingsboard.server.common.data.EventInfo; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
@ToString |
|||
@EqualsAndHashCode(callSuper = true) |
|||
public class RuleChainDebugEvent extends Event { |
|||
|
|||
private static final long serialVersionUID = -386392236201116767L; |
|||
|
|||
@Builder |
|||
private RuleChainDebugEvent(TenantId tenantId, UUID entityId, String serviceId, UUID id, long ts, String message, String error) { |
|||
super(tenantId, entityId, serviceId, id, ts); |
|||
this.message = message; |
|||
this.error = error; |
|||
} |
|||
|
|||
@Getter |
|||
@Setter |
|||
private String message; |
|||
@Getter |
|||
@Setter |
|||
private String error; |
|||
|
|||
@Override |
|||
public EventType getType() { |
|||
return EventType.DEBUG_RULE_CHAIN; |
|||
} |
|||
|
|||
@Override |
|||
public EventInfo toInfo(EntityType entityType) { |
|||
EventInfo eventInfo = super.toInfo(entityType); |
|||
var json = (ObjectNode) eventInfo.getBody(); |
|||
putNotNull(json, "message", message); |
|||
putNotNull(json, "error", error); |
|||
return eventInfo; |
|||
} |
|||
} |
|||
@ -0,0 +1,102 @@ |
|||
/** |
|||
* 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.event; |
|||
|
|||
import com.fasterxml.jackson.databind.node.ObjectNode; |
|||
import lombok.Builder; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
import org.thingsboard.server.common.data.EventInfo; |
|||
import org.thingsboard.server.common.data.id.EntityId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
@ToString |
|||
@EqualsAndHashCode(callSuper = true) |
|||
public class RuleNodeDebugEvent extends Event { |
|||
|
|||
private static final long serialVersionUID = -6575797430064573984L; |
|||
|
|||
@Builder |
|||
private RuleNodeDebugEvent(TenantId tenantId, UUID entityId, String serviceId, UUID id, long ts, |
|||
String eventType, EntityId eventEntity, UUID msgId, |
|||
String msgType, String dataType, String relationType, |
|||
String data, String metadata, String error) { |
|||
super(tenantId, entityId, serviceId, id, ts); |
|||
this.eventType = eventType; |
|||
this.eventEntity = eventEntity; |
|||
this.msgId = msgId; |
|||
this.msgType = msgType; |
|||
this.dataType = dataType; |
|||
this.relationType = relationType; |
|||
this.data = data; |
|||
this.metadata = metadata; |
|||
this.error = error; |
|||
} |
|||
|
|||
@Getter |
|||
private final String eventType; |
|||
@Getter |
|||
private final EntityId eventEntity; |
|||
@Getter |
|||
private final UUID msgId; |
|||
@Getter |
|||
private final String msgType; |
|||
@Getter |
|||
private final String dataType; |
|||
@Getter |
|||
private final String relationType; |
|||
@Getter |
|||
@Setter |
|||
private String data; |
|||
@Getter |
|||
@Setter |
|||
private String metadata; |
|||
@Getter |
|||
@Setter |
|||
private String error; |
|||
|
|||
@Override |
|||
public EventType getType() { |
|||
return EventType.DEBUG_RULE_NODE; |
|||
} |
|||
|
|||
@Override |
|||
public EventInfo toInfo(EntityType entityType) { |
|||
EventInfo eventInfo = super.toInfo(entityType); |
|||
var json = (ObjectNode) eventInfo.getBody(); |
|||
json.put("type", eventType); |
|||
if (eventEntity != null) { |
|||
json.put("entityId", eventEntity.getId().toString()) |
|||
.put("entityType", eventEntity.getEntityType().name()); |
|||
} |
|||
if (msgId != null) { |
|||
json.put("msgId", msgId.toString()); |
|||
} |
|||
putNotNull(json, "msgType", msgType); |
|||
putNotNull(json, "dataType", dataType); |
|||
putNotNull(json, "relationType", relationType); |
|||
putNotNull(json, "data", data); |
|||
putNotNull(json, "metadata", metadata); |
|||
putNotNull(json, "error", error); |
|||
return eventInfo; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,60 @@ |
|||
/** |
|||
* 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.event; |
|||
|
|||
import com.fasterxml.jackson.databind.node.ObjectNode; |
|||
import lombok.Builder; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.Getter; |
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
import org.thingsboard.server.common.data.EventInfo; |
|||
import org.thingsboard.server.common.data.id.EntityId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
@ToString |
|||
@EqualsAndHashCode(callSuper = true) |
|||
public class StatisticsEvent extends Event { |
|||
|
|||
private static final long serialVersionUID = 6683733979448910631L; |
|||
|
|||
@Builder |
|||
private StatisticsEvent(TenantId tenantId, UUID entityId, String serviceId, UUID id, long ts, long messagesProcessed, long errorsOccurred) { |
|||
super(tenantId, entityId, serviceId, id, ts); |
|||
this.messagesProcessed = messagesProcessed; |
|||
this.errorsOccurred = errorsOccurred; |
|||
} |
|||
|
|||
@Getter |
|||
private final long messagesProcessed; |
|||
@Getter |
|||
private final long errorsOccurred; |
|||
|
|||
@Override |
|||
public EventType getType() { |
|||
return EventType.STATS; |
|||
} |
|||
|
|||
@Override |
|||
public EventInfo toInfo(EntityType entityType) { |
|||
EventInfo eventInfo = super.toInfo(entityType); |
|||
var json = (ObjectNode) eventInfo.getBody(); |
|||
json.put("messagesProcessed", messagesProcessed).put("errorsOccurred", errorsOccurred); |
|||
return eventInfo; |
|||
} |
|||
} |
|||
@ -0,0 +1,64 @@ |
|||
/** |
|||
* 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.model.sql; |
|||
|
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.NoArgsConstructor; |
|||
import org.thingsboard.server.common.data.event.ErrorEvent; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.dao.model.BaseEntity; |
|||
|
|||
import javax.persistence.Column; |
|||
import javax.persistence.Entity; |
|||
import javax.persistence.Table; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.ERROR_EVENT_TABLE_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.EVENT_ERROR_COLUMN_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.EVENT_METHOD_COLUMN_NAME; |
|||
|
|||
@Data |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Entity |
|||
@Table(name = ERROR_EVENT_TABLE_NAME) |
|||
@NoArgsConstructor |
|||
public class ErrorEventEntity extends EventEntity<ErrorEvent> implements BaseEntity<ErrorEvent> { |
|||
|
|||
@Column(name = EVENT_METHOD_COLUMN_NAME) |
|||
private String method; |
|||
@Column(name = EVENT_ERROR_COLUMN_NAME) |
|||
private String error; |
|||
|
|||
public ErrorEventEntity(ErrorEvent event) { |
|||
super(event); |
|||
this.method = event.getMethod(); |
|||
this.error = event.getError(); |
|||
} |
|||
|
|||
@Override |
|||
public ErrorEvent toData() { |
|||
return ErrorEvent.builder() |
|||
.tenantId(TenantId.fromUUID(tenantId)) |
|||
.entityId(entityId) |
|||
.serviceId(serviceId) |
|||
.id(id) |
|||
.ts(ts) |
|||
.method(method) |
|||
.error(error) |
|||
.build(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,69 @@ |
|||
/** |
|||
* 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.model.sql; |
|||
|
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.NoArgsConstructor; |
|||
import org.thingsboard.server.common.data.event.LifecycleEvent; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.dao.model.BaseEntity; |
|||
|
|||
import javax.persistence.Column; |
|||
import javax.persistence.Entity; |
|||
import javax.persistence.Table; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.EVENT_ERROR_COLUMN_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.EVENT_SUCCESS_COLUMN_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.EVENT_TYPE_COLUMN_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.LC_EVENT_TABLE_NAME; |
|||
|
|||
@Data |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Entity |
|||
@Table(name = LC_EVENT_TABLE_NAME) |
|||
@NoArgsConstructor |
|||
public class LifecycleEventEntity extends EventEntity<LifecycleEvent> implements BaseEntity<LifecycleEvent> { |
|||
|
|||
@Column(name = EVENT_TYPE_COLUMN_NAME) |
|||
private String eventType; |
|||
@Column(name = EVENT_SUCCESS_COLUMN_NAME) |
|||
private boolean success; |
|||
@Column(name = EVENT_ERROR_COLUMN_NAME) |
|||
private String error; |
|||
|
|||
public LifecycleEventEntity(LifecycleEvent event) { |
|||
super(event); |
|||
this.eventType = event.getLcEventType(); |
|||
this.success = event.isSuccess(); |
|||
this.error = event.getError(); |
|||
} |
|||
|
|||
@Override |
|||
public LifecycleEvent toData() { |
|||
return LifecycleEvent.builder() |
|||
.tenantId(TenantId.fromUUID(tenantId)) |
|||
.entityId(entityId) |
|||
.serviceId(serviceId) |
|||
.id(id) |
|||
.ts(ts) |
|||
.lcEventType(eventType) |
|||
.success(success) |
|||
.error(error) |
|||
.build(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,63 @@ |
|||
/** |
|||
* 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.model.sql; |
|||
|
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.NoArgsConstructor; |
|||
import org.thingsboard.server.common.data.event.RuleChainDebugEvent; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.dao.model.BaseEntity; |
|||
|
|||
import javax.persistence.Column; |
|||
import javax.persistence.Entity; |
|||
import javax.persistence.Table; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.EVENT_ERROR_COLUMN_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.EVENT_MESSAGE_COLUMN_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.RULE_CHAIN_DEBUG_EVENT_TABLE_NAME; |
|||
|
|||
@Data |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Entity |
|||
@Table(name = RULE_CHAIN_DEBUG_EVENT_TABLE_NAME) |
|||
@NoArgsConstructor |
|||
public class RuleChainDebugEventEntity extends EventEntity<RuleChainDebugEvent> implements BaseEntity<RuleChainDebugEvent> { |
|||
|
|||
@Column(name = EVENT_MESSAGE_COLUMN_NAME) |
|||
private String message; |
|||
@Column(name = EVENT_ERROR_COLUMN_NAME) |
|||
private String error; |
|||
|
|||
public RuleChainDebugEventEntity(RuleChainDebugEvent event) { |
|||
super(event); |
|||
this.message = event.getMessage(); |
|||
this.error = event.getError(); |
|||
} |
|||
|
|||
@Override |
|||
public RuleChainDebugEvent toData() { |
|||
return RuleChainDebugEvent.builder() |
|||
.tenantId(TenantId.fromUUID(tenantId)) |
|||
.entityId(entityId) |
|||
.serviceId(serviceId) |
|||
.id(id) |
|||
.ts(ts) |
|||
.message(message) |
|||
.error(error).build(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,109 @@ |
|||
/** |
|||
* 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.model.sql; |
|||
|
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.NoArgsConstructor; |
|||
import org.thingsboard.server.common.data.event.RuleNodeDebugEvent; |
|||
import org.thingsboard.server.common.data.id.EntityIdFactory; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.dao.model.BaseEntity; |
|||
|
|||
import javax.persistence.Column; |
|||
import javax.persistence.Entity; |
|||
import javax.persistence.Table; |
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.EVENT_DATA_COLUMN_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.EVENT_DATA_TYPE_COLUMN_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.EVENT_ENTITY_ID_COLUMN_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.EVENT_ENTITY_TYPE_COLUMN_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.EVENT_ERROR_COLUMN_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.EVENT_METADATA_COLUMN_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.EVENT_MSG_ID_COLUMN_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.EVENT_MSG_TYPE_COLUMN_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.EVENT_RELATION_TYPE_COLUMN_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.EVENT_TYPE_COLUMN_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.RULE_NODE_DEBUG_EVENT_TABLE_NAME; |
|||
|
|||
@Data |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Entity |
|||
@Table(name = RULE_NODE_DEBUG_EVENT_TABLE_NAME) |
|||
@NoArgsConstructor |
|||
public class RuleNodeDebugEventEntity extends EventEntity<RuleNodeDebugEvent> implements BaseEntity<RuleNodeDebugEvent> { |
|||
|
|||
@Column(name = EVENT_TYPE_COLUMN_NAME) |
|||
private String eventType; |
|||
@Column(name = EVENT_ENTITY_ID_COLUMN_NAME) |
|||
private UUID eventEntityId; |
|||
@Column(name = EVENT_ENTITY_TYPE_COLUMN_NAME) |
|||
private String eventEntityType; |
|||
@Column(name = EVENT_MSG_ID_COLUMN_NAME) |
|||
private UUID msgId; |
|||
@Column(name = EVENT_MSG_TYPE_COLUMN_NAME) |
|||
private String msgType; |
|||
@Column(name = EVENT_DATA_TYPE_COLUMN_NAME) |
|||
private String dataType; |
|||
@Column(name = EVENT_RELATION_TYPE_COLUMN_NAME) |
|||
private String relationType; |
|||
@Column(name = EVENT_DATA_COLUMN_NAME) |
|||
private String data; |
|||
@Column(name = EVENT_METADATA_COLUMN_NAME) |
|||
private String metadata; |
|||
@Column(name = EVENT_ERROR_COLUMN_NAME) |
|||
private String error; |
|||
|
|||
public RuleNodeDebugEventEntity(RuleNodeDebugEvent event) { |
|||
super(event); |
|||
this.eventType = event.getEventType(); |
|||
if (event.getEventEntity() != null) { |
|||
this.eventEntityId = event.getEventEntity().getId(); |
|||
this.eventEntityType = event.getEventEntity().getEntityType().name(); |
|||
} |
|||
this.msgId = event.getMsgId(); |
|||
this.msgType = event.getMsgType(); |
|||
this.dataType = event.getDataType(); |
|||
this.relationType = event.getRelationType(); |
|||
this.data = event.getData(); |
|||
this.metadata = event.getMetadata(); |
|||
this.error = event.getError(); |
|||
} |
|||
|
|||
@Override |
|||
public RuleNodeDebugEvent toData() { |
|||
var builder = RuleNodeDebugEvent.builder() |
|||
.tenantId(TenantId.fromUUID(tenantId)) |
|||
.entityId(entityId) |
|||
.serviceId(serviceId) |
|||
.id(id) |
|||
.ts(ts) |
|||
.eventType(eventType) |
|||
.msgId(msgId) |
|||
.msgType(msgType) |
|||
.dataType(dataType) |
|||
.relationType(relationType) |
|||
.data(data) |
|||
.metadata(metadata) |
|||
.error(error); |
|||
if (eventEntityId != null) { |
|||
builder.eventEntity(EntityIdFactory.getByTypeAndUuid(eventEntityType, eventEntityId)); |
|||
} |
|||
return builder.build(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,64 @@ |
|||
/** |
|||
* 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.model.sql; |
|||
|
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.NoArgsConstructor; |
|||
import org.thingsboard.server.common.data.event.StatisticsEvent; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.dao.model.BaseEntity; |
|||
|
|||
import javax.persistence.Column; |
|||
import javax.persistence.Entity; |
|||
import javax.persistence.Table; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.EVENT_ERRORS_OCCURRED_COLUMN_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.EVENT_MESSAGES_PROCESSED_COLUMN_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.STATS_EVENT_TABLE_NAME; |
|||
|
|||
@Data |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Entity |
|||
@Table(name = STATS_EVENT_TABLE_NAME) |
|||
@NoArgsConstructor |
|||
public class StatisticsEventEntity extends EventEntity<StatisticsEvent> implements BaseEntity<StatisticsEvent> { |
|||
|
|||
@Column(name = EVENT_MESSAGES_PROCESSED_COLUMN_NAME) |
|||
private long messagesProcessed; |
|||
@Column(name = EVENT_ERRORS_OCCURRED_COLUMN_NAME) |
|||
private long errorsOccurred; |
|||
|
|||
public StatisticsEventEntity(StatisticsEvent event) { |
|||
super(event); |
|||
this.messagesProcessed = event.getMessagesProcessed(); |
|||
this.errorsOccurred = event.getErrorsOccurred(); |
|||
} |
|||
|
|||
@Override |
|||
public StatisticsEvent toData() { |
|||
return StatisticsEvent.builder() |
|||
.tenantId(TenantId.fromUUID(tenantId)) |
|||
.entityId(entityId) |
|||
.serviceId(serviceId) |
|||
.id(id) |
|||
.ts(ts) |
|||
.messagesProcessed(messagesProcessed) |
|||
.errorsOccurred(errorsOccurred) |
|||
.build(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,114 @@ |
|||
/** |
|||
* 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.sql.event; |
|||
|
|||
import org.springframework.data.domain.Page; |
|||
import org.springframework.data.domain.Pageable; |
|||
import org.springframework.data.jpa.repository.JpaRepository; |
|||
import org.springframework.data.jpa.repository.Modifying; |
|||
import org.springframework.data.jpa.repository.Query; |
|||
import org.springframework.data.repository.query.Param; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
import org.thingsboard.server.common.data.event.ErrorEvent; |
|||
import org.thingsboard.server.common.data.event.LifecycleEvent; |
|||
import org.thingsboard.server.dao.model.sql.ErrorEventEntity; |
|||
import org.thingsboard.server.dao.model.sql.LifecycleEventEntity; |
|||
import org.thingsboard.server.dao.model.sql.StatisticsEventEntity; |
|||
|
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
|
|||
public interface ErrorEventRepository extends EventRepository<ErrorEventEntity, ErrorEvent>, JpaRepository<ErrorEventEntity, UUID> { |
|||
|
|||
@Override |
|||
@Query(nativeQuery = true, value = "SELECT * FROM error_event e WHERE e.tenant_id = :tenantId AND e.entity_id = :entityId ORDER BY e.ts DESC LIMIT :limit") |
|||
List<ErrorEventEntity> findLatestEvents(@Param("tenantId") UUID tenantId, @Param("entityId") UUID entityId, @Param("limit") int limit); |
|||
|
|||
@Override |
|||
@Query("SELECT e FROM ErrorEventEntity e WHERE " + |
|||
"e.tenantId = :tenantId " + |
|||
"AND e.entityId = :entityId " + |
|||
"AND (:startTime IS NULL OR e.ts >= :startTime) " + |
|||
"AND (:endTime IS NULL OR e.ts <= :endTime)" |
|||
) |
|||
Page<ErrorEventEntity> findEvents(@Param("tenantId") UUID tenantId, |
|||
@Param("entityId") UUID entityId, |
|||
@Param("startTime") Long startTime, |
|||
@Param("endTime") Long endTime, |
|||
Pageable pageable); |
|||
|
|||
@Query(nativeQuery = true, |
|||
value = "SELECT * FROM error_event e WHERE " + |
|||
"e.tenant_id = :tenantId " + |
|||
"AND e.entity_id = :entityId " + |
|||
"AND (:startTime IS NULL OR e.ts >= :startTime) " + |
|||
"AND (:endTime IS NULL OR e.ts <= :endTime) " + |
|||
"AND (:serviceId IS NULL OR e.service_id ILIKE concat('%', :serviceId, '%')) " + |
|||
"AND (:method IS NULL OR e.e_method ILIKE concat('%', :method, '%')) " + |
|||
"AND (:error IS NULL OR e.e_error ILIKE concat('%', :error, '%'))" |
|||
, |
|||
countQuery = "SELECT count(*) FROM error_event e WHERE " + |
|||
"e.tenant_id = :tenantId " + |
|||
"AND e.entity_id = :entityId " + |
|||
"AND (:startTime IS NULL OR e.ts >= :startTime) " + |
|||
"AND (:endTime IS NULL OR e.ts <= :endTime) " + |
|||
"AND (:serviceId IS NULL OR e.service_id ILIKE concat('%', :serviceId, '%')) " + |
|||
"AND (:method IS NULL OR e.e_method ILIKE concat('%', :method, '%')) " + |
|||
"AND (:error IS NULL OR e.e_error ILIKE concat('%', :error, '%'))" |
|||
) |
|||
Page<ErrorEventEntity> findEvents(@Param("tenantId") UUID tenantId, |
|||
@Param("entityId") UUID entityId, |
|||
@Param("startTime") Long startTime, |
|||
@Param("endTime") Long endTime, |
|||
@Param("serviceId") String server, |
|||
@Param("method") String method, |
|||
@Param("error") String error, |
|||
Pageable pageable); |
|||
|
|||
@Transactional |
|||
@Modifying |
|||
@Query("DELETE FROM ErrorEventEntity e WHERE " + |
|||
"e.tenantId = :tenantId " + |
|||
"AND e.entityId = :entityId " + |
|||
"AND (:startTime IS NULL OR e.ts >= :startTime) " + |
|||
"AND (:endTime IS NULL OR e.ts <= :endTime)" |
|||
) |
|||
void removeEvents(@Param("tenantId") UUID tenantId, |
|||
@Param("entityId") UUID entityId, |
|||
@Param("startTime") Long startTime, |
|||
@Param("endTime") Long endTime); |
|||
|
|||
@Transactional |
|||
@Modifying |
|||
@Query(nativeQuery = true, |
|||
value = "DELETE FROM error_event e WHERE " + |
|||
"e.tenant_id = :tenantId " + |
|||
"AND e.entity_id = :entityId " + |
|||
"AND (:startTime IS NULL OR e.ts >= :startTime) " + |
|||
"AND (:endTime IS NULL OR e.ts <= :endTime) " + |
|||
"AND (:serviceId IS NULL OR e.service_id ILIKE concat('%', :serviceId, '%')) " + |
|||
"AND (:method IS NULL OR e.e_method ILIKE concat('%', :method, '%')) " + |
|||
"AND (:error IS NULL OR e.e_error ILIKE concat('%', :error, '%'))" |
|||
) |
|||
void removeEvents(@Param("tenantId") UUID tenantId, |
|||
@Param("entityId") UUID entityId, |
|||
@Param("startTime") Long startTime, |
|||
@Param("endTime") Long endTime, |
|||
@Param("serviceId") String server, |
|||
@Param("method") String method, |
|||
@Param("error") String error); |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
/** |
|||
* 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.sql.event; |
|||
|
|||
import lombok.Getter; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.event.EventType; |
|||
|
|||
import javax.annotation.PostConstruct; |
|||
import java.util.concurrent.TimeUnit; |
|||
|
|||
@Component |
|||
public class EventPartitionConfiguration { |
|||
|
|||
@Getter |
|||
@Value("${sql.events.partition_size:168}") |
|||
private int regularPartitionSizeInHours; |
|||
@Getter |
|||
@Value("${sql.events.debug_partition_size:1}") |
|||
private int debugPartitionSizeInHours; |
|||
|
|||
private long regularPartitionSizeInMs; |
|||
private long debugPartitionSizeInMs; |
|||
|
|||
@PostConstruct |
|||
public void init() { |
|||
regularPartitionSizeInMs = TimeUnit.HOURS.toMillis(regularPartitionSizeInHours); |
|||
debugPartitionSizeInMs = TimeUnit.HOURS.toMillis(debugPartitionSizeInHours); |
|||
} |
|||
|
|||
public long getPartitionSizeInMs(EventType eventType) { |
|||
return eventType.isDebug() ? debugPartitionSizeInMs : regularPartitionSizeInMs; |
|||
} |
|||
} |
|||
@ -0,0 +1,118 @@ |
|||
/** |
|||
* 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.sql.event; |
|||
|
|||
import org.springframework.data.domain.Page; |
|||
import org.springframework.data.domain.Pageable; |
|||
import org.springframework.data.jpa.repository.JpaRepository; |
|||
import org.springframework.data.jpa.repository.Modifying; |
|||
import org.springframework.data.jpa.repository.Query; |
|||
import org.springframework.data.repository.query.Param; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
import org.thingsboard.server.common.data.event.LifecycleEvent; |
|||
import org.thingsboard.server.dao.model.sql.LifecycleEventEntity; |
|||
import org.thingsboard.server.dao.model.sql.RuleChainDebugEventEntity; |
|||
|
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
public interface LifecycleEventRepository extends EventRepository<LifecycleEventEntity, LifecycleEvent>, JpaRepository<LifecycleEventEntity, UUID> { |
|||
|
|||
@Override |
|||
@Query(nativeQuery = true, value = "SELECT * FROM lc_event e WHERE e.tenant_id = :tenantId AND e.entity_id = :entityId ORDER BY e.ts DESC LIMIT :limit") |
|||
List<LifecycleEventEntity> findLatestEvents(@Param("tenantId") UUID tenantId, @Param("entityId") UUID entityId, @Param("limit") int limit); |
|||
|
|||
|
|||
@Query("SELECT e FROM LifecycleEventEntity e WHERE " + |
|||
"e.tenantId = :tenantId " + |
|||
"AND e.entityId = :entityId " + |
|||
"AND (:startTime IS NULL OR e.ts >= :startTime) " + |
|||
"AND (:endTime IS NULL OR e.ts <= :endTime)" |
|||
) |
|||
Page<LifecycleEventEntity> findEvents(@Param("tenantId") UUID tenantId, |
|||
@Param("entityId") UUID entityId, |
|||
@Param("startTime") Long startTime, |
|||
@Param("endTime") Long endTime, |
|||
Pageable pageable); |
|||
|
|||
@Query(nativeQuery = true, |
|||
value = "SELECT * FROM lc_event e WHERE " + |
|||
"e.tenant_id = :tenantId " + |
|||
"AND e.entity_id = :entityId " + |
|||
"AND (:startTime IS NULL OR e.ts >= :startTime) " + |
|||
"AND (:endTime IS NULL OR e.ts <= :endTime) " + |
|||
"AND (:serviceId IS NULL OR e.service_id ILIKE concat('%', :serviceId, '%')) " + |
|||
"AND (:eventType IS NULL OR e.e_type ILIKE concat('%', :eventType, '%')) " + |
|||
"AND ((:statusFilterEnabled = FALSE) OR e.e_success = :statusFilter) " + |
|||
"AND (:error IS NULL OR e.e_error ILIKE concat('%', :error, '%'))" |
|||
, |
|||
countQuery = "SELECT count(*) FROM lc_event e WHERE " + |
|||
"e.tenant_id = :tenantId " + |
|||
"AND e.entity_id = :entityId " + |
|||
"AND (:startTime IS NULL OR e.ts >= :startTime) " + |
|||
"AND (:endTime IS NULL OR e.ts <= :endTime) " + |
|||
"AND (:serviceId IS NULL OR e.service_id ILIKE concat('%', :serviceId, '%')) " + |
|||
"AND (:eventType IS NULL OR e.e_type ILIKE concat('%', :eventType, '%')) " + |
|||
"AND ((:statusFilterEnabled = FALSE) OR e.e_success = :statusFilter) " + |
|||
"AND (:error IS NULL OR e.e_error ILIKE concat('%', :error, '%'))" |
|||
) |
|||
Page<LifecycleEventEntity> findEvents(@Param("tenantId") UUID tenantId, |
|||
@Param("entityId") UUID entityId, |
|||
@Param("startTime") Long startTime, |
|||
@Param("endTime") Long endTime, |
|||
@Param("serviceId") String server, |
|||
@Param("eventType") String eventType, |
|||
@Param("statusFilterEnabled") boolean statusFilterEnabled, |
|||
@Param("statusFilter") boolean statusFilter, |
|||
@Param("error") String error, |
|||
Pageable pageable); |
|||
|
|||
@Transactional |
|||
@Modifying |
|||
@Query("DELETE FROM LifecycleEventEntity e WHERE " + |
|||
"e.tenantId = :tenantId " + |
|||
"AND e.entityId = :entityId " + |
|||
"AND (:startTime IS NULL OR e.ts >= :startTime) " + |
|||
"AND (:endTime IS NULL OR e.ts <= :endTime)" |
|||
) |
|||
void removeEvents(@Param("tenantId") UUID tenantId, |
|||
@Param("entityId") UUID entityId, |
|||
@Param("startTime") Long startTime, |
|||
@Param("endTime") Long endTime); |
|||
|
|||
@Transactional |
|||
@Modifying |
|||
@Query(nativeQuery = true, |
|||
value = "DELETE FROM lc_event e WHERE " + |
|||
"e.tenant_id = :tenantId " + |
|||
"AND e.entity_id = :entityId " + |
|||
"AND (:startTime IS NULL OR e.ts >= :startTime) " + |
|||
"AND (:endTime IS NULL OR e.ts <= :endTime) " + |
|||
"AND (:serviceId IS NULL OR e.service_id ILIKE concat('%', :serviceId, '%')) " + |
|||
"AND (:eventType IS NULL OR e.e_type ILIKE concat('%', :eventType, '%')) " + |
|||
"AND ((:statusFilterEnabled = FALSE) OR e.e_success = :statusFilter) " + |
|||
"AND (:error IS NULL OR e.e_error ILIKE concat('%', :error, '%'))" |
|||
) |
|||
void removeEvents(@Param("tenantId") UUID tenantId, |
|||
@Param("entityId") UUID entityId, |
|||
@Param("startTime") Long startTime, |
|||
@Param("endTime") Long endTime, |
|||
@Param("serviceId") String server, |
|||
@Param("eventType") String eventType, |
|||
@Param("statusFilterEnabled") boolean statusFilterEnabled, |
|||
@Param("statusFilter") boolean statusFilter, |
|||
@Param("error") String error); |
|||
} |
|||
@ -0,0 +1,117 @@ |
|||
/** |
|||
* 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.sql.event; |
|||
|
|||
import org.springframework.data.domain.Page; |
|||
import org.springframework.data.domain.Pageable; |
|||
import org.springframework.data.jpa.repository.JpaRepository; |
|||
import org.springframework.data.jpa.repository.Modifying; |
|||
import org.springframework.data.jpa.repository.Query; |
|||
import org.springframework.data.repository.query.Param; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
import org.thingsboard.server.common.data.event.RuleChainDebugEvent; |
|||
import org.thingsboard.server.common.data.event.RuleNodeDebugEvent; |
|||
import org.thingsboard.server.dao.model.sql.RuleChainDebugEventEntity; |
|||
import org.thingsboard.server.dao.model.sql.RuleNodeDebugEventEntity; |
|||
|
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
|
|||
public interface RuleChainDebugEventRepository extends EventRepository<RuleChainDebugEventEntity, RuleChainDebugEvent>, JpaRepository<RuleChainDebugEventEntity, UUID> { |
|||
|
|||
@Override |
|||
@Query(nativeQuery = true, value = "SELECT * FROM rule_chain_debug_event e WHERE e.tenant_id = :tenantId AND e.entity_id = :entityId ORDER BY e.ts DESC LIMIT :limit") |
|||
List<RuleChainDebugEventEntity> findLatestEvents(@Param("tenantId") UUID tenantId, @Param("entityId") UUID entityId, @Param("limit") int limit); |
|||
|
|||
@Override |
|||
@Query("SELECT e FROM RuleChainDebugEventEntity e WHERE " + |
|||
"e.tenantId = :tenantId " + |
|||
"AND e.entityId = :entityId " + |
|||
"AND (:startTime IS NULL OR e.ts >= :startTime) " + |
|||
"AND (:endTime IS NULL OR e.ts <= :endTime)" |
|||
) |
|||
Page<RuleChainDebugEventEntity> findEvents(@Param("tenantId") UUID tenantId, |
|||
@Param("entityId") UUID entityId, |
|||
@Param("startTime") Long startTime, |
|||
@Param("endTime") Long endTime, |
|||
Pageable pageable); |
|||
|
|||
@Query(nativeQuery = true, |
|||
value = "SELECT * FROM rule_chain_debug_event e WHERE " + |
|||
"e.tenant_id = :tenantId " + |
|||
"AND e.entity_id = :entityId " + |
|||
"AND (:startTime IS NULL OR e.ts >= :startTime) " + |
|||
"AND (:endTime IS NULL OR e.ts <= :endTime) " + |
|||
"AND (:serviceId IS NULL OR e.service_id ILIKE concat('%', :serviceId, '%')) " + |
|||
"AND (:message IS NULL OR e.e_message ILIKE concat('%', :message, '%')) " + |
|||
"AND ((:isError = FALSE) OR e.e_error IS NOT NULL) " + |
|||
"AND (:error IS NULL OR e.e_error ILIKE concat('%', :error, '%'))" |
|||
, |
|||
countQuery = "SELECT count(*) FROM rule_chain_debug_event e WHERE " + |
|||
"e.tenant_id = :tenantId " + |
|||
"AND e.entity_id = :entityId " + |
|||
"AND (:startTime IS NULL OR e.ts >= :startTime) " + |
|||
"AND (:endTime IS NULL OR e.ts <= :endTime) " + |
|||
"AND (:serviceId IS NULL OR e.service_id ILIKE concat('%', :serviceId, '%')) " + |
|||
"AND (:message IS NULL OR e.e_message ILIKE concat('%', :message, '%')) " + |
|||
"AND ((:isError = FALSE) OR e.e_error IS NOT NULL) " + |
|||
"AND (:error IS NULL OR e.e_error ILIKE concat('%', :error, '%'))" |
|||
) |
|||
Page<RuleChainDebugEventEntity> findEvents(@Param("tenantId") UUID tenantId, |
|||
@Param("entityId") UUID entityId, |
|||
@Param("startTime") Long startTime, |
|||
@Param("endTime") Long endTime, |
|||
@Param("serviceId") String server, |
|||
@Param("message") String message, |
|||
@Param("isError") boolean isError, |
|||
@Param("error") String error, |
|||
Pageable pageable); |
|||
|
|||
@Transactional |
|||
@Modifying |
|||
@Query("DELETE FROM RuleChainDebugEventEntity e WHERE " + |
|||
"e.tenantId = :tenantId " + |
|||
"AND e.entityId = :entityId " + |
|||
"AND (:startTime IS NULL OR e.ts >= :startTime) " + |
|||
"AND (:endTime IS NULL OR e.ts <= :endTime)" |
|||
) |
|||
void removeEvents(@Param("tenantId") UUID tenantId, |
|||
@Param("entityId") UUID entityId, |
|||
@Param("startTime") Long startTime, |
|||
@Param("endTime") Long endTime); |
|||
|
|||
@Transactional |
|||
@Modifying |
|||
@Query(nativeQuery = true, |
|||
value = "DELETE FROM rule_chain_debug_event e WHERE " + |
|||
"e.tenant_id = :tenantId " + |
|||
"AND e.entity_id = :entityId " + |
|||
"AND (:startTime IS NULL OR e.ts >= :startTime) " + |
|||
"AND (:endTime IS NULL OR e.ts <= :endTime) " + |
|||
"AND (:serviceId IS NULL OR e.service_id ILIKE concat('%', :serviceId, '%')) " + |
|||
"AND (:message IS NULL OR e.e_message ILIKE concat('%', :message, '%')) " + |
|||
"AND ((:isError = FALSE) OR e.e_error IS NOT NULL) " + |
|||
"AND (:error IS NULL OR e.e_error ILIKE concat('%', :error, '%'))") |
|||
void removeEvents(@Param("tenantId") UUID tenantId, |
|||
@Param("entityId") UUID entityId, |
|||
@Param("startTime") Long startTime, |
|||
@Param("endTime") Long endTime, |
|||
@Param("serviceId") String server, |
|||
@Param("message") String message, |
|||
@Param("isError") boolean isError, |
|||
@Param("error") String error); |
|||
} |
|||
@ -0,0 +1,153 @@ |
|||
/** |
|||
* 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.sql.event; |
|||
|
|||
import org.springframework.data.domain.Page; |
|||
import org.springframework.data.domain.Pageable; |
|||
import org.springframework.data.jpa.repository.JpaRepository; |
|||
import org.springframework.data.jpa.repository.Modifying; |
|||
import org.springframework.data.jpa.repository.Query; |
|||
import org.springframework.data.repository.query.Param; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
import org.thingsboard.server.common.data.event.ErrorEvent; |
|||
import org.thingsboard.server.common.data.event.RuleNodeDebugEvent; |
|||
import org.thingsboard.server.dao.model.sql.ErrorEventEntity; |
|||
import org.thingsboard.server.dao.model.sql.RuleNodeDebugEventEntity; |
|||
import org.thingsboard.server.dao.model.sql.StatisticsEventEntity; |
|||
|
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
|
|||
public interface RuleNodeDebugEventRepository extends EventRepository<RuleNodeDebugEventEntity, RuleNodeDebugEvent>, JpaRepository<RuleNodeDebugEventEntity, UUID> { |
|||
|
|||
@Override |
|||
@Query(nativeQuery = true, value = "SELECT * FROM rule_node_debug_event e WHERE e.tenant_id = :tenantId AND e.entity_id = :entityId ORDER BY e.ts DESC LIMIT :limit") |
|||
List<RuleNodeDebugEventEntity> findLatestEvents(@Param("tenantId") UUID tenantId, @Param("entityId") UUID entityId, @Param("limit") int limit); |
|||
|
|||
@Override |
|||
@Query("SELECT e FROM RuleNodeDebugEventEntity e WHERE " + |
|||
"e.tenantId = :tenantId " + |
|||
"AND e.entityId = :entityId " + |
|||
"AND (:startTime IS NULL OR e.ts >= :startTime) " + |
|||
"AND (:endTime IS NULL OR e.ts <= :endTime)" |
|||
) |
|||
Page<RuleNodeDebugEventEntity> findEvents(@Param("tenantId") UUID tenantId, |
|||
@Param("entityId") UUID entityId, |
|||
@Param("startTime") Long startTime, |
|||
@Param("endTime") Long endTime, |
|||
Pageable pageable); |
|||
|
|||
@Query(nativeQuery = true, |
|||
value = "SELECT * FROM rule_node_debug_event e WHERE " + |
|||
"e.tenant_id = :tenantId " + |
|||
"AND e.entity_id = :entityId " + |
|||
"AND (:startTime IS NULL OR e.ts >= :startTime) " + |
|||
"AND (:endTime IS NULL OR e.ts <= :endTime) " + |
|||
"AND (:serviceId IS NULL OR e.service_id ILIKE concat('%', :serviceId, '%')) " + |
|||
"AND (:eventType IS NULL OR e.e_type ILIKE concat('%', :eventType, '%')) " + |
|||
"AND (:eventEntityId IS NULL OR e.e_entity_id = uuid(:eventEntityId)) " + |
|||
"AND (:eventEntityType IS NULL OR e.e_entity_type ILIKE concat('%', :eventEntityType, '%')) " + |
|||
"AND (:msgId IS NULL OR e.e_msg_id = uuid(:msgId)) " + |
|||
"AND (:msgType IS NULL OR e.e_msg_type ILIKE concat('%', :msgType, '%')) " + |
|||
"AND (:relationType IS NULL OR e.e_relation_type ILIKE concat('%', :relationType, '%')) " + |
|||
"AND (:data IS NULL OR e.e_data ILIKE concat('%', :data, '%')) " + |
|||
"AND (:metadata IS NULL OR e.e_metadata ILIKE concat('%', :metadata, '%')) " + |
|||
"AND ((:isError = FALSE) OR e.e_error IS NOT NULL) " + |
|||
"AND (:error IS NULL OR e.e_error ILIKE concat('%', :error, '%'))" |
|||
, |
|||
countQuery = "SELECT count(*) FROM rule_node_debug_event e WHERE " + |
|||
"e.tenant_id = :tenantId " + |
|||
"AND e.entity_id = :entityId " + |
|||
"AND (:startTime IS NULL OR e.ts >= :startTime) " + |
|||
"AND (:endTime IS NULL OR e.ts <= :endTime) " + |
|||
"AND (:serviceId IS NULL OR e.service_id ILIKE concat('%', :serviceId, '%')) " + |
|||
"AND (:eventType IS NULL OR e.e_type ILIKE concat('%', :eventType, '%')) " + |
|||
"AND (:eventEntityId IS NULL OR e.e_entity_id = uuid(:eventEntityId)) " + |
|||
"AND (:eventEntityType IS NULL OR e.e_entity_type ILIKE concat('%', :eventEntityType, '%')) " + |
|||
"AND (:msgId IS NULL OR e.e_msg_id = uuid(:msgId)) " + |
|||
"AND (:msgType IS NULL OR e.e_msg_type ILIKE concat('%', :msgType, '%')) " + |
|||
"AND (:relationType IS NULL OR e.e_relation_type ILIKE concat('%', :relationType, '%')) " + |
|||
"AND (:data IS NULL OR e.e_data ILIKE concat('%', :data, '%')) " + |
|||
"AND (:metadata IS NULL OR e.e_metadata ILIKE concat('%', :metadata, '%')) " + |
|||
"AND ((:isError = FALSE) OR e.e_error IS NOT NULL) " + |
|||
"AND (:error IS NULL OR e.e_error ILIKE concat('%', :error, '%'))" |
|||
) |
|||
Page<RuleNodeDebugEventEntity> findEvents(@Param("tenantId") UUID tenantId, |
|||
@Param("entityId") UUID entityId, |
|||
@Param("startTime") Long startTime, |
|||
@Param("endTime") Long endTime, |
|||
@Param("serviceId") String server, |
|||
@Param("eventType") String type, |
|||
@Param("eventEntityId") String eventEntityId, |
|||
@Param("eventEntityType") String eventEntityType, |
|||
@Param("msgId") String eventMsgId, |
|||
@Param("msgType") String eventMsgType, |
|||
@Param("relationType") String relationType, |
|||
@Param("data") String data, |
|||
@Param("metadata") String metadata, |
|||
@Param("isError") boolean isError, |
|||
@Param("error") String error, |
|||
Pageable pageable); |
|||
|
|||
@Transactional |
|||
@Modifying |
|||
@Query("DELETE FROM RuleNodeDebugEventEntity e WHERE " + |
|||
"e.tenantId = :tenantId " + |
|||
"AND e.entityId = :entityId " + |
|||
"AND (:startTime IS NULL OR e.ts >= :startTime) " + |
|||
"AND (:endTime IS NULL OR e.ts <= :endTime)" |
|||
) |
|||
void removeEvents(@Param("tenantId") UUID tenantId, |
|||
@Param("entityId") UUID entityId, |
|||
@Param("startTime") Long startTime, |
|||
@Param("endTime") Long endTime); |
|||
|
|||
@Transactional |
|||
@Modifying |
|||
@Query(nativeQuery = true, |
|||
value = "DELETE FROM rule_node_debug_event e WHERE " + |
|||
"e.tenant_id = :tenantId " + |
|||
"AND e.entity_id = :entityId " + |
|||
"AND (:startTime IS NULL OR e.ts >= :startTime) " + |
|||
"AND (:endTime IS NULL OR e.ts <= :endTime) " + |
|||
"AND (:serviceId IS NULL OR e.service_id ILIKE concat('%', :serviceId, '%')) " + |
|||
"AND (:eventType IS NULL OR e.e_type ILIKE concat('%', :eventType, '%')) " + |
|||
"AND (:eventEntityId IS NULL OR e.e_entity_id = uuid(:eventEntityId)) " + |
|||
"AND (:eventEntityType IS NULL OR e.e_entity_type ILIKE concat('%', :eventEntityType, '%')) " + |
|||
"AND (:msgId IS NULL OR e.e_msg_id = uuid(:msgId)) " + |
|||
"AND (:msgType IS NULL OR e.e_msg_type ILIKE concat('%', :msgType, '%')) " + |
|||
"AND (:relationType IS NULL OR e.e_relation_type ILIKE concat('%', :relationType, '%')) " + |
|||
"AND (:data IS NULL OR e.e_data ILIKE concat('%', :data, '%')) " + |
|||
"AND (:metadata IS NULL OR e.e_metadata ILIKE concat('%', :metadata, '%')) " + |
|||
"AND ((:isError = FALSE) OR e.e_error IS NOT NULL) " + |
|||
"AND (:error IS NULL OR e.e_error ILIKE concat('%', :error, '%'))") |
|||
void removeEvents(@Param("tenantId") UUID tenantId, |
|||
@Param("entityId") UUID entityId, |
|||
@Param("startTime") Long startTime, |
|||
@Param("endTime") Long endTime, |
|||
@Param("serviceId") String server, |
|||
@Param("eventType") String type, |
|||
@Param("eventEntityId") String eventEntityId, |
|||
@Param("eventEntityType") String eventEntityType, |
|||
@Param("msgId") String eventMsgId, |
|||
@Param("msgType") String eventMsgType, |
|||
@Param("relationType") String relationType, |
|||
@Param("data") String data, |
|||
@Param("metadata") String metadata, |
|||
@Param("isError") boolean isError, |
|||
@Param("error") String error); |
|||
} |
|||
@ -0,0 +1,120 @@ |
|||
/** |
|||
* 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.sql.event; |
|||
|
|||
import org.springframework.data.domain.Page; |
|||
import org.springframework.data.domain.Pageable; |
|||
import org.springframework.data.jpa.repository.JpaRepository; |
|||
import org.springframework.data.jpa.repository.Modifying; |
|||
import org.springframework.data.jpa.repository.Query; |
|||
import org.springframework.data.repository.query.Param; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
import org.thingsboard.server.common.data.event.StatisticsEvent; |
|||
import org.thingsboard.server.dao.model.sql.StatisticsEventEntity; |
|||
|
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
public interface StatisticsEventRepository extends EventRepository<StatisticsEventEntity, StatisticsEvent>, JpaRepository<StatisticsEventEntity, UUID> { |
|||
|
|||
@Override |
|||
@Query(nativeQuery = true, value = "SELECT * FROM stats_event e WHERE e.tenant_id = :tenantId AND e.entity_id = :entityId ORDER BY e.ts DESC LIMIT :limit") |
|||
List<StatisticsEventEntity> findLatestEvents(@Param("tenantId") UUID tenantId, @Param("entityId") UUID entityId, @Param("limit") int limit); |
|||
|
|||
@Query("SELECT e FROM StatisticsEventEntity e WHERE " + |
|||
"e.tenantId = :tenantId " + |
|||
"AND e.entityId = :entityId " + |
|||
"AND (:startTime IS NULL OR e.ts >= :startTime) " + |
|||
"AND (:endTime IS NULL OR e.ts <= :endTime)" |
|||
) |
|||
Page<StatisticsEventEntity> findEvents(@Param("tenantId") UUID tenantId, |
|||
@Param("entityId") UUID entityId, |
|||
@Param("startTime") Long startTime, |
|||
@Param("endTime") Long endTime, |
|||
Pageable pageable); |
|||
|
|||
@Query(nativeQuery = true, |
|||
value = "SELECT * FROM stats_event e WHERE " + |
|||
"e.tenant_id = :tenantId " + |
|||
"AND e.entity_id = :entityId " + |
|||
"AND (:startTime IS NULL OR e.ts >= :startTime) " + |
|||
"AND (:endTime IS NULL OR e.ts <= :endTime) " + |
|||
"AND (:serviceId IS NULL OR e.service_id ILIKE concat('%', :serviceId, '%')) " + |
|||
"AND (:minMessagesProcessed IS NULL OR e.e_messages_processed >= :minMessagesProcessed) " + |
|||
"AND (:maxMessagesProcessed IS NULL OR e.e_messages_processed < :maxMessagesProcessed) " + |
|||
"AND (:minErrorsOccurred IS NULL OR e.e_errors_occurred >= :minErrorsOccurred) " + |
|||
"AND (:maxErrorsOccurred IS NULL OR e.e_errors_occurred < :maxErrorsOccurred)" |
|||
, |
|||
countQuery = "SELECT count(*) FROM stats_event e WHERE " + |
|||
"e.tenant_id = :tenantId " + |
|||
"AND e.entity_id = :entityId " + |
|||
"AND (:startTime IS NULL OR e.ts >= :startTime) " + |
|||
"AND (:endTime IS NULL OR e.ts <= :endTime) " + |
|||
"AND (:serviceId IS NULL OR e.service_id ILIKE concat('%', :serviceId, '%')) " + |
|||
"AND (:minMessagesProcessed IS NULL OR e.e_messages_processed >= :minMessagesProcessed) " + |
|||
"AND (:maxMessagesProcessed IS NULL OR e.e_messages_processed < :maxMessagesProcessed) " + |
|||
"AND (:minErrorsOccurred IS NULL OR e.e_errors_occurred >= :minErrorsOccurred) " + |
|||
"AND (:maxErrorsOccurred IS NULL OR e.e_errors_occurred < :maxErrorsOccurred)" |
|||
) |
|||
Page<StatisticsEventEntity> findEvents(@Param("tenantId") UUID tenantId, |
|||
@Param("entityId") UUID entityId, |
|||
@Param("startTime") Long startTime, |
|||
@Param("endTime") Long endTime, |
|||
@Param("serviceId") String server, |
|||
@Param("minMessagesProcessed") Integer minMessagesProcessed, |
|||
@Param("maxMessagesProcessed") Integer maxMessagesProcessed, |
|||
@Param("minErrorsOccurred") Integer minErrorsOccurred, |
|||
@Param("maxErrorsOccurred") Integer maxErrorsOccurred, |
|||
Pageable pageable); |
|||
|
|||
@Transactional |
|||
@Modifying |
|||
@Query("DELETE FROM StatisticsEventEntity e WHERE " + |
|||
"e.tenantId = :tenantId " + |
|||
"AND e.entityId = :entityId " + |
|||
"AND (:startTime IS NULL OR e.ts >= :startTime) " + |
|||
"AND (:endTime IS NULL OR e.ts <= :endTime)" |
|||
) |
|||
void removeEvents(@Param("tenantId") UUID tenantId, |
|||
@Param("entityId") UUID entityId, |
|||
@Param("startTime") Long startTime, |
|||
@Param("endTime") Long endTime); |
|||
|
|||
@Transactional |
|||
@Modifying |
|||
@Query(nativeQuery = true, |
|||
value = "DELETE FROM stats_event e WHERE " + |
|||
"e.tenant_id = :tenantId " + |
|||
"AND e.entity_id = :entityId " + |
|||
"AND (:startTime IS NULL OR e.ts >= :startTime) " + |
|||
"AND (:endTime IS NULL OR e.ts <= :endTime) " + |
|||
"AND (:serviceId IS NULL OR e.service_id ILIKE concat('%', :serviceId, '%')) " + |
|||
"AND (:minMessagesProcessed IS NULL OR e.e_messages_processed >= :minMessagesProcessed) " + |
|||
"AND (:maxMessagesProcessed IS NULL OR e.e_messages_processed < :maxMessagesProcessed) " + |
|||
"AND (:minErrorsOccurred IS NULL OR e.e_errors_occurred >= :minErrorsOccurred) " + |
|||
"AND (:maxErrorsOccurred IS NULL OR e.e_errors_occurred < :maxErrorsOccurred)" |
|||
|
|||
) |
|||
void removeEvents(@Param("tenantId") UUID tenantId, |
|||
@Param("entityId") UUID entityId, |
|||
@Param("startTime") Long startTime, |
|||
@Param("endTime") Long endTime, |
|||
@Param("serviceId") String server, |
|||
@Param("minMessagesProcessed") Integer minMessagesProcessed, |
|||
@Param("maxMessagesProcessed") Integer maxMessagesProcessed, |
|||
@Param("minErrorsOccurred") Integer minErrorsOccurred, |
|||
@Param("maxErrorsOccurred") Integer maxErrorsOccurred); |
|||
} |
|||
Loading…
Reference in new issue