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=2aa89ba2c48958d9990dada2f24f1f91ecb0f14a;hp=ff96ad779fbc974539ced455494129381bb09635;hb=d762fe6c823ad1ba21db1cad627a1cbd6d7c6d8e;hpb=dc1a275c3c1ea8949dd3a607e08ee4624e758511 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 ff96ad779f..2aa89ba2c4 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 @@ -10,6 +10,12 @@ package org.opendaylight.controller.netconf.impl.osgi; import com.google.common.base.Preconditions; import com.google.common.collect.Maps; import com.google.common.collect.Sets; +import java.util.Collections; +import java.util.HashSet; +import java.util.Map; +import java.util.NavigableMap; +import java.util.Set; +import java.util.TreeMap; import org.opendaylight.controller.netconf.api.NetconfDocumentedException; import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer; import org.opendaylight.controller.netconf.impl.NetconfServerSession; @@ -30,33 +36,26 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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; - public class NetconfOperationRouterImpl implements NetconfOperationRouter { - private static final Logger logger = LoggerFactory.getLogger(NetconfOperationRouterImpl.class); + private static final Logger LOG = LoggerFactory.getLogger(NetconfOperationRouterImpl.class); private final NetconfOperationServiceSnapshot netconfOperationServiceSnapshot; private Set allNetconfOperations; - private NetconfOperationRouterImpl(NetconfOperationServiceSnapshot netconfOperationServiceSnapshot) { + private NetconfOperationRouterImpl(final NetconfOperationServiceSnapshot netconfOperationServiceSnapshot) { this.netconfOperationServiceSnapshot = netconfOperationServiceSnapshot; } - private void initNetconfOperations(Set allOperations) { + private synchronized void initNetconfOperations(final Set allOperations) { allNetconfOperations = allOperations; } /** * Factory method to produce instance of NetconfOperationRouter */ - public static NetconfOperationRouter createOperationRouter(NetconfOperationServiceSnapshot netconfOperationServiceSnapshot, - CapabilityProvider capabilityProvider, DefaultCommitNotificationProducer commitNotifier) { + public static NetconfOperationRouter createOperationRouter(final NetconfOperationServiceSnapshot netconfOperationServiceSnapshot, + final CapabilityProvider capabilityProvider, final DefaultCommitNotificationProducer commitNotifier) { NetconfOperationRouterImpl router = new NetconfOperationRouterImpl(netconfOperationServiceSnapshot); Preconditions.checkNotNull(netconfOperationServiceSnapshot); @@ -76,8 +75,8 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { return router; } - private static Set getAllNetconfOperations(Set defaultNetconfOperations, - NetconfOperationServiceSnapshot netconfOperationServiceSnapshot) { + private static Set getAllNetconfOperations(final Set defaultNetconfOperations, + final NetconfOperationServiceSnapshot netconfOperationServiceSnapshot) { Set result = new HashSet<>(); result.addAll(defaultNetconfOperations); @@ -93,8 +92,8 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { } @Override - public synchronized Document onNetconfMessage(Document message, - NetconfServerSession session) throws NetconfDocumentedException { + public synchronized Document onNetconfMessage(final Document message, + final NetconfServerSession session) throws NetconfDocumentedException { Preconditions.checkNotNull(allNetconfOperations, "Operation router was not initialized properly"); NetconfOperationExecution netconfOperationExecution; @@ -104,7 +103,7 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { messageAsString = XmlUtil.toString(message); netconfOperationExecution = getNetconfOperationWithHighestPriority(message, session); } catch (IllegalArgumentException | IllegalStateException e) { - logger.warn("Unable to handle rpc {} on session {}", messageAsString, session, e); + LOG.warn("Unable to handle rpc {} on session {}", messageAsString, session, e); String errorMessage = String.format("Unable to handle rpc %s on session %s", messageAsString, session); Map errorInfo = Maps.newHashMap(); @@ -136,8 +135,8 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { netconfOperationServiceSnapshot.close(); } - private NetconfDocumentedException handleUnexpectedEx(String s, Exception e) throws NetconfDocumentedException { - logger.error(s, e); + private NetconfDocumentedException handleUnexpectedEx(final String s, final Exception e) throws NetconfDocumentedException { + LOG.error(s, e); Map info = Maps.newHashMap(); info.put(NetconfDocumentedException.ErrorSeverity.error.toString(), e.toString()); @@ -147,28 +146,29 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { NetconfDocumentedException.ErrorSeverity.error, info); } - private Document executeOperationWithHighestPriority(Document message, - NetconfOperationExecution netconfOperationExecution, String messageAsString) + private Document executeOperationWithHighestPriority(final Document message, + final NetconfOperationExecution netconfOperationExecution, final String messageAsString) throws NetconfDocumentedException { - logger.debug("Forwarding netconf message {} to {}", messageAsString, netconfOperationExecution.netconfOperation); + LOG.debug("Forwarding netconf message {} to {}", messageAsString, netconfOperationExecution.netconfOperation); return netconfOperationExecution.execute(message); } private NetconfOperationExecution getNetconfOperationWithHighestPriority( - Document message, NetconfServerSession session) throws NetconfDocumentedException { + final Document message, final NetconfServerSession session) throws NetconfDocumentedException { NavigableMap sortedByPriority = getSortedNetconfOperationsWithCanHandle( message, session); - Preconditions.checkArgument(sortedByPriority.isEmpty() == false, - "No %s available to handle message %s", NetconfOperation.class.getName(), - XmlUtil.toString(message)); + if (sortedByPriority.isEmpty()) { + throw new IllegalArgumentException(String.format("No %s available to handle message %s", + NetconfOperation.class.getName(), XmlUtil.toString(message))); + } return NetconfOperationExecution.createExecutionChain(sortedByPriority, sortedByPriority.lastKey()); } - private TreeMap getSortedNetconfOperationsWithCanHandle(Document message, - NetconfServerSession session) throws NetconfDocumentedException { + private TreeMap getSortedNetconfOperationsWithCanHandle(final Document message, + final NetconfServerSession session) throws NetconfDocumentedException { TreeMap sortedPriority = Maps.newTreeMap(); for (NetconfOperation netconfOperation : allNetconfOperations) { @@ -194,7 +194,7 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { } @Override - public Document execute(Document requestMessage) throws NetconfDocumentedException { + public Document execute(final 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, @@ -204,9 +204,9 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { private static class NetconfOperationExecution implements NetconfOperationChainedExecution { private final NetconfOperation netconfOperation; - private NetconfOperationChainedExecution subsequentExecution; + private final NetconfOperationChainedExecution subsequentExecution; - private NetconfOperationExecution(NetconfOperation netconfOperation, NetconfOperationChainedExecution subsequentExecution) { + private NetconfOperationExecution(final NetconfOperation netconfOperation, final NetconfOperationChainedExecution subsequentExecution) { this.netconfOperation = netconfOperation; this.subsequentExecution = subsequentExecution; } @@ -217,12 +217,12 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { } @Override - public Document execute(Document message) throws NetconfDocumentedException { + public Document execute(final Document message) throws NetconfDocumentedException { return netconfOperation.handle(message, subsequentExecution); } public static NetconfOperationExecution createExecutionChain( - NavigableMap sortedByPriority, HandlingPriority handlingPriority) { + final NavigableMap sortedByPriority, final HandlingPriority handlingPriority) { NetconfOperation netconfOperation = sortedByPriority.get(handlingPriority); HandlingPriority subsequentHandlingPriority = sortedByPriority.lowerKey(handlingPriority);