2 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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.northbound.api;
11 import java.net.HttpURLConnection;
12 import java.util.ArrayList;
13 import java.util.Iterator;
14 import java.util.List;
15 import javax.ws.rs.Consumes;
16 import javax.ws.rs.DELETE;
17 import javax.ws.rs.DefaultValue;
18 import javax.ws.rs.GET;
19 import javax.ws.rs.POST;
20 import javax.ws.rs.PUT;
21 import javax.ws.rs.Path;
22 import javax.ws.rs.PathParam;
23 import javax.ws.rs.Produces;
24 import javax.ws.rs.QueryParam;
25 import javax.ws.rs.core.Context;
26 import javax.ws.rs.core.MediaType;
27 import javax.ws.rs.core.Response;
28 import javax.ws.rs.core.UriInfo;
29 import org.codehaus.enunciate.jaxrs.ResponseCode;
30 import org.codehaus.enunciate.jaxrs.StatusCodes;
31 import org.codehaus.enunciate.jaxrs.TypeHint;
32 import org.opendaylight.neutron.spi.INeutronBgpvpnCRUD;
33 import org.opendaylight.neutron.spi.NeutronBgpvpn;
34 import org.opendaylight.neutron.spi.NeutronCRUDInterfaces;
37 * Neutron Northbound REST APIs for Bgpvpn.<br>
38 * This class provides REST APIs for managing neutron Bgpvpns
42 * Authentication scheme : <b>HTTP Basic</b><br>
43 * Authentication realm : <b>opendaylight</b><br>
44 * Transport : <b>HTTP and HTTPS</b><br>
46 * HTTPS Authentication is disabled by default. Administrator can enable it in
47 * tomcat-server.xml after adding a proper keystore / SSL certificate from a
48 * trusted authority.<br>
50 * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
55 public class NeutronBgpvpnsNorthbound
56 extends AbstractNeutronNorthbound<NeutronBgpvpn, NeutronBgpvpnRequest, INeutronBgpvpnCRUD> {
61 private static final String RESOURCE_NAME = "Bgpvpn";
64 protected String getResourceName() {
69 protected NeutronBgpvpn extractFields(NeutronBgpvpn o, List<String> fields) {
70 return o.extractFields(fields);
74 protected NeutronBgpvpnRequest newNeutronRequest(NeutronBgpvpn o) {
75 return new NeutronBgpvpnRequest(o);
79 protected INeutronBgpvpnCRUD getNeutronCRUD() {
80 NeutronCRUDInterfaces answer = new NeutronCRUDInterfaces().fetchINeutronBgpvpnCRUD(this);
81 if (answer.getBgpvpnInterface() == null) {
82 throw new ServiceUnavailableException(serviceUnavailable());
84 return answer.getBgpvpnInterface();
88 * Returns a list of all Bgpvpns */
91 @Produces({ MediaType.APPLICATION_JSON })
92 //@TypeHint(OpenStackBgpvpns.class)
94 @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
95 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
96 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
97 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
98 public Response listBgpvpns(
100 @QueryParam("fields") List<String> fields,
101 // note: openstack isn't clear about filtering on lists, so we aren't handling them
102 @QueryParam("id") String queryID,
103 @QueryParam("name") String queryName,
104 @QueryParam("admin_state_up") String queryAdminStateUp,
105 @QueryParam("status") String queryStatus,
106 @QueryParam("tenant_id") String queryTenantID,
107 @QueryParam("type") String queryType,
108 @QueryParam("auto_aggregate") String queryAutoAggregate,
110 @QueryParam("limit") Integer limit,
111 @QueryParam("marker") String marker,
112 @DefaultValue("false") @QueryParam("page_reverse") Boolean pageReverse
113 // sorting not supported
115 INeutronBgpvpnCRUD bgpvpnInterface = getNeutronCRUD();
116 List<NeutronBgpvpn> allBgpvpns = bgpvpnInterface.getAll();
117 List<NeutronBgpvpn> ans = new ArrayList<NeutronBgpvpn>();
118 Iterator<NeutronBgpvpn> i = allBgpvpns.iterator();
119 while (i.hasNext()) {
120 NeutronBgpvpn oSN = i.next();
121 //match filters: TODO provider extension
122 Boolean bAdminStateUp = null;
123 Boolean bAutoAggregate = null;
124 if (queryAdminStateUp != null) {
125 bAdminStateUp = Boolean.valueOf(queryAdminStateUp);
127 if (queryAutoAggregate != null) {
128 bAutoAggregate = Boolean.valueOf(queryAutoAggregate);
130 if ((queryID == null || queryID.equals(oSN.getID())) &&
131 (queryName == null || queryName.equals(oSN.getBgpvpnName())) &&
132 (bAdminStateUp == null || bAdminStateUp.booleanValue() == oSN.isAdminStateUp()) &&
133 (queryStatus == null || queryStatus.equals(oSN.getStatus())) &&
134 (bAutoAggregate == null || bAutoAggregate.booleanValue() == oSN.isAutoAggregate()) &&
135 (queryTenantID == null || queryTenantID.equals(oSN.getTenantID()))) {
136 if (fields.size() > 0) {
137 ans.add(extractFields(oSN,fields));
144 if (limit != null && ans.size() > 1) {
145 // Return a paginated request
146 NeutronBgpvpnRequest request = (NeutronBgpvpnRequest) PaginatedRequestFactory.createRequest(limit,
147 marker, pageReverse, uriInfo, ans, NeutronBgpvpn.class);
148 return Response.status(HttpURLConnection.HTTP_OK).entity(request).build();
151 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronBgpvpnRequest(ans)).build();
156 * Returns a specific Bgpvpn */
158 @Path("{bgpvpnUUID}")
160 @Produces({ MediaType.APPLICATION_JSON })
161 //@TypeHint(OpenStackBgpvpns.class)
163 @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
164 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
165 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
166 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
167 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
168 public Response showBgpvpn(
169 @PathParam("bgpvpnUUID") String bgpvpnUUID,
171 @QueryParam("fields") List<String> fields
173 return show(bgpvpnUUID, fields);
177 * Creates new Bgpvpns */
179 @Produces({ MediaType.APPLICATION_JSON })
180 @Consumes({ MediaType.APPLICATION_JSON })
181 @TypeHint(NeutronBgpvpn.class)
183 @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
184 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
185 public Response createBgpvpns(final NeutronBgpvpnRequest input) {
186 return create(input);
190 * Updates a Bgpvpn */
192 protected void updateDelta(String uuid,
193 NeutronBgpvpn delta, NeutronBgpvpn original) {
194 //Fill in defaults if they're missing in update
195 delta.initDefaults();
197 delta.setTenantID(original.getTenantID());
200 @Path("{bgpvpnUUID}")
202 @Produces({ MediaType.APPLICATION_JSON })
203 @Consumes({ MediaType.APPLICATION_JSON })
204 //@TypeHint(OpenStackBgpvpns.class)
206 @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
207 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
208 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
209 public Response updateBgpvpn(
210 @PathParam("bgpvpnUUID") String bgpvpnUUID, final NeutronBgpvpnRequest input
212 return update(bgpvpnUUID, input);
216 * Deletes a Bgpvpn */
218 @Path("{bgpvpnUUID}")
221 @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
222 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
223 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
224 public Response deleteBgpvpn(
225 @PathParam("bgpvpnUUID") String bgpvpnUUID) {
226 return delete(bgpvpnUUID);