blob: fce7ee936025a0801b6f0d09ce0159207b16168e [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska83e090e2014-10-22 14:25:35 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
Thomas Vachuska83e090e2014-10-22 14:25:35 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Thomas Vachuska83e090e2014-10-22 14:25:35 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.flow;
alshabib902d41b2014-10-07 16:52:05 -070017
Brian O'Connor427a1762014-11-19 18:40:32 -080018
19import java.util.Collections;
Madan Jampani117aaae2014-10-23 10:04:05 -070020import java.util.Set;
alshabib193525b2014-10-08 18:58:03 -070021
Yuta HIGUCHI82e53262014-11-27 10:28:51 -080022import com.google.common.base.MoreObjects;
Madan Jampani117aaae2014-10-23 10:04:05 -070023import com.google.common.collect.ImmutableSet;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080024import org.onosproject.net.DeviceId;
alshabib193525b2014-10-08 18:58:03 -070025
Brian O'Connorfa81eae2014-10-30 13:20:05 -070026/**
27 * Representation of a completed flow rule batch operation.
28 */
Yuta HIGUCHI4b524442014-10-28 22:23:57 -070029public class CompletedBatchOperation implements BatchOperationResult<FlowRule> {
alshabib193525b2014-10-08 18:58:03 -070030
alshabib193525b2014-10-08 18:58:03 -070031 private final boolean success;
Yuta HIGUCHI4b524442014-10-28 22:23:57 -070032 private final Set<FlowRule> failures;
Brian O'Connor427a1762014-11-19 18:40:32 -080033 private final Set<Long> failedIds;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080034 private final DeviceId deviceId;
Brian O'Connor427a1762014-11-19 18:40:32 -080035
36 /**
37 * Creates a new batch completion result.
38 *
Brian O'Connor72cb19a2015-01-16 16:14:41 -080039 * @param success indicates whether the completion is successful
Brian O'Connor427a1762014-11-19 18:40:32 -080040 * @param failures set of any failures encountered
41 * @param failedIds (optional) set of failed operation ids
Brian O'Connor72cb19a2015-01-16 16:14:41 -080042 * @param deviceId the device this operation completed for
Brian O'Connor427a1762014-11-19 18:40:32 -080043 */
44 public CompletedBatchOperation(boolean success, Set<? extends FlowRule> failures,
Brian O'Connor72cb19a2015-01-16 16:14:41 -080045 Set<Long> failedIds, DeviceId deviceId) {
Brian O'Connor427a1762014-11-19 18:40:32 -080046 this.success = success;
47 this.failures = ImmutableSet.copyOf(failures);
48 this.failedIds = ImmutableSet.copyOf(failedIds);
Brian O'Connor72cb19a2015-01-16 16:14:41 -080049 this.deviceId = deviceId;
Brian O'Connor427a1762014-11-19 18:40:32 -080050 }
alshabib193525b2014-10-08 18:58:03 -070051
Brian O'Connorfa81eae2014-10-30 13:20:05 -070052 /**
53 * Creates a new batch completion result.
54 *
55 * @param success indicates whether the completion is successful.
56 * @param failures set of any failures encountered
57 */
Brian O'Connor72cb19a2015-01-16 16:14:41 -080058 public CompletedBatchOperation(boolean success, Set<? extends FlowRule> failures,
59 DeviceId deviceId) {
alshabib193525b2014-10-08 18:58:03 -070060 this.success = success;
Madan Jampani117aaae2014-10-23 10:04:05 -070061 this.failures = ImmutableSet.copyOf(failures);
Brian O'Connor427a1762014-11-19 18:40:32 -080062 this.failedIds = Collections.emptySet();
Brian O'Connor72cb19a2015-01-16 16:14:41 -080063 this.deviceId = deviceId;
alshabib193525b2014-10-08 18:58:03 -070064 }
65
Brian O'Connor427a1762014-11-19 18:40:32 -080066
67
alshabib193525b2014-10-08 18:58:03 -070068 @Override
69 public boolean isSuccess() {
70 return success;
71 }
72
73 @Override
Yuta HIGUCHI4b524442014-10-28 22:23:57 -070074 public Set<FlowRule> failedItems() {
alshabib193525b2014-10-08 18:58:03 -070075 return failures;
76 }
alshabib902d41b2014-10-07 16:52:05 -070077
Brian O'Connor427a1762014-11-19 18:40:32 -080078 public Set<Long> failedIds() {
79 return failedIds;
80 }
81
Brian O'Connor72cb19a2015-01-16 16:14:41 -080082 public DeviceId deviceId() {
83 return this.deviceId;
84 }
85
Yuta HIGUCHI82e53262014-11-27 10:28:51 -080086 @Override
87 public String toString() {
88 return MoreObjects.toStringHelper(getClass())
89 .add("success?", success)
90 .add("failedItems", failures)
91 .add("failedIds", failedIds)
Brian O'Connor72cb19a2015-01-16 16:14:41 -080092 .add("deviceId", deviceId)
Yuta HIGUCHI82e53262014-11-27 10:28:51 -080093 .toString();
94 }
alshabib902d41b2014-10-07 16:52:05 -070095}