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 LOG = 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 toMdIds(healthMonitor, healthmonitorBuilder);
55 healthmonitorBuilder.setAdminStateUp(healthMonitor.getLoadBalancerHealthMonitorAdminStateIsUp());
56 if (healthMonitor.getLoadBalancerHealthMonitorDelay() != null) {
57 healthmonitorBuilder.setDelay(Long.valueOf(healthMonitor.getLoadBalancerHealthMonitorDelay()));
59 if (healthMonitor.getLoadBalancerHealthMonitorExpectedCodes() != null) {
60 healthmonitorBuilder.setExpectedCodes(healthMonitor.getLoadBalancerHealthMonitorExpectedCodes());
62 if (healthMonitor.getLoadBalancerHealthMonitorHttpMethod() != null) {
63 healthmonitorBuilder.setHttpMethod(healthMonitor.getLoadBalancerHealthMonitorHttpMethod());
65 if (healthMonitor.getLoadBalancerHealthMonitorMaxRetries() != null) {
66 healthmonitorBuilder.setMaxRetries(Integer.valueOf(healthMonitor.getLoadBalancerHealthMonitorMaxRetries()));
68 if (healthMonitor.getLoadBalancerHealthMonitorPools() != null) {
69 final List<Uuid> listUuid = new ArrayList<>();
70 for (final NeutronID neutronId : healthMonitor.getLoadBalancerHealthMonitorPools()) {
71 listUuid.add(toUuid(neutronId.getID()));
73 healthmonitorBuilder.setPools(listUuid);
75 if (healthMonitor.getLoadBalancerHealthMonitorTimeout() != null) {
76 healthmonitorBuilder.setTimeout(Long.valueOf(healthMonitor.getLoadBalancerHealthMonitorTimeout()));
78 if (healthMonitor.getLoadBalancerHealthMonitorType() != null) {
79 final ImmutableBiMap<String, Class<? extends ProbeBase>> mapper = PROBE_MAP.inverse();
81 .setType(mapper.get(healthMonitor.getLoadBalancerHealthMonitorType()));
83 if (healthMonitor.getLoadBalancerHealthMonitorUrlPath() != null) {
84 healthmonitorBuilder.setUrlPath(healthMonitor.getLoadBalancerHealthMonitorUrlPath());
86 return healthmonitorBuilder.build();
90 protected NeutronLoadBalancerHealthMonitor fromMd(Healthmonitor healthMonitor) {
91 final NeutronLoadBalancerHealthMonitor answer = new NeutronLoadBalancerHealthMonitor();
92 fromMdIds(healthMonitor, answer);
93 if (healthMonitor.isAdminStateUp() != null) {
94 answer.setLoadBalancerHealthMonitorAdminStateIsUp(healthMonitor.isAdminStateUp());
96 if (healthMonitor.getDelay() != null) {
97 answer.setLoadBalancerHealthMonitorDelay(healthMonitor.getDelay().intValue());
99 if (healthMonitor.getExpectedCodes() != null) {
100 answer.setLoadBalancerHealthMonitorExpectedCodes(healthMonitor.getExpectedCodes());
102 if (healthMonitor.getHttpMethod() != null) {
103 answer.setLoadBalancerHealthMonitorHttpMethod(healthMonitor.getHttpMethod());
105 if (healthMonitor.getMaxRetries() != null) {
106 answer.setLoadBalancerHealthMonitorMaxRetries(Integer.valueOf(healthMonitor.getMaxRetries()));
108 if (healthMonitor.getPools() != null) {
109 final List<NeutronID> list = new ArrayList<>();
110 for (final Uuid id : healthMonitor.getPools()) {
111 list.add(new NeutronID(id.getValue()));
113 answer.setLoadBalancerHealthMonitorPools(list);
115 if (healthMonitor.getTimeout() != null) {
116 answer.setLoadBalancerHealthMonitorTimeout(healthMonitor.getTimeout().intValue());
118 if (healthMonitor.getType() != null) {
119 answer.setLoadBalancerHealthMonitorType(PROBE_MAP.get(healthMonitor.getType()));
121 if (healthMonitor.getUrlPath() != null) {
122 answer.setLoadBalancerHealthMonitorUrlPath(healthMonitor.getUrlPath());