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;
public NetconfOperationRouterImpl(NetconfOperationServiceSnapshot netconfOperationServiceSnapshot,
- CapabilityProvider capabilityProvider,
- DefaultCommitNotificationProducer commitNotifier) {
+ CapabilityProvider capabilityProvider, DefaultCommitNotificationProducer commitNotifier) {
this.netconfOperationServiceSnapshot = netconfOperationServiceSnapshot;
.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);
for (NetconfOperationService netconfOperationService : netconfOperationServiceSnapshot.getServices()) {
final Set<NetconfOperationFilter> 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);
}
}
@Override
public synchronized Document onNetconfMessage(Document message,
NetconfSession session) throws NetconfDocumentedException {
- NetconfOperationExecution netconfOperationExecution = null;
+ NetconfOperationExecution netconfOperationExecution;
String messageAsString = XmlUtil.toString(message);
try {
- netconfOperationExecution = getNetconfOperationWithHighestPriority(
- message, session);
+ netconfOperationExecution = getNetconfOperationWithHighestPriority(message, session);
} catch (IllegalArgumentException | IllegalStateException e) {
logger.warn("Unable to handle rpc {} on session {}", messageAsString, session, e);
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<String, String> 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);
private NetconfOperationExecution getNetconfOperationWithHighestPriority(
Document message, NetconfSession session) {
- // TODO test
TreeMap<HandlingPriority, Set<NetconfOperation>> sortedPriority = getSortedNetconfOperationsWithCanHandle(
message, session);