blob: 205345c7eb6b02f546b744e53f868d335d8487ca [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
Brian O'Connor0e271dc2015-02-04 18:20:25 -080018import org.onosproject.net.flow.FlowRuleOperations;
19import org.onosproject.net.intent.IntentData;
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080020import org.slf4j.Logger;
21import org.slf4j.LoggerFactory;
22
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080023import 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 of installing an intent with calling
29 * {@link org.onosproject.net.flow.FlowRuleService}.
30 */
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080031class Installing implements IntentUpdate {
32
33 private static final Logger log = LoggerFactory.getLogger(Installing.class);
34
35 private final IntentManager intentManager;
Brian O'Connor0e271dc2015-02-04 18:20:25 -080036 private final IntentData pending;
Brian O'Connor7775bda2015-02-06 15:01:18 -080037 private final FlowRuleOperations flowRules;
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080038
39 // TODO: define an interface and use it, instead of IntentManager
Brian O'Connor7775bda2015-02-06 15:01:18 -080040 Installing(IntentManager intentManager, IntentData pending, FlowRuleOperations flowRules) {
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080041 this.intentManager = checkNotNull(intentManager);
Brian O'Connor0e271dc2015-02-04 18:20:25 -080042 this.pending = checkNotNull(pending);
Brian O'Connor7775bda2015-02-06 15:01:18 -080043 this.flowRules = flowRules;
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080044 }
45
46 @Override
47 public Optional<IntentUpdate> execute() {
48 try {
Brian O'Connor7775bda2015-02-06 15:01:18 -080049 intentManager.flowRuleService.apply(flowRules); // FIXME we need to provide a context
Brian O'Connor0e271dc2015-02-04 18:20:25 -080050 return Optional.of(new Installed(pending));
Brian O'Connor098da072015-02-04 14:07:59 -080051 } catch (FlowRuleBatchOperationConversionException e) {
Brian O'Connor0e271dc2015-02-04 18:20:25 -080052 log.warn("Unable to install intent {} due to:", pending.intent().id(), e.getCause());
53 return Optional.of(new InstallingFailed(pending));
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080054 }
55 }
56}