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.NeutronCRUDInterfaces;
29 import org.opendaylight.neutron.spi.NeutronQosPolicy;
31 @Path("/qos/policies")
32 public class NeutronQosPolicyNorthbound extends
33 AbstractNeutronNorthbound<NeutronQosPolicy, NeutronQosPolicyRequest, INeutronQosPolicyCRUD> {
35 private static final String RESOURCE_NAME = "Qos Policy";
38 protected String getResourceName() {
43 protected NeutronQosPolicy extractFields(NeutronQosPolicy o, List<String> fields) {
44 return o.extractFields(fields);
48 protected NeutronQosPolicyRequest newNeutronRequest(NeutronQosPolicy o) {
49 return new NeutronQosPolicyRequest(o);
53 protected INeutronQosPolicyCRUD getNeutronCRUD() {
54 NeutronCRUDInterfaces answer = new NeutronCRUDInterfaces().fetchINeutronQosPolicyCRUD(this);
55 if (answer.getQosPolicyInterface() == null) {
56 throw new ServiceUnavailableException(serviceUnavailable());
58 return answer.getQosPolicyInterface();
62 * Returns a list of all Qos Policies
65 @Produces({ MediaType.APPLICATION_JSON })
67 @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
68 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
69 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
70 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
71 public Response listGroups(
73 @QueryParam("fields") List<String> fields,
74 // OpenStack qos Policy attributes
75 @QueryParam("id") String queryQosPolicyUUID,
76 @QueryParam("tenant_id") String queryQosPolicyTenantID,
77 @QueryParam("name") String queryQosPolicyName,
78 @QueryParam("shared") Boolean queryQosPolicyIsShared,
80 @QueryParam("limit") String limit,
81 @QueryParam("marker") String marker,
82 @QueryParam("page_reverse") String pageReverse) {
83 INeutronQosPolicyCRUD qosPolicyInterface = getNeutronCRUD();
84 List<NeutronQosPolicy> ans = new ArrayList<>();
85 for (NeutronQosPolicy nsg : qosPolicyInterface.getAll()) {
86 if ((queryQosPolicyUUID == null || queryQosPolicyUUID.equals(nsg.getID())) &&
87 (queryQosPolicyTenantID == null || queryQosPolicyTenantID.equals(nsg.getTenantID())) &&
88 (queryQosPolicyName == null || queryQosPolicyName.equals(nsg.getQosPolicyName())) &&
89 (queryQosPolicyIsShared == null || queryQosPolicyIsShared.equals(nsg.getPolicyIsShared()))) {
90 if (fields.size() > 0) {
91 ans.add(extractFields(nsg, fields));
97 return Response.status(HttpURLConnection.HTTP_OK).entity(
98 new NeutronQosPolicyRequest(ans)).build();
102 * Returns a specific Qos Policy
104 @Path("{qosPolicyUUID}")
106 @Produces({ MediaType.APPLICATION_JSON })
108 @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
109 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
110 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
111 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
112 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
113 public Response showQosPolicy(
114 @PathParam("qosPolicyUUID") String qosPolicyUUID,
115 @QueryParam("fields") List<String> fields) {
116 return show(qosPolicyUUID, fields);
120 * Creates new Qos Policy
123 @Produces({ MediaType.APPLICATION_JSON })
124 @Consumes({ MediaType.APPLICATION_JSON })
126 @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
127 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
128 public Response createQosPolicies(final NeutronQosPolicyRequest input) {
129 return create(input);
133 * Updates a Qos Policy
135 @Path("{qosPolicyUUID}")
137 @Produces({ MediaType.APPLICATION_JSON })
138 @Consumes({ MediaType.APPLICATION_JSON })
140 @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
141 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
142 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
143 public Response updateQosPolicy(
144 @PathParam("qosPolicyUUID") String qosPolicyUUID,
145 final NeutronQosPolicyRequest input) {
146 return update(qosPolicyUUID, input);
150 * Deletes a Qos Policy
152 @Path("{qosPolicyUUID}")
155 @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
156 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
157 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
158 public Response deleteQosPolicy(
159 @PathParam("qosPolicyUUID") String qosPolicyUUID) {
160 return delete(qosPolicyUUID);