Search in sources :

Example 16 with StatusCode

use of org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode in project milo by eclipse.

the class BrowsePathsHelper method translate.

private CompletableFuture<BrowsePathResult> translate(BrowsePath browsePath) {
    CompletableFuture<BrowsePathResult> future = new CompletableFuture<>();
    NodeId startingNode = browsePath.getStartingNode();
    RelativePath relativePath = browsePath.getRelativePath();
    if (startingNode.isNull()) {
        future.complete(new BrowsePathResult(new StatusCode(StatusCodes.Bad_NodeIdInvalid), new BrowsePathTarget[0]));
        return future;
    }
    List<RelativePathElement> relativePathElements = l(relativePath.getElements());
    if (relativePathElements.isEmpty()) {
        future.complete(new BrowsePathResult(new StatusCode(StatusCodes.Bad_NothingToDo), new BrowsePathTarget[0]));
        return future;
    }
    follow(startingNode, relativePathElements).whenComplete((targets, ex) -> {
        if (targets != null) {
            BrowsePathResult result;
            if (!targets.isEmpty()) {
                result = new BrowsePathResult(StatusCode.GOOD, a(targets, BrowsePathTarget.class));
            } else {
                result = new BrowsePathResult(new StatusCode(StatusCodes.Bad_NoMatch), new BrowsePathTarget[0]);
            }
            future.complete(result);
        } else {
            StatusCode statusCode = UaException.extractStatusCode(ex).orElse(new StatusCode(StatusCodes.Bad_NoMatch));
            BrowsePathResult result = new BrowsePathResult(statusCode, new BrowsePathTarget[0]);
            future.complete(result);
        }
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) BrowsePathResult(org.eclipse.milo.opcua.stack.core.types.structured.BrowsePathResult) RelativePath(org.eclipse.milo.opcua.stack.core.types.structured.RelativePath) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) RelativePathElement(org.eclipse.milo.opcua.stack.core.types.structured.RelativePathElement) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) BrowsePathTarget(org.eclipse.milo.opcua.stack.core.types.structured.BrowsePathTarget)

Example 17 with StatusCode

use of org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode in project milo by eclipse.

the class Subscription method returnKeepAlive.

private void returnKeepAlive(ServiceRequest service) {
    ResponseHeader header = service.createResponseHeader();
    UInteger sequenceNumber = uint(currentSequenceNumber());
    NotificationMessage notificationMessage = new NotificationMessage(sequenceNumber, DateTime.now(), new ExtensionObject[0]);
    UInteger[] available = getAvailableSequenceNumbers();
    StatusCode[] acknowledgeResults = service.attr(KEY_ACK_RESULTS).get();
    PublishResponse response = new PublishResponse(header, subscriptionId, available, moreNotifications, notificationMessage, acknowledgeResults, new DiagnosticInfo[0]);
    service.setResponse(response);
    logger.debug("[id={}] returned keep-alive NotificationMessage sequenceNumber={}.", subscriptionId, sequenceNumber);
}
Also used : PublishResponse(org.eclipse.milo.opcua.stack.core.types.structured.PublishResponse) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) NotificationMessage(org.eclipse.milo.opcua.stack.core.types.structured.NotificationMessage) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)

Example 18 with StatusCode

use of org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode in project milo by eclipse.

the class ManagedAddressSpace method write.

@Override
public void write(WriteContext context, List<WriteValue> writeValues) {
    List<StatusCode> results = Lists.newArrayListWithCapacity(writeValues.size());
    for (WriteValue writeValue : writeValues) {
        UaServerNode node = nodeManager.get(writeValue.getNodeId());
        if (node != null) {
            try {
                node.writeAttribute(new AttributeContext(context), writeValue.getAttributeId(), writeValue.getValue(), writeValue.getIndexRange());
                results.add(StatusCode.GOOD);
                logger.debug("Wrote value {} to {} attribute of {}", writeValue.getValue().getValue(), AttributeId.from(writeValue.getAttributeId()).map(Object::toString).orElse("unknown"), node.getNodeId());
            } catch (UaException e) {
                logger.error("Unable to write value={}", writeValue.getValue(), e);
                results.add(e.getStatusCode());
            }
        } else {
            results.add(new StatusCode(StatusCodes.Bad_NodeIdUnknown));
        }
    }
    context.success(results);
}
Also used : WriteValue(org.eclipse.milo.opcua.stack.core.types.structured.WriteValue) AttributeContext(org.eclipse.milo.opcua.sdk.server.nodes.AttributeContext) UaException(org.eclipse.milo.opcua.stack.core.UaException) UaServerNode(org.eclipse.milo.opcua.sdk.server.nodes.UaServerNode) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)

