2 * Copyright (c) 2013, 2015 IBM Corporation 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.INeutronRouterCRUD;
27 import org.opendaylight.neutron.spi.NeutronRouter;
28 import org.opendaylight.neutron.spi.NeutronRouterInterface;
31 * Neutron Northbound REST APIs for managing neutron routers.
34 public final class NeutronRoutersNorthbound
35 extends AbstractNeutronNorthbound<NeutronRouter, NeutronRouterRequest, INeutronRouterCRUD> {
37 private static final String RESOURCE_NAME = "Router";
40 protected String getResourceName() {
45 * Returns a list of all Routers.
48 @Produces({ MediaType.APPLICATION_JSON })
49 //@TypeHint(OpenStackRouters.class)
50 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
51 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
52 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
53 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
54 public Response listRouters(
56 @QueryParam("fields") List<String> fields,
57 // note: openstack isn't clear about filtering on lists, so we aren't handling them
58 @QueryParam("id") String queryID,
59 @QueryParam("name") String queryName,
60 @QueryParam("admin_state_up") Boolean queryAdminStateUp,
61 @QueryParam("status") String queryStatus,
62 @QueryParam("tenant_id") String queryTenantID,
63 @QueryParam("external_gateway_info") String queryExternalGatewayInfo,
65 @QueryParam("limit") String limit,
66 @QueryParam("marker") String marker,
67 @QueryParam("page_reverse") String pageReverse
68 // sorting not supported
70 INeutronRouterCRUD routerInterface = getNeutronCRUD();
71 if (routerInterface == null) {
72 throw new ServiceUnavailableException(serviceUnavailable());
74 List<NeutronRouter> allRouters = routerInterface.getAll();
75 List<NeutronRouter> ans = new ArrayList<>();
76 for (NeutronRouter router : allRouters) {
77 if ((queryID == null || queryID.equals(router.getID()))
78 && (queryName == null || queryName.equals(router.getName()))
79 && (queryAdminStateUp == null || queryAdminStateUp.equals(router.getAdminStateUp()))
80 && (queryStatus == null || queryStatus.equals(router.getStatus()))
81 && (queryTenantID == null || queryTenantID.equals(router.getTenantID()))) {
82 if (fields.size() > 0) {
83 ans.add(router.extractFields(fields));
89 //TODO: apply pagination to results
90 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronRouterRequest(ans)).build();
94 * Returns a specific Router.
98 @Produces({ MediaType.APPLICATION_JSON })
99 //@TypeHint(OpenStackRouters.class)
100 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
101 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
102 @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
103 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
104 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
105 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
106 public Response showRouter(@PathParam("routerUUID") String routerUUID,
108 @QueryParam("fields") List<String> fields) {
109 return show(routerUUID, fields);
113 * Creates new Routers.
116 @Produces({ MediaType.APPLICATION_JSON })
117 @Consumes({ MediaType.APPLICATION_JSON })
118 //@TypeHint(OpenStackRouters.class)
119 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
120 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
121 public Response createRouters(final NeutronRouterRequest input) {
122 return create(input);
126 protected void updateDelta(String uuid, NeutronRouter delta, NeutronRouter original) {
128 delta.setTenantID(original.getTenantID());
134 @Path("{routerUUID}")
136 @Produces({ MediaType.APPLICATION_JSON })
137 @Consumes({ MediaType.APPLICATION_JSON })
138 //@TypeHint(OpenStackRouters.class)
139 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
140 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
141 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
142 public Response updateRouter(@PathParam("routerUUID") String routerUUID, NeutronRouterRequest input) {
143 return update(routerUUID, input);
149 @Path("{routerUUID}")
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 deleteRouter(@PathParam("routerUUID") String routerUUID) {
155 return delete(routerUUID);
159 * Adds an interface to a router.
161 @Path("{routerUUID}/add_router_interface")
163 @Produces({ MediaType.APPLICATION_JSON })
164 @Consumes({ MediaType.APPLICATION_JSON })
165 //@TypeHint(OpenStackRouterInterfaces.class)
166 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful") })
167 public Response addRouterInterface(@PathParam("routerUUID") String routerUUID, NeutronRouterInterface input) {
168 // Do nothing. Keep this interface for compatibility
169 return Response.status(HttpURLConnection.HTTP_OK).entity(input).build();
172 @Path("{routerUUID}/remove_router_interface")
174 @Produces({ MediaType.APPLICATION_JSON })
175 @Consumes({ MediaType.APPLICATION_JSON })
176 //@TypeHint(OpenStackRouterInterfaces.class)
177 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful") })
178 public Response removeRouterInterface(@PathParam("routerUUID") String routerUUID, NeutronRouterInterface input) {
179 // Do nothing. Keep this interface for compatibility
180 return Response.status(HttpURLConnection.HTTP_OK).entity(input).build();