X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fimpl%2Fosgi%2FNetconfOperationRouterImpl.java;h=ff96ad779fbc974539ced455494129381bb09635;hp=a35851445381f8bdcfd3142d036b9c3c34280d13;hb=e159106bc148e76fc1e3e3c780bdd740d99e74ed;hpb=12204729ecaa1d1862a580cc6282eceacd21efe2 diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationRouterImpl.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationRouterImpl.java index a358514453..ff96ad779f 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationRouterImpl.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationRouterImpl.java @@ -11,20 +11,20 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Maps; import com.google.common.collect.Sets; import org.opendaylight.controller.netconf.api.NetconfDocumentedException; -import org.opendaylight.controller.netconf.api.NetconfOperationRouter; -import org.opendaylight.controller.netconf.api.NetconfSession; import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer; +import org.opendaylight.controller.netconf.impl.NetconfServerSession; import org.opendaylight.controller.netconf.impl.mapping.CapabilityProvider; import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultCloseSession; import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultCommit; import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultGetSchema; +import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultNetconfOperation; import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultStartExi; import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultStopExi; -import org.opendaylight.controller.netconf.mapping.api.DefaultNetconfOperation; import org.opendaylight.controller.netconf.mapping.api.HandlingPriority; import org.opendaylight.controller.netconf.mapping.api.NetconfOperation; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceSnapshot; import org.opendaylight.controller.netconf.util.xml.XmlUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,6 +33,7 @@ import org.w3c.dom.Document; import java.util.Collections; import java.util.HashSet; import java.util.Map; +import java.util.NavigableMap; import java.util.Set; import java.util.TreeMap; @@ -83,7 +84,7 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { for (NetconfOperationService netconfOperationService : netconfOperationServiceSnapshot.getServices()) { final Set netOpsFromService = netconfOperationService.getNetconfOperations(); for (NetconfOperation netconfOperation : netOpsFromService) { - Preconditions.checkState(result.contains(netconfOperation) == false, + Preconditions.checkState(!result.contains(netconfOperation), "Netconf operation %s already present", netconfOperation); result.add(netconfOperation); } @@ -93,13 +94,14 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { @Override public synchronized Document onNetconfMessage(Document message, - NetconfSession session) throws NetconfDocumentedException { + NetconfServerSession session) throws NetconfDocumentedException { Preconditions.checkNotNull(allNetconfOperations, "Operation router was not initialized properly"); NetconfOperationExecution netconfOperationExecution; - String messageAsString = XmlUtil.toString(message); + String messageAsString = ""; try { + messageAsString = XmlUtil.toString(message); netconfOperationExecution = getNetconfOperationWithHighestPriority(message, session); } catch (IllegalArgumentException | IllegalStateException e) { logger.warn("Unable to handle rpc {} on session {}", messageAsString, session, e); @@ -107,11 +109,11 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { String errorMessage = String.format("Unable to handle rpc %s on session %s", messageAsString, session); Map errorInfo = Maps.newHashMap(); - NetconfDocumentedException.ErrorTag tag = null; + NetconfDocumentedException.ErrorTag tag; if (e instanceof IllegalArgumentException) { errorInfo.put(NetconfDocumentedException.ErrorTag.operation_not_supported.toString(), e.getMessage()); tag = NetconfDocumentedException.ErrorTag.operation_not_supported; - } else if (e instanceof IllegalStateException) { + } else { errorInfo.put(NetconfDocumentedException.ErrorTag.operation_failed.toString(), e.getMessage()); tag = NetconfDocumentedException.ErrorTag.operation_failed; } @@ -130,7 +132,7 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { } @Override - public void close() { + public void close() throws Exception { netconfOperationServiceSnapshot.close(); } @@ -153,20 +155,20 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { } private NetconfOperationExecution getNetconfOperationWithHighestPriority( - Document message, NetconfSession session) { + Document message, NetconfServerSession session) throws NetconfDocumentedException { - TreeMap sortedByPriority = getSortedNetconfOperationsWithCanHandle( + NavigableMap sortedByPriority = getSortedNetconfOperationsWithCanHandle( message, session); Preconditions.checkArgument(sortedByPriority.isEmpty() == false, - "No %s available to handleWithNoSubsequentOperations message %s", NetconfOperation.class.getName(), + "No %s available to handle message %s", NetconfOperation.class.getName(), XmlUtil.toString(message)); return NetconfOperationExecution.createExecutionChain(sortedByPriority, sortedByPriority.lastKey()); } private TreeMap getSortedNetconfOperationsWithCanHandle(Document message, - NetconfSession session) { + NetconfServerSession session) throws NetconfDocumentedException { TreeMap sortedPriority = Maps.newTreeMap(); for (NetconfOperation netconfOperation : allNetconfOperations) { @@ -174,9 +176,9 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { if (netconfOperation instanceof DefaultNetconfOperation) { ((DefaultNetconfOperation) netconfOperation).setNetconfSession(session); } - if (handlingPriority.equals(HandlingPriority.CANNOT_HANDLE) == false) { + if (!handlingPriority.equals(HandlingPriority.CANNOT_HANDLE)) { - Preconditions.checkState(sortedPriority.containsKey(handlingPriority) == false, + Preconditions.checkState(!sortedPriority.containsKey(handlingPriority), "Multiple %s available to handle message %s with priority %s", NetconfOperation.class.getName(), message, handlingPriority); sortedPriority.put(handlingPriority, netconfOperation); @@ -185,6 +187,21 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { return sortedPriority; } + public static final NetconfOperationChainedExecution EXECUTION_TERMINATION_POINT = new NetconfOperationChainedExecution() { + @Override + public boolean isExecutionTermination() { + return true; + } + + @Override + public Document execute(Document requestMessage) throws NetconfDocumentedException { + throw new NetconfDocumentedException("This execution represents the termination point in operation execution and cannot be executed itself", + NetconfDocumentedException.ErrorType.application, + NetconfDocumentedException.ErrorTag.operation_failed, + NetconfDocumentedException.ErrorSeverity.error); + } + }; + private static class NetconfOperationExecution implements NetconfOperationChainedExecution { private final NetconfOperation netconfOperation; private NetconfOperationChainedExecution subsequentExecution; @@ -205,7 +222,7 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { } public static NetconfOperationExecution createExecutionChain( - TreeMap sortedByPriority, HandlingPriority handlingPriority) { + NavigableMap sortedByPriority, HandlingPriority handlingPriority) { NetconfOperation netconfOperation = sortedByPriority.get(handlingPriority); HandlingPriority subsequentHandlingPriority = sortedByPriority.lowerKey(handlingPriority);