Code review fixes
This commit is contained in:
parent
ba14bc11e7
commit
69994adb18
@ -118,8 +118,8 @@ public class EdgeGrpcService extends EdgeRpcServiceGrpc.EdgeRpcServiceImplBase i
|
|||||||
log.error("Failed to start Edge RPC server!", e);
|
log.error("Failed to start Edge RPC server!", e);
|
||||||
throw new RuntimeException("Failed to start Edge RPC server!");
|
throw new RuntimeException("Failed to start Edge RPC server!");
|
||||||
}
|
}
|
||||||
log.info("Edge RPC service initialized!");
|
|
||||||
this.scheduler = Executors.newScheduledThreadPool(schedulerPoolSize, ThingsBoardThreadFactory.forName("edge-scheduler"));
|
this.scheduler = Executors.newScheduledThreadPool(schedulerPoolSize, ThingsBoardThreadFactory.forName("edge-scheduler"));
|
||||||
|
log.info("Edge RPC service initialized!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreDestroy
|
@PreDestroy
|
||||||
|
|||||||
@ -16,7 +16,6 @@
|
|||||||
package org.thingsboard.server.service.edge.rpc;
|
package org.thingsboard.server.service.edge.rpc;
|
||||||
|
|
||||||
import com.datastax.driver.core.utils.UUIDs;
|
import com.datastax.driver.core.utils.UUIDs;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.common.util.concurrent.FutureCallback;
|
import com.google.common.util.concurrent.FutureCallback;
|
||||||
import com.google.common.util.concurrent.Futures;
|
import com.google.common.util.concurrent.Futures;
|
||||||
@ -120,7 +119,7 @@ import java.util.function.Consumer;
|
|||||||
@Data
|
@Data
|
||||||
public final class EdgeGrpcSession implements Closeable {
|
public final class EdgeGrpcSession implements Closeable {
|
||||||
|
|
||||||
private static final ReentrantLock responseMsgLock = new ReentrantLock();
|
private static final ReentrantLock downlinkMsgLock = new ReentrantLock();
|
||||||
|
|
||||||
private static final String QUEUE_START_TS_ATTR_KEY = "queueStartTs";
|
private static final String QUEUE_START_TS_ATTR_KEY = "queueStartTs";
|
||||||
|
|
||||||
@ -199,7 +198,7 @@ public final class EdgeGrpcSession implements Closeable {
|
|||||||
@Override
|
@Override
|
||||||
public void onSuccess(@Nullable List<Void> result) {
|
public void onSuccess(@Nullable List<Void> result) {
|
||||||
UplinkResponseMsg uplinkResponseMsg = UplinkResponseMsg.newBuilder().setSuccess(true).build();
|
UplinkResponseMsg uplinkResponseMsg = UplinkResponseMsg.newBuilder().setSuccess(true).build();
|
||||||
sendResponseMsg(ResponseMsg.newBuilder()
|
sendDownlinkMsg(ResponseMsg.newBuilder()
|
||||||
.setUplinkResponseMsg(uplinkResponseMsg)
|
.setUplinkResponseMsg(uplinkResponseMsg)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
@ -207,7 +206,7 @@ public final class EdgeGrpcSession implements Closeable {
|
|||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable t) {
|
public void onFailure(Throwable t) {
|
||||||
UplinkResponseMsg uplinkResponseMsg = UplinkResponseMsg.newBuilder().setSuccess(false).setErrorMsg(t.getMessage()).build();
|
UplinkResponseMsg uplinkResponseMsg = UplinkResponseMsg.newBuilder().setSuccess(false).setErrorMsg(t.getMessage()).build();
|
||||||
sendResponseMsg(ResponseMsg.newBuilder()
|
sendDownlinkMsg(ResponseMsg.newBuilder()
|
||||||
.setUplinkResponseMsg(uplinkResponseMsg)
|
.setUplinkResponseMsg(uplinkResponseMsg)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
@ -227,35 +226,32 @@ public final class EdgeGrpcSession implements Closeable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendResponseMsg(ResponseMsg responseMsg) {
|
private void sendDownlinkMsg(ResponseMsg downlinkMsg) {
|
||||||
log.trace("[{}] Sending response msg [{}]", this.sessionId, responseMsg);
|
log.trace("[{}] Sending downlink msg [{}]", this.sessionId, downlinkMsg);
|
||||||
if (isConnected()) {
|
if (isConnected()) {
|
||||||
try {
|
try {
|
||||||
responseMsgLock.lock();
|
downlinkMsgLock.lock();
|
||||||
outputStream.onNext(responseMsg);
|
outputStream.onNext(downlinkMsg);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("[{}] Failed to send response message [{}]", this.sessionId, responseMsg, e);
|
log.error("[{}] Failed to send downlink message [{}]", this.sessionId, downlinkMsg, e);
|
||||||
connected = false;
|
connected = false;
|
||||||
sessionCloseListener.accept(edge.getId());
|
sessionCloseListener.accept(edge.getId());
|
||||||
} finally {
|
} finally {
|
||||||
responseMsgLock.unlock();
|
downlinkMsgLock.unlock();
|
||||||
}
|
}
|
||||||
log.trace("[{}] Response msg successfully sent [{}]", this.sessionId, responseMsg);
|
log.trace("[{}] Response msg successfully sent [{}]", this.sessionId, downlinkMsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onConfigurationUpdate(Edge edge) {
|
void onConfigurationUpdate(Edge edge) {
|
||||||
log.debug("[{}] onConfigurationUpdate [{}]", this.sessionId, edge);
|
log.debug("[{}] onConfigurationUpdate [{}]", this.sessionId, edge);
|
||||||
try {
|
this.edge = edge;
|
||||||
this.edge = edge;
|
EdgeUpdateMsg edgeConfig = EdgeUpdateMsg.newBuilder()
|
||||||
EdgeUpdateMsg edgeConfig = EdgeUpdateMsg.newBuilder()
|
.setConfiguration(constructEdgeConfigProto(edge)).build();
|
||||||
.setConfiguration(constructEdgeConfigProto(edge)).build();
|
ResponseMsg edgeConfigMsg = ResponseMsg.newBuilder()
|
||||||
outputStream.onNext(ResponseMsg.newBuilder()
|
.setEdgeUpdateMsg(edgeConfig)
|
||||||
.setEdgeUpdateMsg(edgeConfig)
|
.build();
|
||||||
.build());
|
sendDownlinkMsg(edgeConfigMsg);
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("[{}] Failed to construct proto objects!", this.sessionId, e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void processEdgeEvents() throws ExecutionException, InterruptedException {
|
void processEdgeEvents() throws ExecutionException, InterruptedException {
|
||||||
@ -276,7 +272,7 @@ public final class EdgeGrpcSession implements Closeable {
|
|||||||
|
|
||||||
latch = new CountDownLatch(downlinkMsgsPack.size());
|
latch = new CountDownLatch(downlinkMsgsPack.size());
|
||||||
for (DownlinkMsg downlinkMsg : downlinkMsgsPack) {
|
for (DownlinkMsg downlinkMsg : downlinkMsgsPack) {
|
||||||
sendResponseMsg(ResponseMsg.newBuilder()
|
sendDownlinkMsg(ResponseMsg.newBuilder()
|
||||||
.setDownlinkMsg(downlinkMsg)
|
.setDownlinkMsg(downlinkMsg)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -151,7 +151,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
|
|||||||
syncWidgetsBundleAndWidgetTypes(edge);
|
syncWidgetsBundleAndWidgetTypes(edge);
|
||||||
syncAdminSettings(edge);
|
syncAdminSettings(edge);
|
||||||
syncRuleChains(edge, new TimePageLink(DEFAULT_LIMIT));
|
syncRuleChains(edge, new TimePageLink(DEFAULT_LIMIT));
|
||||||
syncUsers(edge);
|
syncUsers(edge, new TextPageLink(DEFAULT_LIMIT));
|
||||||
syncDevices(edge, new TimePageLink(DEFAULT_LIMIT));
|
syncDevices(edge, new TimePageLink(DEFAULT_LIMIT));
|
||||||
syncAssets(edge, new TimePageLink(DEFAULT_LIMIT));
|
syncAssets(edge, new TimePageLink(DEFAULT_LIMIT));
|
||||||
syncEntityViews(edge, new TimePageLink(DEFAULT_LIMIT));
|
syncEntityViews(edge, new TimePageLink(DEFAULT_LIMIT));
|
||||||
@ -303,10 +303,9 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void syncUsers(Edge edge) {
|
private void syncUsers(Edge edge, TextPageLink pageLink) {
|
||||||
log.trace("[{}] syncUsers [{}]", edge.getTenantId(), edge.getName());
|
log.trace("[{}] syncUsers [{}]", edge.getTenantId(), edge.getName());
|
||||||
try {
|
try {
|
||||||
TextPageLink pageLink = new TextPageLink(DEFAULT_LIMIT);
|
|
||||||
TextPageData<User> pageData;
|
TextPageData<User> pageData;
|
||||||
do {
|
do {
|
||||||
pageData = userService.findTenantAdmins(edge.getTenantId(), pageLink);
|
pageData = userService.findTenantAdmins(edge.getTenantId(), pageLink);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user