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 java.util.ArrayList;
12 import java.util.HashSet;
13 import java.util.List;
14 import java.util.Map.Entry;
16 import java.util.concurrent.ConcurrentHashMap;
17 import java.util.concurrent.ConcurrentMap;
19 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
20 import org.opendaylight.neutron.spi.INeutronFirewallRuleCRUD;
21 import org.opendaylight.neutron.spi.INeutronObject;
22 import org.opendaylight.neutron.spi.NeutronFirewallRule;
23 import org.opendaylight.yangtools.yang.binding.DataObject;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.osgi.framework.BundleContext;
26 import org.osgi.framework.ServiceRegistration;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 public class NeutronFirewallRuleInterface extends AbstractNeutronInterface implements INeutronFirewallRuleCRUD {
31 private static final Logger LOGGER = LoggerFactory.getLogger(NeutronFirewallRuleInterface.class);
33 private ConcurrentMap<String, NeutronFirewallRule> firewallRuleDB = new ConcurrentHashMap<String, NeutronFirewallRule>();
36 NeutronFirewallRuleInterface(ProviderContext providerContext) {
37 super(providerContext);
41 public boolean neutronFirewallRuleExists(String uuid) {
42 return firewallRuleDB.containsKey(uuid);
46 public NeutronFirewallRule getNeutronFirewallRule(String uuid) {
47 if (!neutronFirewallRuleExists(uuid)) {
48 LOGGER.debug("No Firewall Rule Have Been Defined");
51 return firewallRuleDB.get(uuid);
55 public List<NeutronFirewallRule> getAllNeutronFirewallRules() {
56 Set<NeutronFirewallRule> allFirewallRules = new HashSet<NeutronFirewallRule>();
57 for (Entry<String, NeutronFirewallRule> entry : firewallRuleDB.entrySet()) {
58 NeutronFirewallRule firewallRule = entry.getValue();
59 allFirewallRules.add(firewallRule);
61 LOGGER.debug("Exiting getFirewallRules, Found {} OpenStackFirewallRule", allFirewallRules.size());
62 List<NeutronFirewallRule> ans = new ArrayList<NeutronFirewallRule>();
63 ans.addAll(allFirewallRules);
68 public boolean addNeutronFirewallRule(NeutronFirewallRule input) {
69 if (neutronFirewallRuleExists(input.getID())) {
72 firewallRuleDB.putIfAbsent(input.getID(), input);
77 public boolean removeNeutronFirewallRule(String uuid) {
78 if (!neutronFirewallRuleExists(uuid)) {
81 firewallRuleDB.remove(uuid);
86 public boolean updateNeutronFirewallRule(String uuid, NeutronFirewallRule delta) {
87 if (!neutronFirewallRuleExists(uuid)) {
90 NeutronFirewallRule target = firewallRuleDB.get(uuid);
91 return overwrite(target, delta);
95 public boolean neutronFirewallRuleInUse(String firewallRuleUUID) {
96 return !neutronFirewallRuleExists(firewallRuleUUID);
100 protected InstanceIdentifier createInstanceIdentifier(DataObject item) {
101 // TODO Auto-generated method stub
106 protected DataObject toMd(INeutronObject neutronObject) {
107 // TODO Auto-generated method stub
112 protected DataObject toMd(String uuid) {
113 // TODO Auto-generated method stub
117 public static void registerNewInterface(BundleContext context,
118 ProviderContext providerContext,
119 List<ServiceRegistration<?>> registrations) {
120 NeutronFirewallRuleInterface neutronFirewallRuleInterface = new NeutronFirewallRuleInterface(providerContext);
121 ServiceRegistration<INeutronFirewallRuleCRUD> neutronFirewallRuleInterfaceRegistration = context.registerService(INeutronFirewallRuleCRUD.class, neutronFirewallRuleInterface, null);
122 if(neutronFirewallRuleInterfaceRegistration != null) {
123 registrations.add(neutronFirewallRuleInterfaceRegistration);