2 * Copyright (c) 2016 Intel, Corp. 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.PUT;
19 import javax.ws.rs.Path;
20 import javax.ws.rs.PathParam;
21 import javax.ws.rs.Produces;
22 import javax.ws.rs.QueryParam;
23 import javax.ws.rs.core.MediaType;
24 import javax.ws.rs.core.Response;
25 import org.codehaus.enunciate.jaxrs.ResponseCode;
26 import org.codehaus.enunciate.jaxrs.StatusCodes;
27 import org.opendaylight.neutron.spi.INeutronQosPolicyCRUD;
28 import org.opendaylight.neutron.spi.NeutronQosPolicy;
30 @Path("/qos/policies")
31 public final class NeutronQosPolicyNorthbound
32 extends AbstractNeutronNorthbound<NeutronQosPolicy, NeutronQosPolicyRequest, INeutronQosPolicyCRUD> {
34 private static final String RESOURCE_NAME = "Qos Policy";
37 protected String getResourceName() {
42 * Returns a list of all Qos Policies.
45 @Produces({ MediaType.APPLICATION_JSON })
46 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
47 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
48 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
49 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
50 public Response listGroups(
52 @QueryParam("fields") List<String> fields,
53 // OpenStack qos Policy attributes
54 @QueryParam("id") String queryQosPolicyUUID,
55 @QueryParam("tenant_id") String queryQosPolicyTenantID,
56 @QueryParam("name") String queryQosPolicyName,
57 @QueryParam("shared") Boolean queryQosPolicyIsShared,
59 @QueryParam("limit") String limit,
60 @QueryParam("marker") String marker,
61 @QueryParam("page_reverse") String pageReverse) {
62 INeutronQosPolicyCRUD qosPolicyInterface = getNeutronCRUD();
63 List<NeutronQosPolicy> ans = new ArrayList<>();
64 for (NeutronQosPolicy nsg : qosPolicyInterface.getAll()) {
65 if ((queryQosPolicyUUID == null || queryQosPolicyUUID.equals(nsg.getID()))
66 && (queryQosPolicyTenantID == null || queryQosPolicyTenantID.equals(nsg.getTenantID()))
67 && (queryQosPolicyName == null || queryQosPolicyName.equals(nsg.getName()))
68 && (queryQosPolicyIsShared == null || queryQosPolicyIsShared.equals(nsg.getPolicyIsShared()))) {
69 if (fields.size() > 0) {
70 ans.add(nsg.extractFields(fields));
76 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronQosPolicyRequest(ans)).build();
80 * Returns a specific Qos Policy.
82 @Path("{qosPolicyUUID}")
84 @Produces({ MediaType.APPLICATION_JSON })
85 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
86 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
87 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
88 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
89 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
90 public Response showQosPolicy(@PathParam("qosPolicyUUID") String qosPolicyUUID,
91 @QueryParam("fields") List<String> fields) {
92 return show(qosPolicyUUID, fields);
96 * Creates new Qos Policy.
99 @Produces({ MediaType.APPLICATION_JSON })
100 @Consumes({ MediaType.APPLICATION_JSON })
101 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
102 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
103 public Response createQosPolicies(final NeutronQosPolicyRequest input) {
104 return create(input);
108 * Updates a Qos Policy.
110 @Path("{qosPolicyUUID}")
112 @Produces({ MediaType.APPLICATION_JSON })
113 @Consumes({ MediaType.APPLICATION_JSON })
114 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
115 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
116 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
117 public Response updateQosPolicy(@PathParam("qosPolicyUUID") String qosPolicyUUID,
118 final NeutronQosPolicyRequest input) {
119 return update(qosPolicyUUID, input);
123 * Deletes a Qos Policy.
125 @Path("{qosPolicyUUID}")
127 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
128 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
129 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
130 public Response deleteQosPolicy(@PathParam("qosPolicyUUID") String qosPolicyUUID) {
131 return delete(qosPolicyUUID);