Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 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 | */ |
| 16 | package org.onosproject.rest.resources; |
| 17 | |
| 18 | import com.fasterxml.jackson.databind.node.ObjectNode; |
Ray Milkey | a412236 | 2015-08-18 15:19:08 -0700 | [diff] [blame] | 19 | import org.onosproject.net.config.NetworkConfigService; |
| 20 | import org.onosproject.net.config.SubjectFactory; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 21 | import org.onosproject.rest.AbstractWebResource; |
| 22 | |
| 23 | import javax.ws.rs.Consumes; |
| 24 | import javax.ws.rs.DELETE; |
| 25 | import javax.ws.rs.GET; |
| 26 | import javax.ws.rs.POST; |
| 27 | import javax.ws.rs.Path; |
| 28 | import javax.ws.rs.PathParam; |
| 29 | import javax.ws.rs.Produces; |
| 30 | import javax.ws.rs.core.MediaType; |
| 31 | import javax.ws.rs.core.Response; |
| 32 | import java.io.IOException; |
| 33 | import java.io.InputStream; |
| 34 | |
| 35 | /** |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 36 | * Manage network configurations. |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 37 | */ |
| 38 | @Path("network/configuration") |
| 39 | public class NetworkConfigWebResource extends AbstractWebResource { |
| 40 | |
| 41 | /** |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 42 | * Get entire network configuration base. |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 43 | * |
| 44 | * @return network configuration JSON |
| 45 | */ |
| 46 | @GET |
| 47 | @Produces(MediaType.APPLICATION_JSON) |
| 48 | @SuppressWarnings("unchecked") |
| 49 | public Response download() { |
| 50 | NetworkConfigService service = get(NetworkConfigService.class); |
| 51 | ObjectNode root = mapper().createObjectNode(); |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 52 | service.getSubjectClasses().forEach(sc -> { |
| 53 | SubjectFactory subjectFactory = service.getSubjectFactory(sc); |
| 54 | produceJson(service, newObject(root, subjectFactory.subjectClassKey()), |
| 55 | subjectFactory, sc); |
| 56 | }); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 57 | return ok(root).build(); |
| 58 | } |
| 59 | |
| 60 | /** |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 61 | * Get all network configuration for a subject class. |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 62 | * |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 63 | * @param subjectClassKey subject class key |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 64 | * @return network configuration JSON |
| 65 | */ |
| 66 | @GET |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 67 | @Path("{subjectClassKey}") |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 68 | @Produces(MediaType.APPLICATION_JSON) |
| 69 | @SuppressWarnings("unchecked") |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 70 | public Response download(@PathParam("subjectClassKey") String subjectClassKey) { |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 71 | NetworkConfigService service = get(NetworkConfigService.class); |
| 72 | ObjectNode root = mapper().createObjectNode(); |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 73 | SubjectFactory subjectFactory = service.getSubjectFactory(subjectClassKey); |
| 74 | produceJson(service, root, subjectFactory, subjectFactory.subjectClass()); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 75 | return ok(root).build(); |
| 76 | } |
| 77 | |
| 78 | /** |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 79 | * Get all network configuration for a subjectKey. |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 80 | * |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 81 | * @param subjectClassKey subjectKey class key |
| 82 | * @param subjectKey subjectKey key |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 83 | * @return network configuration JSON |
| 84 | */ |
| 85 | @GET |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 86 | @Path("{subjectClassKey}/{subjectKey}") |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 87 | @Produces(MediaType.APPLICATION_JSON) |
| 88 | @SuppressWarnings("unchecked") |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 89 | public Response download(@PathParam("subjectClassKey") String subjectClassKey, |
| 90 | @PathParam("subjectKey") String subjectKey) { |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 91 | NetworkConfigService service = get(NetworkConfigService.class); |
| 92 | ObjectNode root = mapper().createObjectNode(); |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 93 | SubjectFactory subjectFactory = service.getSubjectFactory(subjectClassKey); |
| 94 | produceSubjectJson(service, root, subjectFactory.createSubject(subjectKey)); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 95 | return ok(root).build(); |
| 96 | } |
| 97 | |
| 98 | /** |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 99 | * Get specific network configuration for a subjectKey. |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 100 | * |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 101 | * @param subjectClassKey subjectKey class key |
| 102 | * @param subjectKey subjectKey key |
| 103 | * @param configKey configuration class key |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 104 | * @return network configuration JSON |
| 105 | */ |
| 106 | @GET |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 107 | @Path("{subjectClassKey}/{subjectKey}/{configKey}") |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 108 | @Produces(MediaType.APPLICATION_JSON) |
| 109 | @SuppressWarnings("unchecked") |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 110 | public Response download(@PathParam("subjectClassKey") String subjectClassKey, |
| 111 | @PathParam("subjectKey") String subjectKey, |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 112 | @PathParam("configKey") String configKey) { |
| 113 | NetworkConfigService service = get(NetworkConfigService.class); |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 114 | return ok(service.getConfig(service.getSubjectFactory(subjectClassKey).createSubject(subjectKey), |
| 115 | service.getConfigClass(subjectClassKey, configKey)).node()).build(); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | @SuppressWarnings("unchecked") |
| 119 | private void produceJson(NetworkConfigService service, ObjectNode node, |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 120 | SubjectFactory subjectFactory, Class subjectClass) { |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 121 | service.getSubjects(subjectClass).forEach(s -> |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 122 | produceSubjectJson(service, newObject(node, subjectFactory.subjectKey(s)), s)); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | private void produceSubjectJson(NetworkConfigService service, ObjectNode node, |
| 126 | Object subject) { |
| 127 | service.getConfigs(subject).forEach(c -> node.set(c.key(), c.node())); |
| 128 | } |
| 129 | |
| 130 | |
| 131 | /** |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 132 | * Upload bulk network configuration. |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 133 | * |
| 134 | * @param request network configuration JSON rooted at the top node |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 135 | * @return empty response |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 136 | * @throws IOException if unable to parse the request |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 137 | */ |
| 138 | @POST |
| 139 | @Consumes(MediaType.APPLICATION_JSON) |
| 140 | @SuppressWarnings("unchecked") |
| 141 | public Response upload(InputStream request) throws IOException { |
| 142 | NetworkConfigService service = get(NetworkConfigService.class); |
| 143 | ObjectNode root = (ObjectNode) mapper().readTree(request); |
| 144 | root.fieldNames() |
| 145 | .forEachRemaining(sk -> consumeJson(service, (ObjectNode) root.path(sk), |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 146 | service.getSubjectFactory(sk))); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 147 | return Response.ok().build(); |
| 148 | } |
| 149 | |
| 150 | /** |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 151 | * Upload multiple network configurations for a subject class. |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 152 | * |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 153 | * @param subjectClassKey subject class key |
| 154 | * @param request network configuration JSON rooted at the top node |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 155 | * @return empty response |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 156 | * @throws IOException if unable to parse the request |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 157 | */ |
| 158 | @POST |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 159 | @Path("{subjectClassKey}") |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 160 | @Consumes(MediaType.APPLICATION_JSON) |
| 161 | @SuppressWarnings("unchecked") |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 162 | public Response upload(@PathParam("subjectClassKey") String subjectClassKey, |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 163 | InputStream request) throws IOException { |
| 164 | NetworkConfigService service = get(NetworkConfigService.class); |
| 165 | ObjectNode root = (ObjectNode) mapper().readTree(request); |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 166 | consumeJson(service, root, service.getSubjectFactory(subjectClassKey)); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 167 | return Response.ok().build(); |
| 168 | } |
| 169 | |
| 170 | /** |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 171 | * Upload mutliple network configurations for a subjectKey. |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 172 | * |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 173 | * @param subjectClassKey subjectKey class key |
| 174 | * @param subjectKey subjectKey key |
| 175 | * @param request network configuration JSON rooted at the top node |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 176 | * @return empty response |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 177 | * @throws IOException if unable to parse the request |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 178 | */ |
| 179 | @POST |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 180 | @Path("{subjectClassKey}/{subjectKey}") |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 181 | @Consumes(MediaType.APPLICATION_JSON) |
| 182 | @SuppressWarnings("unchecked") |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 183 | public Response upload(@PathParam("subjectClassKey") String subjectClassKey, |
| 184 | @PathParam("subjectKey") String subjectKey, |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 185 | InputStream request) throws IOException { |
| 186 | NetworkConfigService service = get(NetworkConfigService.class); |
| 187 | ObjectNode root = (ObjectNode) mapper().readTree(request); |
| 188 | consumeSubjectJson(service, root, |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 189 | service.getSubjectFactory(subjectClassKey).createSubject(subjectKey), |
| 190 | subjectClassKey); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 191 | return Response.ok().build(); |
| 192 | } |
| 193 | |
| 194 | /** |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 195 | * Upload specific network configuration for a subjectKey. |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 196 | * |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 197 | * @param subjectClassKey subjectKey class key |
| 198 | * @param subjectKey subjectKey key |
| 199 | * @param configKey configuration class key |
| 200 | * @param request network configuration JSON rooted at the top node |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 201 | * @return empty response |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 202 | * @throws IOException if unable to parse the request |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 203 | */ |
| 204 | @POST |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 205 | @Path("{subjectClassKey}/{subjectKey}/{configKey}") |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 206 | @Consumes(MediaType.APPLICATION_JSON) |
| 207 | @SuppressWarnings("unchecked") |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 208 | public Response upload(@PathParam("subjectClassKey") String subjectClassKey, |
| 209 | @PathParam("subjectKey") String subjectKey, |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 210 | @PathParam("configKey") String configKey, |
| 211 | InputStream request) throws IOException { |
| 212 | NetworkConfigService service = get(NetworkConfigService.class); |
| 213 | ObjectNode root = (ObjectNode) mapper().readTree(request); |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 214 | service.applyConfig(service.getSubjectFactory(subjectClassKey).createSubject(subjectKey), |
| 215 | service.getConfigClass(subjectClassKey, configKey), root); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 216 | return Response.ok().build(); |
| 217 | } |
| 218 | |
| 219 | private void consumeJson(NetworkConfigService service, ObjectNode classNode, |
| 220 | SubjectFactory subjectFactory) { |
| 221 | classNode.fieldNames().forEachRemaining(s -> |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 222 | consumeSubjectJson(service, (ObjectNode) classNode.path(s), |
| 223 | subjectFactory.createSubject(s), |
| 224 | subjectFactory.subjectClassKey())); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | private void consumeSubjectJson(NetworkConfigService service, |
Jonathan Hart | 111b42b | 2015-07-14 13:28:05 -0700 | [diff] [blame] | 228 | ObjectNode subjectNode, Object subject, |
| 229 | String subjectKey) { |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 230 | subjectNode.fieldNames().forEachRemaining(c -> |
Jonathan Hart | 111b42b | 2015-07-14 13:28:05 -0700 | [diff] [blame] | 231 | service.applyConfig(subject, service.getConfigClass(subjectKey, c), |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 232 | subjectNode.path(c))); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | |
| 236 | /** |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 237 | * Clear entire network configuration base. |
| 238 | * |
| 239 | * @return empty response |
| 240 | */ |
| 241 | @DELETE |
| 242 | @SuppressWarnings("unchecked") |
| 243 | public Response delete() { |
| 244 | NetworkConfigService service = get(NetworkConfigService.class); |
| 245 | service.getSubjectClasses() |
| 246 | .forEach(subjectClass -> service.getSubjects(subjectClass) |
| 247 | .forEach(subject -> service.getConfigs(subject) |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 248 | .forEach(config -> service.removeConfig(subject, config.getClass())))); |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 249 | return Response.ok().build(); |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * Clear all network configurations for a subject class. |
| 254 | * |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 255 | * @param subjectClassKey subject class key |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 256 | * @return empty response |
| 257 | */ |
| 258 | @DELETE |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 259 | @Path("{subjectClassKey}") |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 260 | @SuppressWarnings("unchecked") |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 261 | public Response delete(@PathParam("subjectClassKey") String subjectClassKey) { |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 262 | NetworkConfigService service = get(NetworkConfigService.class); |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 263 | service.getSubjects(service.getSubjectFactory(subjectClassKey).getClass()) |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 264 | .forEach(subject -> service.getConfigs(subject) |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 265 | .forEach(config -> service.removeConfig(subject, config.getClass()))); |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 266 | return Response.ok().build(); |
| 267 | } |
| 268 | |
| 269 | /** |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 270 | * Clear all network configurations for a subjectKey. |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 271 | * |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 272 | * @param subjectClassKey subjectKey class key |
| 273 | * @param subjectKey subjectKey key |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 274 | * @return empty response |
| 275 | */ |
| 276 | @DELETE |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 277 | @Path("{subjectClassKey}/{subjectKey}") |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 278 | @SuppressWarnings("unchecked") |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 279 | public Response delete(@PathParam("subjectClassKey") String subjectClassKey, |
| 280 | @PathParam("subjectKey") String subjectKey) { |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 281 | NetworkConfigService service = get(NetworkConfigService.class); |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 282 | Object s = service.getSubjectFactory(subjectClassKey).createSubject(subjectKey); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 283 | service.getConfigs(s).forEach(c -> service.removeConfig(s, c.getClass())); |
| 284 | return Response.ok().build(); |
| 285 | } |
| 286 | |
| 287 | /** |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 288 | * Clear specific network configuration for a subjectKey. |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 289 | * |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 290 | * @param subjectClassKey subjectKey class key |
| 291 | * @param subjectKey subjectKey key |
| 292 | * @param configKey configuration class key |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 293 | * @return empty response |
| 294 | */ |
| 295 | @DELETE |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 296 | @Path("{subjectClassKey}/{subjectKey}/{configKey}") |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 297 | @SuppressWarnings("unchecked") |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 298 | public Response delete(@PathParam("subjectClassKey") String subjectClassKey, |
| 299 | @PathParam("subjectKey") String subjectKey, |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 300 | @PathParam("configKey") String configKey) { |
| 301 | NetworkConfigService service = get(NetworkConfigService.class); |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame^] | 302 | service.removeConfig(service.getSubjectFactory(subjectClassKey).createSubject(subjectKey), |
| 303 | service.getConfigClass(subjectClassKey, configKey)); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 304 | return Response.ok().build(); |
| 305 | } |
| 306 | |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 307 | } |