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;
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.codehaus.enunciate.jaxrs.TypeHint;
28 import org.opendaylight.neutron.spi.INeutronVpnServiceCRUD;
29 import org.opendaylight.neutron.spi.NeutronVpnService;
32 * Neutron Northbound REST APIs for VPN Service.<br>
33 * This class provides REST APIs for managing neutron VPN Services
37 * Authentication scheme : <b>HTTP Basic</b><br>
38 * Authentication realm : <b>opendaylight</b><br>
39 * Transport : <b>HTTP and HTTPS</b><br>
41 * HTTPS Authentication is disabled by default. Administrator can enable it in
42 * tomcat-server.xml after adding a proper keystore / SSL certificate from a
43 * trusted authority.<br>
45 * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
49 @Path("/vpn/vpnservices")
50 public final class NeutronVpnServicesNorthbound
51 extends AbstractNeutronNorthbound<NeutronVpnService, NeutronVpnServiceRequest, INeutronVpnServiceCRUD> {
53 private static final String RESOURCE_NAME = "VpnService";
56 protected String getResourceName() {
61 * Returns a list of all VPN Services.
65 @Produces({ MediaType.APPLICATION_JSON })
66 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
67 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
68 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
69 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
70 public Response listVPNServices(
72 @QueryParam("fields") List<String> fields,
73 // OpenStack VPNService attributes
74 @QueryParam("id") String queryID,
75 @QueryParam("tenant_id") String queryTenantID,
76 @QueryParam("name") String queryName,
77 @QueryParam("admin_state_up") Boolean queryAdminStateUp,
78 @QueryParam("router_id") String queryRouterID,
79 @QueryParam("status") String queryStatus,
80 @QueryParam("subnet_id") String querySubnetID,
82 @QueryParam("limit") String limit,
83 @QueryParam("marker") String marker,
84 @QueryParam("page_reverse") String pageReverse
85 // sorting not supported
87 INeutronVpnServiceCRUD vpnServiceInterface = getNeutronCRUD();
88 List<NeutronVpnService> allVPNService = vpnServiceInterface.getAll();
89 List<NeutronVpnService> ans = new ArrayList<>();
90 for (NeutronVpnService vpnService : allVPNService) {
91 if ((queryID == null || queryID.equals(vpnService.getID()))
92 && (queryName == null || queryName.equals(vpnService.getName()))
93 && (queryAdminStateUp == null || queryAdminStateUp.equals(vpnService.getAdminStateUp()))
94 && (queryStatus == null || queryStatus.equals(vpnService.getStatus()))
95 && (querySubnetID == null || querySubnetID.equals(vpnService.getSubnetUUID()))
96 && (queryRouterID == null || queryRouterID.equals(vpnService.getRouterUUID()))
97 && (queryTenantID == null || queryTenantID.equals(vpnService.getTenantID()))) {
98 if (fields.size() > 0) {
99 ans.add(vpnService.extractFields(fields));
106 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronVpnServiceRequest(ans)).build();
110 * Returns a specific VPN Service.
115 @Produces({ MediaType.APPLICATION_JSON })
116 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
117 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
118 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
119 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
120 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
121 public Response showVPNService(@PathParam("serviceID") String serviceID,
123 @QueryParam("fields") List<String> fields) {
124 return show(serviceID, fields);
128 * Creates new VPN Service.
131 @Produces({ MediaType.APPLICATION_JSON })
132 @Consumes({ MediaType.APPLICATION_JSON })
133 @TypeHint(NeutronVpnService.class)
134 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
135 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
136 public Response createVPNService(final NeutronVpnServiceRequest input) {
137 return create(input);
141 * Updates a VPN Service.
145 @Produces({ MediaType.APPLICATION_JSON })
146 @Consumes({ MediaType.APPLICATION_JSON })
147 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
148 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
149 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
150 public Response updateVPNService(@PathParam("serviceID") String serviceID, final NeutronVpnServiceRequest input) {
151 return update(serviceID, input);
155 * Deletes a VPN Service.
160 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
161 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
162 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
163 public Response deleteVPNService(@PathParam("serviceID") String serviceID) {
164 return delete(serviceID);