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.Path;
18 import javax.ws.rs.PathParam;
19 import javax.ws.rs.Produces;
20 import javax.ws.rs.QueryParam;
21 import javax.ws.rs.core.MediaType;
22 import javax.ws.rs.core.Response;
23 import org.codehaus.enunciate.jaxrs.ResponseCode;
24 import org.codehaus.enunciate.jaxrs.StatusCodes;
25 import org.opendaylight.neutron.spi.INeutronL2gatewayConnectionCRUD;
26 import org.opendaylight.neutron.spi.NeutronL2gatewayConnection;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 * Neutron Northbound REST APIs for L2 gateway Connection.
33 @Path("/l2gateway-connections")
34 public final class NeutronL2gatewayConnectionNorthbound extends AbstractNeutronNorthbound<NeutronL2gatewayConnection,
35 NeutronL2gatewayConnectionRequest, INeutronL2gatewayConnectionCRUD> {
37 private static final Logger LOG = LoggerFactory.getLogger(NeutronL2gatewayConnectionNorthbound.class);
39 private static final String RESOURCE_NAME = "L2gatewayConnection";
42 protected String getResourceName() {
47 * Creates L2gateway Connection.
48 * @param input contains connection details
52 @Produces({ MediaType.APPLICATION_JSON })
53 @Consumes({ MediaType.APPLICATION_JSON })
54 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
55 @ResponseCode(code = HttpURLConnection.HTTP_BAD_REQUEST, condition = "Bad Request"),
56 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
57 @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
58 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
59 @ResponseCode(code = HttpURLConnection.HTTP_CONFLICT, condition = "Conflict"),
60 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
61 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
63 public Response createL2gatewayConnection(final NeutronL2gatewayConnectionRequest input) {
64 LOG.debug("createL2GatewayConnection NeutronL2GatewayConnectionRequest");
69 * Returns a list of all L2gateway Connections.
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 listL2gatewayConnections(
79 @QueryParam("fields") List<String> fields,
80 @QueryParam("tenant_id") String queryTenantID,
81 @QueryParam("connection_id") String queryConnectionID,
82 @QueryParam("l2gateway_id") String queryL2gatewayID,
83 @QueryParam("network_id") String queryNetworkID,
84 @QueryParam("segment_id") String querySegmentID,
85 @QueryParam("port_id") String queryPortID,
86 @QueryParam("limit") String limit,
87 @QueryParam("marker") String marker,
88 @QueryParam("page_reverse") String pageReverse
89 // sorting not supported
91 INeutronL2gatewayConnectionCRUD l2gatewayConnectionInterface = getNeutronCRUD();
92 List<NeutronL2gatewayConnection> allL2gatewayConnections = l2gatewayConnectionInterface.getAll();
93 List<NeutronL2gatewayConnection> ans = new ArrayList<>();
94 for (NeutronL2gatewayConnection connection : allL2gatewayConnections) {
95 if ((queryTenantID == null || queryTenantID.equals(connection.getTenantID()))
96 && (queryConnectionID == null || queryConnectionID.equals(connection.getID()))
97 && (queryL2gatewayID == null || queryL2gatewayID.equals(connection.getL2gatewayID()))
98 && (queryNetworkID == null || queryNetworkID.equals(connection.getNetworkID()))
99 && (querySegmentID == null || Integer.valueOf(querySegmentID).equals(connection.getSegmentID()))
100 && (queryPortID == null || queryPortID.equals(connection.getPortID()))) {
101 if (fields.size() > 0) {
102 ans.add(connection.extractFields(fields));
108 // TODO: apply pagination to results
109 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronL2gatewayConnectionRequest(ans)).build();
113 * Returns a specific L2gateway Connection.
114 * @param l2gatewayConnectionID gateway connectID to fetch
115 * @param fields attributes used for querying
118 @Path("{l2gatewayConnectionID}")
120 @Produces({ MediaType.APPLICATION_JSON })
121 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
122 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
123 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
124 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
125 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
126 public Response showL2gatewayID(@PathParam("l2gatewayConnectionID") String l2gatewayConnectionID,
128 @QueryParam("fields") List<String> fields) {
129 return show(l2gatewayConnectionID, fields);
133 * Deletes a L2gateway Connection.
134 * @param l2gatewayConnectionID connection ID to delete
137 @Path("{l2gatewayConnectionID}")
139 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
140 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
141 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
142 public Response deleteL2gatewayConnection(@PathParam("l2gatewayConnectionID") String l2gatewayConnectionID) {
143 return delete(l2gatewayConnectionID);
146 // l2gwconnection API doesn't have update method