blob: 9d2689139c34a3e349ac7cd29a26cbd50ac6a246 [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()
Ray Milkey88cc3432017-03-30 17:19:08 -0700202 .forEachRemaining(sk -> {
Deepa Vaddireddy7fae1892016-06-15 17:13:15 +0530203 errorMsgs.addAll(consumeJson(service, (ObjectNode) root.path(sk),
204 service.getSubjectFactory(sk)));
205 });
Jon Hallcbd1b392017-01-18 20:15:44 -0800206 if (!errorMsgs.isEmpty()) {
Deepa Vaddireddy7fae1892016-06-15 17:13:15 +0530207 return Response.status(MULTI_STATUS_RESPONE).entity(produceErrorJson(errorMsgs)).build();
208 }
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700209 return Response.ok().build();
210 }
211
212 /**
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -0700213 * Upload multiple network configurations for a subject class.
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700214 *
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700215 * @param subjectClassKey subject class key
216 * @param request network configuration JSON rooted at the top node
Jian Licc730a62016-05-10 16:36:16 -0700217 * @return 200 OK
Thomas Vachuskad894b5d2015-07-30 11:59:07 -0700218 * @throws IOException if unable to parse the request
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700219 */
220 @POST
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700221 @Path("{subjectClassKey}")
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700222 @Consumes(MediaType.APPLICATION_JSON)
223 @SuppressWarnings("unchecked")
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700224 public Response upload(@PathParam("subjectClassKey") String subjectClassKey,
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700225 InputStream request) throws IOException {
226 NetworkConfigService service = get(NetworkConfigService.class);
227 ObjectNode root = (ObjectNode) mapper().readTree(request);
Deepa Vaddireddy7fae1892016-06-15 17:13:15 +0530228 List<String> errorMsgs = consumeJson(service, root, service.getSubjectFactory(subjectClassKey));
Jon Hallcbd1b392017-01-18 20:15:44 -0800229 if (!errorMsgs.isEmpty()) {
Deepa Vaddireddy7fae1892016-06-15 17:13:15 +0530230 return Response.status(MULTI_STATUS_RESPONE).entity(produceErrorJson(errorMsgs)).build();
231 }
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700232 return Response.ok().build();
233 }
234
235 /**
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700236 * Upload mutliple network configurations for a subjectKey.
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700237 *
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700238 * @param subjectClassKey subjectKey class key
239 * @param subjectKey subjectKey key
240 * @param request network configuration JSON rooted at the top node
Jian Licc730a62016-05-10 16:36:16 -0700241 * @return 200 OK
Thomas Vachuskad894b5d2015-07-30 11:59:07 -0700242 * @throws IOException if unable to parse the request
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700243 */
244 @POST
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700245 @Path("{subjectClassKey}/{subjectKey}")
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700246 @Consumes(MediaType.APPLICATION_JSON)
247 @SuppressWarnings("unchecked")
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700248 public Response upload(@PathParam("subjectClassKey") String subjectClassKey,
249 @PathParam("subjectKey") String subjectKey,
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700250 InputStream request) throws IOException {
251 NetworkConfigService service = get(NetworkConfigService.class);
252 ObjectNode root = (ObjectNode) mapper().readTree(request);
Deepa Vaddireddy7fae1892016-06-15 17:13:15 +0530253 List<String> errorMsgs = consumeSubjectJson(service, root,
254 service.getSubjectFactory(subjectClassKey).createSubject(subjectKey),
255 subjectClassKey);
Jon Hallcbd1b392017-01-18 20:15:44 -0800256 if (!errorMsgs.isEmpty()) {
Deepa Vaddireddy7fae1892016-06-15 17:13:15 +0530257 return Response.status(MULTI_STATUS_RESPONE).entity(produceErrorJson(errorMsgs)).build();
258 }
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700259 return Response.ok().build();
260 }
261
262 /**
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700263 * Upload specific network configuration for a subjectKey.
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700264 *
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700265 * @param subjectClassKey subjectKey class key
266 * @param subjectKey subjectKey key
267 * @param configKey configuration class key
268 * @param request network configuration JSON rooted at the top node
Jian Licc730a62016-05-10 16:36:16 -0700269 * @return 200 OK
Thomas Vachuskad894b5d2015-07-30 11:59:07 -0700270 * @throws IOException if unable to parse the request
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700271 */
272 @POST
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700273 @Path("{subjectClassKey}/{subjectKey}/{configKey}")
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700274 @Consumes(MediaType.APPLICATION_JSON)
275 @SuppressWarnings("unchecked")
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700276 public Response upload(@PathParam("subjectClassKey") String subjectClassKey,
277 @PathParam("subjectKey") String subjectKey,
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700278 @PathParam("configKey") String configKey,
279 InputStream request) throws IOException {
280 NetworkConfigService service = get(NetworkConfigService.class);
Jonathan Hartb11c4d02016-03-23 09:05:44 -0700281 JsonNode root = mapper().readTree(request);
Thomas Vachuska6f350ed2016-01-08 09:53:03 -0800282 service.applyConfig(subjectClassKey,
283 service.getSubjectFactory(subjectClassKey).createSubject(subjectKey),
284 configKey, root);
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700285 return Response.ok().build();
286 }
287
Deepa Vaddireddy7fae1892016-06-15 17:13:15 +0530288 private List<String> consumeJson(NetworkConfigService service, ObjectNode classNode,
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700289 SubjectFactory subjectFactory) {
Deepa Vaddireddy7fae1892016-06-15 17:13:15 +0530290 List<String> errorMsgs = new ArrayList<String>();
291 classNode.fieldNames().forEachRemaining(s -> {
292 List<String> error = consumeSubjectJson(service, (ObjectNode) classNode.path(s),
293 subjectFactory.createSubject(s),
294 subjectFactory.subjectClassKey());
295 errorMsgs.addAll(error);
296 });
297 return errorMsgs;
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700298 }
299
Deepa Vaddireddy7fae1892016-06-15 17:13:15 +0530300 private List<String> consumeSubjectJson(NetworkConfigService service,
Jonathan Hart111b42b2015-07-14 13:28:05 -0700301 ObjectNode subjectNode, Object subject,
Thomas Vachuska6f350ed2016-01-08 09:53:03 -0800302 String subjectClassKey) {
Deepa Vaddireddy7fae1892016-06-15 17:13:15 +0530303 List<String> errorMsgs = new ArrayList<String>();
304 subjectNode.fieldNames().forEachRemaining(configKey -> {
305 try {
306 service.applyConfig(subjectClassKey, subject, configKey, subjectNode.path(configKey));
307 } catch (IllegalArgumentException e) {
308 errorMsgs.add("Error parsing config " + subjectClassKey + "/" + subject + "/" + configKey);
309 }
310 });
311 return errorMsgs;
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700312 }
313
Deepa Vaddireddy7fae1892016-06-15 17:13:15 +0530314 private ObjectNode produceErrorJson(List<String> errorMsgs) {
315 ObjectMapper mapper = new ObjectMapper();
316 ObjectNode result = mapper.createObjectNode().put("code", 207).putPOJO("message", errorMsgs);
317 return result;
318 }
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700319
Thomas Vachuska6f350ed2016-01-08 09:53:03 -0800320 // FIXME: Refactor to allow queued configs to be removed
321
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700322 /**
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -0700323 * Clear entire network configuration base.
324 *
Jian Lic2a542b2016-05-10 11:48:19 -0700325 * @return 204 NO CONTENT
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -0700326 */
327 @DELETE
328 @SuppressWarnings("unchecked")
329 public Response delete() {
330 NetworkConfigService service = get(NetworkConfigService.class);
Deepa Vaddireddy0c49b602016-06-02 12:19:07 +0530331 service.removeConfig();
Ray Milkey984e2d82016-06-16 14:33:10 -0700332 return Response.noContent().build();
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -0700333 }
334
335 /**
336 * Clear all network configurations for a subject class.
337 *
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700338 * @param subjectClassKey subject class key
Ray Milkey984e2d82016-06-16 14:33:10 -0700339 * @return 204 NO CONTENT
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -0700340 */
341 @DELETE
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700342 @Path("{subjectClassKey}")
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -0700343 @SuppressWarnings("unchecked")
Ray Milkey984e2d82016-06-16 14:33:10 -0700344 public Response delete(@PathParam("subjectClassKey") String subjectClassKey) {
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -0700345 NetworkConfigService service = get(NetworkConfigService.class);
Ray Milkeyb9fe25d2015-11-18 15:54:44 -0800346 service.getSubjects(service.getSubjectFactory(subjectClassKey).subjectClass())
Deepa Vaddireddy0c49b602016-06-02 12:19:07 +0530347 .forEach(subject -> service.removeConfig(subject));
Ray Milkey984e2d82016-06-16 14:33:10 -0700348 return Response.noContent().build();
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -0700349 }
350
351 /**
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700352 * Clear all network configurations for a subjectKey.
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700353 *
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700354 * @param subjectClassKey subjectKey class key
355 * @param subjectKey subjectKey key
Ray Milkey984e2d82016-06-16 14:33:10 -0700356 * @return 204 NO CONTENT
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700357 */
358 @DELETE
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700359 @Path("{subjectClassKey}/{subjectKey}")
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700360 @SuppressWarnings("unchecked")
Ray Milkey984e2d82016-06-16 14:33:10 -0700361 public Response delete(@PathParam("subjectClassKey") String subjectClassKey,
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700362 @PathParam("subjectKey") String subjectKey) {
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700363 NetworkConfigService service = get(NetworkConfigService.class);
Jonathan Hart61924992016-09-01 09:36:27 -0700364 service.removeConfig(service.getSubjectFactory(subjectClassKey).createSubject(subjectKey));
Ray Milkey984e2d82016-06-16 14:33:10 -0700365 return Response.noContent().build();
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700366 }
367
368 /**
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700369 * Clear specific network configuration for a subjectKey.
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700370 *
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700371 * @param subjectClassKey subjectKey class key
372 * @param subjectKey subjectKey key
373 * @param configKey configuration class key
Ray Milkey984e2d82016-06-16 14:33:10 -0700374 * @return 204 NO CONTENT
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700375 */
376 @DELETE
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700377 @Path("{subjectClassKey}/{subjectKey}/{configKey}")
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700378 @SuppressWarnings("unchecked")
Ray Milkey984e2d82016-06-16 14:33:10 -0700379 public Response delete(@PathParam("subjectClassKey") String subjectClassKey,
Thomas Vachuskaea5adc62015-10-07 11:52:30 -0700380 @PathParam("subjectKey") String subjectKey,
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700381 @PathParam("configKey") String configKey) {
382 NetworkConfigService service = get(NetworkConfigService.class);
Deepa Vaddireddy0c49b602016-06-02 12:19:07 +0530383 service.removeConfig(subjectClassKey,
384 service.getSubjectFactory(subjectClassKey).createSubject(subjectKey),
385 configKey);
Ray Milkey984e2d82016-06-16 14:33:10 -0700386 return Response.noContent().build();
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700387 }
388
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700389}