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