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
8 package org.opendaylight.neutron.northbound.api;
10 import java.net.HttpURLConnection;
11 import java.util.ArrayList;
12 import java.util.List;
13 import javax.inject.Inject;
14 import javax.inject.Singleton;
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.ops4j.pax.cdi.api.OsgiService;
37 * Neutron Northbound REST APIs for Bgpvpn.
41 public final class NeutronBgpvpnsNorthbound
42 extends AbstractNeutronNorthbound<NeutronBgpvpn, NeutronBgpvpnRequest, INeutronBgpvpnCRUD> {
44 private static final String RESOURCE_NAME = "Bgpvpn";
50 public NeutronBgpvpnsNorthbound(@OsgiService INeutronBgpvpnCRUD neutronCRUD) {
55 protected String getResourceName() {
60 * Returns a list of all Bgpvpns.
63 @Produces({ MediaType.APPLICATION_JSON })
64 //@TypeHint(OpenStackBgpvpns.class)
65 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
66 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
67 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
68 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
69 public Response listBgpvpns(
71 @QueryParam("fields") List<String> fields,
72 // note: openstack isn't clear about filtering on lists, so we aren't handling them
73 @QueryParam("id") String queryID,
74 @QueryParam("name") String queryName,
75 @QueryParam("admin_state_up") String queryAdminStateUp,
76 @QueryParam("status") String queryStatus,
77 @QueryParam("tenant_id") String queryTenantID,
78 @QueryParam("type") String queryType,
79 @QueryParam("auto_aggregate") String queryAutoAggregate,
81 @QueryParam("limit") Integer limit,
82 @QueryParam("marker") String marker,
83 @DefaultValue("false") @QueryParam("page_reverse") Boolean pageReverse
84 // sorting not supported
86 INeutronBgpvpnCRUD bgpvpnInterface = getNeutronCRUD();
87 List<NeutronBgpvpn> allBgpvpns = bgpvpnInterface.getAll();
88 List<NeutronBgpvpn> ans = new ArrayList<>();
89 for (NeutronBgpvpn bgpvpn : allBgpvpns) {
90 //match filters: TODO provider extension
91 Boolean adminStateUp = queryAdminStateUp != null ? Boolean.valueOf(queryAdminStateUp) : null;
92 Boolean autoAggregate = queryAutoAggregate != null ? Boolean.valueOf(queryAutoAggregate) : null;
93 if ((queryID == null || queryID.equals(bgpvpn.getID()))
94 && (queryName == null || queryName.equals(bgpvpn.getName()))
95 && (adminStateUp == null || adminStateUp.booleanValue() == bgpvpn.isAdminStateUp())
96 && (queryStatus == null || queryStatus.equals(bgpvpn.getStatus()))
97 && (autoAggregate == null || autoAggregate.booleanValue() == bgpvpn.isAutoAggregate())
98 && (queryTenantID == null || queryTenantID.equals(bgpvpn.getTenantID()))) {
99 if (fields.size() > 0) {
100 ans.add(bgpvpn.extractFields(fields));
107 if (limit != null && ans.size() > 1) {
108 // Return a paginated request
109 NeutronBgpvpnRequest request = (NeutronBgpvpnRequest) PaginatedRequestFactory.createRequest(limit, marker,
110 pageReverse, uriInfo, ans, NeutronBgpvpn.class);
111 return Response.status(HttpURLConnection.HTTP_OK).entity(request).build();
114 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronBgpvpnRequest(ans)).build();
119 * Returns a specific Bgpvpn.
121 @Path("{bgpvpnUUID}")
123 @Produces({ MediaType.APPLICATION_JSON })
124 //@TypeHint(OpenStackBgpvpns.class)
125 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
126 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
127 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
128 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
129 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
130 public Response showBgpvpn(@PathParam("bgpvpnUUID") String bgpvpnUUID,
132 @QueryParam("fields") List<String> fields) {
133 return show(bgpvpnUUID, fields);
137 * Creates new Bgpvpns.
140 @Produces({ MediaType.APPLICATION_JSON })
141 @Consumes({ MediaType.APPLICATION_JSON })
142 @TypeHint(NeutronBgpvpn.class)
143 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
144 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
145 public Response createBgpvpns(final NeutronBgpvpnRequest input) {
146 return create(input);
153 protected void updateDelta(String uuid, NeutronBgpvpn delta, NeutronBgpvpn original) {
154 //Fill in defaults if they're missing in update
155 delta.initDefaults();
157 delta.setTenantID(original.getTenantID());
160 @Path("{bgpvpnUUID}")
162 @Produces({ MediaType.APPLICATION_JSON })
163 @Consumes({ MediaType.APPLICATION_JSON })
164 //@TypeHint(OpenStackBgpvpns.class)
165 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
166 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
167 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
168 public Response updateBgpvpn(@PathParam("bgpvpnUUID") String bgpvpnUUID, final NeutronBgpvpnRequest input) {
169 return update(bgpvpnUUID, input);
175 @Path("{bgpvpnUUID}")
177 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
178 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
179 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
180 public Response deleteBgpvpn(@PathParam("bgpvpnUUID") String bgpvpnUUID) {
181 return delete(bgpvpnUUID);