This is an automated email from the ASF dual-hosted git repository.
justinchen pushed a commit to branch new_opc_server
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/new_opc_server by this push:
new d6e1f87df88 may_complete
d6e1f87df88 is described below
commit d6e1f87df88c70272ab936def02b9a57af7c439d
Author: Caideyipi <[email protected]>
AuthorDate: Thu Dec 4 14:38:19 2025 +0800
may_complete
---
.../pipe/sink/protocol/opcua/OpcUaNameSpace.java | 59 +++++++++++++++++-----
1 file changed, 47 insertions(+), 12 deletions(-)
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/opcua/OpcUaNameSpace.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/opcua/OpcUaNameSpace.java
index 69b9c52c261..4040ae0d7d2 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/opcua/OpcUaNameSpace.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/opcua/OpcUaNameSpace.java
@@ -28,6 +28,7 @@ import org.apache.iotdb.db.utils.DateTimeUtils;
import org.apache.iotdb.db.utils.TimestampPrecisionUtils;
import org.apache.iotdb.pipe.api.event.Event;
+import io.netty.buffer.ByteBuf;
import org.apache.tsfile.common.constant.TsFileConstant;
import org.apache.tsfile.enums.ColumnCategory;
import org.apache.tsfile.enums.TSDataType;
@@ -50,6 +51,7 @@ import
org.eclipse.milo.opcua.sdk.server.util.SubscriptionModel;
import org.eclipse.milo.opcua.stack.core.Identifiers;
import org.eclipse.milo.opcua.stack.core.StatusCodes;
import org.eclipse.milo.opcua.stack.core.UaException;
+import
org.eclipse.milo.opcua.stack.core.serialization.OpcUaBinaryStreamDecoder;
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
import org.eclipse.milo.opcua.stack.core.types.builtin.DateTime;
import org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject;
@@ -60,6 +62,8 @@ import
org.eclipse.milo.opcua.stack.core.types.builtin.Variant;
import org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass;
import org.eclipse.milo.opcua.stack.core.types.structured.AddNodesItem;
import org.eclipse.milo.opcua.stack.core.types.structured.AddNodesResult;
+import org.eclipse.milo.opcua.stack.core.types.structured.VariableAttributes;
+import org.eclipse.milo.opcua.stack.core.util.BufferUtil;
import java.nio.file.Paths;
import java.sql.Date;
@@ -477,40 +481,71 @@ public class OpcUaNameSpace extends
ManagedNamespaceWithLifecycle {
final List<AddNodesResult> results = new ArrayList<>(nodesToAdd.size());
for (final AddNodesItem item : nodesToAdd) {
final ExtensionObject attributes = item.getNodeAttributes();
- if
(attributes.getBodyType().equals(ExtensionObject.BodyType.ByteString)) {
-
+ if (Objects.isNull(attributes)) {
+ results.add(
+ new AddNodesResult(
+ new StatusCode(StatusCodes.Bad_NodeAttributesInvalid),
NodeId.NULL_VALUE));
+ continue;
}
if (item.getNodeClass().equals(NodeClass.Variable)) {
final Optional<NodeId> nodeId =
item.getRequestedNewNodeId().toNodeId(getServer().getNamespaceTable());
if (!nodeId.isPresent()) {
results.add(
- new AddNodesResult(new
StatusCode(StatusCodes.Bad_NodeIdRejected), NodeId.NULL_VALUE));
+ new AddNodesResult(
+ new StatusCode(StatusCodes.Bad_NodeIdRejected),
NodeId.NULL_VALUE));
continue;
}
- if (!getNodeManager()
- .containsNode(nodeId.get())) {
+ if (!getNodeManager().containsNode(nodeId.get())) {
+ final Optional<NodeId> parentId =
+ item.getParentNodeId().toNodeId(getServer().getNamespaceTable());
+ if (!parentId.isPresent()) {
+ results.add(
+ new AddNodesResult(
+ new StatusCode(StatusCodes.Bad_ParentNodeIdInvalid),
NodeId.NULL_VALUE));
+ continue;
+ }
+ final UaNode parentNode = getNodeManager().get(parentId.get());
+ if (Objects.isNull(parentNode)) {
+ results.add(
+ new AddNodesResult(
+ new StatusCode(StatusCodes.Bad_ParentNodeIdInvalid),
NodeId.NULL_VALUE));
+ continue;
+ }
+ final VariableAttributes variableAttributes;
+ if
(attributes.getBodyType().equals(ExtensionObject.BodyType.ByteString)) {
+ final OpcUaBinaryStreamDecoder decoder =
+ new
OpcUaBinaryStreamDecoder(getServer().getSerializationContext());
+ final ByteBuf byteBuf = BufferUtil.pooledBuffer();
+ variableAttributes =
+ new VariableAttributes.Codec()
+ .decode(getServer().getSerializationContext(),
decoder.setBuffer(byteBuf));
+ } else {
+ results.add(
+ new AddNodesResult(
+ new StatusCode(StatusCodes.Bad_NodeAttributesInvalid),
NodeId.NULL_VALUE));
+ continue;
+ }
measurementNode =
new UaVariableNode.UaVariableNodeBuilder(getNodeContext())
.setNodeId(nodeId.get())
.setAccessLevel(AccessLevel.READ_WRITE)
.setUserAccessLevel(AccessLevel.READ_WRITE)
.setBrowseName(item.getBrowseName())
- .setDisplayName(LocalizedText.english(name))
- .setDataType(convertToOpcDataType(type))
+ .setDisplayName(variableAttributes.getDisplayName())
+ .setDataType(variableAttributes.getDataType())
.setTypeDefinition(Identifiers.BaseDataVariableType)
.build();
getNodeManager().addNode(measurementNode);
- folderNode.addReference(
+ parentNode.addReference(
new Reference(
- folderNode.getNodeId(),
- Identifiers.Organizes,
+ measurementNode.getNodeId(),
+ item.getReferenceTypeId(),
measurementNode.getNodeId().expanded(),
true));
} else {
results.add(
- new AddNodesResult(new
StatusCode(StatusCodes.Bad_NodeIdExists), NodeId.NULL_VALUE));
- continue;
+ new AddNodesResult(new StatusCode(StatusCodes.Bad_NodeIdExists),
NodeId.NULL_VALUE));
}
}
}