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.
71 @Produces({ MediaType.APPLICATION_JSON })
72 //@TypeHint(OpenStackBgpvpns.class)
73 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
74 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
75 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
76 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
77 public Response listBgpvpns(
79 @QueryParam("fields") List<String> fields,
80 // note: openstack isn't clear about filtering on lists, so we aren't handling them
81 @QueryParam("id") String queryID,
82 @QueryParam("name") String queryName,
83 @QueryParam("admin_state_up") String queryAdminStateUp,
84 @QueryParam("status") String queryStatus,
85 @QueryParam("tenant_id") String queryTenantID,
86 @QueryParam("type") String queryType,
87 @QueryParam("auto_aggregate") String queryAutoAggregate,
89 @QueryParam("limit") Integer limit,
90 @QueryParam("marker") String marker,
91 @DefaultValue("false") @QueryParam("page_reverse") Boolean pageReverse
92 // sorting not supported
94 INeutronBgpvpnCRUD bgpvpnInterface = getNeutronCRUD();
95 List<NeutronBgpvpn> allBgpvpns = bgpvpnInterface.getAll();
96 List<NeutronBgpvpn> ans = new ArrayList<>();
97 for (NeutronBgpvpn bgpvpn : allBgpvpns) {
98 //match filters: TODO provider extension
99 Boolean adminStateUp = queryAdminStateUp != null ? Boolean.valueOf(queryAdminStateUp) : null;
100 Boolean autoAggregate = queryAutoAggregate != null ? Boolean.valueOf(queryAutoAggregate) : null;
101 if ((queryID == null || queryID.equals(bgpvpn.getID()))
102 && (queryName == null || queryName.equals(bgpvpn.getName()))
103 && (adminStateUp == null || adminStateUp.booleanValue() == bgpvpn.isAdminStateUp())
104 && (queryStatus == null || queryStatus.equals(bgpvpn.getStatus()))
105 && (autoAggregate == null || autoAggregate.booleanValue() == bgpvpn.isAutoAggregate())
106 && (queryTenantID == null || queryTenantID.equals(bgpvpn.getTenantID()))) {
107 if (fields.size() > 0) {
108 ans.add(bgpvpn.extractFields(fields));
115 if (limit != null && ans.size() > 1) {
116 // Return a paginated request
117 NeutronBgpvpnRequest request = (NeutronBgpvpnRequest) PaginatedRequestFactory.createRequest(limit, marker,
118 pageReverse, uriInfo, ans, NeutronBgpvpn.class);
119 return Response.status(HttpURLConnection.HTTP_OK).entity(request).build();
122 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronBgpvpnRequest(ans)).build();
127 * Returns a specific Bgpvpn.
130 @Path("{bgpvpnUUID}")
132 @Produces({ MediaType.APPLICATION_JSON })
133 //@TypeHint(OpenStackBgpvpns.class)
134 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
135 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
136 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
137 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
138 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
139 public Response showBgpvpn(@PathParam("bgpvpnUUID") String bgpvpnUUID,
141 @QueryParam("fields") List<String> fields) {
142 return show(bgpvpnUUID, fields);
146 * Creates new Bgpvpns.
149 @Produces({ MediaType.APPLICATION_JSON })
150 @Consumes({ MediaType.APPLICATION_JSON })
151 @TypeHint(NeutronBgpvpn.class)
152 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
153 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
154 public Response createBgpvpns(final NeutronBgpvpnRequest input) {
155 return create(input);
162 protected void updateDelta(String uuid, NeutronBgpvpn delta, NeutronBgpvpn original) {
163 //Fill in defaults if they're missing in update
164 delta.initDefaults();
166 delta.setTenantID(original.getTenantID());
169 @Path("{bgpvpnUUID}")
171 @Produces({ MediaType.APPLICATION_JSON })
172 @Consumes({ MediaType.APPLICATION_JSON })
173 //@TypeHint(OpenStackBgpvpns.class)
174 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
175 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
176 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
177 public Response updateBgpvpn(@PathParam("bgpvpnUUID") String bgpvpnUUID, final NeutronBgpvpnRequest input) {
178 return update(bgpvpnUUID, input);
185 @Path("{bgpvpnUUID}")
187 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
188 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
189 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
190 public Response deleteBgpvpn(@PathParam("bgpvpnUUID") String bgpvpnUUID) {
191 return delete(bgpvpnUUID);