Example 19 with StatusCode

use of org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode in project milo by eclipse.

the class EventContentFilter method validateFilterElement.

private static ContentFilterElementResult validateFilterElement(@NotNull FilterContext context, @NotNull ContentFilterElement filterElement) {
    FilterOperator filterOperator = filterElement.getFilterOperator();
    if (!Operators.SUPPORTED_OPERATORS.contains(filterOperator)) {
        return new ContentFilterElementResult(new StatusCode(StatusCodes.Bad_FilterOperatorUnsupported), new StatusCode[0], new DiagnosticInfo[0]);
    }
    ExtensionObject[] xos = filterElement.getFilterOperands();
    if (xos == null || xos.length == 0) {
        return new ContentFilterElementResult(new StatusCode(StatusCodes.Bad_FilterOperandCountMismatch), new StatusCode[0], new DiagnosticInfo[0]);
    }
    FilterOperand[] operands = new FilterOperand[xos.length];
    StatusCode[] operandStatusCodes = new StatusCode[xos.length];
    for (int i = 0; i < xos.length; i++) {
        Object operand = xos[i].decodeOrNull(context.getServer().getSerializationContext());
        if (operand instanceof FilterOperand) {
            operands[i] = (FilterOperand) operand;
            if (operand instanceof SimpleAttributeOperand) {
                try {
                    validateSimpleOperand(context, (SimpleAttributeOperand) operand);
                    operandStatusCodes[i] = StatusCode.GOOD;
                } catch (ValidationException e) {
                    operandStatusCodes[i] = e.getStatusCode();
                }
            } else if (operand instanceof ElementOperand) {
                operandStatusCodes[i] = StatusCode.GOOD;
            } else if (operand instanceof LiteralOperand) {
                operandStatusCodes[i] = StatusCode.GOOD;
            } else {
                // includes AttributeOperand and any unknown/unhandle subclasses
                operandStatusCodes[i] = new StatusCode(StatusCodes.Bad_FilterOperandInvalid);
            }
        } else {
            operandStatusCodes[i] = new StatusCode(StatusCodes.Bad_FilterOperandInvalid);
        }
    }
    StatusCode operatorStatus = StatusCode.GOOD;
    try {
        Operator<?> operator = getOperator(filterOperator);
        operator.validate(context, operands);
    } catch (ValidationException e) {
        operatorStatus = e.getStatusCode();
    }
    return new ContentFilterElementResult(operatorStatus, operandStatusCodes, new DiagnosticInfo[0]);
}
Also used : LiteralOperand(org.eclipse.milo.opcua.stack.core.types.structured.LiteralOperand) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) ElementOperand(org.eclipse.milo.opcua.stack.core.types.structured.ElementOperand) FilterOperator(org.eclipse.milo.opcua.stack.core.types.enumerated.FilterOperator) SimpleAttributeOperand(org.eclipse.milo.opcua.stack.core.types.structured.SimpleAttributeOperand) FilterOperand(org.eclipse.milo.opcua.stack.core.types.structured.FilterOperand) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) ContentFilterElementResult(org.eclipse.milo.opcua.stack.core.types.structured.ContentFilterElementResult)

Example 20 with StatusCode

use of org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode in project milo by eclipse.

the class NodeManagementServices method addNodes.

default void addNodes(AddNodesContext context, List<AddNodesItem> nodesToAdd) {
    AddNodesResult result = new AddNodesResult(new StatusCode(StatusCodes.Bad_NotSupported), NodeId.NULL_VALUE);
    context.success(Collections.nCopies(nodesToAdd.size(), result));
}
Also used : AddNodesResult(org.eclipse.milo.opcua.stack.core.types.structured.AddNodesResult) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)

Aggregations

StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)130 UaException (org.eclipse.milo.opcua.stack.core.UaException)88 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)78 Variant (org.eclipse.milo.opcua.stack.core.types.builtin.Variant)41 UInteger (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger)36 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)21 Unsigned.uint (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint)19 List (java.util.List)15 LocalizedText (org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText)15 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)15 NodeClass (org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass)12 CompletableFuture (java.util.concurrent.CompletableFuture)11 OpcUaClient (org.eclipse.milo.opcua.sdk.client.OpcUaClient)10 StatusCodes (org.eclipse.milo.opcua.stack.core.StatusCodes)10 ByteString (org.eclipse.milo.opcua.stack.core.types.builtin.ByteString)10 UByte (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UByte)10 ArrayList (java.util.ArrayList)9 ResponseHeader (org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader)9 ExecutionException (java.util.concurrent.ExecutionException)8 ExpandedNodeId (org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId)8