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.List;
14 import javax.ws.rs.Consumes;
15 import javax.ws.rs.DELETE;
16 import javax.ws.rs.DefaultValue;
17 import javax.ws.rs.GET;
18 import javax.ws.rs.POST;
19 import javax.ws.rs.PUT;
20 import javax.ws.rs.Path;
21 import javax.ws.rs.PathParam;
22 import javax.ws.rs.Produces;
23 import javax.ws.rs.QueryParam;
24 import javax.ws.rs.core.Context;
25 import javax.ws.rs.core.MediaType;
26 import javax.ws.rs.core.Response;
27 import javax.ws.rs.core.UriInfo;
28 import org.codehaus.enunciate.jaxrs.ResponseCode;
29 import org.codehaus.enunciate.jaxrs.StatusCodes;
30 import org.codehaus.enunciate.jaxrs.TypeHint;
31 import org.opendaylight.neutron.spi.INeutronBgpvpnCRUD;
32 import org.opendaylight.neutron.spi.NeutronBgpvpn;
35 * Neutron Northbound REST APIs for Bgpvpn.<br>
36 * This class provides REST APIs for managing neutron Bgpvpns
40 * Authentication scheme : <b>HTTP Basic</b><br>
41 * Authentication realm : <b>opendaylight</b><br>
42 * Transport : <b>HTTP and HTTPS</b><br>
44 * HTTPS Authentication is disabled by default. Administrator can enable it in
45 * tomcat-server.xml after adding a proper keystore / SSL certificate from a
46 * trusted authority.<br>
48 * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
53 public final class NeutronBgpvpnsNorthbound
54 extends AbstractNeutronNorthbound<NeutronBgpvpn, NeutronBgpvpnRequest, INeutronBgpvpnCRUD> {
59 private static final String RESOURCE_NAME = "Bgpvpn";
62 protected String getResourceName() {
67 * Returns a list of all Bgpvpns */
70 @Produces({ MediaType.APPLICATION_JSON })
71 //@TypeHint(OpenStackBgpvpns.class)
72 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
73 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
74 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
75 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
76 public Response listBgpvpns(
78 @QueryParam("fields") List<String> fields,
79 // note: openstack isn't clear about filtering on lists, so we aren't handling them
80 @QueryParam("id") String queryID,
81 @QueryParam("name") String queryName,
82 @QueryParam("admin_state_up") String queryAdminStateUp,
83 @QueryParam("status") String queryStatus,
84 @QueryParam("tenant_id") String queryTenantID,
85 @QueryParam("type") String queryType,
86 @QueryParam("auto_aggregate") String queryAutoAggregate,
88 @QueryParam("limit") Integer limit,
89 @QueryParam("marker") String marker,
90 @DefaultValue("false") @QueryParam("page_reverse") Boolean pageReverse
91 // sorting not supported
93 INeutronBgpvpnCRUD bgpvpnInterface = getNeutronCRUD();
94 List<NeutronBgpvpn> allBgpvpns = bgpvpnInterface.getAll();
95 List<NeutronBgpvpn> ans = new ArrayList<>();
96 for (NeutronBgpvpn bgpvpn : allBgpvpns) {
97 //match filters: TODO provider extension
98 Boolean adminStateUp = null;
99 Boolean autoAggregate = null;
100 if (queryAdminStateUp != null) {
101 adminStateUp = Boolean.valueOf(queryAdminStateUp);
103 if (queryAutoAggregate != null) {
104 autoAggregate = Boolean.valueOf(queryAutoAggregate);
106 if ((queryID == null || queryID.equals(bgpvpn.getID()))
107 && (queryName == null || queryName.equals(bgpvpn.getName()))
108 && (adminStateUp == null || adminStateUp.booleanValue() == bgpvpn.isAdminStateUp())
109 && (queryStatus == null || queryStatus.equals(bgpvpn.getStatus()))
110 && (autoAggregate == null || autoAggregate.booleanValue() == bgpvpn.isAutoAggregate())
111 && (queryTenantID == null || queryTenantID.equals(bgpvpn.getTenantID()))) {
112 if (fields.size() > 0) {
113 ans.add(bgpvpn.extractFields(fields));
120 if (limit != null && ans.size() > 1) {
121 // Return a paginated request
122 NeutronBgpvpnRequest request = (NeutronBgpvpnRequest) PaginatedRequestFactory.createRequest(limit, marker,
123 pageReverse, uriInfo, ans, NeutronBgpvpn.class);
124 return Response.status(HttpURLConnection.HTTP_OK).entity(request).build();
127 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronBgpvpnRequest(ans)).build();
132 * Returns a specific Bgpvpn */
134 @Path("{bgpvpnUUID}")
136 @Produces({ MediaType.APPLICATION_JSON })
137 //@TypeHint(OpenStackBgpvpns.class)
138 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
139 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
140 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
141 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
142 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
143 public Response showBgpvpn(@PathParam("bgpvpnUUID") String bgpvpnUUID,
145 @QueryParam("fields") List<String> fields) {
146 return show(bgpvpnUUID, fields);
150 * Creates new Bgpvpns */
152 @Produces({ MediaType.APPLICATION_JSON })
153 @Consumes({ MediaType.APPLICATION_JSON })
154 @TypeHint(NeutronBgpvpn.class)
155 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
156 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
157 public Response createBgpvpns(final NeutronBgpvpnRequest input) {
158 return create(input);
162 * Updates a Bgpvpn */
164 protected void updateDelta(String uuid, NeutronBgpvpn delta, NeutronBgpvpn original) {
165 //Fill in defaults if they're missing in update
166 delta.initDefaults();
168 delta.setTenantID(original.getTenantID());
171 @Path("{bgpvpnUUID}")
173 @Produces({ MediaType.APPLICATION_JSON })
174 @Consumes({ MediaType.APPLICATION_JSON })
175 //@TypeHint(OpenStackBgpvpns.class)
176 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
177 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
178 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
179 public Response updateBgpvpn(@PathParam("bgpvpnUUID") String bgpvpnUUID, final NeutronBgpvpnRequest input) {
180 return update(bgpvpnUUID, input);
184 * Deletes a Bgpvpn */
186 @Path("{bgpvpnUUID}")
188 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
189 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
190 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
191 public Response deleteBgpvpn(@PathParam("bgpvpnUUID") String bgpvpnUUID) {
192 return delete(bgpvpnUUID);