package org.opendaylight.controller.netconf.mdsal.connector.ops.get;
import com.google.common.base.Function;
+import com.google.common.base.Optional;
import com.google.common.base.Throwables;
import com.google.common.collect.Iterables;
import java.io.IOException;
}
protected static final class GetConfigExecution {
- private final Datastore datastore;
+ private final Optional<Datastore> datastore;
- public GetConfigExecution(final Datastore datastore) {
+ public GetConfigExecution(final Optional<Datastore> datastore) {
this.datastore = datastore;
}
- public Datastore getDatastore() {
+ public Optional<Datastore> getDatastore() {
return datastore;
}
throw new NetconfDocumentedException("Incorrect RPC: " + e.getMessage(), e.getErrorType(), e.getErrorTag(), e.getErrorSeverity(), e.getErrorInfo());
}
- final Datastore sourceDatastore;
+ final Optional<Datastore> sourceDatastore;
try {
sourceDatastore = parseSource(xml);
} catch (final NetconfDocumentedException e) {
return new GetConfigExecution(sourceDatastore);
}
- private static Datastore parseSource(final XmlElement xml) throws NetconfDocumentedException {
- final Datastore sourceDatastore;
- final XmlElement sourceElement = xml.getOnlyChildElement(XmlNetconfConstants.SOURCE_KEY,
+ private static Optional<Datastore> parseSource(final XmlElement xml) throws NetconfDocumentedException {
+ final Optional<XmlElement> sourceElement = xml.getOnlyChildElementOptionally(XmlNetconfConstants.SOURCE_KEY,
XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
- final String sourceParsed = sourceElement.getOnlyChildElement().getName();
- sourceDatastore = Datastore.valueOf(sourceParsed);
- return sourceDatastore;
+ return sourceElement.isPresent() ?
+ Optional.of(Datastore.valueOf(sourceElement.get().getOnlyChildElement().getName())) : Optional.<Datastore>absent();
}
private static void validateInputRpc(final XmlElement xml, String operationName) throws NetconfDocumentedException{
}
final YangInstanceIdentifier dataRoot = ROOT;
- DOMDataReadWriteTransaction rwTx = getTransaction(getConfigExecution.getDatastore());
+ DOMDataReadWriteTransaction rwTx = getTransaction(Datastore.running);
try {
final Optional<NormalizedNode<?, ?>> normalizedNodeOptional = rwTx.read(LogicalDatastoreType.OPERATIONAL, dataRoot).checkedGet();
- if (getConfigExecution.getDatastore() == Datastore.running) {
- transactionProvider.abortRunningTransaction(rwTx);
- rwTx = null;
- }
+ transactionProvider.abortRunningTransaction(rwTx);
return (Element) transformNormalizedNode(document, normalizedNodeOptional.get(), dataRoot);
} catch (ReadFailedException e) {
LOG.warn("Unable to read data: {}", dataRoot, e);
package org.opendaylight.controller.netconf.mdsal.connector.ops.get;
import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
}
final YangInstanceIdentifier dataRoot = ROOT;
- DOMDataReadWriteTransaction rwTx = getTransaction(getConfigExecution.getDatastore());
+ // Proper exception should be thrown
+ Preconditions.checkState(getConfigExecution.getDatastore().isPresent(), "Source element missing from request");
+
+ DOMDataReadWriteTransaction rwTx = getTransaction(getConfigExecution.getDatastore().get());
try {
final Optional<NormalizedNode<?, ?>> normalizedNodeOptional = rwTx.read(LogicalDatastoreType.CONFIGURATION, dataRoot).checkedGet();
- if (getConfigExecution.getDatastore() == Datastore.running) {
+ if (getConfigExecution.getDatastore().get() == Datastore.running) {
transactionProvider.abortRunningTransaction(rwTx);
rwTx = null;
}