commit
097429b816
@ -18,7 +18,6 @@ package org.thingsboard.server.edge;
|
||||
import com.google.protobuf.AbstractMessage;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.server.common.data.StringUtils;
|
||||
import org.thingsboard.server.common.data.notification.NotificationDeliveryMethod;
|
||||
|
||||
@ -59,12 +59,7 @@ public class OAuth2EdgeTest extends AbstractEdgeTest {
|
||||
oAuth2Info.setEnabled(false);
|
||||
oAuth2Info.setEdgeEnabled(false);
|
||||
doPost("/api/oauth2/config", oAuth2Info, OAuth2Info.class);
|
||||
Assert.assertTrue(edgeImitator.waitForMessages());
|
||||
latestMessage = edgeImitator.getLatestMessage();
|
||||
Assert.assertTrue(latestMessage instanceof OAuth2UpdateMsg);
|
||||
oAuth2UpdateMsg = (OAuth2UpdateMsg) latestMessage;
|
||||
result = JacksonUtil.fromString(oAuth2UpdateMsg.getEntity(), OAuth2Info.class, true);
|
||||
Assert.assertEquals(oAuth2Info, result);
|
||||
Assert.assertFalse(edgeImitator.waitForMessages(5));
|
||||
|
||||
edgeImitator.ignoreType(OAuth2UpdateMsg.class);
|
||||
loginTenantAdmin();
|
||||
|
||||
@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import org.thingsboard.server.common.data.id.AlarmId;
|
||||
import org.thingsboard.server.common.data.id.CustomerId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
@ -53,9 +54,12 @@ public class AlarmCreateOrUpdateActiveRequest implements AlarmModificationReques
|
||||
private long startTs;
|
||||
@Schema(description = "Timestamp of the alarm end time(last time update), in milliseconds", example = "1634111163522")
|
||||
private long endTs;
|
||||
|
||||
@ToString.Exclude
|
||||
@NoXss
|
||||
@Schema(description = "JSON object with alarm details")
|
||||
private JsonNode details;
|
||||
|
||||
@Valid
|
||||
@Schema(description = "JSON object with propagation details")
|
||||
private AlarmPropagationInfo propagation;
|
||||
|
||||
@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import org.thingsboard.server.common.data.id.AlarmId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.id.UserId;
|
||||
@ -47,9 +48,12 @@ public class AlarmUpdateRequest implements AlarmModificationRequest {
|
||||
private long startTs;
|
||||
@Schema(description = "Timestamp of the alarm end time(last time update), in milliseconds", example = "1634111163522")
|
||||
private long endTs;
|
||||
|
||||
@ToString.Exclude
|
||||
@NoXss
|
||||
@Schema(description = "JSON object with alarm details")
|
||||
private JsonNode details;
|
||||
|
||||
@Valid
|
||||
@Schema(description = "JSON object with propagation details")
|
||||
private AlarmPropagationInfo propagation;
|
||||
|
||||
@ -342,9 +342,12 @@ public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements A
|
||||
|
||||
@Override
|
||||
public AlarmApiCallResult createOrUpdateActiveAlarm(AlarmCreateOrUpdateActiveRequest request, boolean alarmCreationEnabled) {
|
||||
UUID tenantUUID = request.getTenantId().getId();
|
||||
log.debug("[{}] createOrUpdateActiveAlarm [{}] {}", tenantUUID, alarmCreationEnabled, request);
|
||||
|
||||
AlarmPropagationInfo ap = getSafePropagationInfo(request.getPropagation());
|
||||
return toAlarmApiResult(alarmRepository.createOrUpdateActiveAlarm(
|
||||
request.getTenantId().getId(),
|
||||
tenantUUID,
|
||||
request.getCustomerId() != null ? request.getCustomerId().getId() : CustomerId.NULL_UUID,
|
||||
request.getEdgeAlarmId() != null ? request.getEdgeAlarmId().getId() : UUID.randomUUID(),
|
||||
System.currentTimeMillis(),
|
||||
@ -364,10 +367,14 @@ public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements A
|
||||
|
||||
@Override
|
||||
public AlarmApiCallResult updateAlarm(AlarmUpdateRequest request) {
|
||||
UUID tenantUUID = request.getTenantId().getId();
|
||||
UUID alarmUUID = request.getAlarmId().getId();
|
||||
log.debug("[{}][{}] updateAlarm {}", tenantUUID, alarmUUID, request);
|
||||
|
||||
AlarmPropagationInfo ap = getSafePropagationInfo(request.getPropagation());
|
||||
return toAlarmApiResult(alarmRepository.updateAlarm(
|
||||
request.getTenantId().getId(),
|
||||
request.getAlarmId().getId(),
|
||||
tenantUUID,
|
||||
alarmUUID,
|
||||
request.getSeverity().name(),
|
||||
request.getStartTs(), request.getEndTs(),
|
||||
getDetailsAsString(request.getDetails()),
|
||||
@ -380,11 +387,13 @@ public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements A
|
||||
|
||||
@Override
|
||||
public AlarmApiCallResult acknowledgeAlarm(TenantId tenantId, AlarmId id, long ackTs) {
|
||||
log.debug("[{}][{}] acknowledgeAlarm [{}]", tenantId, id, ackTs);
|
||||
return toAlarmApiResult(alarmRepository.acknowledgeAlarm(tenantId.getId(), id.getId(), ackTs));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlarmApiCallResult clearAlarm(TenantId tenantId, AlarmId id, long clearTs, JsonNode details) {
|
||||
log.debug("[{}][{}] clearAlarm [{}]", tenantId, id, clearTs);
|
||||
return toAlarmApiResult(alarmRepository.clearAlarm(tenantId.getId(), id.getId(), clearTs, details != null ? getDetailsAsString(details) : null));
|
||||
}
|
||||
|
||||
|
||||
@ -27,10 +27,10 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
|
||||
import org.springframework.web.client.RestClientResponseException;
|
||||
import org.springframework.web.reactive.function.BodyInserters;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import org.springframework.web.reactive.function.client.WebClient.RequestBodySpec;
|
||||
import org.springframework.web.reactive.function.client.WebClientResponseException;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.rule.engine.api.TbContext;
|
||||
@ -132,6 +132,7 @@ public class TbHttpClient {
|
||||
|
||||
this.webClient = WebClient.builder()
|
||||
.clientConnector(new ReactorClientHttpConnector(httpClient))
|
||||
.defaultHeader(HttpHeaders.CONNECTION, "close") //In previous realization this header was present! (Added for hotfix "Connection reset")
|
||||
.build();
|
||||
} catch (SSLException e) {
|
||||
throw new TbNodeException(e);
|
||||
@ -170,7 +171,7 @@ public class TbHttpClient {
|
||||
BiConsumer<TbMsg, Throwable> onFailure) {
|
||||
try {
|
||||
if (semaphore != null && !semaphore.tryAcquire(config.getReadTimeoutMs(), TimeUnit.MILLISECONDS)) {
|
||||
ctx.tellFailure(msg, new RuntimeException("Timeout during waiting for reply!"));
|
||||
onFailure.accept(msg, new RuntimeException("Timeout during waiting for reply!"));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -183,10 +184,10 @@ public class TbHttpClient {
|
||||
.uri(uri)
|
||||
.headers(headers -> prepareHeaders(headers, msg));
|
||||
|
||||
if (HttpMethod.POST.equals(method) || HttpMethod.PUT.equals(method) ||
|
||||
HttpMethod.PATCH.equals(method) || HttpMethod.DELETE.equals(method) ||
|
||||
if ((HttpMethod.POST.equals(method) || HttpMethod.PUT.equals(method) ||
|
||||
HttpMethod.PATCH.equals(method) || HttpMethod.DELETE.equals(method)) &&
|
||||
!config.isIgnoreRequestBody()) {
|
||||
request.body(BodyInserters.fromValue(getData(msg, config.isIgnoreRequestBody(), config.isParseToPlainText())));
|
||||
request.body(BodyInserters.fromValue(getData(msg, config.isParseToPlainText())));
|
||||
}
|
||||
|
||||
request
|
||||
@ -236,11 +237,9 @@ public class TbHttpClient {
|
||||
return uri;
|
||||
}
|
||||
|
||||
private String getData(TbMsg tbMsg, boolean ignoreBody, boolean parseToPlainText) {
|
||||
if (!ignoreBody && parseToPlainText) {
|
||||
return JacksonUtil.toPlainText(tbMsg.getData());
|
||||
}
|
||||
return tbMsg.getData();
|
||||
private Object getData(TbMsg tbMsg, boolean parseToPlainText) {
|
||||
String data = tbMsg.getData();
|
||||
return parseToPlainText ? JacksonUtil.toPlainText(data) : JacksonUtil.toJsonNode(data);
|
||||
}
|
||||
|
||||
private TbMsg processResponse(TbContext ctx, TbMsg origMsg, ResponseEntity<String> response) {
|
||||
@ -283,10 +282,9 @@ public class TbHttpClient {
|
||||
private TbMsg processException(TbMsg origMsg, Throwable e) {
|
||||
TbMsgMetaData metaData = origMsg.getMetaData();
|
||||
metaData.putValue(ERROR, e.getClass() + ": " + e.getMessage());
|
||||
if (e instanceof RestClientResponseException) {
|
||||
RestClientResponseException restClientResponseException = (RestClientResponseException) e;
|
||||
if (e instanceof WebClientResponseException restClientResponseException) {
|
||||
metaData.putValue(STATUS, restClientResponseException.getStatusText());
|
||||
metaData.putValue(STATUS_CODE, restClientResponseException.getRawStatusCode() + "");
|
||||
metaData.putValue(STATUS_CODE, restClientResponseException.getStatusCode().value() + "");
|
||||
metaData.putValue(ERROR_BODY, restClientResponseException.getResponseBodyAsString());
|
||||
}
|
||||
return TbMsg.transformMsgMetadata(origMsg, metaData);
|
||||
|
||||
@ -168,7 +168,7 @@ public class TbRestApiCallNodeTest extends AbstractRuleNodeUpgradeTest {
|
||||
try {
|
||||
assertEquals(path, request.getRequestLine().getUri(), "Request path matches");
|
||||
assertTrue(request.containsHeader("Content-Type"), "Content-Type included");
|
||||
assertEquals("text/plain;charset=UTF-8",
|
||||
assertEquals("application/json",
|
||||
request.getFirstHeader("Content-Type").getValue(), "Content-Type value");
|
||||
assertTrue(request.containsHeader("Content-Length"), "Content-Length included");
|
||||
assertEquals("2",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user