jiangrui
Committed by Gerrit Code Review

[ONOS-2755] add restfull service of floatingIp

Change-Id: Ife1ee53639f64136d72267d205c71d2766d7d97b
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.vtnweb.web;
17 +
18 +import static com.google.common.base.Preconditions.checkNotNull;
19 +
20 +import java.util.Iterator;
21 +import java.util.List;
22 +
23 +import org.onosproject.codec.CodecContext;
24 +import org.onosproject.codec.JsonCodec;
25 +import org.onosproject.vtnrsc.FloatingIp;
26 +
27 +import com.fasterxml.jackson.databind.node.ObjectNode;
28 +
29 +/**
30 + * FloatingIp JSON codec.
31 + */
32 +public final class FloatingIpCodec extends JsonCodec<FloatingIp> {
33 + @Override
34 + public ObjectNode encode(FloatingIp floatingIp, CodecContext context) {
35 + checkNotNull(floatingIp, "floatingIp cannot be null");
36 + ObjectNode result = context
37 + .mapper()
38 + .createObjectNode()
39 + .put("id", floatingIp.id().floatingIpId().toString())
40 + .put("floating_network_id", floatingIp.networkId().toString())
41 + .put("router_id",
42 + floatingIp.routerId() == null ? null : floatingIp
43 + .routerId().routerId())
44 + .put("tenant_id", floatingIp.tenantId().toString())
45 + .put("port_id",
46 + floatingIp.portId() == null ? null : floatingIp.portId()
47 + .toString())
48 + .put("fixed_ip_address",
49 + floatingIp.fixedIp() == null ? null : floatingIp.fixedIp()
50 + .toString())
51 + .put("floating_ip_address", floatingIp.floatingIp().toString())
52 + .put("status", floatingIp.status().toString());
53 + return result;
54 + }
55 +
56 + public ObjectNode extracFields(FloatingIp floatingIp, CodecContext context,
57 + List<String> fields) {
58 + checkNotNull(floatingIp, "floatingIp cannot be null");
59 + ObjectNode result = context.mapper().createObjectNode();
60 + Iterator<String> i = fields.iterator();
61 + while (i.hasNext()) {
62 + String s = i.next();
63 + if (s.equals("floating_network_id")) {
64 + result.put("floating_network_id", floatingIp.networkId()
65 + .toString());
66 + }
67 + if (s.equals("router_id")) {
68 + result.put("router_id",
69 + floatingIp.routerId() == null ? null : floatingIp
70 + .routerId().routerId());
71 + }
72 + if (s.equals("tenant_id")) {
73 + result.put("tenant_id", floatingIp.tenantId().toString());
74 + }
75 + if (s.equals("port_id")) {
76 + result.put("port_id",
77 + floatingIp.portId() == null ? null : floatingIp
78 + .portId().toString());
79 + }
80 + if (s.equals("id")) {
81 + result.put("id", floatingIp.id().floatingIpId().toString());
82 + }
83 + if (s.equals("fixed_ip_address")) {
84 + result.put("fixed_ip_address",
85 + floatingIp.fixedIp() == null ? null : floatingIp
86 + .fixedIp().toString());
87 + }
88 + if (s.equals("floating_ip_address")) {
89 + result.put("floating_ip_address", floatingIp.floatingIp()
90 + .toString());
91 + }
92 + if (s.equals("status")) {
93 + result.put("status", floatingIp.status().toString());
94 + }
95 + }
96 + return result;
97 + }
98 +}
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
37 org.onosproject.vtnweb.resources.PortChainWebResource 37 org.onosproject.vtnweb.resources.PortChainWebResource
38 org.onosproject.vtnweb.resources.PortPairGroupWebResource 38 org.onosproject.vtnweb.resources.PortPairGroupWebResource
39 org.onosproject.vtnweb.resources.PortPairWebResource 39 org.onosproject.vtnweb.resources.PortPairWebResource
40 + org.onosproject.vtnweb.resources.FloatingIpWebResource
41 + org.onosproject.vtnweb.resources.RouterWebResource
40 </param-value> 42 </param-value>
41 </init-param> 43 </init-param>
42 <load-on-startup>1</load-on-startup> 44 <load-on-startup>1</load-on-startup>
......