use of io.lighty.netconf.device.response.ResponseData 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);
}
}
use of io.lighty.netconf.device.response.ResponseData 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);
}
}
use of io.lighty.netconf.device.response.ResponseData in project lighty-netconf-simulator by PANTHEONtech.
the class NetworkTopologyServiceAbstractProcessor method execute.
@Override
protected CompletableFuture<Response> execute(final Element requestXmlElement) {
try (Reader readerFromElement = RPCUtil.createReaderFromElement(requestXmlElement)) {
final XmlNodeConverter xmlNodeConverter = getNetconfDeviceServices().getXmlNodeConverter();
// 1. convert XML input into NormalizedNode
final NormalizedNode deserializedNode = xmlNodeConverter.deserialize(Absolute.of(getRpcDefinition().getQName(), getRpcDefinition().getInput().getQName()), readerFromElement);
// 2. convert NormalizedNode into RPC input
final T input = convertToBindingAwareRpc(getRpcDefInputAbsolutePath(), (ContainerNode) deserializedNode);
// 3. invoke RPC
final RpcResult<O> rpcResult = execMethod(input);
final DataContainer result = rpcResult.getResult();
// 4. convert RPC output to ContainerNode
final ContainerNode containerNode = this.adapterSerializer.toNormalizedNodeRpcData(result);
// 5. create response
final ResponseData responseData;
if (containerNode.body().isEmpty()) {
responseData = new ResponseData(Collections.emptyList());
} else {
responseData = new ResponseData(Collections.singletonList(containerNode));
}
return CompletableFuture.completedFuture(responseData);
} catch (final ExecutionException | DeserializationException | TransformerException | TimeoutException | IOException e) {
LOG.error("Error while executing RPC", e);
return CompletableFuture.failedFuture(e);
} catch (final InterruptedException e) {
LOG.error("Interrupted while executing RPC", e);
Thread.currentThread().interrupt();
return CompletableFuture.failedFuture(e);
}
}
use of io.lighty.netconf.device.response.ResponseData in project lighty-netconf-simulator by PANTHEONtech.
the class ToasterServiceAbstractProcessor method execute.
@Override
protected CompletableFuture<Response> execute(final Element requestXmlElement) {
// 1. convert XML input into NormalizedNode
try (Reader readerFromElement = RPCUtil.createReaderFromElement(requestXmlElement)) {
final XmlNodeConverter xmlNodeConverter = getNetconfDeviceServices().getXmlNodeConverter();
final NormalizedNode deserializedNode = xmlNodeConverter.deserialize(Absolute.of(getRpcDefinition().getQName(), getRpcDefinition().getInput().getQName()), readerFromElement);
// 2. convert NormalizedNode into RPC input
final I input = convertToBindingAwareRpc(getRpcDefInputAbsolutePath(), (ContainerNode) deserializedNode);
// 3. invoke RPC and wait for completion
final Future<RpcResult<O>> invokeRpc = execMethod(input);
final RpcResult<O> rpcResult = invokeRpc.get(TimeoutUtil.TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
// 4. convert RPC output to ContainerNode
final ContainerNode data = this.adapterSerializer.toNormalizedNodeRpcData(rpcResult.getResult());
// 5. create response
return CompletableFuture.completedFuture(new ResponseData(Collections.singletonList(data)));
} catch (final ExecutionException | DeserializationException | TransformerException | TimeoutException | IOException e) {
LOG.error("Error while executing RPC", e);
return CompletableFuture.failedFuture(e);
} catch (final InterruptedException e) {
LOG.error("Interrupted while executing RPC", e);
Thread.currentThread().interrupt();
return CompletableFuture.failedFuture(e);
}
}
use of io.lighty.netconf.device.response.ResponseData 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;
}
Aggregations