Merge with master
This commit is contained in:
commit
4abf7ccd5a
@ -1,22 +0,0 @@
|
|||||||
-----BEGIN CERTIFICATE-----
|
|
||||||
MIIDdzCCAl+gAwIBAgIEAgAAuTANBgkqhkiG9w0BAQUFADBaMQswCQYDVQQGEwJJ
|
|
||||||
RTESMBAGA1UEChMJQmFsdGltb3JlMRMwEQYDVQQLEwpDeWJlclRydXN0MSIwIAYD
|
|
||||||
VQQDExlCYWx0aW1vcmUgQ3liZXJUcnVzdCBSb290MB4XDTAwMDUxMjE4NDYwMFoX
|
|
||||||
DTI1MDUxMjIzNTkwMFowWjELMAkGA1UEBhMCSUUxEjAQBgNVBAoTCUJhbHRpbW9y
|
|
||||||
ZTETMBEGA1UECxMKQ3liZXJUcnVzdDEiMCAGA1UEAxMZQmFsdGltb3JlIEN5YmVy
|
|
||||||
VHJ1c3QgUm9vdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKMEuyKr
|
|
||||||
mD1X6CZymrV51Cni4eiVgLGw41uOKymaZN+hXe2wCQVt2yguzmKiYv60iNoS6zjr
|
|
||||||
IZ3AQSsBUnuId9Mcj8e6uYi1agnnc+gRQKfRzMpijS3ljwumUNKoUMMo6vWrJYeK
|
|
||||||
mpYcqWe4PwzV9/lSEy/CG9VwcPCPwBLKBsua4dnKM3p31vjsufFoREJIE9LAwqSu
|
|
||||||
XmD+tqYF/LTdB1kC1FkYmGP1pWPgkAx9XbIGevOF6uvUA65ehD5f/xXtabz5OTZy
|
|
||||||
dc93Uk3zyZAsuT3lySNTPx8kmCFcB5kpvcY67Oduhjprl3RjM71oGDHweI12v/ye
|
|
||||||
jl0qhqdNkNwnGjkCAwEAAaNFMEMwHQYDVR0OBBYEFOWdWTCCR1jMrPoIVDaGezq1
|
|
||||||
BE3wMBIGA1UdEwEB/wQIMAYBAf8CAQMwDgYDVR0PAQH/BAQDAgEGMA0GCSqGSIb3
|
|
||||||
DQEBBQUAA4IBAQCFDF2O5G9RaEIFoN27TyclhAO992T9Ldcw46QQF+vaKSm2eT92
|
|
||||||
9hkTI7gQCvlYpNRhcL0EYWoSihfVCr3FvDB81ukMJY2GQE/szKN+OMY3EU/t3Wgx
|
|
||||||
jkzSswF07r51XgdIGn9w/xZchMB5hbgF/X++ZRGjD8ACtPhSNzkE1akxehi/oCr0
|
|
||||||
Epn3o0WC4zxe9Z2etciefC7IpJ5OCBRLbf1wbWsaY71k5h+3zvDyny67G7fyUIhz
|
|
||||||
ksLi4xaNmjICq44Y3ekQEe5+NauQrz4wlHrQMz2nZQ/1/I6eYs9HRCwBXbsdtTLS
|
|
||||||
R9I4LtD+gdwyah617jzV/OeBHRnDJELqYzmp
|
|
||||||
-----END CERTIFICATE-----
|
|
||||||
|
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIDjjCCAnagAwIBAgIQAzrx5qcRqaC7KGSxHQn65TANBgkqhkiG9w0BAQsFADBh
|
||||||
|
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
|
||||||
|
d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBH
|
||||||
|
MjAeFw0xMzA4MDExMjAwMDBaFw0zODAxMTUxMjAwMDBaMGExCzAJBgNVBAYTAlVT
|
||||||
|
MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j
|
||||||
|
b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IEcyMIIBIjANBgkqhkiG
|
||||||
|
9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuzfNNNx7a8myaJCtSnX/RrohCgiN9RlUyfuI
|
||||||
|
2/Ou8jqJkTx65qsGGmvPrC3oXgkkRLpimn7Wo6h+4FR1IAWsULecYxpsMNzaHxmx
|
||||||
|
1x7e/dfgy5SDN67sH0NO3Xss0r0upS/kqbitOtSZpLYl6ZtrAGCSYP9PIUkY92eQ
|
||||||
|
q2EGnI/yuum06ZIya7XzV+hdG82MHauVBJVJ8zUtluNJbd134/tJS7SsVQepj5Wz
|
||||||
|
tCO7TG1F8PapspUwtP1MVYwnSlcUfIKdzXOS0xZKBgyMUNGPHgm+F6HmIcr9g+UQ
|
||||||
|
vIOlCsRnKPZzFBQ9RnbDhxSJITRNrw9FDKZJobq7nMWxM4MphQIDAQABo0IwQDAP
|
||||||
|
BgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBhjAdBgNVHQ4EFgQUTiJUIBiV
|
||||||
|
5uNu5g/6+rkS7QYXjzkwDQYJKoZIhvcNAQELBQADggEBAGBnKJRvDkhj6zHd6mcY
|
||||||
|
1Yl9PMWLSn/pvtsrF9+wX3N3KjITOYFnQoQj8kVnNeyIv/iPsGEMNKSuIEyExtv4
|
||||||
|
NeF22d+mQrvHRAiGfzZ0JFrabA0UWTW98kndth/Jsw1HKj2ZL7tcu7XUIOGZX1NG
|
||||||
|
Fdtom/DzMNU+MeKNhJ7jitralj41E6Vf8PlwUHBHQRFXGU7Aj64GxJUTFy8bJZ91
|
||||||
|
8rGOmaFvE7FBcf6IKshPECBV1/MUReXgRPTqh5Uykw7+U0b6LJ3/iyK5S9kJRaTe
|
||||||
|
pLiaWN0bfVKfjllDiIGknibVb63dDcY3fe0Dkhvld1927jyNxF1WW6LZZm6zNTfl
|
||||||
|
MrY=
|
||||||
|
-----END CERTIFICATE-----
|
||||||
@ -380,21 +380,26 @@ public class EdgeGrpcService extends EdgeRpcServiceGrpc.EdgeRpcServiceImplBase i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onEdgeDisconnect(EdgeId edgeId) {
|
private void onEdgeDisconnect(EdgeId edgeId, UUID sessionId) {
|
||||||
log.info("[{}] edge disconnected!", edgeId);
|
log.info("[{}][{}] edge disconnected!", edgeId, sessionId);
|
||||||
EdgeGrpcSession removed = sessions.remove(edgeId);
|
EdgeGrpcSession toRemove = sessions.get(edgeId);
|
||||||
final Lock newEventLock = sessionNewEventsLocks.computeIfAbsent(edgeId, id -> new ReentrantLock());
|
if (toRemove.getSessionId().equals(sessionId)) {
|
||||||
newEventLock.lock();
|
toRemove = sessions.remove(edgeId);
|
||||||
try {
|
final Lock newEventLock = sessionNewEventsLocks.computeIfAbsent(edgeId, id -> new ReentrantLock());
|
||||||
sessionNewEvents.remove(edgeId);
|
newEventLock.lock();
|
||||||
} finally {
|
try {
|
||||||
newEventLock.unlock();
|
sessionNewEvents.remove(edgeId);
|
||||||
|
} finally {
|
||||||
|
newEventLock.unlock();
|
||||||
|
}
|
||||||
|
save(edgeId, DefaultDeviceStateService.ACTIVITY_STATE, false);
|
||||||
|
long lastDisconnectTs = System.currentTimeMillis();
|
||||||
|
save(edgeId, DefaultDeviceStateService.LAST_DISCONNECT_TIME, lastDisconnectTs);
|
||||||
|
pushRuleEngineMessage(toRemove.getEdge().getTenantId(), edgeId, lastDisconnectTs, DISCONNECT_EVENT);
|
||||||
|
cancelScheduleEdgeEventsCheck(edgeId);
|
||||||
|
} else {
|
||||||
|
log.debug("[{}] edge session [{}] is not available anymore, nothing to remove. most probably this session is already outdated!", edgeId, sessionId);
|
||||||
}
|
}
|
||||||
save(edgeId, DefaultDeviceStateService.ACTIVITY_STATE, false);
|
|
||||||
long lastDisconnectTs = System.currentTimeMillis();
|
|
||||||
save(edgeId, DefaultDeviceStateService.LAST_DISCONNECT_TIME, lastDisconnectTs);
|
|
||||||
pushRuleEngineMessage(removed.getEdge().getTenantId(), edgeId, lastDisconnectTs, DISCONNECT_EVENT);
|
|
||||||
cancelScheduleEdgeEventsCheck(edgeId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void save(EdgeId edgeId, String key, long value) {
|
private void save(EdgeId edgeId, String key, long value) {
|
||||||
|
|||||||
@ -92,7 +92,7 @@ public final class EdgeGrpcSession implements Closeable {
|
|||||||
|
|
||||||
private final UUID sessionId;
|
private final UUID sessionId;
|
||||||
private final BiConsumer<EdgeId, EdgeGrpcSession> sessionOpenListener;
|
private final BiConsumer<EdgeId, EdgeGrpcSession> sessionOpenListener;
|
||||||
private final Consumer<EdgeId> sessionCloseListener;
|
private final BiConsumer<EdgeId, UUID> sessionCloseListener;
|
||||||
|
|
||||||
private final EdgeSessionState sessionState = new EdgeSessionState();
|
private final EdgeSessionState sessionState = new EdgeSessionState();
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ public final class EdgeGrpcSession implements Closeable {
|
|||||||
private ScheduledExecutorService sendDownlinkExecutorService;
|
private ScheduledExecutorService sendDownlinkExecutorService;
|
||||||
|
|
||||||
EdgeGrpcSession(EdgeContextComponent ctx, StreamObserver<ResponseMsg> outputStream, BiConsumer<EdgeId, EdgeGrpcSession> sessionOpenListener,
|
EdgeGrpcSession(EdgeContextComponent ctx, StreamObserver<ResponseMsg> outputStream, BiConsumer<EdgeId, EdgeGrpcSession> sessionOpenListener,
|
||||||
Consumer<EdgeId> sessionCloseListener, ScheduledExecutorService sendDownlinkExecutorService, int maxInboundMessageSize) {
|
BiConsumer<EdgeId, UUID> sessionCloseListener, ScheduledExecutorService sendDownlinkExecutorService, int maxInboundMessageSize) {
|
||||||
this.sessionId = UUID.randomUUID();
|
this.sessionId = UUID.randomUUID();
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
this.outputStream = outputStream;
|
this.outputStream = outputStream;
|
||||||
@ -180,7 +180,7 @@ public final class EdgeGrpcSession implements Closeable {
|
|||||||
connected = false;
|
connected = false;
|
||||||
if (edge != null) {
|
if (edge != null) {
|
||||||
try {
|
try {
|
||||||
sessionCloseListener.accept(edge.getId());
|
sessionCloseListener.accept(edge.getId(), sessionId);
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -288,7 +288,7 @@ public final class EdgeGrpcSession implements Closeable {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("[{}] Failed to send downlink message [{}]", this.sessionId, downlinkMsg, e);
|
log.error("[{}] Failed to send downlink message [{}]", this.sessionId, downlinkMsg, e);
|
||||||
connected = false;
|
connected = false;
|
||||||
sessionCloseListener.accept(edge.getId());
|
sessionCloseListener.accept(edge.getId(), sessionId);
|
||||||
} finally {
|
} finally {
|
||||||
downlinkMsgLock.unlock();
|
downlinkMsgLock.unlock();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,6 +25,7 @@ import com.google.common.util.concurrent.MoreExecutors;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.mvel2.CompileException;
|
||||||
import org.mvel2.ExecutionContext;
|
import org.mvel2.ExecutionContext;
|
||||||
import org.mvel2.MVEL;
|
import org.mvel2.MVEL;
|
||||||
import org.mvel2.ParserContext;
|
import org.mvel2.ParserContext;
|
||||||
@ -65,6 +66,8 @@ public class DefaultTbelInvokeService extends AbstractScriptInvokeService implem
|
|||||||
|
|
||||||
protected final Map<UUID, String> scriptIdToHash = new ConcurrentHashMap<>();
|
protected final Map<UUID, String> scriptIdToHash = new ConcurrentHashMap<>();
|
||||||
protected final Map<String, TbelScript> scriptMap = new ConcurrentHashMap<>();
|
protected final Map<String, TbelScript> scriptMap = new ConcurrentHashMap<>();
|
||||||
|
private final String tbelSwitch = "switch";
|
||||||
|
private final String tbelSwitchErrorMsg = "TBEL does not support the 'switch'.";
|
||||||
protected Cache<String, Serializable> compiledScriptsCache;
|
protected Cache<String, Serializable> compiledScriptsCache;
|
||||||
|
|
||||||
private SandboxedParserConfiguration parserConfig;
|
private SandboxedParserConfiguration parserConfig;
|
||||||
@ -180,6 +183,11 @@ public class DefaultTbelInvokeService extends AbstractScriptInvokeService implem
|
|||||||
lock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
return scriptId;
|
return scriptId;
|
||||||
|
} catch (CompileException ce) {
|
||||||
|
if ( ce.getExpr() != null && new String(ce.getExpr()).contains(tbelSwitch)) {
|
||||||
|
ce = new CompileException(tbelSwitchErrorMsg, ce.getExpr(), ce.getCursor(), ce.getCause());
|
||||||
|
}
|
||||||
|
throw new TbScriptException(scriptId, TbScriptException.ErrorCode.COMPILATION, scriptBody, ce);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new TbScriptException(scriptId, TbScriptException.ErrorCode.COMPILATION, scriptBody, e);
|
throw new TbScriptException(scriptId, TbScriptException.ErrorCode.COMPILATION, scriptBody, e);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,10 +22,12 @@ import javax.crypto.spec.SecretKeySpec;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.DirectoryStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public final class AzureIotHubUtil {
|
public final class AzureIotHubUtil {
|
||||||
@ -36,7 +38,7 @@ public final class AzureIotHubUtil {
|
|||||||
private static final String DATA_DIR = "data";
|
private static final String DATA_DIR = "data";
|
||||||
private static final String CERTS_DIR = "certs";
|
private static final String CERTS_DIR = "certs";
|
||||||
private static final String AZURE_DIR = "azure";
|
private static final String AZURE_DIR = "azure";
|
||||||
private static final String FILE_NAME = "BaltimoreCyberTrustRoot.crt.pem";
|
private static final String FILE_NAME = "DigiCertGlobalRootG2.crt.pem";
|
||||||
|
|
||||||
private static final Path FULL_FILE_PATH;
|
private static final Path FULL_FILE_PATH;
|
||||||
|
|
||||||
@ -88,12 +90,31 @@ public final class AzureIotHubUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getDefaultCaCert() {
|
public static String getDefaultCaCert() {
|
||||||
try {
|
byte[] fileBytes;
|
||||||
return new String(Files.readAllBytes(FULL_FILE_PATH));
|
if (Files.exists(FULL_FILE_PATH)) {
|
||||||
} catch (IOException e) {
|
try {
|
||||||
log.error("Failed to load Default CaCert file!!! [{}]", FULL_FILE_PATH.toString());
|
fileBytes = Files.readAllBytes(FULL_FILE_PATH);
|
||||||
throw new RuntimeException("Failed to load Default CaCert file!!!");
|
} catch (IOException e) {
|
||||||
|
log.error("Failed to load Default CaCert file!!! [{}]", FULL_FILE_PATH, e);
|
||||||
|
throw new RuntimeException("Failed to load Default CaCert file!!!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Path azureDirectory = FULL_FILE_PATH.getParent();
|
||||||
|
try (DirectoryStream<Path> stream = Files.newDirectoryStream(azureDirectory)) {
|
||||||
|
Iterator<Path> iterator = stream.iterator();
|
||||||
|
if (iterator.hasNext()) {
|
||||||
|
Path firstFile = iterator.next();
|
||||||
|
fileBytes = Files.readAllBytes(firstFile);
|
||||||
|
} else {
|
||||||
|
log.error("Default CaCert file not found in the directory [{}]!!!", azureDirectory);
|
||||||
|
throw new RuntimeException("Default CaCert file not found in the directory!!!");
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("Failed to load Default CaCert file from the directory [{}]!!!", azureDirectory, e);
|
||||||
|
throw new RuntimeException("Failed to load Default CaCert file from the directory!!!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return new String(fileBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5229,6 +5229,10 @@ var JSHINT = (function() {
|
|||||||
var a = [], p;
|
var a = [], p;
|
||||||
|
|
||||||
while (!state.tokens.next.reach && state.tokens.next.id !== "(end)") {
|
while (!state.tokens.next.reach && state.tokens.next.id !== "(end)") {
|
||||||
|
if (state.tokens.next.value === "switch") {
|
||||||
|
warning("E067", state.tokens.next, "switch");
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (state.tokens.next.id === ";") {
|
if (state.tokens.next.id === ";") {
|
||||||
p = peek();
|
p = peek();
|
||||||
|
|
||||||
@ -9215,7 +9219,7 @@ var JSHINT = (function() {
|
|||||||
statements(0);
|
statements(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.tokens.next.id !== "(end)") {
|
if (state.tokens.next.id !== "(end)"&& state.tokens.next.value !== "switch") {
|
||||||
quit("E041", state.tokens.curr);
|
quit("E041", state.tokens.curr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -11266,7 +11270,8 @@ var errors = {
|
|||||||
E064: "Super call may only be used within class method bodies.",
|
E064: "Super call may only be used within class method bodies.",
|
||||||
E065: "Functions defined outside of strict mode with non-simple parameter lists may not " +
|
E065: "Functions defined outside of strict mode with non-simple parameter lists may not " +
|
||||||
"enable strict mode.",
|
"enable strict mode.",
|
||||||
E066: "Asynchronous iteration is only available with for-of loops."
|
E066: "Asynchronous iteration is only available with for-of loops.",
|
||||||
|
E067: "Expected an 'if/else' and instead saw 'switch'. TBEL does not support the 'switch' statement."
|
||||||
};
|
};
|
||||||
|
|
||||||
var warnings = {
|
var warnings = {
|
||||||
@ -11364,7 +11369,6 @@ var warnings = {
|
|||||||
W086: "Expected a 'break' statement before '{a}'.",
|
W086: "Expected a 'break' statement before '{a}'.",
|
||||||
W087: "Forgotten 'debugger' statement?",
|
W087: "Forgotten 'debugger' statement?",
|
||||||
W088: "Creating global 'for' variable. Should be 'for (var {a} ...'.",
|
W088: "Creating global 'for' variable. Should be 'for (var {a} ...'.",
|
||||||
// W288: "The syntax of function '{a}' is specific to TBEL, and is not supported by JS executor.",
|
|
||||||
W089: "The body of a for in should be wrapped in an if statement to filter " +
|
W089: "The body of a for in should be wrapped in an if statement to filter " +
|
||||||
"unwanted properties from the prototype.",
|
"unwanted properties from the prototype.",
|
||||||
W090: "'{a}' is not a statement label.",
|
W090: "'{a}' is not a statement label.",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user