2 * Copyright (C) 2014 Red Hat, Inc.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.neutron.transcriber;
11 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
12 import org.opendaylight.neutron.spi.INeutronFirewallCRUD;
13 import org.opendaylight.neutron.spi.NeutronFirewall;
14 import org.opendaylight.yangtools.yang.binding.DataObject;
15 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
16 import org.osgi.framework.BundleContext;
17 import org.osgi.framework.ServiceRegistration;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 import java.util.ArrayList;
23 import java.util.HashSet;
24 import java.util.List;
25 import java.util.Map.Entry;
27 import java.util.concurrent.ConcurrentHashMap;
28 import java.util.concurrent.ConcurrentMap;
30 public class NeutronFirewallInterface extends AbstractNeutronInterface implements INeutronFirewallCRUD {
32 private static final Logger LOGGER = LoggerFactory.getLogger(NeutronFirewallInterface.class);
34 private ConcurrentMap<String, NeutronFirewall> firewallDB = new ConcurrentHashMap<String, NeutronFirewall>();
37 NeutronFirewallInterface(ProviderContext providerContext) {
38 super(providerContext);
42 public boolean neutronFirewallExists(String uuid) {
43 return firewallDB.containsKey(uuid);
47 public NeutronFirewall getNeutronFirewall(String uuid) {
48 if (!neutronFirewallExists(uuid)) {
49 LOGGER.debug("No Firewall Have Been Defined");
52 return firewallDB.get(uuid);
56 public List<NeutronFirewall> getAllNeutronFirewalls() {
57 Set<NeutronFirewall> allFirewalls = new HashSet<NeutronFirewall>();
58 for (Entry<String, NeutronFirewall> entry : firewallDB.entrySet()) {
59 NeutronFirewall firewall = entry.getValue();
60 allFirewalls.add(firewall);
62 LOGGER.debug("Exiting getFirewalls, Found {} OpenStackFirewall", allFirewalls.size());
63 List<NeutronFirewall> ans = new ArrayList<NeutronFirewall>();
64 ans.addAll(allFirewalls);
69 public boolean addNeutronFirewall(NeutronFirewall input) {
70 if (neutronFirewallExists(input.getFirewallUUID())) {
73 firewallDB.putIfAbsent(input.getFirewallUUID(), input);
78 public boolean removeNeutronFirewall(String uuid) {
79 if (!neutronFirewallExists(uuid)) {
82 firewallDB.remove(uuid);
87 public boolean updateNeutronFirewall(String uuid, NeutronFirewall delta) {
88 if (!neutronFirewallExists(uuid)) {
91 NeutronFirewall target = firewallDB.get(uuid);
92 return overwrite(target, delta);
96 public boolean neutronFirewallInUse(String firewallUUID) {
97 return !neutronFirewallExists(firewallUUID);
101 protected InstanceIdentifier createInstanceIdentifier(DataObject item) {
102 // TODO Auto-generated method stub
107 protected DataObject toMd(Object neutronObject) {
108 // TODO Auto-generated method stub
113 protected DataObject toMd(String uuid) {
114 // TODO Auto-generated method stub
118 public static void registerNewInterface(BundleContext context,
119 ProviderContext providerContext,
120 List<ServiceRegistration<?>> registrations) {
121 NeutronFirewallInterface neutronFirewallInterface = new NeutronFirewallInterface(providerContext);
122 ServiceRegistration<INeutronFirewallCRUD> neutronFirewallInterfaceRegistration = context.registerService(INeutronFirewallCRUD.class, neutronFirewallInterface, null);
123 if(neutronFirewallInterfaceRegistration != null) {
124 registrations.add(neutronFirewallInterfaceRegistration);