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 org.onosproject.net.intent.Intent; |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 19 | import org.onosproject.net.intent.IntentData; |
Sho SHIMIZU | 5cb438e | 2015-02-04 13:46:00 -0800 | [diff] [blame] | 20 | import org.onosproject.net.intent.IntentException; |
| 21 | import org.slf4j.Logger; |
| 22 | import org.slf4j.LoggerFactory; |
| 23 | |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 24 | import java.util.List; |
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 | |
| 29 | class Compiling implements IntentUpdate { |
| 30 | |
| 31 | private static final Logger log = LoggerFactory.getLogger(Compiling.class); |
| 32 | |
| 33 | // TODO: define an interface and use it, instead of IntentManager |
| 34 | private final IntentManager intentManager; |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 35 | private final IntentData pending; |
| 36 | private final IntentData current; |
Sho SHIMIZU | 5cb438e | 2015-02-04 13:46:00 -0800 | [diff] [blame] | 37 | |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 38 | Compiling(IntentManager intentManager, IntentData pending, IntentData current) { |
Sho SHIMIZU | 5cb438e | 2015-02-04 13:46:00 -0800 | [diff] [blame] | 39 | this.intentManager = checkNotNull(intentManager); |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 40 | this.pending = checkNotNull(pending); |
| 41 | this.current = current; |
Sho SHIMIZU | 5cb438e | 2015-02-04 13:46:00 -0800 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public Optional<IntentUpdate> execute() { |
| 46 | try { |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 47 | List<Intent> installables = (current != null) ? current.installables() : null; |
| 48 | pending.setInstallables(intentManager.compileIntent(pending.intent(), installables)); |
Brian O'Connor | 7775bda | 2015-02-06 15:01:18 -0800 | [diff] [blame^] | 49 | return Optional.of(new Coordinating(intentManager, pending, current)); |
Sho SHIMIZU | 5cb438e | 2015-02-04 13:46:00 -0800 | [diff] [blame] | 50 | } catch (PathNotFoundException e) { |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 51 | log.debug("Path not found for intent {}", pending.intent()); |
Sho SHIMIZU | 5cb438e | 2015-02-04 13:46:00 -0800 | [diff] [blame] | 52 | // TODO: revisit to implement failure handling |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 53 | return Optional.of(new CompilingFailed(pending)); //FIXME failed state transition |
Sho SHIMIZU | 5cb438e | 2015-02-04 13:46:00 -0800 | [diff] [blame] | 54 | } catch (IntentException e) { |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 55 | log.warn("Unable to compile intent {} due to:", pending.intent().id(), e); |
Sho SHIMIZU | 5cb438e | 2015-02-04 13:46:00 -0800 | [diff] [blame] | 56 | // TODO: revisit to implement failure handling |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 57 | return Optional.of(new CompilingFailed(pending)); //FIXME failed state transition |
Sho SHIMIZU | 5cb438e | 2015-02-04 13:46:00 -0800 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | } |