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
9 package org.opendaylight.neutron.northbound.api;
11 import java.net.HttpURLConnection;
12 import java.util.ArrayList;
13 import java.util.Iterator;
14 import java.util.List;
16 import javax.ws.rs.Consumes;
17 import javax.ws.rs.DELETE;
18 import javax.ws.rs.GET;
19 import javax.ws.rs.POST;
20 import javax.ws.rs.Path;
21 import javax.ws.rs.PathParam;
22 import javax.ws.rs.Produces;
23 import javax.ws.rs.QueryParam;
24 import javax.ws.rs.core.Context;
25 import javax.ws.rs.core.MediaType;
26 import javax.ws.rs.core.Response;
27 import javax.ws.rs.core.UriInfo;
29 import org.codehaus.enunciate.jaxrs.ResponseCode;
30 import org.codehaus.enunciate.jaxrs.StatusCodes;
31 import org.opendaylight.neutron.spi.INeutronL2gatewayConnectionCRUD;
32 import org.opendaylight.neutron.spi.NeutronCRUDInterfaces;
33 import org.opendaylight.neutron.spi.NeutronL2gatewayConnection;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
38 * Neutron Northbound REST APIs for L2 gateway Connection.<br>
39 * This class provides REST APIs for managing L2 gateway Connection
43 * Authentication scheme : <b>HTTP Basic</b><br>
44 * Authentication realm : <b>opendaylight</b><br>
45 * Transport : <b>HTTP and HTTPS</b><br>
47 * HTTPS Authentication is disabled by default. Administrator can enable it in
48 * tomcat-server.xml after adding a proper keystore / SSL certificate from a
49 * trusted authority.<br>
51 * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
54 @Path ("/l2gateway-connections")
55 public class NeutronL2gatewayConnectionNorthbound
56 extends AbstractNeutronNorthbound<NeutronL2gatewayConnection, NeutronL2gatewayConnectionRequest, INeutronL2gatewayConnectionCRUD> {
58 static final Logger logger = LoggerFactory.getLogger(NeutronL2gatewayConnectionNorthbound.class);
63 private static final String RESOURCE_NAME = "L2gatewayConnection";
64 private static final String INTERFACE_NAME = "L2gatewayConnection CRUD Interface";
67 protected String getResourceName() {
72 protected NeutronL2gatewayConnection extractFields(NeutronL2gatewayConnection o,
73 List<String> fields) {
74 return o.extractFields(fields);
78 protected NeutronL2gatewayConnectionRequest newNeutronRequest(NeutronL2gatewayConnection o) {
79 return new NeutronL2gatewayConnectionRequest(o);
83 protected INeutronL2gatewayConnectionCRUD getNeutronCRUD() {
84 NeutronCRUDInterfaces answer = new NeutronCRUDInterfaces().fetchINeutronL2gatewayConnectionCRUD(this);
85 if (answer.getFirewallInterface() == null) {
86 throw new ServiceUnavailableException(serviceUnavailable());
88 return answer.getL2gatewayConnectionInterface();
92 * Creates L2gateway Connection
93 * @param input contains connection details
97 @Produces ({MediaType.APPLICATION_JSON})
98 @Consumes ({MediaType.APPLICATION_JSON})
100 @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
101 @ResponseCode(code = HttpURLConnection.HTTP_BAD_REQUEST, condition = "Bad Request"),
102 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
103 @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
104 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
105 @ResponseCode(code = HttpURLConnection.HTTP_CONFLICT, condition = "Conflict"),
106 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
107 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
109 public Response createL2gatewayConnection(final NeutronL2gatewayConnectionRequest input) {
110 logger.debug("createL2GatewayConnection NeutronL2GatewayConnectionRequest");
111 return create(input);
115 * Returns a list of all L2gateway Connections.
119 @Produces({ MediaType.APPLICATION_JSON })
121 @ResponseCode(code = HttpURLConnection.HTTP_OK,
122 condition = "Operation successful"),
123 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED,
124 condition = "Unauthorized"),
125 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED,
126 condition = "Not Implemented"),
127 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE,
128 condition = "No providers available") })
129 public Response listL2gatewayConnections(
131 @QueryParam("fields") List<String> fields,
132 @QueryParam("tenant_id") String queryTenantID,
133 @QueryParam("connection_id") String queryConnectionID,
134 @QueryParam("l2gateway_id") String queryL2gatewayID,
135 @QueryParam("network_id") String queryNetworkID,
136 @QueryParam("segment_id") String querySegmentID,
137 @QueryParam("port_id") String queryPortID,
138 @QueryParam ("limit") String limit,
139 @QueryParam ("marker") String marker,
140 @QueryParam ("page_reverse") String pageReverse
141 // sorting not supported
143 INeutronL2gatewayConnectionCRUD l2gatewayConnectionInterface = getNeutronInterfaces()
144 .getL2gatewayConnectionInterface();
145 if (l2gatewayConnectionInterface == null) {
146 throw new ServiceUnavailableException(INTERFACE_NAME
147 + RestMessages.SERVICEUNAVAILABLE.toString());
149 List<NeutronL2gatewayConnection> allL2gatewayConnections = l2gatewayConnectionInterface.getAll();
150 List<NeutronL2gatewayConnection> ans = new ArrayList<NeutronL2gatewayConnection>();
151 Iterator<NeutronL2gatewayConnection> i = allL2gatewayConnections
153 while (i.hasNext()) {
154 NeutronL2gatewayConnection oSS = i.next();
155 if ((queryTenantID == null || queryTenantID.equals(oSS
157 && (queryConnectionID == null || queryConnectionID
158 .equals(oSS.getID()))
159 && (queryL2gatewayID == null || queryL2gatewayID.equals(oSS
161 && (queryNetworkID == null || queryNetworkID.equals(oSS
163 && (querySegmentID == null || querySegmentID.equals(oSS
165 && (queryPortID == null || queryPortID.equals(oSS
167 if (fields.size() > 0) {
168 ans.add(extractFields(oSS, fields));
174 // TODO: apply pagination to results
175 return Response.status(HttpURLConnection.HTTP_OK)
176 .entity(new NeutronL2gatewayConnectionRequest(ans)).build();
180 * Returns a specific L2gateway Connection.
181 * @param l2gatewayConnectionID gateway connectID to fetch
182 * @param fields attributes used for querying
185 @Path ("{l2gatewayConnectionID}")
187 @Produces ({MediaType.APPLICATION_JSON})
189 @ResponseCode (code = HttpURLConnection.HTTP_OK,
190 condition = "Operation successful"),
191 @ResponseCode (code = HttpURLConnection.HTTP_UNAUTHORIZED,
192 condition = "Unauthorized"),
193 @ResponseCode (code = HttpURLConnection.HTTP_NOT_FOUND,
194 condition = "Not Found"),
195 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED,
196 condition = "Not Implemented"),
197 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE,
198 condition = "No providers available") })
199 public Response showL2gatewayID(@PathParam("l2gatewayConnectionID") String l2gatewayConnectionID,
201 @QueryParam("fields") List<String> fields) {
202 return show(l2gatewayConnectionID, fields);
206 * Deletes a L2gateway Connection
207 * @param l2gatewayConnectionID connection ID to delete
210 @Path("{l2gatewayConnectionID}")
213 @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT,
214 condition = "No Content"),
215 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE,
216 condition = "No providers available") })
217 public Response deleteL2gatewayConnection(
218 @PathParam("l2gatewayConnectionID") String l2gatewayConnectionID) {
219 return delete(l2gatewayConnectionID);
222 private NeutronCRUDInterfaces getNeutronInterfaces() {
223 logger.debug("Get Neutron interface");
224 NeutronCRUDInterfaces answer = new NeutronCRUDInterfaces().fetchINeutronL2gatewayConnectionCRUD(this);
225 if (answer.getL2gatewayConnectionInterface() == null) {
226 throw new ServiceUnavailableException(INTERFACE_NAME + RestMessages.SERVICEUNAVAILABLE.toString());
231 // l2gwconnection API doesn't have update method