@@ -409,20 +409,8 @@ private EventNotificationConfig eventNotificationConfig() {
409
409
return EventNotificationConfig .newBuilder ().setPubsubTopicName (topicName ).build ();
410
410
}
411
411
412
- private HashMap <String , CloudModel > fetchBoundGateways (String deviceRegistryId , String deviceId ,
413
- Consumer <String > progress ) {
414
- GatewayListOptions gatewayListOptions = ifNotNullGet (deviceId , this ::getBoundGatewaysOptions );
415
- return fetchDevices (deviceRegistryId , progress , gatewayListOptions );
416
- }
417
-
418
- private HashMap <String , CloudModel > fetchDevices (String deviceRegistryId , String gatewayId ,
419
- Consumer <String > progress ) {
420
- GatewayListOptions gatewayListOptions = ifNotNullGet (gatewayId , this ::getBoundDevicesOptions );
421
- return fetchDevices (deviceRegistryId , progress , gatewayListOptions );
422
- }
423
-
424
412
private HashMap <String , CloudModel > fetchDevices (String deviceRegistryId ,
425
- Consumer <String > progress , GatewayListOptions gatewayListOptions ) {
413
+ Consumer <String > progress , boolean chattyProgress , GatewayListOptions gatewayListOptions ) {
426
414
requireNonNull (progress , "fetchDevices has null progress" );
427
415
String location = getRegistryLocation (deviceRegistryId );
428
416
String registryFullName =
@@ -448,7 +436,8 @@ private HashMap<String, CloudModel> fetchDevices(String deviceRegistryId,
448
436
collect .putAll (responseMap );
449
437
pageToken = response .getNextPageToken ();
450
438
queryCount ++;
451
- progress .accept (getProgressMessage (collect , gatewayListOptions ));
439
+ ifTrueThen (pageToken != null || chattyProgress ,
440
+ () -> progress .accept (getProgressMessage (collect , gatewayListOptions )));
452
441
debug (format ("fetchDevices %s #%d found %d total %d more %s" , deviceRegistryId ,
453
442
queryCount , responseMap .size (), collect .size (), pageToken != null ));
454
443
} while (pageToken != null );
@@ -479,7 +468,8 @@ private CloudModel findDevicesForGateway(String registryId, Device device) {
479
468
480
469
private CloudModel findGatewaysForDevice (String registryId , Device device ) {
481
470
String deviceId = requireNonNull (device .toBuilder ().getId (), "unspecified device id" );
482
- Set <String > boundGateways = fetchBoundGateways (registryId , deviceId , this ::bitBucket ).keySet ();
471
+ Set <String > boundGateways = fetchDevices (registryId , this ::bitBucket ,
472
+ true , getBoundGatewaysOptions (deviceId )).keySet ();
483
473
if (boundGateways .isEmpty ()) {
484
474
throw new RuntimeException ("Was expecting at least one bound gateway!" );
485
475
}
@@ -537,10 +527,16 @@ private String hashedDeviceId(String registryId, String deviceId) {
537
527
538
528
private CloudModel listRegistryDevices (String registryId , String gatewayId ,
539
529
Consumer <String > maybeProgress ) {
530
+ return listRegistryDevices (registryId , gatewayId , maybeProgress , true );
531
+ }
532
+
533
+ private CloudModel listRegistryDevices (String registryId , String gatewayId ,
534
+ Consumer <String > maybeProgress , boolean chattyProgress ) {
540
535
try {
541
536
CloudModel cloudModel = new CloudModel ();
542
537
Consumer <String > progress = ofNullable (maybeProgress ).orElse (this ::bitBucket );
543
- HashMap <String , CloudModel > boundDevices = fetchDevices (registryId , gatewayId , progress );
538
+ GatewayListOptions options = ifNotNullGet (gatewayId , this ::getBoundDevicesOptions );
539
+ HashMap <String , CloudModel > boundDevices = fetchDevices (registryId , progress , chattyProgress , options );
544
540
debug (format ("Fetched %d devices from %s gateway %s" , boundDevices .size (), registryId ,
545
541
gatewayId ));
546
542
if (gatewayId != null ) {
@@ -562,8 +558,7 @@ private Map<String, CloudModel> augmentGatewayModels(String registryId,
562
558
boundDevices .entrySet ().stream ().filter (this ::isGateway ).collect (Collectors .toSet ());
563
559
AtomicInteger count = new AtomicInteger ();
564
560
gateways .forEach (entry -> {
565
- // Send progress updates to bitBucket to suppress redundant log messages.
566
- int added = augmentGatewayModel (registryId , entry , proxyDeviceGateways , this ::bitBucket );
561
+ int added = augmentGatewayModel (registryId , entry , proxyDeviceGateways , progress );
567
562
progress .accept (format ("Augmented gateway %s (%d/%d) with %d entries" ,
568
563
entry .getKey (), count .incrementAndGet (), gateways .size (), added ));
569
564
});
@@ -587,7 +582,7 @@ private void augmentProxiedModel(Entry<String, CloudModel> entry,
587
582
private int augmentGatewayModel (String registryId , Entry <String , CloudModel > model ,
588
583
HashMap <String , String > proxyDeviceGateways , Consumer <String > progress ) {
589
584
String gatewayId = model .getKey ();
590
- CloudModel gatewayModel = listRegistryDevices (registryId , gatewayId , progress );
585
+ CloudModel gatewayModel = listRegistryDevices (registryId , gatewayId , progress , false );
591
586
model .getValue ().gateway = gatewayModel .gateway ;
592
587
gatewayModel .gateway .proxy_ids .forEach (proxyId -> proxyDeviceGateways .put (proxyId , gatewayId ));
593
588
return gatewayModel .gateway .proxy_ids .size ();
0 commit comments