Committed by
Gerrit Code Review
Corrected output of network configuration subjectKeys in JSON output; no longer …
…relies on subject.toString. Change-Id: If4e07bc27cfaf8feb59397a5f104e5f663504f6e
Showing
8 changed files
with
61 additions
and
33 deletions
... | @@ -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 { | ... | ... |
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment