Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
Adding nodes, deleting them, and re-adding them returns BadInternalError
May 3, 2019
14:29, EEST
Avatar
Thomas Reuther
Member
Members
Forum Posts: 33
Member Since:
September 18, 2017
sp_UserOfflineSmall Offline

Hi everyone,

I use Java SDK 3.1.6. I created a test server which dynamically adds and removes nodes.
I use custom structs but I don’t think it belongs to the custom types.

But for completeness I’ll describe them here:

  • DataType Point2D which has to elements X:ushort and Y:ushort.
  • VariableType Point2DType which is a subtype of BaseDataVariableType and a value of type Point2D. Nodes of this type will be added and removed.
  • ObjectType PointFolderType which is a subtype of FolderType and has two methods:
    1. addPoint with one input argument of type Point2D. This will add variable nodes of type Point2DType as children of this folder with reference type Organizes.
    2. removeAll with no arguments. This method deletes the nodes from this folder.

    This folder also has the property NodeVersion

  • EventType PointCreationEventType with one extra field PointData of type Point2D.

I used UA Modeler for modelling and the code generator to get the code for my server.

This is the code of the method listener:

public class MyMethodListener implements CallableListener {

private static final NodeId NODE_ID_POINTS_FOLDER = new NodeId(3, 5018);

@Override
public boolean onCall(ServiceContext serviceContext, NodeId objectId, UaNode object, NodeId methodId,
UaMethod method, Variant[] inputArguments, StatusCode[] inputArgumentResults,
DiagnosticInfo[] inputArgumentDiagnosticInfos, Variant[] outputs) throws StatusException {

String sNodeId = methodId.toString();
switch (sNodeId) {
case "ns=3;i=7022":
try {
addPoint(inputArguments, inputArgumentResults, outputs);
} catch (ServiceException e) {
throw new StatusException(e.getMessage(), e.getServiceResult());
}
return true;
case "ns=3;i=7027":
removeAllPoints(inputArguments, inputArgumentResults, outputs);
return true;
}
return false;
}

The addPoint method:

private void addPoint(Variant[] inputArguments, StatusCode[] inputArgumentResults, Variant[] outputs) throws ServiceException, StatusException {
Point2D point = inputArguments[0].asClass(Point2D.class, null);
if (point.getX() == null || point.getY() == null) {
inputArgumentResults[0] = new StatusCode(StatusCodes.Bad_InvalidArgument);
throw new StatusException(inputArgumentResults[0]);
} else {
PointFolderTypeNode pointFolder = (PointFolderTypeNode)this.nodeManager.getNode(NODE_ID_POINTS_FOLDER);
this.rootManager.beginModelChange();
try {
Point2DTypeNode pointNode = this.nodeManager.createInstance(Point2DTypeNode.class, point.getX().toString() + "," + point.getY().toString());
pointNode.setValue(point);
pointFolder.addReference(pointNode, Identifiers.Organizes, false);
} finally {
this.rootManager.endModelChange();
}

PointCreationEventType event = this.nodeManager.createEvent(PointCreationEventType.class);
event.setPointData(point);
event.setSourceNode(pointFolder.getNodeId());
event.setMessage(new LocalizedText("Point {" + point.getX() + "," + point.getY() + "} created."));
((PointCreationEventTypeNode)event).triggerEvent(null);
}
}

The string representation of X and Y is used for node id and browse/display name. When I call this method a new variable node is created and all attributes are correct. Also the event is raised.

The removeAll method:

private void removeAllPoints(Variant[] inputArguments, StatusCode[] inputArgumentResults, Variant[] outputs) throws StatusException {
PointFolderTypeNode pointFolder = (PointFolderTypeNode)this.nodeManager.getNode(NODE_ID_POINTS_FOLDER);
UaReference[] references = this.nodeManager.getReferences(pointFolder.getNodeId());
this.rootManager.beginModelChange();
try {
List<UaNode> nodes = Stream.of(references)
// Filter1: only references of type "Organizes"
.filter(ref -> ref.getReferenceTypeId().equals(Identifiers.Organizes))
// Filter2: only forward references starting at "Points" folder
.filter(ref -> ref.getSourceNode().equals(pointFolder))
.map(ref -> ref.getTargetNode())
.collect(Collectors.toList());
for (UaNode node : nodes) {
this.nodeManager.deleteNode(node, true, false);
}
} finally {
this.rootManager.endModelChange();
}
}

After calling this method all nodes disappear from the address space.

Here comes the problem: when I call addPoint again with the same arguments (x,y) as before I’l get a Bad_InternalError.
After restarting my server I can recreate the nodes (but only once).
It seems that deleting the nodes is not enough.

Update:
On the server side I’ll get the exception:

com.prosysopc.ua.server.UaInstantiationException: Creating the node with builder failed
Caused by: com.prosysopc.ua.server.NodeBuilderException: Could not add node NodeId=ns=3;s=0,0/3:X, NodeClass=Variable, BrowseName=3:X; Type={NodeId=i=63, NodeClass=VariableType, BrowseName=BaseDataVariableType, IsAbstract=false, DataType=i=24, ValueRank=-2, ArrayDimensions=null, Value=(null)} DataType=NodeId=i=24, NodeClass=DataType, BrowseName=BaseDataType, IsAbstract=true, ValueRank=-1, MinimumSamplingInterval=-1,000000, AccessLevel=[CurrentRead, CurrentWrite], UserAccessLevel=[CurrentRead, CurrentWrite], Historizing=false, Value=DataValue(value=(null), statusCode=Bad_WaitingForInitialData (0x80320000) "Waiting for the server to obtain values from the underlying data source.", sourceTimestamp=null, sourcePicoseconds=0, serverTimestamp=null, serverPicoseconds=0) to NodeManager
Caused by: com.prosysopc.ua.StatusException: A different node with the same nodeId (ns=3;s=0,0/3:X) already exists in the nodeManager. Existing node: NodeId=ns=3;s=0,0/3:X, NodeClass=Variable, BrowseName=3:X; Type={NodeId=i=63, NodeClass=VariableType, BrowseName=BaseDataVariableType, IsAbstract=false, DataType=i=24, ValueRank=-2, ArrayDimensions=null, Value=(null)} DataType=NodeId=i=5, NodeClass=DataType, BrowseName=UInt16, IsAbstract=false, ValueRank=-1, MinimumSamplingInterval=0,000000, AccessLevel=[CurrentRead], UserAccessLevel=[CurrentRead, CurrentWrite], Historizing=false, Value=DataValue(value=0, statusCode= (0x00004000) "", sourceTimestamp=05/03/19 11:52:40.0370000 GMT, sourcePicoseconds=0, serverTimestamp=05/03/19 11:52:40.0370000 GMT, serverPicoseconds=0) StatusCode=Bad_UnexpectedError (0x80010000) "An unexpected error occurred." Diagnostics=Diagnostic Info:

If I call nodeManager.getNode(nodeId) immediatly after call of deleteNode() I’ll get an error “BadNodeIdUnknown”. So the node was deleted by NodeManagerUaNode.

Thomas

May 3, 2019
15:04, EEST
Avatar
Thomas Reuther
Member
Members
Forum Posts: 33
Member Since:
September 18, 2017
sp_UserOfflineSmall Offline

Sorry, I made a mistake.
Please do not investigate on this.

I was not aware of the fact that there were sub-nodes for each variable node. The structure variable node created sub-nodes for each element of the structure. The delete command accidently deletes only the parent. When I re-recreate the node, the children already exist.
To find out I needed to carefullly read the stack trace. Surprised

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 518

Currently Online:
26 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 135

pramanj: 86

Francesco Zambon: 81

rocket science: 77

Ibrahim: 76

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

fred: 41

Member Stats:

Guest Posters: 0

Members: 680

Moderators: 16

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1467

Posts: 6261

Newest Members:

sagarchau, elviralangwell4, Donnavek, Eddiefauth, DonaldPooma, fidelduke938316, Jan-Pfizer, DavidROunc, fen.pang@woodside.com, aytule

Moderators: Jouni Aro: 1010, Otso Palonen: 32, Tuomas Hiltunen: 5, Pyry: 1, Petri: 0, Bjarne Boström: 983, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 26, Teppo Uimonen: 21, Markus Johansson: 42, Niklas Nurminen: 0, Matti Siponen: 321, Lusetti: 0, Ari-Pekka Soikkeli: 5

Administrators: admin: 1