blob: cd8a1859b3a4a9332c8f161db1dce8acd4e9886c [file] [log] [blame]
Yoonseon Han096cea02017-05-15 15:10:41 -07001/*
2 * Copyright 2017-present Open Networking Foundation
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
17package org.onosproject.incubator.net.virtual.impl.intent.phase;
18
19import org.onosproject.incubator.net.virtual.NetworkId;
20import org.onosproject.incubator.net.virtual.impl.intent.VirtualIntentProcessor;
21import org.onosproject.net.intent.IntentData;
22
23import java.util.Optional;
24
25import static com.google.common.base.Preconditions.checkNotNull;
26import static org.onosproject.net.intent.IntentState.INSTALLING;
27
28/**
29 * Represents a phase where an intent is being installed for a virtual network.
30 */
31//FIXME: better way to implement intent phase and processing for virtual networks?
32public class VirtualIntentInstalling extends VirtualFinalIntentProcessPhase {
33
34 private final NetworkId networkId;
35 private final VirtualIntentProcessor processor;
36 private final IntentData data;
37 private final Optional<IntentData> stored;
38
39 /**
40 * Create an installing phase.
41 *
42 * @param networkId virtual network identifier
43 * @param processor intent processor that does work for installing
44 * @param data intent data containing an intent to be installed
45 * @param stored intent data already stored
46 */
47 VirtualIntentInstalling(NetworkId networkId, VirtualIntentProcessor processor,
48 IntentData data,
49 Optional<IntentData> stored) {
50 this.networkId = checkNotNull(networkId);
51 this.processor = checkNotNull(processor);
52 this.data = checkNotNull(data);
53 this.stored = checkNotNull(stored);
54 this.data.setState(INSTALLING);
55 }
56
57 @Override
58 public void preExecute() {
59 processor.apply(networkId, stored, Optional.of(data));
60 }
61
62 @Override
63 public IntentData data() {
64 return data;
65 }
66}