alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.store.group.impl; |
| 17 | |
Jonathan Hart | 6ec029a | 2015-03-24 17:12:35 -0700 | [diff] [blame] | 18 | import com.google.common.collect.FluentIterable; |
Charles Chan | f4838a7 | 2015-12-07 18:13:45 -0800 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableSet; |
Jonathan Hart | 6ec029a | 2015-03-24 17:12:35 -0700 | [diff] [blame] | 20 | import com.google.common.collect.Iterables; |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 21 | import com.google.common.collect.Sets; |
Srikanth Vavilapalli | 10e75cd | 2015-04-13 16:21:24 -0700 | [diff] [blame] | 22 | |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 23 | import org.apache.felix.scr.annotations.Activate; |
| 24 | import org.apache.felix.scr.annotations.Component; |
| 25 | import org.apache.felix.scr.annotations.Deactivate; |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 26 | import org.apache.felix.scr.annotations.Reference; |
| 27 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 28 | import org.apache.felix.scr.annotations.Service; |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 29 | import org.onlab.util.KryoNamespace; |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 30 | import org.onlab.util.NewConcurrentHashMap; |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 31 | import org.onosproject.cluster.ClusterService; |
Charles Chan | f4838a7 | 2015-12-07 18:13:45 -0800 | [diff] [blame] | 32 | import org.onosproject.cluster.NodeId; |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 33 | import org.onosproject.core.DefaultGroupId; |
| 34 | import org.onosproject.core.GroupId; |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 35 | import org.onosproject.mastership.MastershipService; |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 36 | import org.onosproject.net.DeviceId; |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 37 | import org.onosproject.net.MastershipRole; |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 38 | import org.onosproject.net.group.DefaultGroup; |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 39 | import org.onosproject.net.group.DefaultGroupBucket; |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 40 | import org.onosproject.net.group.DefaultGroupDescription; |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 41 | import org.onosproject.net.group.DefaultGroupKey; |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 42 | import org.onosproject.net.group.Group; |
| 43 | import org.onosproject.net.group.Group.GroupState; |
| 44 | import org.onosproject.net.group.GroupBucket; |
| 45 | import org.onosproject.net.group.GroupBuckets; |
| 46 | import org.onosproject.net.group.GroupDescription; |
| 47 | import org.onosproject.net.group.GroupEvent; |
| 48 | import org.onosproject.net.group.GroupEvent.Type; |
| 49 | import org.onosproject.net.group.GroupKey; |
| 50 | import org.onosproject.net.group.GroupOperation; |
| 51 | import org.onosproject.net.group.GroupStore; |
| 52 | import org.onosproject.net.group.GroupStoreDelegate; |
Srikanth Vavilapalli | 10e75cd | 2015-04-13 16:21:24 -0700 | [diff] [blame] | 53 | import org.onosproject.net.group.StoredGroupBucketEntry; |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 54 | import org.onosproject.net.group.StoredGroupEntry; |
| 55 | import org.onosproject.store.AbstractStore; |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 56 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; |
Jonathan Hart | 63939a3 | 2015-05-08 11:57:03 -0700 | [diff] [blame] | 57 | import org.onosproject.store.service.MultiValuedTimestamp; |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 58 | import org.onosproject.store.serializers.KryoNamespaces; |
Madan Jampani | 0b84753 | 2016-03-03 13:44:15 -0800 | [diff] [blame] | 59 | import org.onosproject.store.service.ConsistentMap; |
| 60 | import org.onosproject.store.service.MapEvent; |
| 61 | import org.onosproject.store.service.MapEventListener; |
| 62 | import org.onosproject.store.service.Serializer; |
Jonathan Hart | 6ec029a | 2015-03-24 17:12:35 -0700 | [diff] [blame] | 63 | import org.onosproject.store.service.StorageService; |
Madan Jampani | 0b84753 | 2016-03-03 13:44:15 -0800 | [diff] [blame] | 64 | import org.onosproject.store.service.Versioned; |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 65 | import org.slf4j.Logger; |
| 66 | |
Jonathan Hart | 6ec029a | 2015-03-24 17:12:35 -0700 | [diff] [blame] | 67 | import java.util.ArrayList; |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 68 | import java.util.Collection; |
Charles Chan | f4838a7 | 2015-12-07 18:13:45 -0800 | [diff] [blame] | 69 | import java.util.Collections; |
Jonathan Hart | 6ec029a | 2015-03-24 17:12:35 -0700 | [diff] [blame] | 70 | import java.util.HashMap; |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 71 | import java.util.HashSet; |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 72 | import java.util.Iterator; |
Jonathan Hart | 6ec029a | 2015-03-24 17:12:35 -0700 | [diff] [blame] | 73 | import java.util.List; |
Madan Jampani | 0b84753 | 2016-03-03 13:44:15 -0800 | [diff] [blame] | 74 | import java.util.Map; |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 75 | import java.util.Map.Entry; |
Jonathan Hart | 6ec029a | 2015-03-24 17:12:35 -0700 | [diff] [blame] | 76 | import java.util.Objects; |
Sho SHIMIZU | 30d639b | 2015-05-05 09:30:35 -0700 | [diff] [blame] | 77 | import java.util.Optional; |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 78 | import java.util.Set; |
Jonathan Hart | 6ec029a | 2015-03-24 17:12:35 -0700 | [diff] [blame] | 79 | import java.util.concurrent.ConcurrentHashMap; |
| 80 | import java.util.concurrent.ConcurrentMap; |
| 81 | import java.util.concurrent.ExecutorService; |
| 82 | import java.util.concurrent.Executors; |
| 83 | import java.util.concurrent.atomic.AtomicInteger; |
Jonathan Hart | 6ec029a | 2015-03-24 17:12:35 -0700 | [diff] [blame] | 84 | import java.util.stream.Collectors; |
| 85 | |
| 86 | import static org.apache.commons.lang3.concurrent.ConcurrentUtils.createIfAbsentUnchecked; |
| 87 | import static org.onlab.util.Tools.groupedThreads; |
| 88 | import static org.slf4j.LoggerFactory.getLogger; |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 89 | |
| 90 | /** |
Saurav Das | 0fd79d9 | 2016-03-07 10:58:36 -0800 | [diff] [blame^] | 91 | * Manages inventory of group entries using distributed group stores from the |
| 92 | * storage service. |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 93 | */ |
| 94 | @Component(immediate = true) |
| 95 | @Service |
| 96 | public class DistributedGroupStore |
| 97 | extends AbstractStore<GroupEvent, GroupStoreDelegate> |
| 98 | implements GroupStore { |
| 99 | |
| 100 | private final Logger log = getLogger(getClass()); |
| 101 | |
| 102 | private final int dummyId = 0xffffffff; |
| 103 | private final GroupId dummyGroupId = new DefaultGroupId(dummyId); |
| 104 | |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 105 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 106 | protected ClusterCommunicationService clusterCommunicator; |
| 107 | |
| 108 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 109 | protected ClusterService clusterService; |
| 110 | |
| 111 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Jonathan Hart | 6ec029a | 2015-03-24 17:12:35 -0700 | [diff] [blame] | 112 | protected StorageService storageService; |
| 113 | |
| 114 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 115 | protected MastershipService mastershipService; |
| 116 | |
| 117 | // Per device group table with (device id + app cookie) as key |
Madan Jampani | 0b84753 | 2016-03-03 13:44:15 -0800 | [diff] [blame] | 118 | private ConsistentMap<GroupStoreKeyMapKey, |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 119 | StoredGroupEntry> groupStoreEntriesByKey = null; |
| 120 | // Per device group table with (device id + group id) as key |
Srikanth Vavilapalli | 6a9d4e4 | 2015-03-30 19:41:56 -0700 | [diff] [blame] | 121 | private final ConcurrentMap<DeviceId, ConcurrentMap<GroupId, StoredGroupEntry>> |
| 122 | groupEntriesById = new ConcurrentHashMap<>(); |
Madan Jampani | 0b84753 | 2016-03-03 13:44:15 -0800 | [diff] [blame] | 123 | private ConsistentMap<GroupStoreKeyMapKey, |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 124 | StoredGroupEntry> auditPendingReqQueue = null; |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 125 | private final ConcurrentMap<DeviceId, ConcurrentMap<GroupId, Group>> |
| 126 | extraneousGroupEntriesById = new ConcurrentHashMap<>(); |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 127 | private ExecutorService messageHandlingExecutor; |
| 128 | private static final int MESSAGE_HANDLER_THREAD_POOL_SIZE = 1; |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 129 | |
Sho SHIMIZU | 7a4087b | 2015-09-10 09:23:16 -0700 | [diff] [blame] | 130 | private final HashMap<DeviceId, Boolean> deviceAuditStatus = new HashMap<>(); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 131 | |
| 132 | private final AtomicInteger groupIdGen = new AtomicInteger(); |
| 133 | |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 134 | private KryoNamespace.Builder kryoBuilder = null; |
| 135 | |
HIGUCHI Yuta | 180d70f | 2015-10-01 16:13:56 -0700 | [diff] [blame] | 136 | private KryoNamespace clusterMsgSerializer; |
| 137 | |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 138 | @Activate |
| 139 | public void activate() { |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 140 | kryoBuilder = new KryoNamespace.Builder() |
Charles Chan | 138cd5a | 2015-09-29 16:57:41 -0700 | [diff] [blame] | 141 | .register(KryoNamespaces.API) |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 142 | .register(DefaultGroup.class, |
| 143 | DefaultGroupBucket.class, |
| 144 | DefaultGroupDescription.class, |
| 145 | DefaultGroupKey.class, |
| 146 | GroupDescription.Type.class, |
| 147 | Group.GroupState.class, |
| 148 | GroupBuckets.class, |
| 149 | DefaultGroupId.class, |
| 150 | GroupStoreMessage.class, |
| 151 | GroupStoreMessage.Type.class, |
| 152 | UpdateType.class, |
| 153 | GroupStoreMessageSubjects.class, |
| 154 | MultiValuedTimestamp.class, |
| 155 | GroupStoreKeyMapKey.class, |
| 156 | GroupStoreIdMapKey.class, |
| 157 | GroupStoreMapKey.class |
Charles Chan | 138cd5a | 2015-09-29 16:57:41 -0700 | [diff] [blame] | 158 | ); |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 159 | |
HIGUCHI Yuta | 180d70f | 2015-10-01 16:13:56 -0700 | [diff] [blame] | 160 | clusterMsgSerializer = kryoBuilder.build(); |
| 161 | |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 162 | messageHandlingExecutor = Executors. |
| 163 | newFixedThreadPool(MESSAGE_HANDLER_THREAD_POOL_SIZE, |
| 164 | groupedThreads("onos/store/group", |
| 165 | "message-handlers")); |
Madan Jampani | 01e05fb | 2015-08-13 13:29:36 -0700 | [diff] [blame] | 166 | |
| 167 | clusterCommunicator.addSubscriber(GroupStoreMessageSubjects.REMOTE_GROUP_OP_REQUEST, |
HIGUCHI Yuta | 180d70f | 2015-10-01 16:13:56 -0700 | [diff] [blame] | 168 | clusterMsgSerializer::deserialize, |
Madan Jampani | 01e05fb | 2015-08-13 13:29:36 -0700 | [diff] [blame] | 169 | this::process, |
| 170 | messageHandlingExecutor); |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 171 | |
Madan Jampani | 0b84753 | 2016-03-03 13:44:15 -0800 | [diff] [blame] | 172 | log.debug("Creating Consistent map onos-group-store-keymap"); |
Jonathan Hart | 6ec029a | 2015-03-24 17:12:35 -0700 | [diff] [blame] | 173 | |
Madan Jampani | 0b84753 | 2016-03-03 13:44:15 -0800 | [diff] [blame] | 174 | groupStoreEntriesByKey = storageService.<GroupStoreKeyMapKey, StoredGroupEntry>consistentMapBuilder() |
| 175 | .withName("onos-group-store-keymap") |
| 176 | .withSerializer(Serializer.using(kryoBuilder.build())) |
Jonathan Hart | 6ec029a | 2015-03-24 17:12:35 -0700 | [diff] [blame] | 177 | .build(); |
Srikanth Vavilapalli | 6a9d4e4 | 2015-03-30 19:41:56 -0700 | [diff] [blame] | 178 | groupStoreEntriesByKey.addListener(new GroupStoreKeyMapListener()); |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 179 | log.debug("Current size of groupstorekeymap:{}", |
| 180 | groupStoreEntriesByKey.size()); |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 181 | |
Madan Jampani | 0b84753 | 2016-03-03 13:44:15 -0800 | [diff] [blame] | 182 | log.debug("Creating Consistent map pendinggroupkeymap"); |
Jonathan Hart | 6ec029a | 2015-03-24 17:12:35 -0700 | [diff] [blame] | 183 | |
Madan Jampani | 0b84753 | 2016-03-03 13:44:15 -0800 | [diff] [blame] | 184 | auditPendingReqQueue = storageService.<GroupStoreKeyMapKey, StoredGroupEntry>consistentMapBuilder() |
| 185 | .withName("onos-pending-group-keymap") |
| 186 | .withSerializer(Serializer.using(kryoBuilder.build())) |
Jonathan Hart | 6ec029a | 2015-03-24 17:12:35 -0700 | [diff] [blame] | 187 | .build(); |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 188 | log.debug("Current size of pendinggroupkeymap:{}", |
| 189 | auditPendingReqQueue.size()); |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 190 | |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 191 | log.info("Started"); |
| 192 | } |
| 193 | |
| 194 | @Deactivate |
| 195 | public void deactivate() { |
HIGUCHI Yuta | 180d70f | 2015-10-01 16:13:56 -0700 | [diff] [blame] | 196 | clusterCommunicator.removeSubscriber(GroupStoreMessageSubjects.REMOTE_GROUP_OP_REQUEST); |
Thomas Vachuska | 152f9fd | 2015-04-02 16:28:13 -0700 | [diff] [blame] | 197 | groupStoreEntriesByKey.destroy(); |
Thomas Vachuska | 152f9fd | 2015-04-02 16:28:13 -0700 | [diff] [blame] | 198 | auditPendingReqQueue.destroy(); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 199 | log.info("Stopped"); |
| 200 | } |
| 201 | |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 202 | private static NewConcurrentHashMap<GroupId, Group> |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 203 | lazyEmptyExtraneousGroupIdTable() { |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 204 | return NewConcurrentHashMap.<GroupId, Group>ifNeeded(); |
| 205 | } |
| 206 | |
Srikanth Vavilapalli | 6a9d4e4 | 2015-03-30 19:41:56 -0700 | [diff] [blame] | 207 | private static NewConcurrentHashMap<GroupId, StoredGroupEntry> |
| 208 | lazyEmptyGroupIdTable() { |
| 209 | return NewConcurrentHashMap.<GroupId, StoredGroupEntry>ifNeeded(); |
| 210 | } |
| 211 | |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 212 | /** |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 213 | * Returns the group store eventual consistent key map. |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 214 | * |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 215 | * @return Map representing group key table. |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 216 | */ |
Madan Jampani | 0b84753 | 2016-03-03 13:44:15 -0800 | [diff] [blame] | 217 | private Map<GroupStoreKeyMapKey, StoredGroupEntry> |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 218 | getGroupStoreKeyMap() { |
Madan Jampani | 0b84753 | 2016-03-03 13:44:15 -0800 | [diff] [blame] | 219 | return groupStoreEntriesByKey.asJavaMap(); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | /** |
Srikanth Vavilapalli | 6a9d4e4 | 2015-03-30 19:41:56 -0700 | [diff] [blame] | 223 | * Returns the group id table for specified device. |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 224 | * |
Srikanth Vavilapalli | 6a9d4e4 | 2015-03-30 19:41:56 -0700 | [diff] [blame] | 225 | * @param deviceId identifier of the device |
| 226 | * @return Map representing group key table of given device. |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 227 | */ |
Srikanth Vavilapalli | 6a9d4e4 | 2015-03-30 19:41:56 -0700 | [diff] [blame] | 228 | private ConcurrentMap<GroupId, StoredGroupEntry> getGroupIdTable(DeviceId deviceId) { |
| 229 | return createIfAbsentUnchecked(groupEntriesById, |
| 230 | deviceId, lazyEmptyGroupIdTable()); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | /** |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 234 | * Returns the pending group request table. |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 235 | * |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 236 | * @return Map representing group key table. |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 237 | */ |
Madan Jampani | 0b84753 | 2016-03-03 13:44:15 -0800 | [diff] [blame] | 238 | private Map<GroupStoreKeyMapKey, StoredGroupEntry> |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 239 | getPendingGroupKeyTable() { |
Madan Jampani | 0b84753 | 2016-03-03 13:44:15 -0800 | [diff] [blame] | 240 | return auditPendingReqQueue.asJavaMap(); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | /** |
| 244 | * Returns the extraneous group id table for specified device. |
| 245 | * |
| 246 | * @param deviceId identifier of the device |
| 247 | * @return Map representing group key table of given device. |
| 248 | */ |
| 249 | private ConcurrentMap<GroupId, Group> |
| 250 | getExtraneousGroupIdTable(DeviceId deviceId) { |
| 251 | return createIfAbsentUnchecked(extraneousGroupEntriesById, |
| 252 | deviceId, |
| 253 | lazyEmptyExtraneousGroupIdTable()); |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * Returns the number of groups for the specified device in the store. |
| 258 | * |
| 259 | * @return number of groups for the specified device |
| 260 | */ |
| 261 | @Override |
| 262 | public int getGroupCount(DeviceId deviceId) { |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 263 | return (getGroups(deviceId) != null) ? |
| 264 | Iterables.size(getGroups(deviceId)) : 0; |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Returns the groups associated with a device. |
| 269 | * |
| 270 | * @param deviceId the device ID |
| 271 | * |
| 272 | * @return the group entries |
| 273 | */ |
| 274 | @Override |
| 275 | public Iterable<Group> getGroups(DeviceId deviceId) { |
Charles Chan | f4838a7 | 2015-12-07 18:13:45 -0800 | [diff] [blame] | 276 | // Let ImmutableSet.copyOf do the type conversion |
| 277 | return ImmutableSet.copyOf(getStoredGroups(deviceId)); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 278 | } |
| 279 | |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 280 | private Iterable<StoredGroupEntry> getStoredGroups(DeviceId deviceId) { |
Charles Chan | f4838a7 | 2015-12-07 18:13:45 -0800 | [diff] [blame] | 281 | NodeId master = mastershipService.getMasterFor(deviceId); |
| 282 | if (master == null) { |
| 283 | log.debug("Failed to getGroups: No master for {}", deviceId); |
| 284 | return Collections.emptySet(); |
| 285 | } |
| 286 | |
| 287 | Set<StoredGroupEntry> storedGroups = getGroupStoreKeyMap().values() |
| 288 | .stream() |
| 289 | .filter(input -> input.deviceId().equals(deviceId)) |
| 290 | .collect(Collectors.toSet()); |
| 291 | return ImmutableSet.copyOf(storedGroups); |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 292 | } |
| 293 | |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 294 | /** |
| 295 | * Returns the stored group entry. |
| 296 | * |
| 297 | * @param deviceId the device ID |
| 298 | * @param appCookie the group key |
| 299 | * |
| 300 | * @return a group associated with the key |
| 301 | */ |
| 302 | @Override |
| 303 | public Group getGroup(DeviceId deviceId, GroupKey appCookie) { |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 304 | return getStoredGroupEntry(deviceId, appCookie); |
| 305 | } |
| 306 | |
| 307 | private StoredGroupEntry getStoredGroupEntry(DeviceId deviceId, |
| 308 | GroupKey appCookie) { |
| 309 | return getGroupStoreKeyMap().get(new GroupStoreKeyMapKey(deviceId, |
| 310 | appCookie)); |
| 311 | } |
| 312 | |
| 313 | @Override |
| 314 | public Group getGroup(DeviceId deviceId, GroupId groupId) { |
| 315 | return getStoredGroupEntry(deviceId, groupId); |
| 316 | } |
| 317 | |
| 318 | private StoredGroupEntry getStoredGroupEntry(DeviceId deviceId, |
| 319 | GroupId groupId) { |
Srikanth Vavilapalli | 6a9d4e4 | 2015-03-30 19:41:56 -0700 | [diff] [blame] | 320 | return getGroupIdTable(deviceId).get(groupId); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | private int getFreeGroupIdValue(DeviceId deviceId) { |
| 324 | int freeId = groupIdGen.incrementAndGet(); |
| 325 | |
| 326 | while (true) { |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 327 | Group existing = getGroup(deviceId, new DefaultGroupId(freeId)); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 328 | if (existing == null) { |
| 329 | existing = ( |
| 330 | extraneousGroupEntriesById.get(deviceId) != null) ? |
| 331 | extraneousGroupEntriesById.get(deviceId). |
| 332 | get(new DefaultGroupId(freeId)) : |
| 333 | null; |
| 334 | } |
| 335 | if (existing != null) { |
| 336 | freeId = groupIdGen.incrementAndGet(); |
| 337 | } else { |
| 338 | break; |
| 339 | } |
| 340 | } |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 341 | log.debug("getFreeGroupIdValue: Next Free ID is {}", freeId); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 342 | return freeId; |
| 343 | } |
| 344 | |
| 345 | /** |
| 346 | * Stores a new group entry using the information from group description. |
| 347 | * |
| 348 | * @param groupDesc group description to be used to create group entry |
| 349 | */ |
| 350 | @Override |
| 351 | public void storeGroupDescription(GroupDescription groupDesc) { |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 352 | log.debug("In storeGroupDescription"); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 353 | // Check if a group is existing with the same key |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 354 | Group existingGroup = getGroup(groupDesc.deviceId(), groupDesc.appCookie()); |
| 355 | if (existingGroup != null) { |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 356 | log.warn("Group already exists with the same key {} in dev:{} with id:0x{}", |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 357 | groupDesc.appCookie(), groupDesc.deviceId(), |
| 358 | Integer.toHexString(existingGroup.id().id())); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 359 | return; |
| 360 | } |
| 361 | |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 362 | // Check if group to be created by a remote instance |
Madan Jampani | 175e8fd | 2015-05-20 14:10:45 -0700 | [diff] [blame] | 363 | if (mastershipService.getLocalRole(groupDesc.deviceId()) != MastershipRole.MASTER) { |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 364 | log.debug("storeGroupDescription: Device {} local role is not MASTER", |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 365 | groupDesc.deviceId()); |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 366 | if (mastershipService.getMasterFor(groupDesc.deviceId()) == null) { |
| 367 | log.error("No Master for device {}..." |
| 368 | + "Can not perform add group operation", |
| 369 | groupDesc.deviceId()); |
| 370 | //TODO: Send Group operation failure event |
| 371 | return; |
| 372 | } |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 373 | GroupStoreMessage groupOp = GroupStoreMessage. |
| 374 | createGroupAddRequestMsg(groupDesc.deviceId(), |
| 375 | groupDesc); |
Madan Jampani | 2bfa94c | 2015-04-11 05:03:49 -0700 | [diff] [blame] | 376 | |
Madan Jampani | 175e8fd | 2015-05-20 14:10:45 -0700 | [diff] [blame] | 377 | clusterCommunicator.unicast(groupOp, |
Madan Jampani | 2bfa94c | 2015-04-11 05:03:49 -0700 | [diff] [blame] | 378 | GroupStoreMessageSubjects.REMOTE_GROUP_OP_REQUEST, |
HIGUCHI Yuta | 180d70f | 2015-10-01 16:13:56 -0700 | [diff] [blame] | 379 | clusterMsgSerializer::serialize, |
Madan Jampani | 175e8fd | 2015-05-20 14:10:45 -0700 | [diff] [blame] | 380 | mastershipService.getMasterFor(groupDesc.deviceId())).whenComplete((result, error) -> { |
| 381 | if (error != null) { |
| 382 | log.warn("Failed to send request to master: {} to {}", |
| 383 | groupOp, |
| 384 | mastershipService.getMasterFor(groupDesc.deviceId())); |
| 385 | //TODO: Send Group operation failure event |
| 386 | } else { |
| 387 | log.debug("Sent Group operation request for device {} " |
| 388 | + "to remote MASTER {}", |
| 389 | groupDesc.deviceId(), |
| 390 | mastershipService.getMasterFor(groupDesc.deviceId())); |
| 391 | } |
| 392 | }); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 393 | return; |
| 394 | } |
| 395 | |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 396 | log.debug("Store group for device {} is getting handled locally", |
| 397 | groupDesc.deviceId()); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 398 | storeGroupDescriptionInternal(groupDesc); |
| 399 | } |
| 400 | |
Srikanth Vavilapalli | e48b3cf | 2015-07-06 11:43:07 -0700 | [diff] [blame] | 401 | private Group getMatchingExtraneousGroupbyId(DeviceId deviceId, Integer groupId) { |
| 402 | ConcurrentMap<GroupId, Group> extraneousMap = |
| 403 | extraneousGroupEntriesById.get(deviceId); |
| 404 | if (extraneousMap == null) { |
| 405 | return null; |
| 406 | } |
| 407 | return extraneousMap.get(new DefaultGroupId(groupId)); |
| 408 | } |
| 409 | |
| 410 | private Group getMatchingExtraneousGroupbyBuckets(DeviceId deviceId, |
| 411 | GroupBuckets buckets) { |
| 412 | ConcurrentMap<GroupId, Group> extraneousMap = |
| 413 | extraneousGroupEntriesById.get(deviceId); |
| 414 | if (extraneousMap == null) { |
| 415 | return null; |
| 416 | } |
| 417 | |
| 418 | for (Group extraneousGroup:extraneousMap.values()) { |
| 419 | if (extraneousGroup.buckets().equals(buckets)) { |
| 420 | return extraneousGroup; |
| 421 | } |
| 422 | } |
| 423 | return null; |
| 424 | } |
| 425 | |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 426 | private void storeGroupDescriptionInternal(GroupDescription groupDesc) { |
| 427 | // Check if a group is existing with the same key |
| 428 | if (getGroup(groupDesc.deviceId(), groupDesc.appCookie()) != null) { |
| 429 | return; |
| 430 | } |
| 431 | |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 432 | if (deviceAuditStatus.get(groupDesc.deviceId()) == null) { |
| 433 | // Device group audit has not completed yet |
| 434 | // Add this group description to pending group key table |
| 435 | // Create a group entry object with Dummy Group ID |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 436 | log.debug("storeGroupDescriptionInternal: Device {} AUDIT pending...Queuing Group ADD request", |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 437 | groupDesc.deviceId()); |
| 438 | StoredGroupEntry group = new DefaultGroup(dummyGroupId, groupDesc); |
| 439 | group.setState(GroupState.WAITING_AUDIT_COMPLETE); |
Madan Jampani | 0b84753 | 2016-03-03 13:44:15 -0800 | [diff] [blame] | 440 | Map<GroupStoreKeyMapKey, StoredGroupEntry> pendingKeyTable = |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 441 | getPendingGroupKeyTable(); |
| 442 | pendingKeyTable.put(new GroupStoreKeyMapKey(groupDesc.deviceId(), |
| 443 | groupDesc.appCookie()), |
| 444 | group); |
| 445 | return; |
| 446 | } |
| 447 | |
Srikanth Vavilapalli | e48b3cf | 2015-07-06 11:43:07 -0700 | [diff] [blame] | 448 | Group matchingExtraneousGroup = null; |
| 449 | if (groupDesc.givenGroupId() != null) { |
| 450 | //Check if there is a extraneous group existing with the same Id |
| 451 | matchingExtraneousGroup = getMatchingExtraneousGroupbyId( |
| 452 | groupDesc.deviceId(), groupDesc.givenGroupId()); |
| 453 | if (matchingExtraneousGroup != null) { |
Saurav Das | 0fd79d9 | 2016-03-07 10:58:36 -0800 | [diff] [blame^] | 454 | log.debug("storeGroupDescriptionInternal: Matching extraneous group " |
| 455 | + "found in Device {} for group id 0x{}", |
Srikanth Vavilapalli | e48b3cf | 2015-07-06 11:43:07 -0700 | [diff] [blame] | 456 | groupDesc.deviceId(), |
Saurav Das | 0fd79d9 | 2016-03-07 10:58:36 -0800 | [diff] [blame^] | 457 | Integer.toHexString(groupDesc.givenGroupId())); |
Srikanth Vavilapalli | e48b3cf | 2015-07-06 11:43:07 -0700 | [diff] [blame] | 458 | //Check if the group buckets matches with user provided buckets |
| 459 | if (matchingExtraneousGroup.buckets().equals(groupDesc.buckets())) { |
| 460 | //Group is already existing with the same buckets and Id |
| 461 | // Create a group entry object |
Saurav Das | 0fd79d9 | 2016-03-07 10:58:36 -0800 | [diff] [blame^] | 462 | log.debug("storeGroupDescriptionInternal: Buckets also matching " |
| 463 | + "in Device {} for group id 0x{}", |
Srikanth Vavilapalli | e48b3cf | 2015-07-06 11:43:07 -0700 | [diff] [blame] | 464 | groupDesc.deviceId(), |
Saurav Das | 0fd79d9 | 2016-03-07 10:58:36 -0800 | [diff] [blame^] | 465 | Integer.toHexString(groupDesc.givenGroupId())); |
Srikanth Vavilapalli | e48b3cf | 2015-07-06 11:43:07 -0700 | [diff] [blame] | 466 | StoredGroupEntry group = new DefaultGroup( |
| 467 | matchingExtraneousGroup.id(), groupDesc); |
| 468 | // Insert the newly created group entry into key and id maps |
| 469 | getGroupStoreKeyMap(). |
| 470 | put(new GroupStoreKeyMapKey(groupDesc.deviceId(), |
| 471 | groupDesc.appCookie()), group); |
| 472 | // Ensure it also inserted into group id based table to |
| 473 | // avoid any chances of duplication in group id generation |
| 474 | getGroupIdTable(groupDesc.deviceId()). |
| 475 | put(matchingExtraneousGroup.id(), group); |
| 476 | addOrUpdateGroupEntry(matchingExtraneousGroup); |
| 477 | removeExtraneousGroupEntry(matchingExtraneousGroup); |
| 478 | return; |
| 479 | } else { |
| 480 | //Group buckets are not matching. Update group |
| 481 | //with user provided buckets. |
Saurav Das | 0fd79d9 | 2016-03-07 10:58:36 -0800 | [diff] [blame^] | 482 | log.debug("storeGroupDescriptionInternal: Buckets are not " |
| 483 | + "matching in Device {} for group id 0x{}", |
Srikanth Vavilapalli | e48b3cf | 2015-07-06 11:43:07 -0700 | [diff] [blame] | 484 | groupDesc.deviceId(), |
Saurav Das | 0fd79d9 | 2016-03-07 10:58:36 -0800 | [diff] [blame^] | 485 | Integer.toHexString(groupDesc.givenGroupId())); |
| 486 | StoredGroupEntry modifiedGroup = new DefaultGroup( |
| 487 | matchingExtraneousGroup.id(), groupDesc); |
| 488 | modifiedGroup.setState(GroupState.PENDING_UPDATE); |
| 489 | getGroupStoreKeyMap(). |
| 490 | put(new GroupStoreKeyMapKey(groupDesc.deviceId(), |
| 491 | groupDesc.appCookie()), modifiedGroup); |
| 492 | // Ensure it also inserted into group id based table to |
| 493 | // avoid any chances of duplication in group id generation |
| 494 | getGroupIdTable(groupDesc.deviceId()). |
| 495 | put(matchingExtraneousGroup.id(), modifiedGroup); |
| 496 | removeExtraneousGroupEntry(matchingExtraneousGroup); |
| 497 | log.debug("storeGroupDescriptionInternal: Triggering Group " |
| 498 | + "UPDATE request for {} in device {}", |
| 499 | matchingExtraneousGroup.id(), |
| 500 | groupDesc.deviceId()); |
| 501 | notifyDelegate(new GroupEvent(Type.GROUP_UPDATE_REQUESTED, modifiedGroup)); |
| 502 | return; |
Srikanth Vavilapalli | e48b3cf | 2015-07-06 11:43:07 -0700 | [diff] [blame] | 503 | } |
| 504 | } |
| 505 | } else { |
| 506 | //Check if there is an extraneous group with user provided buckets |
| 507 | matchingExtraneousGroup = getMatchingExtraneousGroupbyBuckets( |
| 508 | groupDesc.deviceId(), groupDesc.buckets()); |
| 509 | if (matchingExtraneousGroup != null) { |
| 510 | //Group is already existing with the same buckets. |
| 511 | //So reuse this group. |
| 512 | log.debug("storeGroupDescriptionInternal: Matching extraneous group found in Device {}", |
| 513 | groupDesc.deviceId()); |
| 514 | //Create a group entry object |
| 515 | StoredGroupEntry group = new DefaultGroup( |
| 516 | matchingExtraneousGroup.id(), groupDesc); |
| 517 | // Insert the newly created group entry into key and id maps |
| 518 | getGroupStoreKeyMap(). |
| 519 | put(new GroupStoreKeyMapKey(groupDesc.deviceId(), |
| 520 | groupDesc.appCookie()), group); |
| 521 | // Ensure it also inserted into group id based table to |
| 522 | // avoid any chances of duplication in group id generation |
| 523 | getGroupIdTable(groupDesc.deviceId()). |
| 524 | put(matchingExtraneousGroup.id(), group); |
| 525 | addOrUpdateGroupEntry(matchingExtraneousGroup); |
| 526 | removeExtraneousGroupEntry(matchingExtraneousGroup); |
| 527 | return; |
| 528 | } else { |
| 529 | //TODO: Check if there are any empty groups that can be used here |
| 530 | log.debug("storeGroupDescriptionInternal: No matching extraneous groups found in Device {}", |
| 531 | groupDesc.deviceId()); |
| 532 | } |
| 533 | } |
| 534 | |
Saurav Das | 100e3b8 | 2015-04-30 11:12:10 -0700 | [diff] [blame] | 535 | GroupId id = null; |
| 536 | if (groupDesc.givenGroupId() == null) { |
| 537 | // Get a new group identifier |
| 538 | id = new DefaultGroupId(getFreeGroupIdValue(groupDesc.deviceId())); |
| 539 | } else { |
| 540 | id = new DefaultGroupId(groupDesc.givenGroupId()); |
| 541 | } |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 542 | // Create a group entry object |
| 543 | StoredGroupEntry group = new DefaultGroup(id, groupDesc); |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 544 | // Insert the newly created group entry into key and id maps |
| 545 | getGroupStoreKeyMap(). |
| 546 | put(new GroupStoreKeyMapKey(groupDesc.deviceId(), |
| 547 | groupDesc.appCookie()), group); |
Srikanth Vavilapalli | 6a9d4e4 | 2015-03-30 19:41:56 -0700 | [diff] [blame] | 548 | // Ensure it also inserted into group id based table to |
| 549 | // avoid any chances of duplication in group id generation |
| 550 | getGroupIdTable(groupDesc.deviceId()). |
| 551 | put(id, group); |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 552 | log.debug("storeGroupDescriptionInternal: Processing Group ADD request for Id {} in device {}", |
| 553 | id, |
| 554 | groupDesc.deviceId()); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 555 | notifyDelegate(new GroupEvent(GroupEvent.Type.GROUP_ADD_REQUESTED, |
| 556 | group)); |
| 557 | } |
| 558 | |
| 559 | /** |
| 560 | * Updates the existing group entry with the information |
| 561 | * from group description. |
| 562 | * |
| 563 | * @param deviceId the device ID |
| 564 | * @param oldAppCookie the current group key |
| 565 | * @param type update type |
| 566 | * @param newBuckets group buckets for updates |
| 567 | * @param newAppCookie optional new group key |
| 568 | */ |
| 569 | @Override |
| 570 | public void updateGroupDescription(DeviceId deviceId, |
| 571 | GroupKey oldAppCookie, |
| 572 | UpdateType type, |
| 573 | GroupBuckets newBuckets, |
| 574 | GroupKey newAppCookie) { |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 575 | // Check if group update to be done by a remote instance |
sangho | 52abe3a | 2015-05-05 14:13:34 -0700 | [diff] [blame] | 576 | if (mastershipService.getMasterFor(deviceId) != null && |
| 577 | mastershipService.getLocalRole(deviceId) != MastershipRole.MASTER) { |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 578 | log.debug("updateGroupDescription: Device {} local role is not MASTER", |
| 579 | deviceId); |
| 580 | if (mastershipService.getMasterFor(deviceId) == null) { |
| 581 | log.error("No Master for device {}..." |
| 582 | + "Can not perform update group operation", |
| 583 | deviceId); |
| 584 | //TODO: Send Group operation failure event |
| 585 | return; |
| 586 | } |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 587 | GroupStoreMessage groupOp = GroupStoreMessage. |
| 588 | createGroupUpdateRequestMsg(deviceId, |
| 589 | oldAppCookie, |
| 590 | type, |
| 591 | newBuckets, |
| 592 | newAppCookie); |
Madan Jampani | 2bfa94c | 2015-04-11 05:03:49 -0700 | [diff] [blame] | 593 | |
Madan Jampani | 175e8fd | 2015-05-20 14:10:45 -0700 | [diff] [blame] | 594 | clusterCommunicator.unicast(groupOp, |
| 595 | GroupStoreMessageSubjects.REMOTE_GROUP_OP_REQUEST, |
HIGUCHI Yuta | 180d70f | 2015-10-01 16:13:56 -0700 | [diff] [blame] | 596 | clusterMsgSerializer::serialize, |
Madan Jampani | 175e8fd | 2015-05-20 14:10:45 -0700 | [diff] [blame] | 597 | mastershipService.getMasterFor(deviceId)).whenComplete((result, error) -> { |
| 598 | if (error != null) { |
| 599 | log.warn("Failed to send request to master: {} to {}", |
| 600 | groupOp, |
| 601 | mastershipService.getMasterFor(deviceId), error); |
| 602 | } |
| 603 | //TODO: Send Group operation failure event |
| 604 | }); |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 605 | return; |
| 606 | } |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 607 | log.debug("updateGroupDescription for device {} is getting handled locally", |
| 608 | deviceId); |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 609 | updateGroupDescriptionInternal(deviceId, |
| 610 | oldAppCookie, |
| 611 | type, |
| 612 | newBuckets, |
| 613 | newAppCookie); |
| 614 | } |
| 615 | |
| 616 | private void updateGroupDescriptionInternal(DeviceId deviceId, |
| 617 | GroupKey oldAppCookie, |
| 618 | UpdateType type, |
| 619 | GroupBuckets newBuckets, |
| 620 | GroupKey newAppCookie) { |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 621 | // Check if a group is existing with the provided key |
| 622 | Group oldGroup = getGroup(deviceId, oldAppCookie); |
| 623 | if (oldGroup == null) { |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 624 | log.warn("updateGroupDescriptionInternal: Group not found...strange"); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 625 | return; |
| 626 | } |
| 627 | |
| 628 | List<GroupBucket> newBucketList = getUpdatedBucketList(oldGroup, |
| 629 | type, |
| 630 | newBuckets); |
| 631 | if (newBucketList != null) { |
| 632 | // Create a new group object from the old group |
| 633 | GroupBuckets updatedBuckets = new GroupBuckets(newBucketList); |
| 634 | GroupKey newCookie = (newAppCookie != null) ? newAppCookie : oldAppCookie; |
| 635 | GroupDescription updatedGroupDesc = new DefaultGroupDescription( |
| 636 | oldGroup.deviceId(), |
| 637 | oldGroup.type(), |
| 638 | updatedBuckets, |
| 639 | newCookie, |
Saurav Das | 100e3b8 | 2015-04-30 11:12:10 -0700 | [diff] [blame] | 640 | oldGroup.givenGroupId(), |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 641 | oldGroup.appId()); |
| 642 | StoredGroupEntry newGroup = new DefaultGroup(oldGroup.id(), |
| 643 | updatedGroupDesc); |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 644 | log.debug("updateGroupDescriptionInternal: group entry {} in device {} moving from {} to PENDING_UPDATE", |
| 645 | oldGroup.id(), |
| 646 | oldGroup.deviceId(), |
| 647 | oldGroup.state()); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 648 | newGroup.setState(GroupState.PENDING_UPDATE); |
| 649 | newGroup.setLife(oldGroup.life()); |
| 650 | newGroup.setPackets(oldGroup.packets()); |
| 651 | newGroup.setBytes(oldGroup.bytes()); |
Srikanth Vavilapalli | 6a9d4e4 | 2015-03-30 19:41:56 -0700 | [diff] [blame] | 652 | //Update the group entry in groupkey based map. |
| 653 | //Update to groupid based map will happen in the |
| 654 | //groupkey based map update listener |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 655 | log.debug("updateGroupDescriptionInternal with type {}: Group updated with buckets", |
| 656 | type); |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 657 | getGroupStoreKeyMap(). |
| 658 | put(new GroupStoreKeyMapKey(newGroup.deviceId(), |
| 659 | newGroup.appCookie()), newGroup); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 660 | notifyDelegate(new GroupEvent(Type.GROUP_UPDATE_REQUESTED, newGroup)); |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 661 | } else { |
| 662 | log.warn("updateGroupDescriptionInternal with type {}: No " |
| 663 | + "change in the buckets in update", type); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 664 | } |
| 665 | } |
| 666 | |
| 667 | private List<GroupBucket> getUpdatedBucketList(Group oldGroup, |
| 668 | UpdateType type, |
| 669 | GroupBuckets buckets) { |
| 670 | GroupBuckets oldBuckets = oldGroup.buckets(); |
Sho SHIMIZU | 7a4087b | 2015-09-10 09:23:16 -0700 | [diff] [blame] | 671 | List<GroupBucket> newBucketList = new ArrayList<>(oldBuckets.buckets()); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 672 | boolean groupDescUpdated = false; |
| 673 | |
| 674 | if (type == UpdateType.ADD) { |
| 675 | // Check if the any of the new buckets are part of |
| 676 | // the old bucket list |
| 677 | for (GroupBucket addBucket:buckets.buckets()) { |
| 678 | if (!newBucketList.contains(addBucket)) { |
| 679 | newBucketList.add(addBucket); |
| 680 | groupDescUpdated = true; |
| 681 | } |
| 682 | } |
| 683 | } else if (type == UpdateType.REMOVE) { |
| 684 | // Check if the to be removed buckets are part of the |
| 685 | // old bucket list |
| 686 | for (GroupBucket removeBucket:buckets.buckets()) { |
| 687 | if (newBucketList.contains(removeBucket)) { |
| 688 | newBucketList.remove(removeBucket); |
| 689 | groupDescUpdated = true; |
| 690 | } |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | if (groupDescUpdated) { |
| 695 | return newBucketList; |
| 696 | } else { |
| 697 | return null; |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | /** |
| 702 | * Triggers deleting the existing group entry. |
| 703 | * |
| 704 | * @param deviceId the device ID |
| 705 | * @param appCookie the group key |
| 706 | */ |
| 707 | @Override |
| 708 | public void deleteGroupDescription(DeviceId deviceId, |
| 709 | GroupKey appCookie) { |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 710 | // Check if group to be deleted by a remote instance |
| 711 | if (mastershipService. |
| 712 | getLocalRole(deviceId) != MastershipRole.MASTER) { |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 713 | log.debug("deleteGroupDescription: Device {} local role is not MASTER", |
| 714 | deviceId); |
| 715 | if (mastershipService.getMasterFor(deviceId) == null) { |
| 716 | log.error("No Master for device {}..." |
| 717 | + "Can not perform delete group operation", |
| 718 | deviceId); |
| 719 | //TODO: Send Group operation failure event |
| 720 | return; |
| 721 | } |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 722 | GroupStoreMessage groupOp = GroupStoreMessage. |
| 723 | createGroupDeleteRequestMsg(deviceId, |
| 724 | appCookie); |
Madan Jampani | 2bfa94c | 2015-04-11 05:03:49 -0700 | [diff] [blame] | 725 | |
Madan Jampani | 175e8fd | 2015-05-20 14:10:45 -0700 | [diff] [blame] | 726 | clusterCommunicator.unicast(groupOp, |
Madan Jampani | 2bfa94c | 2015-04-11 05:03:49 -0700 | [diff] [blame] | 727 | GroupStoreMessageSubjects.REMOTE_GROUP_OP_REQUEST, |
HIGUCHI Yuta | 180d70f | 2015-10-01 16:13:56 -0700 | [diff] [blame] | 728 | clusterMsgSerializer::serialize, |
Madan Jampani | 175e8fd | 2015-05-20 14:10:45 -0700 | [diff] [blame] | 729 | mastershipService.getMasterFor(deviceId)).whenComplete((result, error) -> { |
| 730 | if (error != null) { |
| 731 | log.warn("Failed to send request to master: {} to {}", |
| 732 | groupOp, |
| 733 | mastershipService.getMasterFor(deviceId), error); |
| 734 | } |
| 735 | //TODO: Send Group operation failure event |
| 736 | }); |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 737 | return; |
| 738 | } |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 739 | log.debug("deleteGroupDescription in device {} is getting handled locally", |
| 740 | deviceId); |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 741 | deleteGroupDescriptionInternal(deviceId, appCookie); |
| 742 | } |
| 743 | |
| 744 | private void deleteGroupDescriptionInternal(DeviceId deviceId, |
| 745 | GroupKey appCookie) { |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 746 | // Check if a group is existing with the provided key |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 747 | StoredGroupEntry existing = getStoredGroupEntry(deviceId, appCookie); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 748 | if (existing == null) { |
| 749 | return; |
| 750 | } |
| 751 | |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 752 | log.debug("deleteGroupDescriptionInternal: group entry {} in device {} moving from {} to PENDING_DELETE", |
| 753 | existing.id(), |
| 754 | existing.deviceId(), |
| 755 | existing.state()); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 756 | synchronized (existing) { |
| 757 | existing.setState(GroupState.PENDING_DELETE); |
| 758 | } |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 759 | log.debug("deleteGroupDescriptionInternal: in device {} issuing GROUP_REMOVE_REQUESTED", |
| 760 | deviceId); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 761 | notifyDelegate(new GroupEvent(Type.GROUP_REMOVE_REQUESTED, existing)); |
| 762 | } |
| 763 | |
| 764 | /** |
| 765 | * Stores a new group entry, or updates an existing entry. |
| 766 | * |
| 767 | * @param group group entry |
| 768 | */ |
| 769 | @Override |
| 770 | public void addOrUpdateGroupEntry(Group group) { |
| 771 | // check if this new entry is an update to an existing entry |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 772 | StoredGroupEntry existing = getStoredGroupEntry(group.deviceId(), |
| 773 | group.id()); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 774 | GroupEvent event = null; |
| 775 | |
| 776 | if (existing != null) { |
Saurav Das | 0fd79d9 | 2016-03-07 10:58:36 -0800 | [diff] [blame^] | 777 | log.trace("addOrUpdateGroupEntry: updating group entry {} in device {}", |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 778 | group.id(), |
| 779 | group.deviceId()); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 780 | synchronized (existing) { |
Srikanth Vavilapalli | 10e75cd | 2015-04-13 16:21:24 -0700 | [diff] [blame] | 781 | for (GroupBucket bucket:group.buckets().buckets()) { |
Sho SHIMIZU | 30d639b | 2015-05-05 09:30:35 -0700 | [diff] [blame] | 782 | Optional<GroupBucket> matchingBucket = |
Srikanth Vavilapalli | 10e75cd | 2015-04-13 16:21:24 -0700 | [diff] [blame] | 783 | existing.buckets().buckets() |
| 784 | .stream() |
| 785 | .filter((existingBucket)->(existingBucket.equals(bucket))) |
| 786 | .findFirst(); |
| 787 | if (matchingBucket.isPresent()) { |
| 788 | ((StoredGroupBucketEntry) matchingBucket. |
| 789 | get()).setPackets(bucket.packets()); |
| 790 | ((StoredGroupBucketEntry) matchingBucket. |
| 791 | get()).setBytes(bucket.bytes()); |
| 792 | } else { |
| 793 | log.warn("addOrUpdateGroupEntry: No matching " |
| 794 | + "buckets to update stats"); |
| 795 | } |
| 796 | } |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 797 | existing.setLife(group.life()); |
| 798 | existing.setPackets(group.packets()); |
| 799 | existing.setBytes(group.bytes()); |
Srikanth Vavilapalli | 5428b6c | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 800 | if ((existing.state() == GroupState.PENDING_ADD) || |
| 801 | (existing.state() == GroupState.PENDING_ADD_RETRY)) { |
Saurav Das | 0fd79d9 | 2016-03-07 10:58:36 -0800 | [diff] [blame^] | 802 | log.trace("addOrUpdateGroupEntry: group entry {} in device {} moving from {} to ADDED", |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 803 | existing.id(), |
| 804 | existing.deviceId(), |
Srikanth Vavilapalli | 5428b6c | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 805 | existing.state()); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 806 | existing.setState(GroupState.ADDED); |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 807 | existing.setIsGroupStateAddedFirstTime(true); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 808 | event = new GroupEvent(Type.GROUP_ADDED, existing); |
| 809 | } else { |
Saurav Das | 0fd79d9 | 2016-03-07 10:58:36 -0800 | [diff] [blame^] | 810 | log.trace("addOrUpdateGroupEntry: group entry {} in device {} moving from {} to ADDED", |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 811 | existing.id(), |
| 812 | existing.deviceId(), |
| 813 | GroupState.PENDING_UPDATE); |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 814 | existing.setState(GroupState.ADDED); |
| 815 | existing.setIsGroupStateAddedFirstTime(false); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 816 | event = new GroupEvent(Type.GROUP_UPDATED, existing); |
| 817 | } |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 818 | //Re-PUT map entries to trigger map update events |
| 819 | getGroupStoreKeyMap(). |
| 820 | put(new GroupStoreKeyMapKey(existing.deviceId(), |
| 821 | existing.appCookie()), existing); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 822 | } |
Srikanth Vavilapalli | 6a9d4e4 | 2015-03-30 19:41:56 -0700 | [diff] [blame] | 823 | } else { |
| 824 | log.warn("addOrUpdateGroupEntry: Group update " |
| 825 | + "happening for a non-existing entry in the map"); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | if (event != null) { |
| 829 | notifyDelegate(event); |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | /** |
| 834 | * Removes the group entry from store. |
| 835 | * |
| 836 | * @param group group entry |
| 837 | */ |
| 838 | @Override |
| 839 | public void removeGroupEntry(Group group) { |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 840 | StoredGroupEntry existing = getStoredGroupEntry(group.deviceId(), |
| 841 | group.id()); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 842 | |
| 843 | if (existing != null) { |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 844 | log.debug("removeGroupEntry: removing group entry {} in device {}", |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 845 | group.id(), |
| 846 | group.deviceId()); |
Srikanth Vavilapalli | 6a9d4e4 | 2015-03-30 19:41:56 -0700 | [diff] [blame] | 847 | //Removal from groupid based map will happen in the |
| 848 | //map update listener |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 849 | getGroupStoreKeyMap().remove(new GroupStoreKeyMapKey(existing.deviceId(), |
| 850 | existing.appCookie())); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 851 | notifyDelegate(new GroupEvent(Type.GROUP_REMOVED, existing)); |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 852 | } else { |
| 853 | log.warn("removeGroupEntry for {} in device{} is " |
| 854 | + "not existing in our maps", |
| 855 | group.id(), |
| 856 | group.deviceId()); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 857 | } |
| 858 | } |
| 859 | |
| 860 | @Override |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 861 | public void purgeGroupEntry(DeviceId deviceId) { |
| 862 | Set<Entry<GroupStoreKeyMapKey, StoredGroupEntry>> entryPendingRemove = |
| 863 | new HashSet<>(); |
| 864 | |
Madan Jampani | 0b84753 | 2016-03-03 13:44:15 -0800 | [diff] [blame] | 865 | getGroupStoreKeyMap().entrySet().stream() |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 866 | .filter(entry -> entry.getKey().deviceId().equals(deviceId)) |
| 867 | .forEach(entryPendingRemove::add); |
| 868 | |
| 869 | entryPendingRemove.forEach(entry -> { |
| 870 | groupStoreEntriesByKey.remove(entry.getKey()); |
| 871 | notifyDelegate(new GroupEvent(Type.GROUP_REMOVED, entry.getValue())); |
| 872 | }); |
| 873 | } |
| 874 | |
| 875 | @Override |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 876 | public void deviceInitialAuditCompleted(DeviceId deviceId, |
| 877 | boolean completed) { |
| 878 | synchronized (deviceAuditStatus) { |
| 879 | if (completed) { |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 880 | log.debug("AUDIT completed for device {}", |
| 881 | deviceId); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 882 | deviceAuditStatus.put(deviceId, true); |
| 883 | // Execute all pending group requests |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 884 | List<StoredGroupEntry> pendingGroupRequests = |
| 885 | getPendingGroupKeyTable().values() |
| 886 | .stream() |
| 887 | .filter(g-> g.deviceId().equals(deviceId)) |
| 888 | .collect(Collectors.toList()); |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 889 | log.debug("processing pending group add requests for device {} and number of pending requests {}", |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 890 | deviceId, |
| 891 | pendingGroupRequests.size()); |
| 892 | for (Group group:pendingGroupRequests) { |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 893 | GroupDescription tmp = new DefaultGroupDescription( |
| 894 | group.deviceId(), |
| 895 | group.type(), |
| 896 | group.buckets(), |
| 897 | group.appCookie(), |
Saurav Das | 100e3b8 | 2015-04-30 11:12:10 -0700 | [diff] [blame] | 898 | group.givenGroupId(), |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 899 | group.appId()); |
| 900 | storeGroupDescriptionInternal(tmp); |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 901 | getPendingGroupKeyTable(). |
| 902 | remove(new GroupStoreKeyMapKey(deviceId, group.appCookie())); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 903 | } |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 904 | } else { |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 905 | Boolean audited = deviceAuditStatus.get(deviceId); |
| 906 | if (audited != null && audited) { |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 907 | log.debug("Clearing AUDIT status for device {}", deviceId); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 908 | deviceAuditStatus.put(deviceId, false); |
| 909 | } |
| 910 | } |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | @Override |
| 915 | public boolean deviceInitialAuditStatus(DeviceId deviceId) { |
| 916 | synchronized (deviceAuditStatus) { |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 917 | Boolean audited = deviceAuditStatus.get(deviceId); |
| 918 | return audited != null && audited; |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 919 | } |
| 920 | } |
| 921 | |
| 922 | @Override |
| 923 | public void groupOperationFailed(DeviceId deviceId, GroupOperation operation) { |
| 924 | |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 925 | StoredGroupEntry existing = getStoredGroupEntry(deviceId, |
| 926 | operation.groupId()); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 927 | |
| 928 | if (existing == null) { |
| 929 | log.warn("No group entry with ID {} found ", operation.groupId()); |
| 930 | return; |
| 931 | } |
| 932 | |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 933 | log.warn("groupOperationFailed: group operation {} failed" |
Saurav Das | 0fd79d9 | 2016-03-07 10:58:36 -0800 | [diff] [blame^] | 934 | + "for group {} in device {} with code {}", |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 935 | operation.opType(), |
| 936 | existing.id(), |
Saurav Das | 0fd79d9 | 2016-03-07 10:58:36 -0800 | [diff] [blame^] | 937 | existing.deviceId(), |
| 938 | operation.failureCode()); |
| 939 | if (operation.failureCode() == GroupOperation.GroupMsgErrorCode.GROUP_EXISTS) { |
| 940 | log.warn("Current extraneous groups in device:{} are: {}", |
| 941 | deviceId, |
| 942 | getExtraneousGroups(deviceId)); |
| 943 | } |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 944 | switch (operation.opType()) { |
| 945 | case ADD: |
Srikanth Vavilapalli | 5428b6c | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 946 | if (existing.state() == GroupState.PENDING_ADD) { |
Srikanth Vavilapalli | 5428b6c | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 947 | notifyDelegate(new GroupEvent(Type.GROUP_ADD_FAILED, existing)); |
| 948 | log.warn("groupOperationFailed: cleaningup " |
| 949 | + "group {} from store in device {}....", |
| 950 | existing.id(), |
| 951 | existing.deviceId()); |
| 952 | //Removal from groupid based map will happen in the |
| 953 | //map update listener |
| 954 | getGroupStoreKeyMap().remove(new GroupStoreKeyMapKey(existing.deviceId(), |
| 955 | existing.appCookie())); |
| 956 | } |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 957 | break; |
| 958 | case MODIFY: |
| 959 | notifyDelegate(new GroupEvent(Type.GROUP_UPDATE_FAILED, existing)); |
| 960 | break; |
| 961 | case DELETE: |
| 962 | notifyDelegate(new GroupEvent(Type.GROUP_REMOVE_FAILED, existing)); |
| 963 | break; |
| 964 | default: |
| 965 | log.warn("Unknown group operation type {}", operation.opType()); |
| 966 | } |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | @Override |
| 970 | public void addOrUpdateExtraneousGroupEntry(Group group) { |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 971 | log.debug("add/update extraneous group entry {} in device {}", |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 972 | group.id(), |
| 973 | group.deviceId()); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 974 | ConcurrentMap<GroupId, Group> extraneousIdTable = |
| 975 | getExtraneousGroupIdTable(group.deviceId()); |
| 976 | extraneousIdTable.put(group.id(), group); |
Srikanth Vavilapalli | e48b3cf | 2015-07-06 11:43:07 -0700 | [diff] [blame] | 977 | // Don't remove the extraneous groups, instead re-use it when |
| 978 | // a group request comes with the same set of buckets |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | @Override |
| 982 | public void removeExtraneousGroupEntry(Group group) { |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 983 | log.debug("remove extraneous group entry {} of device {} from store", |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 984 | group.id(), |
| 985 | group.deviceId()); |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 986 | ConcurrentMap<GroupId, Group> extraneousIdTable = |
| 987 | getExtraneousGroupIdTable(group.deviceId()); |
| 988 | extraneousIdTable.remove(group.id()); |
| 989 | } |
| 990 | |
| 991 | @Override |
| 992 | public Iterable<Group> getExtraneousGroups(DeviceId deviceId) { |
| 993 | // flatten and make iterator unmodifiable |
| 994 | return FluentIterable.from( |
| 995 | getExtraneousGroupIdTable(deviceId).values()); |
| 996 | } |
| 997 | |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 998 | /** |
Srikanth Vavilapalli | 6a9d4e4 | 2015-03-30 19:41:56 -0700 | [diff] [blame] | 999 | * Map handler to receive any events when the group key map is updated. |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 1000 | */ |
Srikanth Vavilapalli | 6a9d4e4 | 2015-03-30 19:41:56 -0700 | [diff] [blame] | 1001 | private class GroupStoreKeyMapListener implements |
Madan Jampani | 0b84753 | 2016-03-03 13:44:15 -0800 | [diff] [blame] | 1002 | MapEventListener<GroupStoreKeyMapKey, StoredGroupEntry> { |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 1003 | |
| 1004 | @Override |
Madan Jampani | 0b84753 | 2016-03-03 13:44:15 -0800 | [diff] [blame] | 1005 | public void event(MapEvent<GroupStoreKeyMapKey, StoredGroupEntry> mapEvent) { |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 1006 | GroupEvent groupEvent = null; |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 1007 | GroupStoreKeyMapKey key = mapEvent.key(); |
Madan Jampani | 0b84753 | 2016-03-03 13:44:15 -0800 | [diff] [blame] | 1008 | StoredGroupEntry group = Versioned.valueOrNull(mapEvent.newValue()); |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 1009 | if ((key == null) && (group == null)) { |
| 1010 | log.error("GroupStoreKeyMapListener: Received " |
| 1011 | + "event {} with null entry", mapEvent.type()); |
| 1012 | return; |
| 1013 | } else if (group == null) { |
| 1014 | group = getGroupIdTable(key.deviceId()).values() |
| 1015 | .stream() |
| 1016 | .filter((storedGroup) -> (storedGroup.appCookie().equals(key.appCookie))) |
| 1017 | .findFirst().get(); |
| 1018 | if (group == null) { |
| 1019 | log.error("GroupStoreKeyMapListener: Received " |
| 1020 | + "event {} with null entry... can not process", mapEvent.type()); |
| 1021 | return; |
| 1022 | } |
| 1023 | } |
| 1024 | log.trace("received groupid map event {} for id {} in device {}", |
| 1025 | mapEvent.type(), |
| 1026 | group.id(), |
| 1027 | key.deviceId()); |
Madan Jampani | 0b84753 | 2016-03-03 13:44:15 -0800 | [diff] [blame] | 1028 | if (mapEvent.type() == MapEvent.Type.INSERT || mapEvent.type() == MapEvent.Type.UPDATE) { |
Srikanth Vavilapalli | 6a9d4e4 | 2015-03-30 19:41:56 -0700 | [diff] [blame] | 1029 | // Update the group ID table |
| 1030 | getGroupIdTable(group.deviceId()).put(group.id(), group); |
Madan Jampani | 0b84753 | 2016-03-03 13:44:15 -0800 | [diff] [blame] | 1031 | StoredGroupEntry value = Versioned.valueOrNull(mapEvent.newValue()); |
| 1032 | if (value.state() == Group.GroupState.ADDED) { |
| 1033 | if (value.isGroupStateAddedFirstTime()) { |
| 1034 | groupEvent = new GroupEvent(Type.GROUP_ADDED, value); |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 1035 | log.trace("Received first time GROUP_ADDED state update for id {} in device {}", |
| 1036 | group.id(), |
| 1037 | group.deviceId()); |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 1038 | } else { |
Madan Jampani | 0b84753 | 2016-03-03 13:44:15 -0800 | [diff] [blame] | 1039 | groupEvent = new GroupEvent(Type.GROUP_UPDATED, value); |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 1040 | log.trace("Received following GROUP_ADDED state update for id {} in device {}", |
| 1041 | group.id(), |
| 1042 | group.deviceId()); |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 1043 | } |
| 1044 | } |
Madan Jampani | 0b84753 | 2016-03-03 13:44:15 -0800 | [diff] [blame] | 1045 | } else if (mapEvent.type() == MapEvent.Type.REMOVE) { |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 1046 | groupEvent = new GroupEvent(Type.GROUP_REMOVED, group); |
Srikanth Vavilapalli | 6a9d4e4 | 2015-03-30 19:41:56 -0700 | [diff] [blame] | 1047 | // Remove the entry from the group ID table |
| 1048 | getGroupIdTable(group.deviceId()).remove(group.id(), group); |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | if (groupEvent != null) { |
| 1052 | notifyDelegate(groupEvent); |
| 1053 | } |
| 1054 | } |
| 1055 | } |
Madan Jampani | 01e05fb | 2015-08-13 13:29:36 -0700 | [diff] [blame] | 1056 | |
| 1057 | private void process(GroupStoreMessage groupOp) { |
| 1058 | log.debug("Received remote group operation {} request for device {}", |
| 1059 | groupOp.type(), |
| 1060 | groupOp.deviceId()); |
| 1061 | if (!mastershipService.isLocalMaster(groupOp.deviceId())) { |
| 1062 | log.warn("This node is not MASTER for device {}", groupOp.deviceId()); |
| 1063 | return; |
| 1064 | } |
| 1065 | if (groupOp.type() == GroupStoreMessage.Type.ADD) { |
| 1066 | storeGroupDescriptionInternal(groupOp.groupDesc()); |
| 1067 | } else if (groupOp.type() == GroupStoreMessage.Type.UPDATE) { |
| 1068 | updateGroupDescriptionInternal(groupOp.deviceId(), |
| 1069 | groupOp.appCookie(), |
| 1070 | groupOp.updateType(), |
| 1071 | groupOp.updateBuckets(), |
| 1072 | groupOp.newAppCookie()); |
| 1073 | } else if (groupOp.type() == GroupStoreMessage.Type.DELETE) { |
| 1074 | deleteGroupDescriptionInternal(groupOp.deviceId(), |
| 1075 | groupOp.appCookie()); |
| 1076 | } |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | /** |
| 1080 | * Flattened map key to be used to store group entries. |
| 1081 | */ |
Ray Milkey | b3c5ce2 | 2015-08-10 09:07:36 -0700 | [diff] [blame] | 1082 | protected static class GroupStoreMapKey { |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 1083 | private final DeviceId deviceId; |
| 1084 | |
| 1085 | public GroupStoreMapKey(DeviceId deviceId) { |
| 1086 | this.deviceId = deviceId; |
| 1087 | } |
| 1088 | |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 1089 | public DeviceId deviceId() { |
| 1090 | return deviceId; |
| 1091 | } |
| 1092 | |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 1093 | @Override |
| 1094 | public boolean equals(Object o) { |
| 1095 | if (this == o) { |
| 1096 | return true; |
| 1097 | } |
| 1098 | if (!(o instanceof GroupStoreMapKey)) { |
| 1099 | return false; |
| 1100 | } |
| 1101 | GroupStoreMapKey that = (GroupStoreMapKey) o; |
| 1102 | return this.deviceId.equals(that.deviceId); |
| 1103 | } |
| 1104 | |
| 1105 | @Override |
| 1106 | public int hashCode() { |
| 1107 | int result = 17; |
| 1108 | |
| 1109 | result = 31 * result + Objects.hash(this.deviceId); |
| 1110 | |
| 1111 | return result; |
| 1112 | } |
| 1113 | } |
| 1114 | |
Ray Milkey | b3c5ce2 | 2015-08-10 09:07:36 -0700 | [diff] [blame] | 1115 | protected static class GroupStoreKeyMapKey extends GroupStoreMapKey { |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 1116 | private final GroupKey appCookie; |
| 1117 | public GroupStoreKeyMapKey(DeviceId deviceId, |
| 1118 | GroupKey appCookie) { |
| 1119 | super(deviceId); |
| 1120 | this.appCookie = appCookie; |
| 1121 | } |
| 1122 | |
| 1123 | @Override |
| 1124 | public boolean equals(Object o) { |
| 1125 | if (this == o) { |
| 1126 | return true; |
| 1127 | } |
| 1128 | if (!(o instanceof GroupStoreKeyMapKey)) { |
| 1129 | return false; |
| 1130 | } |
| 1131 | GroupStoreKeyMapKey that = (GroupStoreKeyMapKey) o; |
| 1132 | return (super.equals(that) && |
| 1133 | this.appCookie.equals(that.appCookie)); |
| 1134 | } |
| 1135 | |
| 1136 | @Override |
| 1137 | public int hashCode() { |
| 1138 | int result = 17; |
| 1139 | |
| 1140 | result = 31 * result + super.hashCode() + Objects.hash(this.appCookie); |
| 1141 | |
| 1142 | return result; |
| 1143 | } |
| 1144 | } |
| 1145 | |
Ray Milkey | b3c5ce2 | 2015-08-10 09:07:36 -0700 | [diff] [blame] | 1146 | protected static class GroupStoreIdMapKey extends GroupStoreMapKey { |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 1147 | private final GroupId groupId; |
| 1148 | public GroupStoreIdMapKey(DeviceId deviceId, |
| 1149 | GroupId groupId) { |
| 1150 | super(deviceId); |
| 1151 | this.groupId = groupId; |
| 1152 | } |
| 1153 | |
| 1154 | @Override |
| 1155 | public boolean equals(Object o) { |
| 1156 | if (this == o) { |
| 1157 | return true; |
| 1158 | } |
| 1159 | if (!(o instanceof GroupStoreIdMapKey)) { |
| 1160 | return false; |
| 1161 | } |
| 1162 | GroupStoreIdMapKey that = (GroupStoreIdMapKey) o; |
| 1163 | return (super.equals(that) && |
| 1164 | this.groupId.equals(that.groupId)); |
| 1165 | } |
| 1166 | |
| 1167 | @Override |
| 1168 | public int hashCode() { |
| 1169 | int result = 17; |
| 1170 | |
| 1171 | result = 31 * result + super.hashCode() + Objects.hash(this.groupId); |
| 1172 | |
| 1173 | return result; |
| 1174 | } |
| 1175 | } |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 1176 | |
| 1177 | @Override |
| 1178 | public void pushGroupMetrics(DeviceId deviceId, |
| 1179 | Collection<Group> groupEntries) { |
| 1180 | boolean deviceInitialAuditStatus = |
| 1181 | deviceInitialAuditStatus(deviceId); |
| 1182 | Set<Group> southboundGroupEntries = |
| 1183 | Sets.newHashSet(groupEntries); |
| 1184 | Set<StoredGroupEntry> storedGroupEntries = |
| 1185 | Sets.newHashSet(getStoredGroups(deviceId)); |
| 1186 | Set<Group> extraneousStoredEntries = |
| 1187 | Sets.newHashSet(getExtraneousGroups(deviceId)); |
| 1188 | |
| 1189 | log.trace("pushGroupMetrics: Displaying all ({}) southboundGroupEntries for device {}", |
| 1190 | southboundGroupEntries.size(), |
| 1191 | deviceId); |
| 1192 | for (Iterator<Group> it = southboundGroupEntries.iterator(); it.hasNext();) { |
| 1193 | Group group = it.next(); |
| 1194 | log.trace("Group {} in device {}", group, deviceId); |
| 1195 | } |
| 1196 | |
| 1197 | log.trace("Displaying all ({}) stored group entries for device {}", |
| 1198 | storedGroupEntries.size(), |
| 1199 | deviceId); |
| 1200 | for (Iterator<StoredGroupEntry> it1 = storedGroupEntries.iterator(); |
| 1201 | it1.hasNext();) { |
| 1202 | Group group = it1.next(); |
| 1203 | log.trace("Stored Group {} for device {}", group, deviceId); |
| 1204 | } |
| 1205 | |
| 1206 | for (Iterator<Group> it2 = southboundGroupEntries.iterator(); it2.hasNext();) { |
| 1207 | Group group = it2.next(); |
| 1208 | if (storedGroupEntries.remove(group)) { |
| 1209 | // we both have the group, let's update some info then. |
| 1210 | log.trace("Group AUDIT: group {} exists in both planes for device {}", |
| 1211 | group.id(), deviceId); |
| 1212 | groupAdded(group); |
| 1213 | it2.remove(); |
| 1214 | } |
| 1215 | } |
| 1216 | for (Group group : southboundGroupEntries) { |
| 1217 | if (getGroup(group.deviceId(), group.id()) != null) { |
| 1218 | // There is a group existing with the same id |
| 1219 | // It is possible that group update is |
| 1220 | // in progress while we got a stale info from switch |
| 1221 | if (!storedGroupEntries.remove(getGroup( |
| 1222 | group.deviceId(), group.id()))) { |
| 1223 | log.warn("Group AUDIT: Inconsistent state:" |
| 1224 | + "Group exists in ID based table while " |
| 1225 | + "not present in key based table"); |
| 1226 | } |
| 1227 | } else { |
| 1228 | // there are groups in the switch that aren't in the store |
| 1229 | log.debug("Group AUDIT: extraneous group {} exists in data plane for device {}", |
| 1230 | group.id(), deviceId); |
| 1231 | extraneousStoredEntries.remove(group); |
| 1232 | extraneousGroup(group); |
| 1233 | } |
| 1234 | } |
| 1235 | for (Group group : storedGroupEntries) { |
| 1236 | // there are groups in the store that aren't in the switch |
| 1237 | log.debug("Group AUDIT: group {} missing in data plane for device {}", |
| 1238 | group.id(), deviceId); |
| 1239 | groupMissing(group); |
| 1240 | } |
| 1241 | for (Group group : extraneousStoredEntries) { |
| 1242 | // there are groups in the extraneous store that |
| 1243 | // aren't in the switch |
Saurav Das | 0fd79d9 | 2016-03-07 10:58:36 -0800 | [diff] [blame^] | 1244 | log.debug("Group AUDIT: clearing extraneous group {} from store for device {}", |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 1245 | group.id(), deviceId); |
| 1246 | removeExtraneousGroupEntry(group); |
| 1247 | } |
| 1248 | |
| 1249 | if (!deviceInitialAuditStatus) { |
Saurav Das | 0fd79d9 | 2016-03-07 10:58:36 -0800 | [diff] [blame^] | 1250 | log.info("Group AUDIT: Setting device {} initial AUDIT completed", |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 1251 | deviceId); |
| 1252 | deviceInitialAuditCompleted(deviceId, true); |
| 1253 | } |
| 1254 | } |
| 1255 | |
| 1256 | private void groupMissing(Group group) { |
| 1257 | switch (group.state()) { |
| 1258 | case PENDING_DELETE: |
| 1259 | log.debug("Group {} delete confirmation from device {}", |
| 1260 | group, group.deviceId()); |
| 1261 | removeGroupEntry(group); |
| 1262 | break; |
| 1263 | case ADDED: |
| 1264 | case PENDING_ADD: |
Srikanth Vavilapalli | 5428b6c | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 1265 | case PENDING_ADD_RETRY: |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 1266 | case PENDING_UPDATE: |
| 1267 | log.debug("Group {} is in store but not on device {}", |
| 1268 | group, group.deviceId()); |
| 1269 | StoredGroupEntry existing = |
| 1270 | getStoredGroupEntry(group.deviceId(), group.id()); |
Srikanth Vavilapalli | 5428b6c | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 1271 | log.debug("groupMissing: group entry {} in device {} moving from {} to PENDING_ADD_RETRY", |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 1272 | existing.id(), |
| 1273 | existing.deviceId(), |
| 1274 | existing.state()); |
Srikanth Vavilapalli | 5428b6c | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 1275 | existing.setState(Group.GroupState.PENDING_ADD_RETRY); |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 1276 | //Re-PUT map entries to trigger map update events |
| 1277 | getGroupStoreKeyMap(). |
| 1278 | put(new GroupStoreKeyMapKey(existing.deviceId(), |
| 1279 | existing.appCookie()), existing); |
| 1280 | notifyDelegate(new GroupEvent(GroupEvent.Type.GROUP_ADD_REQUESTED, |
| 1281 | group)); |
| 1282 | break; |
| 1283 | default: |
| 1284 | log.debug("Group {} has not been installed.", group); |
| 1285 | break; |
| 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | private void extraneousGroup(Group group) { |
Saurav Das | 0fd79d9 | 2016-03-07 10:58:36 -0800 | [diff] [blame^] | 1290 | log.trace("Group {} is on device {} but not in store.", |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 1291 | group, group.deviceId()); |
| 1292 | addOrUpdateExtraneousGroupEntry(group); |
| 1293 | } |
| 1294 | |
| 1295 | private void groupAdded(Group group) { |
| 1296 | log.trace("Group {} Added or Updated in device {}", |
| 1297 | group, group.deviceId()); |
| 1298 | addOrUpdateGroupEntry(group); |
| 1299 | } |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 1300 | } |