X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-remoterpc-connector%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fconnector%2Fremoterpc%2FServerImpl.java;h=d256b998d4f8abd254fffea087778600a1b70051;hp=b5a67ff0df97f3d110f1842074617468ce836b61;hb=408eeef51f435abd2027f9d25ac5592066b202dd;hpb=d3230a844c5c0c6ca6ae774672fcb97a0c5a3951 diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/ServerImpl.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/ServerImpl.java index b5a67ff0df..d256b998d4 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/ServerImpl.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/ServerImpl.java @@ -18,6 +18,7 @@ import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTableExcep import org.opendaylight.controller.sal.connector.remoterpc.api.SystemException; import org.opendaylight.controller.sal.connector.remoterpc.dto.RouteIdentifierImpl; import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; +import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry; import org.opendaylight.controller.sal.core.api.RpcRegistrationListener; import org.opendaylight.controller.sal.core.api.RpcRoutingContext; import org.opendaylight.yangtools.yang.common.QName; @@ -40,12 +41,12 @@ import java.util.concurrent.FutureTask; import java.util.concurrent.TimeUnit; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; /** - * ZeroMq based implementation of RpcRouter. It implements RouteChangeListener of RoutingTable - * so that it gets route change notifications from routing table. + * ZeroMq based implementation of RpcRouter. */ -public class ServerImpl implements RemoteRpcServer, RouteChangeListener { +public class ServerImpl implements RemoteRpcServer { private Logger _logger = LoggerFactory.getLogger(ServerImpl.class); @@ -56,8 +57,6 @@ public class ServerImpl implements RemoteRpcServer, RouteChangeListener();// serverPool = Executors.newSingleThreadExecutor();//main server thread serverPool.execute(receive()); // Start listening rpc requests - brokerSession.addRpcRegistrationListener(listener); - - announceLocalRpcs(); - - registerRemoteRpcs(); status = State.STARTED; _logger.info("Remote RPC Server started [{}]", getServerAddress()); @@ -160,8 +152,6 @@ public class ServerImpl implements RemoteRpcServer, RouteChangeListener> routingTableOptional = routingTableProvider.getRoutingTable(); - - Preconditions.checkState(routingTableOptional.isPresent(), "Routing table is absent"); - - Set remoteRoutes = - routingTableProvider.getRoutingTable().get().getAllRoutes(); - - //filter out all entries that contains local address - //we dont want to register local RPCs as remote - Predicate notLocalAddressFilter = new Predicate(){ - public boolean apply(Map.Entry remoteRoute){ - return !getServerAddress().equalsIgnoreCase((String)remoteRoute.getValue()); - } - }; - - //filter the entries created by current node - Set filteredRemoteRoutes = Sets.filter(remoteRoutes, notLocalAddressFilter); - - for (Map.Entry route : filteredRemoteRoutes){ - onRouteUpdated((String) route.getKey(), "");//value is not needed by broker - } - } - - /** - * Un-Register the local RPCs from the routing table - */ - private void unregisterLocalRpcs(){ - Set currentlySupported = brokerSession.getSupportedRpcs(); - for (QName rpc : currentlySupported) { - listener.onRpcImplementationRemoved(rpc); - } - } - - /** - * Publish all the locally registered RPCs in the routing table - */ - private void announceLocalRpcs(){ - Set currentlySupported = brokerSession.getSupportedRpcs(); - for (QName rpc : currentlySupported) { - listener.onRpcImplementationAdded(rpc); - } - } - - /** - * @param key - * @param value - */ - @Override - public void onRouteUpdated(String key, String value) { - RouteIdentifierImpl rId = new RouteIdentifierImpl(); - try { - _logger.debug("Updating key/value {}-{}", key, value); - brokerSession.addRpcImplementation( - (QName) rId.fromString(key).getType(), client); - - //TODO: Check with Tony for routed rpc - //brokerSession.addRoutedRpcImplementation((QName) rId.fromString(key).getRoute(), client); - } catch (Exception e) { - _logger.info("Route update failed {}", e); - } - } - - /** - * @param key - */ - @Override - public void onRouteDeleted(String key) { - //TODO: Broker session needs to be updated to support this - throw new UnsupportedOperationException(); - } - /** * Finds IPv4 address of the local VM * TODO: This method is non-deterministic. There may be more than one IPv4 address. Cant say which @@ -334,12 +249,12 @@ public class ServerImpl implements RemoteRpcServer, RouteChangeListener routingTable = getRoutingTable(); - - try { - routingTable.addGlobalRoute(routeId.toString(), getServerAddress()); - _logger.debug("Route added [{}-{}]", name, getServerAddress()); - - } catch (RoutingTableException | SystemException e) { - //TODO: This can be thrown when route already exists in the table. Broker - //needs to handle this. - _logger.error("Unhandled exception while adding global route to routing table [{}]", e); - - } - } - - @Override - public void onRpcImplementationRemoved(QName name) { - - _logger.debug("Removing registration for [{}]", name); - RouteIdentifierImpl routeId = new RouteIdentifierImpl(); - routeId.setType(name); - - RoutingTable routingTable = getRoutingTable(); - - try { - routingTable.removeGlobalRoute(routeId.toString()); - } catch (RoutingTableException | SystemException e) { - _logger.error("Route delete failed {}", e); + _logger.debug("Trying address {}", i); + if ((i instanceof Inet4Address) && (!i.isLoopbackAddress())) { + String hostAddress = i.getHostAddress(); + _logger.debug("Settled on host address {}", hostAddress); + return hostAddress; + } } } - private RoutingTable getRoutingTable(){ - Optional> routingTable = - routingTableProvider.getRoutingTable(); - - checkNotNull(routingTable.isPresent(), "Routing table is null"); - - return routingTable.get(); - } - } - - /* - * Listener for Route changes in broker. Broker notifies this listener in the event - * of any change (add/delete). Listener then updates the routing table. - */ - private class BrokerRouteChangeListener - implements org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener{ - - @Override - public void onRouteChange(RouteChange routeChange) { - - } + _logger.error("Failed to find a suitable host address"); + return null; } }