blob: 5f7412bc966e1474ab1dbfd23379cbbeee147df8 [file] [log] [blame]
Sho SHIMIZUbdc17e72015-01-27 17:46:41 -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 */
Sho SHIMIZU36a8a6e2015-02-13 15:38:45 -080016package org.onosproject.net.intent.impl.phase;
Sho SHIMIZUbdc17e72015-01-27 17:46:41 -080017
Sho SHIMIZUce49b602015-02-23 19:15:49 -080018import org.onosproject.net.intent.IntentData;
19import org.onosproject.net.intent.impl.IntentProcessor;
20
Sho SHIMIZUbdc17e72015-01-27 17:46:41 -080021import java.util.Optional;
22
Sho SHIMIZUce49b602015-02-23 19:15:49 -080023import static org.onlab.util.Tools.isNullOrEmpty;
24import static org.onosproject.net.intent.IntentState.WITHDRAWN;
25
Sho SHIMIZUbdc17e72015-01-27 17:46:41 -080026/**
27 * Represents a phase of processing an intent.
28 */
Sho SHIMIZU36a8a6e2015-02-13 15:38:45 -080029public interface IntentProcessPhase {
Sho SHIMIZUbdc17e72015-01-27 17:46:41 -080030
31 /**
32 * Execute the procedure represented by the instance
33 * and generates the next update instance.
34 *
35 * @return next update
36 */
Sho SHIMIZU36a8a6e2015-02-13 15:38:45 -080037 Optional<IntentProcessPhase> execute();
Sho SHIMIZUce49b602015-02-23 19:15:49 -080038
39 /**
40 * Create a starting intent process phase according to intent data this class holds.
41 *
42 * @param processor intent processor to be passed to intent process phases
43 * generated while this instance is working
44 * @param data intent data to be processed
45 * @param current intent date that is stored in the store
46 * @return starting intent process phase
47 */
48 static IntentProcessPhase newInitialPhase(IntentProcessor processor,
49 IntentData data, IntentData current) {
50 switch (data.state()) {
51 case INSTALL_REQ:
52 return new InstallRequest(processor, data, Optional.ofNullable(current));
53 case WITHDRAW_REQ:
54 if (current == null || isNullOrEmpty(current.installables())) {
55 return new Withdrawn(data, WITHDRAWN);
56 } else {
57 return new WithdrawRequest(processor, data, current);
58 }
59 default:
60 // illegal state
61 return new CompilingFailed(data);
62 }
63 }
64
Sho SHIMIZUbdc17e72015-01-27 17:46:41 -080065}