blob: 316821b7262f26355260233f2ee1370d237ef759 [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
18import com.google.common.collect.ImmutableList;
19import org.onosproject.net.flow.FlowRuleBatchOperation;
20import org.onosproject.net.intent.Intent;
21import org.onosproject.net.intent.IntentState;
22
23import java.util.LinkedList;
24import java.util.List;
25
26import static com.google.common.base.Preconditions.checkNotNull;
27import static org.onosproject.net.intent.IntentState.FAILED;
28import static org.onosproject.net.intent.IntentState.INSTALLING;
29
30class Installed implements CompletedIntentUpdate {
31
32 // TODO: define an interface and use it, instead of IntentManager
33 private final IntentManager intentManager;
34 private final Intent intent;
35 private final List<Intent> installables;
36 private IntentState intentState;
37 private final List<FlowRuleBatchOperation> batches;
38 private int currentBatch = 0;
39
40 Installed(IntentManager intentManager,
41 Intent intent, List<Intent> installables, List<FlowRuleBatchOperation> batches) {
42 this.intentManager = checkNotNull(intentManager);
43 this.intent = checkNotNull(intent);
44 this.installables = ImmutableList.copyOf(checkNotNull(installables));
45 this.batches = new LinkedList<>(checkNotNull(batches));
46 this.intentState = INSTALLING;
47 }
48
49 @Override
50 public void batchSuccess() {
51 currentBatch++;
52 }
53
54 @Override
55 public List<Intent> allInstallables() {
56 return installables;
57 }
58
59 @Override
60 public FlowRuleBatchOperation currentBatch() {
61 return currentBatch < batches.size() ? batches.get(currentBatch) : null;
62 }
63
64 @Override
65 public void batchFailed() {
66 for (int i = batches.size() - 1; i >= currentBatch; i--) {
67 batches.remove(i);
68 }
69 intentState = FAILED;
70 batches.addAll(intentManager.uninstallIntent(intent, installables));
71
72 // TODO we might want to try to recompile the new intent
73 }
74}