Search in sources :

Example 11 with StatusCode

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

the class UaDataTypeNode method readIsAbstract.

/**
 * Read the IsAbstract attribute for this Node from the server and update the local
 * attribute if the operation succeeds.
 *
 * @return the {@link Boolean} read from the server.
 * @throws UaException if a service- or operation-level error occurs.s
 */
public Boolean readIsAbstract() throws UaException {
    DataValue value = readAttribute(AttributeId.IsAbstract);
    StatusCode statusCode = value.getStatusCode();
    if (statusCode != null && statusCode.isBad()) {
        throw new UaException(statusCode, "read IsAbstract failed");
    } else {
        Boolean isAbstract = (Boolean) value.getValue().getValue();
        setIsAbstract(isAbstract);
        return isAbstract;
    }
}
Also used : DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) UaException(org.eclipse.milo.opcua.stack.core.UaException) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)

Example 12 with StatusCode

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

the class UaMethodNode method writeUserExecutable.

/**
 * Write a new UserExecutable attribute for this Node to the server and update the local
 * attribute if the operation succeeds.
 *
 * @param userExecutable the {@link Boolean} to write to the server.
 * @throws UaException if a service- or operation-level error occurs.
 */
public void writeUserExecutable(Boolean userExecutable) throws UaException {
    DataValue value = DataValue.valueOnly(new Variant(userExecutable));
    StatusCode statusCode = writeAttribute(AttributeId.UserExecutable, value);
    if (statusCode != null && statusCode.isBad()) {
        throw new UaException(statusCode, "write UserExecutable failed");
    } else {
        setUserExecutable(userExecutable);
    }
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) UaException(org.eclipse.milo.opcua.stack.core.UaException) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)

Example 13 with StatusCode

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

the class SubscriptionManager method publish.

public void publish(ServiceRequest service) {
    PublishRequest request = (PublishRequest) service.getRequest();
    SubscriptionAcknowledgement[] acknowledgements = request.getSubscriptionAcknowledgements();
    if (acknowledgements != null) {
        StatusCode[] results = new StatusCode[acknowledgements.length];
        for (int i = 0; i < acknowledgements.length; i++) {
            SubscriptionAcknowledgement acknowledgement = acknowledgements[i];
            UInteger sequenceNumber = acknowledgement.getSequenceNumber();
            UInteger subscriptionId = acknowledgement.getSubscriptionId();
            Subscription subscription = subscriptions.get(subscriptionId);
            if (subscription == null) {
                logger.debug("Can't acknowledge sequenceNumber={} on subscriptionId={}; id not valid for this session", sequenceNumber, subscriptionId);
                results[i] = new StatusCode(StatusCodes.Bad_SubscriptionIdInvalid);
            } else {
                logger.debug("Acknowledging sequenceNumber={} on subscriptionId={}", sequenceNumber, subscriptionId);
                results[i] = subscription.acknowledge(sequenceNumber);
            }
        }
        service.attr(KEY_ACK_RESULTS).set(results);
    }
    if (!transferred.isEmpty()) {
        Subscription subscription = transferred.remove(0);
        subscription.returnStatusChangeNotification(service, new StatusCode(StatusCodes.Good_SubscriptionTransferred));
        return;
    }
    if (subscriptions.isEmpty()) {
        service.setServiceFault(StatusCodes.Bad_NoSubscription);
        return;
    }
    publishQueue.addRequest(service);
}
Also used : SubscriptionAcknowledgement(org.eclipse.milo.opcua.stack.core.types.structured.SubscriptionAcknowledgement) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) PublishRequest(org.eclipse.milo.opcua.stack.core.types.structured.PublishRequest) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint)

Example 14 with StatusCode

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

the class DefaultSubscriptionServiceSet method onTransferSubscriptions.

