Sho SHIMIZU
Committed by Brian O'Connor

Pull out inner IntentUpdate sub-classes from IntentManager

Change-Id: Iefec2e3d5929d0e85e40bee24ba4fd0679c13b19
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.intent.Intent;
19 +import org.onosproject.net.intent.IntentException;
20 +import org.slf4j.Logger;
21 +import org.slf4j.LoggerFactory;
22 +
23 +import java.util.Optional;
24 +
25 +import static com.google.common.base.Preconditions.checkNotNull;
26 +
27 +class Compiling implements IntentUpdate {
28 +
29 + private static final Logger log = LoggerFactory.getLogger(Compiling.class);
30 +
31 + // TODO: define an interface and use it, instead of IntentManager
32 + private final IntentManager intentManager;
33 + private final Intent intent;
34 +
35 + Compiling(IntentManager intentManager, Intent intent) {
36 + this.intentManager = checkNotNull(intentManager);
37 + this.intent = checkNotNull(intent);
38 + }
39 +
40 + @Override
41 + public Optional<IntentUpdate> execute() {
42 + try {
43 + return Optional.of(new Installing(intentManager, intent, intentManager.compileIntent(intent, null)));
44 + } catch (PathNotFoundException e) {
45 + log.debug("Path not found for intent {}", intent);
46 + // TODO: revisit to implement failure handling
47 + return Optional.of(new DoNothing());
48 + } catch (IntentException e) {
49 + log.warn("Unable to compile intent {} due to:", intent.id(), e);
50 + // TODO: revisit to implement failure handling
51 + return Optional.of(new DoNothing());
52 + }
53 + }
54 +}
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.intent.Intent;
19 +import org.onosproject.net.intent.IntentData;
20 +
21 +import java.util.Optional;
22 +
23 +import static com.google.common.base.Preconditions.checkNotNull;
24 +
25 +// TODO pull out the IntentUpdate inner classes
26 +class InstallRequest implements IntentUpdate {
27 +
28 + // TODO: define an interface and use it, instead of IntentManager
29 + private final IntentManager intentManager;
30 + private final Intent intent;
31 + private final IntentData currentState;
32 +
33 + InstallRequest(IntentManager intentManager, Intent intent, IntentData currentState) {
34 + this.intentManager = checkNotNull(intentManager);
35 + this.intent = checkNotNull(intent);
36 + this.currentState = currentState;
37 + }
38 +
39 + @Override
40 + public Optional<IntentUpdate> execute() {
41 + return Optional.of(new Compiling(intentManager, intent)); //FIXME
42 + }
43 +}
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 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 +
26 +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;
29 +
30 +class Installed implements CompletedIntentUpdate {
31 +
32 + // TODO: define an interface and use it, instead of IntentManager
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 +
59 + @Override
60 + public FlowRuleBatchOperation currentBatch() {
61 + return currentBatch < batches.size() ? batches.get(currentBatch) : null;
62 + }
63 +
64 + @Override
65 + public void batchFailed() {
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 + }
74 +}
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 org.onosproject.net.flow.FlowRuleBatchOperation;
20 +import org.onosproject.net.intent.Intent;
21 +import org.slf4j.Logger;
22 +import org.slf4j.LoggerFactory;
23 +
24 +import java.util.List;
25 +import java.util.Optional;
26 +
27 +import static com.google.common.base.Preconditions.checkNotNull;
28 +
29 +// TODO: better naming because install() method actually generate FlowRuleBatchOperations
30 +class Installing implements IntentUpdate {
31 +
32 + private static final Logger log = LoggerFactory.getLogger(Installing.class);
33 +
34 + private final IntentManager intentManager;
35 + private final Intent intent;
36 + private final List<Intent> installables;
37 +
38 + // TODO: define an interface and use it, instead of IntentManager
39 + Installing(IntentManager intentManager, Intent intent, List<Intent> installables) {
40 + this.intentManager = checkNotNull(intentManager);
41 + this.intent = checkNotNull(intent);
42 + this.installables = ImmutableList.copyOf(checkNotNull(installables));
43 + }
44 +
45 + @Override
46 + public Optional<IntentUpdate> execute() {
47 + try {
48 + List<FlowRuleBatchOperation> converted = intentManager.convert(installables);
49 + // TODO: call FlowRuleService API to push FlowRules and track resources,
50 + // which the submitted intent will use.
51 + return Optional.of(new Installed(intentManager, intent, installables, converted));
52 + } catch (FlowRuleBatchOperationConvertionException e) {
53 + log.warn("Unable to install intent {} due to:", intent.id(), e.getCause());
54 + return Optional.of(new InstallingFailed(intentManager, intent, installables, e.converted()));
55 + }
56 + }
57 +}
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 org.onosproject.net.flow.FlowRuleBatchOperation;
20 +import org.onosproject.net.intent.Intent;
21 +
22 +import java.util.LinkedList;
23 +import java.util.List;
24 +
25 +import static com.google.common.base.Preconditions.checkNotNull;
26 +
27 +class InstallingFailed implements CompletedIntentUpdate {
28 +
29 + private IntentManager intentManager;
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 +
43 + @Override
44 + public List<Intent> allInstallables() {
45 + return installables;
46 + }
47 +
48 + @Override
49 + public void batchSuccess() {
50 + currentBatch++;
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 + }
67 +}
...@@ -19,7 +19,6 @@ import java.util.ArrayList; ...@@ -19,7 +19,6 @@ import java.util.ArrayList;
19 import java.util.Collection; 19 import java.util.Collection;
20 import java.util.Collections; 20 import java.util.Collections;
21 import java.util.EnumSet; 21 import java.util.EnumSet;
22 -import java.util.LinkedList;
23 import java.util.List; 22 import java.util.List;
24 import java.util.Map; 23 import java.util.Map;
25 import java.util.Optional; 24 import java.util.Optional;
...@@ -69,7 +68,6 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -69,7 +68,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
69 import static java.util.concurrent.Executors.newFixedThreadPool; 68 import static java.util.concurrent.Executors.newFixedThreadPool;
70 import static org.onlab.util.Tools.namedThreads; 69 import static org.onlab.util.Tools.namedThreads;
71 import static org.onosproject.net.intent.IntentState.FAILED; 70 import static org.onosproject.net.intent.IntentState.FAILED;
72 -import static org.onosproject.net.intent.IntentState.INSTALLING;
73 import static org.onosproject.net.intent.IntentState.INSTALL_REQ; 71 import static org.onosproject.net.intent.IntentState.INSTALL_REQ;
74 import static org.onosproject.net.intent.IntentState.WITHDRAW_REQ; 72 import static org.onosproject.net.intent.IntentState.WITHDRAW_REQ;
75 import static org.slf4j.LoggerFactory.getLogger; 73 import static org.slf4j.LoggerFactory.getLogger;
...@@ -269,7 +267,7 @@ public class IntentManager ...@@ -269,7 +267,7 @@ public class IntentManager
269 * @param intent intent 267 * @param intent intent
270 * @return result of compilation 268 * @return result of compilation
271 */ 269 */
272 - private List<Intent> compileIntent(Intent intent, List<Intent> previousInstallables) { 270 + List<Intent> compileIntent(Intent intent, List<Intent> previousInstallables) {
273 if (intent.isInstallable()) { 271 if (intent.isInstallable()) {
274 return ImmutableList.of(intent); 272 return ImmutableList.of(intent);
275 } 273 }
...@@ -290,7 +288,7 @@ public class IntentManager ...@@ -290,7 +288,7 @@ public class IntentManager
290 * @param installables installable intents 288 * @param installables installable intents
291 * @return list of batches to uninstall intent 289 * @return list of batches to uninstall intent
292 */ 290 */
293 - private List<FlowRuleBatchOperation> uninstallIntent(Intent intent, List<Intent> installables) { 291 + List<FlowRuleBatchOperation> uninstallIntent(Intent intent, List<Intent> installables) {
294 List<FlowRuleBatchOperation> batches = Lists.newArrayList(); 292 List<FlowRuleBatchOperation> batches = Lists.newArrayList();
295 for (Intent installable : installables) { 293 for (Intent installable : installables) {
296 trackerService.removeTrackedResources(intent.id(), 294 trackerService.removeTrackedResources(intent.id(),
...@@ -415,9 +413,9 @@ public class IntentManager ...@@ -415,9 +413,9 @@ public class IntentManager
415 IntentData currentState = store.getIntentData(intentData.key()); 413 IntentData currentState = store.getIntentData(intentData.key());
416 switch (intentData.state()) { 414 switch (intentData.state()) {
417 case INSTALL_REQ: 415 case INSTALL_REQ:
418 - return new InstallRequest(intentData.intent(), currentState); 416 + return new InstallRequest(this, intentData.intent(), currentState);
419 case WITHDRAW_REQ: 417 case WITHDRAW_REQ:
420 - return new WithdrawRequest(intentData.intent(), currentState); 418 + return new WithdrawRequest(this, intentData.intent(), currentState);
421 // fallthrough 419 // fallthrough
422 case COMPILING: 420 case COMPILING:
423 case INSTALLING: 421 case INSTALLING:
...@@ -432,89 +430,7 @@ public class IntentManager ...@@ -432,89 +430,7 @@ public class IntentManager
432 } 430 }
433 } 431 }
434 432
435 - // TODO pull out the IntentUpdate inner classes 433 + List<FlowRuleBatchOperation> convert(List<Intent> installables) {
436 - private class InstallRequest implements IntentUpdate {
437 -
438 - private final Intent intent;
439 - private final IntentData currentState;
440 -
441 - InstallRequest(Intent intent, IntentData currentState) {
442 - this.intent = checkNotNull(intent);
443 - this.currentState = currentState;
444 - }
445 -
446 - @Override
447 - public Optional<IntentUpdate> execute() {
448 - return Optional.of(new Compiling(intent)); //FIXME
449 - }
450 - }
451 -
452 - private class WithdrawRequest implements IntentUpdate {
453 -
454 - private final Intent intent;
455 - private final IntentData currentState;
456 -
457 - WithdrawRequest(Intent intent, IntentData currentState) {
458 - this.intent = checkNotNull(intent);
459 - this.currentState = currentState;
460 - }
461 -
462 - @Override
463 - public Optional<IntentUpdate> execute() {
464 - return Optional.of(new Withdrawing(intent, currentState.installables())); //FIXME
465 - }
466 - }
467 -
468 - private class Compiling implements IntentUpdate {
469 -
470 - private final Intent intent;
471 -
472 - Compiling(Intent intent) {
473 - this.intent = checkNotNull(intent);
474 - }
475 -
476 - @Override
477 - public Optional<IntentUpdate> execute() {
478 - try {
479 - return Optional.of(new Installing(intent, compileIntent(intent, null)));
480 - } catch (PathNotFoundException e) {
481 - log.debug("Path not found for intent {}", intent);
482 - // TODO: revisit to implement failure handling
483 - return Optional.of(new DoNothing());
484 - } catch (IntentException e) {
485 - log.warn("Unable to compile intent {} due to:", intent.id(), e);
486 - // TODO: revisit to implement failure handling
487 - return Optional.of(new DoNothing());
488 - }
489 - }
490 - }
491 -
492 - // TODO: better naming because install() method actually generate FlowRuleBatchOperations
493 - private class Installing implements IntentUpdate {
494 -
495 - private final Intent intent;
496 - private final List<Intent> installables;
497 -
498 - Installing(Intent intent, List<Intent> installables) {
499 - this.intent = checkNotNull(intent);
500 - this.installables = ImmutableList.copyOf(checkNotNull(installables));
501 - }
502 -
503 - @Override
504 - public Optional<IntentUpdate> execute() {
505 - try {
506 - List<FlowRuleBatchOperation> converted = convert(installables);
507 - // TODO: call FlowRuleService API to push FlowRules and track resources,
508 - // which the submitted intent will use.
509 - return Optional.of(new Installed(intent, installables, converted));
510 - } catch (FlowRuleBatchOperationConvertionException e) {
511 - log.warn("Unable to install intent {} due to:", intent.id(), e.getCause());
512 - return Optional.of(new InstallingFailed(intent, installables, e.converted()));
513 - }
514 - }
515 - }
516 -
517 - private List<FlowRuleBatchOperation> convert(List<Intent> installables) {
518 List<FlowRuleBatchOperation> batches = new ArrayList<>(installables.size()); 434 List<FlowRuleBatchOperation> batches = new ArrayList<>(installables.size());
519 for (Intent installable : installables) { 435 for (Intent installable : installables) {
520 try { 436 try {
...@@ -527,143 +443,6 @@ public class IntentManager ...@@ -527,143 +443,6 @@ public class IntentManager
527 return batches; 443 return batches;
528 } 444 }
529 445
530 - private class Withdrawing implements IntentUpdate {
531 -
532 - private final Intent intent;
533 - private final List<Intent> installables;
534 -
535 - Withdrawing(Intent intent, List<Intent> installables) {
536 - this.intent = checkNotNull(intent);
537 - this.installables = ImmutableList.copyOf(installables);
538 - }
539 -
540 - @Override
541 - public Optional<IntentUpdate> execute() {
542 - List<FlowRuleBatchOperation> batches = uninstallIntent(intent, installables);
543 -
544 - return Optional.of(new Withdrawn(intent, installables, batches));
545 - }
546 - }
547 -
548 - private class Installed implements CompletedIntentUpdate {
549 -
550 - private final Intent intent;
551 - private final List<Intent> installables;
552 - private IntentState intentState;
553 - private final List<FlowRuleBatchOperation> batches;
554 - private int currentBatch = 0;
555 -
556 - Installed(Intent intent, List<Intent> installables, List<FlowRuleBatchOperation> batches) {
557 - this.intent = checkNotNull(intent);
558 - this.installables = ImmutableList.copyOf(checkNotNull(installables));
559 - this.batches = new LinkedList<>(checkNotNull(batches));
560 - this.intentState = INSTALLING;
561 - }
562 -
563 - @Override
564 - public void batchSuccess() {
565 - currentBatch++;
566 - }
567 -
568 - @Override
569 - public List<Intent> allInstallables() {
570 - return installables;
571 - }
572 -
573 - @Override
574 - public FlowRuleBatchOperation currentBatch() {
575 - return currentBatch < batches.size() ? batches.get(currentBatch) : null;
576 - }
577 -
578 - @Override
579 - public void batchFailed() {
580 - for (int i = batches.size() - 1; i >= currentBatch; i--) {
581 - batches.remove(i);
582 - }
583 - intentState = FAILED;
584 - batches.addAll(uninstallIntent(intent, installables));
585 -
586 - // TODO we might want to try to recompile the new intent
587 - }
588 - }
589 -
590 - private class Withdrawn implements CompletedIntentUpdate {
591 -
592 - private final Intent intent;
593 - private final List<Intent> installables;
594 - private final List<FlowRuleBatchOperation> batches;
595 - private int currentBatch;
596 -
597 - Withdrawn(Intent intent, List<Intent> installables, List<FlowRuleBatchOperation> batches) {
598 - this.intent = checkNotNull(intent);
599 - this.installables = ImmutableList.copyOf(installables);
600 - this.batches = new LinkedList<>(batches);
601 - this.currentBatch = 0;
602 - }
603 -
604 - @Override
605 - public List<Intent> allInstallables() {
606 - return installables;
607 - }
608 -
609 - @Override
610 - public void batchSuccess() {
611 - currentBatch++;
612 - }
613 -
614 - @Override
615 - public FlowRuleBatchOperation currentBatch() {
616 - return currentBatch < batches.size() ? batches.get(currentBatch) : null;
617 - }
618 -
619 - @Override
620 - public void batchFailed() {
621 - for (int i = batches.size() - 1; i >= currentBatch; i--) {
622 - batches.remove(i);
623 - }
624 - batches.addAll(uninstallIntent(intent, installables));
625 - }
626 - }
627 -
628 - private class InstallingFailed implements CompletedIntentUpdate {
629 -
630 - private final Intent intent;
631 - private final List<Intent> installables;
632 - private final List<FlowRuleBatchOperation> batches;
633 - private int currentBatch = 0;
634 -
635 - InstallingFailed(Intent intent, List<Intent> installables, List<FlowRuleBatchOperation> batches) {
636 - this.intent = checkNotNull(intent);
637 - this.installables = ImmutableList.copyOf(checkNotNull(installables));
638 - this.batches = new LinkedList<>(checkNotNull(batches));
639 - }
640 -
641 - @Override
642 - public List<Intent> allInstallables() {
643 - return installables;
644 - }
645 -
646 - @Override
647 - public void batchSuccess() {
648 - currentBatch++;
649 - }
650 -
651 - @Override
652 - public FlowRuleBatchOperation currentBatch() {
653 - return currentBatch < batches.size() ? batches.get(currentBatch) : null;
654 - }
655 -
656 - @Override
657 - public void batchFailed() {
658 - for (int i = batches.size() - 1; i >= currentBatch; i--) {
659 - batches.remove(i);
660 - }
661 - batches.addAll(uninstallIntent(intent, installables));
662 -
663 - // TODO we might want to try to recompile the new intent
664 - }
665 - }
666 -
667 private class IntentBatchPreprocess implements Runnable { 446 private class IntentBatchPreprocess implements Runnable {
668 447
669 // TODO make this configurable 448 // TODO make this configurable
......
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.intent.Intent;
19 +import org.onosproject.net.intent.IntentData;
20 +
21 +import java.util.Optional;
22 +
23 +import static com.google.common.base.Preconditions.checkNotNull;
24 +
25 +class WithdrawRequest implements IntentUpdate {
26 +
27 + // TODO: define an interface and use it, instead of IntentManager
28 + private final IntentManager intentManager;
29 + private final Intent intent;
30 + private final IntentData currentState;
31 +
32 + WithdrawRequest(IntentManager intentManager, Intent intent, IntentData currentState) {
33 + this.intentManager = checkNotNull(intentManager);
34 + this.intent = checkNotNull(intent);
35 + this.currentState = currentState;
36 + }
37 +
38 + @Override
39 + public Optional<IntentUpdate> execute() {
40 + return Optional.of(new Withdrawing(intentManager, intent, currentState.installables())); //FIXME
41 + }
42 +}
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 org.onosproject.net.flow.FlowRuleBatchOperation;
20 +import org.onosproject.net.intent.Intent;
21 +
22 +import java.util.List;
23 +import java.util.Optional;
24 +
25 +import static com.google.common.base.Preconditions.checkNotNull;
26 +
27 +class Withdrawing implements IntentUpdate {
28 +
29 + // TODO: define an interface and use it, instead of IntentManager
30 + private final IntentManager intentManager;
31 + private final Intent intent;
32 + private final List<Intent> installables;
33 +
34 + Withdrawing(IntentManager intentManager, Intent intent, List<Intent> installables) {
35 + this.intentManager = checkNotNull(intentManager);
36 + this.intent = checkNotNull(intent);
37 + this.installables = ImmutableList.copyOf(installables);
38 + }
39 +
40 + @Override
41 + public Optional<IntentUpdate> execute() {
42 + List<FlowRuleBatchOperation> batches = intentManager.uninstallIntent(intent, installables);
43 +
44 + return Optional.of(new Withdrawn(intentManager, intent, installables, batches));
45 + }
46 +}
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 org.onosproject.net.flow.FlowRuleBatchOperation;
20 +import org.onosproject.net.intent.Intent;
21 +
22 +import java.util.LinkedList;
23 +import java.util.List;
24 +
25 +import static com.google.common.base.Preconditions.checkNotNull;
26 +
27 +class Withdrawn implements CompletedIntentUpdate {
28 +
29 + // TODO: define an interface and use it, instead of IntentManager
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 +
55 + @Override
56 + public FlowRuleBatchOperation currentBatch() {
57 + return currentBatch < batches.size() ? batches.get(currentBatch) : null;
58 + }
59 +
60 + @Override
61 + public void batchFailed() {
62 + for (int i = batches.size() - 1; i >= currentBatch; i--) {
63 + batches.remove(i);
64 + }
65 + batches.addAll(intentManager.uninstallIntent(intent, installables));
66 + }
67 +}