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);
}
}
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);
}
}
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());
}
}
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;
}
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;
}
Aggregations