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.ws.rs.Consumes;
14 import javax.ws.rs.DELETE;
15 import javax.ws.rs.DefaultValue;
16 import javax.ws.rs.GET;
17 import javax.ws.rs.POST;
18 import javax.ws.rs.PUT;
19 import javax.ws.rs.Path;
20 import javax.ws.rs.PathParam;
21 import javax.ws.rs.Produces;
22 import javax.ws.rs.QueryParam;
23 import javax.ws.rs.core.Context;
24 import javax.ws.rs.core.MediaType;
25 import javax.ws.rs.core.Response;
26 import javax.ws.rs.core.UriInfo;
27 import org.codehaus.enunciate.jaxrs.ResponseCode;
28 import org.codehaus.enunciate.jaxrs.StatusCodes;
29 import org.codehaus.enunciate.jaxrs.TypeHint;
30 import org.opendaylight.neutron.spi.INeutronBgpvpnCRUD;
31 import org.opendaylight.neutron.spi.NeutronBgpvpn;
34 * Neutron Northbound REST APIs for Bgpvpn.
37 public final class NeutronBgpvpnsNorthbound
38 extends AbstractNeutronNorthbound<NeutronBgpvpn, NeutronBgpvpnRequest, INeutronBgpvpnCRUD> {
40 private static final String RESOURCE_NAME = "Bgpvpn";
46 protected String getResourceName() {
51 * Returns a list of all Bgpvpns.
54 @Produces({ MediaType.APPLICATION_JSON })
55 //@TypeHint(OpenStackBgpvpns.class)
56 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
57 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
58 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
59 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
60 public Response listBgpvpns(
62 @QueryParam("fields") List<String> fields,
63 // note: openstack isn't clear about filtering on lists, so we aren't handling them
64 @QueryParam("id") String queryID,
65 @QueryParam("name") String queryName,
66 @QueryParam("admin_state_up") String queryAdminStateUp,
67 @QueryParam("status") String queryStatus,
68 @QueryParam("tenant_id") String queryTenantID,
69 @QueryParam("type") String queryType,
70 @QueryParam("auto_aggregate") String queryAutoAggregate,
72 @QueryParam("limit") Integer limit,
73 @QueryParam("marker") String marker,
74 @DefaultValue("false") @QueryParam("page_reverse") Boolean pageReverse
75 // sorting not supported
77 INeutronBgpvpnCRUD bgpvpnInterface = getNeutronCRUD();
78 List<NeutronBgpvpn> allBgpvpns = bgpvpnInterface.getAll();
79 List<NeutronBgpvpn> ans = new ArrayList<>();
80 for (NeutronBgpvpn bgpvpn : allBgpvpns) {
81 //match filters: TODO provider extension
82 Boolean adminStateUp = queryAdminStateUp != null ? Boolean.valueOf(queryAdminStateUp) : null;
83 Boolean autoAggregate = queryAutoAggregate != null ? Boolean.valueOf(queryAutoAggregate) : null;
84 if ((queryID == null || queryID.equals(bgpvpn.getID()))
85 && (queryName == null || queryName.equals(bgpvpn.getName()))
86 && (adminStateUp == null || adminStateUp.booleanValue() == bgpvpn.isAdminStateUp())
87 && (queryStatus == null || queryStatus.equals(bgpvpn.getStatus()))
88 && (autoAggregate == null || autoAggregate.booleanValue() == bgpvpn.isAutoAggregate())
89 && (queryTenantID == null || queryTenantID.equals(bgpvpn.getTenantID()))) {
90 if (fields.size() > 0) {
91 ans.add(bgpvpn.extractFields(fields));
98 if (limit != null && ans.size() > 1) {
99 // Return a paginated request
100 NeutronBgpvpnRequest request = (NeutronBgpvpnRequest) PaginatedRequestFactory.createRequest(limit, marker,
101 pageReverse, uriInfo, ans, NeutronBgpvpn.class);
102 return Response.status(HttpURLConnection.HTTP_OK).entity(request).build();
105 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronBgpvpnRequest(ans)).build();
110 * Returns a specific Bgpvpn.
112 @Path("{bgpvpnUUID}")
114 @Produces({ MediaType.APPLICATION_JSON })
115 //@TypeHint(OpenStackBgpvpns.class)
116 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
117 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
118 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
119 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
120 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
121 public Response showBgpvpn(@PathParam("bgpvpnUUID") String bgpvpnUUID,
123 @QueryParam("fields") List<String> fields) {
124 return show(bgpvpnUUID, fields);
128 * Creates new Bgpvpns.
131 @Produces({ MediaType.APPLICATION_JSON })
132 @Consumes({ MediaType.APPLICATION_JSON })
133 @TypeHint(NeutronBgpvpn.class)
134 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
135 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
136 public Response createBgpvpns(final NeutronBgpvpnRequest input) {
137 return create(input);
144 protected void updateDelta(String uuid, NeutronBgpvpn delta, NeutronBgpvpn original) {
145 //Fill in defaults if they're missing in update
146 delta.initDefaults();
148 delta.setTenantID(original.getTenantID());
151 @Path("{bgpvpnUUID}")
153 @Produces({ MediaType.APPLICATION_JSON })
154 @Consumes({ MediaType.APPLICATION_JSON })
155 //@TypeHint(OpenStackBgpvpns.class)
156 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
157 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
158 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
159 public Response updateBgpvpn(@PathParam("bgpvpnUUID") String bgpvpnUUID, final NeutronBgpvpnRequest input) {
160 return update(bgpvpnUUID, input);
166 @Path("{bgpvpnUUID}")
168 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
169 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
170 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
171 public Response deleteBgpvpn(@PathParam("bgpvpnUUID") String bgpvpnUUID) {
172 return delete(bgpvpnUUID);