import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
+import org.opendaylight.controller.sal.inventory.IInventoryService;
import org.opendaylight.controller.sal.inventory.IListenInventoryUpdates;
public class Activator extends ComponentActivatorAbstractBase {
* ComponentActivatorAbstractBase.
*
*/
+ @Override
public void init() {
}
* cleanup done by ComponentActivatorAbstractBase
*
*/
+ @Override
public void destroy() {
}
* @return The list of implementations the bundle will support,
* in Global version
*/
+ @Override
protected Object[] getGlobalImplementations() {
Object[] res = { ConnectionManager.class };
return res;
* @param imp implementation to be configured
* @param containerName container on which the configuration happens
*/
+ @Override
protected void configureGlobalInstance(Component c, Object imp) {
if (imp.equals(ConnectionManager.class)) {
Dictionary<String, Object> props = new Hashtable<String, Object>();
c.add(createServiceDependency().setService(IConnectionService.class)
.setCallbacks("setConnectionService", "unsetConnectionService")
.setRequired(true));
+ c.add(createServiceDependency().setService(IInventoryService.class, "(scope=Global)")
+ .setCallbacks("setInventoryService", "unsetInventoryService")
+ .setRequired(true));
}
}
}
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
import org.eclipse.osgi.framework.console.CommandInterpreter;
import org.eclipse.osgi.framework.console.CommandProvider;
import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
import org.opendaylight.controller.sal.core.NodeConnector;
import org.opendaylight.controller.sal.core.Property;
import org.opendaylight.controller.sal.core.UpdateType;
+import org.opendaylight.controller.sal.inventory.IInventoryService;
import org.opendaylight.controller.sal.inventory.IListenInventoryUpdates;
import org.opendaylight.controller.sal.utils.Status;
import org.opendaylight.controller.sal.utils.StatusCode;
private IConnectionService connectionService;
private Thread connectionEventThread;
private BlockingQueue<ConnectionMgmtEvent> connectionEvents;
+ private IInventoryService inventoryService;
public void setClusterServices(IClusterGlobalServices i) {
this.clusterServices = i;
}
}
+ public void setInventoryService(IInventoryService service) {
+ logger.trace("Got inventory service set request {}", service);
+ this.inventoryService = service;
+ }
+
+ public void unsetInventoryService(IInventoryService service) {
+ logger.trace("Got a service UNset request");
+ this.inventoryService = null;
+ }
+
+ private void getInventories() {
+ Map<Node, Map<String, Property>> nodeProp = this.inventoryService.getNodeProps();
+ for (Map.Entry<Node, Map<String, Property>> entry : nodeProp.entrySet()) {
+ Node node = entry.getKey();
+ logger.debug("getInventories for node:{}", new Object[] { node });
+ Map<String, Property> propMap = entry.getValue();
+ Set<Property> props = new HashSet<Property>();
+ for (Property property : propMap.values()) {
+ props.add(property);
+ }
+ updateNode(node, UpdateType.ADDED, props);
+ }
+
+ Map<NodeConnector, Map<String, Property>> nodeConnectorProp = this.inventoryService.getNodeConnectorProps();
+ for (Map.Entry<NodeConnector, Map<String, Property>> entry : nodeConnectorProp.entrySet()) {
+ Map<String, Property> propMap = entry.getValue();
+ Set<Property> props = new HashSet<Property>();
+ for (Property property : propMap.values()) {
+ props.add(property);
+ }
+ updateNodeConnector(entry.getKey(), UpdateType.ADDED, props);
+ }
+ }
+
public void started() {
connectionEventThread = new Thread(new EventHandler(), "ConnectionEvent Thread");
connectionEventThread.start();
registerWithOSGIConsole();
notifyClusterViewChanged();
+ // Should pull the Inventory updates in case we missed it
+ getInventories();
}
public void init() {
* are done by the ComponentActivatorAbstractBase.
*
*/
+ @Override
public void init() {
Node.NodeIDType.registerIDType("STUB", Integer.class);
NodeConnector.NodeConnectorIDType.registerIDType("STUB", Integer.class, "STUB");
* ComponentActivatorAbstractBase
*
*/
+ @Override
public void destroy() {
Node.NodeIDType.unRegisterIDType("STUB");
NodeConnector.NodeConnectorIDType.unRegisterIDType("STUB");
* instantiated in order to get an fully working implementation
* Object
*/
+ @Override
public Object[] getImplementations() {
Object[] res = { ReadService.class, InventoryService.class };
return res;
* per-container different behavior if needed, usually should not
* be the case though.
*/
+ @Override
public void configureInstance(Component c, Object imp, String containerName) {
if (imp.equals(ReadService.class)) {
// export the service to be used by SAL
}
}
+ @Override
public Object[] getGlobalImplementations() {
- Object[] res = { FlowProgrammerService.class, StubNodeFactory.class, StubNodeConnectorFactory.class };
+ Object[] res =
+ {
+ FlowProgrammerService.class,
+ StubNodeFactory.class,
+ StubNodeConnectorFactory.class,
+ InventoryService.class };
return res;
}
+ @Override
public void configureGlobalInstance(Component c, Object imp){
if (imp.equals(FlowProgrammerService.class)) {
// export the service to be used by SAL
props.put("protocolName", "STUB");
c.setInterface(INodeConnectorFactory.class.getName(), props);
}
-
+ if (imp.equals(InventoryService.class)) {
+ // export the service to be used by SAL
+ Dictionary<String, Object> props = new Hashtable<String, Object>();
+ // Set the protocolPluginType property which will be used
+ // by SAL
+ props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "STUB");
+ props.put("scope", "Global");
+ c.setInterface(IPluginInInventoryService.class.getName(), props);
+ c.add(createServiceDependency().setService(IPluginOutInventoryService.class, "(scope=Global)")
+ .setCallbacks("setPluginOutInventoryServices", "unsetPluginOutInventoryServices")
+ .setRequired(true));
+ }
}
}
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.CopyOnWriteArraySet;
import org.apache.felix.dm.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
import org.opendaylight.controller.sal.core.Actions;
import org.opendaylight.controller.sal.core.Bandwidth;
import org.opendaylight.controller.sal.core.Buffers;
import org.opendaylight.controller.sal.core.State;
import org.opendaylight.controller.sal.core.Tables;
import org.opendaylight.controller.sal.core.TimeStamp;
+import org.opendaylight.controller.sal.core.UpdateType;
import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
+import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
import org.opendaylight.controller.sal.utils.NodeCreator;
import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
// global
// container
// only
+ private final Set<IPluginOutInventoryService> pluginOutInventoryServices =
+ new CopyOnWriteArraySet<IPluginOutInventoryService>();
+
+ public void setPluginOutInventoryServices(IPluginOutInventoryService service) {
+ logger.trace("Got a service set request {}", service);
+ if (this.pluginOutInventoryServices != null) {
+ this.pluginOutInventoryServices.add(service);
+ }
+ }
+
+ public void unsetPluginOutInventoryServices(IPluginOutInventoryService service) {
+ logger.trace("Got a service UNset request");
+ if (this.pluginOutInventoryServices != null) {
+ this.pluginOutInventoryServices.remove(service);
+ }
+ }
/**
* Function called by the dependency manager when all the required
void start() {
}
+ /**
+ * Method called when the plugin has exposed it's services, this will be
+ * used to publish the updates so connection manager can think the
+ * connection is local
+ */
+ void started() {
+ // update sal and discovery
+ for (IPluginOutInventoryService service : pluginOutInventoryServices) {
+ for (Node node : nodeProps.keySet()) {
+ Set<Property> props = new HashSet<Property>(nodeProps.get(node)
+ .values());
+ service.updateNode(node, UpdateType.ADDED, props);
+ logger.trace("Adding Node {} with props {}", node, props);
+ }
+ for (NodeConnector nc : nodeConnectorProps.keySet()) {
+ Set<Property> props = new HashSet<Property>(nodeConnectorProps.get(nc)
+ .values());
+ service.updateNodeConnector(nc, UpdateType.ADDED, props);
+ logger.trace("Adding NodeConnectors {} with props {}", nc, props);
+ }
+ }
+ }
+
/**
* Function called by the dependency manager before the services exported by
* the component are unregistered, this will be followed by a "destroy ()"
*
*/
void stop() {
+ pluginOutInventoryServices.clear();
}
/**