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.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.INeutronTrunkCRUD;
27 import org.opendaylight.neutron.spi.NeutronTrunk;
30 public final class NeutronTrunksNorthbound
31 extends AbstractNeutronNorthbound<NeutronTrunk, NeutronTrunkRequest, INeutronTrunkCRUD> {
33 private static final String RESOURCE_NAME = "Trunk";
36 protected String getResourceName() {
41 * Returns a list of all Trunks.
44 @Produces({ MediaType.APPLICATION_JSON })
45 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
46 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
47 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
48 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
49 public Response listGroups(
51 @QueryParam("fields") List<String> fields,
52 // OpenStack trunk attributes
53 @QueryParam("id") String queryUUID,
54 @QueryParam("tenant_id") String queryTenantID,
55 @QueryParam("status") String queryStatus,
56 @QueryParam("name") String queryName,
58 @QueryParam("limit") String limit,
59 @QueryParam("marker") String marker,
60 @QueryParam("page_reverse") String pageReverse) {
61 INeutronTrunkCRUD trunkInterface = getNeutronCRUD();
62 List<NeutronTrunk> ans = new ArrayList<>();
63 for (NeutronTrunk nsg : trunkInterface.getAll()) {
64 if ((queryUUID == null || queryUUID.equals(nsg.getID()))
65 && (queryTenantID == null || queryTenantID.equals(nsg.getTenantID()))
66 && (queryStatus == null || queryStatus.equals(nsg.getStatus()))
67 && (queryName == null || queryName.equals(nsg.getName()))) {
68 if (fields.size() > 0) {
69 ans.add(nsg.extractFields(fields));
75 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronTrunkRequest(ans)).build();
79 * Returns a specific Trunk.
83 @Produces({ MediaType.APPLICATION_JSON })
84 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
85 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
86 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
87 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
88 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
89 public Response showTrunk(@PathParam("trunkUUID") String trunkUUID,
90 @QueryParam("fields") List<String> fields) {
91 return show(trunkUUID, fields);
98 @Produces({ MediaType.APPLICATION_JSON })
99 @Consumes({ MediaType.APPLICATION_JSON })
100 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
101 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
102 public Response createTrunks(final NeutronTrunkRequest input) {
103 return create(input);
111 @Produces({ MediaType.APPLICATION_JSON })
112 @Consumes({ MediaType.APPLICATION_JSON })
113 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
114 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
115 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
116 public Response updateTrunk(@PathParam("trunkUUID") String trunkUUID,
117 final NeutronTrunkRequest input) {
118 return update(trunkUUID, input);
126 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
127 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
128 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
129 public Response deleteTrunk(@PathParam("trunkUUID") String trunkUUID) {
130 return delete(trunkUUID);