Updates to Intent Manager and store interface
Change-Id: Ida612bf5d0f4abe7e81d2f307a80f989603015e7
Showing
6 changed files
with
134 additions
and
155 deletions
... | @@ -15,10 +15,11 @@ | ... | @@ -15,10 +15,11 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.intent; | 16 | package org.onosproject.net.intent; |
17 | 17 | ||
18 | +import java.util.Collection; | ||
19 | + | ||
18 | /** | 20 | /** |
19 | * Facade for receiving notifications from the intent batch service. | 21 | * Facade for receiving notifications from the intent batch service. |
20 | */ | 22 | */ |
21 | -@Deprecated | ||
22 | public interface IntentBatchDelegate { | 23 | public interface IntentBatchDelegate { |
23 | 24 | ||
24 | /** | 25 | /** |
... | @@ -26,12 +27,6 @@ public interface IntentBatchDelegate { | ... | @@ -26,12 +27,6 @@ public interface IntentBatchDelegate { |
26 | * | 27 | * |
27 | * @param operations batch of operations | 28 | * @param operations batch of operations |
28 | */ | 29 | */ |
29 | - void execute(IntentOperations operations); | 30 | + void execute(Collection<IntentData> operations); |
30 | 31 | ||
31 | - /** | ||
32 | - * Cancesl the specified batch of intent operations. | ||
33 | - * | ||
34 | - * @param operations batch of operations to be cancelled | ||
35 | - */ | ||
36 | - void cancel(IntentOperations operations); | ||
37 | } | 32 | } | ... | ... |
... | @@ -45,6 +45,7 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> { | ... | @@ -45,6 +45,7 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> { |
45 | * @param intentId intent identification | 45 | * @param intentId intent identification |
46 | * @return intent or null if not found | 46 | * @return intent or null if not found |
47 | */ | 47 | */ |
48 | + @Deprecated | ||
48 | Intent getIntent(IntentId intentId); | 49 | Intent getIntent(IntentId intentId); |
49 | 50 | ||
50 | /** | 51 | /** |
... | @@ -53,6 +54,7 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> { | ... | @@ -53,6 +54,7 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> { |
53 | * @param intentId intent identification | 54 | * @param intentId intent identification |
54 | * @return current intent state | 55 | * @return current intent state |
55 | */ | 56 | */ |
57 | + @Deprecated | ||
56 | IntentState getIntentState(IntentId intentId); | 58 | IntentState getIntentState(IntentId intentId); |
57 | 59 | ||
58 | /** | 60 | /** |
... | @@ -62,6 +64,7 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> { | ... | @@ -62,6 +64,7 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> { |
62 | * @param intentId original intent identifier | 64 | * @param intentId original intent identifier |
63 | * @return compiled installable intents | 65 | * @return compiled installable intents |
64 | */ | 66 | */ |
67 | + @Deprecated | ||
65 | List<Intent> getInstallableIntents(IntentId intentId); | 68 | List<Intent> getInstallableIntents(IntentId intentId); |
66 | 69 | ||
67 | /** | 70 | /** |
... | @@ -74,6 +77,26 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> { | ... | @@ -74,6 +77,26 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> { |
74 | List<Operation> batchWrite(BatchWrite batch); | 77 | List<Operation> batchWrite(BatchWrite batch); |
75 | 78 | ||
76 | /** | 79 | /** |
80 | + * Returns the intent with the specified identifier. | ||
81 | + * | ||
82 | + * @param key key | ||
83 | + * @return intent or null if not found | ||
84 | + */ | ||
85 | + default Intent getIntent(String key) { //FIXME remove when impl. | ||
86 | + return null; | ||
87 | + } | ||
88 | + | ||
89 | + /** | ||
90 | + * Returns the intent data object associated with the specified key. | ||
91 | + * | ||
92 | + * @param key key to look up | ||
93 | + * @return intent data object | ||
94 | + */ | ||
95 | + default IntentData getIntentData(String key) { //FIXME remove when impl. | ||
96 | + return null; | ||
97 | + } | ||
98 | + | ||
99 | + /** | ||
77 | * Adds a new operation, which should be persisted and delegated. | 100 | * Adds a new operation, which should be persisted and delegated. |
78 | * | 101 | * |
79 | * @param intent operation | 102 | * @param intent operation | ... | ... |
... | @@ -17,6 +17,7 @@ package org.onosproject.net.intent.impl; | ... | @@ -17,6 +17,7 @@ package org.onosproject.net.intent.impl; |
17 | 17 | ||
18 | import com.google.common.collect.Maps; | 18 | import com.google.common.collect.Maps; |
19 | import org.onlab.util.AbstractAccumulator; | 19 | import org.onlab.util.AbstractAccumulator; |
20 | +import org.onosproject.net.intent.IntentBatchDelegate; | ||
20 | import org.onosproject.net.intent.IntentData; | 21 | import org.onosproject.net.intent.IntentData; |
21 | 22 | ||
22 | import java.util.List; | 23 | import java.util.List; |
... | @@ -37,16 +38,20 @@ public class IntentAccumulator extends AbstractAccumulator<IntentData> { | ... | @@ -37,16 +38,20 @@ public class IntentAccumulator extends AbstractAccumulator<IntentData> { |
37 | // TODO: Convert to use HashedWheelTimer or produce a variant of that; then decide which we want to adopt | 38 | // TODO: Convert to use HashedWheelTimer or produce a variant of that; then decide which we want to adopt |
38 | private static final Timer TIMER = new Timer("intent-op-batching"); | 39 | private static final Timer TIMER = new Timer("intent-op-batching"); |
39 | 40 | ||
41 | + private final IntentBatchDelegate delegate; | ||
42 | + | ||
40 | /** | 43 | /** |
41 | * Creates an intent operation accumulator. | 44 | * Creates an intent operation accumulator. |
42 | */ | 45 | */ |
43 | - protected IntentAccumulator() { | 46 | + protected IntentAccumulator(IntentBatchDelegate delegate) { |
44 | super(TIMER, DEFAULT_MAX_EVENTS, DEFAULT_MAX_BATCH_MS, DEFAULT_MAX_IDLE_MS); | 47 | super(TIMER, DEFAULT_MAX_EVENTS, DEFAULT_MAX_BATCH_MS, DEFAULT_MAX_IDLE_MS); |
48 | + this.delegate = delegate; | ||
45 | } | 49 | } |
46 | 50 | ||
47 | @Override | 51 | @Override |
48 | public void processEvents(List<IntentData> ops) { | 52 | public void processEvents(List<IntentData> ops) { |
49 | Map<String, IntentData> opMap = reduce(ops); | 53 | Map<String, IntentData> opMap = reduce(ops); |
54 | + delegate.execute(opMap.values()); | ||
50 | // FIXME kick off the work | 55 | // FIXME kick off the work |
51 | //for (IntentData data : opMap.values()) {} | 56 | //for (IntentData data : opMap.values()) {} |
52 | } | 57 | } | ... | ... |
... | @@ -33,9 +33,9 @@ import org.onosproject.event.EventDeliveryService; | ... | @@ -33,9 +33,9 @@ import org.onosproject.event.EventDeliveryService; |
33 | import org.onosproject.net.flow.CompletedBatchOperation; | 33 | import org.onosproject.net.flow.CompletedBatchOperation; |
34 | import org.onosproject.net.flow.FlowRuleBatchOperation; | 34 | import org.onosproject.net.flow.FlowRuleBatchOperation; |
35 | import org.onosproject.net.flow.FlowRuleService; | 35 | import org.onosproject.net.flow.FlowRuleService; |
36 | +import org.onosproject.net.intent.BatchWrite; | ||
36 | import org.onosproject.net.intent.Intent; | 37 | import org.onosproject.net.intent.Intent; |
37 | import org.onosproject.net.intent.IntentBatchDelegate; | 38 | import org.onosproject.net.intent.IntentBatchDelegate; |
38 | -import org.onosproject.net.intent.IntentBatchService; | ||
39 | import org.onosproject.net.intent.IntentCompiler; | 39 | import org.onosproject.net.intent.IntentCompiler; |
40 | import org.onosproject.net.intent.IntentData; | 40 | import org.onosproject.net.intent.IntentData; |
41 | import org.onosproject.net.intent.IntentEvent; | 41 | import org.onosproject.net.intent.IntentEvent; |
... | @@ -49,11 +49,11 @@ import org.onosproject.net.intent.IntentOperations; | ... | @@ -49,11 +49,11 @@ import org.onosproject.net.intent.IntentOperations; |
49 | import org.onosproject.net.intent.IntentService; | 49 | import org.onosproject.net.intent.IntentService; |
50 | import org.onosproject.net.intent.IntentState; | 50 | import org.onosproject.net.intent.IntentState; |
51 | import org.onosproject.net.intent.IntentStore; | 51 | import org.onosproject.net.intent.IntentStore; |
52 | -import org.onosproject.net.intent.BatchWrite; | ||
53 | import org.onosproject.net.intent.IntentStoreDelegate; | 52 | import org.onosproject.net.intent.IntentStoreDelegate; |
54 | import org.slf4j.Logger; | 53 | import org.slf4j.Logger; |
55 | 54 | ||
56 | import java.util.ArrayList; | 55 | import java.util.ArrayList; |
56 | +import java.util.Collection; | ||
57 | import java.util.Collections; | 57 | import java.util.Collections; |
58 | import java.util.EnumSet; | 58 | import java.util.EnumSet; |
59 | import java.util.LinkedList; | 59 | import java.util.LinkedList; |
... | @@ -72,8 +72,8 @@ import java.util.stream.Collectors; | ... | @@ -72,8 +72,8 @@ import java.util.stream.Collectors; |
72 | import static com.google.common.base.Preconditions.checkNotNull; | 72 | import static com.google.common.base.Preconditions.checkNotNull; |
73 | import static com.google.common.base.Preconditions.checkState; | 73 | import static com.google.common.base.Preconditions.checkState; |
74 | import static java.util.concurrent.Executors.newFixedThreadPool; | 74 | import static java.util.concurrent.Executors.newFixedThreadPool; |
75 | -import static org.onosproject.net.intent.IntentState.*; | ||
76 | import static org.onlab.util.Tools.namedThreads; | 75 | import static org.onlab.util.Tools.namedThreads; |
76 | +import static org.onosproject.net.intent.IntentState.*; | ||
77 | import static org.slf4j.LoggerFactory.getLogger; | 77 | import static org.slf4j.LoggerFactory.getLogger; |
78 | 78 | ||
79 | /** | 79 | /** |
... | @@ -110,9 +110,6 @@ public class IntentManager | ... | @@ -110,9 +110,6 @@ public class IntentManager |
110 | protected IntentStore store; | 110 | protected IntentStore store; |
111 | 111 | ||
112 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 112 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
113 | - protected IntentBatchService batchService; | ||
114 | - | ||
115 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
116 | protected ObjectiveTrackerService trackerService; | 113 | protected ObjectiveTrackerService trackerService; |
117 | 114 | ||
118 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 115 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
... | @@ -129,13 +126,12 @@ public class IntentManager | ... | @@ -129,13 +126,12 @@ public class IntentManager |
129 | private final IntentBatchDelegate batchDelegate = new InternalBatchDelegate(); | 126 | private final IntentBatchDelegate batchDelegate = new InternalBatchDelegate(); |
130 | private IdGenerator idGenerator; | 127 | private IdGenerator idGenerator; |
131 | 128 | ||
132 | - private final IntentAccumulator accumulator = new IntentAccumulator(); | 129 | + private final IntentAccumulator accumulator = new IntentAccumulator(batchDelegate); |
133 | 130 | ||
134 | @Activate | 131 | @Activate |
135 | public void activate() { | 132 | public void activate() { |
136 | store.setDelegate(delegate); | 133 | store.setDelegate(delegate); |
137 | trackerService.setDelegate(topoDelegate); | 134 | trackerService.setDelegate(topoDelegate); |
138 | - batchService.setDelegate(batchDelegate); | ||
139 | eventDispatcher.addSink(IntentEvent.class, listenerRegistry); | 135 | eventDispatcher.addSink(IntentEvent.class, listenerRegistry); |
140 | executor = newFixedThreadPool(NUM_THREADS, namedThreads("onos-intent-%d")); | 136 | executor = newFixedThreadPool(NUM_THREADS, namedThreads("onos-intent-%d")); |
141 | idGenerator = coreService.getIdGenerator("intent-ids"); | 137 | idGenerator = coreService.getIdGenerator("intent-ids"); |
... | @@ -147,7 +143,6 @@ public class IntentManager | ... | @@ -147,7 +143,6 @@ public class IntentManager |
147 | public void deactivate() { | 143 | public void deactivate() { |
148 | store.unsetDelegate(delegate); | 144 | store.unsetDelegate(delegate); |
149 | trackerService.unsetDelegate(topoDelegate); | 145 | trackerService.unsetDelegate(topoDelegate); |
150 | - batchService.unsetDelegate(batchDelegate); | ||
151 | eventDispatcher.removeSink(IntentEvent.class); | 146 | eventDispatcher.removeSink(IntentEvent.class); |
152 | executor.shutdown(); | 147 | executor.shutdown(); |
153 | Intent.unbindIdGenerator(idGenerator); | 148 | Intent.unbindIdGenerator(idGenerator); |
... | @@ -435,11 +430,12 @@ public class IntentManager | ... | @@ -435,11 +430,12 @@ public class IntentManager |
435 | } | 430 | } |
436 | } | 431 | } |
437 | 432 | ||
438 | - for (ApplicationId appId : batches.keySet()) { | 433 | + //FIXME |
439 | - if (batchService.isLocalLeader(appId)) { | 434 | +// for (ApplicationId appId : batches.keySet()) { |
440 | - execute(batches.get(appId).build()); | 435 | +// if (batchService.isLocalLeader(appId)) { |
441 | - } | 436 | +// execute(batches.get(appId).build()); |
442 | - } | 437 | +// } |
438 | +// } | ||
443 | } | 439 | } |
444 | 440 | ||
445 | // Topology change delegate | 441 | // Topology change delegate |
... | @@ -452,48 +448,21 @@ public class IntentManager | ... | @@ -452,48 +448,21 @@ public class IntentManager |
452 | } | 448 | } |
453 | 449 | ||
454 | // TODO: simplify the branching statements | 450 | // TODO: simplify the branching statements |
455 | - private IntentUpdate createIntentUpdate(IntentOperation operation) { | 451 | + private IntentUpdate createIntentUpdate(IntentData intentData) { |
456 | - switch (operation.type()) { | 452 | + IntentData currentState = store.getIntentData(intentData.key()); |
457 | - case SUBMIT: | 453 | + switch (intentData.state()) { |
458 | - return new InstallRequest(operation.intent()); | 454 | + case INSTALL_REQ: |
459 | - case WITHDRAW: { | 455 | + return new InstallRequest(intentData.intent(), currentState); |
460 | - Intent oldIntent = store.getIntent(operation.intentId()); | 456 | + case WITHDRAW_REQ: |
461 | - if (oldIntent == null) { | 457 | + return new WithdrawRequest(intentData.intent(), currentState); |
462 | - return new DoNothing(); | 458 | + // fallthrough |
463 | - } | 459 | + case COMPILING: |
464 | - List<Intent> installables = store.getInstallableIntents(oldIntent.id()); | 460 | + case INSTALLING: |
465 | - if (installables == null) { | 461 | + case INSTALLED: |
466 | - return new WithdrawStateChange1(oldIntent); | 462 | + case RECOMPILING: |
467 | - } | 463 | + case WITHDRAWING: |
468 | - return new WithdrawRequest(oldIntent, installables); | 464 | + case WITHDRAWN: |
469 | - } | 465 | + case FAILED: |
470 | - case REPLACE: { | ||
471 | - Intent newIntent = operation.intent(); | ||
472 | - Intent oldIntent = store.getIntent(operation.intentId()); | ||
473 | - if (oldIntent == null) { | ||
474 | - return new InstallRequest(newIntent); | ||
475 | - } | ||
476 | - List<Intent> installables = store.getInstallableIntents(oldIntent.id()); | ||
477 | - if (installables == null) { | ||
478 | - if (newIntent.equals(oldIntent)) { | ||
479 | - return new InstallRequest(newIntent); | ||
480 | - } else { | ||
481 | - return new WithdrawStateChange2(oldIntent); | ||
482 | - } | ||
483 | - } | ||
484 | - return new ReplaceRequest(newIntent, oldIntent, installables); | ||
485 | - } | ||
486 | - case UPDATE: { | ||
487 | - Intent oldIntent = store.getIntent(operation.intentId()); | ||
488 | - if (oldIntent == null) { | ||
489 | - return new DoNothing(); | ||
490 | - } | ||
491 | - List<Intent> installables = getInstallableIntents(oldIntent.id()); | ||
492 | - if (installables == null) { | ||
493 | - return new InstallRequest(oldIntent); | ||
494 | - } | ||
495 | - return new ReplaceRequest(oldIntent, oldIntent, installables); | ||
496 | - } | ||
497 | default: | 466 | default: |
498 | // illegal state | 467 | // illegal state |
499 | return new DoNothing(); | 468 | return new DoNothing(); |
... | @@ -504,9 +473,11 @@ public class IntentManager | ... | @@ -504,9 +473,11 @@ public class IntentManager |
504 | private class InstallRequest implements IntentUpdate { | 473 | private class InstallRequest implements IntentUpdate { |
505 | 474 | ||
506 | private final Intent intent; | 475 | private final Intent intent; |
476 | + private final IntentData currentState; | ||
507 | 477 | ||
508 | - InstallRequest(Intent intent) { | 478 | + InstallRequest(Intent intent, IntentData currentState) { |
509 | this.intent = checkNotNull(intent); | 479 | this.intent = checkNotNull(intent); |
480 | + this.currentState = currentState; | ||
510 | } | 481 | } |
511 | 482 | ||
512 | @Override | 483 | @Override |
... | @@ -518,18 +489,18 @@ public class IntentManager | ... | @@ -518,18 +489,18 @@ public class IntentManager |
518 | 489 | ||
519 | @Override | 490 | @Override |
520 | public Optional<IntentUpdate> execute() { | 491 | public Optional<IntentUpdate> execute() { |
521 | - return Optional.of(new Compiling(intent)); | 492 | + return Optional.of(new Compiling(intent)); //FIXME |
522 | } | 493 | } |
523 | } | 494 | } |
524 | 495 | ||
525 | private class WithdrawRequest implements IntentUpdate { | 496 | private class WithdrawRequest implements IntentUpdate { |
526 | 497 | ||
527 | private final Intent intent; | 498 | private final Intent intent; |
528 | - private final List<Intent> installables; | 499 | + private final IntentData currentState; |
529 | 500 | ||
530 | - WithdrawRequest(Intent intent, List<Intent> installables) { | 501 | + WithdrawRequest(Intent intent, IntentData currentState) { |
531 | this.intent = checkNotNull(intent); | 502 | this.intent = checkNotNull(intent); |
532 | - this.installables = ImmutableList.copyOf(checkNotNull(installables)); | 503 | + this.currentState = currentState; |
533 | } | 504 | } |
534 | 505 | ||
535 | @Override | 506 | @Override |
... | @@ -539,7 +510,7 @@ public class IntentManager | ... | @@ -539,7 +510,7 @@ public class IntentManager |
539 | 510 | ||
540 | @Override | 511 | @Override |
541 | public Optional<IntentUpdate> execute() { | 512 | public Optional<IntentUpdate> execute() { |
542 | - return Optional.of(new Withdrawing(intent, installables)); | 513 | + return Optional.of(new Withdrawing(intent, currentState.installables())); //FIXME |
543 | } | 514 | } |
544 | } | 515 | } |
545 | 516 | ||
... | @@ -1052,24 +1023,24 @@ public class IntentManager | ... | @@ -1052,24 +1023,24 @@ public class IntentManager |
1052 | private static final int TIMEOUT_PER_OP = 500; // ms | 1023 | private static final int TIMEOUT_PER_OP = 500; // ms |
1053 | protected static final int MAX_ATTEMPTS = 3; | 1024 | protected static final int MAX_ATTEMPTS = 3; |
1054 | 1025 | ||
1055 | - protected final IntentOperations ops; | 1026 | + protected final Collection<IntentData> ops; |
1056 | 1027 | ||
1057 | // future holding current FlowRuleBatch installation result | 1028 | // future holding current FlowRuleBatch installation result |
1058 | protected final long startTime = System.currentTimeMillis(); | 1029 | protected final long startTime = System.currentTimeMillis(); |
1059 | protected final long endTime; | 1030 | protected final long endTime; |
1060 | 1031 | ||
1061 | - private IntentBatchPreprocess(IntentOperations ops, long endTime) { | 1032 | + private IntentBatchPreprocess(Collection<IntentData> ops, long endTime) { |
1062 | this.ops = checkNotNull(ops); | 1033 | this.ops = checkNotNull(ops); |
1063 | this.endTime = endTime; | 1034 | this.endTime = endTime; |
1064 | } | 1035 | } |
1065 | 1036 | ||
1066 | - public IntentBatchPreprocess(IntentOperations ops) { | 1037 | + public IntentBatchPreprocess(Collection<IntentData> ops) { |
1067 | - this(ops, System.currentTimeMillis() + ops.operations().size() * TIMEOUT_PER_OP); | 1038 | + this(ops, System.currentTimeMillis() + ops.size() * TIMEOUT_PER_OP); |
1068 | } | 1039 | } |
1069 | 1040 | ||
1070 | // FIXME compute reasonable timeouts | 1041 | // FIXME compute reasonable timeouts |
1071 | protected long calculateTimeoutLimit() { | 1042 | protected long calculateTimeoutLimit() { |
1072 | - return System.currentTimeMillis() + ops.operations().size() * TIMEOUT_PER_OP; | 1043 | + return System.currentTimeMillis() + ops.size() * TIMEOUT_PER_OP; |
1073 | } | 1044 | } |
1074 | 1045 | ||
1075 | @Override | 1046 | @Override |
... | @@ -1099,12 +1070,13 @@ public class IntentManager | ... | @@ -1099,12 +1070,13 @@ public class IntentManager |
1099 | // the batch has failed | 1070 | // the batch has failed |
1100 | // TODO: maybe we should do more? | 1071 | // TODO: maybe we should do more? |
1101 | log.error("Walk the plank, matey..."); | 1072 | log.error("Walk the plank, matey..."); |
1102 | - batchService.removeIntentOperations(ops); | 1073 | + //FIXME |
1074 | +// batchService.removeIntentOperations(ops); | ||
1103 | } | 1075 | } |
1104 | } | 1076 | } |
1105 | 1077 | ||
1106 | private List<IntentUpdate> createIntentUpdates() { | 1078 | private List<IntentUpdate> createIntentUpdates() { |
1107 | - return ops.operations().stream() | 1079 | + return ops.stream() |
1108 | .map(IntentManager.this::createIntentUpdate) | 1080 | .map(IntentManager.this::createIntentUpdate) |
1109 | .collect(Collectors.toList()); | 1081 | .collect(Collectors.toList()); |
1110 | } | 1082 | } |
... | @@ -1143,7 +1115,7 @@ public class IntentManager | ... | @@ -1143,7 +1115,7 @@ public class IntentManager |
1143 | protected final int installAttempt; | 1115 | protected final int installAttempt; |
1144 | protected Future<CompletedBatchOperation> future; | 1116 | protected Future<CompletedBatchOperation> future; |
1145 | 1117 | ||
1146 | - IntentBatchApplyFirst(IntentOperations operations, List<CompletedIntentUpdate> intentUpdates, | 1118 | + IntentBatchApplyFirst(Collection<IntentData> operations, List<CompletedIntentUpdate> intentUpdates, |
1147 | long endTime, int installAttempt, Future<CompletedBatchOperation> future) { | 1119 | long endTime, int installAttempt, Future<CompletedBatchOperation> future) { |
1148 | super(operations, endTime); | 1120 | super(operations, endTime); |
1149 | this.intentUpdates = ImmutableList.copyOf(intentUpdates); | 1121 | this.intentUpdates = ImmutableList.copyOf(intentUpdates); |
... | @@ -1202,14 +1174,15 @@ public class IntentManager | ... | @@ -1202,14 +1174,15 @@ public class IntentManager |
1202 | // TODO: maybe we should do more? | 1174 | // TODO: maybe we should do more? |
1203 | log.error("Walk the plank, matey..."); | 1175 | log.error("Walk the plank, matey..."); |
1204 | future = null; | 1176 | future = null; |
1205 | - batchService.removeIntentOperations(ops); | 1177 | + //FIXME |
1178 | +// batchService.removeIntentOperations(ops); | ||
1206 | } | 1179 | } |
1207 | } | 1180 | } |
1208 | 1181 | ||
1209 | // TODO: better naming | 1182 | // TODO: better naming |
1210 | private class IntentBatchProcessFutures extends IntentBatchApplyFirst { | 1183 | private class IntentBatchProcessFutures extends IntentBatchApplyFirst { |
1211 | 1184 | ||
1212 | - IntentBatchProcessFutures(IntentOperations operations, List<CompletedIntentUpdate> intentUpdates, | 1185 | + IntentBatchProcessFutures(Collection<IntentData> operations, List<CompletedIntentUpdate> intentUpdates, |
1213 | long endTime, int installAttempt, Future<CompletedBatchOperation> future) { | 1186 | long endTime, int installAttempt, Future<CompletedBatchOperation> future) { |
1214 | super(operations, intentUpdates, endTime, installAttempt, future); | 1187 | super(operations, intentUpdates, endTime, installAttempt, future); |
1215 | } | 1188 | } |
... | @@ -1228,7 +1201,9 @@ public class IntentManager | ... | @@ -1228,7 +1201,9 @@ public class IntentManager |
1228 | Future<CompletedBatchOperation> future = processFutures(); | 1201 | Future<CompletedBatchOperation> future = processFutures(); |
1229 | if (future == null) { | 1202 | if (future == null) { |
1230 | // there are no outstanding batches; we are done | 1203 | // there are no outstanding batches; we are done |
1231 | - batchService.removeIntentOperations(ops); | 1204 | + //FIXME |
1205 | + return; //? | ||
1206 | +// batchService.removeIntentOperations(ops); | ||
1232 | } else if (System.currentTimeMillis() > endTime) { | 1207 | } else if (System.currentTimeMillis() > endTime) { |
1233 | // - cancel current FlowRuleBatch and resubmit again | 1208 | // - cancel current FlowRuleBatch and resubmit again |
1234 | retry(); | 1209 | retry(); |
... | @@ -1317,17 +1292,10 @@ public class IntentManager | ... | @@ -1317,17 +1292,10 @@ public class IntentManager |
1317 | 1292 | ||
1318 | private class InternalBatchDelegate implements IntentBatchDelegate { | 1293 | private class InternalBatchDelegate implements IntentBatchDelegate { |
1319 | @Override | 1294 | @Override |
1320 | - public void execute(IntentOperations operations) { | 1295 | + public void execute(Collection<IntentData> operations) { |
1321 | - log.info("Execute {} operation(s).", operations.operations().size()); | 1296 | + log.info("Execute {} operation(s).", operations.size()); |
1322 | - log.debug("Execute operations: {}", operations.operations()); | 1297 | + log.debug("Execute operations: {}", operations); |
1323 | - //FIXME: perhaps we want to track this task so that we can cancel it. | ||
1324 | executor.execute(new IntentBatchPreprocess(operations)); | 1298 | executor.execute(new IntentBatchPreprocess(operations)); |
1325 | } | 1299 | } |
1326 | - | ||
1327 | - @Override | ||
1328 | - public void cancel(IntentOperations operations) { | ||
1329 | - //FIXME: implement this | ||
1330 | - log.warn("NOT IMPLEMENTED -- Cancel operations: {}", operations); | ||
1331 | - } | ||
1332 | } | 1300 | } |
1333 | } | 1301 | } | ... | ... |
... | @@ -15,15 +15,11 @@ | ... | @@ -15,15 +15,11 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.intent.impl; | 16 | package org.onosproject.net.intent.impl; |
17 | 17 | ||
18 | -import java.util.Collection; | 18 | +import com.google.common.collect.HashMultimap; |
19 | -import java.util.Collections; | 19 | +import com.google.common.collect.Lists; |
20 | -import java.util.List; | 20 | +import com.google.common.collect.Maps; |
21 | -import java.util.Map; | 21 | +import com.google.common.collect.Multimap; |
22 | -import java.util.Set; | 22 | +import com.google.common.collect.Sets; |
23 | -import java.util.concurrent.CountDownLatch; | ||
24 | -import java.util.concurrent.TimeUnit; | ||
25 | -import java.util.concurrent.atomic.AtomicLong; | ||
26 | - | ||
27 | import org.hamcrest.Description; | 23 | import org.hamcrest.Description; |
28 | import org.hamcrest.TypeSafeMatcher; | 24 | import org.hamcrest.TypeSafeMatcher; |
29 | import org.junit.After; | 25 | import org.junit.After; |
... | @@ -52,21 +48,20 @@ import org.onosproject.net.intent.IntentTestsMocks; | ... | @@ -52,21 +48,20 @@ import org.onosproject.net.intent.IntentTestsMocks; |
52 | import org.onosproject.net.resource.LinkResourceAllocations; | 48 | import org.onosproject.net.resource.LinkResourceAllocations; |
53 | import org.onosproject.store.trivial.impl.SimpleIntentStore; | 49 | import org.onosproject.store.trivial.impl.SimpleIntentStore; |
54 | 50 | ||
55 | -import com.google.common.collect.HashMultimap; | 51 | +import java.util.Collection; |
56 | -import com.google.common.collect.Lists; | 52 | +import java.util.Collections; |
57 | -import com.google.common.collect.Maps; | 53 | +import java.util.List; |
58 | -import com.google.common.collect.Multimap; | 54 | +import java.util.Map; |
59 | -import com.google.common.collect.Sets; | 55 | +import java.util.Set; |
56 | +import java.util.concurrent.CountDownLatch; | ||
57 | +import java.util.concurrent.TimeUnit; | ||
58 | +import java.util.concurrent.atomic.AtomicLong; | ||
60 | 59 | ||
61 | import static org.hamcrest.MatcherAssert.assertThat; | 60 | import static org.hamcrest.MatcherAssert.assertThat; |
62 | import static org.hamcrest.Matchers.hasSize; | 61 | import static org.hamcrest.Matchers.hasSize; |
63 | -import static org.junit.Assert.assertEquals; | 62 | +import static org.junit.Assert.*; |
64 | -import static org.junit.Assert.assertNotNull; | ||
65 | -import static org.junit.Assert.assertTrue; | ||
66 | import static org.onlab.util.Tools.delay; | 63 | import static org.onlab.util.Tools.delay; |
67 | -import static org.onosproject.net.intent.IntentState.FAILED; | 64 | +import static org.onosproject.net.intent.IntentState.*; |
68 | -import static org.onosproject.net.intent.IntentState.INSTALLED; | ||
69 | -import static org.onosproject.net.intent.IntentState.WITHDRAWN; | ||
70 | 65 | ||
71 | /** | 66 | /** |
72 | * Test intent manager and transitions. | 67 | * Test intent manager and transitions. |
... | @@ -305,14 +300,16 @@ public class IntentManagerTest { | ... | @@ -305,14 +300,16 @@ public class IntentManagerTest { |
305 | } | 300 | } |
306 | //the batch has not yet been removed when we receive the last event | 301 | //the batch has not yet been removed when we receive the last event |
307 | // FIXME: this doesn't guarantee to avoid the race | 302 | // FIXME: this doesn't guarantee to avoid the race |
308 | - for (int tries = 0; tries < 10; tries++) { | 303 | + |
309 | - if (manager.batchService.getPendingOperations().isEmpty()) { | 304 | + //FIXME |
310 | - break; | 305 | +// for (int tries = 0; tries < 10; tries++) { |
311 | - } | 306 | +// if (manager.batchService.getPendingOperations().isEmpty()) { |
312 | - delay(10); | 307 | +// break; |
313 | - } | 308 | +// } |
314 | - assertTrue("There are still pending batch operations.", | 309 | +// delay(10); |
315 | - manager.batchService.getPendingOperations().isEmpty()); | 310 | +// } |
311 | +// assertTrue("There are still pending batch operations.", | ||
312 | +// manager.batchService.getPendingOperations().isEmpty()); | ||
316 | 313 | ||
317 | extensionService.unregisterCompiler(MockIntent.class); | 314 | extensionService.unregisterCompiler(MockIntent.class); |
318 | extensionService.unregisterInstaller(MockInstallableIntent.class); | 315 | extensionService.unregisterInstaller(MockInstallableIntent.class); | ... | ... |
... | @@ -15,8 +15,8 @@ | ... | @@ -15,8 +15,8 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.store.trivial.impl; | 16 | package org.onosproject.store.trivial.impl; |
17 | 17 | ||
18 | -import com.google.common.collect.ImmutableSet; | ||
19 | import com.google.common.collect.Lists; | 18 | import com.google.common.collect.Lists; |
19 | +import com.google.common.collect.Maps; | ||
20 | import org.apache.felix.scr.annotations.Activate; | 20 | import org.apache.felix.scr.annotations.Activate; |
21 | import org.apache.felix.scr.annotations.Component; | 21 | import org.apache.felix.scr.annotations.Component; |
22 | import org.apache.felix.scr.annotations.Deactivate; | 22 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -36,10 +36,10 @@ import org.slf4j.Logger; | ... | @@ -36,10 +36,10 @@ import org.slf4j.Logger; |
36 | import java.util.Collections; | 36 | import java.util.Collections; |
37 | import java.util.List; | 37 | import java.util.List; |
38 | import java.util.Map; | 38 | import java.util.Map; |
39 | -import java.util.concurrent.ConcurrentHashMap; | 39 | +import java.util.stream.Collectors; |
40 | 40 | ||
41 | -import static com.google.common.base.Preconditions.*; | 41 | +import static com.google.common.base.Preconditions.checkArgument; |
42 | -import static org.onosproject.net.intent.IntentState.WITHDRAWN; | 42 | +import static com.google.common.base.Preconditions.checkNotNull; |
43 | import static org.slf4j.LoggerFactory.getLogger; | 43 | import static org.slf4j.LoggerFactory.getLogger; |
44 | 44 | ||
45 | @Component(immediate = true) | 45 | @Component(immediate = true) |
... | @@ -51,11 +51,8 @@ public class SimpleIntentStore | ... | @@ -51,11 +51,8 @@ public class SimpleIntentStore |
51 | private final Logger log = getLogger(getClass()); | 51 | private final Logger log = getLogger(getClass()); |
52 | 52 | ||
53 | // current state maps FIXME.. make this a IntentData map | 53 | // current state maps FIXME.. make this a IntentData map |
54 | - private final Map<IntentId, Intent> intents = new ConcurrentHashMap<>(); | 54 | + private final Map<String, IntentData> current = Maps.newConcurrentMap(); |
55 | - private final Map<IntentId, IntentState> states = new ConcurrentHashMap<>(); | 55 | + private final Map<String, IntentData> pending = Maps.newConcurrentMap(); //String is "key" |
56 | - private final Map<IntentId, List<Intent>> installable = new ConcurrentHashMap<>(); | ||
57 | - | ||
58 | - private final Map<String, IntentData> pending = new ConcurrentHashMap<>(); //String is "key" | ||
59 | 56 | ||
60 | @Activate | 57 | @Activate |
61 | public void activate() { | 58 | public void activate() { |
... | @@ -67,45 +64,32 @@ public class SimpleIntentStore | ... | @@ -67,45 +64,32 @@ public class SimpleIntentStore |
67 | log.info("Stopped"); | 64 | log.info("Stopped"); |
68 | } | 65 | } |
69 | 66 | ||
70 | - private void createIntent(Intent intent) { | ||
71 | - if (intents.containsKey(intent.id())) { | ||
72 | - return; | ||
73 | - } | ||
74 | - intents.put(intent.id(), intent); | ||
75 | - this.setState(intent, IntentState.INSTALL_REQ); | ||
76 | - } | ||
77 | - | ||
78 | - private void removeIntent(IntentId intentId) { | ||
79 | - checkState(getIntentState(intentId) == WITHDRAWN, | ||
80 | - "Intent state for {} is not WITHDRAWN.", intentId); | ||
81 | - intents.remove(intentId); | ||
82 | - installable.remove(intentId); | ||
83 | - states.remove(intentId); | ||
84 | - } | ||
85 | - | ||
86 | @Override | 67 | @Override |
87 | public long getIntentCount() { | 68 | public long getIntentCount() { |
88 | - return intents.size(); | 69 | + return current.size(); |
89 | } | 70 | } |
90 | 71 | ||
91 | @Override | 72 | @Override |
92 | public Iterable<Intent> getIntents() { | 73 | public Iterable<Intent> getIntents() { |
93 | - return ImmutableSet.copyOf(intents.values()); | 74 | + return current.values().stream() |
75 | + .map(IntentData::intent) | ||
76 | + .collect(Collectors.toList()); | ||
94 | } | 77 | } |
95 | 78 | ||
96 | @Override | 79 | @Override |
97 | public Intent getIntent(IntentId intentId) { | 80 | public Intent getIntent(IntentId intentId) { |
98 | - return intents.get(intentId); | 81 | + throw new UnsupportedOperationException("deprecated"); |
99 | } | 82 | } |
100 | 83 | ||
101 | @Override | 84 | @Override |
102 | public IntentState getIntentState(IntentId id) { | 85 | public IntentState getIntentState(IntentId id) { |
103 | - return states.get(id); | 86 | + throw new UnsupportedOperationException("deprecated"); |
104 | } | 87 | } |
105 | 88 | ||
106 | private void setState(Intent intent, IntentState state) { | 89 | private void setState(Intent intent, IntentState state) { |
90 | + //FIXME | ||
107 | IntentId id = intent.id(); | 91 | IntentId id = intent.id(); |
108 | - states.put(id, state); | 92 | +// states.put(id, state); |
109 | IntentEvent.Type type = null; | 93 | IntentEvent.Type type = null; |
110 | 94 | ||
111 | switch (state) { | 95 | switch (state) { |
... | @@ -133,16 +117,23 @@ public class SimpleIntentStore | ... | @@ -133,16 +117,23 @@ public class SimpleIntentStore |
133 | } | 117 | } |
134 | 118 | ||
135 | private void setInstallableIntents(IntentId intentId, List<Intent> result) { | 119 | private void setInstallableIntents(IntentId intentId, List<Intent> result) { |
136 | - installable.put(intentId, result); | 120 | + //FIXME |
121 | +// installable.put(intentId, result); | ||
137 | } | 122 | } |
138 | 123 | ||
139 | @Override | 124 | @Override |
140 | public List<Intent> getInstallableIntents(IntentId intentId) { | 125 | public List<Intent> getInstallableIntents(IntentId intentId) { |
141 | - return installable.get(intentId); | 126 | + throw new UnsupportedOperationException("deprecated"); |
127 | + } | ||
128 | + | ||
129 | + @Override | ||
130 | + public IntentData getIntentData(String key) { | ||
131 | + return current.get(key); | ||
142 | } | 132 | } |
143 | 133 | ||
144 | private void removeInstalledIntents(IntentId intentId) { | 134 | private void removeInstalledIntents(IntentId intentId) { |
145 | - installable.remove(intentId); | 135 | + //FIXME |
136 | +// installable.remove(intentId); | ||
146 | } | 137 | } |
147 | 138 | ||
148 | /** | 139 | /** |
... | @@ -165,14 +156,14 @@ public class SimpleIntentStore | ... | @@ -165,14 +156,14 @@ public class SimpleIntentStore |
165 | "CREATE_INTENT takes 1 argument. %s", op); | 156 | "CREATE_INTENT takes 1 argument. %s", op); |
166 | Intent intent = (Intent) op.args().get(0); | 157 | Intent intent = (Intent) op.args().get(0); |
167 | // TODO: what if it failed? | 158 | // TODO: what if it failed? |
168 | - createIntent(intent); | 159 | +// createIntent(intent); FIXME |
169 | break; | 160 | break; |
170 | 161 | ||
171 | case REMOVE_INTENT: | 162 | case REMOVE_INTENT: |
172 | checkArgument(op.args().size() == 1, | 163 | checkArgument(op.args().size() == 1, |
173 | "REMOVE_INTENT takes 1 argument. %s", op); | 164 | "REMOVE_INTENT takes 1 argument. %s", op); |
174 | IntentId intentId = (IntentId) op.args().get(0); | 165 | IntentId intentId = (IntentId) op.args().get(0); |
175 | - removeIntent(intentId); | 166 | +// removeIntent(intentId); FIXME |
176 | break; | 167 | break; |
177 | 168 | ||
178 | case REMOVE_INSTALLED: | 169 | case REMOVE_INSTALLED: | ... | ... |
-
Please register or login to post a comment