blob: eef8d0bc8aff2b4a31b8b6586064226532de23ab [file] [log] [blame]
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -08001/*
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 */
16package org.onosproject.net.intent.impl;
17
18import org.onosproject.net.intent.Intent;
Brian O'Connor0e271dc2015-02-04 18:20:25 -080019import org.onosproject.net.intent.IntentData;
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080020import org.onosproject.net.intent.IntentException;
21import org.slf4j.Logger;
22import org.slf4j.LoggerFactory;
23
Brian O'Connor0e271dc2015-02-04 18:20:25 -080024import java.util.List;
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080025import java.util.Optional;
26
27import static com.google.common.base.Preconditions.checkNotNull;
28
29class 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'Connor0e271dc2015-02-04 18:20:25 -080035 private final IntentData pending;
36 private final IntentData current;
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080037
Brian O'Connor0e271dc2015-02-04 18:20:25 -080038 Compiling(IntentManager intentManager, IntentData pending, IntentData current) {
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080039 this.intentManager = checkNotNull(intentManager);
Brian O'Connor0e271dc2015-02-04 18:20:25 -080040 this.pending = checkNotNull(pending);
41 this.current = current;
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080042 }
43
44 @Override
45 public Optional<IntentUpdate> execute() {
46 try {
Brian O'Connor0e271dc2015-02-04 18:20:25 -080047 List<Intent> installables = (current != null) ? current.installables() : null;
48 pending.setInstallables(intentManager.compileIntent(pending.intent(), installables));
Brian O'Connor7775bda2015-02-06 15:01:18 -080049 return Optional.of(new Coordinating(intentManager, pending, current));
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080050 } catch (PathNotFoundException e) {
Brian O'Connor0e271dc2015-02-04 18:20:25 -080051 log.debug("Path not found for intent {}", pending.intent());
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080052 // TODO: revisit to implement failure handling
Brian O'Connor0e271dc2015-02-04 18:20:25 -080053 return Optional.of(new CompilingFailed(pending)); //FIXME failed state transition
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080054 } catch (IntentException e) {
Brian O'Connor0e271dc2015-02-04 18:20:25 -080055 log.warn("Unable to compile intent {} due to:", pending.intent().id(), e);
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080056 // TODO: revisit to implement failure handling
Brian O'Connor0e271dc2015-02-04 18:20:25 -080057 return Optional.of(new CompilingFailed(pending)); //FIXME failed state transition
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080058 }
59 }
60}