Search in sources :

Example 1 with Response

use of io.lighty.netconf.device.response.Response in project lighty-netconf-simulator by PANTHEONtech.

the class ResetActionProcessor method execute.

@SuppressWarnings({ "rawtypes", "unchecked", "checkstyle:IllegalCatch" })
@Override
protected CompletableFuture<Response> execute(final Element requestXmlElement, final ActionDefinition paramActionDefinition) {
    this.actionDefinition = paramActionDefinition;
    final XmlNodeConverter xmlNodeConverter = getNetconfDeviceServices().getXmlNodeConverter();
    try {
        final XmlElement xmlElement = XmlElement.fromDomElement(requestXmlElement);
        final Element actionElement = findInputElement(xmlElement, this.actionDefinition.getQName());
        final Reader readerFromElement = RPCUtil.createReaderFromElement(actionElement);
        final ContainerNode deserializedNode = (ContainerNode) xmlNodeConverter.deserialize(this.actionDefinition.getInput(), readerFromElement);
        final Input input = this.adapterSerializer.fromNormalizedNodeActionInput(Reset.class, deserializedNode);
        final String key = findNameElement(xmlElement);
        Preconditions.checkNotNull(key);
        final Class listItem = Server.class;
        final Identifier listKey = new ServerKey(key);
        final KeyedInstanceIdentifier<Server, ServerKey> keydIID = (KeyedInstanceIdentifier<Server, ServerKey>) InstanceIdentifier.create(Collections.singletonList(IdentifiableItem.of(listItem, listKey)));
        final ListenableFuture<RpcResult<Output>> outputFuture = this.resetAction.invoke(keydIID, input);
        final CompletableFuture<Response> completableFuture = new CompletableFuture<>();
        Futures.addCallback(outputFuture, new FutureCallback<RpcResult<Output>>() {

            @Override
            public void onSuccess(final RpcResult<Output> result) {
                final NormalizedNode domOutput = ResetActionProcessor.this.adapterSerializer.toNormalizedNodeActionOutput(Reset.class, result.getResult());
                final List<NormalizedNode> list = new ArrayList<>();
                list.add(domOutput);
                completableFuture.complete(new ResponseData(list));
            }

            @Override
            public void onFailure(final Throwable throwable) {
            }
        }, Executors.newSingleThreadExecutor());
        return completableFuture;
    } catch (final TransformerException | DocumentedException | DeserializationException e) {
        throw new RuntimeException(e);
    }
}
Also used : Server(org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.Server) XmlElement(org.opendaylight.netconf.api.xml.XmlElement) Element(org.w3c.dom.Element) Reader(java.io.Reader) DeserializationException(io.lighty.codecs.util.exception.DeserializationException) ServerKey(org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.ServerKey) Input(org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.server.reset.Input) CompletableFuture(java.util.concurrent.CompletableFuture) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) Identifier(org.opendaylight.yangtools.yang.binding.Identifier) DocumentedException(org.opendaylight.netconf.api.DocumentedException) Output(org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.server.reset.Output) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Reset(org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.server.Reset) TransformerException(javax.xml.transform.TransformerException) ResponseData(io.lighty.netconf.device.response.ResponseData) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Response(io.lighty.netconf.device.response.Response) XmlElement(org.opendaylight.netconf.api.xml.XmlElement) XmlNodeConverter(io.lighty.codecs.util.XmlNodeConverter) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier)

Example 2 with Response

use of io.lighty.netconf.device.response.Response in project lighty-netconf-simulator by PANTHEONtech.

the class StartActionProcessor method execute.

