blob: 29291cd9a2e2518c6ed8f6485bbf46b997b879bc [file] [log] [blame]
Thomas Vachuska96d55b12015-05-11 08:52:03 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Thomas Vachuska96d55b12015-05-11 08:52:03 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.rest.resources;
17
Jonathan Hartb11c4d02016-03-23 09:05:44 -070018import com.fasterxml.jackson.databind.JsonNode;
Deepa Vaddireddy7fae1892016-06-15 17:13:15 +053019import com.fasterxml.jackson.databind.ObjectMapper;
Jonathan Hartb11c4d02016-03-23 09:05:44 -070020import com.fasterxml.jackson.databind.node.ObjectNode;
21import org.onosproject.net.config.Config;
22import org.onosproject.net.config.NetworkConfigService;
23import org.onosproject.net.config.SubjectFactory;
24import org.onosproject.rest.AbstractWebResource;
Thomas Vachuska96d55b12015-05-11 08:52:03 -070025
26import javax.ws.rs.Consumes;
27import javax.ws.rs.DELETE;
28import javax.ws.rs.GET;
29import javax.ws.rs.POST;
30import javax.ws.rs.Path;
31import javax.ws.rs.PathParam;
32import javax.ws.rs.Produces;
33import javax.ws.rs.core.MediaType;
34import javax.ws.rs.core.Response;
Jonathan Hartb11c4d02016-03-23 09:05:44 -070035import java.io.IOException;
36import java.io.InputStream;
Deepa Vaddireddy7fae1892016-06-15 17:13:15 +053037import java.util.ArrayList;
38import java.util.List;
Jonathan Hartb11c4d02016-03-23 09:05:44 -070039import java.util.Set;
Ray Milkey36992c82015-11-17 13:31:15 -080040
41import static org.onlab.util.Tools.emptyIsNotFound;
42import static org.onlab.util.Tools.nullIsNotFound;
Thomas Vachuska96d55b12015-05-11 08:52:03 -070043
44/**
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -070045 * Manage network configurations.
Thomas Vachuska96d55b12015-05-11 08:52:03 -070046 */
47@Path("network/configuration")
48public class NetworkConfigWebResource extends AbstractWebResource {
49
Deepa Vaddireddy7fae1892016-06-15 17:13:15 +053050 //FIX ME not found Multi status error code 207 in jaxrs Response Status.
51 private static final int MULTI_STATUS_RESPONE = 207;
52
Ray Milkey36992c82015-11-17 13:31:15 -080053 private String subjectClassNotFoundErrorString(String subjectClassKey) {
54 return "Config for '" + subjectClassKey + "' not found";
55 }
56
57 private String subjectNotFoundErrorString(String subjectClassKey,
58 String subjectKey) {
59 return "Config for '"
60 + subjectClassKey + "/" + subjectKey
61 + "' not found";
62 }
63
64 private String configKeyNotFoundErrorString(String subjectClassKey,
65 String subjectKey,
66 String configKey) {
67 return "Config for '"
68 + subjectClassKey + "/" + subjectKey + "/" + configKey
69 + "' not found";
70 }
71
Thomas Vachuska96d55b12015-05-11 08:52:03 -070072 /**
Jian Licc730a62016-05-10 16:36:16 -070073 * Gets entire network configuration base.
Ray Milkey36992c82015-11-17 13:31:15 -080074 *
Jian Licc730a62016-05-10 16:36:16 -070075 * @return 200 OK with network configuration JSON
Thomas Vachuska96d55b12015-05-11 08:52:03 -070076 */
77 @GET
78 @Produces(MediaType.APPLICATION_JSON)
79 @SuppressWarnings("unchecked")
80 public Response download() {
81 NetworkConfigService service = get(NetworkConfigService.class);
82 ObjectNode root = mapper().createObjectNode();
Thomas Vachuskaea5adc62015-10-07 11:52:30 -070083 service.getSubjectClasses().forEach(sc -> {
84 SubjectFactory subjectFactory = service.getSubjectFactory(sc);
85 produceJson(service, newObject(root, subjectFactory.subjectClassKey()),
86 subjectFactory, sc);
87 });
Thomas Vachuska96d55b12015-05-11 08:52:03 -070088 return ok(root).build();
89 }
90
91 /**
Jian Licc730a62016-05-10 16:36:16 -070092 * Gets all network configuration for a subject class.
Thomas Vachuska96d55b12015-05-11 08:52:03 -070093 *
Thomas Vachuskaea5adc62015-10-07 11:52:30 -070094 * @param subjectClassKey subject class key
Jian Licc730a62016-05-10 16:36:16 -070095 * @return 200 OK with network configuration JSON
Thomas Vachuska96d55b12015-05-11 08:52:03 -070096 */
97 @GET
Thomas Vachuskaea5adc62015-10-07 11:52:30 -070098 @Path("{subjectClassKey}")
Thomas Vachuska96d55b12015-05-11 08:52:03 -070099 @Produces(MediaType.APPLICATION_JSON)
100 @SuppressWarnings("unchecked")
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700101 public Response download(@PathParam("subjectClassKey") String subjectClassKey) {
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700102 NetworkConfigService service = get(NetworkConfigService.class);
103 ObjectNode root = mapper().createObjectNode();
Ray Milkey36992c82015-11-17 13:31:15 -0800104 SubjectFactory subjectFactory =
105 nullIsNotFound(service.getSubjectFactory(subjectClassKey),
106 subjectClassNotFoundErrorString(subjectClassKey));
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700107 produceJson(service, root, subjectFactory, subjectFactory.subjectClass());
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700108 return ok(root).build();
109 }
110
111 /**
Jian Licc730a62016-05-10 16:36:16 -0700112 * Gets all network configuration for a subjectKey.
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700113 *
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700114 * @param subjectClassKey subjectKey class key
115 * @param subjectKey subjectKey key
Jian Licc730a62016-05-10 16:36:16 -0700116 * @return 200 OK with network configuration JSON
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700117 */
118 @GET
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700119 @Path("{subjectClassKey}/{subjectKey}")
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700120 @Produces(MediaType.APPLICATION_JSON)
121 @SuppressWarnings("unchecked")
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700122 public Response download(@PathParam("subjectClassKey") String subjectClassKey,
123 @PathParam("subjectKey") String subjectKey) {
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700124 NetworkConfigService service = get(NetworkConfigService.class);
125 ObjectNode root = mapper().createObjectNode();
Ray Milkey36992c82015-11-17 13:31:15 -0800126 SubjectFactory subjectFactory =
127 nullIsNotFound(service.getSubjectFactory(subjectClassKey),
128 subjectClassNotFoundErrorString(subjectClassKey));
129 produceSubjectJson(service, root, subjectFactory.createSubject(subjectKey),
130 true,
131 subjectNotFoundErrorString(subjectClassKey, subjectKey));
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700132 return ok(root).build();
133 }
134
135 /**
Jian Licc730a62016-05-10 16:36:16 -0700136 * Gets specific network configuration for a subjectKey.
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700137 *
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700138 * @param subjectClassKey subjectKey class key
139 * @param subjectKey subjectKey key
140 * @param configKey configuration class key
Jian Licc730a62016-05-10 16:36:16 -0700141 * @return 200 OK with network configuration JSON
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700142 */
143 @GET
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700144 @Path("{subjectClassKey}/{subjectKey}/{configKey}")
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700145 @Produces(MediaType.APPLICATION_JSON)
146 @SuppressWarnings("unchecked")
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700147 public Response download(@PathParam("subjectClassKey") String subjectClassKey,
148 @PathParam("subjectKey") String subjectKey,
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700149 @PathParam("configKey") String configKey) {
150 NetworkConfigService service = get(NetworkConfigService.class);
Ray Milkey36992c82015-11-17 13:31:15 -0800151
152 Object subject =
153 nullIsNotFound(service.getSubjectFactory(subjectClassKey)
154 .createSubject(subjectKey),
155 subjectNotFoundErrorString(subjectClassKey, subjectKey));
156
157 Class configClass =
158 nullIsNotFound(service.getConfigClass(subjectClassKey, configKey),
159 configKeyNotFoundErrorString(subjectClassKey, subjectKey, configKey));
Jian Li7d069232016-05-13 17:08:29 -0700160 Config config = nullIsNotFound((Config) service.getConfig(subject, configClass),
Ray Milkey36992c82015-11-17 13:31:15 -0800161 configKeyNotFoundErrorString(subjectClassKey,
162 subjectKey,
163 configKey));
164 return ok(config.node()).build();
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700165 }
166
167 @SuppressWarnings("unchecked")
168 private void produceJson(NetworkConfigService service, ObjectNode node,
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700169 SubjectFactory subjectFactory, Class subjectClass) {
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700170 service.getSubjects(subjectClass).forEach(s ->
Ray Milkey36992c82015-11-17 13:31:15 -0800171 produceSubjectJson(service, newObject(node, subjectFactory.subjectKey(s)), s, false, ""));
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700172 }
173
174 private void produceSubjectJson(NetworkConfigService service, ObjectNode node,
Ray Milkey36992c82015-11-17 13:31:15 -0800175 Object subject,
176 boolean emptyIsError,
177 String emptyErrorMessage) {
178 Set<? extends Config<Object>> configs = service.getConfigs(subject);
179 if (emptyIsError) {
180 // caller wants an empty set to be a 404
181 configs = emptyIsNotFound(configs, emptyErrorMessage);
182 }
183 configs.forEach(c -> node.set(c.key(), c.node()));
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700184 }
185
186
187 /**
Jian Licc730a62016-05-10 16:36:16 -0700188 * Uploads bulk network configuration.
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700189 *
190 * @param request network configuration JSON rooted at the top node
Jian Licc730a62016-05-10 16:36:16 -0700191 * @return 200 OK
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700192 * @throws IOException if unable to parse the request
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700193 */
194 @POST
195 @Consumes(MediaType.APPLICATION_JSON)
196 @SuppressWarnings("unchecked")
197 public Response upload(InputStream request) throws IOException {
198 NetworkConfigService service = get(NetworkConfigService.class);
199 ObjectNode root = (ObjectNode) mapper().readTree(request);
Deepa Vaddireddy7fae1892016-06-15 17:13:15 +0530200 List<String> errorMsgs = new ArrayList<String>();
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700201 root.fieldNames()
Deepa Vaddireddy7fae1892016-06-15 17:13:15 +0530202 .forEachRemaining(sk ->
203 {
204 errorMsgs.addAll(consumeJson(service, (ObjectNode) root.path(sk),
205 service.getSubjectFactory(sk)));
206 });
Jon Hallcbd1b392017-01-18 20:15:44 -0800207 if (!errorMsgs.isEmpty()) {
Deepa Vaddireddy7fae1892016-06-15 17:13:15 +0530208 return Response.status(MULTI_STATUS_RESPONE).entity(produceErrorJson(errorMsgs)).build();
209 }
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700210 return Response.ok().build();
211 }
212
213 /**
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -0700214 * Upload multiple network configurations for a subject class.
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700215 *
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700216 * @param subjectClassKey subject class key
217 * @param request network configuration JSON rooted at the top node
Jian Licc730a62016-05-10 16:36:16 -0700218 * @return 200 OK
Thomas Vachuskad894b5d2015-07-30 11:59:07 -0700219 * @throws IOException if unable to parse the request
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700220 */
221 @POST
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700222 @Path("{subjectClassKey}")
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700223 @Consumes(MediaType.APPLICATION_JSON)
224 @SuppressWarnings("unchecked")
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700225 public Response upload(@PathParam("subjectClassKey") String subjectClassKey,
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700226 InputStream request) throws IOException {
227 NetworkConfigService service = get(NetworkConfigService.class);
228 ObjectNode root = (ObjectNode) mapper().readTree(request);
Deepa Vaddireddy7fae1892016-06-15 17:13:15 +0530229 List<String> errorMsgs = consumeJson(service, root, service.getSubjectFactory(subjectClassKey));
Jon Hallcbd1b392017-01-18 20:15:44 -0800230 if (!errorMsgs.isEmpty()) {
Deepa Vaddireddy7fae1892016-06-15 17:13:15 +0530231 return Response.status(MULTI_STATUS_RESPONE).entity(produceErrorJson(errorMsgs)).build();
232 }
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700233 return Response.ok().build();
234 }
235
236 /**
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700237 * Upload mutliple network configurations for a subjectKey.
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700238 *
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700239 * @param subjectClassKey subjectKey class key
240 * @param subjectKey subjectKey key
241 * @param request network configuration JSON rooted at the top node
Jian Licc730a62016-05-10 16:36:16 -0700242 * @return 200 OK
Thomas Vachuskad894b5d2015-07-30 11:59:07 -0700243 * @throws IOException if unable to parse the request
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700244 */
245 @POST
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700246 @Path("{subjectClassKey}/{subjectKey}")
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700247 @Consumes(MediaType.APPLICATION_JSON)
248 @SuppressWarnings("unchecked")
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700249 public Response upload(@PathParam("subjectClassKey") String subjectClassKey,
250 @PathParam("subjectKey") String subjectKey,
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700251 InputStream request) throws IOException {
252 NetworkConfigService service = get(NetworkConfigService.class);
253 ObjectNode root = (ObjectNode) mapper().readTree(request);
Deepa Vaddireddy7fae1892016-06-15 17:13:15 +0530254 List<String> errorMsgs = consumeSubjectJson(service, root,
255 service.getSubjectFactory(subjectClassKey).createSubject(subjectKey),
256 subjectClassKey);
Jon Hallcbd1b392017-01-18 20:15:44 -0800257 if (!errorMsgs.isEmpty()) {
Deepa Vaddireddy7fae1892016-06-15 17:13:15 +0530258 return Response.status(MULTI_STATUS_RESPONE).entity(produceErrorJson(errorMsgs)).build();
259 }
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700260 return Response.ok().build();
261 }
262
263 /**
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700264 * Upload specific network configuration for a subjectKey.
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700265 *
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700266 * @param subjectClassKey subjectKey class key
267 * @param subjectKey subjectKey key
268 * @param configKey configuration class key
269 * @param request network configuration JSON rooted at the top node
Jian Licc730a62016-05-10 16:36:16 -0700270 * @return 200 OK
Thomas Vachuskad894b5d2015-07-30 11:59:07 -0700271 * @throws IOException if unable to parse the request
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700272 */
273 @POST
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700274 @Path("{subjectClassKey}/{subjectKey}/{configKey}")
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700275 @Consumes(MediaType.APPLICATION_JSON)
276 @SuppressWarnings("unchecked")
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700277 public Response upload(@PathParam("subjectClassKey") String subjectClassKey,
278 @PathParam("subjectKey") String subjectKey,
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700279 @PathParam("configKey") String configKey,
280 InputStream request) throws IOException {
281 NetworkConfigService service = get(NetworkConfigService.class);
Jonathan Hartb11c4d02016-03-23 09:05:44 -0700282 JsonNode root = mapper().readTree(request);
Thomas Vachuska6f350ed2016-01-08 09:53:03 -0800283 service.applyConfig(subjectClassKey,
284 service.getSubjectFactory(subjectClassKey).createSubject(subjectKey),
285 configKey, root);
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700286 return Response.ok().build();
287 }
288
Deepa Vaddireddy7fae1892016-06-15 17:13:15 +0530289 private List<String> consumeJson(NetworkConfigService service, ObjectNode classNode,
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700290 SubjectFactory subjectFactory) {
Deepa Vaddireddy7fae1892016-06-15 17:13:15 +0530291 List<String> errorMsgs = new ArrayList<String>();
292 classNode.fieldNames().forEachRemaining(s -> {
293 List<String> error = consumeSubjectJson(service, (ObjectNode) classNode.path(s),
294 subjectFactory.createSubject(s),
295 subjectFactory.subjectClassKey());
296 errorMsgs.addAll(error);
297 });
298 return errorMsgs;
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700299 }
300
Deepa Vaddireddy7fae1892016-06-15 17:13:15 +0530301 private List<String> consumeSubjectJson(NetworkConfigService service,
Jonathan Hart111b42b2015-07-14 13:28:05 -0700302 ObjectNode subjectNode, Object subject,
Thomas Vachuska6f350ed2016-01-08 09:53:03 -0800303 String subjectClassKey) {
Deepa Vaddireddy7fae1892016-06-15 17:13:15 +0530304 List<String> errorMsgs = new ArrayList<String>();
305 subjectNode.fieldNames().forEachRemaining(configKey -> {
306 try {
307 service.applyConfig(subjectClassKey, subject, configKey, subjectNode.path(configKey));
308 } catch (IllegalArgumentException e) {
309 errorMsgs.add("Error parsing config " + subjectClassKey + "/" + subject + "/" + configKey);
310 }
311 });
312 return errorMsgs;
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700313 }
314
Deepa Vaddireddy7fae1892016-06-15 17:13:15 +0530315 private ObjectNode produceErrorJson(List<String> errorMsgs) {
316 ObjectMapper mapper = new ObjectMapper();
317 ObjectNode result = mapper.createObjectNode().put("code", 207).putPOJO("message", errorMsgs);
318 return result;
319 }
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700320
Thomas Vachuska6f350ed2016-01-08 09:53:03 -0800321 // FIXME: Refactor to allow queued configs to be removed
322
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700323 /**
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -0700324 * Clear entire network configuration base.
325 *
Jian Lic2a542b2016-05-10 11:48:19 -0700326 * @return 204 NO CONTENT
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -0700327 */
328 @DELETE
329 @SuppressWarnings("unchecked")
330 public Response delete() {
331 NetworkConfigService service = get(NetworkConfigService.class);
Deepa Vaddireddy0c49b602016-06-02 12:19:07 +0530332 service.removeConfig();
Ray Milkey984e2d82016-06-16 14:33:10 -0700333 return Response.noContent().build();
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -0700334 }
335
336 /**
337 * Clear all network configurations for a subject class.
338 *
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700339 * @param subjectClassKey subject class key
Ray Milkey984e2d82016-06-16 14:33:10 -0700340 * @return 204 NO CONTENT
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -0700341 */
342 @DELETE
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700343 @Path("{subjectClassKey}")
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -0700344 @SuppressWarnings("unchecked")
Ray Milkey984e2d82016-06-16 14:33:10 -0700345 public Response delete(@PathParam("subjectClassKey") String subjectClassKey) {
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -0700346 NetworkConfigService service = get(NetworkConfigService.class);
Ray Milkeyb9fe25d2015-11-18 15:54:44 -0800347 service.getSubjects(service.getSubjectFactory(subjectClassKey).subjectClass())
Deepa Vaddireddy0c49b602016-06-02 12:19:07 +0530348 .forEach(subject -> service.removeConfig(subject));
Ray Milkey984e2d82016-06-16 14:33:10 -0700349 return Response.noContent().build();
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -0700350 }
351
352 /**
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700353 * Clear all network configurations for a subjectKey.
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700354 *
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700355 * @param subjectClassKey subjectKey class key
356 * @param subjectKey subjectKey key
Ray Milkey984e2d82016-06-16 14:33:10 -0700357 * @return 204 NO CONTENT
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700358 */
359 @DELETE
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700360 @Path("{subjectClassKey}/{subjectKey}")
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700361 @SuppressWarnings("unchecked")
Ray Milkey984e2d82016-06-16 14:33:10 -0700362 public Response delete(@PathParam("subjectClassKey") String subjectClassKey,
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700363 @PathParam("subjectKey") String subjectKey) {
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700364 NetworkConfigService service = get(NetworkConfigService.class);
Jonathan Hart61924992016-09-01 09:36:27 -0700365 service.removeConfig(service.getSubjectFactory(subjectClassKey).createSubject(subjectKey));
Ray Milkey984e2d82016-06-16 14:33:10 -0700366 return Response.noContent().build();
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700367 }
368
369 /**
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700370 * Clear specific network configuration for a subjectKey.
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700371 *
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700372 * @param subjectClassKey subjectKey class key
373 * @param subjectKey subjectKey key
374 * @param configKey configuration class key
Ray Milkey984e2d82016-06-16 14:33:10 -0700375 * @return 204 NO CONTENT
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700376 */
377 @DELETE
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700378 @Path("{subjectClassKey}/{subjectKey}/{configKey}")
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700379 @SuppressWarnings("unchecked")
Ray Milkey984e2d82016-06-16 14:33:10 -0700380 public Response delete(@PathParam("subjectClassKey") String subjectClassKey,
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700381 @PathParam("subjectKey") String subjectKey,
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700382 @PathParam("configKey") String configKey) {
383 NetworkConfigService service = get(NetworkConfigService.class);
Deepa Vaddireddy0c49b602016-06-02 12:19:07 +0530384 service.removeConfig(subjectClassKey,
385 service.getSubjectFactory(subjectClassKey).createSubject(subjectKey),
386 configKey);
Ray Milkey984e2d82016-06-16 14:33:10 -0700387 return Response.noContent().build();
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700388 }
389
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700390}