X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fforwarding%2Fstaticrouting%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fforwarding%2Fstaticrouting%2Finternal%2FStaticRoutingImplementation.java;h=ec6da387691f617cefb810c5624e67ddab613770;hp=8819be39885d950e9f6aafc7ed4ad737247a2037;hb=4ca5ea31c027f33cd4c8c84adece356c354c1c3a;hpb=39e1d43dc8f41f682fb818469a3aeb542e76ea8e diff --git a/opendaylight/forwarding/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/internal/StaticRoutingImplementation.java b/opendaylight/forwarding/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/internal/StaticRoutingImplementation.java index 8819be3988..ec6da38769 100644 --- a/opendaylight/forwarding/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/internal/StaticRoutingImplementation.java +++ b/opendaylight/forwarding/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/internal/StaticRoutingImplementation.java @@ -24,8 +24,11 @@ import java.util.Map; import java.util.Set; import java.util.Timer; import java.util.TimerTask; +import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -33,7 +36,6 @@ import java.util.regex.Pattern; import org.apache.felix.dm.Component; import org.opendaylight.controller.clustering.services.CacheConfigException; import org.opendaylight.controller.clustering.services.CacheExistException; -import org.opendaylight.controller.clustering.services.ICacheUpdateAware; import org.opendaylight.controller.clustering.services.IClusterContainerServices; import org.opendaylight.controller.clustering.services.IClusterServices; import org.opendaylight.controller.configuration.IConfigurationContainerAware; @@ -44,24 +46,20 @@ import org.opendaylight.controller.forwarding.staticrouting.StaticRouteConfig; import org.opendaylight.controller.hosttracker.IfIptoHost; import org.opendaylight.controller.hosttracker.IfNewHostNotify; import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector; -import org.opendaylight.controller.sal.utils.StatusCode; import org.opendaylight.controller.sal.utils.GlobalConstants; import org.opendaylight.controller.sal.utils.IObjectReader; import org.opendaylight.controller.sal.utils.ObjectReader; import org.opendaylight.controller.sal.utils.ObjectWriter; import org.opendaylight.controller.sal.utils.Status; +import org.opendaylight.controller.sal.utils.StatusCode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Static Routing feature provides the bridge between SDN and Non-SDN networks. - * - * - * */ public class StaticRoutingImplementation implements IfNewHostNotify, - IForwardingStaticRouting, IObjectReader, IConfigurationContainerAware, - ICacheUpdateAware { + IForwardingStaticRouting, IObjectReader, IConfigurationContainerAware { private static Logger log = LoggerFactory .getLogger(StaticRoutingImplementation.class); private static String ROOT = GlobalConstants.STARTUPHOME.toString(); @@ -71,10 +69,10 @@ public class StaticRoutingImplementation implements IfNewHostNotify, private IfIptoHost hostTracker; private Timer gatewayProbeTimer; private String staticRoutesFileName = null; - private Map configSaveEvent; private IClusterContainerServices clusterContainerService = null; private Set staticRoutingAware = Collections .synchronizedSet(new HashSet()); + private ExecutorService executor; void setStaticRoutingAware(IStaticRoutingAware s) { if (this.staticRoutingAware != null) { @@ -133,8 +131,6 @@ public class StaticRoutingImplementation implements IfNewHostNotify, private Status saveConfig() { - // Publish the save config event to the cluster nodes - configSaveEvent.put(new Date().getTime(), SAVE); return saveConfigInternal(); } @@ -164,14 +160,10 @@ public class StaticRoutingImplementation implements IfNewHostNotify, try { clusterContainerService.createCache( "forwarding.staticrouting.routes", EnumSet - .of(IClusterServices.cacheMode.NON_TRANSACTIONAL)); + .of(IClusterServices.cacheMode.TRANSACTIONAL)); clusterContainerService.createCache( "forwarding.staticrouting.configs", EnumSet - .of(IClusterServices.cacheMode.NON_TRANSACTIONAL)); - clusterContainerService.createCache( - "forwarding.staticrouting.configSaveEvent", EnumSet - .of(IClusterServices.cacheMode.NON_TRANSACTIONAL)); - + .of(IClusterServices.cacheMode.TRANSACTIONAL)); } catch (CacheExistException cee) { log .error("\nCache already exists - destroy and recreate if needed"); @@ -199,41 +191,6 @@ public class StaticRoutingImplementation implements IfNewHostNotify, if (staticRouteConfigs == null) { log.error("\nFailed to get rulesDB handle"); } - configSaveEvent = (ConcurrentMap) clusterContainerService - .getCache("forwarding.staticrouting.configSaveEvent"); - if (configSaveEvent == null) { - log.error("\nFailed to get cache for configSaveEvent"); - } - } - - @SuppressWarnings("deprecation") - private void destroyCaches() { - if (this.clusterContainerService == null) { - log - .info("un-initialized clusterContainerService, can't destroy cache"); - return; - } - - clusterContainerService.destroyCache("forwarding.staticrouting.routes"); - clusterContainerService - .destroyCache("forwarding.staticrouting.configs"); - clusterContainerService - .destroyCache("forwarding.staticrouting.configSaveEvent"); - - } - - @Override - public void entryCreated(Long key, String cacheName, boolean local) { - } - - @Override - public void entryUpdated(Long key, String new_value, String cacheName, - boolean originLocal) { - saveConfigInternal(); - } - - @Override - public void entryDeleted(Long key, String cacheName, boolean originLocal) { } private void notifyStaticRouteUpdate(StaticRoute s, boolean update) { @@ -251,43 +208,53 @@ public class StaticRoutingImplementation implements IfNewHostNotify, } } - private class NotifyStaticRouteThread extends Thread { + private class NotifyStaticRouteWorker implements Callable { private StaticRoute staticRoute; private boolean added; - public NotifyStaticRouteThread(StaticRoute s, boolean update) { + public NotifyStaticRouteWorker(StaticRoute s, boolean update) { this.staticRoute = s; this.added = update; } - public void run() { + @Override + public Object call() throws Exception { if (!added || (staticRoute.getType() == StaticRoute.NextHopType.SWITCHPORT)) { notifyStaticRouteUpdate(staticRoute, added); } else { - HostNodeConnector host = hostTracker.hostQuery(staticRoute - .getNextHopAddress()); + InetAddress nh = staticRoute.getNextHopAddress(); + HostNodeConnector host = hostTracker.hostQuery(nh); if (host == null) { - Future future = hostTracker - .discoverHost(staticRoute.getNextHopAddress()); + log.debug("Next hop {} is not present, try to discover it", nh.getHostAddress()); + Future future = hostTracker.discoverHost(nh); if (future != null) { try { host = future.get(); } catch (Exception e) { - log.error("",e); + log.error("", e); } } } if (host != null) { + log.debug("Next hop {} is found", nh.getHostAddress()); staticRoute.setHost(host); notifyStaticRouteUpdate(staticRoute, added); + } else { + log.debug("Next hop {} is still not present, try again later", nh.getHostAddress()); } } + return null; } } private void checkAndUpdateListeners(StaticRoute staticRoute, boolean added) { - new NotifyStaticRouteThread(staticRoute, added).start(); + NotifyStaticRouteWorker worker = new NotifyStaticRouteWorker(staticRoute, added); + try { + executor.submit(worker); + } catch (Exception e) { + log.error("got Exception ", e); + } } private void notifyHostUpdate(HostNodeConnector host, boolean added) { @@ -456,7 +423,7 @@ public class StaticRoutingImplementation implements IfNewHostNotify, //staticRoutes = new ConcurrentHashMap(); allocateCaches(); retrieveCaches(); - + this.executor = Executors.newFixedThreadPool(1); if (staticRouteConfigs.isEmpty()) loadConfiguration(); @@ -488,7 +455,6 @@ public class StaticRoutingImplementation implements IfNewHostNotify, log.debug("Destroy all the Static Routing Rules given we are " + "shutting down"); - destroyCaches(); gatewayProbeTimer.cancel(); // Clear the listener so to be ready in next life @@ -511,10 +477,12 @@ public class StaticRoutingImplementation implements IfNewHostNotify, * */ void stop() { + executor.shutdown(); } @Override public Status saveConfiguration() { return this.saveConfig(); } + }