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;
16 import javax.ws.rs.Consumes;
17 import javax.ws.rs.DELETE;
18 import javax.ws.rs.DefaultValue;
19 import javax.ws.rs.GET;
20 import javax.ws.rs.POST;
21 import javax.ws.rs.PUT;
22 import javax.ws.rs.Path;
23 import javax.ws.rs.PathParam;
24 import javax.ws.rs.Produces;
25 import javax.ws.rs.QueryParam;
26 import javax.ws.rs.core.Context;
27 import javax.ws.rs.core.MediaType;
28 import javax.ws.rs.core.Response;
29 import javax.ws.rs.core.UriInfo;
31 import org.codehaus.enunciate.jaxrs.ResponseCode;
32 import org.codehaus.enunciate.jaxrs.StatusCodes;
33 import org.codehaus.enunciate.jaxrs.TypeHint;
34 import org.opendaylight.neutron.spi.INeutronBgpvpnCRUD;
35 import org.opendaylight.neutron.spi.NeutronCRUDInterfaces;
36 import org.opendaylight.neutron.spi.NeutronBgpvpn;
39 * Neutron Northbound REST APIs for Bgpvpn.<br>
40 * This class provides REST APIs for managing neutron Bgpvpns
44 * Authentication scheme : <b>HTTP Basic</b><br>
45 * Authentication realm : <b>opendaylight</b><br>
46 * Transport : <b>HTTP and HTTPS</b><br>
48 * HTTPS Authentication is disabled by default. Administrator can enable it in
49 * tomcat-server.xml after adding a proper keystore / SSL certificate from a
50 * trusted authority.<br>
52 * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
57 public class NeutronBgpvpnsNorthbound
58 extends AbstractNeutronNorthbound<NeutronBgpvpn, NeutronBgpvpnRequest, INeutronBgpvpnCRUD> {
63 private static final String RESOURCE_NAME = "Bgpvpn";
66 protected String getResourceName() {
71 protected NeutronBgpvpn extractFields(NeutronBgpvpn o, List<String> fields) {
72 return o.extractFields(fields);
76 protected NeutronBgpvpnRequest newNeutronRequest(NeutronBgpvpn o) {
77 return new NeutronBgpvpnRequest(o);
81 protected INeutronBgpvpnCRUD getNeutronCRUD() {
82 NeutronCRUDInterfaces answer = new NeutronCRUDInterfaces().fetchINeutronBgpvpnCRUD(this);
83 if (answer.getBgpvpnInterface() == null) {
84 throw new ServiceUnavailableException(serviceUnavailable());
86 return answer.getBgpvpnInterface();
90 * Returns a list of all Bgpvpns */
93 @Produces({ MediaType.APPLICATION_JSON })
94 //@TypeHint(OpenStackBgpvpns.class)
96 @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
97 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
98 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
99 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
100 public Response listBgpvpns(
102 @QueryParam("fields") List<String> fields,
103 // note: openstack isn't clear about filtering on lists, so we aren't handling them
104 @QueryParam("id") String queryID,
105 @QueryParam("name") String queryName,
106 @QueryParam("admin_state_up") String queryAdminStateUp,
107 @QueryParam("status") String queryStatus,
108 @QueryParam("tenant_id") String queryTenantID,
109 @QueryParam("type") String queryType,
110 @QueryParam("auto_aggregate") String queryAutoAggregate,
112 @QueryParam("limit") Integer limit,
113 @QueryParam("marker") String marker,
114 @DefaultValue("false") @QueryParam("page_reverse") Boolean pageReverse
115 // sorting not supported
117 INeutronBgpvpnCRUD bgpvpnInterface = getNeutronCRUD();
118 List<NeutronBgpvpn> allBgpvpns = bgpvpnInterface.getAll();
119 List<NeutronBgpvpn> ans = new ArrayList<NeutronBgpvpn>();
120 Iterator<NeutronBgpvpn> i = allBgpvpns.iterator();
121 while (i.hasNext()) {
122 NeutronBgpvpn oSN = i.next();
123 //match filters: TODO provider extension
124 Boolean bAdminStateUp = null;
125 Boolean bAutoAggregate = null;
126 if (queryAdminStateUp != null) {
127 bAdminStateUp = Boolean.valueOf(queryAdminStateUp);
129 if (queryAutoAggregate != null) {
130 bAutoAggregate = Boolean.valueOf(queryAutoAggregate);
132 if ((queryID == null || queryID.equals(oSN.getID())) &&
133 (queryName == null || queryName.equals(oSN.getBgpvpnName())) &&
134 (bAdminStateUp == null || bAdminStateUp.booleanValue() == oSN.isAdminStateUp()) &&
135 (queryStatus == null || queryStatus.equals(oSN.getStatus())) &&
136 (bAutoAggregate == null || bAutoAggregate.booleanValue() == oSN.isAutoAggregate()) &&
137 (queryTenantID == null || queryTenantID.equals(oSN.getTenantID()))) {
138 if (fields.size() > 0) {
139 ans.add(extractFields(oSN,fields));
146 if (limit != null && ans.size() > 1) {
147 // Return a paginated request
148 NeutronBgpvpnRequest request = (NeutronBgpvpnRequest) PaginatedRequestFactory.createRequest(limit,
149 marker, pageReverse, uriInfo, ans, NeutronBgpvpn.class);
150 return Response.status(HttpURLConnection.HTTP_OK).entity(request).build();
153 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronBgpvpnRequest(ans)).build();
158 * Returns a specific Bgpvpn */
160 @Path("{bgpvpnUUID}")
162 @Produces({ MediaType.APPLICATION_JSON })
163 //@TypeHint(OpenStackBgpvpns.class)
165 @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
166 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
167 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
168 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
169 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
170 public Response showBgpvpn(
171 @PathParam("bgpvpnUUID") String bgpvpnUUID,
173 @QueryParam("fields") List<String> fields
175 return show(bgpvpnUUID, fields);
179 * Creates new Bgpvpns */
181 @Produces({ MediaType.APPLICATION_JSON })
182 @Consumes({ MediaType.APPLICATION_JSON })
183 @TypeHint(NeutronBgpvpn.class)
185 @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
186 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
187 public Response createBgpvpns(final NeutronBgpvpnRequest input) {
188 return create(input);
192 * Updates a Bgpvpn */
194 protected void updateDelta(String uuid,
195 NeutronBgpvpn delta, NeutronBgpvpn original) {
196 //Fill in defaults if they're missing in update
197 delta.initDefaults();
199 delta.setTenantID(original.getTenantID());
202 @Path("{bgpvpnUUID}")
204 @Produces({ MediaType.APPLICATION_JSON })
205 @Consumes({ MediaType.APPLICATION_JSON })
206 //@TypeHint(OpenStackBgpvpns.class)
208 @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
209 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
210 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
211 public Response updateBgpvpn(
212 @PathParam("bgpvpnUUID") String bgpvpnUUID, final NeutronBgpvpnRequest input
214 return update(bgpvpnUUID, input);
218 * Deletes a Bgpvpn */
220 @Path("{bgpvpnUUID}")
223 @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
224 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
225 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
226 public Response deleteBgpvpn(
227 @PathParam("bgpvpnUUID") String bgpvpnUUID) {
228 return delete(bgpvpnUUID);