Corrected output of network configuration subjectKeys in JSON output; no longer relies on subject.toString.
Change-Id: If4e07bc27cfaf8feb59397a5f104e5f663504f6e
diff --git a/cli/src/main/java/org/onosproject/cli/cfg/NetworkConfigCommand.java b/cli/src/main/java/org/onosproject/cli/cfg/NetworkConfigCommand.java
index d99a183..7ce5669 100644
--- a/cli/src/main/java/org/onosproject/cli/cfg/NetworkConfigCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/cfg/NetworkConfigCommand.java
@@ -35,14 +35,14 @@
description = "Manages network configuration")
public class NetworkConfigCommand extends AbstractShellCommand {
- @Argument(index = 0, name = "subjectKey", description = "Subject key",
+ @Argument(index = 0, name = "subjectClassKey", description = "Subject class key",
+ required = false, multiValued = false)
+ String subjectClassKey = null;
+
+ @Argument(index = 1, name = "subjectKey", description = "Subject key",
required = false, multiValued = false)
String subjectKey = null;
- @Argument(index = 1, name = "subject", description = "Subject",
- required = false, multiValued = false)
- String subject = null;
-
@Argument(index = 2, name = "configKey", description = "Config key",
required = false, multiValued = false)
String configKey = null;
@@ -54,18 +54,18 @@
protected void execute() {
service = get(NetworkConfigService.class);
JsonNode root = mapper.createObjectNode();
- if (isNullOrEmpty(subjectKey)) {
+ if (isNullOrEmpty(subjectClassKey)) {
addAll((ObjectNode) root);
} else {
- SubjectFactory subjectFactory = service.getSubjectFactory(subjectKey);
- if (isNullOrEmpty(subject)) {
+ SubjectFactory subjectFactory = service.getSubjectFactory(subjectClassKey);
+ if (isNullOrEmpty(subjectKey)) {
addSubjectClass((ObjectNode) root, subjectFactory);
} else {
- Object s = subjectFactory.createSubject(subject);
+ Object s = subjectFactory.createSubject(subjectKey);
if (isNullOrEmpty(configKey)) {
addSubject((ObjectNode) root, s);
} else {
- root = getSubjectConfig(getConfig(s, subjectKey, configKey));
+ root = getSubjectConfig(getConfig(s, subjectClassKey, configKey));
}
}
}
@@ -82,14 +82,14 @@
service.getSubjectClasses()
.forEach(sc -> {
SubjectFactory sf = service.getSubjectFactory(sc);
- addSubjectClass(newObject(root, sf.subjectKey()), sf);
+ addSubjectClass(newObject(root, sf.subjectClassKey()), sf);
});
}
@SuppressWarnings("unchecked")
private void addSubjectClass(ObjectNode root, SubjectFactory sf) {
service.getSubjects(sf.subjectClass())
- .forEach(s -> addSubject(newObject(root, s.toString()), s));
+ .forEach(s -> addSubject(newObject(root, sf.subjectKey(s)), s));
}
private void addSubject(ObjectNode root, Object s) {
diff --git a/cli/src/main/java/org/onosproject/cli/cfg/NetworkConfigRegistryCommand.java b/cli/src/main/java/org/onosproject/cli/cfg/NetworkConfigRegistryCommand.java
index f94967e..cf58877 100644
--- a/cli/src/main/java/org/onosproject/cli/cfg/NetworkConfigRegistryCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/cfg/NetworkConfigRegistryCommand.java
@@ -42,7 +42,7 @@
private void print(ConfigFactory configFactory) {
print(shortOnly ? SHORT_FMT : FMT,
- configFactory.subjectFactory().subjectKey(),
+ configFactory.subjectFactory().subjectClassKey(),
configFactory.configKey(),
configFactory.subjectFactory().subjectClass().getName(),
configFactory.configClass().getName());
diff --git a/core/api/src/main/java/org/onosproject/net/config/NetworkConfigService.java b/core/api/src/main/java/org/onosproject/net/config/NetworkConfigService.java
index c1eed98..8eb69a45 100644
--- a/core/api/src/main/java/org/onosproject/net/config/NetworkConfigService.java
+++ b/core/api/src/main/java/org/onosproject/net/config/NetworkConfigService.java
@@ -41,27 +41,27 @@
/**
* Returns the subject factory with the specified key.
*
- * @param subjectKey subject class key
+ * @param subjectClassKey subject class key
* @return subject class
*/
- SubjectFactory getSubjectFactory(String subjectKey);
+ SubjectFactory getSubjectFactory(String subjectClassKey);
/**
* Returns the subject factory for the specified class.
*
* @param subjectClass subject class
- * @return subject class key
+ * @return subject class factory
*/
SubjectFactory getSubjectFactory(Class subjectClass);
/**
* Returns the configuration class with the specified key.
*
- * @param subjectKey subject class key
- * @param configKey subject class name
+ * @param subjectClassKey subject class key
+ * @param configKey subject class name
* @return subject class
*/
- Class<? extends Config> getConfigClass(String subjectKey, String configKey);
+ Class<? extends Config> getConfigClass(String subjectClassKey, String configKey);
/**
* Returns the set of subjects for which some configuration is available.
diff --git a/core/api/src/main/java/org/onosproject/net/config/SubjectFactory.java b/core/api/src/main/java/org/onosproject/net/config/SubjectFactory.java
index cd2db34..f992d72 100644
--- a/core/api/src/main/java/org/onosproject/net/config/SubjectFactory.java
+++ b/core/api/src/main/java/org/onosproject/net/config/SubjectFactory.java
@@ -28,7 +28,7 @@
public abstract class SubjectFactory<S> {
private final Class<S> subjectClass;
- private final String subjectKey;
+ private final String subjectClassKey;
/**
* Creates a new configuration factory for the specified class of subjects
@@ -36,12 +36,12 @@
* subject and configuration class keys are used merely as keys for use in
* composite JSON trees.
*
- * @param subjectClass subject class
- * @param subjectKey subject class key
+ * @param subjectClass subject class
+ * @param subjectClassKey subject class key
*/
- protected SubjectFactory(Class<S> subjectClass, String subjectKey) {
+ protected SubjectFactory(Class<S> subjectClass, String subjectClassKey) {
this.subjectClass = subjectClass;
- this.subjectKey = subjectKey;
+ this.subjectClassKey = subjectClassKey;
}
/**
@@ -60,8 +60,20 @@
*
* @return configuration key
*/
- public String subjectKey() {
- return subjectKey;
+ public String subjectClassKey() {
+ return subjectClassKey;
+ }
+
+ /**
+ * Returns the unique key of the specified configuration subject.
+ * This is primarily aimed for use in composite JSON trees in external
+ * representations and has no bearing on the internal behaviours.
+ *
+ * @param subject specific subject
+ * @return subject key
+ */
+ public String subjectKey(S subject) {
+ return subject.toString();
}
/**
diff --git a/core/api/src/main/java/org/onosproject/net/config/basics/SubjectFactories.java b/core/api/src/main/java/org/onosproject/net/config/basics/SubjectFactories.java
index 884f2e2..311566b 100644
--- a/core/api/src/main/java/org/onosproject/net/config/basics/SubjectFactories.java
+++ b/core/api/src/main/java/org/onosproject/net/config/basics/SubjectFactories.java
@@ -43,6 +43,10 @@
public ApplicationId createSubject(String key) {
return coreService.registerApplication(key);
}
+ @Override
+ public String subjectKey(ApplicationId subject) {
+ return subject.name();
+ }
};
public static final SubjectFactory<DeviceId> DEVICE_SUBJECT_FACTORY =
@@ -59,6 +63,10 @@
public ConnectPoint createSubject(String key) {
return ConnectPoint.deviceConnectPoint(key);
}
+ @Override
+ public String subjectKey(ConnectPoint subject) {
+ return key(subject);
+ }
};
public static final SubjectFactory<HostId> HOST_SUBJECT_FACTORY =
@@ -78,6 +86,10 @@
return LinkKey.linkKey(ConnectPoint.deviceConnectPoint(cps[0]),
ConnectPoint.deviceConnectPoint(cps[1]));
}
+ @Override
+ public String subjectKey(LinkKey subject) {
+ return key(subject.src()) + "-" + key(subject.dst());
+ }
};
/**
@@ -90,4 +102,8 @@
coreService = service;
}
+ private static String key(ConnectPoint subject) {
+ return subject.deviceId() + "/" + subject.port();
+ }
+
}
diff --git a/core/api/src/test/java/org/onosproject/net/config/NetworkConfigServiceAdapter.java b/core/api/src/test/java/org/onosproject/net/config/NetworkConfigServiceAdapter.java
index b70d14e..7307258 100644
--- a/core/api/src/test/java/org/onosproject/net/config/NetworkConfigServiceAdapter.java
+++ b/core/api/src/test/java/org/onosproject/net/config/NetworkConfigServiceAdapter.java
@@ -29,7 +29,7 @@
}
@Override
- public SubjectFactory getSubjectFactory(String subjectKey) {
+ public SubjectFactory getSubjectFactory(String subjectClassKey) {
return null;
}
@@ -39,7 +39,7 @@
}
@Override
- public Class<? extends Config> getConfigClass(String subjectKey, String configKey) {
+ public Class<? extends Config> getConfigClass(String subjectClassKey, String configKey) {
return null;
}
diff --git a/core/net/src/main/java/org/onosproject/net/config/impl/NetworkConfigManager.java b/core/net/src/main/java/org/onosproject/net/config/impl/NetworkConfigManager.java
index 5cd96ca..db484ee 100644
--- a/core/net/src/main/java/org/onosproject/net/config/impl/NetworkConfigManager.java
+++ b/core/net/src/main/java/org/onosproject/net/config/impl/NetworkConfigManager.java
@@ -96,7 +96,7 @@
configClasses.put(identifier(configFactory), configFactory.configClass());
SubjectFactory subjectFactory = configFactory.subjectFactory();
- subjectClasses.putIfAbsent(subjectFactory.subjectKey(), subjectFactory);
+ subjectClasses.putIfAbsent(subjectFactory.subjectClassKey(), subjectFactory);
subjectClassKeys.putIfAbsent(subjectFactory.subjectClass(), subjectFactory);
store.addConfigFactory(configFactory);
@@ -145,8 +145,8 @@
}
@Override
- public SubjectFactory getSubjectFactory(String subjectKey) {
- return subjectClasses.get(subjectKey);
+ public SubjectFactory getSubjectFactory(String subjectClassKey) {
+ return subjectClasses.get(subjectClassKey);
}
@Override
@@ -155,8 +155,8 @@
}
@Override
- public Class<? extends Config> getConfigClass(String subjectKey, String configKey) {
- return configClasses.get(new ConfigIdentifier(subjectKey, configKey));
+ public Class<? extends Config> getConfigClass(String subjectClassKey, String configKey) {
+ return configClasses.get(new ConfigIdentifier(subjectClassKey, configKey));
}
@Override
@@ -255,7 +255,7 @@
}
private static ConfigIdentifier identifier(ConfigFactory factory) {
- return new ConfigIdentifier(factory.subjectFactory().subjectKey(), factory.configKey());
+ return new ConfigIdentifier(factory.subjectFactory().subjectClassKey(), factory.configKey());
}
static final class ConfigIdentifier {
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/NetworkConfigWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/NetworkConfigWebResource.java
index 9e2b627..808fcc1 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/NetworkConfigWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/NetworkConfigWebResource.java
@@ -49,73 +49,77 @@
public Response download() {
NetworkConfigService service = get(NetworkConfigService.class);
ObjectNode root = mapper().createObjectNode();
- service.getSubjectClasses().forEach(sc ->
- produceJson(service, newObject(root, service.getSubjectFactory(sc).subjectKey()), sc));
+ service.getSubjectClasses().forEach(sc -> {
+ SubjectFactory subjectFactory = service.getSubjectFactory(sc);
+ produceJson(service, newObject(root, subjectFactory.subjectClassKey()),
+ subjectFactory, sc);
+ });
return ok(root).build();
}
/**
* Get all network configuration for a subject class.
*
- * @param subjectKey subject class key
+ * @param subjectClassKey subject class key
* @return network configuration JSON
*/
@GET
- @Path("{subjectKey}")
+ @Path("{subjectClassKey}")
@Produces(MediaType.APPLICATION_JSON)
@SuppressWarnings("unchecked")
- public Response download(@PathParam("subjectKey") String subjectKey) {
+ public Response download(@PathParam("subjectClassKey") String subjectClassKey) {
NetworkConfigService service = get(NetworkConfigService.class);
ObjectNode root = mapper().createObjectNode();
- produceJson(service, root, service.getSubjectFactory(subjectKey).subjectClass());
+ SubjectFactory subjectFactory = service.getSubjectFactory(subjectClassKey);
+ produceJson(service, root, subjectFactory, subjectFactory.subjectClass());
return ok(root).build();
}
/**
- * Get all network configuration for a subject.
+ * Get all network configuration for a subjectKey.
*
- * @param subjectKey subject class key
- * @param subject subject key
+ * @param subjectClassKey subjectKey class key
+ * @param subjectKey subjectKey key
* @return network configuration JSON
*/
@GET
- @Path("{subjectKey}/{subject}")
+ @Path("{subjectClassKey}/{subjectKey}")
@Produces(MediaType.APPLICATION_JSON)
@SuppressWarnings("unchecked")
- public Response download(@PathParam("subjectKey") String subjectKey,
- @PathParam("subject") String subject) {
+ public Response download(@PathParam("subjectClassKey") String subjectClassKey,
+ @PathParam("subjectKey") String subjectKey) {
NetworkConfigService service = get(NetworkConfigService.class);
ObjectNode root = mapper().createObjectNode();
- produceSubjectJson(service, root,
- service.getSubjectFactory(subjectKey).createSubject(subject));
+ SubjectFactory subjectFactory = service.getSubjectFactory(subjectClassKey);
+ produceSubjectJson(service, root, subjectFactory.createSubject(subjectKey));
return ok(root).build();
}
/**
- * Get specific network configuration for a subject.
+ * Get specific network configuration for a subjectKey.
*
- * @param subjectKey subject class key
- * @param subject subject key
- * @param configKey configuration class key
+ * @param subjectClassKey subjectKey class key
+ * @param subjectKey subjectKey key
+ * @param configKey configuration class key
* @return network configuration JSON
*/
@GET
- @Path("{subjectKey}/{subject}/{configKey}")
+ @Path("{subjectClassKey}/{subjectKey}/{configKey}")
@Produces(MediaType.APPLICATION_JSON)
@SuppressWarnings("unchecked")
- public Response download(@PathParam("subjectKey") String subjectKey,
- @PathParam("subject") String subject,
+ public Response download(@PathParam("subjectClassKey") String subjectClassKey,
+ @PathParam("subjectKey") String subjectKey,
@PathParam("configKey") String configKey) {
NetworkConfigService service = get(NetworkConfigService.class);
- return ok(service.getConfig(service.getSubjectFactory(subjectKey).createSubject(subject),
- service.getConfigClass(subjectKey, configKey)).node()).build();
+ return ok(service.getConfig(service.getSubjectFactory(subjectClassKey).createSubject(subjectKey),
+ service.getConfigClass(subjectClassKey, configKey)).node()).build();
}
@SuppressWarnings("unchecked")
private void produceJson(NetworkConfigService service, ObjectNode node,
- Class subjectClass) {
+ SubjectFactory subjectFactory, Class subjectClass) {
service.getSubjects(subjectClass).forEach(s ->
- produceSubjectJson(service, newObject(node, s.toString()), s));
+ produceSubjectJson(service, newObject(node, subjectFactory.subjectKey(s)), s));
}
private void produceSubjectJson(NetworkConfigService service, ObjectNode node,
@@ -128,8 +132,8 @@
* Upload bulk network configuration.
*
* @param request network configuration JSON rooted at the top node
- * @throws IOException if unable to parse the request
* @return empty response
+ * @throws IOException if unable to parse the request
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@@ -146,78 +150,78 @@
/**
* Upload multiple network configurations for a subject class.
*
- * @param subjectKey subject class key
- * @param request network configuration JSON rooted at the top node
+ * @param subjectClassKey subject class key
+ * @param request network configuration JSON rooted at the top node
* @return empty response
* @throws IOException if unable to parse the request
*/
@POST
- @Path("{subjectKey}")
+ @Path("{subjectClassKey}")
@Consumes(MediaType.APPLICATION_JSON)
@SuppressWarnings("unchecked")
- public Response upload(@PathParam("subjectKey") String subjectKey,
+ public Response upload(@PathParam("subjectClassKey") String subjectClassKey,
InputStream request) throws IOException {
NetworkConfigService service = get(NetworkConfigService.class);
ObjectNode root = (ObjectNode) mapper().readTree(request);
- consumeJson(service, root, service.getSubjectFactory(subjectKey));
+ consumeJson(service, root, service.getSubjectFactory(subjectClassKey));
return Response.ok().build();
}
/**
- * Upload mutliple network configurations for a subject.
+ * Upload mutliple network configurations for a subjectKey.
*
- * @param subjectKey subject class key
- * @param subject subject key
- * @param request network configuration JSON rooted at the top node
+ * @param subjectClassKey subjectKey class key
+ * @param subjectKey subjectKey key
+ * @param request network configuration JSON rooted at the top node
* @return empty response
* @throws IOException if unable to parse the request
*/
@POST
- @Path("{subjectKey}/{subject}")
+ @Path("{subjectClassKey}/{subjectKey}")
@Consumes(MediaType.APPLICATION_JSON)
@SuppressWarnings("unchecked")
- public Response upload(@PathParam("subjectKey") String subjectKey,
- @PathParam("subject") String subject,
+ public Response upload(@PathParam("subjectClassKey") String subjectClassKey,
+ @PathParam("subjectKey") String subjectKey,
InputStream request) throws IOException {
NetworkConfigService service = get(NetworkConfigService.class);
ObjectNode root = (ObjectNode) mapper().readTree(request);
consumeSubjectJson(service, root,
- service.getSubjectFactory(subjectKey).createSubject(subject),
- subjectKey);
+ service.getSubjectFactory(subjectClassKey).createSubject(subjectKey),
+ subjectClassKey);
return Response.ok().build();
}
/**
- * Upload specific network configuration for a subject.
+ * Upload specific network configuration for a subjectKey.
*
- * @param subjectKey subject class key
- * @param subject subject key
- * @param configKey configuration class key
- * @param request network configuration JSON rooted at the top node
+ * @param subjectClassKey subjectKey class key
+ * @param subjectKey subjectKey key
+ * @param configKey configuration class key
+ * @param request network configuration JSON rooted at the top node
* @return empty response
* @throws IOException if unable to parse the request
*/
@POST
- @Path("{subjectKey}/{subject}/{configKey}")
+ @Path("{subjectClassKey}/{subjectKey}/{configKey}")
@Consumes(MediaType.APPLICATION_JSON)
@SuppressWarnings("unchecked")
- public Response upload(@PathParam("subjectKey") String subjectKey,
- @PathParam("subject") String subject,
+ public Response upload(@PathParam("subjectClassKey") String subjectClassKey,
+ @PathParam("subjectKey") String subjectKey,
@PathParam("configKey") String configKey,
InputStream request) throws IOException {
NetworkConfigService service = get(NetworkConfigService.class);
ObjectNode root = (ObjectNode) mapper().readTree(request);
- service.applyConfig(service.getSubjectFactory(subjectKey).createSubject(subject),
- service.getConfigClass(subjectKey, configKey), root);
+ service.applyConfig(service.getSubjectFactory(subjectClassKey).createSubject(subjectKey),
+ service.getConfigClass(subjectClassKey, configKey), root);
return Response.ok().build();
}
private void consumeJson(NetworkConfigService service, ObjectNode classNode,
SubjectFactory subjectFactory) {
classNode.fieldNames().forEachRemaining(s ->
- consumeSubjectJson(service, (ObjectNode) classNode.path(s),
- subjectFactory.createSubject(s),
- subjectFactory.subjectKey()));
+ consumeSubjectJson(service, (ObjectNode) classNode.path(s),
+ subjectFactory.createSubject(s),
+ subjectFactory.subjectClassKey()));
}
private void consumeSubjectJson(NetworkConfigService service,
@@ -225,7 +229,7 @@
String subjectKey) {
subjectNode.fieldNames().forEachRemaining(c ->
service.applyConfig(subject, service.getConfigClass(subjectKey, c),
- (ObjectNode) subjectNode.path(c)));
+ subjectNode.path(c)));
}
@@ -241,64 +245,62 @@
service.getSubjectClasses()
.forEach(subjectClass -> service.getSubjects(subjectClass)
.forEach(subject -> service.getConfigs(subject)
- .forEach(config -> service
- .removeConfig(subject, config.getClass()))));
+ .forEach(config -> service.removeConfig(subject, config.getClass()))));
return Response.ok().build();
}
/**
* Clear all network configurations for a subject class.
*
- * @param subjectKey subject class key
+ * @param subjectClassKey subject class key
* @return empty response
*/
@DELETE
- @Path("{subjectKey}")
+ @Path("{subjectClassKey}")
@SuppressWarnings("unchecked")
- public Response delete(@PathParam("subjectKey") String subjectKey) {
+ public Response delete(@PathParam("subjectClassKey") String subjectClassKey) {
NetworkConfigService service = get(NetworkConfigService.class);
- service.getSubjects(service.getSubjectFactory(subjectKey).getClass())
+ service.getSubjects(service.getSubjectFactory(subjectClassKey).getClass())
.forEach(subject -> service.getConfigs(subject)
- .forEach(config -> service
- .removeConfig(subject, config.getClass())));
+ .forEach(config -> service.removeConfig(subject, config.getClass())));
return Response.ok().build();
}
/**
- * Clear all network configurations for a subject.
+ * Clear all network configurations for a subjectKey.
*
- * @param subjectKey subject class key
- * @param subject subject key
+ * @param subjectClassKey subjectKey class key
+ * @param subjectKey subjectKey key
* @return empty response
*/
@DELETE
- @Path("{subjectKey}/{subject}")
+ @Path("{subjectClassKey}/{subjectKey}")
@SuppressWarnings("unchecked")
- public Response delete(@PathParam("subjectKey") String subjectKey,
- @PathParam("subject") String subject) {
+ public Response delete(@PathParam("subjectClassKey") String subjectClassKey,
+ @PathParam("subjectKey") String subjectKey) {
NetworkConfigService service = get(NetworkConfigService.class);
- Object s = service.getSubjectFactory(subjectKey).createSubject(subject);
+ Object s = service.getSubjectFactory(subjectClassKey).createSubject(subjectKey);
service.getConfigs(s).forEach(c -> service.removeConfig(s, c.getClass()));
return Response.ok().build();
}
/**
- * Clear specific network configuration for a subject.
+ * Clear specific network configuration for a subjectKey.
*
- * @param subjectKey subject class key
- * @param subject subject key
- * @param configKey configuration class key
+ * @param subjectClassKey subjectKey class key
+ * @param subjectKey subjectKey key
+ * @param configKey configuration class key
* @return empty response
*/
@DELETE
- @Path("{subjectKey}/{subject}/{configKey}")
+ @Path("{subjectClassKey}/{subjectKey}/{configKey}")
@SuppressWarnings("unchecked")
- public Response delete(@PathParam("subjectKey") String subjectKey,
- @PathParam("subject") String subject,
+ public Response delete(@PathParam("subjectClassKey") String subjectClassKey,
+ @PathParam("subjectKey") String subjectKey,
@PathParam("configKey") String configKey) {
NetworkConfigService service = get(NetworkConfigService.class);
- service.removeConfig(service.getSubjectFactory(subjectKey).createSubject(subject),
- service.getConfigClass(subjectKey, configKey));
+ service.removeConfig(service.getSubjectFactory(subjectClassKey).createSubject(subjectKey),
+ service.getConfigClass(subjectClassKey, configKey));
return Response.ok().build();
}