Sho SHIMIZU | 5cb438e | 2015-02-04 13:46:00 -0800 | [diff] [blame] | 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 | */ |
Sho SHIMIZU | 36a8a6e | 2015-02-13 15:38:45 -0800 | [diff] [blame^] | 16 | package org.onosproject.net.intent.impl.phase; |
Sho SHIMIZU | 5cb438e | 2015-02-04 13:46:00 -0800 | [diff] [blame] | 17 | |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 18 | import org.onosproject.net.flow.FlowRuleOperations; |
| 19 | import org.onosproject.net.intent.IntentData; |
Sho SHIMIZU | b5cd581 | 2015-02-09 14:25:13 -0800 | [diff] [blame] | 20 | import org.onosproject.net.intent.IntentException; |
Sho SHIMIZU | 36a8a6e | 2015-02-13 15:38:45 -0800 | [diff] [blame^] | 21 | import org.onosproject.net.intent.impl.IntentManager; |
Sho SHIMIZU | 5cb438e | 2015-02-04 13:46:00 -0800 | [diff] [blame] | 22 | import org.slf4j.Logger; |
| 23 | import org.slf4j.LoggerFactory; |
| 24 | |
Sho SHIMIZU | 5cb438e | 2015-02-04 13:46:00 -0800 | [diff] [blame] | 25 | import java.util.Optional; |
| 26 | |
| 27 | import static com.google.common.base.Preconditions.checkNotNull; |
| 28 | |
Sho SHIMIZU | 37a24a8 | 2015-02-09 09:12:21 -0800 | [diff] [blame] | 29 | /** |
| 30 | * Represents a phase of installing an intent with calling |
| 31 | * {@link org.onosproject.net.flow.FlowRuleService}. |
| 32 | */ |
Sho SHIMIZU | 36a8a6e | 2015-02-13 15:38:45 -0800 | [diff] [blame^] | 33 | final class Installing implements IntentProcessPhase { |
Sho SHIMIZU | 5cb438e | 2015-02-04 13:46:00 -0800 | [diff] [blame] | 34 | |
| 35 | private static final Logger log = LoggerFactory.getLogger(Installing.class); |
| 36 | |
| 37 | private final IntentManager intentManager; |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 38 | private final IntentData pending; |
Brian O'Connor | 7775bda | 2015-02-06 15:01:18 -0800 | [diff] [blame] | 39 | private final FlowRuleOperations flowRules; |
Sho SHIMIZU | 5cb438e | 2015-02-04 13:46:00 -0800 | [diff] [blame] | 40 | |
| 41 | // TODO: define an interface and use it, instead of IntentManager |
Brian O'Connor | 7775bda | 2015-02-06 15:01:18 -0800 | [diff] [blame] | 42 | Installing(IntentManager intentManager, IntentData pending, FlowRuleOperations flowRules) { |
Sho SHIMIZU | 5cb438e | 2015-02-04 13:46:00 -0800 | [diff] [blame] | 43 | this.intentManager = checkNotNull(intentManager); |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 44 | this.pending = checkNotNull(pending); |
Brian O'Connor | 7775bda | 2015-02-06 15:01:18 -0800 | [diff] [blame] | 45 | this.flowRules = flowRules; |
Sho SHIMIZU | 5cb438e | 2015-02-04 13:46:00 -0800 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | @Override |
Sho SHIMIZU | 36a8a6e | 2015-02-13 15:38:45 -0800 | [diff] [blame^] | 49 | public Optional<IntentProcessPhase> execute() { |
Sho SHIMIZU | 5cb438e | 2015-02-04 13:46:00 -0800 | [diff] [blame] | 50 | try { |
Brian O'Connor | 7775bda | 2015-02-06 15:01:18 -0800 | [diff] [blame] | 51 | intentManager.flowRuleService.apply(flowRules); // FIXME we need to provide a context |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 52 | return Optional.of(new Installed(pending)); |
Sho SHIMIZU | b5cd581 | 2015-02-09 14:25:13 -0800 | [diff] [blame] | 53 | // What kinds of exceptions are thrown by FlowRuleService.apply()? |
| 54 | // Is IntentException a correct exception abstraction? |
| 55 | } catch (IntentException e) { |
| 56 | log.warn("Unable to install intent {} due to: {}", pending.intent().id(), e); |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 57 | return Optional.of(new InstallingFailed(pending)); |
Sho SHIMIZU | 5cb438e | 2015-02-04 13:46:00 -0800 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | } |