add blueprint wiring for neutron/transcriber
[neutron.git] / transcriber / src / main / java / org / opendaylight / neutron / transcriber / NeutronLoadBalancerHealthMonitorInterface.java
1 /*
2  * Copyright (c) 2014, 2015 Red Hat, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.neutron.transcriber;
10
11 import java.util.ArrayList;
12 import java.util.List;
13
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.neutron.spi.INeutronLoadBalancerHealthMonitorCRUD;
16 import org.opendaylight.neutron.spi.NeutronLoadBalancerHealthMonitor;
17 import org.opendaylight.neutron.spi.Neutron_ID;
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.rev150712.Neutron;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 import com.google.common.collect.ImmutableBiMap;
33
34 public class NeutronLoadBalancerHealthMonitorInterface extends AbstractNeutronInterface<Healthmonitor, Healthmonitors, NeutronLoadBalancerHealthMonitor> implements INeutronLoadBalancerHealthMonitorCRUD {
35     private static final Logger LOGGER = LoggerFactory.getLogger(NeutronLoadBalancerHealthMonitorInterface.class);
36
37     private static final ImmutableBiMap<Class<? extends ProbeBase>,String> PROBE_MAP
38             = new ImmutableBiMap.Builder<Class<? extends ProbeBase>,String>()
39             .put(ProbeHttp.class,"HTTP")
40             .put(ProbeHttps.class,"HTTPS")
41             .put(ProbePing.class,"PING")
42             .put(ProbeTcp.class,"TCP")
43             .build();
44
45
46     NeutronLoadBalancerHealthMonitorInterface(DataBroker db) {
47         super(db);
48     }
49
50     @Override
51     protected List<Healthmonitor> getDataObjectList(Healthmonitors healthMonitors) {
52         return healthMonitors.getHealthmonitor();
53     }
54
55     @Override
56     protected Healthmonitor toMd(String uuid) {
57         final HealthmonitorBuilder healthmonitorBuilder = new HealthmonitorBuilder();
58         healthmonitorBuilder.setUuid(toUuid(uuid));
59         return healthmonitorBuilder.build();
60     }
61
62     @Override
63     protected InstanceIdentifier<Healthmonitor> createInstanceIdentifier(
64             Healthmonitor healthMonitor) {
65         return InstanceIdentifier.create(Neutron.class)
66                 .child(Healthmonitors.class )
67                 .child(Healthmonitor.class, healthMonitor.getKey());
68     }
69
70     @Override
71     protected InstanceIdentifier<Healthmonitors> createInstanceIdentifier() {
72         return InstanceIdentifier.create(Neutron.class)
73                 .child(Healthmonitors.class);
74     }
75
76     @Override
77     protected Healthmonitor toMd(NeutronLoadBalancerHealthMonitor healthMonitor) {
78         final HealthmonitorBuilder healthmonitorBuilder = new HealthmonitorBuilder();
79         healthmonitorBuilder.setAdminStateUp(healthMonitor.getLoadBalancerHealthMonitorAdminStateIsUp());
80         if (healthMonitor.getLoadBalancerHealthMonitorDelay() != null) {
81             healthmonitorBuilder.setDelay(Long.valueOf(healthMonitor.getLoadBalancerHealthMonitorDelay()));
82         }
83         if (healthMonitor.getLoadBalancerHealthMonitorExpectedCodes() != null) {
84             healthmonitorBuilder.setExpectedCodes(healthMonitor.getLoadBalancerHealthMonitorExpectedCodes());
85         }
86         if (healthMonitor.getLoadBalancerHealthMonitorHttpMethod() != null) {
87             healthmonitorBuilder.setHttpMethod(healthMonitor.getLoadBalancerHealthMonitorHttpMethod());
88         }
89         if (healthMonitor.getLoadBalancerHealthMonitorMaxRetries() != null) {
90             healthmonitorBuilder.setMaxRetries(Integer.valueOf(healthMonitor.getLoadBalancerHealthMonitorMaxRetries()));
91         }
92         if (healthMonitor.getLoadBalancerHealthMonitorPools() != null) {
93             final List<Uuid> listUuid = new ArrayList<Uuid>();
94             for (final Neutron_ID neutron_id : healthMonitor.getLoadBalancerHealthMonitorPools()) {
95                 listUuid.add(toUuid(neutron_id.getID()));
96             }
97             healthmonitorBuilder.setPools(listUuid);
98         }
99         if (healthMonitor.getTenantID() != null) {
100             healthmonitorBuilder.setTenantId(toUuid(healthMonitor.getTenantID()));
101         }
102         if (healthMonitor.getLoadBalancerHealthMonitorTimeout() != null) {
103             healthmonitorBuilder.setTimeout(Long.valueOf(healthMonitor.getLoadBalancerHealthMonitorTimeout()));
104         }
105         if (healthMonitor.getLoadBalancerHealthMonitorType() != null) {
106             final ImmutableBiMap<String, Class<? extends ProbeBase>> mapper =
107                     PROBE_MAP.inverse();
108             healthmonitorBuilder.setType((Class<? extends ProbeBase>) mapper.get(healthMonitor.getLoadBalancerHealthMonitorType()));
109         }
110         if (healthMonitor.getLoadBalancerHealthMonitorUrlPath() != null) {
111             healthmonitorBuilder.setUrlPath(healthMonitor.getLoadBalancerHealthMonitorUrlPath());
112         }
113         if (healthMonitor.getID() != null) {
114             healthmonitorBuilder.setUuid(toUuid(healthMonitor.getID()));
115         } else {
116             LOGGER.warn("Attempting to write neutron laod balancer health monitor without UUID");
117         }
118         return healthmonitorBuilder.build();
119     }
120
121     protected NeutronLoadBalancerHealthMonitor fromMd(Healthmonitor healthMonitor) {
122         final NeutronLoadBalancerHealthMonitor answer = new NeutronLoadBalancerHealthMonitor();
123         if (healthMonitor.isAdminStateUp() != null) {
124              answer.setLoadBalancerHealthMonitorAdminStateIsUp(healthMonitor.isAdminStateUp());
125         }
126         if (healthMonitor.getDelay() != null) {
127             answer.setLoadBalancerHealthMonitorDelay(healthMonitor.getDelay().intValue());
128         }
129         if (healthMonitor.getExpectedCodes() != null) {
130             answer.setLoadBalancerHealthMonitorExpectedCodes(healthMonitor.getExpectedCodes());
131         }
132         if (healthMonitor.getHttpMethod() != null) {
133             answer.setLoadBalancerHealthMonitorHttpMethod(healthMonitor.getHttpMethod());
134         }
135         if (healthMonitor.getMaxRetries() != null) {
136             answer.setLoadBalancerHealthMonitorMaxRetries(Integer.valueOf(healthMonitor.getMaxRetries()));
137         }
138         if (healthMonitor.getPools() != null) {
139             final List<Neutron_ID> list = new ArrayList<Neutron_ID>();
140             for (final Uuid id : healthMonitor.getPools()) {
141                 list.add(new Neutron_ID(id.getValue()));
142             }
143             answer.setLoadBalancerHealthMonitorPools(list);
144         }
145         if (healthMonitor.getTenantId() != null) {
146             answer.setTenantID(healthMonitor.getTenantId());
147         }
148         if (healthMonitor.getTimeout() != null) {
149             answer.setLoadBalancerHealthMonitorTimeout(healthMonitor.getTimeout().intValue());
150         }
151         if (healthMonitor.getType() != null) {
152             answer.setLoadBalancerHealthMonitorType(PROBE_MAP.get(healthMonitor.getType()));
153         }
154         if (healthMonitor.getUrlPath() != null) {
155             answer.setLoadBalancerHealthMonitorUrlPath(healthMonitor.getUrlPath());
156         }
157         if (healthMonitor.getUuid() != null) {
158             answer.setID(healthMonitor.getUuid().getValue());
159         } else {
160             LOGGER.warn("Attempting to write neutron laod balancer health monitor without UUID");
161         }
162         return answer;
163     }
164 }