Brian O'Connor

Refactored intermediate IntentUpdate classes

Change-Id: I3d4a435ef4aa97559d5407d49f45519098c3f193
...@@ -15,7 +15,10 @@ ...@@ -15,7 +15,10 @@
15 */ 15 */
16 package org.onosproject.net.intent; 16 package org.onosproject.net.intent;
17 17
18 +import org.onosproject.net.flow.FlowRule;
19 +import org.onosproject.net.flow.FlowRuleBatchEntry;
18 import org.onosproject.net.flow.FlowRuleBatchOperation; 20 import org.onosproject.net.flow.FlowRuleBatchOperation;
21 +import org.onosproject.net.flow.FlowRuleOperations;
19 22
20 import java.util.List; 23 import java.util.List;
21 24
...@@ -30,7 +33,32 @@ public interface IntentInstaller<T extends Intent> { ...@@ -30,7 +33,32 @@ public interface IntentInstaller<T extends Intent> {
30 * @return flow rule operations to complete install 33 * @return flow rule operations to complete install
31 * @throws IntentException if issues are encountered while installing the intent 34 * @throws IntentException if issues are encountered while installing the intent
32 */ 35 */
36 + @Deprecated
33 List<FlowRuleBatchOperation> install(T intent); 37 List<FlowRuleBatchOperation> install(T intent);
38 + // FIXME
39 + default FlowRuleOperations.Builder install2(T intent) {
40 + FlowRuleOperations.Builder builder = FlowRuleOperations.builder();
41 + for (FlowRuleBatchOperation batch : install(intent)) {
42 + for (FlowRuleBatchEntry entry : batch.getOperations()) {
43 + FlowRule rule = entry.target();
44 + switch (entry.operator()) {
45 + case ADD:
46 + builder.add(rule);
47 + break;
48 + case REMOVE:
49 + builder.remove(rule);
50 + break;
51 + case MODIFY:
52 + builder.modify(rule);
53 + break;
54 + default:
55 + break;
56 + }
57 + }
58 + builder.newStage();
59 + }
60 + return builder;
61 + }
34 62
35 /** 63 /**
36 * Uninstalls the specified intent from the environment. 64 * Uninstalls the specified intent from the environment.
...@@ -39,7 +67,32 @@ public interface IntentInstaller<T extends Intent> { ...@@ -39,7 +67,32 @@ public interface IntentInstaller<T extends Intent> {
39 * @return flow rule operations to complete uninstall 67 * @return flow rule operations to complete uninstall
40 * @throws IntentException if issues are encountered while uninstalling the intent 68 * @throws IntentException if issues are encountered while uninstalling the intent
41 */ 69 */
70 + @Deprecated
42 List<FlowRuleBatchOperation> uninstall(T intent); 71 List<FlowRuleBatchOperation> uninstall(T intent);
72 + // FIXME
73 + default FlowRuleOperations.Builder uninstall2(T intent) {
74 + FlowRuleOperations.Builder builder = FlowRuleOperations.builder();
75 + for (FlowRuleBatchOperation batch : uninstall(intent)) {
76 + for (FlowRuleBatchEntry entry : batch.getOperations()) {
77 + FlowRule rule = entry.target();
78 + switch (entry.operator()) {
79 + case ADD:
80 + builder.add(rule);
81 + break;
82 + case REMOVE:
83 + builder.remove(rule);
84 + break;
85 + case MODIFY:
86 + builder.modify(rule);
87 + break;
88 + default:
89 + break;
90 + }
91 + }
92 + builder.newStage();
93 + }
94 + return builder;
95 + }
43 96
44 /** 97 /**
45 * Replaces the specified intent with a new one in the environment. 98 * Replaces the specified intent with a new one in the environment.
...@@ -49,6 +102,31 @@ public interface IntentInstaller<T extends Intent> { ...@@ -49,6 +102,31 @@ public interface IntentInstaller<T extends Intent> {
49 * @return flow rule operations to complete the replace 102 * @return flow rule operations to complete the replace
50 * @throws IntentException if issues are encountered while uninstalling the intent 103 * @throws IntentException if issues are encountered while uninstalling the intent
51 */ 104 */
105 + @Deprecated
52 List<FlowRuleBatchOperation> replace(T oldIntent, T newIntent); 106 List<FlowRuleBatchOperation> replace(T oldIntent, T newIntent);
107 + // FIXME
108 + default FlowRuleOperations.Builder replace2(T oldIntent, T newIntent) {
109 + FlowRuleOperations.Builder builder = FlowRuleOperations.builder();
110 + for (FlowRuleBatchOperation batch : replace(oldIntent, newIntent)) {
111 + for (FlowRuleBatchEntry entry : batch.getOperations()) {
112 + FlowRule rule = entry.target();
113 + switch (entry.operator()) {
114 + case ADD:
115 + builder.add(rule);
116 + break;
117 + case REMOVE:
118 + builder.remove(rule);
119 + break;
120 + case MODIFY:
121 + builder.modify(rule);
122 + break;
123 + default:
124 + break;
125 + }
126 + }
127 + builder.newStage();
128 + }
129 + return builder;
130 + }
53 131
54 } 132 }
......
...@@ -16,10 +16,12 @@ ...@@ -16,10 +16,12 @@
16 package org.onosproject.net.intent.impl; 16 package org.onosproject.net.intent.impl;
17 17
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.IntentException; 20 import org.onosproject.net.intent.IntentException;
20 import org.slf4j.Logger; 21 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory; 22 import org.slf4j.LoggerFactory;
22 23
24 +import java.util.List;
23 import java.util.Optional; 25 import java.util.Optional;
24 26
25 import static com.google.common.base.Preconditions.checkNotNull; 27 import static com.google.common.base.Preconditions.checkNotNull;
...@@ -30,25 +32,29 @@ class Compiling implements IntentUpdate { ...@@ -30,25 +32,29 @@ class Compiling implements IntentUpdate {
30 32
31 // TODO: define an interface and use it, instead of IntentManager 33 // TODO: define an interface and use it, instead of IntentManager
32 private final IntentManager intentManager; 34 private final IntentManager intentManager;
33 - private final Intent intent; 35 + private final IntentData pending;
36 + private final IntentData current;
34 37
35 - Compiling(IntentManager intentManager, Intent intent) { 38 + Compiling(IntentManager intentManager, IntentData pending, IntentData current) {
36 this.intentManager = checkNotNull(intentManager); 39 this.intentManager = checkNotNull(intentManager);
37 - this.intent = checkNotNull(intent); 40 + this.pending = checkNotNull(pending);
41 + this.current = current;
38 } 42 }
39 43
40 @Override 44 @Override
41 public Optional<IntentUpdate> execute() { 45 public Optional<IntentUpdate> execute() {
42 try { 46 try {
43 - return Optional.of(new Installing(intentManager, intent, intentManager.compileIntent(intent, null))); 47 + List<Intent> installables = (current != null) ? current.installables() : null;
48 + pending.setInstallables(intentManager.compileIntent(pending.intent(), installables));
49 + return Optional.of(new Installing(intentManager, pending, current));
44 } catch (PathNotFoundException e) { 50 } catch (PathNotFoundException e) {
45 - log.debug("Path not found for intent {}", intent); 51 + log.debug("Path not found for intent {}", pending.intent());
46 // TODO: revisit to implement failure handling 52 // TODO: revisit to implement failure handling
47 - return Optional.of(new DoNothing()); 53 + return Optional.of(new CompilingFailed(pending)); //FIXME failed state transition
48 } catch (IntentException e) { 54 } catch (IntentException e) {
49 - log.warn("Unable to compile intent {} due to:", intent.id(), e); 55 + log.warn("Unable to compile intent {} due to:", pending.intent().id(), e);
50 // TODO: revisit to implement failure handling 56 // TODO: revisit to implement failure handling
51 - return Optional.of(new DoNothing()); 57 + return Optional.of(new CompilingFailed(pending)); //FIXME failed state transition
52 } 58 }
53 } 59 }
54 } 60 }
......
...@@ -15,8 +15,26 @@ ...@@ -15,8 +15,26 @@
15 */ 15 */
16 package org.onosproject.net.intent.impl; 16 package org.onosproject.net.intent.impl;
17 17
18 +import org.onosproject.net.intent.IntentData;
19 +
20 +import static org.onosproject.net.intent.IntentState.FAILED;
21 +
18 /** 22 /**
19 - * Represents a phase doing nothing. 23 + * Represents a phase where the compile has failed.
20 */ 24 */
21 -class DoNothing implements CompletedIntentUpdate { 25 +class CompilingFailed implements CompletedIntentUpdate {
26 +
27 + private final IntentData intentData;
28 +
29 + CompilingFailed(IntentData intentData) {
30 + this.intentData = intentData;
31 + this.intentData.setState(FAILED);
32 + }
33 +
34 + @Override
35 + public IntentData data() {
36 + return intentData;
37 + }
38 +
39 + //FIXME we also need to decide what to do with the current intent's resources i.e. cleanup or revert
22 } 40 }
......
...@@ -15,11 +15,8 @@ ...@@ -15,11 +15,8 @@
15 */ 15 */
16 package org.onosproject.net.intent.impl; 16 package org.onosproject.net.intent.impl;
17 17
18 -import org.onosproject.net.flow.FlowRuleBatchOperation; 18 +import org.onosproject.net.intent.IntentData;
19 -import org.onosproject.net.intent.Intent;
20 19
21 -import java.util.Collections;
22 -import java.util.List;
23 import java.util.Optional; 20 import java.util.Optional;
24 21
25 /** 22 /**
...@@ -27,38 +24,10 @@ import java.util.Optional; ...@@ -27,38 +24,10 @@ import java.util.Optional;
27 */ 24 */
28 interface CompletedIntentUpdate extends IntentUpdate { 25 interface CompletedIntentUpdate extends IntentUpdate {
29 26
30 - /**
31 - * Moves forward with the contained current batch.
32 - * This method is invoked when the batch is successfully completed.
33 - */
34 - default void batchSuccess() {}
35 -
36 - /**
37 - * Reverts the contained batches.
38 - * This method is invoked when the batch results in failure.
39 - */
40 - default void batchFailed() {}
41 -
42 - /**
43 - * Returns the current FlowRuleBatchOperation.
44 - *
45 - * @return current FlowRuleBatchOperation
46 - */
47 - default FlowRuleBatchOperation currentBatch() {
48 - return null;
49 - }
50 -
51 - /**
52 - * Returns all of installable intents this instance holds.
53 - *
54 - * @return all of installable intents
55 - */
56 - default List<Intent> allInstallables() {
57 - return Collections.emptyList();
58 - }
59 -
60 @Override 27 @Override
61 default Optional<IntentUpdate> execute() { 28 default Optional<IntentUpdate> execute() {
62 return Optional.empty(); 29 return Optional.empty();
63 } 30 }
31 +
32 + IntentData data();
64 } 33 }
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
15 */ 15 */
16 package org.onosproject.net.intent.impl; 16 package org.onosproject.net.intent.impl;
17 17
18 -import org.onosproject.net.intent.Intent;
19 import org.onosproject.net.intent.IntentData; 18 import org.onosproject.net.intent.IntentData;
20 19
21 import java.util.Optional; 20 import java.util.Optional;
...@@ -27,17 +26,17 @@ class InstallRequest implements IntentUpdate { ...@@ -27,17 +26,17 @@ class InstallRequest implements IntentUpdate {
27 26
28 // TODO: define an interface and use it, instead of IntentManager 27 // TODO: define an interface and use it, instead of IntentManager
29 private final IntentManager intentManager; 28 private final IntentManager intentManager;
30 - private final Intent intent; 29 + private final IntentData pending;
31 - private final IntentData currentState;
32 30
33 - InstallRequest(IntentManager intentManager, Intent intent, IntentData currentState) { 31 + InstallRequest(IntentManager intentManager, IntentData intentData) {
34 this.intentManager = checkNotNull(intentManager); 32 this.intentManager = checkNotNull(intentManager);
35 - this.intent = checkNotNull(intent); 33 + this.pending = checkNotNull(intentData);
36 - this.currentState = currentState;
37 } 34 }
38 35
39 @Override 36 @Override
40 public Optional<IntentUpdate> execute() { 37 public Optional<IntentUpdate> execute() {
41 - return Optional.of(new Compiling(intentManager, intent)); //FIXME 38 + //FIXME... store hack
39 + IntentData current = intentManager.store.getIntentData(pending.key());
40 + return Optional.of(new Compiling(intentManager, pending, current));
42 } 41 }
43 } 42 }
......
...@@ -15,60 +15,21 @@ ...@@ -15,60 +15,21 @@
15 */ 15 */
16 package org.onosproject.net.intent.impl; 16 package org.onosproject.net.intent.impl;
17 17
18 -import com.google.common.collect.ImmutableList; 18 +import org.onosproject.net.intent.IntentData;
19 -import org.onosproject.net.flow.FlowRuleBatchOperation;
20 -import org.onosproject.net.intent.Intent;
21 -import org.onosproject.net.intent.IntentState;
22 -
23 -import java.util.LinkedList;
24 -import java.util.List;
25 19
26 import static com.google.common.base.Preconditions.checkNotNull; 20 import static com.google.common.base.Preconditions.checkNotNull;
27 -import static org.onosproject.net.intent.IntentState.FAILED;
28 import static org.onosproject.net.intent.IntentState.INSTALLING; 21 import static org.onosproject.net.intent.IntentState.INSTALLING;
29 22
30 class Installed implements CompletedIntentUpdate { 23 class Installed implements CompletedIntentUpdate {
31 24
32 - // TODO: define an interface and use it, instead of IntentManager 25 + private final IntentData intentData;
33 - private final IntentManager intentManager;
34 - private final Intent intent;
35 - private final List<Intent> installables;
36 - private IntentState intentState;
37 - private final List<FlowRuleBatchOperation> batches;
38 - private int currentBatch = 0;
39 -
40 - Installed(IntentManager intentManager,
41 - Intent intent, List<Intent> installables, List<FlowRuleBatchOperation> batches) {
42 - this.intentManager = checkNotNull(intentManager);
43 - this.intent = checkNotNull(intent);
44 - this.installables = ImmutableList.copyOf(checkNotNull(installables));
45 - this.batches = new LinkedList<>(checkNotNull(batches));
46 - this.intentState = INSTALLING;
47 - }
48 -
49 - @Override
50 - public void batchSuccess() {
51 - currentBatch++;
52 - }
53 -
54 - @Override
55 - public List<Intent> allInstallables() {
56 - return installables;
57 - }
58 26
59 - @Override 27 + Installed(IntentData intentData) {
60 - public FlowRuleBatchOperation currentBatch() { 28 + this.intentData = checkNotNull(intentData);
61 - return currentBatch < batches.size() ? batches.get(currentBatch) : null; 29 + this.intentData.setState(INSTALLING);
62 } 30 }
63 31
64 - @Override 32 + public IntentData data() {
65 - public void batchFailed() { 33 + return intentData;
66 - for (int i = batches.size() - 1; i >= currentBatch; i--) {
67 - batches.remove(i);
68 - }
69 - intentState = FAILED;
70 - batches.addAll(intentManager.uninstallIntent(intent, installables));
71 -
72 - // TODO we might want to try to recompile the new intent
73 } 34 }
74 } 35 }
......
...@@ -15,13 +15,11 @@ ...@@ -15,13 +15,11 @@
15 */ 15 */
16 package org.onosproject.net.intent.impl; 16 package org.onosproject.net.intent.impl;
17 17
18 -import com.google.common.collect.ImmutableList; 18 +import org.onosproject.net.flow.FlowRuleOperations;
19 -import org.onosproject.net.flow.FlowRuleBatchOperation; 19 +import org.onosproject.net.intent.IntentData;
20 -import org.onosproject.net.intent.Intent;
21 import org.slf4j.Logger; 20 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory; 21 import org.slf4j.LoggerFactory;
23 22
24 -import java.util.List;
25 import java.util.Optional; 23 import java.util.Optional;
26 24
27 import static com.google.common.base.Preconditions.checkNotNull; 25 import static com.google.common.base.Preconditions.checkNotNull;
...@@ -32,26 +30,27 @@ class Installing implements IntentUpdate { ...@@ -32,26 +30,27 @@ class Installing implements IntentUpdate {
32 private static final Logger log = LoggerFactory.getLogger(Installing.class); 30 private static final Logger log = LoggerFactory.getLogger(Installing.class);
33 31
34 private final IntentManager intentManager; 32 private final IntentManager intentManager;
35 - private final Intent intent; 33 + private final IntentData pending;
36 - private final List<Intent> installables; 34 + private final IntentData current;
37 35
38 // TODO: define an interface and use it, instead of IntentManager 36 // TODO: define an interface and use it, instead of IntentManager
39 - Installing(IntentManager intentManager, Intent intent, List<Intent> installables) { 37 + Installing(IntentManager intentManager, IntentData pending, IntentData current) {
40 this.intentManager = checkNotNull(intentManager); 38 this.intentManager = checkNotNull(intentManager);
41 - this.intent = checkNotNull(intent); 39 + this.pending = checkNotNull(pending);
42 - this.installables = ImmutableList.copyOf(checkNotNull(installables)); 40 + this.current = current;
43 } 41 }
44 42
45 @Override 43 @Override
46 public Optional<IntentUpdate> execute() { 44 public Optional<IntentUpdate> execute() {
47 try { 45 try {
48 - List<FlowRuleBatchOperation> converted = intentManager.convert(installables); 46 + FlowRuleOperations flowRules = intentManager.coordinate(pending.installables());
49 // TODO: call FlowRuleService API to push FlowRules and track resources, 47 // TODO: call FlowRuleService API to push FlowRules and track resources,
50 // which the submitted intent will use. 48 // which the submitted intent will use.
51 - return Optional.of(new Installed(intentManager, intent, installables, converted)); 49 + intentManager.flowRuleService.apply(flowRules);
50 + return Optional.of(new Installed(pending));
52 } catch (FlowRuleBatchOperationConversionException e) { 51 } catch (FlowRuleBatchOperationConversionException e) {
53 - log.warn("Unable to install intent {} due to:", intent.id(), e.getCause()); 52 + log.warn("Unable to install intent {} due to:", pending.intent().id(), e.getCause());
54 - return Optional.of(new InstallingFailed(intentManager, intent, installables, e.converted())); 53 + return Optional.of(new InstallingFailed(pending));
55 } 54 }
56 } 55 }
57 } 56 }
......
...@@ -15,53 +15,23 @@ ...@@ -15,53 +15,23 @@
15 */ 15 */
16 package org.onosproject.net.intent.impl; 16 package org.onosproject.net.intent.impl;
17 17
18 -import com.google.common.collect.ImmutableList; 18 +import org.onosproject.net.intent.IntentData;
19 -import org.onosproject.net.flow.FlowRuleBatchOperation;
20 -import org.onosproject.net.intent.Intent;
21 -
22 -import java.util.LinkedList;
23 -import java.util.List;
24 19
25 import static com.google.common.base.Preconditions.checkNotNull; 20 import static com.google.common.base.Preconditions.checkNotNull;
21 +import static org.onosproject.net.intent.IntentState.FAILED;
26 22
27 class InstallingFailed implements CompletedIntentUpdate { 23 class InstallingFailed implements CompletedIntentUpdate {
28 24
29 - private IntentManager intentManager; 25 + private final IntentData intentData;
30 - private final Intent intent;
31 - private final List<Intent> installables;
32 - private final List<FlowRuleBatchOperation> batches;
33 - private int currentBatch = 0;
34 -
35 - InstallingFailed(IntentManager intentManager,
36 - Intent intent, List<Intent> installables, List<FlowRuleBatchOperation> batches) {
37 - this.intentManager = intentManager;
38 - this.intent = checkNotNull(intent);
39 - this.installables = ImmutableList.copyOf(checkNotNull(installables));
40 - this.batches = new LinkedList<>(checkNotNull(batches));
41 - }
42 26
43 - @Override 27 + InstallingFailed(IntentData intentData) {
44 - public List<Intent> allInstallables() { 28 + this.intentData = checkNotNull(intentData);
45 - return installables; 29 + this.intentData.setState(FAILED); //FIXME maybe should be "BROKEN"
30 + //TODO consider adding the flow rule operations here
46 } 31 }
47 32
48 @Override 33 @Override
49 - public void batchSuccess() { 34 + public IntentData data() {
50 - currentBatch++; 35 + return intentData;
51 - }
52 -
53 - @Override
54 - public FlowRuleBatchOperation currentBatch() {
55 - return currentBatch < batches.size() ? batches.get(currentBatch) : null;
56 - }
57 -
58 - @Override
59 - public void batchFailed() {
60 - for (int i = batches.size() - 1; i >= currentBatch; i--) {
61 - batches.remove(i);
62 - }
63 - batches.addAll(intentManager.uninstallIntent(intent, installables));
64 -
65 - // TODO we might want to try to recompile the new intent
66 } 36 }
67 } 37 }
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
15 */ 15 */
16 package org.onosproject.net.intent.impl; 16 package org.onosproject.net.intent.impl;
17 17
18 -import org.onosproject.net.intent.Intent;
19 import org.onosproject.net.intent.IntentData; 18 import org.onosproject.net.intent.IntentData;
20 19
21 import java.util.Optional; 20 import java.util.Optional;
...@@ -26,17 +25,20 @@ class WithdrawRequest implements IntentUpdate { ...@@ -26,17 +25,20 @@ class WithdrawRequest implements IntentUpdate {
26 25
27 // TODO: define an interface and use it, instead of IntentManager 26 // TODO: define an interface and use it, instead of IntentManager
28 private final IntentManager intentManager; 27 private final IntentManager intentManager;
29 - private final Intent intent; 28 + private final IntentData pending;
30 - private final IntentData currentState;
31 29
32 - WithdrawRequest(IntentManager intentManager, Intent intent, IntentData currentState) { 30 + WithdrawRequest(IntentManager intentManager, IntentData intentData) {
33 this.intentManager = checkNotNull(intentManager); 31 this.intentManager = checkNotNull(intentManager);
34 - this.intent = checkNotNull(intent); 32 + this.pending = checkNotNull(intentData);
35 - this.currentState = currentState;
36 } 33 }
37 34
38 @Override 35 @Override
39 public Optional<IntentUpdate> execute() { 36 public Optional<IntentUpdate> execute() {
40 - return Optional.of(new Withdrawing(intentManager, intent, currentState.installables())); //FIXME 37 + //FIXME... store hack
38 + IntentData current = intentManager.store.getIntentData(pending.key());
39 + //TODO perhaps we want to validate that the pending and current are the
40 + // same version i.e. they are the same
41 + // Note: this call is not just the symmetric version of submit
42 + return Optional.of(new Withdrawing(intentManager, pending, current));
41 } 43 }
42 } 44 }
......
...@@ -15,11 +15,9 @@ ...@@ -15,11 +15,9 @@
15 */ 15 */
16 package org.onosproject.net.intent.impl; 16 package org.onosproject.net.intent.impl;
17 17
18 -import com.google.common.collect.ImmutableList; 18 +import org.onosproject.net.flow.FlowRuleOperations;
19 -import org.onosproject.net.flow.FlowRuleBatchOperation; 19 +import org.onosproject.net.intent.IntentData;
20 -import org.onosproject.net.intent.Intent;
21 20
22 -import java.util.List;
23 import java.util.Optional; 21 import java.util.Optional;
24 22
25 import static com.google.common.base.Preconditions.checkNotNull; 23 import static com.google.common.base.Preconditions.checkNotNull;
...@@ -28,19 +26,21 @@ class Withdrawing implements IntentUpdate { ...@@ -28,19 +26,21 @@ class Withdrawing implements IntentUpdate {
28 26
29 // TODO: define an interface and use it, instead of IntentManager 27 // TODO: define an interface and use it, instead of IntentManager
30 private final IntentManager intentManager; 28 private final IntentManager intentManager;
31 - private final Intent intent; 29 + private final IntentData pending;
32 - private final List<Intent> installables; 30 + private final IntentData current;
33 31
34 - Withdrawing(IntentManager intentManager, Intent intent, List<Intent> installables) { 32 + Withdrawing(IntentManager intentManager, IntentData pending, IntentData current) {
35 this.intentManager = checkNotNull(intentManager); 33 this.intentManager = checkNotNull(intentManager);
36 - this.intent = checkNotNull(intent); 34 + this.pending = checkNotNull(pending);
37 - this.installables = ImmutableList.copyOf(installables); 35 + this.current = checkNotNull(current);
38 } 36 }
39 37
40 @Override 38 @Override
41 public Optional<IntentUpdate> execute() { 39 public Optional<IntentUpdate> execute() {
42 - List<FlowRuleBatchOperation> batches = intentManager.uninstallIntent(intent, installables); 40 + FlowRuleOperations flowRules
41 + = intentManager.uninstallIntent(current.intent(), current.installables());
42 + intentManager.flowRuleService.apply(flowRules); //FIXME
43 43
44 - return Optional.of(new Withdrawn(intentManager, intent, installables, batches)); 44 + return Optional.of(new Withdrawn(pending));
45 } 45 }
46 } 46 }
......
...@@ -15,53 +15,22 @@ ...@@ -15,53 +15,22 @@
15 */ 15 */
16 package org.onosproject.net.intent.impl; 16 package org.onosproject.net.intent.impl;
17 17
18 -import com.google.common.collect.ImmutableList; 18 +import org.onosproject.net.intent.IntentData;
19 -import org.onosproject.net.flow.FlowRuleBatchOperation;
20 -import org.onosproject.net.intent.Intent;
21 -
22 -import java.util.LinkedList;
23 -import java.util.List;
24 19
25 import static com.google.common.base.Preconditions.checkNotNull; 20 import static com.google.common.base.Preconditions.checkNotNull;
21 +import static org.onosproject.net.intent.IntentState.WITHDRAWING;
26 22
27 class Withdrawn implements CompletedIntentUpdate { 23 class Withdrawn implements CompletedIntentUpdate {
28 24
29 - // TODO: define an interface and use it, instead of IntentManager 25 + private final IntentData intentData;
30 - private final IntentManager intentManager;
31 - private final Intent intent;
32 - private final List<Intent> installables;
33 - private final List<FlowRuleBatchOperation> batches;
34 - private int currentBatch;
35 -
36 - Withdrawn(IntentManager intentManager,
37 - Intent intent, List<Intent> installables, List<FlowRuleBatchOperation> batches) {
38 - this.intentManager = checkNotNull(intentManager);
39 - this.intent = checkNotNull(intent);
40 - this.installables = ImmutableList.copyOf(installables);
41 - this.batches = new LinkedList<>(batches);
42 - this.currentBatch = 0;
43 - }
44 -
45 - @Override
46 - public List<Intent> allInstallables() {
47 - return installables;
48 - }
49 -
50 - @Override
51 - public void batchSuccess() {
52 - currentBatch++;
53 - }
54 26
55 - @Override 27 + Withdrawn(IntentData intentData) {
56 - public FlowRuleBatchOperation currentBatch() { 28 + this.intentData = checkNotNull(intentData);
57 - return currentBatch < batches.size() ? batches.get(currentBatch) : null; 29 + this.intentData.setState(WITHDRAWING);
58 } 30 }
59 31
60 @Override 32 @Override
61 - public void batchFailed() { 33 + public IntentData data() {
62 - for (int i = batches.size() - 1; i >= currentBatch; i--) { 34 + return intentData;
63 - batches.remove(i);
64 - }
65 - batches.addAll(intentManager.uninstallIntent(intent, installables));
66 } 35 }
67 } 36 }
......