Committed by
Brian O'Connor
Move CompilingFailed to upper level to reduce IntentManager's size
Change-Id: Ia75d91ff7f4de01c74f4ca6dac0d15b1d772ed69
Showing
2 changed files
with
56 additions
and
30 deletions
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.net.intent.impl; | ||
17 | + | ||
18 | +import org.onosproject.net.intent.BatchWrite; | ||
19 | +import org.onosproject.net.intent.Intent; | ||
20 | + | ||
21 | +import java.util.Optional; | ||
22 | + | ||
23 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
24 | +import static org.onosproject.net.intent.IntentState.FAILED; | ||
25 | + | ||
26 | +/** | ||
27 | + * A processing phase after compilation failure. | ||
28 | + */ | ||
29 | +class CompilingFailed implements CompletedIntentUpdate { | ||
30 | + | ||
31 | + private final Intent intent; | ||
32 | + | ||
33 | + /** | ||
34 | + * Create an instance from the submitted intent. | ||
35 | + * | ||
36 | + * @param intent submitted intent. | ||
37 | + */ | ||
38 | + CompilingFailed(Intent intent) { | ||
39 | + this.intent = checkNotNull(intent); | ||
40 | + } | ||
41 | + | ||
42 | + @Override | ||
43 | + public Optional<IntentUpdate> execute() { | ||
44 | + return Optional.empty(); | ||
45 | + } | ||
46 | + | ||
47 | + @Override | ||
48 | + public void writeAfterExecution(BatchWrite batchWrite) { | ||
49 | + batchWrite.setState(intent, FAILED); | ||
50 | + batchWrite.removeInstalledIntents(intent.id()); | ||
51 | + } | ||
52 | +} |
... | @@ -626,9 +626,11 @@ public class IntentManager | ... | @@ -626,9 +626,11 @@ public class IntentManager |
626 | // intents with the top-level intent and proceed to install. | 626 | // intents with the top-level intent and proceed to install. |
627 | return Optional.of(new Installing(intent, compileIntent(intent, null))); | 627 | return Optional.of(new Installing(intent, compileIntent(intent, null))); |
628 | } catch (PathNotFoundException e) { | 628 | } catch (PathNotFoundException e) { |
629 | - return Optional.of(new CompilingFailed(intent, e)); | 629 | + log.debug("Path not found for intent {}", intent); |
630 | + return Optional.of(new CompilingFailed(intent)); | ||
630 | } catch (IntentException e) { | 631 | } catch (IntentException e) { |
631 | - return Optional.of(new CompilingFailed(intent, e)); | 632 | + log.warn("Unable to compile intent {} due to:", intent.id(), e); |
633 | + return Optional.of(new CompilingFailed(intent)); | ||
632 | } | 634 | } |
633 | } | 635 | } |
634 | } | 636 | } |
... | @@ -921,34 +923,6 @@ public class IntentManager | ... | @@ -921,34 +923,6 @@ public class IntentManager |
921 | } | 923 | } |
922 | } | 924 | } |
923 | 925 | ||
924 | - private class CompilingFailed implements CompletedIntentUpdate { | ||
925 | - | ||
926 | - private final Intent intent; | ||
927 | - private final IntentException exception; | ||
928 | - | ||
929 | - CompilingFailed(Intent intent, IntentException exception) { | ||
930 | - this.intent = checkNotNull(intent); | ||
931 | - this.exception = checkNotNull(exception); | ||
932 | - } | ||
933 | - | ||
934 | - @Override | ||
935 | - public Optional<IntentUpdate> execute() { | ||
936 | - if (exception instanceof PathNotFoundException) { | ||
937 | - log.debug("Path not found for intent {}", intent); | ||
938 | - } else { | ||
939 | - log.warn("Unable to compile intent {} due to:", intent.id(), exception); | ||
940 | - } | ||
941 | - | ||
942 | - return Optional.empty(); | ||
943 | - } | ||
944 | - | ||
945 | - @Override | ||
946 | - public void writeAfterExecution(BatchWrite batchWrite) { | ||
947 | - batchWrite.setState(intent, FAILED); | ||
948 | - batchWrite.removeInstalledIntents(intent.id()); | ||
949 | - } | ||
950 | - } | ||
951 | - | ||
952 | private class InstallingFailed implements CompletedIntentUpdate { | 926 | private class InstallingFailed implements CompletedIntentUpdate { |
953 | 927 | ||
954 | private final Intent intent; | 928 | private final Intent intent; | ... | ... |
-
Please register or login to post a comment