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=ee474dbba01f4068de6190662c50d25f8339749d;hp=3dd6e6803bda9662b7e54a95849db368931a8452;hb=38dbf4451a20bee38ccb5a9c685dcf9fa9d6fb33;hpb=b0e337733be06807c12d5bbd3b5a29a94f44fdba 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 3dd6e6803b..ee474dbba0 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 @@ -7,17 +7,12 @@ */ package org.opendaylight.controller.netconf.impl.osgi; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Set; -import java.util.TreeMap; -import java.util.TreeSet; - +import com.google.common.base.Preconditions; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import org.opendaylight.controller.netconf.api.NetconfSession; 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.mapping.CapabilityProvider; import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultCloseSession; @@ -36,9 +31,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; -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.Iterator; +import java.util.LinkedList; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; public class NetconfOperationRouterImpl implements NetconfOperationRouter { @@ -53,8 +53,7 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { public NetconfOperationRouterImpl(NetconfOperationServiceSnapshot netconfOperationServiceSnapshot, - CapabilityProvider capabilityProvider, - DefaultCommitNotificationProducer commitNotifier) { + CapabilityProvider capabilityProvider, DefaultCommitNotificationProducer commitNotifier) { this.netconfOperationServiceSnapshot = netconfOperationServiceSnapshot; @@ -65,12 +64,10 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { .getNetconfSessionIdForReporting())); defaultNetconfOperations.add(new DefaultCloseSession(netconfOperationServiceSnapshot .getNetconfSessionIdForReporting())); - defaultNetconfOperations.add(new DefaultStartExi( - netconfOperationServiceSnapshot - .getNetconfSessionIdForReporting())); - defaultNetconfOperations.add(new DefaultStopExi( - netconfOperationServiceSnapshot - .getNetconfSessionIdForReporting())); + defaultNetconfOperations.add(new DefaultStartExi(netconfOperationServiceSnapshot + .getNetconfSessionIdForReporting())); + defaultNetconfOperations.add(new DefaultStopExi(netconfOperationServiceSnapshot + .getNetconfSessionIdForReporting())); allNetconfOperations = getAllNetconfOperations(defaultNetconfOperations, netconfOperationServiceSnapshot); @@ -102,7 +99,8 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { for (NetconfOperationService netconfOperationService : netconfOperationServiceSnapshot.getServices()) { final Set filtersFromService = netconfOperationService.getFilters(); for (NetconfOperationFilter filter : filtersFromService) { - Preconditions.checkState(result.contains(filter) == false, "Filter %s already present", filter); + Preconditions.checkState(result.contains(filter) == false, + "Filter %s already present, all filters so far: %s", filter, result); result.add(filter); } } @@ -116,9 +114,53 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { @Override public synchronized Document onNetconfMessage(Document message, NetconfSession session) throws NetconfDocumentedException { - NetconfOperationExecution netconfOperationExecution = getNetconfOperationWithHighestPriority( - message, session); - logger.debug("Forwarding netconf message {} to {}", XmlUtil.toString(message), + NetconfOperationExecution netconfOperationExecution; + + String messageAsString = XmlUtil.toString(message); + + try { + netconfOperationExecution = getNetconfOperationWithHighestPriority(message, session); + } catch (IllegalArgumentException | IllegalStateException e) { + logger.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(); + + NetconfDocumentedException.ErrorTag tag = null; + 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) { + errorInfo.put(NetconfDocumentedException.ErrorTag.operation_failed.toString(), e.getMessage()); + tag = NetconfDocumentedException.ErrorTag.operation_failed; + } + + throw new NetconfDocumentedException(errorMessage, e, NetconfDocumentedException.ErrorType.application, + tag, NetconfDocumentedException.ErrorSeverity.error, errorInfo); + } catch (RuntimeException e) { + throw handleUnexpectedEx("Unexpected exception during netconf operation sort", e); + } + + try { + return executeOperationWithHighestPriority(message, netconfOperationExecution, messageAsString); + } catch (RuntimeException e) { + throw handleUnexpectedEx("Unexpected exception during netconf operation execution", e); + } + } + + private NetconfDocumentedException handleUnexpectedEx(String s, Exception e) throws NetconfDocumentedException { + logger.error(s, e); + + Map info = Maps.newHashMap(); + info.put(NetconfDocumentedException.ErrorSeverity.error.toString(), e.toString()); + return new NetconfDocumentedException("Unexpected error", + NetconfDocumentedException.ErrorType.application, + NetconfDocumentedException.ErrorTag.operation_failed, + NetconfDocumentedException.ErrorSeverity.error, info); + } + + private Document executeOperationWithHighestPriority(Document message, NetconfOperationExecution netconfOperationExecution, String messageAsString) throws NetconfDocumentedException { + logger.debug("Forwarding netconf message {} to {}", messageAsString, netconfOperationExecution.operationWithHighestPriority); final LinkedList chain = new LinkedList<>(); @@ -147,7 +189,7 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { TreeMap> sortedPriority = getSortedNetconfOperationsWithCanHandle( message, session); - Preconditions.checkState(sortedPriority.isEmpty() == false, "No %s available to handle message %s", + Preconditions.checkArgument(sortedPriority.isEmpty() == false, "No %s available to handle message %s", NetconfOperation.class.getName(), XmlUtil.toString(message)); HandlingPriority highestFoundPriority = sortedPriority.lastKey();