2 * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. 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.inject.Inject;
14 import javax.inject.Singleton;
15 import javax.ws.rs.Consumes;
16 import javax.ws.rs.DELETE;
17 import javax.ws.rs.GET;
18 import javax.ws.rs.POST;
19 import javax.ws.rs.PUT;
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.MediaType;
25 import javax.ws.rs.core.Response;
26 import org.codehaus.enunciate.jaxrs.ResponseCode;
27 import org.codehaus.enunciate.jaxrs.StatusCodes;
28 import org.opendaylight.neutron.spi.INeutronTrunkCRUD;
29 import org.opendaylight.neutron.spi.NeutronTrunk;
30 import org.ops4j.pax.cdi.api.OsgiService;
34 public final class NeutronTrunksNorthbound
35 extends AbstractNeutronNorthbound<NeutronTrunk, NeutronTrunkRequest, INeutronTrunkCRUD> {
37 private static final String RESOURCE_NAME = "Trunk";
40 public NeutronTrunksNorthbound(@OsgiService INeutronTrunkCRUD neutronCRUD) {
45 protected String getResourceName() {
50 * Returns a list of all Trunks.
53 @Produces({ MediaType.APPLICATION_JSON })
54 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
55 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
56 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
57 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
58 public Response listGroups(
60 @QueryParam("fields") List<String> fields,
61 // OpenStack trunk attributes
62 @QueryParam("id") String queryUUID,
63 @QueryParam("tenant_id") String queryTenantID,
64 @QueryParam("status") String queryStatus,
65 @QueryParam("name") String queryName,
67 @QueryParam("limit") String limit,
68 @QueryParam("marker") String marker,
69 @QueryParam("page_reverse") String pageReverse) {
70 INeutronTrunkCRUD trunkInterface = getNeutronCRUD();
71 List<NeutronTrunk> ans = new ArrayList<>();
72 for (NeutronTrunk nsg : trunkInterface.getAll()) {
73 if ((queryUUID == null || queryUUID.equals(nsg.getID()))
74 && (queryTenantID == null || queryTenantID.equals(nsg.getTenantID()))
75 && (queryStatus == null || queryStatus.equals(nsg.getStatus()))
76 && (queryName == null || queryName.equals(nsg.getName()))) {
77 if (fields.size() > 0) {
78 ans.add(nsg.extractFields(fields));
84 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronTrunkRequest(ans)).build();
88 * Returns a specific Trunk.
92 @Produces({ MediaType.APPLICATION_JSON })
93 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
94 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
95 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
96 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
97 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
98 public Response showTrunk(@PathParam("trunkUUID") String trunkUUID,
99 @QueryParam("fields") List<String> fields) {
100 return show(trunkUUID, fields);
107 @Produces({ MediaType.APPLICATION_JSON })
108 @Consumes({ MediaType.APPLICATION_JSON })
109 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
110 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
111 public Response createTrunks(final NeutronTrunkRequest input) {
112 return create(input);
120 @Produces({ MediaType.APPLICATION_JSON })
121 @Consumes({ MediaType.APPLICATION_JSON })
122 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
123 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
124 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
125 public Response updateTrunk(@PathParam("trunkUUID") String trunkUUID,
126 final NeutronTrunkRequest input) {
127 return update(trunkUUID, input);
135 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
136 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
137 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
138 public Response deleteTrunk(@PathParam("trunkUUID") String trunkUUID) {
139 return delete(trunkUUID);