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
9 package org.opendaylight.neutron.northbound.api;
11 import java.net.HttpURLConnection;
13 import java.util.ArrayList;
14 import java.util.Iterator;
15 import java.util.List;
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.Context;
26 import javax.ws.rs.core.MediaType;
27 import javax.ws.rs.core.Response;
28 import javax.ws.rs.core.UriInfo;
30 import org.codehaus.enunciate.jaxrs.ResponseCode;
31 import org.codehaus.enunciate.jaxrs.StatusCodes;
32 import org.codehaus.enunciate.jaxrs.TypeHint;
34 import org.opendaylight.neutron.spi.INeutronMeteringLabelAware;
35 import org.opendaylight.neutron.spi.INeutronMeteringLabelCRUD;
36 import org.opendaylight.neutron.spi.NeutronCRUDInterfaces;
37 import org.opendaylight.neutron.spi.NeutronMeteringLabel;
40 * Neutron Northbound REST APIs for Metering Lables.<br>
41 * This class provides REST APIs for managing neutron metering labels
45 * Authentication scheme : <b>HTTP Basic</b><br>
46 * Authentication realm : <b>opendaylight</b><br>
47 * Transport : <b>HTTP and HTTPS</b><br>
49 * HTTPS Authentication is disabled by default. Administrator can enable it in
50 * tomcat-server.xml after adding a proper keystore / SSL certificate from a
51 * trusted authority.<br>
53 * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
57 @Path("/metering/metering-labels")
58 public class NeutronMeteringLabelsNorthbound
59 extends AbstractNeutronNorthbound<NeutronMeteringLabel, NeutronMeteringLabelRequest, INeutronMeteringLabelCRUD, INeutronMeteringLabelAware> {
60 private static final String RESOURCE_NAME = "Metering Label";
63 protected String getResourceName() {
68 protected NeutronMeteringLabel extractFields(NeutronMeteringLabel o, List<String> fields) {
69 return o.extractFields(fields);
73 protected INeutronMeteringLabelCRUD getNeutronCRUD() {
74 NeutronCRUDInterfaces answer = new NeutronCRUDInterfaces().fetchINeutronMeteringLabelCRUD(this);
75 if (answer.getMeteringLabelInterface() == null) {
76 throw new ServiceUnavailableException(serviceUnavailable());
78 return answer.getMeteringLabelInterface();
82 protected NeutronMeteringLabelRequest newNeutronRequest(NeutronMeteringLabel o) {
83 return new NeutronMeteringLabelRequest(o);
87 protected Object[] getInstances() {
88 return NeutronUtil.getInstances(INeutronMeteringLabelAware.class, this);
92 protected int canCreate(Object instance, NeutronMeteringLabel singleton) {
93 INeutronMeteringLabelAware service = (INeutronMeteringLabelAware) instance;
94 return service.canCreateMeteringLabel(singleton);
98 protected void created(Object instance, NeutronMeteringLabel singleton) {
99 INeutronMeteringLabelAware service = (INeutronMeteringLabelAware) instance;
100 service.neutronMeteringLabelCreated(singleton);
104 protected int canUpdate(Object instance, NeutronMeteringLabel delta, NeutronMeteringLabel original) {
109 protected void updated(Object instance, NeutronMeteringLabel updated) {
110 throw new UnsupportedOperationException();
114 protected int canDelete(Object instance, NeutronMeteringLabel singleton) {
115 INeutronMeteringLabelAware service = (INeutronMeteringLabelAware) instance;
116 return service.canDeleteMeteringLabel(singleton);
120 protected void deleted(Object instance, NeutronMeteringLabel singleton) {
121 INeutronMeteringLabelAware service = (INeutronMeteringLabelAware) instance;
122 service.neutronMeteringLabelDeleted(singleton);
129 * Returns a list of all metering labels */
132 @Produces({ MediaType.APPLICATION_JSON })
133 //@TypeHint(OpenStackNetworks.class)
135 @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
136 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
137 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
138 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
139 public Response listMeteringLabels(
141 @QueryParam("fields") List<String> fields,
143 @QueryParam("id") String queryID,
144 @QueryParam("name") String queryName,
145 @QueryParam("tenant_id") String queryTenantID,
146 @QueryParam("description") String queryDescription
147 // pagination and sorting are TODO
149 INeutronMeteringLabelCRUD labelInterface = getNeutronCRUD();
150 List<NeutronMeteringLabel> allNeutronMeteringLabel = labelInterface.getAllNeutronMeteringLabels();
151 List<NeutronMeteringLabel> ans = new ArrayList<NeutronMeteringLabel>();
152 Iterator<NeutronMeteringLabel> i = allNeutronMeteringLabel.iterator();
153 while (i.hasNext()) {
154 NeutronMeteringLabel oSS = i.next();
155 if ((queryID == null || queryID.equals(oSS.getID())) &&
156 (queryName == null || queryName.equals(oSS.getMeteringLabelName())) &&
157 (queryDescription == null || queryDescription.equals(oSS.getMeteringLabelDescription())) &&
158 (queryTenantID == null || queryTenantID.equals(oSS.getTenantID()))) {
159 if (fields.size() > 0) {
160 ans.add(extractFields(oSS,fields));
166 //TODO: apply pagination to results
167 return Response.status(HttpURLConnection.HTTP_OK).entity(
168 new NeutronMeteringLabelRequest(ans)).build();
172 * Returns a specific metering label */
176 @Produces({ MediaType.APPLICATION_JSON })
178 @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
179 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
180 @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
181 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
182 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
183 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
184 public Response showMeteringLabel(
185 @PathParam("labelUUID") String labelUUID,
187 @QueryParam("fields") List<String> fields) {
188 return show(labelUUID, fields);
192 * Creates new metering label */
194 @Produces({ MediaType.APPLICATION_JSON })
195 @Consumes({ MediaType.APPLICATION_JSON })
196 //@TypeHint(NeutronNetwork.class)
198 @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
199 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
200 public Response createMeteringLabel(final NeutronMeteringLabelRequest input) {
201 return create(input);
205 * Deletes a Metering Label */
210 @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
211 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
212 public Response deleteMeteringLabel(
213 @PathParam("labelUUID") String labelUUID) {
214 return delete(labelUUID);