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.PUT;
18 import javax.ws.rs.Path;
19 import javax.ws.rs.PathParam;
20 import javax.ws.rs.Produces;
21 import javax.ws.rs.QueryParam;
22 import javax.ws.rs.core.MediaType;
23 import javax.ws.rs.core.Response;
24 import org.codehaus.enunciate.jaxrs.ResponseCode;
25 import org.codehaus.enunciate.jaxrs.StatusCodes;
26 import org.codehaus.enunciate.jaxrs.TypeHint;
27 import org.opendaylight.neutron.spi.INeutronVpnIkePolicyCRUD;
28 import org.opendaylight.neutron.spi.NeutronVpnIkePolicy;
31 * Neutron Northbound REST APIs for VPN IKE Policy.
33 @Path("/vpn/ikepolicies")
34 public final class NeutronVpnIkePoliciesNorthbound
35 extends AbstractNeutronNorthbound<NeutronVpnIkePolicy, NeutronVpnIkePolicyRequest, INeutronVpnIkePolicyCRUD> {
37 private static final String RESOURCE_NAME = "VPNIKEPolicy";
40 protected String getResourceName() {
45 * Returns a list of all VPN IKE Policies.
48 @Produces({ MediaType.APPLICATION_JSON })
49 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
50 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
51 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
52 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
53 public Response listVpnIkePolicies(
55 @QueryParam("fields") List<String> fields,
57 @QueryParam("id") String queryID,
58 @QueryParam("name") String queryName,
59 @QueryParam("tenant_id") String queryTenantID,
60 @QueryParam("auth_algorithm") String queryAuthAlgorithm,
61 @QueryParam("encryption_algorithm") String queryEncryptionAlgorithm,
62 @QueryParam("phase1_negotiation_mode") String queryPhase1NegotiationMode,
63 @QueryParam("pfs") String queryPFS,
64 @QueryParam("ike_version") String queryIKEVersion
65 // pagination and sorting are TODO
67 INeutronVpnIkePolicyCRUD labelInterface = getNeutronCRUD();
68 List<NeutronVpnIkePolicy> allNeutronVpnIkePolicy = labelInterface.getAll();
69 List<NeutronVpnIkePolicy> ans = new ArrayList<>();
70 for (NeutronVpnIkePolicy policy : allNeutronVpnIkePolicy) {
71 if ((queryID == null || queryID.equals(policy.getID()))
72 && (queryName == null || queryName.equals(policy.getName()))
73 && (queryAuthAlgorithm == null || queryAuthAlgorithm.equals(policy.getAuthAlgorithm()))
74 && (queryEncryptionAlgorithm == null
75 || queryEncryptionAlgorithm.equals(policy.getEncryptionAlgorithm()))
76 && (queryPhase1NegotiationMode == null
77 || queryPhase1NegotiationMode.equals(policy.getPhase1NegotiationMode()))
78 && (queryPFS == null || queryPFS.equals(policy.getPerfectForwardSecrecy()))
79 && (queryIKEVersion == null || queryIKEVersion.equals(policy.getIkeVersion()))
80 && (queryTenantID == null || queryTenantID.equals(policy.getTenantID()))) {
81 if (fields.size() > 0) {
82 ans.add(policy.extractFields(fields));
88 //TODO: apply pagination to results
89 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronVpnIkePolicyRequest(ans)).build();
93 * Returns a specific VPN IKE Policy.
97 @Produces({ MediaType.APPLICATION_JSON })
98 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
99 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
100 @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
101 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
102 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
103 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
104 public Response showVpnIkePolicy(@PathParam("policyID") String policyUUID,
106 @QueryParam("fields") List<String> fields) {
107 return show(policyUUID, fields);
111 * Creates new VPN IKE Policy.
114 @Produces({ MediaType.APPLICATION_JSON })
115 @Consumes({ MediaType.APPLICATION_JSON })
116 @TypeHint(NeutronVpnIkePolicy.class)
117 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
118 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
119 public Response createVpnIkePolicy(final NeutronVpnIkePolicyRequest input) {
120 return create(input);
124 * Updates a VPN IKE Policy.
128 @Produces({ MediaType.APPLICATION_JSON })
129 @Consumes({ MediaType.APPLICATION_JSON })
130 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
131 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
132 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
133 public Response updateVpnIkePolicy(@PathParam("policyID") String policyUUID,
134 final NeutronVpnIkePolicyRequest input) {
135 return update(policyUUID, input);
139 * Deletes a VPN IKE Policy.
143 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
144 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
145 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
146 public Response deleteVpnIkePolicy(@PathParam("policyID") String policyUUID) {
147 return delete(policyUUID);