blob: e21b2fa79e09094906b08edabc63def6a72c64ce [file] [log] [blame]
Brian O'Connor7775bda2015-02-06 15:01:18 -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.flow.FlowRuleOperations;
19import org.onosproject.net.intent.IntentData;
20import org.slf4j.Logger;
21import org.slf4j.LoggerFactory;
22
23import java.util.Optional;
24
25import static com.google.common.base.Preconditions.checkNotNull;
26
Sho SHIMIZU37a24a82015-02-09 09:12:21 -080027/**
28 * Represents a phase to create a {@link FlowRuleOperations} instance
29 * with using registered intent installers.
30 */
31class InstallCoordinating implements IntentUpdate {
Brian O'Connor7775bda2015-02-06 15:01:18 -080032
Sho SHIMIZU37a24a82015-02-09 09:12:21 -080033 private static final Logger log = LoggerFactory.getLogger(InstallCoordinating.class);
Brian O'Connor7775bda2015-02-06 15:01:18 -080034
35 private final IntentManager intentManager;
36 private final IntentData pending;
37 private final IntentData current;
38
39 // TODO: define an interface and use it, instead of IntentManager
Sho SHIMIZU37a24a82015-02-09 09:12:21 -080040 InstallCoordinating(IntentManager intentManager, IntentData pending, IntentData current) {
Brian O'Connor7775bda2015-02-06 15:01:18 -080041 this.intentManager = checkNotNull(intentManager);
42 this.pending = checkNotNull(pending);
43 this.current = current;
44 }
45
46 @Override
47 public Optional<IntentUpdate> execute() {
48 try {
49 FlowRuleOperations flowRules = intentManager.coordinate(pending);
50 return Optional.of(new Installing(intentManager, pending, flowRules));
51 } catch (FlowRuleBatchOperationConversionException e) {
52 log.warn("Unable to install intent {} due to:", pending.intent().id(), e.getCause());
53 return Optional.of(new InstallingFailed(pending)); //FIXME
54 }
55 }
56}