Thomas Vachuska
Committed by Gerrit Code Review

Corrected output of network configuration subjectKeys in JSON output; no longer …

…relies on subject.toString.

Change-Id: If4e07bc27cfaf8feb59397a5f104e5f663504f6e
...@@ -35,13 +35,13 @@ import static com.google.common.base.Strings.isNullOrEmpty; ...@@ -35,13 +35,13 @@ import static com.google.common.base.Strings.isNullOrEmpty;
35 description = "Manages network configuration") 35 description = "Manages network configuration")
36 public class NetworkConfigCommand extends AbstractShellCommand { 36 public class NetworkConfigCommand extends AbstractShellCommand {
37 37
38 - @Argument(index = 0, name = "subjectKey", description = "Subject key", 38 + @Argument(index = 0, name = "subjectClassKey", description = "Subject class key",
39 required = false, multiValued = false) 39 required = false, multiValued = false)
40 - String subjectKey = null; 40 + String subjectClassKey = null;
41 41
42 - @Argument(index = 1, name = "subject", description = "Subject", 42 + @Argument(index = 1, name = "subjectKey", description = "Subject key",
43 required = false, multiValued = false) 43 required = false, multiValued = false)
44 - String subject = null; 44 + String subjectKey = null;
45 45
46 @Argument(index = 2, name = "configKey", description = "Config key", 46 @Argument(index = 2, name = "configKey", description = "Config key",
47 required = false, multiValued = false) 47 required = false, multiValued = false)
...@@ -54,18 +54,18 @@ public class NetworkConfigCommand extends AbstractShellCommand { ...@@ -54,18 +54,18 @@ public class NetworkConfigCommand extends AbstractShellCommand {
54 protected void execute() { 54 protected void execute() {
55 service = get(NetworkConfigService.class); 55 service = get(NetworkConfigService.class);
56 JsonNode root = mapper.createObjectNode(); 56 JsonNode root = mapper.createObjectNode();
57 - if (isNullOrEmpty(subjectKey)) { 57 + if (isNullOrEmpty(subjectClassKey)) {
58 addAll((ObjectNode) root); 58 addAll((ObjectNode) root);
59 } else { 59 } else {
60 - SubjectFactory subjectFactory = service.getSubjectFactory(subjectKey); 60 + SubjectFactory subjectFactory = service.getSubjectFactory(subjectClassKey);
61 - if (isNullOrEmpty(subject)) { 61 + if (isNullOrEmpty(subjectKey)) {
62 addSubjectClass((ObjectNode) root, subjectFactory); 62 addSubjectClass((ObjectNode) root, subjectFactory);
63 } else { 63 } else {
64 - Object s = subjectFactory.createSubject(subject); 64 + Object s = subjectFactory.createSubject(subjectKey);
65 if (isNullOrEmpty(configKey)) { 65 if (isNullOrEmpty(configKey)) {
66 addSubject((ObjectNode) root, s); 66 addSubject((ObjectNode) root, s);
67 } else { 67 } else {
68 - root = getSubjectConfig(getConfig(s, subjectKey, configKey)); 68 + root = getSubjectConfig(getConfig(s, subjectClassKey, configKey));
69 } 69 }
70 } 70 }
71 } 71 }
...@@ -82,14 +82,14 @@ public class NetworkConfigCommand extends AbstractShellCommand { ...@@ -82,14 +82,14 @@ public class NetworkConfigCommand extends AbstractShellCommand {
82 service.getSubjectClasses() 82 service.getSubjectClasses()
83 .forEach(sc -> { 83 .forEach(sc -> {
84 SubjectFactory sf = service.getSubjectFactory(sc); 84 SubjectFactory sf = service.getSubjectFactory(sc);
85 - addSubjectClass(newObject(root, sf.subjectKey()), sf); 85 + addSubjectClass(newObject(root, sf.subjectClassKey()), sf);
86 }); 86 });
87 } 87 }
88 88
89 @SuppressWarnings("unchecked") 89 @SuppressWarnings("unchecked")
90 private void addSubjectClass(ObjectNode root, SubjectFactory sf) { 90 private void addSubjectClass(ObjectNode root, SubjectFactory sf) {
91 service.getSubjects(sf.subjectClass()) 91 service.getSubjects(sf.subjectClass())
92 - .forEach(s -> addSubject(newObject(root, s.toString()), s)); 92 + .forEach(s -> addSubject(newObject(root, sf.subjectKey(s)), s));
93 } 93 }
94 94
95 private void addSubject(ObjectNode root, Object s) { 95 private void addSubject(ObjectNode root, Object s) {
......
...@@ -42,7 +42,7 @@ public class NetworkConfigRegistryCommand extends AbstractShellCommand { ...@@ -42,7 +42,7 @@ public class NetworkConfigRegistryCommand extends AbstractShellCommand {
42 42
43 private void print(ConfigFactory configFactory) { 43 private void print(ConfigFactory configFactory) {
44 print(shortOnly ? SHORT_FMT : FMT, 44 print(shortOnly ? SHORT_FMT : FMT,
45 - configFactory.subjectFactory().subjectKey(), 45 + configFactory.subjectFactory().subjectClassKey(),
46 configFactory.configKey(), 46 configFactory.configKey(),
47 configFactory.subjectFactory().subjectClass().getName(), 47 configFactory.subjectFactory().subjectClass().getName(),
48 configFactory.configClass().getName()); 48 configFactory.configClass().getName());
......
...@@ -41,27 +41,27 @@ public interface NetworkConfigService ...@@ -41,27 +41,27 @@ public interface NetworkConfigService
41 /** 41 /**
42 * Returns the subject factory with the specified key. 42 * Returns the subject factory with the specified key.
43 * 43 *
44 - * @param subjectKey subject class key 44 + * @param subjectClassKey subject class key
45 * @return subject class 45 * @return subject class
46 */ 46 */
47 - SubjectFactory getSubjectFactory(String subjectKey); 47 + SubjectFactory getSubjectFactory(String subjectClassKey);
48 48
49 /** 49 /**
50 * Returns the subject factory for the specified class. 50 * Returns the subject factory for the specified class.
51 * 51 *
52 * @param subjectClass subject class 52 * @param subjectClass subject class
53 - * @return subject class key 53 + * @return subject class factory
54 */ 54 */
55 SubjectFactory getSubjectFactory(Class subjectClass); 55 SubjectFactory getSubjectFactory(Class subjectClass);
56 56
57 /** 57 /**
58 * Returns the configuration class with the specified key. 58 * Returns the configuration class with the specified key.
59 * 59 *
60 - * @param subjectKey subject class key 60 + * @param subjectClassKey subject class key
61 - * @param configKey subject class name 61 + * @param configKey subject class name
62 * @return subject class 62 * @return subject class
63 */ 63 */
64 - Class<? extends Config> getConfigClass(String subjectKey, String configKey); 64 + Class<? extends Config> getConfigClass(String subjectClassKey, String configKey);
65 65
66 /** 66 /**
67 * Returns the set of subjects for which some configuration is available. 67 * Returns the set of subjects for which some configuration is available.
......
...@@ -28,7 +28,7 @@ import com.google.common.annotations.Beta; ...@@ -28,7 +28,7 @@ import com.google.common.annotations.Beta;
28 public abstract class SubjectFactory<S> { 28 public abstract class SubjectFactory<S> {
29 29
30 private final Class<S> subjectClass; 30 private final Class<S> subjectClass;
31 - private final String subjectKey; 31 + private final String subjectClassKey;
32 32
33 /** 33 /**
34 * Creates a new configuration factory for the specified class of subjects 34 * Creates a new configuration factory for the specified class of subjects
...@@ -36,12 +36,12 @@ public abstract class SubjectFactory<S> { ...@@ -36,12 +36,12 @@ public abstract class SubjectFactory<S> {
36 * subject and configuration class keys are used merely as keys for use in 36 * subject and configuration class keys are used merely as keys for use in
37 * composite JSON trees. 37 * composite JSON trees.
38 * 38 *
39 - * @param subjectClass subject class 39 + * @param subjectClass subject class
40 - * @param subjectKey subject class key 40 + * @param subjectClassKey subject class key
41 */ 41 */
42 - protected SubjectFactory(Class<S> subjectClass, String subjectKey) { 42 + protected SubjectFactory(Class<S> subjectClass, String subjectClassKey) {
43 this.subjectClass = subjectClass; 43 this.subjectClass = subjectClass;
44 - this.subjectKey = subjectKey; 44 + this.subjectClassKey = subjectClassKey;
45 } 45 }
46 46
47 /** 47 /**
...@@ -60,8 +60,20 @@ public abstract class SubjectFactory<S> { ...@@ -60,8 +60,20 @@ public abstract class SubjectFactory<S> {
60 * 60 *
61 * @return configuration key 61 * @return configuration key
62 */ 62 */
63 - public String subjectKey() { 63 + public String subjectClassKey() {
64 - return subjectKey; 64 + return subjectClassKey;
65 + }
66 +
67 + /**
68 + * Returns the unique key of the specified configuration subject.
69 + * This is primarily aimed for use in composite JSON trees in external
70 + * representations and has no bearing on the internal behaviours.
71 + *
72 + * @param subject specific subject
73 + * @return subject key
74 + */
75 + public String subjectKey(S subject) {
76 + return subject.toString();
65 } 77 }
66 78
67 /** 79 /**
......
...@@ -43,6 +43,10 @@ public final class SubjectFactories { ...@@ -43,6 +43,10 @@ public final class SubjectFactories {
43 public ApplicationId createSubject(String key) { 43 public ApplicationId createSubject(String key) {
44 return coreService.registerApplication(key); 44 return coreService.registerApplication(key);
45 } 45 }
46 + @Override
47 + public String subjectKey(ApplicationId subject) {
48 + return subject.name();
49 + }
46 }; 50 };
47 51
48 public static final SubjectFactory<DeviceId> DEVICE_SUBJECT_FACTORY = 52 public static final SubjectFactory<DeviceId> DEVICE_SUBJECT_FACTORY =
...@@ -59,6 +63,10 @@ public final class SubjectFactories { ...@@ -59,6 +63,10 @@ public final class SubjectFactories {
59 public ConnectPoint createSubject(String key) { 63 public ConnectPoint createSubject(String key) {
60 return ConnectPoint.deviceConnectPoint(key); 64 return ConnectPoint.deviceConnectPoint(key);
61 } 65 }
66 + @Override
67 + public String subjectKey(ConnectPoint subject) {
68 + return key(subject);
69 + }
62 }; 70 };
63 71
64 public static final SubjectFactory<HostId> HOST_SUBJECT_FACTORY = 72 public static final SubjectFactory<HostId> HOST_SUBJECT_FACTORY =
...@@ -78,6 +86,10 @@ public final class SubjectFactories { ...@@ -78,6 +86,10 @@ public final class SubjectFactories {
78 return LinkKey.linkKey(ConnectPoint.deviceConnectPoint(cps[0]), 86 return LinkKey.linkKey(ConnectPoint.deviceConnectPoint(cps[0]),
79 ConnectPoint.deviceConnectPoint(cps[1])); 87 ConnectPoint.deviceConnectPoint(cps[1]));
80 } 88 }
89 + @Override
90 + public String subjectKey(LinkKey subject) {
91 + return key(subject.src()) + "-" + key(subject.dst());
92 + }
81 }; 93 };
82 94
83 /** 95 /**
...@@ -90,4 +102,8 @@ public final class SubjectFactories { ...@@ -90,4 +102,8 @@ public final class SubjectFactories {
90 coreService = service; 102 coreService = service;
91 } 103 }
92 104
105 + private static String key(ConnectPoint subject) {
106 + return subject.deviceId() + "/" + subject.port();
107 + }
108 +
93 } 109 }
......
...@@ -29,7 +29,7 @@ public class NetworkConfigServiceAdapter implements NetworkConfigService { ...@@ -29,7 +29,7 @@ public class NetworkConfigServiceAdapter implements NetworkConfigService {
29 } 29 }
30 30
31 @Override 31 @Override
32 - public SubjectFactory getSubjectFactory(String subjectKey) { 32 + public SubjectFactory getSubjectFactory(String subjectClassKey) {
33 return null; 33 return null;
34 } 34 }
35 35
...@@ -39,7 +39,7 @@ public class NetworkConfigServiceAdapter implements NetworkConfigService { ...@@ -39,7 +39,7 @@ public class NetworkConfigServiceAdapter implements NetworkConfigService {
39 } 39 }
40 40
41 @Override 41 @Override
42 - public Class<? extends Config> getConfigClass(String subjectKey, String configKey) { 42 + public Class<? extends Config> getConfigClass(String subjectClassKey, String configKey) {
43 return null; 43 return null;
44 } 44 }
45 45
......
...@@ -96,7 +96,7 @@ public class NetworkConfigManager ...@@ -96,7 +96,7 @@ public class NetworkConfigManager
96 configClasses.put(identifier(configFactory), configFactory.configClass()); 96 configClasses.put(identifier(configFactory), configFactory.configClass());
97 97
98 SubjectFactory subjectFactory = configFactory.subjectFactory(); 98 SubjectFactory subjectFactory = configFactory.subjectFactory();
99 - subjectClasses.putIfAbsent(subjectFactory.subjectKey(), subjectFactory); 99 + subjectClasses.putIfAbsent(subjectFactory.subjectClassKey(), subjectFactory);
100 subjectClassKeys.putIfAbsent(subjectFactory.subjectClass(), subjectFactory); 100 subjectClassKeys.putIfAbsent(subjectFactory.subjectClass(), subjectFactory);
101 101
102 store.addConfigFactory(configFactory); 102 store.addConfigFactory(configFactory);
...@@ -145,8 +145,8 @@ public class NetworkConfigManager ...@@ -145,8 +145,8 @@ public class NetworkConfigManager
145 } 145 }
146 146
147 @Override 147 @Override
148 - public SubjectFactory getSubjectFactory(String subjectKey) { 148 + public SubjectFactory getSubjectFactory(String subjectClassKey) {
149 - return subjectClasses.get(subjectKey); 149 + return subjectClasses.get(subjectClassKey);
150 } 150 }
151 151
152 @Override 152 @Override
...@@ -155,8 +155,8 @@ public class NetworkConfigManager ...@@ -155,8 +155,8 @@ public class NetworkConfigManager
155 } 155 }
156 156
157 @Override 157 @Override
158 - public Class<? extends Config> getConfigClass(String subjectKey, String configKey) { 158 + public Class<? extends Config> getConfigClass(String subjectClassKey, String configKey) {
159 - return configClasses.get(new ConfigIdentifier(subjectKey, configKey)); 159 + return configClasses.get(new ConfigIdentifier(subjectClassKey, configKey));
160 } 160 }
161 161
162 @Override 162 @Override
...@@ -255,7 +255,7 @@ public class NetworkConfigManager ...@@ -255,7 +255,7 @@ public class NetworkConfigManager
255 } 255 }
256 256
257 private static ConfigIdentifier identifier(ConfigFactory factory) { 257 private static ConfigIdentifier identifier(ConfigFactory factory) {
258 - return new ConfigIdentifier(factory.subjectFactory().subjectKey(), factory.configKey()); 258 + return new ConfigIdentifier(factory.subjectFactory().subjectClassKey(), factory.configKey());
259 } 259 }
260 260
261 static final class ConfigIdentifier { 261 static final class ConfigIdentifier {
......
...@@ -49,73 +49,77 @@ public class NetworkConfigWebResource extends AbstractWebResource { ...@@ -49,73 +49,77 @@ public class NetworkConfigWebResource extends AbstractWebResource {
49 public Response download() { 49 public Response download() {
50 NetworkConfigService service = get(NetworkConfigService.class); 50 NetworkConfigService service = get(NetworkConfigService.class);
51 ObjectNode root = mapper().createObjectNode(); 51 ObjectNode root = mapper().createObjectNode();
52 - service.getSubjectClasses().forEach(sc -> 52 + service.getSubjectClasses().forEach(sc -> {
53 - produceJson(service, newObject(root, service.getSubjectFactory(sc).subjectKey()), sc)); 53 + SubjectFactory subjectFactory = service.getSubjectFactory(sc);
54 + produceJson(service, newObject(root, subjectFactory.subjectClassKey()),
55 + subjectFactory, sc);
56 + });
54 return ok(root).build(); 57 return ok(root).build();
55 } 58 }
56 59
57 /** 60 /**
58 * Get all network configuration for a subject class. 61 * Get all network configuration for a subject class.
59 * 62 *
60 - * @param subjectKey subject class key 63 + * @param subjectClassKey subject class key
61 * @return network configuration JSON 64 * @return network configuration JSON
62 */ 65 */
63 @GET 66 @GET
64 - @Path("{subjectKey}") 67 + @Path("{subjectClassKey}")
65 @Produces(MediaType.APPLICATION_JSON) 68 @Produces(MediaType.APPLICATION_JSON)
66 @SuppressWarnings("unchecked") 69 @SuppressWarnings("unchecked")
67 - public Response download(@PathParam("subjectKey") String subjectKey) { 70 + public Response download(@PathParam("subjectClassKey") String subjectClassKey) {
68 NetworkConfigService service = get(NetworkConfigService.class); 71 NetworkConfigService service = get(NetworkConfigService.class);
69 ObjectNode root = mapper().createObjectNode(); 72 ObjectNode root = mapper().createObjectNode();
70 - produceJson(service, root, service.getSubjectFactory(subjectKey).subjectClass()); 73 + SubjectFactory subjectFactory = service.getSubjectFactory(subjectClassKey);
74 + produceJson(service, root, subjectFactory, subjectFactory.subjectClass());
71 return ok(root).build(); 75 return ok(root).build();
72 } 76 }
73 77
74 /** 78 /**
75 - * Get all network configuration for a subject. 79 + * Get all network configuration for a subjectKey.
76 * 80 *
77 - * @param subjectKey subject class key 81 + * @param subjectClassKey subjectKey class key
78 - * @param subject subject key 82 + * @param subjectKey subjectKey key
79 * @return network configuration JSON 83 * @return network configuration JSON
80 */ 84 */
81 @GET 85 @GET
82 - @Path("{subjectKey}/{subject}") 86 + @Path("{subjectClassKey}/{subjectKey}")
83 @Produces(MediaType.APPLICATION_JSON) 87 @Produces(MediaType.APPLICATION_JSON)
84 @SuppressWarnings("unchecked") 88 @SuppressWarnings("unchecked")
85 - public Response download(@PathParam("subjectKey") String subjectKey, 89 + public Response download(@PathParam("subjectClassKey") String subjectClassKey,
86 - @PathParam("subject") String subject) { 90 + @PathParam("subjectKey") String subjectKey) {
87 NetworkConfigService service = get(NetworkConfigService.class); 91 NetworkConfigService service = get(NetworkConfigService.class);
88 ObjectNode root = mapper().createObjectNode(); 92 ObjectNode root = mapper().createObjectNode();
89 - produceSubjectJson(service, root, 93 + SubjectFactory subjectFactory = service.getSubjectFactory(subjectClassKey);
90 - service.getSubjectFactory(subjectKey).createSubject(subject)); 94 + produceSubjectJson(service, root, subjectFactory.createSubject(subjectKey));
91 return ok(root).build(); 95 return ok(root).build();
92 } 96 }
93 97
94 /** 98 /**
95 - * Get specific network configuration for a subject. 99 + * Get specific network configuration for a subjectKey.
96 * 100 *
97 - * @param subjectKey subject class key 101 + * @param subjectClassKey subjectKey class key
98 - * @param subject subject key 102 + * @param subjectKey subjectKey key
99 - * @param configKey configuration class key 103 + * @param configKey configuration class key
100 * @return network configuration JSON 104 * @return network configuration JSON
101 */ 105 */
102 @GET 106 @GET
103 - @Path("{subjectKey}/{subject}/{configKey}") 107 + @Path("{subjectClassKey}/{subjectKey}/{configKey}")
104 @Produces(MediaType.APPLICATION_JSON) 108 @Produces(MediaType.APPLICATION_JSON)
105 @SuppressWarnings("unchecked") 109 @SuppressWarnings("unchecked")
106 - public Response download(@PathParam("subjectKey") String subjectKey, 110 + public Response download(@PathParam("subjectClassKey") String subjectClassKey,
107 - @PathParam("subject") String subject, 111 + @PathParam("subjectKey") String subjectKey,
108 @PathParam("configKey") String configKey) { 112 @PathParam("configKey") String configKey) {
109 NetworkConfigService service = get(NetworkConfigService.class); 113 NetworkConfigService service = get(NetworkConfigService.class);
110 - return ok(service.getConfig(service.getSubjectFactory(subjectKey).createSubject(subject), 114 + return ok(service.getConfig(service.getSubjectFactory(subjectClassKey).createSubject(subjectKey),
111 - service.getConfigClass(subjectKey, configKey)).node()).build(); 115 + service.getConfigClass(subjectClassKey, configKey)).node()).build();
112 } 116 }
113 117
114 @SuppressWarnings("unchecked") 118 @SuppressWarnings("unchecked")
115 private void produceJson(NetworkConfigService service, ObjectNode node, 119 private void produceJson(NetworkConfigService service, ObjectNode node,
116 - Class subjectClass) { 120 + SubjectFactory subjectFactory, Class subjectClass) {
117 service.getSubjects(subjectClass).forEach(s -> 121 service.getSubjects(subjectClass).forEach(s ->
118 - produceSubjectJson(service, newObject(node, s.toString()), s)); 122 + produceSubjectJson(service, newObject(node, subjectFactory.subjectKey(s)), s));
119 } 123 }
120 124
121 private void produceSubjectJson(NetworkConfigService service, ObjectNode node, 125 private void produceSubjectJson(NetworkConfigService service, ObjectNode node,
...@@ -128,8 +132,8 @@ public class NetworkConfigWebResource extends AbstractWebResource { ...@@ -128,8 +132,8 @@ public class NetworkConfigWebResource extends AbstractWebResource {
128 * Upload bulk network configuration. 132 * Upload bulk network configuration.
129 * 133 *
130 * @param request network configuration JSON rooted at the top node 134 * @param request network configuration JSON rooted at the top node
131 - * @throws IOException if unable to parse the request
132 * @return empty response 135 * @return empty response
136 + * @throws IOException if unable to parse the request
133 */ 137 */
134 @POST 138 @POST
135 @Consumes(MediaType.APPLICATION_JSON) 139 @Consumes(MediaType.APPLICATION_JSON)
...@@ -146,78 +150,78 @@ public class NetworkConfigWebResource extends AbstractWebResource { ...@@ -146,78 +150,78 @@ public class NetworkConfigWebResource extends AbstractWebResource {
146 /** 150 /**
147 * Upload multiple network configurations for a subject class. 151 * Upload multiple network configurations for a subject class.
148 * 152 *
149 - * @param subjectKey subject class key 153 + * @param subjectClassKey subject class key
150 - * @param request network configuration JSON rooted at the top node 154 + * @param request network configuration JSON rooted at the top node
151 * @return empty response 155 * @return empty response
152 * @throws IOException if unable to parse the request 156 * @throws IOException if unable to parse the request
153 */ 157 */
154 @POST 158 @POST
155 - @Path("{subjectKey}") 159 + @Path("{subjectClassKey}")
156 @Consumes(MediaType.APPLICATION_JSON) 160 @Consumes(MediaType.APPLICATION_JSON)
157 @SuppressWarnings("unchecked") 161 @SuppressWarnings("unchecked")
158 - public Response upload(@PathParam("subjectKey") String subjectKey, 162 + public Response upload(@PathParam("subjectClassKey") String subjectClassKey,
159 InputStream request) throws IOException { 163 InputStream request) throws IOException {
160 NetworkConfigService service = get(NetworkConfigService.class); 164 NetworkConfigService service = get(NetworkConfigService.class);
161 ObjectNode root = (ObjectNode) mapper().readTree(request); 165 ObjectNode root = (ObjectNode) mapper().readTree(request);
162 - consumeJson(service, root, service.getSubjectFactory(subjectKey)); 166 + consumeJson(service, root, service.getSubjectFactory(subjectClassKey));
163 return Response.ok().build(); 167 return Response.ok().build();
164 } 168 }
165 169
166 /** 170 /**
167 - * Upload mutliple network configurations for a subject. 171 + * Upload mutliple network configurations for a subjectKey.
168 * 172 *
169 - * @param subjectKey subject class key 173 + * @param subjectClassKey subjectKey class key
170 - * @param subject subject key 174 + * @param subjectKey subjectKey key
171 - * @param request network configuration JSON rooted at the top node 175 + * @param request network configuration JSON rooted at the top node
172 * @return empty response 176 * @return empty response
173 * @throws IOException if unable to parse the request 177 * @throws IOException if unable to parse the request
174 */ 178 */
175 @POST 179 @POST
176 - @Path("{subjectKey}/{subject}") 180 + @Path("{subjectClassKey}/{subjectKey}")
177 @Consumes(MediaType.APPLICATION_JSON) 181 @Consumes(MediaType.APPLICATION_JSON)
178 @SuppressWarnings("unchecked") 182 @SuppressWarnings("unchecked")
179 - public Response upload(@PathParam("subjectKey") String subjectKey, 183 + public Response upload(@PathParam("subjectClassKey") String subjectClassKey,
180 - @PathParam("subject") String subject, 184 + @PathParam("subjectKey") String subjectKey,
181 InputStream request) throws IOException { 185 InputStream request) throws IOException {
182 NetworkConfigService service = get(NetworkConfigService.class); 186 NetworkConfigService service = get(NetworkConfigService.class);
183 ObjectNode root = (ObjectNode) mapper().readTree(request); 187 ObjectNode root = (ObjectNode) mapper().readTree(request);
184 consumeSubjectJson(service, root, 188 consumeSubjectJson(service, root,
185 - service.getSubjectFactory(subjectKey).createSubject(subject), 189 + service.getSubjectFactory(subjectClassKey).createSubject(subjectKey),
186 - subjectKey); 190 + subjectClassKey);
187 return Response.ok().build(); 191 return Response.ok().build();
188 } 192 }
189 193
190 /** 194 /**
191 - * Upload specific network configuration for a subject. 195 + * Upload specific network configuration for a subjectKey.
192 * 196 *
193 - * @param subjectKey subject class key 197 + * @param subjectClassKey subjectKey class key
194 - * @param subject subject key 198 + * @param subjectKey subjectKey key
195 - * @param configKey configuration class key 199 + * @param configKey configuration class key
196 - * @param request network configuration JSON rooted at the top node 200 + * @param request network configuration JSON rooted at the top node
197 * @return empty response 201 * @return empty response
198 * @throws IOException if unable to parse the request 202 * @throws IOException if unable to parse the request
199 */ 203 */
200 @POST 204 @POST
201 - @Path("{subjectKey}/{subject}/{configKey}") 205 + @Path("{subjectClassKey}/{subjectKey}/{configKey}")
202 @Consumes(MediaType.APPLICATION_JSON) 206 @Consumes(MediaType.APPLICATION_JSON)
203 @SuppressWarnings("unchecked") 207 @SuppressWarnings("unchecked")
204 - public Response upload(@PathParam("subjectKey") String subjectKey, 208 + public Response upload(@PathParam("subjectClassKey") String subjectClassKey,
205 - @PathParam("subject") String subject, 209 + @PathParam("subjectKey") String subjectKey,
206 @PathParam("configKey") String configKey, 210 @PathParam("configKey") String configKey,
207 InputStream request) throws IOException { 211 InputStream request) throws IOException {
208 NetworkConfigService service = get(NetworkConfigService.class); 212 NetworkConfigService service = get(NetworkConfigService.class);
209 ObjectNode root = (ObjectNode) mapper().readTree(request); 213 ObjectNode root = (ObjectNode) mapper().readTree(request);
210 - service.applyConfig(service.getSubjectFactory(subjectKey).createSubject(subject), 214 + service.applyConfig(service.getSubjectFactory(subjectClassKey).createSubject(subjectKey),
211 - service.getConfigClass(subjectKey, configKey), root); 215 + service.getConfigClass(subjectClassKey, configKey), root);
212 return Response.ok().build(); 216 return Response.ok().build();
213 } 217 }
214 218
215 private void consumeJson(NetworkConfigService service, ObjectNode classNode, 219 private void consumeJson(NetworkConfigService service, ObjectNode classNode,
216 SubjectFactory subjectFactory) { 220 SubjectFactory subjectFactory) {
217 classNode.fieldNames().forEachRemaining(s -> 221 classNode.fieldNames().forEachRemaining(s ->
218 - consumeSubjectJson(service, (ObjectNode) classNode.path(s), 222 + consumeSubjectJson(service, (ObjectNode) classNode.path(s),
219 - subjectFactory.createSubject(s), 223 + subjectFactory.createSubject(s),
220 - subjectFactory.subjectKey())); 224 + subjectFactory.subjectClassKey()));
221 } 225 }
222 226
223 private void consumeSubjectJson(NetworkConfigService service, 227 private void consumeSubjectJson(NetworkConfigService service,
...@@ -225,7 +229,7 @@ public class NetworkConfigWebResource extends AbstractWebResource { ...@@ -225,7 +229,7 @@ public class NetworkConfigWebResource extends AbstractWebResource {
225 String subjectKey) { 229 String subjectKey) {
226 subjectNode.fieldNames().forEachRemaining(c -> 230 subjectNode.fieldNames().forEachRemaining(c ->
227 service.applyConfig(subject, service.getConfigClass(subjectKey, c), 231 service.applyConfig(subject, service.getConfigClass(subjectKey, c),
228 - (ObjectNode) subjectNode.path(c))); 232 + subjectNode.path(c)));
229 } 233 }
230 234
231 235
...@@ -241,64 +245,62 @@ public class NetworkConfigWebResource extends AbstractWebResource { ...@@ -241,64 +245,62 @@ public class NetworkConfigWebResource extends AbstractWebResource {
241 service.getSubjectClasses() 245 service.getSubjectClasses()
242 .forEach(subjectClass -> service.getSubjects(subjectClass) 246 .forEach(subjectClass -> service.getSubjects(subjectClass)
243 .forEach(subject -> service.getConfigs(subject) 247 .forEach(subject -> service.getConfigs(subject)
244 - .forEach(config -> service 248 + .forEach(config -> service.removeConfig(subject, config.getClass()))));
245 - .removeConfig(subject, config.getClass()))));
246 return Response.ok().build(); 249 return Response.ok().build();
247 } 250 }
248 251
249 /** 252 /**
250 * Clear all network configurations for a subject class. 253 * Clear all network configurations for a subject class.
251 * 254 *
252 - * @param subjectKey subject class key 255 + * @param subjectClassKey subject class key
253 * @return empty response 256 * @return empty response
254 */ 257 */
255 @DELETE 258 @DELETE
256 - @Path("{subjectKey}") 259 + @Path("{subjectClassKey}")
257 @SuppressWarnings("unchecked") 260 @SuppressWarnings("unchecked")
258 - public Response delete(@PathParam("subjectKey") String subjectKey) { 261 + public Response delete(@PathParam("subjectClassKey") String subjectClassKey) {
259 NetworkConfigService service = get(NetworkConfigService.class); 262 NetworkConfigService service = get(NetworkConfigService.class);
260 - service.getSubjects(service.getSubjectFactory(subjectKey).getClass()) 263 + service.getSubjects(service.getSubjectFactory(subjectClassKey).getClass())
261 .forEach(subject -> service.getConfigs(subject) 264 .forEach(subject -> service.getConfigs(subject)
262 - .forEach(config -> service 265 + .forEach(config -> service.removeConfig(subject, config.getClass())));
263 - .removeConfig(subject, config.getClass())));
264 return Response.ok().build(); 266 return Response.ok().build();
265 } 267 }
266 268
267 /** 269 /**
268 - * Clear all network configurations for a subject. 270 + * Clear all network configurations for a subjectKey.
269 * 271 *
270 - * @param subjectKey subject class key 272 + * @param subjectClassKey subjectKey class key
271 - * @param subject subject key 273 + * @param subjectKey subjectKey key
272 * @return empty response 274 * @return empty response
273 */ 275 */
274 @DELETE 276 @DELETE
275 - @Path("{subjectKey}/{subject}") 277 + @Path("{subjectClassKey}/{subjectKey}")
276 @SuppressWarnings("unchecked") 278 @SuppressWarnings("unchecked")
277 - public Response delete(@PathParam("subjectKey") String subjectKey, 279 + public Response delete(@PathParam("subjectClassKey") String subjectClassKey,
278 - @PathParam("subject") String subject) { 280 + @PathParam("subjectKey") String subjectKey) {
279 NetworkConfigService service = get(NetworkConfigService.class); 281 NetworkConfigService service = get(NetworkConfigService.class);
280 - Object s = service.getSubjectFactory(subjectKey).createSubject(subject); 282 + Object s = service.getSubjectFactory(subjectClassKey).createSubject(subjectKey);
281 service.getConfigs(s).forEach(c -> service.removeConfig(s, c.getClass())); 283 service.getConfigs(s).forEach(c -> service.removeConfig(s, c.getClass()));
282 return Response.ok().build(); 284 return Response.ok().build();
283 } 285 }
284 286
285 /** 287 /**
286 - * Clear specific network configuration for a subject. 288 + * Clear specific network configuration for a subjectKey.
287 * 289 *
288 - * @param subjectKey subject class key 290 + * @param subjectClassKey subjectKey class key
289 - * @param subject subject key 291 + * @param subjectKey subjectKey key
290 - * @param configKey configuration class key 292 + * @param configKey configuration class key
291 * @return empty response 293 * @return empty response
292 */ 294 */
293 @DELETE 295 @DELETE
294 - @Path("{subjectKey}/{subject}/{configKey}") 296 + @Path("{subjectClassKey}/{subjectKey}/{configKey}")
295 @SuppressWarnings("unchecked") 297 @SuppressWarnings("unchecked")
296 - public Response delete(@PathParam("subjectKey") String subjectKey, 298 + public Response delete(@PathParam("subjectClassKey") String subjectClassKey,
297 - @PathParam("subject") String subject, 299 + @PathParam("subjectKey") String subjectKey,
298 @PathParam("configKey") String configKey) { 300 @PathParam("configKey") String configKey) {
299 NetworkConfigService service = get(NetworkConfigService.class); 301 NetworkConfigService service = get(NetworkConfigService.class);
300 - service.removeConfig(service.getSubjectFactory(subjectKey).createSubject(subject), 302 + service.removeConfig(service.getSubjectFactory(subjectClassKey).createSubject(subjectKey),
301 - service.getConfigClass(subjectKey, configKey)); 303 + service.getConfigClass(subjectClassKey, configKey));
302 return Response.ok().build(); 304 return Response.ok().build();
303 } 305 }
304 306
......