use of org.eclipse.milo.opcua.sdk.server.OpcUaServer in project milo by eclipse.
the class AttributeWriterTest method testWriteConversion.
private void testWriteConversion(DataValue value, NodeId dataType, Consumer<UaVariableNode> nodeCustomizer) throws UaException {
final UaVariableNode varNode = createMockNode("test", node -> {
UByte accessLevel = AccessLevel.toValue(AccessLevel.READ_WRITE);
node.setAccessLevel(accessLevel);
node.setUserAccessLevel(accessLevel);
if (nodeCustomizer != null) {
nodeCustomizer.accept(node);
}
});
if (dataType != null) {
varNode.setDataType(dataType);
}
OpcUaServer server = Mockito.mock(OpcUaServer.class);
AttributeWriter.writeAttribute(new AttributeContext(server, null), varNode, AttributeId.Value, value, null);
}
use of org.eclipse.milo.opcua.sdk.server.OpcUaServer in project milo by eclipse.
the class DefaultMethodServiceSet method onCall.
@Override
public void onCall(ServiceRequest service) {
callCounter.record(service);
OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
CallRequest request = (CallRequest) service.getRequest();
List<CallMethodRequest> methodsToCall = l(request.getMethodsToCall());
if (methodsToCall.isEmpty()) {
service.setServiceFault(StatusCodes.Bad_NothingToDo);
return;
}
if (methodsToCall.size() > server.getConfig().getLimits().getMaxNodesPerMethodCall().longValue()) {
service.setServiceFault(StatusCodes.Bad_TooManyOperations);
return;
}
DiagnosticsContext<CallMethodRequest> diagnosticsContext = new DiagnosticsContext<>();
CallContext context = new CallContext(server, session, diagnosticsContext);
server.getAddressSpaceManager().call(context, methodsToCall);
context.getFuture().thenAccept(values -> {
ResponseHeader header = service.createResponseHeader();
CallResponse response = new CallResponse(header, a(values, CallMethodResult.class), new DiagnosticInfo[0]);
service.setResponse(response);
});
}
use of org.eclipse.milo.opcua.sdk.server.OpcUaServer in project milo by eclipse.
the class DefaultNodeManagementServiceSet method onAddNodes.
@Override
public void onAddNodes(ServiceRequest service) {
OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
AddNodesRequest request = (AddNodesRequest) service.getRequest();
List<AddNodesItem> nodesToAdd = l(request.getNodesToAdd());
if (nodesToAdd.isEmpty()) {
service.setServiceFault(StatusCodes.Bad_NothingToDo);
return;
}
if (nodesToAdd.size() > server.getConfig().getLimits().getMaxNodesPerNodeManagement().longValue()) {
service.setServiceFault(StatusCodes.Bad_TooManyOperations);
return;
}
AddNodesContext context = new AddNodesContext(server, session, new DiagnosticsContext<>());
server.getAddressSpaceManager().addNodes(context, nodesToAdd);
context.getFuture().thenAccept(results -> {
ResponseHeader header = service.createResponseHeader();
AddNodesResponse response = new AddNodesResponse(header, a(results, AddNodesResult.class), new DiagnosticInfo[0]);
service.setResponse(response);
});
}
use of org.eclipse.milo.opcua.sdk.server.OpcUaServer in project milo by eclipse.
the class DefaultNodeManagementServiceSet method onDeleteNodes.
@Override
public void onDeleteNodes(ServiceRequest service) {
OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
DeleteNodesRequest request = (DeleteNodesRequest) service.getRequest();
List<DeleteNodesItem> nodesToDelete = l(request.getNodesToDelete());
if (nodesToDelete.isEmpty()) {
service.setServiceFault(StatusCodes.Bad_NothingToDo);
return;
}
if (nodesToDelete.size() > server.getConfig().getLimits().getMaxNodesPerNodeManagement().longValue()) {
service.setServiceFault(StatusCodes.Bad_TooManyOperations);
return;
}
DeleteNodesContext context = new DeleteNodesContext(server, session, new DiagnosticsContext<>());
server.getAddressSpaceManager().deleteNodes(context, nodesToDelete);
context.getFuture().thenAccept(results -> {
ResponseHeader header = service.createResponseHeader();
DeleteNodesResponse response = new DeleteNodesResponse(header, a(results, StatusCode.class), new DiagnosticInfo[0]);
service.setResponse(response);
});
}
use of org.eclipse.milo.opcua.sdk.server.OpcUaServer in project milo by eclipse.
the class DefaultViewServiceSet method onUnregisterNodes.
@Override
public void onUnregisterNodes(ServiceRequest service) throws UaException {
OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
UnregisterNodesRequest request = (UnregisterNodesRequest) service.getRequest();
List<NodeId> nodeIds = l(request.getNodesToUnregister());
if (nodeIds.isEmpty()) {
throw new UaException(StatusCodes.Bad_NothingToDo);
}
if (nodeIds.size() > server.getConfig().getLimits().getMaxNodesPerRegisterNodes().intValue()) {
throw new UaException(StatusCodes.Bad_TooManyOperations);
}
UnregisterNodesContext context = new UnregisterNodesContext(server, session);
server.getAddressSpaceManager().unregisterNodes(context, nodeIds);
context.getFuture().thenAccept(registeredNodeIds -> {
ResponseHeader header = service.createResponseHeader();
UnregisterNodesResponse response = new UnregisterNodesResponse(header);
service.setResponse(response);
});
}
Aggregations