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.List;
14 import javax.ws.rs.Consumes;
15 import javax.ws.rs.DELETE;
16 import javax.ws.rs.GET;
17 import javax.ws.rs.POST;
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.INeutronL2gatewayConnectionCRUD;
27 import org.opendaylight.neutron.spi.NeutronL2gatewayConnection;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * Neutron Northbound REST APIs for L2 gateway Connection.<br>
33 * This class provides REST APIs for managing L2 gateway Connection
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
48 @Path("/l2gateway-connections")
49 public final class NeutronL2gatewayConnectionNorthbound extends AbstractNeutronNorthbound<NeutronL2gatewayConnection,
50 NeutronL2gatewayConnectionRequest, INeutronL2gatewayConnectionCRUD> {
52 static final Logger LOGGER = LoggerFactory.getLogger(NeutronL2gatewayConnectionNorthbound.class);
54 private static final String RESOURCE_NAME = "L2gatewayConnection";
57 protected String getResourceName() {
62 * Creates L2gateway Connection
63 * @param input contains connection details
67 @Produces({ MediaType.APPLICATION_JSON })
68 @Consumes({ MediaType.APPLICATION_JSON })
69 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
70 @ResponseCode(code = HttpURLConnection.HTTP_BAD_REQUEST, condition = "Bad Request"),
71 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
72 @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
73 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
74 @ResponseCode(code = HttpURLConnection.HTTP_CONFLICT, condition = "Conflict"),
75 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
76 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
78 public Response createL2gatewayConnection(final NeutronL2gatewayConnectionRequest input) {
79 LOGGER.debug("createL2GatewayConnection NeutronL2GatewayConnectionRequest");
84 * Returns a list of all L2gateway Connections.
88 @Produces({ MediaType.APPLICATION_JSON })
89 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
90 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
91 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
92 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
93 public Response listL2gatewayConnections(
95 @QueryParam("fields") List<String> fields,
96 @QueryParam("tenant_id") String queryTenantID,
97 @QueryParam("connection_id") String queryConnectionID,
98 @QueryParam("l2gateway_id") String queryL2gatewayID,
99 @QueryParam("network_id") String queryNetworkID,
100 @QueryParam("segment_id") String querySegmentID,
101 @QueryParam("port_id") String queryPortID,
102 @QueryParam("limit") String limit,
103 @QueryParam("marker") String marker,
104 @QueryParam("page_reverse") String pageReverse
105 // sorting not supported
107 INeutronL2gatewayConnectionCRUD l2gatewayConnectionInterface = getNeutronCRUD();
108 List<NeutronL2gatewayConnection> allL2gatewayConnections = l2gatewayConnectionInterface.getAll();
109 List<NeutronL2gatewayConnection> ans = new ArrayList<>();
110 for (NeutronL2gatewayConnection connection : allL2gatewayConnections) {
111 if ((queryTenantID == null || queryTenantID.equals(connection.getTenantID()))
112 && (queryConnectionID == null || queryConnectionID.equals(connection.getID()))
113 && (queryL2gatewayID == null || queryL2gatewayID.equals(connection.getL2gatewayID()))
114 && (queryNetworkID == null || queryNetworkID.equals(connection.getNetworkID()))
115 && (querySegmentID == null || (Integer.valueOf(querySegmentID).equals(connection.getSegmentID())))
116 && (queryPortID == null || queryPortID.equals(connection.getPortID()))) {
117 if (fields.size() > 0) {
118 ans.add(connection.extractFields(fields));
124 // TODO: apply pagination to results
125 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronL2gatewayConnectionRequest(ans)).build();
129 * Returns a specific L2gateway Connection.
130 * @param l2gatewayConnectionID gateway connectID to fetch
131 * @param fields attributes used for querying
134 @Path("{l2gatewayConnectionID}")
136 @Produces({ MediaType.APPLICATION_JSON })
137 @StatusCodes({ @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") })
142 public Response showL2gatewayID(@PathParam("l2gatewayConnectionID") String l2gatewayConnectionID,
144 @QueryParam("fields") List<String> fields) {
145 return show(l2gatewayConnectionID, fields);
149 * Deletes a L2gateway Connection
150 * @param l2gatewayConnectionID connection ID to delete
153 @Path("{l2gatewayConnectionID}")
155 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
156 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
157 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
158 public Response deleteL2gatewayConnection(@PathParam("l2gatewayConnectionID") String l2gatewayConnectionID) {
159 return delete(l2gatewayConnectionID);
162 // l2gwconnection API doesn't have update method