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 NeutronBgpvpnRequest newNeutronRequest(NeutronBgpvpn o) {
70 return new NeutronBgpvpnRequest(o);
74 protected INeutronBgpvpnCRUD getNeutronCRUD() {
75 NeutronCRUDInterfaces answer = new NeutronCRUDInterfaces().fetchINeutronBgpvpnCRUD(this);
76 if (answer.getBgpvpnInterface() == null) {
77 throw new ServiceUnavailableException(serviceUnavailable());
79 return answer.getBgpvpnInterface();
83 * Returns a list of all Bgpvpns */
86 @Produces({ MediaType.APPLICATION_JSON })
87 //@TypeHint(OpenStackBgpvpns.class)
88 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
89 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
90 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
91 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
92 public Response listBgpvpns(
94 @QueryParam("fields") List<String> fields,
95 // note: openstack isn't clear about filtering on lists, so we aren't handling them
96 @QueryParam("id") String queryID,
97 @QueryParam("name") String queryName,
98 @QueryParam("admin_state_up") String queryAdminStateUp,
99 @QueryParam("status") String queryStatus,
100 @QueryParam("tenant_id") String queryTenantID,
101 @QueryParam("type") String queryType,
102 @QueryParam("auto_aggregate") String queryAutoAggregate,
104 @QueryParam("limit") Integer limit,
105 @QueryParam("marker") String marker,
106 @DefaultValue("false") @QueryParam("page_reverse") Boolean pageReverse
107 // sorting not supported
109 INeutronBgpvpnCRUD bgpvpnInterface = getNeutronCRUD();
110 List<NeutronBgpvpn> allBgpvpns = bgpvpnInterface.getAll();
111 List<NeutronBgpvpn> ans = new ArrayList<>();
112 Iterator<NeutronBgpvpn> i = allBgpvpns.iterator();
113 while (i.hasNext()) {
114 NeutronBgpvpn oSN = i.next();
115 //match filters: TODO provider extension
116 Boolean bAdminStateUp = null;
117 Boolean bAutoAggregate = null;
118 if (queryAdminStateUp != null) {
119 bAdminStateUp = Boolean.valueOf(queryAdminStateUp);
121 if (queryAutoAggregate != null) {
122 bAutoAggregate = Boolean.valueOf(queryAutoAggregate);
124 if ((queryID == null || queryID.equals(oSN.getID()))
125 && (queryName == null || queryName.equals(oSN.getBgpvpnName()))
126 && (bAdminStateUp == null || bAdminStateUp.booleanValue() == oSN.isAdminStateUp())
127 && (queryStatus == null || queryStatus.equals(oSN.getStatus()))
128 && (bAutoAggregate == null || bAutoAggregate.booleanValue() == oSN.isAutoAggregate())
129 && (queryTenantID == null || queryTenantID.equals(oSN.getTenantID()))) {
130 if (fields.size() > 0) {
131 ans.add(oSN.extractFields(fields));
138 if (limit != null && ans.size() > 1) {
139 // Return a paginated request
140 NeutronBgpvpnRequest request = (NeutronBgpvpnRequest) PaginatedRequestFactory.createRequest(limit, marker,
141 pageReverse, uriInfo, ans, NeutronBgpvpn.class);
142 return Response.status(HttpURLConnection.HTTP_OK).entity(request).build();
145 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronBgpvpnRequest(ans)).build();
150 * Returns a specific Bgpvpn */
152 @Path("{bgpvpnUUID}")
154 @Produces({ MediaType.APPLICATION_JSON })
155 //@TypeHint(OpenStackBgpvpns.class)
156 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
157 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
158 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
159 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
160 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
161 public Response showBgpvpn(@PathParam("bgpvpnUUID") String bgpvpnUUID,
163 @QueryParam("fields") List<String> fields) {
164 return show(bgpvpnUUID, fields);
168 * Creates new Bgpvpns */
170 @Produces({ MediaType.APPLICATION_JSON })
171 @Consumes({ MediaType.APPLICATION_JSON })
172 @TypeHint(NeutronBgpvpn.class)
173 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
174 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
175 public Response createBgpvpns(final NeutronBgpvpnRequest input) {
176 return create(input);
180 * Updates a Bgpvpn */
182 protected void updateDelta(String uuid, NeutronBgpvpn delta, NeutronBgpvpn original) {
183 //Fill in defaults if they're missing in update
184 delta.initDefaults();
186 delta.setTenantID(original.getTenantID());
189 @Path("{bgpvpnUUID}")
191 @Produces({ MediaType.APPLICATION_JSON })
192 @Consumes({ MediaType.APPLICATION_JSON })
193 //@TypeHint(OpenStackBgpvpns.class)
194 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
195 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
196 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
197 public Response updateBgpvpn(@PathParam("bgpvpnUUID") String bgpvpnUUID, final NeutronBgpvpnRequest input) {
198 return update(bgpvpnUUID, input);
202 * Deletes a Bgpvpn */
204 @Path("{bgpvpnUUID}")
206 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
207 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
208 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
209 public Response deleteBgpvpn(@PathParam("bgpvpnUUID") String bgpvpnUUID) {
210 return delete(bgpvpnUUID);