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.<br>
33 * This class provides REST APIs for managing L2 gateway
37 * Authentication scheme : <b>HTTP Basic</b><br>
38 * Authentication realm : <b>opendaylight</b><br>
39 * Transport : <b>HTTP and HTTPS</b><br>
41 * HTTPS Authentication is disabled by default. Administrator can enable it in
42 * tomcat-server.xml after adding a proper keystore / SSL certificate from a
43 * trusted authority.<br>
45 * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
49 public final class NeutronL2gatewayNorthbound
50 extends AbstractNeutronNorthbound<NeutronL2gateway, NeutronL2gatewayRequest, INeutronL2gatewayCRUD> {
51 static final Logger LOG = LoggerFactory.getLogger(NeutronL2gatewayNorthbound.class);
53 private static final String RESOURCE_NAME = "L2gateway";
56 protected String getResourceName() {
62 * @param input l2gateway attributes
63 * @return success or error code
66 @Produces({ MediaType.APPLICATION_JSON })
67 @Consumes({ MediaType.APPLICATION_JSON })
68 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
69 @ResponseCode(code = HttpURLConnection.HTTP_BAD_REQUEST, condition = "Bad Request"),
70 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
71 @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
72 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
73 @ResponseCode(code = HttpURLConnection.HTTP_CONFLICT, condition = "Conflict"),
74 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
75 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
77 public Response createL2gateway(final NeutronL2gatewayRequest input) {
78 LOG.debug("CreateL2gateway NeutronL2gatewayRequest");
83 * Returns a list of all L2gateways.
86 @Produces({ MediaType.APPLICATION_JSON })
87 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
88 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
89 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
90 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
91 public Response listL2gateways(
93 @QueryParam("fields") List<String> fields,
94 // OpenStack L2gateway attributes
95 @QueryParam("id") String queryID,
96 @QueryParam("name") String queryName,
97 @QueryParam("tenant_id") String queryTenantID,
98 @QueryParam("devices") String queryNeutronL2gatewayDevice,
100 @QueryParam("limit") String limit,
101 @QueryParam("marker") String marker,
102 @QueryParam("page_reverse") String pageReverse
103 // sorting not supported
105 INeutronL2gatewayCRUD l2gatewayInterface = getNeutronCRUD();
106 List<NeutronL2gateway> allL2gateways = l2gatewayInterface.getAll();
107 List<NeutronL2gateway> ans = new ArrayList<>();
108 for (NeutronL2gateway l2gateway : allL2gateways) {
109 if ((queryID == null || queryID.equals(l2gateway.getID()))
110 && (queryName == null || queryName.equals(l2gateway.getName()))
111 && (queryTenantID == null || queryTenantID.equals(l2gateway.getTenantID()))) {
112 if (fields.size() > 0) {
113 ans.add(l2gateway.extractFields(fields));
119 //TODO: apply pagination to results
120 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronL2gatewayRequest(ans)).build();
124 * Returns a specific L2gateway.
125 * @param l2gatewayID requested l2gateway uuid
126 * @param fields l2gateway attributes
127 * @return l2gateway details or error.
129 @Path("{l2gatewayID}")
131 @Produces({ MediaType.APPLICATION_JSON })
132 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
133 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
134 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
135 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
136 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
137 public Response showL2gateway(@PathParam("l2gatewayID") String l2gatewayID,
139 @QueryParam("fields") List<String> fields) {
140 return show(l2gatewayID, fields);
144 * Deletes a L2gateway.
145 * @param l2gatewayID l2gateway uuid which should be deleted
146 * @return success or error code
149 @Path("{l2gatewayID}")
151 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
152 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
153 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
154 public Response deleteL2gateway(@PathParam("l2gatewayID") String l2gatewayID) {
155 return delete(l2gatewayID);
159 * Updates a L2gateway.
160 * @param l2gatewayID gateway ID that needs to be modified
161 * @param input gateway attributes
164 @Path("{l2gatewayID}")
166 @Produces({ MediaType.APPLICATION_JSON })
167 @Consumes({ MediaType.APPLICATION_JSON })
168 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
169 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
170 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
171 public Response updateL2gateway(@PathParam("l2gatewayID") String l2gatewayID, NeutronL2gatewayRequest input) {
172 return update(l2gatewayID, input);