Committed by
Brian O'Connor
Handle exception that is potentially occurred in WithdrawCoordinating
- Introduce a common parent class, AbstractFailed for IntentUpdate subclass representing failure - Write Javadoc for each class representing failure Change-Id: I3945642f5985ddd66c11b6de1924b9c1d23a5fc6
Showing
5 changed files
with
105 additions
and
28 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.IntentData; | ||
19 | + | ||
20 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
21 | +import static org.onosproject.net.intent.IntentState.FAILED; | ||
22 | + | ||
23 | +/** | ||
24 | + * A common parent class of a class representing failure | ||
25 | + * as IntentUpdate subclass. | ||
26 | + */ | ||
27 | +abstract class AbstractFailed extends CompletedIntentUpdate { | ||
28 | + | ||
29 | + private final IntentData intentData; | ||
30 | + | ||
31 | + /** | ||
32 | + * Create an instance with the specified data. | ||
33 | + * | ||
34 | + * @param intentData intentData | ||
35 | + */ | ||
36 | + AbstractFailed(IntentData intentData) { | ||
37 | + this.intentData = checkNotNull(intentData); | ||
38 | + this.intentData.setState(FAILED); | ||
39 | + } | ||
40 | + | ||
41 | + @Override | ||
42 | + public IntentData data() { | ||
43 | + return intentData; | ||
44 | + } | ||
45 | +} |
... | @@ -17,24 +17,17 @@ package org.onosproject.net.intent.impl; | ... | @@ -17,24 +17,17 @@ package org.onosproject.net.intent.impl; |
17 | 17 | ||
18 | import org.onosproject.net.intent.IntentData; | 18 | import org.onosproject.net.intent.IntentData; |
19 | 19 | ||
20 | -import static org.onosproject.net.intent.IntentState.FAILED; | ||
21 | - | ||
22 | /** | 20 | /** |
23 | * Represents a phase where the compile has failed. | 21 | * Represents a phase where the compile has failed. |
24 | */ | 22 | */ |
25 | -class CompilingFailed extends CompletedIntentUpdate { | 23 | +class CompilingFailed extends AbstractFailed { |
26 | - | ||
27 | - private final IntentData intentData; | ||
28 | 24 | ||
25 | + /** | ||
26 | + * Create an instance with the specified data. | ||
27 | + * | ||
28 | + * @param intentData intentData | ||
29 | + */ | ||
29 | CompilingFailed(IntentData intentData) { | 30 | CompilingFailed(IntentData intentData) { |
30 | - this.intentData = intentData; | 31 | + super(intentData); |
31 | - this.intentData.setState(FAILED); | ||
32 | } | 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 | ||
40 | } | 33 | } | ... | ... |
... | @@ -17,21 +17,17 @@ package org.onosproject.net.intent.impl; | ... | @@ -17,21 +17,17 @@ package org.onosproject.net.intent.impl; |
17 | 17 | ||
18 | import org.onosproject.net.intent.IntentData; | 18 | import org.onosproject.net.intent.IntentData; |
19 | 19 | ||
20 | -import static com.google.common.base.Preconditions.checkNotNull; | 20 | +/** |
21 | -import static org.onosproject.net.intent.IntentState.FAILED; | 21 | + * Represent a phase where the install has failed. |
22 | - | 22 | + */ |
23 | -class InstallingFailed extends CompletedIntentUpdate { | 23 | +class InstallingFailed extends AbstractFailed { |
24 | - | ||
25 | - private final IntentData intentData; | ||
26 | 24 | ||
25 | + /** | ||
26 | + * Create an instance with the specified data. | ||
27 | + * | ||
28 | + * @param intentData intentData | ||
29 | + */ | ||
27 | InstallingFailed(IntentData intentData) { | 30 | InstallingFailed(IntentData intentData) { |
28 | - this.intentData = checkNotNull(intentData); | 31 | + super(intentData); |
29 | - this.intentData.setState(FAILED); //FIXME maybe should be "BROKEN" | ||
30 | - //TODO consider adding the flow rule operations here | ||
31 | - } | ||
32 | - | ||
33 | - @Override | ||
34 | - public IntentData data() { | ||
35 | - return intentData; | ||
36 | } | 32 | } |
37 | } | 33 | } | ... | ... |
... | @@ -17,6 +17,9 @@ package org.onosproject.net.intent.impl; | ... | @@ -17,6 +17,9 @@ package org.onosproject.net.intent.impl; |
17 | 17 | ||
18 | import org.onosproject.net.flow.FlowRuleOperations; | 18 | import org.onosproject.net.flow.FlowRuleOperations; |
19 | import org.onosproject.net.intent.IntentData; | 19 | import org.onosproject.net.intent.IntentData; |
20 | +import org.onosproject.net.intent.IntentException; | ||
21 | +import org.slf4j.Logger; | ||
22 | +import org.slf4j.LoggerFactory; | ||
20 | 23 | ||
21 | import java.util.Optional; | 24 | import java.util.Optional; |
22 | 25 | ||
... | @@ -28,6 +31,8 @@ import static com.google.common.base.Preconditions.checkNotNull; | ... | @@ -28,6 +31,8 @@ import static com.google.common.base.Preconditions.checkNotNull; |
28 | */ | 31 | */ |
29 | class WithdrawCoordinating implements IntentUpdate { | 32 | class WithdrawCoordinating implements IntentUpdate { |
30 | 33 | ||
34 | + private static final Logger log = LoggerFactory.getLogger(WithdrawCoordinating.class); | ||
35 | + | ||
31 | // TODO: define an interface and use it, instead of IntentManager | 36 | // TODO: define an interface and use it, instead of IntentManager |
32 | private final IntentManager intentManager; | 37 | private final IntentManager intentManager; |
33 | private final IntentData pending; | 38 | private final IntentData pending; |
... | @@ -41,8 +46,13 @@ class WithdrawCoordinating implements IntentUpdate { | ... | @@ -41,8 +46,13 @@ class WithdrawCoordinating implements IntentUpdate { |
41 | 46 | ||
42 | @Override | 47 | @Override |
43 | public Optional<IntentUpdate> execute() { | 48 | public Optional<IntentUpdate> execute() { |
49 | + try { | ||
44 | FlowRuleOperations flowRules = intentManager.uninstallCoordinate(current, pending); | 50 | FlowRuleOperations flowRules = intentManager.uninstallCoordinate(current, pending); |
45 | pending.setInstallables(current.installables()); | 51 | pending.setInstallables(current.installables()); |
46 | return Optional.of(new Withdrawing(intentManager, pending, flowRules)); | 52 | return Optional.of(new Withdrawing(intentManager, pending, flowRules)); |
53 | + } catch (IntentException e) { | ||
54 | + log.warn("Unable to generate generate a FlowRuleOperations from intent {} due to:", pending.intent(), e); | ||
55 | + return Optional.of(new WithdrawingFailed(pending)); | ||
56 | + } | ||
47 | } | 57 | } |
48 | } | 58 | } | ... | ... |
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.IntentData; | ||
19 | + | ||
20 | +/** | ||
21 | + * Represents a phase where the withdraw has failed. | ||
22 | + */ | ||
23 | +class WithdrawingFailed extends AbstractFailed { | ||
24 | + | ||
25 | + /** | ||
26 | + * Create an instance with the specified data. | ||
27 | + * | ||
28 | + * @param intentData intentData | ||
29 | + */ | ||
30 | + WithdrawingFailed(IntentData intentData) { | ||
31 | + super(intentData); | ||
32 | + } | ||
33 | +} |
-
Please register or login to post a comment