blob: fe10074c37ea09363ab08ced340ca3c2ca0eb8ff [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present 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
Yuta HIGUCHI82e53262014-11-27 10:28:51 -080019import com.google.common.base.MoreObjects;
Madan Jampani117aaae2014-10-23 10:04:05 -070020import com.google.common.collect.ImmutableSet;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080021import org.onosproject.net.DeviceId;
alshabib193525b2014-10-08 18:58:03 -070022
Jonathan Hartd0ba2172015-02-11 13:54:33 -080023import java.util.Collections;
24import java.util.Set;
25
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
Jonathan Hartd0ba2172015-02-11 13:54:33 -080057 * @param deviceId the device this operation completed for
Brian O'Connorfa81eae2014-10-30 13:20:05 -070058 */
Brian O'Connor72cb19a2015-01-16 16:14:41 -080059 public CompletedBatchOperation(boolean success, Set<? extends FlowRule> failures,
60 DeviceId deviceId) {
alshabib193525b2014-10-08 18:58:03 -070061 this.success = success;
Madan Jampani117aaae2014-10-23 10:04:05 -070062 this.failures = ImmutableSet.copyOf(failures);
Brian O'Connor427a1762014-11-19 18:40:32 -080063 this.failedIds = Collections.emptySet();
Brian O'Connor72cb19a2015-01-16 16:14:41 -080064 this.deviceId = deviceId;
alshabib193525b2014-10-08 18:58:03 -070065 }
66
Brian O'Connor427a1762014-11-19 18:40:32 -080067
68
alshabib193525b2014-10-08 18:58:03 -070069 @Override
70 public boolean isSuccess() {
71 return success;
72 }
73
74 @Override
Yuta HIGUCHI4b524442014-10-28 22:23:57 -070075 public Set<FlowRule> failedItems() {
alshabib193525b2014-10-08 18:58:03 -070076 return failures;
77 }
alshabib902d41b2014-10-07 16:52:05 -070078
Brian O'Connor427a1762014-11-19 18:40:32 -080079 public Set<Long> failedIds() {
80 return failedIds;
81 }
82
Brian O'Connor72cb19a2015-01-16 16:14:41 -080083 public DeviceId deviceId() {
84 return this.deviceId;
85 }
86
Yuta HIGUCHI82e53262014-11-27 10:28:51 -080087 @Override
88 public String toString() {
89 return MoreObjects.toStringHelper(getClass())
90 .add("success?", success)
91 .add("failedItems", failures)
92 .add("failedIds", failedIds)
Brian O'Connor72cb19a2015-01-16 16:14:41 -080093 .add("deviceId", deviceId)
Yuta HIGUCHI82e53262014-11-27 10:28:51 -080094 .toString();
95 }
alshabib902d41b2014-10-07 16:52:05 -070096}