Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -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.phase; |
| 17 | |
| 18 | import org.onosproject.net.intent.Intent; |
| 19 | import org.onosproject.net.intent.IntentData; |
Ray Milkey | fd7931d | 2015-03-30 13:58:38 -0700 | [diff] [blame^] | 20 | import org.onosproject.net.intent.IntentException; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 21 | import org.onosproject.net.intent.impl.IntentProcessor; |
Ray Milkey | fd7931d | 2015-03-30 13:58:38 -0700 | [diff] [blame^] | 22 | import org.slf4j.Logger; |
| 23 | import org.slf4j.LoggerFactory; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 24 | |
| 25 | import java.util.List; |
| 26 | import java.util.Optional; |
| 27 | |
| 28 | import static com.google.common.base.Preconditions.checkNotNull; |
| 29 | |
| 30 | /** |
| 31 | * Represents a phase where an intent is being recompiled. |
| 32 | */ |
| 33 | class Recompiling implements IntentProcessPhase { |
| 34 | |
Ray Milkey | fd7931d | 2015-03-30 13:58:38 -0700 | [diff] [blame^] | 35 | private static final Logger log = LoggerFactory.getLogger(Recompiling.class); |
| 36 | |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 37 | private final IntentProcessor processor; |
| 38 | private final IntentData data; |
| 39 | private final IntentData stored; |
| 40 | |
| 41 | /** |
| 42 | * Creates a intent recompiling phase. |
| 43 | * |
| 44 | * @param processor intent processor that does work for recompiling |
| 45 | * @param data intent data containing an intent to be recompiled |
| 46 | * @param stored intent data stored in the store |
| 47 | */ |
| 48 | Recompiling(IntentProcessor processor, IntentData data, IntentData stored) { |
| 49 | this.processor = checkNotNull(processor); |
| 50 | this.data = checkNotNull(data); |
| 51 | this.stored = checkNotNull(stored); |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public Optional<IntentProcessPhase> execute() { |
Ray Milkey | fd7931d | 2015-03-30 13:58:38 -0700 | [diff] [blame^] | 56 | try { |
| 57 | List<Intent> compiled = processor.compile(data.intent(), stored.installables()); |
| 58 | data.setInstallables(compiled); |
| 59 | return Optional.of(new Installing(processor, data, stored)); |
| 60 | } catch (IntentException e) { |
| 61 | log.debug("Unable to recompile intent {} due to: {}", data.intent(), e); |
| 62 | // FIXME we need to removed orphaned flows and deallocate resources |
| 63 | return Optional.of(new CompileFailed(data)); |
| 64 | } |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 65 | } |
| 66 | } |