blob: 0a7a5c4247bb0b38a13882672f839af71f4b62ab [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;
21
22import java.util.LinkedList;
23import java.util.List;
24
25import static com.google.common.base.Preconditions.checkNotNull;
26
27class InstallingFailed implements CompletedIntentUpdate {
28
29 private IntentManager intentManager;
30 private final Intent intent;
31 private final List<Intent> installables;
32 private final List<FlowRuleBatchOperation> batches;
33 private int currentBatch = 0;
34
35 InstallingFailed(IntentManager intentManager,
36 Intent intent, List<Intent> installables, List<FlowRuleBatchOperation> batches) {
37 this.intentManager = intentManager;
38 this.intent = checkNotNull(intent);
39 this.installables = ImmutableList.copyOf(checkNotNull(installables));
40 this.batches = new LinkedList<>(checkNotNull(batches));
41 }
42
43 @Override
44 public List<Intent> allInstallables() {
45 return installables;
46 }
47
48 @Override
49 public void batchSuccess() {
50 currentBatch++;
51 }
52
53 @Override
54 public FlowRuleBatchOperation currentBatch() {
55 return currentBatch < batches.size() ? batches.get(currentBatch) : null;
56 }
57
58 @Override
59 public void batchFailed() {
60 for (int i = batches.size() - 1; i >= currentBatch; i--) {
61 batches.remove(i);
62 }
63 batches.addAll(intentManager.uninstallIntent(intent, installables));
64
65 // TODO we might want to try to recompile the new intent
66 }
67}