[Boron] remove I*Aware interface
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronVPNIPSECSiteConnectionsNorthbound.java
1 /*
2  * Copyright (c) 2013, 2015 IBM Corporation and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.neutron.northbound.api;
10
11 import java.net.HttpURLConnection;
12
13 import java.util.ArrayList;
14 import java.util.Iterator;
15 import java.util.List;
16
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.PUT;
22 import javax.ws.rs.Path;
23 import javax.ws.rs.PathParam;
24 import javax.ws.rs.Produces;
25 import javax.ws.rs.QueryParam;
26 import javax.ws.rs.core.Context;
27 import javax.ws.rs.core.MediaType;
28 import javax.ws.rs.core.Response;
29 import javax.ws.rs.core.UriInfo;
30
31 import org.codehaus.enunciate.jaxrs.ResponseCode;
32 import org.codehaus.enunciate.jaxrs.StatusCodes;
33 import org.codehaus.enunciate.jaxrs.TypeHint;
34 import org.opendaylight.neutron.spi.INeutronVPNIPSECSiteConnectionsCRUD;
35 import org.opendaylight.neutron.spi.NeutronCRUDInterfaces;
36 import org.opendaylight.neutron.spi.NeutronVPNIPSECSiteConnection;
37
38 /**
39  * Neutron Northbound REST APIs for VPN IPSEC SiteConnection.<br>
40  * This class provides REST APIs for managing neutron VPN IPSEC SiteConnections
41  *
42  * <br>
43  * <br>
44  * Authentication scheme : <b>HTTP Basic</b><br>
45  * Authentication realm : <b>opendaylight</b><br>
46  * Transport : <b>HTTP and HTTPS</b><br>
47  * <br>
48  * HTTPS Authentication is disabled by default. Administrator can enable it in
49  * tomcat-server.xml after adding a proper keystore / SSL certificate from a
50  * trusted authority.<br>
51  * More info :
52  * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
53  *
54  */
55
56 @Path("/vpn/ipsecsiteconnections")
57 public class NeutronVPNIPSECSiteConnectionsNorthbound
58     extends AbstractNeutronNorthbound<NeutronVPNIPSECSiteConnection, NeutronVPNIPSECSiteConnectionRequest, INeutronVPNIPSECSiteConnectionsCRUD> {
59
60     private static final String RESOURCE_NAME = "VPNIPSECSiteConnections";
61
62     @Override
63     protected String getResourceName() {
64         return RESOURCE_NAME;
65     }
66
67     @Override
68     protected NeutronVPNIPSECSiteConnection extractFields(NeutronVPNIPSECSiteConnection o, List<String> fields) {
69         return o.extractFields(fields);
70     }
71
72     @Override
73     protected NeutronVPNIPSECSiteConnectionRequest newNeutronRequest(NeutronVPNIPSECSiteConnection o) {
74         return new NeutronVPNIPSECSiteConnectionRequest(o);
75     }
76
77     @Override
78     protected INeutronVPNIPSECSiteConnectionsCRUD getNeutronCRUD() {
79         NeutronCRUDInterfaces answer = new NeutronCRUDInterfaces().fetchINeutronVPNIPSECSiteConnectionsCRUD(this);
80         if (answer.getVPNIPSECSiteConnectionsInterface() == null) {
81             throw new ServiceUnavailableException(serviceUnavailable());
82         }
83         return answer.getVPNIPSECSiteConnectionsInterface();
84     }
85
86     @Context
87     UriInfo uriInfo;
88
89     /**
90      * Returns a list of all VPN IPSEC SiteConnections
91      */
92
93     @GET
94     @Produces({ MediaType.APPLICATION_JSON })
95     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
96             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
97             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
98             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
99     public Response listVPNIPSECSiteConnections(
100             // return fields
101             @QueryParam("fields") List<String> fields,
102             // filter fields
103             @QueryParam("id") String queryID, @QueryParam("tenant_id") String queryTenantID,
104             @QueryParam("name") String queryName,
105             @QueryParam("peer_address") String queryPeerAddress, @QueryParam("peer_id") String queryPeerID,
106             @QueryParam("route_mode") String queryRouteMode, @QueryParam("mtu") Integer queryMtu,
107             @QueryParam("auth_mode") String queryAuthMode, @QueryParam("psk") String queryPsk,
108             @QueryParam("initiator") String queryInitiator, @QueryParam("admin_state_up") Boolean queryAdminStateUp,
109             @QueryParam("status") String queryStatus, @QueryParam("ikepolicy_id") String queryIkePolicyID,
110             @QueryParam("ipsecpolicy_id") String queryIpSecPolicyID,
111             @QueryParam("vpnservice_id") String queryVpnServiceID
112     // pagination and sorting are TODO
113     ) {
114         INeutronVPNIPSECSiteConnectionsCRUD labelInterface = getNeutronCRUD();
115         List<NeutronVPNIPSECSiteConnection> allNeutronVPNIPSECSiteConnection = labelInterface
116                 .getAllNeutronVPNIPSECSiteConnections();
117         List<NeutronVPNIPSECSiteConnection> ans = new ArrayList<NeutronVPNIPSECSiteConnection>();
118         Iterator<NeutronVPNIPSECSiteConnection> i = allNeutronVPNIPSECSiteConnection.iterator();
119         while (i.hasNext()) {
120             NeutronVPNIPSECSiteConnection oSS = i.next();
121             if ((queryID == null || queryID.equals(oSS.getID()))
122                     && (queryTenantID == null || queryTenantID.equals(oSS.getTenantID()))
123                     && (queryName == null || queryName.equals(oSS.getName()))
124                     && (queryPeerAddress == null || queryPeerAddress.equals(oSS.getPeerAddress()))
125                     && (queryPeerID == null || queryPeerID.equals(oSS.getPeerID()))
126                     && (queryRouteMode == null || queryRouteMode.equals(oSS.getRouteMode()))
127                     && (queryMtu == null || queryMtu.equals(oSS.getMtu()))
128                     && (queryAuthMode == null || queryAuthMode.equals(oSS.getAuthMode()))
129                     && (queryPsk == null || queryPsk.equals(oSS.getPreSharedKey()))
130                     && (queryInitiator == null || queryInitiator.equals(oSS.getInitiator()))
131                     && (queryAdminStateUp == null || queryAdminStateUp.equals(oSS.getAdminStateUp()))
132                     && (queryStatus == null || queryStatus.equals(oSS.getStatus()))
133                     && (queryIkePolicyID == null || queryIkePolicyID.equals(oSS.getIkePolicyID()))
134                     && (queryIpSecPolicyID == null || queryIpSecPolicyID.equals(oSS.getIpsecPolicyID()))
135                     && (queryVpnServiceID == null || queryVpnServiceID.equals(oSS.getVpnServiceID()))) {
136                 if (fields.size() > 0) {
137                     ans.add(extractFields(oSS, fields));
138                 } else {
139                     ans.add(oSS);
140                 }
141             }
142         }
143
144         // TODO: apply pagination to results
145         return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronVPNIPSECSiteConnectionRequest(ans)).build();
146     }
147
148     /**
149      * Returns a specific VPN IPSEC SiteConnection
150      */
151
152     @Path("{connectionID}")
153     @GET
154     @Produces({ MediaType.APPLICATION_JSON })
155     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
156             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
157             @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
158             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
159             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
160             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
161     public Response showVPNIPSECSiteConnection(@PathParam("connectionID") String connectionID,
162     // return fields
163             @QueryParam("fields") List<String> fields) {
164         return show(connectionID, fields);
165     }
166
167     /**
168      * Creates new VPN IPSEC SiteConnection
169      */
170     @POST
171     @Produces({ MediaType.APPLICATION_JSON })
172     @Consumes({ MediaType.APPLICATION_JSON })
173     @TypeHint(NeutronVPNIPSECSiteConnection.class)
174     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
175             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
176     public Response createVPNIPSECSiteConnection(final NeutronVPNIPSECSiteConnectionRequest input) {
177         return create(input);
178     }
179
180     /**
181      * Updates a VPN IPSEC SiteConnection
182      */
183     @Path("{connectionID}")
184     @PUT
185     @Produces({ MediaType.APPLICATION_JSON })
186     @Consumes({ MediaType.APPLICATION_JSON })
187     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
188             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
189             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
190     public Response updateVPNIPSECSiteConnection(@PathParam("connectionID") String connectionID,
191             final NeutronVPNIPSECSiteConnectionRequest input) {
192         return update(connectionID, input);
193     }
194
195     /**
196      * Deletes a VPN IPSEC SiteConnection
197      */
198
199     @Path("{connectionID}")
200     @DELETE
201     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
202             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
203             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
204     public Response deleteVPNIPSECSiteConnection(@PathParam("connectionID") String connectionID) {
205         return delete(connectionID);
206     }
207
208 }