2 * Copyright (c) 2014, 2015 Red Hat, Inc. and others. All rights reserved.
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 com.google.common.collect.ImmutableBiMap;
12 import java.util.ArrayList;
13 import java.util.List;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.neutron.spi.INeutronLoadBalancerHealthMonitorCRUD;
16 import org.opendaylight.neutron.spi.NeutronID;
17 import org.opendaylight.neutron.spi.NeutronLoadBalancerHealthMonitor;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.ProbeBase;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.ProbeHttp;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.ProbeHttps;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.ProbePing;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.ProbeTcp;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.lbaasv2.rev150712.lbaas.attributes.Healthmonitors;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.lbaasv2.rev150712.lbaas.attributes.healthmonitors.Healthmonitor;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.lbaasv2.rev150712.lbaas.attributes.healthmonitors.HealthmonitorBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.lbaasv2.rev150712.lbaas.attributes.healthmonitors.HealthmonitorKey;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 public final class NeutronLoadBalancerHealthMonitorInterface
32 extends AbstractNeutronInterface<Healthmonitor, Healthmonitors, HealthmonitorKey,
33 NeutronLoadBalancerHealthMonitor>
34 implements INeutronLoadBalancerHealthMonitorCRUD {
35 private static final Logger LOGGER = LoggerFactory.getLogger(NeutronLoadBalancerHealthMonitorInterface.class);
37 private static final ImmutableBiMap<Class<? extends ProbeBase>,
38 String> PROBE_MAP = new ImmutableBiMap.Builder<Class<? extends ProbeBase>, String>()
39 .put(ProbeHttp.class, "HTTP").put(ProbeHttps.class, "HTTPS").put(ProbePing.class, "PING")
40 .put(ProbeTcp.class, "TCP").build();
42 NeutronLoadBalancerHealthMonitorInterface(DataBroker db) {
43 super(HealthmonitorBuilder.class, db);
47 protected List<Healthmonitor> getDataObjectList(Healthmonitors healthMonitors) {
48 return healthMonitors.getHealthmonitor();
52 protected Healthmonitor toMd(NeutronLoadBalancerHealthMonitor healthMonitor) {
53 final HealthmonitorBuilder healthmonitorBuilder = new HealthmonitorBuilder();
54 healthmonitorBuilder.setAdminStateUp(healthMonitor.getLoadBalancerHealthMonitorAdminStateIsUp());
55 if (healthMonitor.getLoadBalancerHealthMonitorDelay() != null) {
56 healthmonitorBuilder.setDelay(Long.valueOf(healthMonitor.getLoadBalancerHealthMonitorDelay()));
58 if (healthMonitor.getLoadBalancerHealthMonitorExpectedCodes() != null) {
59 healthmonitorBuilder.setExpectedCodes(healthMonitor.getLoadBalancerHealthMonitorExpectedCodes());
61 if (healthMonitor.getLoadBalancerHealthMonitorHttpMethod() != null) {
62 healthmonitorBuilder.setHttpMethod(healthMonitor.getLoadBalancerHealthMonitorHttpMethod());
64 if (healthMonitor.getLoadBalancerHealthMonitorMaxRetries() != null) {
65 healthmonitorBuilder.setMaxRetries(Integer.valueOf(healthMonitor.getLoadBalancerHealthMonitorMaxRetries()));
67 if (healthMonitor.getLoadBalancerHealthMonitorPools() != null) {
68 final List<Uuid> listUuid = new ArrayList<Uuid>();
69 for (final NeutronID neutronId : healthMonitor.getLoadBalancerHealthMonitorPools()) {
70 listUuid.add(toUuid(neutronId.getID()));
72 healthmonitorBuilder.setPools(listUuid);
74 if (healthMonitor.getTenantID() != null) {
75 healthmonitorBuilder.setTenantId(toUuid(healthMonitor.getTenantID()));
77 if (healthMonitor.getLoadBalancerHealthMonitorTimeout() != null) {
78 healthmonitorBuilder.setTimeout(Long.valueOf(healthMonitor.getLoadBalancerHealthMonitorTimeout()));
80 if (healthMonitor.getLoadBalancerHealthMonitorType() != null) {
81 final ImmutableBiMap<String, Class<? extends ProbeBase>> mapper = PROBE_MAP.inverse();
83 .setType((Class<? extends ProbeBase>) mapper.get(healthMonitor.getLoadBalancerHealthMonitorType()));
85 if (healthMonitor.getLoadBalancerHealthMonitorUrlPath() != null) {
86 healthmonitorBuilder.setUrlPath(healthMonitor.getLoadBalancerHealthMonitorUrlPath());
88 if (healthMonitor.getID() != null) {
89 healthmonitorBuilder.setUuid(toUuid(healthMonitor.getID()));
91 LOGGER.warn("Attempting to write neutron laod balancer health monitor without UUID");
93 return healthmonitorBuilder.build();
96 protected NeutronLoadBalancerHealthMonitor fromMd(Healthmonitor healthMonitor) {
97 final NeutronLoadBalancerHealthMonitor answer = new NeutronLoadBalancerHealthMonitor();
98 if (healthMonitor.isAdminStateUp() != null) {
99 answer.setLoadBalancerHealthMonitorAdminStateIsUp(healthMonitor.isAdminStateUp());
101 if (healthMonitor.getDelay() != null) {
102 answer.setLoadBalancerHealthMonitorDelay(healthMonitor.getDelay().intValue());
104 if (healthMonitor.getExpectedCodes() != null) {
105 answer.setLoadBalancerHealthMonitorExpectedCodes(healthMonitor.getExpectedCodes());
107 if (healthMonitor.getHttpMethod() != null) {
108 answer.setLoadBalancerHealthMonitorHttpMethod(healthMonitor.getHttpMethod());
110 if (healthMonitor.getMaxRetries() != null) {
111 answer.setLoadBalancerHealthMonitorMaxRetries(Integer.valueOf(healthMonitor.getMaxRetries()));
113 if (healthMonitor.getPools() != null) {
114 final List<NeutronID> list = new ArrayList<NeutronID>();
115 for (final Uuid id : healthMonitor.getPools()) {
116 list.add(new NeutronID(id.getValue()));
118 answer.setLoadBalancerHealthMonitorPools(list);
120 if (healthMonitor.getTenantId() != null) {
121 answer.setTenantID(healthMonitor.getTenantId());
123 if (healthMonitor.getTimeout() != null) {
124 answer.setLoadBalancerHealthMonitorTimeout(healthMonitor.getTimeout().intValue());
126 if (healthMonitor.getType() != null) {
127 answer.setLoadBalancerHealthMonitorType(PROBE_MAP.get(healthMonitor.getType()));
129 if (healthMonitor.getUrlPath() != null) {
130 answer.setLoadBalancerHealthMonitorUrlPath(healthMonitor.getUrlPath());
132 if (healthMonitor.getUuid() != null) {
133 answer.setID(healthMonitor.getUuid().getValue());
135 LOGGER.warn("Attempting to write neutron laod balancer health monitor without UUID");