Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions dependencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"com.google.j2objc:j2objc-annotations",
"com.h2database:h2-mvstore",
"com.sun.activation:jakarta.activation",
"com.sun.istack:istack-commons-runtime",
"com.zaxxer:HikariCP",
"commons-cli:commons-cli",
"commons-codec:commons-codec",
Expand Down Expand Up @@ -116,14 +115,11 @@
"org.eclipse.jetty:jetty-session",
"org.eclipse.jetty:jetty-util",
"org.eclipse.jetty.ee10:jetty-ee10-servlet",
"org.eclipse.milo:bsd-core",
"org.eclipse.milo:bsd-generator",
"org.eclipse.milo:sdk-client",
"org.eclipse.milo:sdk-core",
"org.eclipse.milo:sdk-server",
"org.eclipse.milo:stack-client",
"org.eclipse.milo:stack-core",
"org.eclipse.milo:stack-server",
"org.eclipse.milo:milo-sdk-client",
"org.eclipse.milo:milo-sdk-core",
"org.eclipse.milo:milo-sdk-server",
"org.eclipse.milo:milo-stack-core",
"org.eclipse.milo:milo-transport",
"org.fusesource.hawtbuf:hawtbuf",
"org.fusesource.hawtdispatch:hawtdispatch",
"org.fusesource.hawtdispatch:hawtdispatch-transport",
Expand All @@ -133,8 +129,6 @@
"org.glassfish.hk2:hk2-utils",
"org.glassfish.hk2:osgi-resource-locator",
"org.glassfish.hk2.external:aopalliance-repackaged",
"org.glassfish.jaxb:jaxb-runtime",
"org.glassfish.jaxb:txw2",
"org.glassfish.jersey.containers:jersey-container-servlet-core",
"org.glassfish.jersey.core:jersey-client",
"org.glassfish.jersey.core:jersey-common",
Expand All @@ -145,6 +139,7 @@
"org.java-websocket:Java-WebSocket",
"org.javassist:javassist",
"org.jline:jline",
"org.jspecify:jspecify",
"org.jvnet.mimepull:mimepull",
"org.latencyutils:LatencyUtils",
"org.ops4j.pax.jdbc:pax-jdbc-common",
Expand Down
4 changes: 2 additions & 2 deletions example/pipe-opc-ua-sink/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
<dependencies>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>sdk-client</artifactId>
<artifactId>milo-sdk-client</artifactId>
<version>${milo.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>sdk-server</artifactId>
<artifactId>milo-sdk-server</artifactId>
</dependency>
</dependencies>
<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
package org.apache.iotdb.opcua;

import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
import org.eclipse.milo.opcua.sdk.client.api.identity.AnonymousProvider;
import org.eclipse.milo.opcua.sdk.client.api.identity.IdentityProvider;
import org.eclipse.milo.opcua.sdk.client.identity.AnonymousProvider;
import org.eclipse.milo.opcua.sdk.client.identity.IdentityProvider;
import org.eclipse.milo.opcua.stack.core.security.SecurityPolicy;
import org.eclipse.milo.opcua.stack.core.types.structured.EndpointDescription;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@

import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
import org.eclipse.milo.opcua.stack.client.security.DefaultClientCertificateValidator;
import org.eclipse.milo.opcua.stack.core.Stack;
import org.eclipse.milo.opcua.stack.core.security.DefaultTrustListManager;
import org.eclipse.milo.opcua.stack.core.security.DefaultClientCertificateValidator;
import org.eclipse.milo.opcua.stack.core.security.FileBasedCertificateQuarantine;
import org.eclipse.milo.opcua.stack.core.security.FileBasedTrustListManager;
import org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -48,6 +49,7 @@ public class ClientExampleRunner {
private final CompletableFuture<OpcUaClient> future = new CompletableFuture<>();

private final ClientExample clientExample;
private FileBasedTrustListManager trustListManager;

public ClientExampleRunner(ClientExample clientExample) {
this.clientExample = clientExample;
Expand All @@ -61,21 +63,24 @@ private OpcUaClient createClient() throws Exception {
throw new Exception("unable to create security dir: " + securityTempDir);
}

final File pkiDir = securityTempDir.resolve("pki").toFile();
final Path pkiDir = securityTempDir.resolve("pki");

System.out.println("security dir: " + securityTempDir.toAbsolutePath());
LoggerFactory.getLogger(getClass()).info("security pki dir: {}", pkiDir.getAbsolutePath());
LoggerFactory.getLogger(getClass()).info("security pki dir: {}", pkiDir.toAbsolutePath());

final IoTDBKeyStoreLoaderClient loader = new IoTDBKeyStoreLoaderClient().load(securityTempDir);

final DefaultTrustListManager trustListManager = new DefaultTrustListManager(pkiDir);
trustListManager = FileBasedTrustListManager.createAndInitialize(pkiDir);
final FileBasedCertificateQuarantine certificateQuarantine =
FileBasedCertificateQuarantine.create(pkiDir.resolve("rejected").resolve("certs"));

final DefaultClientCertificateValidator certificateValidator =
new DefaultClientCertificateValidator(trustListManager);
new DefaultClientCertificateValidator(trustListManager, certificateQuarantine);

return OpcUaClient.create(
clientExample.getEndpointUrl(),
endpoints -> endpoints.stream().filter(clientExample.endpointFilter()).findFirst(),
transportBuilder -> {},
configBuilder ->
configBuilder
.setApplicationName(LocalizedText.english("eclipse milo opc-ua client"))
Expand All @@ -85,8 +90,7 @@ private OpcUaClient createClient() throws Exception {
.setCertificateChain(loader.getClientCertificateChain())
.setCertificateValidator(certificateValidator)
.setIdentityProvider(clientExample.getIdentityProvider())
.setRequestTimeout(uint(5000))
.build());
.setRequestTimeout(uint(5000)));
}

public void run() {
Expand All @@ -100,11 +104,13 @@ public void run() {
}

try {
client.disconnect().get();
Stack.releaseSharedResources();
client.disconnectAsync().get();
} catch (InterruptedException | ExecutionException e) {
Thread.currentThread().interrupt();
System.out.println("Error disconnecting: {}" + e.getMessage());
} finally {
closeTrustListManager();
Stack.releaseSharedResources();
}

try {
Expand All @@ -126,6 +132,7 @@ public void run() {
} catch (Throwable t) {
System.out.println("Error getting client: {}" + t.getMessage());

closeTrustListManager();
future.completeExceptionally(t);

try {
Expand All @@ -144,4 +151,16 @@ public void run() {
e.printStackTrace();
}
}

private void closeTrustListManager() {
if (trustListManager != null) {
try {
trustListManager.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
trustListManager = null;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,18 @@
package org.apache.iotdb.opcua;

import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
import org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaMonitoredItem;
import org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaSubscription;
import org.eclipse.milo.opcua.sdk.client.subscriptions.OpcUaMonitoredItem;
import org.eclipse.milo.opcua.sdk.client.subscriptions.OpcUaSubscription;
import org.eclipse.milo.opcua.stack.core.AttributeId;
import org.eclipse.milo.opcua.stack.core.Identifiers;
import org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject;
import org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName;
import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger;
import org.eclipse.milo.opcua.stack.core.types.enumerated.MonitoringMode;
import org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn;
import org.eclipse.milo.opcua.stack.core.types.structured.ContentFilter;
import org.eclipse.milo.opcua.stack.core.types.structured.EventFilter;
import org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemCreateRequest;
import org.eclipse.milo.opcua.stack.core.types.structured.MonitoringParameters;
import org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId;
import org.eclipse.milo.opcua.stack.core.types.structured.SimpleAttributeOperand;

import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint;

Expand All @@ -52,24 +43,19 @@ public static void main(String[] args) {
new ClientExampleRunner(example).run();
}

private final AtomicLong clientHandles = new AtomicLong(1L);

@Override
public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
// synchronous connect
client.connect().get();
client.connect();

// create a subscription and a monitored item
final UaSubscription subscription =
client.getSubscriptionManager().createSubscription(200.0).get();
final OpcUaSubscription subscription = new OpcUaSubscription(client, 200.0);
subscription.create();

final ReadValueId readValueId =
new ReadValueId(
Identifiers.Server, AttributeId.EventNotifier.uid(), null, QualifiedName.NULL_VALUE);

// client handle must be unique per item
final UInteger clientHandle = uint(clientHandles.getAndIncrement());

final EventFilter eventFilter =
new EventFilter(
new SimpleAttributeOperand[] {
Expand All @@ -96,30 +82,18 @@ public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throw
},
new ContentFilter(null));

final MonitoringParameters parameters =
new MonitoringParameters(
clientHandle,
0.0,
ExtensionObject.encode(client.getStaticSerializationContext(), eventFilter),
uint(10000),
true);

final MonitoredItemCreateRequest request =
new MonitoredItemCreateRequest(readValueId, MonitoringMode.Reporting, parameters);

final List<UaMonitoredItem> items =
subscription
.createMonitoredItems(TimestampsToReturn.Both, Collections.singletonList(request))
.get();
final OpcUaMonitoredItem monitoredItem =
new OpcUaMonitoredItem(readValueId, MonitoringMode.Reporting);
monitoredItem.setSamplingInterval(0.0);
monitoredItem.setFilter(eventFilter);
monitoredItem.setQueueSize(uint(10000));
monitoredItem.setDiscardOldest(true);
subscription.addMonitoredItem(monitoredItem);
subscription.synchronizeMonitoredItems();

// do something with the value updates
final UaMonitoredItem monitoredItem = items.get(0);

final AtomicInteger eventCount = new AtomicInteger(0);

monitoredItem.setEventConsumer(
monitoredItem.setEventValueListener(
(item, vs) -> {
eventCount.incrementAndGet();
System.out.println("Event Received from " + item.getReadValueId().getNodeId());

for (int i = 0; i < vs.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@

import org.apache.tsfile.common.conf.TSFileConfig;
import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
import org.eclipse.milo.opcua.sdk.client.api.identity.AnonymousProvider;
import org.eclipse.milo.opcua.sdk.client.api.identity.IdentityProvider;
import org.eclipse.milo.opcua.sdk.client.api.identity.UsernameProvider;
import org.eclipse.milo.opcua.sdk.client.identity.AnonymousProvider;
import org.eclipse.milo.opcua.sdk.client.identity.IdentityProvider;
import org.eclipse.milo.opcua.sdk.client.identity.UsernameProvider;
import org.eclipse.milo.opcua.stack.core.security.SecurityPolicy;
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
import org.eclipse.milo.opcua.stack.core.types.builtin.DateTime;
Expand Down Expand Up @@ -127,13 +127,10 @@ public void testOPCUAServerSink() throws Exception {
throw e;
}
}
value =
opcUaClient
.readValue(0, TimestampsToReturn.Both, new NodeId(2, "root/db/d1/`1`"))
.get();
value = opcUaClient.readValue(0, TimestampsToReturn.Both, new NodeId(2, "root/db/d1/`1`"));
Assert.assertEquals(new Variant(1.0), value.getValue());
Assert.assertEquals(new DateTime(timestampToUtc(1)), value.getSourceTime());
opcUaClient.disconnect().get();
opcUaClient.disconnect();
break;
}

Expand Down Expand Up @@ -194,26 +191,19 @@ public void testOPCUAServerSink() throws Exception {
long startTime = System.currentTimeMillis();
while (true) {
try {
value =
opcUaClient
.readValue(0, TimestampsToReturn.Both, new NodeId(2, "root/db/`123`"))
.get();
value = opcUaClient.readValue(0, TimestampsToReturn.Both, new NodeId(2, "root/db/`123`"));
Assert.assertEquals(new Variant(1.0), value.getValue());
Assert.assertEquals(StatusCode.BAD, value.getStatusCode());
Assert.assertEquals(new DateTime(timestampToUtc(1)), value.getSourceTime());

value =
opcUaClient
.readValue(0, TimestampsToReturn.Both, new NodeId(2, "root/db/`1231`"))
.get();
opcUaClient.readValue(0, TimestampsToReturn.Both, new NodeId(2, "root/db/`1231`"));
Assert.assertEquals(new Variant(1.0), value.getValue());
Assert.assertEquals(StatusCode.BAD, value.getStatusCode());
Assert.assertEquals(new DateTime(timestampToUtc(1)), value.getSourceTime());

value =
opcUaClient
.readValue(0, TimestampsToReturn.Both, new NodeId(2, "root/db/`1232`"))
.get();
opcUaClient.readValue(0, TimestampsToReturn.Both, new NodeId(2, "root/db/`1232`"));
Assert.assertEquals(new Variant(1.0), value.getValue());
Assert.assertEquals(StatusCode.BAD, value.getStatusCode());
Assert.assertEquals(new DateTime(timestampToUtc(1)), value.getSourceTime());
Expand All @@ -232,10 +222,7 @@ public void testOPCUAServerSink() throws Exception {
startTime = System.currentTimeMillis();
while (true) {
try {
value =
opcUaClient
.readValue(0, TimestampsToReturn.Both, new NodeId(2, "root/db/`123`"))
.get();
value = opcUaClient.readValue(0, TimestampsToReturn.Both, new NodeId(2, "root/db/`123`"));
Assert.assertEquals(new DateTime(timestampToUtc(2)), value.getSourceTime());
Assert.assertEquals(new Variant(2.0), value.getValue());
Assert.assertEquals(StatusCode.UNCERTAIN, value.getStatusCode());
Expand All @@ -247,7 +234,7 @@ public void testOPCUAServerSink() throws Exception {
}
}

opcUaClient.disconnect().get();
opcUaClient.disconnect();
Assert.assertEquals(
TSStatusCode.SUCCESS_STATUS.getStatusCode(), client.dropPipe("testPipe").getCode());

Expand Down
14 changes: 5 additions & 9 deletions iotdb-core/datanode/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,23 +187,19 @@
</dependency>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>stack-core</artifactId>
<artifactId>milo-stack-core</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>sdk-core</artifactId>
<artifactId>milo-sdk-core</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>stack-server</artifactId>
<artifactId>milo-transport</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>stack-client</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>sdk-client</artifactId>
<artifactId>milo-sdk-client</artifactId>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
Expand All @@ -223,7 +219,7 @@
</dependency>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>sdk-server</artifactId>
<artifactId>milo-sdk-server</artifactId>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
Expand Down
Loading
Loading