package org.opendaylight.neutron.transcriber;
+import com.google.common.collect.ImmutableBiMap;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.neutron.spi.INeutronLoadBalancerHealthMonitorCRUD;
import org.opendaylight.neutron.spi.NeutronLoadBalancerHealthMonitor;
import org.opendaylight.neutron.spi.Neutron_ID;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev160807.ProbeBase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev160807.ProbeHttp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev160807.ProbeHttps;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev160807.ProbeIcmp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev160807.ProbeTcp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.lbaasv2.rev141002.lbaas.attributes.Healthmonitors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.lbaasv2.rev141002.lbaas.attributes.healthmonitors.Healthmonitor;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.lbaasv2.rev141002.lbaas.attributes.healthmonitors.HealthmonitorBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150325.Neutron;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.ProbeBase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.ProbeHttp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.ProbeHttps;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.ProbePing;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.ProbeTcp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.lbaasv2.rev150712.lbaas.attributes.Healthmonitors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.lbaasv2.rev150712.lbaas.attributes.healthmonitors.Healthmonitor;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.lbaasv2.rev150712.lbaas.attributes.healthmonitors.HealthmonitorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.collect.ImmutableBiMap;
-
-public class NeutronLoadBalancerHealthMonitorInterface extends AbstractNeutronInterface<Healthmonitor, NeutronLoadBalancerHealthMonitor> implements INeutronLoadBalancerHealthMonitorCRUD {
+public final class NeutronLoadBalancerHealthMonitorInterface
+ extends AbstractNeutronInterface<Healthmonitor, Healthmonitors, NeutronLoadBalancerHealthMonitor>
+ implements INeutronLoadBalancerHealthMonitorCRUD {
private static final Logger LOGGER = LoggerFactory.getLogger(NeutronLoadBalancerHealthMonitorInterface.class);
- private ConcurrentMap<String, NeutronLoadBalancerHealthMonitor> loadBalancerHealthMonitorDB = new ConcurrentHashMap<String, NeutronLoadBalancerHealthMonitor>();
-
- private static final ImmutableBiMap<Class<? extends ProbeBase>,String> PROBE_MAP
- = new ImmutableBiMap.Builder<Class<? extends ProbeBase>,String>()
- .put(ProbeHttp.class,"HTTP")
- .put(ProbeHttps.class,"HTTPS")
- .put(ProbeIcmp.class,"ICMP")
- .put(ProbeTcp.class,"TCP")
- .build();
-
-
- NeutronLoadBalancerHealthMonitorInterface(ProviderContext providerContext) {
- super(providerContext);
- }
-
- @Override
- public boolean neutronLoadBalancerHealthMonitorExists(String uuid) {
- Healthmonitor healthMonitor = readMd(createInstanceIdentifier(toMd(uuid)));
- if (healthMonitor == null) {
- return false;
- }
- return true;
- }
- @Override
- public NeutronLoadBalancerHealthMonitor getNeutronLoadBalancerHealthMonitor(String uuid) {
- Healthmonitor healthMonitor = readMd(createInstanceIdentifier(toMd(uuid)));
- if (healthMonitor == null) {
- return null;
- }
- return fromMd(healthMonitor);
- }
+ private static final ImmutableBiMap<Class<? extends ProbeBase>,
+ String> PROBE_MAP = new ImmutableBiMap.Builder<Class<? extends ProbeBase>, String>()
+ .put(ProbeHttp.class, "HTTP").put(ProbeHttps.class, "HTTPS").put(ProbePing.class, "PING")
+ .put(ProbeTcp.class, "TCP").build();
- @Override
- public List<NeutronLoadBalancerHealthMonitor> getAllNeutronLoadBalancerHealthMonitors() {
- Set<NeutronLoadBalancerHealthMonitor> allLoadBalancerHealthMonitors = new HashSet<NeutronLoadBalancerHealthMonitor>();
- Healthmonitors healthMonitors = readMd(createInstanceIdentifier());
- if (healthMonitors != null) {
- for (Healthmonitor healthMonitor : healthMonitors.getHealthmonitor()) {
- allLoadBalancerHealthMonitors.add(fromMd(healthMonitor));
- }
- }
- LOGGER.debug("Exiting getLoadBalancerHealthMonitors, Found {} OpenStackLoadBalancerHealthMonitor", allLoadBalancerHealthMonitors.size());
- List<NeutronLoadBalancerHealthMonitor> ans = new ArrayList<NeutronLoadBalancerHealthMonitor>();
- ans.addAll(allLoadBalancerHealthMonitors);
- return ans;
+ NeutronLoadBalancerHealthMonitorInterface(DataBroker db) {
+ super(HealthmonitorBuilder.class, db);
}
@Override
- public boolean addNeutronLoadBalancerHealthMonitor(NeutronLoadBalancerHealthMonitor input) {
- if (neutronLoadBalancerHealthMonitorExists(input.getID())) {
- return false;
- }
- addMd(input);
- return true;
+ protected List<Healthmonitor> getDataObjectList(Healthmonitors healthMonitors) {
+ return healthMonitors.getHealthmonitor();
}
@Override
- public boolean removeNeutronLoadBalancerHealthMonitor(String uuid) {
- if (!neutronLoadBalancerHealthMonitorExists(uuid)) {
- return false;
- }
- return removeMd(toMd(uuid));
- }
-
- @Override
- public boolean updateNeutronLoadBalancerHealthMonitor(String uuid, NeutronLoadBalancerHealthMonitor delta) {
- if (!neutronLoadBalancerHealthMonitorExists(uuid)) {
- return false;
- }
- updateMd(delta);
- return true;
- }
-
- @Override
- public boolean neutronLoadBalancerHealthMonitorInUse(String loadBalancerHealthMonitorUUID) {
- return !neutronLoadBalancerHealthMonitorExists(loadBalancerHealthMonitorUUID);
- }
-
- @Override
- protected Healthmonitor toMd(String uuid) {
- HealthmonitorBuilder healthmonitorBuilder = new HealthmonitorBuilder();
- healthmonitorBuilder.setUuid(toUuid(uuid));
- return healthmonitorBuilder.build();
- }
-
- @Override
- protected InstanceIdentifier<Healthmonitor> createInstanceIdentifier(
- Healthmonitor healthMonitor) {
- return InstanceIdentifier.create(Neutron.class)
- .child(Healthmonitors.class )
- .child(Healthmonitor.class, healthMonitor.getKey());
- }
-
- protected InstanceIdentifier<Healthmonitors> createInstanceIdentifier() {
- return InstanceIdentifier.create(Neutron.class)
- .child(Healthmonitors.class);
+ protected InstanceIdentifier<Healthmonitor> createInstanceIdentifier(Healthmonitor healthMonitor) {
+ return InstanceIdentifier.create(Neutron.class).child(Healthmonitors.class).child(Healthmonitor.class,
+ healthMonitor.getKey());
}
@Override
protected Healthmonitor toMd(NeutronLoadBalancerHealthMonitor healthMonitor) {
- HealthmonitorBuilder healthmonitorBuilder = new HealthmonitorBuilder();
+ final HealthmonitorBuilder healthmonitorBuilder = new HealthmonitorBuilder();
healthmonitorBuilder.setAdminStateUp(healthMonitor.getLoadBalancerHealthMonitorAdminStateIsUp());
if (healthMonitor.getLoadBalancerHealthMonitorDelay() != null) {
healthmonitorBuilder.setDelay(Long.valueOf(healthMonitor.getLoadBalancerHealthMonitorDelay()));
healthmonitorBuilder.setMaxRetries(Integer.valueOf(healthMonitor.getLoadBalancerHealthMonitorMaxRetries()));
}
if (healthMonitor.getLoadBalancerHealthMonitorPools() != null) {
- List<Uuid> listUuid = new ArrayList<Uuid>();
- for (Neutron_ID neutron_id : healthMonitor.getLoadBalancerHealthMonitorPools()) {
+ final List<Uuid> listUuid = new ArrayList<Uuid>();
+ for (final Neutron_ID neutron_id : healthMonitor.getLoadBalancerHealthMonitorPools()) {
listUuid.add(toUuid(neutron_id.getID()));
}
healthmonitorBuilder.setPools(listUuid);
}
- if (healthMonitor.getLoadBalancerHealthMonitorTenantID() != null) {
- healthmonitorBuilder.setTenantId(toUuid(healthMonitor.getLoadBalancerHealthMonitorTenantID()));
+ if (healthMonitor.getTenantID() != null) {
+ healthmonitorBuilder.setTenantId(toUuid(healthMonitor.getTenantID()));
}
if (healthMonitor.getLoadBalancerHealthMonitorTimeout() != null) {
healthmonitorBuilder.setTimeout(Long.valueOf(healthMonitor.getLoadBalancerHealthMonitorTimeout()));
}
if (healthMonitor.getLoadBalancerHealthMonitorType() != null) {
- ImmutableBiMap<String, Class<? extends ProbeBase>> mapper =
- PROBE_MAP.inverse();
- healthmonitorBuilder.setType((Class<? extends ProbeBase>) mapper.get(healthMonitor.getLoadBalancerHealthMonitorType()));
+ final ImmutableBiMap<String, Class<? extends ProbeBase>> mapper = PROBE_MAP.inverse();
+ healthmonitorBuilder
+ .setType((Class<? extends ProbeBase>) mapper.get(healthMonitor.getLoadBalancerHealthMonitorType()));
}
if (healthMonitor.getLoadBalancerHealthMonitorUrlPath() != null) {
healthmonitorBuilder.setUrlPath(healthMonitor.getLoadBalancerHealthMonitorUrlPath());
}
protected NeutronLoadBalancerHealthMonitor fromMd(Healthmonitor healthMonitor) {
- NeutronLoadBalancerHealthMonitor answer = new NeutronLoadBalancerHealthMonitor();
+ final NeutronLoadBalancerHealthMonitor answer = new NeutronLoadBalancerHealthMonitor();
if (healthMonitor.isAdminStateUp() != null) {
- answer.setLoadBalancerHealthMonitorAdminStateIsUp(healthMonitor.isAdminStateUp());
+ answer.setLoadBalancerHealthMonitorAdminStateIsUp(healthMonitor.isAdminStateUp());
}
if (healthMonitor.getDelay() != null) {
answer.setLoadBalancerHealthMonitorDelay(healthMonitor.getDelay().intValue());
answer.setLoadBalancerHealthMonitorMaxRetries(Integer.valueOf(healthMonitor.getMaxRetries()));
}
if (healthMonitor.getPools() != null) {
- List<Neutron_ID> list = new ArrayList<Neutron_ID>();
- for (Uuid id : healthMonitor.getPools()) {
+ final List<Neutron_ID> list = new ArrayList<Neutron_ID>();
+ for (final Uuid id : healthMonitor.getPools()) {
list.add(new Neutron_ID(id.getValue()));
}
answer.setLoadBalancerHealthMonitorPools(list);
}
if (healthMonitor.getTenantId() != null) {
- answer.setLoadBalancerHealthMonitorTenantID(healthMonitor.getTenantId().getValue().replace("-",""));
+ answer.setTenantID(healthMonitor.getTenantId());
}
if (healthMonitor.getTimeout() != null) {
answer.setLoadBalancerHealthMonitorTimeout(healthMonitor.getTimeout().intValue());
}
return answer;
}
-
- public static void registerNewInterface(BundleContext context,
- ProviderContext providerContext,
- List<ServiceRegistration<?>> registrations) {
- NeutronLoadBalancerHealthMonitorInterface neutronLoadBalancerHealthMonitorInterface = new NeutronLoadBalancerHealthMonitorInterface(providerContext);
- ServiceRegistration<INeutronLoadBalancerHealthMonitorCRUD> neutronLoadBalancerHealthMonitorInterfaceRegistration = context.registerService(INeutronLoadBalancerHealthMonitorCRUD.class, neutronLoadBalancerHealthMonitorInterface, null);
- if(neutronLoadBalancerHealthMonitorInterfaceRegistration != null) {
- registrations.add(neutronLoadBalancerHealthMonitorInterfaceRegistration);
- }
- }
}