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