blob: 0f6a5ac5bec0400a6493a0e2407e395eb5458564 [file] [log] [blame]
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -08003 *
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 */
16package org.onosproject.net.group.impl;
17
Jian Lid9b5f552016-03-11 18:15:31 -080018import org.onlab.util.Tools;
Charles Chan0c7c43b2016-01-14 17:39:20 -080019import org.onosproject.cfg.ComponentConfigService;
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -080020import org.onosproject.core.ApplicationId;
Andrea Campanella1ea15102017-09-04 16:00:09 +020021import org.onosproject.mastership.MastershipService;
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -080022import org.onosproject.net.DeviceId;
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080023import org.onosproject.net.device.DeviceEvent;
24import org.onosproject.net.device.DeviceListener;
25import org.onosproject.net.device.DeviceService;
Jordan Halterman59afc6a2017-10-30 16:12:42 -070026import org.onosproject.net.driver.DriverService;
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -080027import org.onosproject.net.group.Group;
28import org.onosproject.net.group.GroupBuckets;
29import org.onosproject.net.group.GroupDescription;
30import org.onosproject.net.group.GroupEvent;
31import org.onosproject.net.group.GroupKey;
32import org.onosproject.net.group.GroupListener;
33import org.onosproject.net.group.GroupOperation;
34import org.onosproject.net.group.GroupOperations;
35import org.onosproject.net.group.GroupProvider;
36import org.onosproject.net.group.GroupProviderRegistry;
37import org.onosproject.net.group.GroupProviderService;
38import org.onosproject.net.group.GroupService;
39import org.onosproject.net.group.GroupStore;
40import org.onosproject.net.group.GroupStore.UpdateType;
41import org.onosproject.net.group.GroupStoreDelegate;
Jian Lid9b5f552016-03-11 18:15:31 -080042import org.onosproject.net.provider.AbstractListenerProviderRegistry;
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -080043import org.onosproject.net.provider.AbstractProviderService;
Charles Chan0c7c43b2016-01-14 17:39:20 -080044import org.osgi.service.component.ComponentContext;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070045import org.osgi.service.component.annotations.Activate;
46import org.osgi.service.component.annotations.Component;
47import org.osgi.service.component.annotations.Deactivate;
48import org.osgi.service.component.annotations.Modified;
49import org.osgi.service.component.annotations.Reference;
50import org.osgi.service.component.annotations.ReferenceCardinality;
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -080051import org.slf4j.Logger;
52
Thomas Vachuska42e8cce2015-07-29 19:25:18 -070053import java.util.Collection;
54import java.util.Collections;
Charles Chan0c7c43b2016-01-14 17:39:20 -080055import java.util.Dictionary;
Charles Chan07f15f22018-05-08 21:35:50 -070056import java.util.concurrent.ExecutorService;
57import java.util.concurrent.Executors;
Thomas Vachuska42e8cce2015-07-29 19:25:18 -070058
Andrea Campanella1ea15102017-09-04 16:00:09 +020059import static com.google.common.base.Strings.isNullOrEmpty;
60import static org.onlab.util.Tools.get;
Charles Chan07f15f22018-05-08 21:35:50 -070061import static org.onlab.util.Tools.groupedThreads;
Ray Milkeyd04e2272018-10-16 18:20:18 -070062import static org.onosproject.net.OsgiPropertyConstants.GM_POLL_FREQUENCY;
63import static org.onosproject.net.OsgiPropertyConstants.GM_POLL_FREQUENCY_DEFAULT;
64import static org.onosproject.net.OsgiPropertyConstants.GM_PURGE_ON_DISCONNECTION;
65import static org.onosproject.net.OsgiPropertyConstants.GM_PURGE_ON_DISCONNECTION_DEFAULT;
Changhoon Yoon541ef712015-05-23 17:18:34 +090066import static org.onosproject.security.AppGuard.checkPermission;
Jian Lid9b5f552016-03-11 18:15:31 -080067import static org.onosproject.security.AppPermission.Type.GROUP_READ;
68import static org.onosproject.security.AppPermission.Type.GROUP_WRITE;
Thomas Vachuska42e8cce2015-07-29 19:25:18 -070069import static org.slf4j.LoggerFactory.getLogger;
Changhoon Yoonb856b812015-08-10 03:47:19 +090070
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -080071/**
72 * Provides implementation of the group service APIs.
73 */
Ray Milkeyd04e2272018-10-16 18:20:18 -070074@Component(
75 immediate = true,
76 service = {
77 GroupService.class,
78 GroupProviderRegistry.class
79 },
80 property = {
Ray Milkey2d7bca12018-10-17 14:51:52 -070081 GM_POLL_FREQUENCY + ":Integer=" + GM_POLL_FREQUENCY_DEFAULT,
82 GM_PURGE_ON_DISCONNECTION + ":Boolean=" + GM_PURGE_ON_DISCONNECTION_DEFAULT
Ray Milkeyd04e2272018-10-16 18:20:18 -070083 }
84)
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -080085public class GroupManager
Thomas Vachuska42e8cce2015-07-29 19:25:18 -070086 extends AbstractListenerProviderRegistry<GroupEvent, GroupListener,
87 GroupProvider, GroupProviderService>
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -080088 implements GroupService, GroupProviderRegistry {
89
90 private final Logger log = getLogger(getClass());
91
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -080092 private final GroupStoreDelegate delegate = new InternalGroupStoreDelegate();
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080093 private final DeviceListener deviceListener = new InternalDeviceListener();
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -080094
Charles Chan07f15f22018-05-08 21:35:50 -070095 private final GroupDriverProvider defaultProvider = new GroupDriverProvider();
96
97 private ExecutorService eventExecutor;
Andrea Campanella1ea15102017-09-04 16:00:09 +020098
Ray Milkeyd84f89b2018-08-17 14:54:17 -070099 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800100 protected GroupStore store;
101
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700102 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800103 protected DeviceService deviceService;
104
Jordan Halterman59afc6a2017-10-30 16:12:42 -0700105 // Reference the DriverService to ensure the service is bound prior to initialization of the GroupDriverProvider
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700106 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Jordan Halterman59afc6a2017-10-30 16:12:42 -0700107 protected DriverService driverService;
108
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700109 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Charles Chan0c7c43b2016-01-14 17:39:20 -0800110 protected ComponentConfigService cfgService;
111
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700112 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Andrea Campanella1ea15102017-09-04 16:00:09 +0200113 protected MastershipService mastershipService;
114
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700115 //@Property(name = "fallbackGroupPollFrequency", intValue = DEFAULT_POLL_FREQUENCY,
116 // label = "Frequency (in seconds) for polling groups via fallback provider")
Ray Milkeyd04e2272018-10-16 18:20:18 -0700117 private int fallbackGroupPollFrequency = GM_POLL_FREQUENCY_DEFAULT;
Andrea Campanella1ea15102017-09-04 16:00:09 +0200118
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700119 //@Property(name = "purgeOnDisconnection", boolValue = false,
120 // label = "Purge entries associated with a device when the device goes offline")
Ray Milkeyd04e2272018-10-16 18:20:18 -0700121 private boolean purgeOnDisconnection = GM_PURGE_ON_DISCONNECTION_DEFAULT;
Andrea Campanella1ea15102017-09-04 16:00:09 +0200122
Charles Chan0c7c43b2016-01-14 17:39:20 -0800123
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800124 @Activate
Charles Chan0c7c43b2016-01-14 17:39:20 -0800125 public void activate(ComponentContext context) {
Charles Chan07f15f22018-05-08 21:35:50 -0700126 eventExecutor = Executors.newSingleThreadExecutor(groupedThreads("onos/group", "event"));
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800127 store.setDelegate(delegate);
128 eventDispatcher.addSink(GroupEvent.class, listenerRegistry);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800129 deviceService.addListener(deviceListener);
Charles Chan0c7c43b2016-01-14 17:39:20 -0800130 cfgService.registerProperties(getClass());
131 modified(context);
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800132 log.info("Started");
133 }
134
135 @Deactivate
136 public void deactivate() {
Charles Chan07f15f22018-05-08 21:35:50 -0700137 eventExecutor.shutdown();
Andrea Campanella5a3c09c2017-12-01 13:57:48 +0100138 defaultProvider.terminate();
Andrea Campanella3f1c61e2016-04-01 17:30:12 -0700139 deviceService.removeListener(deviceListener);
Charles Chan0c7c43b2016-01-14 17:39:20 -0800140 cfgService.unregisterProperties(getClass(), false);
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800141 store.unsetDelegate(delegate);
142 eventDispatcher.removeSink(GroupEvent.class);
143 log.info("Stopped");
144 }
145
Charles Chan0c7c43b2016-01-14 17:39:20 -0800146 @Modified
147 public void modified(ComponentContext context) {
148 if (context != null) {
149 readComponentConfiguration(context);
150 }
Andrea Campanella1ea15102017-09-04 16:00:09 +0200151 defaultProvider.init(deviceService, new InternalGroupProviderService(defaultProvider),
152 mastershipService, fallbackGroupPollFrequency);
Andrea Campanella6ee73922016-02-03 18:00:00 -0800153 }
154
155 @Override
156 protected GroupProvider defaultProvider() {
157 return defaultProvider;
Charles Chan0c7c43b2016-01-14 17:39:20 -0800158 }
159
160 /**
161 * Extracts properties from the component configuration context.
162 *
163 * @param context the component context
164 */
165 private void readComponentConfiguration(ComponentContext context) {
166 Dictionary<?, ?> properties = context.getProperties();
167 Boolean flag;
168
Jian Lid9b5f552016-03-11 18:15:31 -0800169 flag = Tools.isPropertyEnabled(properties, "purgeOnDisconnection");
Charles Chan0c7c43b2016-01-14 17:39:20 -0800170 if (flag == null) {
171 log.info("PurgeOnDisconnection is not configured, " +
172 "using current value of {}", purgeOnDisconnection);
173 } else {
174 purgeOnDisconnection = flag;
175 log.info("Configured. PurgeOnDisconnection is {}",
176 purgeOnDisconnection ? "enabled" : "disabled");
177 }
Andrea Campanella1ea15102017-09-04 16:00:09 +0200178 String s = get(properties, "fallbackGroupPollFrequency");
179 try {
Ray Milkeyd04e2272018-10-16 18:20:18 -0700180 fallbackGroupPollFrequency = isNullOrEmpty(s) ? GM_POLL_FREQUENCY_DEFAULT : Integer.parseInt(s);
Andrea Campanella1ea15102017-09-04 16:00:09 +0200181 } catch (NumberFormatException e) {
Ray Milkeyd04e2272018-10-16 18:20:18 -0700182 fallbackGroupPollFrequency = GM_POLL_FREQUENCY_DEFAULT;
Andrea Campanella1ea15102017-09-04 16:00:09 +0200183 }
Charles Chan0c7c43b2016-01-14 17:39:20 -0800184 }
185
186 /**
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800187 * Create a group in the specified device with the provided parameters.
188 *
189 * @param groupDesc group creation parameters
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800190 */
191 @Override
192 public void addGroup(GroupDescription groupDesc) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900193 checkPermission(GROUP_WRITE);
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800194 store.storeGroupDescription(groupDesc);
195 }
196
197 /**
198 * Return a group object associated to an application cookie.
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700199 * <p>
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800200 * NOTE1: The presence of group object in the system does not
201 * guarantee that the "group" is actually created in device.
202 * GROUP_ADDED notification would confirm the creation of
203 * this group in data plane.
204 *
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700205 * @param deviceId device identifier
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800206 * @param appCookie application cookie to be used for lookup
207 * @return group associated with the application cookie or
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700208 * NULL if Group is not found for the provided cookie
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800209 */
210 @Override
211 public Group getGroup(DeviceId deviceId, GroupKey appCookie) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900212 checkPermission(GROUP_READ);
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800213 return store.getGroup(deviceId, appCookie);
214 }
215
216 /**
217 * Append buckets to existing group. The caller can optionally
218 * associate a new cookie during this updation. GROUP_UPDATED or
219 * GROUP_UPDATE_FAILED notifications would be provided along with
220 * cookie depending on the result of the operation on the device.
221 *
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700222 * @param deviceId device identifier
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800223 * @param oldCookie cookie to be used to retrieve the existing group
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700224 * @param buckets immutable list of group bucket to be added
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800225 * @param newCookie immutable cookie to be used post update operation
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700226 * @param appId Application Id
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800227 */
228 @Override
229 public void addBucketsToGroup(DeviceId deviceId,
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700230 GroupKey oldCookie,
231 GroupBuckets buckets,
232 GroupKey newCookie,
233 ApplicationId appId) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900234 checkPermission(GROUP_WRITE);
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800235 store.updateGroupDescription(deviceId,
236 oldCookie,
237 UpdateType.ADD,
238 buckets,
239 newCookie);
240 }
241
242 /**
243 * Remove buckets from existing group. The caller can optionally
244 * associate a new cookie during this updation. GROUP_UPDATED or
245 * GROUP_UPDATE_FAILED notifications would be provided along with
246 * cookie depending on the result of the operation on the device.
247 *
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700248 * @param deviceId device identifier
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800249 * @param oldCookie cookie to be used to retrieve the existing group
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700250 * @param buckets immutable list of group bucket to be removed
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800251 * @param newCookie immutable cookie to be used post update operation
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700252 * @param appId Application Id
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800253 */
254 @Override
255 public void removeBucketsFromGroup(DeviceId deviceId,
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700256 GroupKey oldCookie,
257 GroupBuckets buckets,
258 GroupKey newCookie,
259 ApplicationId appId) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900260 checkPermission(GROUP_WRITE);
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800261 store.updateGroupDescription(deviceId,
262 oldCookie,
263 UpdateType.REMOVE,
264 buckets,
265 newCookie);
266 }
267
Victor Silva0282ab82016-11-15 16:30:27 -0300268 /**
269 * Set buckets for an existing group. The caller can optionally
270 * associate a new cookie during this updation. GROUP_UPDATED or
271 * GROUP_UPDATE_FAILED notifications would be provided along with
272 * cookie depending on the result of the operation on the device.
273 *
274 * This operation overwrites the previous group buckets entirely.
275 *
276 * @param deviceId device identifier
277 * @param oldCookie cookie to be used to retrieve the existing group
278 * @param buckets immutable list of group buckets to be set
279 * @param newCookie immutable cookie to be used post update operation
280 * @param appId Application Id
281 */
282 @Override
283 public void setBucketsForGroup(DeviceId deviceId,
284 GroupKey oldCookie,
285 GroupBuckets buckets,
286 GroupKey newCookie,
287 ApplicationId appId) {
288 checkPermission(GROUP_WRITE);
289 store.updateGroupDescription(deviceId,
290 oldCookie,
291 UpdateType.SET,
292 buckets,
293 newCookie);
294 }
295
Kavitha Alagesanc69c66a2016-06-15 14:26:04 +0530296 @Override
297 public void purgeGroupEntries(DeviceId deviceId) {
298 checkPermission(GROUP_WRITE);
299 store.purgeGroupEntry(deviceId);
300 }
301
Victor Silva4e8b7832016-08-17 17:11:19 -0300302 @Override
303 public void purgeGroupEntries() {
304 checkPermission(GROUP_WRITE);
305 store.purgeGroupEntries();
306 }
Kavitha Alagesanc69c66a2016-06-15 14:26:04 +0530307
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800308 /**
309 * Delete a group associated to an application cookie.
310 * GROUP_DELETED or GROUP_DELETE_FAILED notifications would be
311 * provided along with cookie depending on the result of the
312 * operation on the device.
313 *
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700314 * @param deviceId device identifier
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800315 * @param appCookie application cookie to be used for lookup
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700316 * @param appId Application Id
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800317 */
318 @Override
319 public void removeGroup(DeviceId deviceId,
320 GroupKey appCookie,
321 ApplicationId appId) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900322 checkPermission(GROUP_WRITE);
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800323 store.deleteGroupDescription(deviceId, appCookie);
324 }
325
326 /**
327 * Retrieve all groups created by an application in the specified device
328 * as seen by current controller instance.
329 *
330 * @param deviceId device identifier
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700331 * @param appId application id
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800332 * @return collection of immutable group objects created by the application
333 */
334 @Override
335 public Iterable<Group> getGroups(DeviceId deviceId,
336 ApplicationId appId) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900337 checkPermission(GROUP_READ);
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800338 return store.getGroups(deviceId);
339 }
340
Jonathan Hart32600692015-03-09 10:38:40 -0700341 @Override
342 public Iterable<Group> getGroups(DeviceId deviceId) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900343 checkPermission(GROUP_READ);
Jonathan Hart32600692015-03-09 10:38:40 -0700344 return store.getGroups(deviceId);
345 }
346
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800347 @Override
348 protected GroupProviderService createProviderService(GroupProvider provider) {
349 return new InternalGroupProviderService(provider);
350 }
351
352 private class InternalGroupStoreDelegate implements GroupStoreDelegate {
353 @Override
354 public void notify(GroupEvent event) {
355 final Group group = event.subject();
356 GroupProvider groupProvider =
357 getProvider(group.deviceId());
358 GroupOperations groupOps = null;
359 switch (event.type()) {
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700360 case GROUP_ADD_REQUESTED:
361 log.debug("GROUP_ADD_REQUESTED for Group {} on device {}",
362 group.id(), group.deviceId());
363 GroupOperation groupAddOp = GroupOperation.
364 createAddGroupOperation(group.id(),
365 group.type(),
366 group.buckets());
367 groupOps = new GroupOperations(
368 Collections.singletonList(groupAddOp));
369 groupProvider.performGroupOperation(group.deviceId(), groupOps);
370 break;
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800371
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700372 case GROUP_UPDATE_REQUESTED:
373 log.debug("GROUP_UPDATE_REQUESTED for Group {} on device {}",
374 group.id(), group.deviceId());
375 GroupOperation groupModifyOp = GroupOperation.
376 createModifyGroupOperation(group.id(),
377 group.type(),
378 group.buckets());
379 groupOps = new GroupOperations(
380 Collections.singletonList(groupModifyOp));
381 groupProvider.performGroupOperation(group.deviceId(), groupOps);
382 break;
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800383
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700384 case GROUP_REMOVE_REQUESTED:
385 log.debug("GROUP_REMOVE_REQUESTED for Group {} on device {}",
386 group.id(), group.deviceId());
387 GroupOperation groupDeleteOp = GroupOperation.
388 createDeleteGroupOperation(group.id(),
389 group.type());
390 groupOps = new GroupOperations(
391 Collections.singletonList(groupDeleteOp));
392 groupProvider.performGroupOperation(group.deviceId(), groupOps);
393 break;
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800394
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700395 case GROUP_ADDED:
396 case GROUP_UPDATED:
397 case GROUP_REMOVED:
398 case GROUP_ADD_FAILED:
399 case GROUP_UPDATE_FAILED:
400 case GROUP_REMOVE_FAILED:
helenyrwu89470f12016-08-12 13:18:10 -0700401 case GROUP_BUCKET_FAILOVER:
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700402 post(event);
403 break;
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700404 default:
405 break;
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800406 }
407 }
408 }
409
410 private class InternalGroupProviderService
411 extends AbstractProviderService<GroupProvider>
412 implements GroupProviderService {
413
414 protected InternalGroupProviderService(GroupProvider provider) {
415 super(provider);
416 }
417
418 @Override
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700419 public void groupOperationFailed(DeviceId deviceId, GroupOperation operation) {
sangho7ff01812015-02-09 16:21:53 -0800420 store.groupOperationFailed(deviceId, operation);
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800421 }
422
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800423 @Override
424 public void pushGroupMetrics(DeviceId deviceId,
425 Collection<Group> groupEntries) {
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700426 log.trace("Received group metrics from device {}", deviceId);
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700427 checkValidity();
428 store.pushGroupMetrics(deviceId, groupEntries);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800429 }
helenyrwu89470f12016-08-12 13:18:10 -0700430
431 @Override
432 public void notifyOfFailovers(Collection<Group> failoverGroups) {
433 store.notifyOfFailovers(failoverGroups);
434 }
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800435 }
436
437 private class InternalDeviceListener implements DeviceListener {
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800438 @Override
439 public void event(DeviceEvent event) {
Charles Chan07f15f22018-05-08 21:35:50 -0700440 eventExecutor.execute(() -> processEventInternal(event));
441 }
442
443 private void processEventInternal(DeviceEvent event) {
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800444 switch (event.type()) {
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700445 case DEVICE_REMOVED:
446 case DEVICE_AVAILABILITY_CHANGED:
Charles Chan0c7c43b2016-01-14 17:39:20 -0800447 DeviceId deviceId = event.subject().id();
448 if (!deviceService.isAvailable(deviceId)) {
Charles Chan07f15f22018-05-08 21:35:50 -0700449 log.debug("Device {} became unavailable; clearing initial audit status",
450 event.type(), event.subject().id());
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700451 store.deviceInitialAuditCompleted(event.subject().id(), false);
Charles Chan0c7c43b2016-01-14 17:39:20 -0800452
453 if (purgeOnDisconnection) {
454 store.purgeGroupEntry(deviceId);
455 }
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700456 }
457 break;
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700458 default:
459 break;
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800460 }
461 }
462 }
helenyrwu89470f12016-08-12 13:18:10 -0700463
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800464}