36 changed files with 667 additions and 287 deletions
@ -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,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,82 @@ |
|||
/** |
|||
* 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.Query; |
|||
import org.springframework.data.repository.query.Param; |
|||
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("SELECT e FROM RuleChainDebugEventEntity e WHERE e.tenantId = :tenantId AND e.entityId = :entityId ORDER BY e.ts DESC") |
|||
List<RuleChainDebugEventEntity> findLatestEvents(UUID tenantId, UUID entityId, 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); |
|||
|
|||
} |
|||
@ -0,0 +1,103 @@ |
|||
/** |
|||
* 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.Query; |
|||
import org.springframework.data.repository.query.Param; |
|||
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 java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
|
|||
public interface RuleNodeDebugEventRepository extends EventRepository<RuleNodeDebugEventEntity, RuleNodeDebugEvent>, JpaRepository<RuleNodeDebugEventEntity, UUID> { |
|||
|
|||
@Override |
|||
@Query("SELECT e FROM RuleNodeDebugEventEntity e WHERE e.tenantId = :tenantId AND e.entityId = :entityId ORDER BY e.ts DESC") |
|||
List<RuleNodeDebugEventEntity> findLatestEvents(UUID tenantId, UUID entityId, 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); |
|||
|
|||
} |
|||
Loading…
Reference in new issue