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 com.webcohesion.enunciate.metadata.rs.TypeHint;
13 import java.net.HttpURLConnection;
14 import java.util.ArrayList;
15 import java.util.List;
16 import javax.inject.Inject;
17 import javax.inject.Singleton;
18 import javax.ws.rs.Consumes;
19 import javax.ws.rs.DELETE;
20 import javax.ws.rs.GET;
21 import javax.ws.rs.POST;
22 import javax.ws.rs.PUT;
23 import javax.ws.rs.Path;
24 import javax.ws.rs.PathParam;
25 import javax.ws.rs.Produces;
26 import javax.ws.rs.QueryParam;
27 import javax.ws.rs.core.MediaType;
28 import javax.ws.rs.core.Response;
29 import org.apache.aries.blueprint.annotation.service.Reference;
30 import org.opendaylight.neutron.spi.INeutronVpnIkePolicyCRUD;
31 import org.opendaylight.neutron.spi.NeutronVpnIkePolicy;
34 * Neutron Northbound REST APIs for VPN IKE Policy.
37 @Path("/vpn/ikepolicies")
38 public final class NeutronVpnIkePoliciesNorthbound
39 extends AbstractNeutronNorthbound<NeutronVpnIkePolicy, NeutronVpnIkePolicyRequest, INeutronVpnIkePolicyCRUD> {
41 private static final String RESOURCE_NAME = "VPNIKEPolicy";
44 public NeutronVpnIkePoliciesNorthbound(@Reference INeutronVpnIkePolicyCRUD neutronCRUD) {
49 protected String getResourceName() {
54 * Returns a list of all VPN IKE Policies.
57 @Produces({ MediaType.APPLICATION_JSON })
58 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
59 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
60 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
61 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
62 public Response listVpnIkePolicies(
64 @QueryParam("fields") List<String> fields,
66 @QueryParam("id") String queryID,
67 @QueryParam("name") String queryName,
68 @QueryParam("tenant_id") String queryTenantID,
69 @QueryParam("auth_algorithm") String queryAuthAlgorithm,
70 @QueryParam("encryption_algorithm") String queryEncryptionAlgorithm,
71 @QueryParam("phase1_negotiation_mode") String queryPhase1NegotiationMode,
72 @QueryParam("pfs") String queryPFS,
73 @QueryParam("ike_version") String queryIKEVersion
74 // pagination and sorting are TODO
76 INeutronVpnIkePolicyCRUD labelInterface = getNeutronCRUD();
77 List<NeutronVpnIkePolicy> allNeutronVpnIkePolicy = labelInterface.getAll();
78 List<NeutronVpnIkePolicy> ans = new ArrayList<>();
79 for (NeutronVpnIkePolicy policy : allNeutronVpnIkePolicy) {
80 if ((queryID == null || queryID.equals(policy.getID()))
81 && (queryName == null || queryName.equals(policy.getName()))
82 && (queryAuthAlgorithm == null || queryAuthAlgorithm.equals(policy.getAuthAlgorithm()))
83 && (queryEncryptionAlgorithm == null
84 || queryEncryptionAlgorithm.equals(policy.getEncryptionAlgorithm()))
85 && (queryPhase1NegotiationMode == null
86 || queryPhase1NegotiationMode.equals(policy.getPhase1NegotiationMode()))
87 && (queryPFS == null || queryPFS.equals(policy.getPerfectForwardSecrecy()))
88 && (queryIKEVersion == null || queryIKEVersion.equals(policy.getIkeVersion()))
89 && (queryTenantID == null || queryTenantID.equals(policy.getTenantID()))) {
90 if (fields.size() > 0) {
91 ans.add(policy.extractFields(fields));
97 //TODO: apply pagination to results
98 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronVpnIkePolicyRequest(ans)).build();
102 * Returns a specific VPN IKE Policy.
106 @Produces({ MediaType.APPLICATION_JSON })
107 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
108 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
109 @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
110 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
111 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
112 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
113 public Response showVpnIkePolicy(@PathParam("policyID") String policyUUID,
115 @QueryParam("fields") List<String> fields) {
116 return show(policyUUID, fields);
120 * Creates new VPN IKE Policy.
123 @Produces({ MediaType.APPLICATION_JSON })
124 @Consumes({ MediaType.APPLICATION_JSON })
125 @TypeHint(NeutronVpnIkePolicy.class)
126 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
127 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
128 public Response createVpnIkePolicy(final NeutronVpnIkePolicyRequest input) {
129 return create(input);
133 * Updates a VPN IKE Policy.
137 @Produces({ MediaType.APPLICATION_JSON })
138 @Consumes({ MediaType.APPLICATION_JSON })
139 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
140 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
141 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
142 public Response updateVpnIkePolicy(@PathParam("policyID") String policyUUID,
143 final NeutronVpnIkePolicyRequest input) {
144 return update(policyUUID, input);
148 * Deletes a VPN IKE Policy.
152 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
153 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
154 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
155 public Response deleteVpnIkePolicy(@PathParam("policyID") String policyUUID) {
156 return delete(policyUUID);