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.lang.reflect.Method;
12 import java.util.ArrayList;
13 import java.util.HashSet;
14 import java.util.List;
15 import java.util.Map.Entry;
17 import java.util.concurrent.ConcurrentHashMap;
18 import java.util.concurrent.ConcurrentMap;
20 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
21 import org.opendaylight.neutron.spi.INeutronLoadBalancerPoolCRUD;
22 import org.opendaylight.neutron.spi.NeutronLoadBalancerPool;
23 import org.opendaylight.yangtools.yang.binding.DataObject;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 public class NeutronLoadBalancerPoolInterface extends AbstractNeutronInterface implements INeutronLoadBalancerPoolCRUD {
29 private static final Logger logger = LoggerFactory.getLogger(NeutronLoadBalancerPoolInterface.class);
30 private ConcurrentMap<String, NeutronLoadBalancerPool> loadBalancerPoolDB = new ConcurrentHashMap<String, NeutronLoadBalancerPool>();
33 NeutronLoadBalancerPoolInterface(ProviderContext providerContext) {
34 super(providerContext);
37 // this method uses reflection to update an object from it's delta.
39 private boolean overwrite(Object target, Object delta) {
40 Method[] methods = target.getClass().getMethods();
42 for (Method toMethod : methods) {
43 if (toMethod.getDeclaringClass().equals(target.getClass())
44 && toMethod.getName().startsWith("set")) {
46 String toName = toMethod.getName();
47 String fromName = toName.replace("set", "get");
50 Method fromMethod = delta.getClass().getMethod(fromName);
51 Object value = fromMethod.invoke(delta, (Object[]) null);
53 toMethod.invoke(target, value);
55 } catch (Exception e) {
65 public boolean neutronLoadBalancerPoolExists(String uuid) {
66 return loadBalancerPoolDB.containsKey(uuid);
70 public NeutronLoadBalancerPool getNeutronLoadBalancerPool(String uuid) {
71 if (!neutronLoadBalancerPoolExists(uuid)) {
72 logger.debug("No LoadBalancerPool has Been Defined");
75 return loadBalancerPoolDB.get(uuid);
79 public List<NeutronLoadBalancerPool> getAllNeutronLoadBalancerPools() {
80 Set<NeutronLoadBalancerPool> allLoadBalancerPools = new HashSet<NeutronLoadBalancerPool>();
81 for (Entry<String, NeutronLoadBalancerPool> entry : loadBalancerPoolDB.entrySet()) {
82 NeutronLoadBalancerPool loadBalancerPool = entry.getValue();
83 allLoadBalancerPools.add(loadBalancerPool);
85 logger.debug("Exiting getLoadBalancerPools, Found {} OpenStackLoadBalancerPool", allLoadBalancerPools.size());
86 List<NeutronLoadBalancerPool> ans = new ArrayList<NeutronLoadBalancerPool>();
87 ans.addAll(allLoadBalancerPools);
92 public boolean addNeutronLoadBalancerPool(NeutronLoadBalancerPool input) {
93 if (neutronLoadBalancerPoolExists(input.getLoadBalancerPoolID())) {
96 loadBalancerPoolDB.putIfAbsent(input.getLoadBalancerPoolID(), input);
97 //TODO: add code to find INeutronLoadBalancerPoolAware services and call newtorkCreated on them
102 public boolean removeNeutronLoadBalancerPool(String uuid) {
103 if (!neutronLoadBalancerPoolExists(uuid)) {
106 loadBalancerPoolDB.remove(uuid);
107 //TODO: add code to find INeutronLoadBalancerPoolAware services and call newtorkDeleted on them
112 public boolean updateNeutronLoadBalancerPool(String uuid, NeutronLoadBalancerPool delta) {
113 if (!neutronLoadBalancerPoolExists(uuid)) {
116 NeutronLoadBalancerPool target = loadBalancerPoolDB.get(uuid);
117 return overwrite(target, delta);
121 public boolean neutronLoadBalancerPoolInUse(String loadBalancerPoolUUID) {
122 return !neutronLoadBalancerPoolExists(loadBalancerPoolUUID);
126 protected InstanceIdentifier createInstanceIdentifier(DataObject item) {
127 // TODO Auto-generated method stub
132 protected DataObject toMd(Object neutronObject) {
133 // TODO Auto-generated method stub
138 protected DataObject toMd(String uuid) {
139 // TODO Auto-generated method stub