2 * Copyright (c) 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.Path;
18 import javax.ws.rs.PathParam;
19 import javax.ws.rs.Produces;
20 import javax.ws.rs.QueryParam;
21 import javax.ws.rs.core.MediaType;
22 import javax.ws.rs.core.Response;
23 import org.codehaus.enunciate.jaxrs.ResponseCode;
24 import org.codehaus.enunciate.jaxrs.StatusCodes;
25 import org.opendaylight.neutron.spi.INeutronMeteringLabelCRUD;
26 import org.opendaylight.neutron.spi.NeutronMeteringLabel;
29 * Neutron Northbound REST APIs for Metering Lables.
31 @Path("/metering/metering-labels")
32 public final class NeutronMeteringLabelsNorthbound extends
33 AbstractNeutronNorthbound<NeutronMeteringLabel, NeutronMeteringLabelRequest, INeutronMeteringLabelCRUD> {
35 private static final String RESOURCE_NAME = "Metering Label";
38 protected String getResourceName() {
43 * Returns a list of all metering labels.
46 @Produces({ MediaType.APPLICATION_JSON })
47 //@TypeHint(OpenStackNetworks.class)
48 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
49 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
50 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
51 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
52 public Response listMeteringLabels(
54 @QueryParam("fields") List<String> fields,
56 @QueryParam("id") String queryID,
57 @QueryParam("name") String queryName,
58 @QueryParam("tenant_id") String queryTenantID
59 // pagination and sorting are TODO
61 INeutronMeteringLabelCRUD labelInterface = getNeutronCRUD();
62 List<NeutronMeteringLabel> allNeutronMeteringLabel = labelInterface.getAll();
63 List<NeutronMeteringLabel> ans = new ArrayList<>();
64 for (NeutronMeteringLabel label : allNeutronMeteringLabel) {
65 if ((queryID == null || queryID.equals(label.getID()))
66 && (queryName == null || queryName.equals(label.getName()))
67 && (queryTenantID == null || queryTenantID.equals(label.getTenantID()))) {
68 if (fields.size() > 0) {
69 ans.add(label.extractFields(fields));
75 //TODO: apply pagination to results
76 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronMeteringLabelRequest(ans)).build();
80 * Returns a specific metering label.
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_FORBIDDEN, condition = "Forbidden"),
88 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
89 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
90 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
91 public Response showMeteringLabel(@PathParam("labelUUID") String labelUUID,
93 @QueryParam("fields") List<String> fields) {
94 return show(labelUUID, fields);
98 * Creates new metering label.
101 @Produces({ MediaType.APPLICATION_JSON })
102 @Consumes({ MediaType.APPLICATION_JSON })
103 //@TypeHint(NeutronNetwork.class)
104 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
105 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
106 public Response createMeteringLabel(final NeutronMeteringLabelRequest input) {
107 return create(input);
111 * Deletes a Metering Label.
115 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
116 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
117 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
118 public Response deleteMeteringLabel(@PathParam("labelUUID") String labelUUID) {
119 return delete(labelUUID);