blob: aa5e993185c445eb2da3a31c4678b7e65a7a0b07 [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;
Sho SHIMIZUbb4d8272015-02-12 08:30:26 -080020import org.onosproject.net.intent.IntentException;
21import org.slf4j.Logger;
22import org.slf4j.LoggerFactory;
Brian O'Connor7775bda2015-02-06 15:01:18 -080023
24import java.util.Optional;
25
26import static com.google.common.base.Preconditions.checkNotNull;
27
Sho SHIMIZU37a24a82015-02-09 09:12:21 -080028/**
29 * Represents a phase to create a {@link FlowRuleOperations} instance
30 * with using registered intent installers.
31 */
32class WithdrawCoordinating implements IntentUpdate {
Brian O'Connor7775bda2015-02-06 15:01:18 -080033
Sho SHIMIZUbb4d8272015-02-12 08:30:26 -080034 private static final Logger log = LoggerFactory.getLogger(WithdrawCoordinating.class);
35
Sho SHIMIZU37a24a82015-02-09 09:12:21 -080036 // TODO: define an interface and use it, instead of IntentManager
Brian O'Connor7775bda2015-02-06 15:01:18 -080037 private final IntentManager intentManager;
38 private final IntentData pending;
39 private final IntentData current;
40
Sho SHIMIZU37a24a82015-02-09 09:12:21 -080041 WithdrawCoordinating(IntentManager intentManager, IntentData pending, IntentData current) {
Brian O'Connor7775bda2015-02-06 15:01:18 -080042 this.intentManager = checkNotNull(intentManager);
43 this.pending = checkNotNull(pending);
Sho SHIMIZU6aa4fb42015-02-11 23:33:42 -080044 this.current = checkNotNull(current);
Brian O'Connor7775bda2015-02-06 15:01:18 -080045 }
46
47 @Override
48 public Optional<IntentUpdate> execute() {
Sho SHIMIZUbb4d8272015-02-12 08:30:26 -080049 try {
Brian O'Connore2eac102015-02-12 18:30:22 -080050 // Note: current.installables() are not null or empty due to createIntentUpdate check
Sho SHIMIZUbb4d8272015-02-12 08:30:26 -080051 FlowRuleOperations flowRules = intentManager.uninstallCoordinate(current, pending);
52 pending.setInstallables(current.installables());
53 return Optional.of(new Withdrawing(intentManager, pending, flowRules));
54 } catch (IntentException e) {
55 log.warn("Unable to generate generate a FlowRuleOperations from intent {} due to:", pending.intent(), e);
56 return Optional.of(new WithdrawingFailed(pending));
57 }
Brian O'Connor7775bda2015-02-06 15:01:18 -080058 }
59}