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 com.webcohesion.enunciate.metadata.rs.ResponseCode;
11 import com.webcohesion.enunciate.metadata.rs.StatusCodes;
12 import com.webcohesion.enunciate.metadata.rs.TypeHint;
13 import java.net.HttpURLConnection;
14 import java.util.ArrayList;
15 import java.util.List;
16 import javax.inject.Inject;
17 import javax.inject.Singleton;
18 import javax.ws.rs.Consumes;
19 import javax.ws.rs.DELETE;
20 import javax.ws.rs.DefaultValue;
21 import javax.ws.rs.GET;
22 import javax.ws.rs.POST;
23 import javax.ws.rs.PUT;
24 import javax.ws.rs.Path;
25 import javax.ws.rs.PathParam;
26 import javax.ws.rs.Produces;
27 import javax.ws.rs.QueryParam;
28 import javax.ws.rs.core.Context;
29 import javax.ws.rs.core.MediaType;
30 import javax.ws.rs.core.Response;
31 import javax.ws.rs.core.UriInfo;
32 import org.apache.aries.blueprint.annotation.service.Reference;
33 import org.opendaylight.neutron.spi.INeutronBgpvpnCRUD;
34 import org.opendaylight.neutron.spi.INeutronBgpvpnNetworkAssociationCRUD;
35 import org.opendaylight.neutron.spi.INeutronBgpvpnRouterAssociationCRUD;
36 import org.opendaylight.neutron.spi.NeutronBgpvpn;
37 import org.opendaylight.neutron.spi.NeutronBgpvpnNetworkAssociation;
38 import org.opendaylight.neutron.spi.NeutronBgpvpnRouterAssociation;
41 * Neutron Northbound REST APIs for Bgpvpn.
45 public final class NeutronBgpvpnsNorthbound
46 extends AbstractNeutronNorthbound<NeutronBgpvpn, NeutronBgpvpnRequest, INeutronBgpvpnCRUD> {
47 private static final String RESOURCE_NAME = "Bgpvpn";
52 INeutronBgpvpnNetworkAssociationCRUD neutronBgpvpnNetworkAssociation;
53 INeutronBgpvpnRouterAssociationCRUD neutronBgpvpnRouterAssociation;
56 public NeutronBgpvpnsNorthbound(@Reference INeutronBgpvpnCRUD neutronCRUD,
57 INeutronBgpvpnNetworkAssociationCRUD neutronBgpvpnNetworkAssociation,
58 INeutronBgpvpnRouterAssociationCRUD neutronBgpvpnRouterAssociation) {
60 this.neutronBgpvpnNetworkAssociation = neutronBgpvpnNetworkAssociation;
61 this.neutronBgpvpnRouterAssociation = neutronBgpvpnRouterAssociation;
65 protected String getResourceName() {
70 * Returns a list of all Bgpvpns.
73 @Produces({ MediaType.APPLICATION_JSON })
74 //@TypeHint(OpenStackBgpvpns.class)
76 @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
77 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
78 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
79 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available")
81 public Response listBgpvpns(
83 @QueryParam("fields") List<String> fields,
84 // note: openstack isn't clear about filtering on lists, so we aren't handling them
85 @QueryParam("id") String queryID,
86 @QueryParam("name") String queryName,
87 @QueryParam("admin_state_up") String queryAdminStateUp,
88 @QueryParam("status") String queryStatus,
89 @QueryParam("tenant_id") String queryTenantID,
90 @QueryParam("type") String queryType,
91 @QueryParam("auto_aggregate") String queryAutoAggregate,
93 @QueryParam("limit") Integer limit,
94 @QueryParam("marker") String marker,
95 @DefaultValue("false") @QueryParam("page_reverse") Boolean pageReverse
96 // sorting not supported
98 INeutronBgpvpnCRUD bgpvpnInterface = getNeutronCRUD();
99 List<NeutronBgpvpn> allBgpvpns = bgpvpnInterface.getAll();
100 List<NeutronBgpvpn> ans = new ArrayList<>();
101 for (NeutronBgpvpn bgpvpn : allBgpvpns) {
102 //match filters: TODO provider extension
103 Boolean adminStateUp = queryAdminStateUp != null ? Boolean.valueOf(queryAdminStateUp) : null;
104 Boolean autoAggregate = queryAutoAggregate != null ? Boolean.valueOf(queryAutoAggregate) : null;
105 if ((queryID == null || queryID.equals(bgpvpn.getID()))
106 && (queryName == null || queryName.equals(bgpvpn.getName()))
107 && (adminStateUp == null || adminStateUp.booleanValue() == bgpvpn.isAdminStateUp())
108 && (queryStatus == null || queryStatus.equals(bgpvpn.getStatus()))
109 && (autoAggregate == null || autoAggregate.booleanValue() == bgpvpn.isAutoAggregate())
110 && (queryTenantID == null || queryTenantID.equals(bgpvpn.getTenantID()))) {
111 if (fields.size() > 0) {
112 ans.add(bgpvpn.extractFields(fields));
119 if (limit != null && ans.size() > 1) {
120 // Return a paginated request
121 NeutronBgpvpnRequest request = (NeutronBgpvpnRequest) PaginatedRequestFactory.createRequest(limit, marker,
122 pageReverse, uriInfo, ans, NeutronBgpvpn.class);
123 return Response.status(HttpURLConnection.HTTP_OK).entity(request).build();
126 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronBgpvpnRequest(ans)).build();
130 * Returns a specific Bgpvpn.
132 @Path("{bgpvpnUUID}")
134 @Produces({ MediaType.APPLICATION_JSON })
135 //@TypeHint(OpenStackBgpvpns.class)
137 @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
138 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
139 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
140 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
141 @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.
153 @Produces({ MediaType.APPLICATION_JSON })
154 @Consumes({ MediaType.APPLICATION_JSON })
155 @TypeHint(NeutronBgpvpn.class)
157 @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
158 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available")
160 public Response createBgpvpns(final NeutronBgpvpnRequest input) {
161 return create(input);
168 protected void updateDelta(String uuid, NeutronBgpvpn delta, NeutronBgpvpn original) {
169 //Fill in defaults if they're missing in update
170 delta.initDefaults();
172 delta.setTenantID(original.getTenantID());
175 @Path("{bgpvpnUUID}")
177 @Produces({ MediaType.APPLICATION_JSON })
178 @Consumes({ MediaType.APPLICATION_JSON })
179 //@TypeHint(OpenStackBgpvpns.class)
181 @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
182 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
183 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available")
185 public Response updateBgpvpn(@PathParam("bgpvpnUUID") String bgpvpnUUID, final NeutronBgpvpnRequest input) {
186 return update(bgpvpnUUID, input);
192 @Path("{bgpvpnUUID}")
195 @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
196 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
197 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available")
199 public Response deleteBgpvpn(@PathParam("bgpvpnUUID") String bgpvpnUUID) {
200 NeutronBgpvpnNetworkAssociationsNorthbound netAssoNorthBound =
201 new NeutronBgpvpnNetworkAssociationsNorthbound(neutronBgpvpnNetworkAssociation);
202 List<NeutronBgpvpnNetworkAssociation> allBgpvpnNetAssos = neutronBgpvpnNetworkAssociation.getAll();
203 for (NeutronBgpvpnNetworkAssociation bgpvpnNetAsso : allBgpvpnNetAssos) {
204 if (bgpvpnUUID != null && bgpvpnUUID.equals(bgpvpnNetAsso.getBgpvpnId())) {
205 netAssoNorthBound.delete(bgpvpnNetAsso.getID());
209 NeutronBgpvpnRouterAssociationsNorthbound routeAssoNorthBound =
210 new NeutronBgpvpnRouterAssociationsNorthbound(neutronBgpvpnRouterAssociation);
211 List<NeutronBgpvpnRouterAssociation> allBgpvpnRouteAssos = neutronBgpvpnRouterAssociation.getAll();
212 for (NeutronBgpvpnRouterAssociation bgpvpnRouteAsso : allBgpvpnRouteAssos) {
213 if (bgpvpnUUID != null && bgpvpnUUID.equals(bgpvpnRouteAsso.getBgpvpnId())) {
214 routeAssoNorthBound.delete(bgpvpnRouteAsso.getID());
217 return delete(bgpvpnUUID);