Committed by
Gerrit Code Review
Sketching out basis for network configuration subsystem API.
Change-Id: I9d56a8392bd300566fb333607102cc965b2fa66e
Showing
6 changed files
with
311 additions
and
0 deletions
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.exp.net.config; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
19 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
20 | + | ||
21 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
22 | + | ||
23 | +/** | ||
24 | + * Base abstraction of a configuration facade for a specific subject. Derived | ||
25 | + * classes should keep all state in the specified JSON tree. | ||
26 | + * | ||
27 | + * @param <S> type of subject | ||
28 | + */ | ||
29 | +public abstract class Config<S> { | ||
30 | + | ||
31 | + protected ObjectMapper mapper; | ||
32 | + protected ObjectNode node; | ||
33 | + private S subject; | ||
34 | + private ConfigApplyDelegate<S> delegate; | ||
35 | + | ||
36 | + /** | ||
37 | + * Returns the specific subject to which this configuration pertains. | ||
38 | + * | ||
39 | + * @return configuration subject | ||
40 | + */ | ||
41 | + S subject() { | ||
42 | + return subject; | ||
43 | + } | ||
44 | + | ||
45 | + /** | ||
46 | + * Initializes the configuration behaviour with necessary context. | ||
47 | + * | ||
48 | + * @param subject configuration subject | ||
49 | + * @param node JSON object node where configuration data is stored | ||
50 | + * @param mapper JSON object mapper | ||
51 | + */ | ||
52 | + public void init(S subject, ObjectNode node, ObjectMapper mapper, | ||
53 | + ConfigApplyDelegate<S> delegate) { | ||
54 | + this.subject = checkNotNull(subject); | ||
55 | + this.node = checkNotNull(node); | ||
56 | + this.mapper = checkNotNull(mapper); | ||
57 | + this.delegate = checkNotNull(delegate); | ||
58 | + } | ||
59 | + | ||
60 | + /** | ||
61 | + * Applies any configuration changes made via this configuration. | ||
62 | + */ | ||
63 | + public void apply() { | ||
64 | + delegate.onApply(this); | ||
65 | + } | ||
66 | + | ||
67 | +} |
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.exp.net.config; | ||
17 | + | ||
18 | +/** | ||
19 | + * Delegate for notification when configuration changes have been applied. | ||
20 | + */ | ||
21 | +public interface ConfigApplyDelegate<S> { | ||
22 | + | ||
23 | + /** | ||
24 | + * Processes changes applied to the specified configuration. | ||
25 | + * | ||
26 | + * @param config changed configuration | ||
27 | + */ | ||
28 | + void onApply(Config<S> config); | ||
29 | + | ||
30 | +} |
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.exp.net.config; | ||
17 | + | ||
18 | + | ||
19 | +/** | ||
20 | + * Base abstract factory for creating configurations for the specified subject type. | ||
21 | + * | ||
22 | + * @param <S> subject class | ||
23 | + */ | ||
24 | +public abstract class ConfigFactory<S> { | ||
25 | + | ||
26 | + private final Class<S> subjectClass; | ||
27 | + private final String key; | ||
28 | + | ||
29 | + /** | ||
30 | + * Creates a new configuration factory for the specified class of subjects | ||
31 | + * and bound to the given subject configuration key. | ||
32 | + * | ||
33 | + * @param subjectClass subject class | ||
34 | + * @param key subject configuration key | ||
35 | + */ | ||
36 | + protected ConfigFactory(Class<S> subjectClass, String key) { | ||
37 | + this.subjectClass = subjectClass; | ||
38 | + this.key = key; | ||
39 | + } | ||
40 | + | ||
41 | + /** | ||
42 | + * Returns the class of the subject to which this factory applies. | ||
43 | + * | ||
44 | + * @return subject type | ||
45 | + */ | ||
46 | + public Class<S> subjectClass() { | ||
47 | + return subjectClass; | ||
48 | + } | ||
49 | + | ||
50 | + /** | ||
51 | + * Returns the key to which produced configurations should be bound. | ||
52 | + * | ||
53 | + * @return subject configuration key | ||
54 | + */ | ||
55 | + public String key() { | ||
56 | + return key; | ||
57 | + } | ||
58 | + | ||
59 | + /** | ||
60 | + * Creates a new but uninitialized configuration. Framework will initialize | ||
61 | + * the configuration via {@link Config#init} method. | ||
62 | + * | ||
63 | + * @return new uninitialized configuration | ||
64 | + */ | ||
65 | + public abstract Config<S> createConfig(); | ||
66 | + | ||
67 | +} |
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.exp.net.config; | ||
17 | + | ||
18 | +import java.util.Set; | ||
19 | + | ||
20 | +/** | ||
21 | + * Service for tracking network configuration factories. | ||
22 | + */ | ||
23 | +public interface NetworkConfigRegistry { | ||
24 | + | ||
25 | + /** | ||
26 | + * Registers the specified configuration factory. | ||
27 | + * | ||
28 | + * @param configFactory configuration factory | ||
29 | + */ | ||
30 | + void registerConfigFactory(ConfigFactory configFactory); | ||
31 | + | ||
32 | + /** | ||
33 | + * Unregisters the specified configuration factory. | ||
34 | + * | ||
35 | + * @param configFactory configuration factory | ||
36 | + */ | ||
37 | + void unregisterConfigFactory(ConfigFactory configFactory); | ||
38 | + | ||
39 | + /** | ||
40 | + * Returns set of configuration factories available for the specified | ||
41 | + * class of subject. | ||
42 | + * | ||
43 | + * @param subjectClass subject class | ||
44 | + */ | ||
45 | + <T> Set<ConfigFactory<T>> getConfigFactories(Class<T> subjectClass); | ||
46 | + | ||
47 | + /** | ||
48 | + * Returns the configuration type registered for the specified | ||
49 | + * subject type and key. | ||
50 | + * | ||
51 | + * @param subjectClass subject class | ||
52 | + */ | ||
53 | + <T> ConfigFactory<T> getConfigFactory(Class<T> subjectClass, String configKey); | ||
54 | + | ||
55 | + /** | ||
56 | + * Returns the configuration type registered for the specified | ||
57 | + * configuration class. | ||
58 | + * | ||
59 | + * @param configClass configuration class | ||
60 | + */ | ||
61 | + <T> ConfigFactory<T> getConfigFactory(Class<Config<T>> configClass); | ||
62 | + | ||
63 | +} |
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.exp.net.config; | ||
17 | + | ||
18 | +import java.util.Set; | ||
19 | + | ||
20 | +/** | ||
21 | + * Service for tracking network configurations which specify how the discovered | ||
22 | + * network information should be interpretted and how the network should be | ||
23 | + * configured. | ||
24 | + */ | ||
25 | +public interface NetworkConfigService { | ||
26 | + | ||
27 | + /** | ||
28 | + * Returns the set of subjects for which some configuration is available. | ||
29 | + * | ||
30 | + * @param subjectClass subject class | ||
31 | + * @return set of configured subjects | ||
32 | + */ | ||
33 | + <T> Set<T> getSubjects(Class<T> subjectClass); | ||
34 | + | ||
35 | + /** | ||
36 | + * Returns the set of subjects for which the specified configuration is | ||
37 | + * available. | ||
38 | + * | ||
39 | + * @param subjectClass subject class | ||
40 | + * @param configClass configuration class | ||
41 | + * @return set of configured subjects | ||
42 | + */ | ||
43 | + <T> Set<T> getSubjects(Class<T> subjectClass, Class<Config<T>> configClass); | ||
44 | + | ||
45 | + | ||
46 | + /** | ||
47 | + * Returns all configurations for the specified subject. | ||
48 | + * | ||
49 | + * @param subject configuration subject | ||
50 | + * @return set of configurations | ||
51 | + */ | ||
52 | + <T> Set<Config<T>> getConfigs(T subject); | ||
53 | + | ||
54 | + /** | ||
55 | + * Returns the configuration for the specified subject and configuration | ||
56 | + * class if one is available; null otherwise. | ||
57 | + * | ||
58 | + * @param subject configuration subject | ||
59 | + * @param configClass configuration class | ||
60 | + * @return configuration or null if one is not available | ||
61 | + */ | ||
62 | + <T> Config<T> getConfig(T subject, Class<Config<T>> configClass); | ||
63 | + | ||
64 | +} |
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 | + | ||
17 | +/** | ||
18 | + * Subsystem for tracking network environment configuration. | ||
19 | + */ | ||
20 | +package org.onosproject.exp.net.config; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment