2 * Copyright (c) 2015 Hewlett-Packard Development Company, L.P. 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.GET;
16 import javax.ws.rs.POST;
17 import javax.ws.rs.PUT;
18 import javax.ws.rs.Path;
19 import javax.ws.rs.PathParam;
20 import javax.ws.rs.Produces;
21 import javax.ws.rs.QueryParam;
22 import javax.ws.rs.core.MediaType;
23 import javax.ws.rs.core.Response;
24 import org.codehaus.enunciate.jaxrs.ResponseCode;
25 import org.codehaus.enunciate.jaxrs.StatusCodes;
26 import org.opendaylight.neutron.spi.INeutronL2gatewayCRUD;
27 import org.opendaylight.neutron.spi.NeutronL2gateway;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * Neutron Northbound REST APIs for L2 gateway.
35 public final class NeutronL2gatewayNorthbound
36 extends AbstractNeutronNorthbound<NeutronL2gateway, NeutronL2gatewayRequest, INeutronL2gatewayCRUD> {
38 private static final Logger LOG = LoggerFactory.getLogger(NeutronL2gatewayNorthbound.class);
40 private static final String RESOURCE_NAME = "L2gateway";
43 protected String getResourceName() {
49 * @param input l2gateway attributes
50 * @return success or error code
53 @Produces({ MediaType.APPLICATION_JSON })
54 @Consumes({ MediaType.APPLICATION_JSON })
55 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
56 @ResponseCode(code = HttpURLConnection.HTTP_BAD_REQUEST, condition = "Bad Request"),
57 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
58 @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
59 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
60 @ResponseCode(code = HttpURLConnection.HTTP_CONFLICT, condition = "Conflict"),
61 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
62 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
63 public Response createL2gateway(final NeutronL2gatewayRequest input) {
64 LOG.debug("CreateL2gateway NeutronL2gatewayRequest");
69 * Returns a list of all L2gateways.
72 @Produces({ MediaType.APPLICATION_JSON })
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 listL2gateways(
79 @QueryParam("fields") List<String> fields,
80 // OpenStack L2gateway attributes
81 @QueryParam("id") String queryID,
82 @QueryParam("name") String queryName,
83 @QueryParam("tenant_id") String queryTenantID,
84 @QueryParam("devices") String queryNeutronL2gatewayDevice,
86 @QueryParam("limit") String limit,
87 @QueryParam("marker") String marker,
88 @QueryParam("page_reverse") String pageReverse
89 // sorting not supported
91 INeutronL2gatewayCRUD l2gatewayInterface = getNeutronCRUD();
92 List<NeutronL2gateway> allL2gateways = l2gatewayInterface.getAll();
93 List<NeutronL2gateway> ans = new ArrayList<>();
94 for (NeutronL2gateway l2gateway : allL2gateways) {
95 if ((queryID == null || queryID.equals(l2gateway.getID()))
96 && (queryName == null || queryName.equals(l2gateway.getName()))
97 && (queryTenantID == null || queryTenantID.equals(l2gateway.getTenantID()))) {
98 if (fields.size() > 0) {
99 ans.add(l2gateway.extractFields(fields));
105 //TODO: apply pagination to results
106 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronL2gatewayRequest(ans)).build();
110 * Returns a specific L2gateway.
111 * @param l2gatewayID requested l2gateway uuid
112 * @param fields l2gateway attributes
113 * @return l2gateway details or error.
115 @Path("{l2gatewayID}")
117 @Produces({ MediaType.APPLICATION_JSON })
118 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
119 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
120 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
121 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
122 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
123 public Response showL2gateway(@PathParam("l2gatewayID") String l2gatewayID,
125 @QueryParam("fields") List<String> fields) {
126 return show(l2gatewayID, fields);
130 * Deletes a L2gateway.
131 * @param l2gatewayID l2gateway uuid which should be deleted
132 * @return success or error code
135 @Path("{l2gatewayID}")
137 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
138 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
139 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
140 public Response deleteL2gateway(@PathParam("l2gatewayID") String l2gatewayID) {
141 return delete(l2gatewayID);
145 * Updates a L2gateway.
146 * @param l2gatewayID gateway ID that needs to be modified
147 * @param input gateway attributes
150 @Path("{l2gatewayID}")
152 @Produces({ MediaType.APPLICATION_JSON })
153 @Consumes({ MediaType.APPLICATION_JSON })
154 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
155 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
156 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
157 public Response updateL2gateway(@PathParam("l2gatewayID") String l2gatewayID, NeutronL2gatewayRequest input) {
158 return update(l2gatewayID, input);