Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -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.net.group.impl; |
| 17 | |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 18 | import org.apache.felix.scr.annotations.Activate; |
| 19 | import org.apache.felix.scr.annotations.Component; |
| 20 | import org.apache.felix.scr.annotations.Deactivate; |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 21 | import org.apache.felix.scr.annotations.Modified; |
| 22 | import org.apache.felix.scr.annotations.Property; |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 23 | import org.apache.felix.scr.annotations.Reference; |
| 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 25 | import org.apache.felix.scr.annotations.Service; |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 26 | import org.onlab.util.Tools; |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 27 | import org.onosproject.cfg.ComponentConfigService; |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 28 | import org.onosproject.core.ApplicationId; |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 29 | import org.onosproject.net.DeviceId; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 30 | import org.onosproject.net.device.DeviceEvent; |
| 31 | import org.onosproject.net.device.DeviceListener; |
| 32 | import org.onosproject.net.device.DeviceService; |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 33 | import org.onosproject.net.group.Group; |
| 34 | import org.onosproject.net.group.GroupBuckets; |
| 35 | import org.onosproject.net.group.GroupDescription; |
| 36 | import org.onosproject.net.group.GroupEvent; |
| 37 | import org.onosproject.net.group.GroupKey; |
| 38 | import org.onosproject.net.group.GroupListener; |
| 39 | import org.onosproject.net.group.GroupOperation; |
| 40 | import org.onosproject.net.group.GroupOperations; |
| 41 | import org.onosproject.net.group.GroupProvider; |
| 42 | import org.onosproject.net.group.GroupProviderRegistry; |
| 43 | import org.onosproject.net.group.GroupProviderService; |
| 44 | import org.onosproject.net.group.GroupService; |
| 45 | import org.onosproject.net.group.GroupStore; |
| 46 | import org.onosproject.net.group.GroupStore.UpdateType; |
| 47 | import org.onosproject.net.group.GroupStoreDelegate; |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 48 | import org.onosproject.net.provider.AbstractListenerProviderRegistry; |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 49 | import org.onosproject.net.provider.AbstractProviderService; |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 50 | import org.osgi.service.component.ComponentContext; |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 51 | import org.slf4j.Logger; |
| 52 | |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 53 | import java.util.Collection; |
| 54 | import java.util.Collections; |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 55 | import java.util.Dictionary; |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 56 | |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame] | 57 | import static org.onosproject.security.AppGuard.checkPermission; |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 58 | import static org.onosproject.security.AppPermission.Type.GROUP_READ; |
| 59 | import static org.onosproject.security.AppPermission.Type.GROUP_WRITE; |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 60 | import static org.slf4j.LoggerFactory.getLogger; |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 61 | |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame] | 62 | |
| 63 | |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 64 | /** |
| 65 | * Provides implementation of the group service APIs. |
| 66 | */ |
| 67 | @Component(immediate = true) |
| 68 | @Service |
| 69 | public class GroupManager |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 70 | extends AbstractListenerProviderRegistry<GroupEvent, GroupListener, |
| 71 | GroupProvider, GroupProviderService> |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 72 | implements GroupService, GroupProviderRegistry { |
| 73 | |
| 74 | private final Logger log = getLogger(getClass()); |
| 75 | |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 76 | private final GroupStoreDelegate delegate = new InternalGroupStoreDelegate(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 77 | private final DeviceListener deviceListener = new InternalDeviceListener(); |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 78 | |
| 79 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 80 | protected GroupStore store; |
| 81 | |
| 82 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 83 | protected DeviceService deviceService; |
| 84 | |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 85 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 86 | protected ComponentConfigService cfgService; |
| 87 | |
| 88 | @Property(name = "purgeOnDisconnection", boolValue = false, |
| 89 | label = "Purge entries associated with a device when the device goes offline") |
| 90 | private boolean purgeOnDisconnection = false; |
Andrea Campanella | 6ee7392 | 2016-02-03 18:00:00 -0800 | [diff] [blame] | 91 | private final GroupDriverProvider defaultProvider = new GroupDriverProvider(); |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 92 | |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 93 | @Activate |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 94 | public void activate(ComponentContext context) { |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 95 | store.setDelegate(delegate); |
| 96 | eventDispatcher.addSink(GroupEvent.class, listenerRegistry); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 97 | deviceService.addListener(deviceListener); |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 98 | cfgService.registerProperties(getClass()); |
| 99 | modified(context); |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 100 | log.info("Started"); |
| 101 | } |
| 102 | |
| 103 | @Deactivate |
| 104 | public void deactivate() { |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 105 | cfgService.unregisterProperties(getClass(), false); |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 106 | store.unsetDelegate(delegate); |
| 107 | eventDispatcher.removeSink(GroupEvent.class); |
| 108 | log.info("Stopped"); |
| 109 | } |
| 110 | |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 111 | @Modified |
| 112 | public void modified(ComponentContext context) { |
| 113 | if (context != null) { |
| 114 | readComponentConfiguration(context); |
| 115 | } |
Andrea Campanella | 6ee7392 | 2016-02-03 18:00:00 -0800 | [diff] [blame] | 116 | defaultProvider.init(deviceService); |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | protected GroupProvider defaultProvider() { |
| 121 | return defaultProvider; |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Extracts properties from the component configuration context. |
| 126 | * |
| 127 | * @param context the component context |
| 128 | */ |
| 129 | private void readComponentConfiguration(ComponentContext context) { |
| 130 | Dictionary<?, ?> properties = context.getProperties(); |
| 131 | Boolean flag; |
| 132 | |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 133 | flag = Tools.isPropertyEnabled(properties, "purgeOnDisconnection"); |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 134 | if (flag == null) { |
| 135 | log.info("PurgeOnDisconnection is not configured, " + |
| 136 | "using current value of {}", purgeOnDisconnection); |
| 137 | } else { |
| 138 | purgeOnDisconnection = flag; |
| 139 | log.info("Configured. PurgeOnDisconnection is {}", |
| 140 | purgeOnDisconnection ? "enabled" : "disabled"); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | /** |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 145 | * Create a group in the specified device with the provided parameters. |
| 146 | * |
| 147 | * @param groupDesc group creation parameters |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 148 | */ |
| 149 | @Override |
| 150 | public void addGroup(GroupDescription groupDesc) { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 151 | checkPermission(GROUP_WRITE); |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 152 | store.storeGroupDescription(groupDesc); |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Return a group object associated to an application cookie. |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 157 | * <p> |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 158 | * NOTE1: The presence of group object in the system does not |
| 159 | * guarantee that the "group" is actually created in device. |
| 160 | * GROUP_ADDED notification would confirm the creation of |
| 161 | * this group in data plane. |
| 162 | * |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 163 | * @param deviceId device identifier |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 164 | * @param appCookie application cookie to be used for lookup |
| 165 | * @return group associated with the application cookie or |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 166 | * NULL if Group is not found for the provided cookie |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 167 | */ |
| 168 | @Override |
| 169 | public Group getGroup(DeviceId deviceId, GroupKey appCookie) { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 170 | checkPermission(GROUP_READ); |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 171 | return store.getGroup(deviceId, appCookie); |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Append buckets to existing group. The caller can optionally |
| 176 | * associate a new cookie during this updation. GROUP_UPDATED or |
| 177 | * GROUP_UPDATE_FAILED notifications would be provided along with |
| 178 | * cookie depending on the result of the operation on the device. |
| 179 | * |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 180 | * @param deviceId device identifier |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 181 | * @param oldCookie cookie to be used to retrieve the existing group |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 182 | * @param buckets immutable list of group bucket to be added |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 183 | * @param newCookie immutable cookie to be used post update operation |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 184 | * @param appId Application Id |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 185 | */ |
| 186 | @Override |
| 187 | public void addBucketsToGroup(DeviceId deviceId, |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 188 | GroupKey oldCookie, |
| 189 | GroupBuckets buckets, |
| 190 | GroupKey newCookie, |
| 191 | ApplicationId appId) { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 192 | checkPermission(GROUP_WRITE); |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 193 | store.updateGroupDescription(deviceId, |
| 194 | oldCookie, |
| 195 | UpdateType.ADD, |
| 196 | buckets, |
| 197 | newCookie); |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Remove buckets from existing group. The caller can optionally |
| 202 | * associate a new cookie during this updation. GROUP_UPDATED or |
| 203 | * GROUP_UPDATE_FAILED notifications would be provided along with |
| 204 | * cookie depending on the result of the operation on the device. |
| 205 | * |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 206 | * @param deviceId device identifier |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 207 | * @param oldCookie cookie to be used to retrieve the existing group |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 208 | * @param buckets immutable list of group bucket to be removed |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 209 | * @param newCookie immutable cookie to be used post update operation |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 210 | * @param appId Application Id |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 211 | */ |
| 212 | @Override |
| 213 | public void removeBucketsFromGroup(DeviceId deviceId, |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 214 | GroupKey oldCookie, |
| 215 | GroupBuckets buckets, |
| 216 | GroupKey newCookie, |
| 217 | ApplicationId appId) { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 218 | checkPermission(GROUP_WRITE); |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 219 | store.updateGroupDescription(deviceId, |
| 220 | oldCookie, |
| 221 | UpdateType.REMOVE, |
| 222 | buckets, |
| 223 | newCookie); |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Delete a group associated to an application cookie. |
| 228 | * GROUP_DELETED or GROUP_DELETE_FAILED notifications would be |
| 229 | * provided along with cookie depending on the result of the |
| 230 | * operation on the device. |
| 231 | * |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 232 | * @param deviceId device identifier |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 233 | * @param appCookie application cookie to be used for lookup |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 234 | * @param appId Application Id |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 235 | */ |
| 236 | @Override |
| 237 | public void removeGroup(DeviceId deviceId, |
| 238 | GroupKey appCookie, |
| 239 | ApplicationId appId) { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 240 | checkPermission(GROUP_WRITE); |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 241 | store.deleteGroupDescription(deviceId, appCookie); |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * Retrieve all groups created by an application in the specified device |
| 246 | * as seen by current controller instance. |
| 247 | * |
| 248 | * @param deviceId device identifier |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 249 | * @param appId application id |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 250 | * @return collection of immutable group objects created by the application |
| 251 | */ |
| 252 | @Override |
| 253 | public Iterable<Group> getGroups(DeviceId deviceId, |
| 254 | ApplicationId appId) { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 255 | checkPermission(GROUP_READ); |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 256 | return store.getGroups(deviceId); |
| 257 | } |
| 258 | |
Jonathan Hart | 3260069 | 2015-03-09 10:38:40 -0700 | [diff] [blame] | 259 | @Override |
| 260 | public Iterable<Group> getGroups(DeviceId deviceId) { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 261 | checkPermission(GROUP_READ); |
Jonathan Hart | 3260069 | 2015-03-09 10:38:40 -0700 | [diff] [blame] | 262 | return store.getGroups(deviceId); |
| 263 | } |
| 264 | |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 265 | @Override |
| 266 | protected GroupProviderService createProviderService(GroupProvider provider) { |
| 267 | return new InternalGroupProviderService(provider); |
| 268 | } |
| 269 | |
| 270 | private class InternalGroupStoreDelegate implements GroupStoreDelegate { |
| 271 | @Override |
| 272 | public void notify(GroupEvent event) { |
| 273 | final Group group = event.subject(); |
| 274 | GroupProvider groupProvider = |
| 275 | getProvider(group.deviceId()); |
| 276 | GroupOperations groupOps = null; |
| 277 | switch (event.type()) { |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 278 | case GROUP_ADD_REQUESTED: |
| 279 | log.debug("GROUP_ADD_REQUESTED for Group {} on device {}", |
| 280 | group.id(), group.deviceId()); |
| 281 | GroupOperation groupAddOp = GroupOperation. |
| 282 | createAddGroupOperation(group.id(), |
| 283 | group.type(), |
| 284 | group.buckets()); |
| 285 | groupOps = new GroupOperations( |
| 286 | Collections.singletonList(groupAddOp)); |
| 287 | groupProvider.performGroupOperation(group.deviceId(), groupOps); |
| 288 | break; |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 289 | |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 290 | case GROUP_UPDATE_REQUESTED: |
| 291 | log.debug("GROUP_UPDATE_REQUESTED for Group {} on device {}", |
| 292 | group.id(), group.deviceId()); |
| 293 | GroupOperation groupModifyOp = GroupOperation. |
| 294 | createModifyGroupOperation(group.id(), |
| 295 | group.type(), |
| 296 | group.buckets()); |
| 297 | groupOps = new GroupOperations( |
| 298 | Collections.singletonList(groupModifyOp)); |
| 299 | groupProvider.performGroupOperation(group.deviceId(), groupOps); |
| 300 | break; |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 301 | |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 302 | case GROUP_REMOVE_REQUESTED: |
| 303 | log.debug("GROUP_REMOVE_REQUESTED for Group {} on device {}", |
| 304 | group.id(), group.deviceId()); |
| 305 | GroupOperation groupDeleteOp = GroupOperation. |
| 306 | createDeleteGroupOperation(group.id(), |
| 307 | group.type()); |
| 308 | groupOps = new GroupOperations( |
| 309 | Collections.singletonList(groupDeleteOp)); |
| 310 | groupProvider.performGroupOperation(group.deviceId(), groupOps); |
| 311 | break; |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 312 | |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 313 | case GROUP_ADDED: |
| 314 | case GROUP_UPDATED: |
| 315 | case GROUP_REMOVED: |
| 316 | case GROUP_ADD_FAILED: |
| 317 | case GROUP_UPDATE_FAILED: |
| 318 | case GROUP_REMOVE_FAILED: |
| 319 | post(event); |
| 320 | break; |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 321 | |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 322 | default: |
| 323 | break; |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | private class InternalGroupProviderService |
| 329 | extends AbstractProviderService<GroupProvider> |
| 330 | implements GroupProviderService { |
| 331 | |
| 332 | protected InternalGroupProviderService(GroupProvider provider) { |
| 333 | super(provider); |
| 334 | } |
| 335 | |
| 336 | @Override |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 337 | public void groupOperationFailed(DeviceId deviceId, GroupOperation operation) { |
sangho | 7ff0181 | 2015-02-09 16:21:53 -0800 | [diff] [blame] | 338 | store.groupOperationFailed(deviceId, operation); |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 339 | } |
| 340 | |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 341 | @Override |
| 342 | public void pushGroupMetrics(DeviceId deviceId, |
| 343 | Collection<Group> groupEntries) { |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 344 | log.trace("Received group metrics from device {}", deviceId); |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 345 | checkValidity(); |
| 346 | store.pushGroupMetrics(deviceId, groupEntries); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | |
| 350 | private class InternalDeviceListener implements DeviceListener { |
| 351 | |
| 352 | @Override |
| 353 | public void event(DeviceEvent event) { |
| 354 | switch (event.type()) { |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 355 | case DEVICE_REMOVED: |
| 356 | case DEVICE_AVAILABILITY_CHANGED: |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 357 | DeviceId deviceId = event.subject().id(); |
| 358 | if (!deviceService.isAvailable(deviceId)) { |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 359 | log.debug("Device {} became un available; clearing initial audit status", |
| 360 | event.type(), event.subject().id()); |
| 361 | store.deviceInitialAuditCompleted(event.subject().id(), false); |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 362 | |
| 363 | if (purgeOnDisconnection) { |
| 364 | store.purgeGroupEntry(deviceId); |
| 365 | } |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 366 | } |
| 367 | break; |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 368 | default: |
| 369 | break; |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 370 | } |
| 371 | } |
| 372 | } |
| 373 | } |