@Override
public void onTransferSubscriptions(ServiceRequest service) throws UaException {
    TransferSubscriptionsRequest request = (TransferSubscriptionsRequest) service.getRequest();
    OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
    Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
    List<UInteger> subscriptionIds = l(request.getSubscriptionIds());
    if (subscriptionIds.isEmpty()) {
        throw new UaException(StatusCodes.Bad_NothingToDo);
    }
    List<TransferResult> results = Lists.newArrayList();
    for (UInteger subscriptionId : subscriptionIds) {
        Subscription subscription = server.getSubscriptions().get(subscriptionId);
        if (subscription == null) {
            results.add(new TransferResult(new StatusCode(StatusCodes.Bad_SubscriptionIdInvalid), new UInteger[0]));
        } else {
            Session otherSession = subscription.getSession();
            if (!sessionsHaveSameUser(session, otherSession)) {
                results.add(new TransferResult(new StatusCode(StatusCodes.Bad_UserAccessDenied), new UInteger[0]));
            } else {
                UInteger[] availableSequenceNumbers;
                synchronized (subscription) {
                    otherSession.getSubscriptionManager().sendStatusChangeNotification(subscription, new StatusCode(StatusCodes.Good_SubscriptionTransferred));
                    otherSession.getSubscriptionManager().removeSubscription(subscriptionId);
                    subscription.setSubscriptionManager(session.getSubscriptionManager());
                    subscriptionManager.addSubscription(subscription);
                    subscription.getMonitoredItems().values().forEach(item -> item.setSession(session));
                    availableSequenceNumbers = subscription.getAvailableSequenceNumbers();
                    if (request.getSendInitialValues()) {
                        subscription.getMonitoredItems().values().stream().filter(item -> item instanceof MonitoredDataItem).map(item -> (MonitoredDataItem) item).forEach(MonitoredDataItem::maybeSendLastValue);
                    }
                }
                subscription.getSubscriptionDiagnostics().getTransferRequestCount().increment();
                ApplicationDescription toClient = session.getClientDescription();
                ApplicationDescription fromClient = otherSession.getClientDescription();
                if (Objects.equals(toClient, fromClient)) {
                    subscription.getSubscriptionDiagnostics().getTransferredToSameClientCount().increment();
                } else {
                    subscription.getSubscriptionDiagnostics().getTransferredToAltClientCount().increment();
                }
                results.add(new TransferResult(StatusCode.GOOD, availableSequenceNumbers));
            }
        }
    }
    TransferSubscriptionsResponse response = new TransferSubscriptionsResponse(service.createResponseHeader(), a(results, TransferResult.class), new DiagnosticInfo[0]);
    service.setResponse(response);
}
Also used : StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) MonitoredDataItem(org.eclipse.milo.opcua.sdk.server.items.MonitoredDataItem) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) Subscription(org.eclipse.milo.opcua.sdk.server.subscriptions.Subscription) TransferResult(org.eclipse.milo.opcua.stack.core.types.structured.TransferResult) TransferSubscriptionsResponse(org.eclipse.milo.opcua.stack.core.types.structured.TransferSubscriptionsResponse) Session(org.eclipse.milo.opcua.sdk.server.Session) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) ConversionUtil.a(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.a) Objects(java.util.Objects) DiagnosticInfo(org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo) List(java.util.List) Lists(com.google.common.collect.Lists) ServiceRequest(org.eclipse.milo.opcua.stack.server.services.ServiceRequest) ConversionUtil.l(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.l) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) ApplicationDescription(org.eclipse.milo.opcua.stack.core.types.structured.ApplicationDescription) UaException(org.eclipse.milo.opcua.stack.core.UaException) SubscriptionManager(org.eclipse.milo.opcua.sdk.server.subscriptions.SubscriptionManager) SubscriptionServiceSet(org.eclipse.milo.opcua.stack.server.services.SubscriptionServiceSet) TransferSubscriptionsRequest(org.eclipse.milo.opcua.stack.core.types.structured.TransferSubscriptionsRequest) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) TransferSubscriptionsRequest(org.eclipse.milo.opcua.stack.core.types.structured.TransferSubscriptionsRequest) UaException(org.eclipse.milo.opcua.stack.core.UaException) TransferResult(org.eclipse.milo.opcua.stack.core.types.structured.TransferResult) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) ApplicationDescription(org.eclipse.milo.opcua.stack.core.types.structured.ApplicationDescription) MonitoredDataItem(org.eclipse.milo.opcua.sdk.server.items.MonitoredDataItem) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) TransferSubscriptionsResponse(org.eclipse.milo.opcua.stack.core.types.structured.TransferSubscriptionsResponse) Subscription(org.eclipse.milo.opcua.sdk.server.subscriptions.Subscription) Session(org.eclipse.milo.opcua.sdk.server.Session)

Example 15 with StatusCode

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

the class DefaultAttributeServiceSet method onWrite.

@Override
public void onWrite(ServiceRequest service) {
    WriteRequest request = (WriteRequest) service.getRequest();
    OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
    Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
    List<WriteValue> nodesToWrite = l(request.getNodesToWrite());
    if (nodesToWrite.isEmpty()) {
        service.setServiceFault(StatusCodes.Bad_NothingToDo);
        return;
    }
    if (nodesToWrite.size() > server.getConfig().getLimits().getMaxNodesPerWrite().intValue()) {
        service.setServiceFault(StatusCodes.Bad_TooManyOperations);
        return;
    }
    DiagnosticsContext<WriteValue> diagnosticsContext = new DiagnosticsContext<>();
    WriteContext context = new WriteContext(server, session, new DiagnosticsContext<>());
    server.getAddressSpaceManager().write(context, nodesToWrite);
    context.getFuture().thenAccept(values -> {
        ResponseHeader header = service.createResponseHeader();
        DiagnosticInfo[] diagnosticInfos = diagnosticsContext.getDiagnosticInfos(nodesToWrite);
        WriteResponse response = new WriteResponse(header, values.toArray(new StatusCode[0]), diagnosticInfos);
        service.setResponse(response);
    });
}
Also used : OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) WriteRequest(org.eclipse.milo.opcua.stack.core.types.structured.WriteRequest) DiagnosticInfo(org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo) WriteResponse(org.eclipse.milo.opcua.stack.core.types.structured.WriteResponse) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) WriteContext(org.eclipse.milo.opcua.sdk.server.api.services.AttributeServices.WriteContext) WriteValue(org.eclipse.milo.opcua.stack.core.types.structured.WriteValue) DiagnosticsContext(org.eclipse.milo.opcua.sdk.server.DiagnosticsContext) Session(org.eclipse.milo.opcua.sdk.server.Session)

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