@SuppressWarnings("checkstyle:IllegalCatch")
@Override
protected CompletableFuture<Response> execute(final Element requestXmlElement, final ActionDefinition paramActionDefinition) {
    this.actionDefinition = paramActionDefinition;
    final XmlNodeConverter xmlNodeConverter = getNetconfDeviceServices().getXmlNodeConverter();
    try {
        final XmlElement xmlElement = XmlElement.fromDomElement(requestXmlElement);
        final Element actionElement = findInputElement(xmlElement, this.actionDefinition.getQName());
        final Reader readerFromElement = RPCUtil.createReaderFromElement(actionElement);
        final ContainerNode deserializedNode = (ContainerNode) xmlNodeConverter.deserialize(this.actionDefinition.getInput(), readerFromElement);
        final Input input = this.adapterSerializer.fromNormalizedNodeActionInput(Start.class, deserializedNode);
        final ListenableFuture<RpcResult<Output>> outputFuture = this.startAction.invoke(InstanceIdentifier.create(Device.class), input);
        final CompletableFuture<Response> completableFuture = new CompletableFuture<>();
        Futures.addCallback(outputFuture, new FutureCallback<RpcResult<Output>>() {

            @Override
            public void onSuccess(final RpcResult<Output> result) {
                final NormalizedNode domOutput = StartActionProcessor.this.adapterSerializer.toNormalizedNodeActionOutput(Start.class, result.getResult());
                final List<NormalizedNode> list = new ArrayList<>();
                list.add(domOutput);
                completableFuture.complete(new ResponseData(list));
            }

            @Override
            public void onFailure(final Throwable throwable) {
            }
        }, Executors.newSingleThreadExecutor());
        return completableFuture;
    } catch (final TransformerException | DocumentedException | DeserializationException e) {
        throw new RuntimeException(e);
    }
}
Also used : Start(org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.device.Start) XmlElement(org.opendaylight.netconf.api.xml.XmlElement) Element(org.w3c.dom.Element) Reader(java.io.Reader) DeserializationException(io.lighty.codecs.util.exception.DeserializationException) Input(org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.device.start.Input) CompletableFuture(java.util.concurrent.CompletableFuture) DocumentedException(org.opendaylight.netconf.api.DocumentedException) Output(org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.device.start.Output) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) ArrayList(java.util.ArrayList) List(java.util.List) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) TransformerException(javax.xml.transform.TransformerException) Device(org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.Device) ResponseData(io.lighty.netconf.device.response.ResponseData) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Response(io.lighty.netconf.device.response.Response) XmlElement(org.opendaylight.netconf.api.xml.XmlElement) XmlNodeConverter(io.lighty.codecs.util.XmlNodeConverter)

Example 3 with Response

use of io.lighty.netconf.device.response.Response in project lighty-netconf-simulator by PANTHEONtech.

the class BaseRequestProcessor method processResponse.

private Document processResponse(final CompletableFuture<Response> responseOutput) throws ExecutionException, InterruptedException, ParserConfigurationException, TimeoutException {
    final Response listResponse = responseOutput.get(TimeoutUtil.TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
    final Document error = listResponse.getErrorDocument();
    if (error != null) {
        return error;
    } else {
        return wrapToFinalDocumentReply(listResponse.getData());
    }
}
Also used : Response(io.lighty.netconf.device.response.Response) Document(org.w3c.dom.Document)

Example 4 with Response

use of io.lighty.netconf.device.response.Response in project lighty-netconf-simulator by PANTHEONtech.

the class CreateSubscriptionRequestProcessor method execute.

@Override
protected CompletableFuture<Response> execute(Element requestXmlElement) {
    messageId = requestXmlElement.getAttribute("message-id");
    final CompletableFuture<Response> responseFuture = new CompletableFuture<>();
    responseFuture.complete(new ResponseData(Collections.emptyList()));
    return responseFuture;
}
Also used : Response(io.lighty.netconf.device.response.Response) CompletableFuture(java.util.concurrent.CompletableFuture) ResponseData(io.lighty.netconf.device.response.ResponseData)

Example 5 with Response

use of io.lighty.netconf.device.response.Response in project lighty-netconf-simulator by PANTHEONtech.

the class GetConfigRequestProcessor method execute.

@Override
public CompletableFuture<Response> execute(Element requestXml) {
    final CompletableFuture<Response> responseFuture = new CompletableFuture<>();
    final List<NormalizedNode> allDataFromDatastore = getAllDataFromDatastore(LogicalDatastoreType.CONFIGURATION);
    responseFuture.complete(new ResponseData(allDataFromDatastore));
    return responseFuture;
}
Also used : Response(io.lighty.netconf.device.response.Response) CompletableFuture(java.util.concurrent.CompletableFuture) ResponseData(io.lighty.netconf.device.response.ResponseData) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)

Aggregations

Response (io.lighty.netconf.device.response.Response)10 ResponseData (io.lighty.netconf.device.response.ResponseData)9 CompletableFuture (java.util.concurrent.CompletableFuture)9 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)7 DeserializationException (io.lighty.codecs.util.exception.DeserializationException)5 Element (org.w3c.dom.Element)5 XmlNodeConverter (io.lighty.codecs.util.XmlNodeConverter)4 Reader (java.io.Reader)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 TransformerException (javax.xml.transform.TransformerException)4 DocumentedException (org.opendaylight.netconf.api.DocumentedException)4 XmlElement (org.opendaylight.netconf.api.xml.XmlElement)4 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)4 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)4 Device (org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.Device)2 Server (org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.Server)2 ServerKey (org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.ServerKey)2 Start (org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.device.Start)2 Input (org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.device.start.Input)2