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 com.webcohesion.enunciate.metadata.rs.ResponseCode;
11 import com.webcohesion.enunciate.metadata.rs.StatusCodes;
12 import java.net.HttpURLConnection;
13 import java.util.ArrayList;
14 import java.util.List;
15 import javax.inject.Inject;
16 import javax.inject.Singleton;
17 import javax.ws.rs.Consumes;
18 import javax.ws.rs.DELETE;
19 import javax.ws.rs.GET;
20 import javax.ws.rs.POST;
21 import javax.ws.rs.Path;
22 import javax.ws.rs.PathParam;
23 import javax.ws.rs.Produces;
24 import javax.ws.rs.QueryParam;
25 import javax.ws.rs.core.MediaType;
26 import javax.ws.rs.core.Response;
27 import org.apache.aries.blueprint.annotation.service.Reference;
28 import org.opendaylight.neutron.spi.INeutronMeteringLabelCRUD;
29 import org.opendaylight.neutron.spi.NeutronMeteringLabel;
32 * Neutron Northbound REST APIs for Metering Lables.
35 @Path("/metering/metering-labels")
36 public final class NeutronMeteringLabelsNorthbound extends
37 AbstractNeutronNorthbound<NeutronMeteringLabel, NeutronMeteringLabelRequest, INeutronMeteringLabelCRUD> {
39 private static final String RESOURCE_NAME = "Metering Label";
42 public NeutronMeteringLabelsNorthbound(@Reference INeutronMeteringLabelCRUD neutronCRUD) {
47 protected String getResourceName() {
52 * Returns a list of all metering labels.
55 @Produces({ MediaType.APPLICATION_JSON })
56 //@TypeHint(OpenStackNetworks.class)
57 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
58 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
59 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
60 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
61 public Response listMeteringLabels(
63 @QueryParam("fields") List<String> fields,
65 @QueryParam("id") String queryID,
66 @QueryParam("name") String queryName,
67 @QueryParam("tenant_id") String queryTenantID
68 // pagination and sorting are TODO
70 INeutronMeteringLabelCRUD labelInterface = getNeutronCRUD();
71 List<NeutronMeteringLabel> allNeutronMeteringLabel = labelInterface.getAll();
72 List<NeutronMeteringLabel> ans = new ArrayList<>();
73 for (NeutronMeteringLabel label : allNeutronMeteringLabel) {
74 if ((queryID == null || queryID.equals(label.getID()))
75 && (queryName == null || queryName.equals(label.getName()))
76 && (queryTenantID == null || queryTenantID.equals(label.getTenantID()))) {
77 if (fields.size() > 0) {
78 ans.add(label.extractFields(fields));
84 //TODO: apply pagination to results
85 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronMeteringLabelRequest(ans)).build();
89 * Returns a specific metering label.
93 @Produces({ MediaType.APPLICATION_JSON })
94 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
95 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
96 @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
97 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
98 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
99 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
100 public Response showMeteringLabel(@PathParam("labelUUID") String labelUUID,
102 @QueryParam("fields") List<String> fields) {
103 return show(labelUUID, fields);
107 * Creates new metering label.
110 @Produces({ MediaType.APPLICATION_JSON })
111 @Consumes({ MediaType.APPLICATION_JSON })
112 //@TypeHint(NeutronNetwork.class)
113 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
114 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
115 public Response createMeteringLabel(final NeutronMeteringLabelRequest input) {
116 return create(input);
120 * Deletes a Metering Label.
124 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
125 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
126 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
127 public Response deleteMeteringLabel(@PathParam("labelUUID") String labelUUID) {
128 return delete(labelUUID);