blob: 1ed42fd5d4e5a45067405f04f7859b45f033234e [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
23/**
24 * Represents a phase of processing an intent.
25 */
Sho SHIMIZU36a8a6e2015-02-13 15:38:45 -080026public interface IntentProcessPhase {
Sho SHIMIZUbdc17e72015-01-27 17:46:41 -080027
28 /**
29 * Execute the procedure represented by the instance
30 * and generates the next update instance.
31 *
32 * @return next update
33 */
Sho SHIMIZU36a8a6e2015-02-13 15:38:45 -080034 Optional<IntentProcessPhase> execute();
Sho SHIMIZUce49b602015-02-23 19:15:49 -080035
36 /**
37 * Create a starting intent process phase according to intent data this class holds.
38 *
39 * @param processor intent processor to be passed to intent process phases
40 * generated while this instance is working
41 * @param data intent data to be processed
42 * @param current intent date that is stored in the store
43 * @return starting intent process phase
44 */
45 static IntentProcessPhase newInitialPhase(IntentProcessor processor,
46 IntentData data, IntentData current) {
Brian O'Connorf0c5a052015-04-27 00:34:53 -070047 switch (data.request()) {
Sho SHIMIZUce49b602015-02-23 19:15:49 -080048 case INSTALL_REQ:
49 return new InstallRequest(processor, data, Optional.ofNullable(current));
50 case WITHDRAW_REQ:
Brian O'Connorf0c5a052015-04-27 00:34:53 -070051 return new WithdrawRequest(processor, data, Optional.ofNullable(current));
Ray Milkey8c6d00e2015-03-13 14:14:34 -070052 case PURGE_REQ:
53 return new PurgeRequest(data, current);
Sho SHIMIZUce49b602015-02-23 19:15:49 -080054 default:
55 // illegal state
Brian O'Connorf0c5a052015-04-27 00:34:53 -070056 return new Failed(data);
Sho SHIMIZUce49b602015-02-23 19:15:49 -080057 }
58 }
59
Sho SHIMIZUbdc17e72015-01-27 17:46:41 -080060}