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 | */ |
| 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 | } |