With this change, lbaas handler will be getting notifyNode() callbacks.
Patch 2 (code review):
- add missing copyright header
- make node callback more resilient
Change-Id: I58ca64b9fa987f994cdf68bf076fef820092a8ce
Signed-off-by: Flavio Fernandes <ffernand@redhat.com>
import org.opendaylight.ovsdb.openstack.netvirt.api.MultiTenantAwareRouter;
import org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProvider;
import org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProviderManager;
+import org.opendaylight.ovsdb.openstack.netvirt.api.NodeCacheListener;
import org.opendaylight.ovsdb.openstack.netvirt.api.NodeCacheManager;
import org.opendaylight.ovsdb.openstack.netvirt.api.OutboundNatProvider;
import org.opendaylight.ovsdb.openstack.netvirt.api.RoutingProvider;
manager.add(createComponent()
.setInterface(new String[]{INeutronLoadBalancerAware.class.getName(),
- AbstractHandler.class.getName()},
+ NodeCacheListener.class.getName(), AbstractHandler.class.getName()},
lbaasHandlerProperties)
.setImplementation(LBaaSHandler.class)
.add(createServiceDependency().setService(EventDispatcher.class).setRequired(true))
.setInterface(new String[]{NodeCacheManager.class.getName(), AbstractHandler.class.getName()},
nodeCacheManagerProperties)
.setImplementation(NodeCacheManagerImpl.class)
- .add(createServiceDependency().setService(EventDispatcher.class).setRequired(true)));
+ .add(createServiceDependency().setService(EventDispatcher.class).setRequired(true))
+ .add(createServiceDependency().setService(NodeCacheListener.class)
+ .setCallbacks("cacheListenerAdded", "cacheListenerRemoved")));
}
@Override
import org.opendaylight.ovsdb.openstack.netvirt.api.LoadBalancerConfiguration;
import org.opendaylight.ovsdb.openstack.netvirt.api.LoadBalancerProvider;
import org.opendaylight.ovsdb.openstack.netvirt.api.NodeCacheManager;
+import org.opendaylight.ovsdb.openstack.netvirt.api.NodeCacheListener;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//TODO: Implement INeutronLoadBalancerHealthMonitorAware, INeutronLoadBalancerListenerAware, INeutronLoadBalancerPoolMemberAware,
public class LBaaSHandler extends AbstractHandler
- implements INeutronLoadBalancerAware {
+ implements INeutronLoadBalancerAware, NodeCacheListener {
private static final Logger logger = LoggerFactory.getLogger(LBaaSHandler.class);
}
/**
- FIXME!
-
* On the addition of a new node, we iterate through all existing loadbalancer
* instances and program the node for all of them. It is sufficient to do that only
* when a node is added, and only for the LB instances (and not individual members).
- *
+ */
@Override
- public void notifyNode(Node node, UpdateType type, Map<String, Property> propMap) {
+ public void notifyNode(Node node, Action type) {
logger.debug("notifyNode: Node {} update {} from Controller's inventory Service", node, type);
Preconditions.checkNotNull(loadBalancerProvider);
if (!lbConfig.isValid()) {
logger.debug("Neutron LB configuration invalid for {} ", lbConfig.getName());
} else {
- if (type.equals(UpdateType.ADDED)) {
+ if (type.equals(Action.ADD)) {
loadBalancerProvider.programLoadBalancerRules(node, lbConfig, Action.ADD);
- * When node disappears, we do nothing for now. Making a call to
+ /* When node disappears, we do nothing for now. Making a call to
* loadBalancerProvider.programLoadBalancerRules(node, lbConfig, Action.DELETE)
* can lead to TransactionCommitFailedException. Similarly when node is changed,
* because of remove followed by add, we do nothing.
- *
+ */
//(type.equals(UpdateType.REMOVED) || type.equals(UpdateType.CHANGED))
} else {
}
}
}
- */
-
}
--- /dev/null
+/*
+ * Copyright (C) 2015 Red Hat, Inc.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Authors : Flavio Fernandes
+ */
+package org.opendaylight.ovsdb.openstack.netvirt.api;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+
+/**
+ * When this interface is used, instance owner will get callbacks on
+ * changes that occur in NodeCacheManager
+ */
+public interface NodeCacheListener {
+
+ public void notifyNode(Node node, Action action);
+}
package org.opendaylight.ovsdb.openstack.netvirt.impl;
import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
import org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent;
import org.opendaylight.ovsdb.openstack.netvirt.AbstractHandler;
import org.opendaylight.ovsdb.openstack.netvirt.NodeCacheManagerEvent;
import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
+import org.opendaylight.ovsdb.openstack.netvirt.api.NodeCacheListener;
import org.opendaylight.ovsdb.openstack.netvirt.api.NodeCacheManager;
import org.opendaylight.ovsdb.utils.mdsal.node.NodeUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.osgi.framework.ServiceReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
+import java.util.Map;
public class NodeCacheManagerImpl extends AbstractHandler
implements NodeCacheManager {
private static final Logger logger = LoggerFactory.getLogger(NodeCacheManagerImpl.class);
private List<Node> nodeCache = Lists.newArrayList();
-
+ private Map<Long, NodeCacheListener> handlers = Maps.newHashMap();
@Override
public void nodeAdded(String nodeIdentifier) {
private void _processNodeAdded(Node node) {
nodeCache.add(node);
+ for (NodeCacheListener handler : handlers.values()) {
+ try {
+ handler.notifyNode(node, Action.ADD);
+ } catch (Exception e) {
+ logger.error("Failed notifying node add event", e);
+ }
+ }
}
private void _processNodeRemoved(Node node) {
nodeCache.remove(node);
+ for (NodeCacheListener handler : handlers.values()) {
+ try {
+ handler.notifyNode(node, Action.DELETE);
+ } catch (Exception e) {
+ logger.error("Failed notifying node remove event", e);
+ }
+ }
}
/**
break;
}
}
+
+ public void cacheListenerAdded(final ServiceReference ref, NodeCacheListener handler){
+ Long pid = (Long) ref.getProperty(org.osgi.framework.Constants.SERVICE_ID);
+ handlers.put(pid, handler);
+ logger.debug("Node cache listener registered, pid {}", pid);
+ }
+
+ public void cacheListenerRemoved(final ServiceReference ref){
+ Long pid = (Long) ref.getProperty(org.osgi.framework.Constants.SERVICE_ID);
+ handlers.remove(pid);
+ logger.debug("Node cache listener unregistered, pid {}", pid);
+ }
}