ONOS-1048 - Define interfaces instead of using IntentManager
- Define IntentProcessor interface containing methods to process an intent - Pull out IntentCompiler related tasks to CompilerRegistry - Pull out IntentInstaller related tasks to InstallerRegistry - Create an IntentProcessor subclass as inner class in IntentManager Change-Id: Ia3e8d574a1053e7ddc9b961873ef758c9e0b1b26
Showing
11 changed files
with
233 additions
and
43 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.net.intent.impl; | ||
17 | + | ||
18 | +import com.google.common.collect.ImmutableList; | ||
19 | +import com.google.common.collect.ImmutableMap; | ||
20 | +import org.onosproject.net.intent.Intent; | ||
21 | +import org.onosproject.net.intent.IntentCompiler; | ||
22 | +import org.onosproject.net.intent.IntentException; | ||
23 | + | ||
24 | +import java.util.ArrayList; | ||
25 | +import java.util.List; | ||
26 | +import java.util.Map; | ||
27 | +import java.util.concurrent.ConcurrentHashMap; | ||
28 | +import java.util.concurrent.ConcurrentMap; | ||
29 | + | ||
30 | +// TODO: consider a better name | ||
31 | +class CompilerRegistry { | ||
32 | + | ||
33 | + private final ConcurrentMap<Class<? extends Intent>, | ||
34 | + IntentCompiler<? extends Intent>> compilers = new ConcurrentHashMap<>(); | ||
35 | + | ||
36 | + /** | ||
37 | + * Registers the specified compiler for the given intent class. | ||
38 | + * | ||
39 | + * @param cls intent class | ||
40 | + * @param compiler intent compiler | ||
41 | + * @param <T> the type of intent | ||
42 | + */ | ||
43 | + public <T extends Intent> void registerCompiler(Class<T> cls, IntentCompiler<T> compiler) { | ||
44 | + compilers.put(cls, compiler); | ||
45 | + } | ||
46 | + | ||
47 | + /** | ||
48 | + * Unregisters the compiler for the specified intent class. | ||
49 | + * | ||
50 | + * @param cls intent class | ||
51 | + * @param <T> the type of intent | ||
52 | + */ | ||
53 | + public <T extends Intent> void unregisterCompiler(Class<T> cls) { | ||
54 | + compilers.remove(cls); | ||
55 | + } | ||
56 | + | ||
57 | + /** | ||
58 | + * Returns immutable set of bindings of currently registered intent compilers. | ||
59 | + * | ||
60 | + * @return the set of compiler bindings | ||
61 | + */ | ||
62 | + public Map<Class<? extends Intent>, IntentCompiler<? extends Intent>> getCompilers() { | ||
63 | + return ImmutableMap.copyOf(compilers); | ||
64 | + } | ||
65 | + | ||
66 | + /** | ||
67 | + * Compiles an intent recursively. | ||
68 | + * | ||
69 | + * @param intent intent | ||
70 | + * @param previousInstallables previous intent installables | ||
71 | + * @return result of compilation | ||
72 | + */ | ||
73 | + List<Intent> compile(Intent intent, List<Intent> previousInstallables) { | ||
74 | + if (intent.isInstallable()) { | ||
75 | + return ImmutableList.of(intent); | ||
76 | + } | ||
77 | + | ||
78 | + registerSubclassCompilerIfNeeded(intent); | ||
79 | + // FIXME: get previous resources | ||
80 | + List<Intent> installable = new ArrayList<>(); | ||
81 | + for (Intent compiled : getCompiler(intent).compile(intent, previousInstallables, null)) { | ||
82 | + installable.addAll(compile(compiled, previousInstallables)); | ||
83 | + } | ||
84 | + return installable; | ||
85 | + } | ||
86 | + | ||
87 | + /** | ||
88 | + * Returns the corresponding intent compiler to the specified intent. | ||
89 | + * | ||
90 | + * @param intent intent | ||
91 | + * @param <T> the type of intent | ||
92 | + * @return intent compiler corresponding to the specified intent | ||
93 | + */ | ||
94 | + private <T extends Intent> IntentCompiler<T> getCompiler(T intent) { | ||
95 | + @SuppressWarnings("unchecked") | ||
96 | + IntentCompiler<T> compiler = (IntentCompiler<T>) compilers.get(intent.getClass()); | ||
97 | + if (compiler == null) { | ||
98 | + throw new IntentException("no compiler for class " + intent.getClass()); | ||
99 | + } | ||
100 | + return compiler; | ||
101 | + } | ||
102 | + | ||
103 | + /** | ||
104 | + * Registers an intent compiler of the specified intent if an intent compiler | ||
105 | + * for the intent is not registered. This method traverses the class hierarchy of | ||
106 | + * the intent. Once an intent compiler for a parent type is found, this method | ||
107 | + * registers the found intent compiler. | ||
108 | + * | ||
109 | + * @param intent intent | ||
110 | + */ | ||
111 | + private void registerSubclassCompilerIfNeeded(Intent intent) { | ||
112 | + if (!compilers.containsKey(intent.getClass())) { | ||
113 | + Class<?> cls = intent.getClass(); | ||
114 | + while (cls != Object.class) { | ||
115 | + // As long as we're within the Intent class descendants | ||
116 | + if (Intent.class.isAssignableFrom(cls)) { | ||
117 | + IntentCompiler<?> compiler = compilers.get(cls); | ||
118 | + if (compiler != null) { | ||
119 | + compilers.put(intent.getClass(), compiler); | ||
120 | + return; | ||
121 | + } | ||
122 | + } | ||
123 | + cls = cls.getSuperclass(); | ||
124 | + } | ||
125 | + } | ||
126 | + } | ||
127 | +} |
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
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.net.intent.impl; | ||
17 | + | ||
18 | +import org.onosproject.net.flow.FlowRuleOperations; | ||
19 | +import org.onosproject.net.intent.Intent; | ||
20 | +import org.onosproject.net.intent.IntentData; | ||
21 | + | ||
22 | +import java.util.List; | ||
23 | + | ||
24 | +/** | ||
25 | + * A collection of methods to process an intent. | ||
26 | + * | ||
27 | + * This interface is public, but intended to be used only by IntentManager and | ||
28 | + * IntentProcessPhase subclasses stored under phase package. | ||
29 | + */ | ||
30 | +public interface IntentProcessor { | ||
31 | + | ||
32 | + /** | ||
33 | + * Compiles an intent recursively. | ||
34 | + * | ||
35 | + * @param intent intent | ||
36 | + * @param previousInstallables previous intent installables | ||
37 | + * @return result of compilation | ||
38 | + */ | ||
39 | + List<Intent> compile(Intent intent, List<Intent> previousInstallables); | ||
40 | + | ||
41 | + /** | ||
42 | + * Generate a {@link FlowRuleOperations} instance from the specified intent data. | ||
43 | + * | ||
44 | + * @param current intent data stored in the store | ||
45 | + * @param pending intent data being processed | ||
46 | + * @return flow rule operations | ||
47 | + */ | ||
48 | + FlowRuleOperations coordinate(IntentData current, IntentData pending); | ||
49 | + | ||
50 | + /** | ||
51 | + * Generate a {@link FlowRuleOperations} instance from the specified intent data. | ||
52 | + * | ||
53 | + * @param current intent data stored in the store | ||
54 | + * @param pending intent data being processed | ||
55 | + * @return flow rule operations | ||
56 | + */ | ||
57 | + FlowRuleOperations uninstallCoordinate(IntentData current, IntentData pending); | ||
58 | + | ||
59 | + /** | ||
60 | + * Applies a batch operation of FlowRules. | ||
61 | + * | ||
62 | + * @param flowRules batch operation to apply | ||
63 | + */ | ||
64 | + // TODO: consider a better name | ||
65 | + // This methods gives strangeness a bit because | ||
66 | + // it doesn't receive/return intent related information | ||
67 | + void applyFlowRules(FlowRuleOperations flowRules); | ||
68 | +} |
... | @@ -18,7 +18,7 @@ package org.onosproject.net.intent.impl.phase; | ... | @@ -18,7 +18,7 @@ package org.onosproject.net.intent.impl.phase; |
18 | import org.onosproject.net.intent.Intent; | 18 | import org.onosproject.net.intent.Intent; |
19 | import org.onosproject.net.intent.IntentData; | 19 | import org.onosproject.net.intent.IntentData; |
20 | import org.onosproject.net.intent.IntentException; | 20 | import org.onosproject.net.intent.IntentException; |
21 | -import org.onosproject.net.intent.impl.IntentManager; | 21 | +import org.onosproject.net.intent.impl.IntentProcessor; |
22 | import org.slf4j.Logger; | 22 | import org.slf4j.Logger; |
23 | import org.slf4j.LoggerFactory; | 23 | import org.slf4j.LoggerFactory; |
24 | 24 | ||
... | @@ -34,13 +34,12 @@ final class Compiling implements IntentProcessPhase { | ... | @@ -34,13 +34,12 @@ final class Compiling implements IntentProcessPhase { |
34 | 34 | ||
35 | private static final Logger log = LoggerFactory.getLogger(Compiling.class); | 35 | private static final Logger log = LoggerFactory.getLogger(Compiling.class); |
36 | 36 | ||
37 | - // TODO: define an interface and use it, instead of IntentManager | 37 | + private final IntentProcessor processor; |
38 | - private final IntentManager intentManager; | ||
39 | private final IntentData pending; | 38 | private final IntentData pending; |
40 | private final IntentData current; | 39 | private final IntentData current; |
41 | 40 | ||
42 | - Compiling(IntentManager intentManager, IntentData pending, IntentData current) { | 41 | + Compiling(IntentProcessor processor, IntentData pending, IntentData current) { |
43 | - this.intentManager = checkNotNull(intentManager); | 42 | + this.processor = checkNotNull(processor); |
44 | this.pending = checkNotNull(pending); | 43 | this.pending = checkNotNull(pending); |
45 | this.current = current; | 44 | this.current = current; |
46 | } | 45 | } |
... | @@ -49,11 +48,12 @@ final class Compiling implements IntentProcessPhase { | ... | @@ -49,11 +48,12 @@ final class Compiling implements IntentProcessPhase { |
49 | public Optional<IntentProcessPhase> execute() { | 48 | public Optional<IntentProcessPhase> execute() { |
50 | try { | 49 | try { |
51 | List<Intent> installables = (current != null) ? current.installables() : null; | 50 | List<Intent> installables = (current != null) ? current.installables() : null; |
52 | - pending.setInstallables(intentManager.compileIntent(pending.intent(), installables)); | 51 | + pending.setInstallables(processor.compile(pending.intent(), installables)); |
53 | - return Optional.of(new InstallCoordinating(intentManager, pending, current)); | 52 | + return Optional.of(new InstallCoordinating(processor, pending, current)); |
54 | } catch (IntentException e) { | 53 | } catch (IntentException e) { |
55 | log.debug("Unable to compile intent {} due to: {}", pending.intent(), e); | 54 | log.debug("Unable to compile intent {} due to: {}", pending.intent(), e); |
56 | return Optional.of(new CompilingFailed(pending)); | 55 | return Optional.of(new CompilingFailed(pending)); |
57 | } | 56 | } |
58 | } | 57 | } |
58 | + | ||
59 | } | 59 | } | ... | ... |
... | @@ -18,7 +18,7 @@ package org.onosproject.net.intent.impl.phase; | ... | @@ -18,7 +18,7 @@ package org.onosproject.net.intent.impl.phase; |
18 | import org.onosproject.net.flow.FlowRuleOperations; | 18 | import org.onosproject.net.flow.FlowRuleOperations; |
19 | import org.onosproject.net.intent.IntentData; | 19 | import org.onosproject.net.intent.IntentData; |
20 | import org.onosproject.net.intent.IntentException; | 20 | import org.onosproject.net.intent.IntentException; |
21 | -import org.onosproject.net.intent.impl.IntentManager; | 21 | +import org.onosproject.net.intent.impl.IntentProcessor; |
22 | import org.slf4j.Logger; | 22 | import org.slf4j.Logger; |
23 | import org.slf4j.LoggerFactory; | 23 | import org.slf4j.LoggerFactory; |
24 | 24 | ||
... | @@ -34,13 +34,13 @@ final class InstallCoordinating implements IntentProcessPhase { | ... | @@ -34,13 +34,13 @@ final class InstallCoordinating implements IntentProcessPhase { |
34 | 34 | ||
35 | private static final Logger log = LoggerFactory.getLogger(InstallCoordinating.class); | 35 | private static final Logger log = LoggerFactory.getLogger(InstallCoordinating.class); |
36 | 36 | ||
37 | - private final IntentManager intentManager; | 37 | + private final IntentProcessor processor; |
38 | private final IntentData pending; | 38 | private final IntentData pending; |
39 | private final IntentData current; | 39 | private final IntentData current; |
40 | 40 | ||
41 | // TODO: define an interface and use it, instead of IntentManager | 41 | // TODO: define an interface and use it, instead of IntentManager |
42 | - InstallCoordinating(IntentManager intentManager, IntentData pending, IntentData current) { | 42 | + InstallCoordinating(IntentProcessor processor, IntentData pending, IntentData current) { |
43 | - this.intentManager = checkNotNull(intentManager); | 43 | + this.processor = checkNotNull(processor); |
44 | this.pending = checkNotNull(pending); | 44 | this.pending = checkNotNull(pending); |
45 | this.current = current; | 45 | this.current = current; |
46 | } | 46 | } |
... | @@ -50,8 +50,8 @@ final class InstallCoordinating implements IntentProcessPhase { | ... | @@ -50,8 +50,8 @@ final class InstallCoordinating implements IntentProcessPhase { |
50 | try { | 50 | try { |
51 | //FIXME we orphan flow rules that are currently on the data plane | 51 | //FIXME we orphan flow rules that are currently on the data plane |
52 | // ... should either reuse them or remove them | 52 | // ... should either reuse them or remove them |
53 | - FlowRuleOperations flowRules = intentManager.coordinate(current, pending); | 53 | + FlowRuleOperations flowRules = processor.coordinate(current, pending); |
54 | - return Optional.of(new Installing(intentManager, pending, flowRules)); | 54 | + return Optional.of(new Installing(processor, pending, flowRules)); |
55 | } catch (IntentException e) { | 55 | } catch (IntentException e) { |
56 | log.warn("Unable to generate a FlowRuleOperations from intent {} due to:", pending.intent().id(), e); | 56 | log.warn("Unable to generate a FlowRuleOperations from intent {} due to:", pending.intent().id(), e); |
57 | return Optional.of(new InstallingFailed(pending)); | 57 | return Optional.of(new InstallingFailed(pending)); | ... | ... |
... | @@ -16,7 +16,7 @@ | ... | @@ -16,7 +16,7 @@ |
16 | package org.onosproject.net.intent.impl.phase; | 16 | package org.onosproject.net.intent.impl.phase; |
17 | 17 | ||
18 | import org.onosproject.net.intent.IntentData; | 18 | import org.onosproject.net.intent.IntentData; |
19 | -import org.onosproject.net.intent.impl.IntentManager; | 19 | +import org.onosproject.net.intent.impl.IntentProcessor; |
20 | 20 | ||
21 | import java.util.Optional; | 21 | import java.util.Optional; |
22 | 22 | ||
... | @@ -27,13 +27,12 @@ import static com.google.common.base.Preconditions.checkNotNull; | ... | @@ -27,13 +27,12 @@ import static com.google.common.base.Preconditions.checkNotNull; |
27 | */ | 27 | */ |
28 | public final class InstallRequest implements IntentProcessPhase { | 28 | public final class InstallRequest implements IntentProcessPhase { |
29 | 29 | ||
30 | - // TODO: define an interface and use it, instead of IntentManager | 30 | + private final IntentProcessor intentManager; |
31 | - private final IntentManager intentManager; | ||
32 | private final IntentData pending; | 31 | private final IntentData pending; |
33 | private final Optional<IntentData> current; | 32 | private final Optional<IntentData> current; |
34 | 33 | ||
35 | - public InstallRequest(IntentManager intentManager, IntentData intentData, Optional<IntentData> current) { | 34 | + public InstallRequest(IntentProcessor processor, IntentData intentData, Optional<IntentData> current) { |
36 | - this.intentManager = checkNotNull(intentManager); | 35 | + this.intentManager = checkNotNull(processor); |
37 | this.pending = checkNotNull(intentData); | 36 | this.pending = checkNotNull(intentData); |
38 | this.current = checkNotNull(current); | 37 | this.current = checkNotNull(current); |
39 | } | 38 | } | ... | ... |
... | @@ -18,7 +18,7 @@ package org.onosproject.net.intent.impl.phase; | ... | @@ -18,7 +18,7 @@ package org.onosproject.net.intent.impl.phase; |
18 | import org.onosproject.net.flow.FlowRuleOperations; | 18 | import org.onosproject.net.flow.FlowRuleOperations; |
19 | import org.onosproject.net.intent.IntentData; | 19 | import org.onosproject.net.intent.IntentData; |
20 | import org.onosproject.net.intent.IntentException; | 20 | import org.onosproject.net.intent.IntentException; |
21 | -import org.onosproject.net.intent.impl.IntentManager; | 21 | +import org.onosproject.net.intent.impl.IntentProcessor; |
22 | import org.slf4j.Logger; | 22 | import org.slf4j.Logger; |
23 | import org.slf4j.LoggerFactory; | 23 | import org.slf4j.LoggerFactory; |
24 | 24 | ||
... | @@ -34,13 +34,12 @@ final class Installing implements IntentProcessPhase { | ... | @@ -34,13 +34,12 @@ final class Installing implements IntentProcessPhase { |
34 | 34 | ||
35 | private static final Logger log = LoggerFactory.getLogger(Installing.class); | 35 | private static final Logger log = LoggerFactory.getLogger(Installing.class); |
36 | 36 | ||
37 | - private final IntentManager intentManager; | 37 | + private final IntentProcessor processor; |
38 | private final IntentData pending; | 38 | private final IntentData pending; |
39 | private final FlowRuleOperations flowRules; | 39 | private final FlowRuleOperations flowRules; |
40 | 40 | ||
41 | - // TODO: define an interface and use it, instead of IntentManager | 41 | + Installing(IntentProcessor processor, IntentData pending, FlowRuleOperations flowRules) { |
42 | - Installing(IntentManager intentManager, IntentData pending, FlowRuleOperations flowRules) { | 42 | + this.processor = checkNotNull(processor); |
43 | - this.intentManager = checkNotNull(intentManager); | ||
44 | this.pending = checkNotNull(pending); | 43 | this.pending = checkNotNull(pending); |
45 | this.flowRules = flowRules; | 44 | this.flowRules = flowRules; |
46 | } | 45 | } |
... | @@ -48,7 +47,7 @@ final class Installing implements IntentProcessPhase { | ... | @@ -48,7 +47,7 @@ final class Installing implements IntentProcessPhase { |
48 | @Override | 47 | @Override |
49 | public Optional<IntentProcessPhase> execute() { | 48 | public Optional<IntentProcessPhase> execute() { |
50 | try { | 49 | try { |
51 | - intentManager.flowRuleService.apply(flowRules); // FIXME we need to provide a context | 50 | + processor.applyFlowRules(flowRules); |
52 | return Optional.of(new Installed(pending)); | 51 | return Optional.of(new Installed(pending)); |
53 | // What kinds of exceptions are thrown by FlowRuleService.apply()? | 52 | // What kinds of exceptions are thrown by FlowRuleService.apply()? |
54 | // Is IntentException a correct exception abstraction? | 53 | // Is IntentException a correct exception abstraction? | ... | ... |
... | @@ -18,7 +18,7 @@ package org.onosproject.net.intent.impl.phase; | ... | @@ -18,7 +18,7 @@ package org.onosproject.net.intent.impl.phase; |
18 | import org.onosproject.net.flow.FlowRuleOperations; | 18 | import org.onosproject.net.flow.FlowRuleOperations; |
19 | import org.onosproject.net.intent.IntentData; | 19 | import org.onosproject.net.intent.IntentData; |
20 | import org.onosproject.net.intent.IntentException; | 20 | import org.onosproject.net.intent.IntentException; |
21 | -import org.onosproject.net.intent.impl.IntentManager; | 21 | +import org.onosproject.net.intent.impl.IntentProcessor; |
22 | import org.slf4j.Logger; | 22 | import org.slf4j.Logger; |
23 | import org.slf4j.LoggerFactory; | 23 | import org.slf4j.LoggerFactory; |
24 | 24 | ||
... | @@ -34,13 +34,12 @@ final class WithdrawCoordinating implements IntentProcessPhase { | ... | @@ -34,13 +34,12 @@ final class WithdrawCoordinating implements IntentProcessPhase { |
34 | 34 | ||
35 | private static final Logger log = LoggerFactory.getLogger(WithdrawCoordinating.class); | 35 | private static final Logger log = LoggerFactory.getLogger(WithdrawCoordinating.class); |
36 | 36 | ||
37 | - // TODO: define an interface and use it, instead of IntentManager | 37 | + private final IntentProcessor processor; |
38 | - private final IntentManager intentManager; | ||
39 | private final IntentData pending; | 38 | private final IntentData pending; |
40 | private final IntentData current; | 39 | private final IntentData current; |
41 | 40 | ||
42 | - WithdrawCoordinating(IntentManager intentManager, IntentData pending, IntentData current) { | 41 | + WithdrawCoordinating(IntentProcessor processor, IntentData pending, IntentData current) { |
43 | - this.intentManager = checkNotNull(intentManager); | 42 | + this.processor = checkNotNull(processor); |
44 | this.pending = checkNotNull(pending); | 43 | this.pending = checkNotNull(pending); |
45 | this.current = checkNotNull(current); | 44 | this.current = checkNotNull(current); |
46 | } | 45 | } |
... | @@ -49,9 +48,9 @@ final class WithdrawCoordinating implements IntentProcessPhase { | ... | @@ -49,9 +48,9 @@ final class WithdrawCoordinating implements IntentProcessPhase { |
49 | public Optional<IntentProcessPhase> execute() { | 48 | public Optional<IntentProcessPhase> execute() { |
50 | try { | 49 | try { |
51 | // Note: current.installables() are not null or empty due to createIntentUpdate check | 50 | // Note: current.installables() are not null or empty due to createIntentUpdate check |
52 | - FlowRuleOperations flowRules = intentManager.uninstallCoordinate(current, pending); | 51 | + FlowRuleOperations flowRules = processor.uninstallCoordinate(current, pending); |
53 | pending.setInstallables(current.installables()); | 52 | pending.setInstallables(current.installables()); |
54 | - return Optional.of(new Withdrawing(intentManager, pending, flowRules)); | 53 | + return Optional.of(new Withdrawing(processor, pending, flowRules)); |
55 | } catch (IntentException e) { | 54 | } catch (IntentException e) { |
56 | log.warn("Unable to generate generate a FlowRuleOperations from intent {} due to:", pending.intent(), e); | 55 | log.warn("Unable to generate generate a FlowRuleOperations from intent {} due to:", pending.intent(), e); |
57 | return Optional.of(new WithdrawingFailed(pending)); | 56 | return Optional.of(new WithdrawingFailed(pending)); | ... | ... |
... | @@ -16,7 +16,7 @@ | ... | @@ -16,7 +16,7 @@ |
16 | package org.onosproject.net.intent.impl.phase; | 16 | package org.onosproject.net.intent.impl.phase; |
17 | 17 | ||
18 | import org.onosproject.net.intent.IntentData; | 18 | import org.onosproject.net.intent.IntentData; |
19 | -import org.onosproject.net.intent.impl.IntentManager; | 19 | +import org.onosproject.net.intent.impl.IntentProcessor; |
20 | 20 | ||
21 | import java.util.Optional; | 21 | import java.util.Optional; |
22 | 22 | ||
... | @@ -27,13 +27,12 @@ import static com.google.common.base.Preconditions.checkNotNull; | ... | @@ -27,13 +27,12 @@ import static com.google.common.base.Preconditions.checkNotNull; |
27 | */ | 27 | */ |
28 | public final class WithdrawRequest implements IntentProcessPhase { | 28 | public final class WithdrawRequest implements IntentProcessPhase { |
29 | 29 | ||
30 | - // TODO: define an interface and use it, instead of IntentManager | 30 | + private final IntentProcessor processor; |
31 | - private final IntentManager intentManager; | ||
32 | private final IntentData pending; | 31 | private final IntentData pending; |
33 | private final IntentData current; | 32 | private final IntentData current; |
34 | 33 | ||
35 | - public WithdrawRequest(IntentManager intentManager, IntentData intentData, IntentData current) { | 34 | + public WithdrawRequest(IntentProcessor processor, IntentData intentData, IntentData current) { |
36 | - this.intentManager = checkNotNull(intentManager); | 35 | + this.processor = checkNotNull(processor); |
37 | this.pending = checkNotNull(intentData); | 36 | this.pending = checkNotNull(intentData); |
38 | this.current = checkNotNull(current); | 37 | this.current = checkNotNull(current); |
39 | } | 38 | } |
... | @@ -43,6 +42,6 @@ public final class WithdrawRequest implements IntentProcessPhase { | ... | @@ -43,6 +42,6 @@ public final class WithdrawRequest implements IntentProcessPhase { |
43 | //TODO perhaps we want to validate that the pending and current are the | 42 | //TODO perhaps we want to validate that the pending and current are the |
44 | // same version i.e. they are the same | 43 | // same version i.e. they are the same |
45 | // Note: this call is not just the symmetric version of submit | 44 | // Note: this call is not just the symmetric version of submit |
46 | - return Optional.of(new WithdrawCoordinating(intentManager, pending, current)); | 45 | + return Optional.of(new WithdrawCoordinating(processor, pending, current)); |
47 | } | 46 | } |
48 | } | 47 | } | ... | ... |
... | @@ -17,7 +17,7 @@ package org.onosproject.net.intent.impl.phase; | ... | @@ -17,7 +17,7 @@ package org.onosproject.net.intent.impl.phase; |
17 | 17 | ||
18 | import org.onosproject.net.flow.FlowRuleOperations; | 18 | import org.onosproject.net.flow.FlowRuleOperations; |
19 | import org.onosproject.net.intent.IntentData; | 19 | import org.onosproject.net.intent.IntentData; |
20 | -import org.onosproject.net.intent.impl.IntentManager; | 20 | +import org.onosproject.net.intent.impl.IntentProcessor; |
21 | 21 | ||
22 | import java.util.Optional; | 22 | import java.util.Optional; |
23 | 23 | ||
... | @@ -29,20 +29,19 @@ import static com.google.common.base.Preconditions.checkNotNull; | ... | @@ -29,20 +29,19 @@ import static com.google.common.base.Preconditions.checkNotNull; |
29 | */ | 29 | */ |
30 | class Withdrawing implements IntentProcessPhase { | 30 | class Withdrawing implements IntentProcessPhase { |
31 | 31 | ||
32 | - // TODO: define an interface and use it, instead of IntentManager | 32 | + private final IntentProcessor processor; |
33 | - private final IntentManager intentManager; | ||
34 | private final IntentData pending; | 33 | private final IntentData pending; |
35 | private final FlowRuleOperations flowRules; | 34 | private final FlowRuleOperations flowRules; |
36 | 35 | ||
37 | - Withdrawing(IntentManager intentManager, IntentData pending, FlowRuleOperations flowRules) { | 36 | + Withdrawing(IntentProcessor processor, IntentData pending, FlowRuleOperations flowRules) { |
38 | - this.intentManager = checkNotNull(intentManager); | 37 | + this.processor = checkNotNull(processor); |
39 | this.pending = checkNotNull(pending); | 38 | this.pending = checkNotNull(pending); |
40 | this.flowRules = checkNotNull(flowRules); | 39 | this.flowRules = checkNotNull(flowRules); |
41 | } | 40 | } |
42 | 41 | ||
43 | @Override | 42 | @Override |
44 | public Optional<IntentProcessPhase> execute() { | 43 | public Optional<IntentProcessPhase> execute() { |
45 | - intentManager.flowRuleService.apply(flowRules); | 44 | + processor.applyFlowRules(flowRules); |
46 | return Optional.of(new Withdrawn(pending)); | 45 | return Optional.of(new Withdrawn(pending)); |
47 | } | 46 | } |
48 | } | 47 | } | ... | ... |
-
Please register or login to post a comment