Skip to content

Commit 996c7d8

Browse files
committed
Streamline logging calls
1 parent 23f9d55 commit 996c7d8

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

udmis/src/main/java/com/google/bos/udmi/service/access/ClearBladeIotAccessProvider.java

+14-19
Original file line numberDiff line numberDiff line change
@@ -409,20 +409,8 @@ private EventNotificationConfig eventNotificationConfig() {
409409
return EventNotificationConfig.newBuilder().setPubsubTopicName(topicName).build();
410410
}
411411

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-
424412
private HashMap<String, CloudModel> fetchDevices(String deviceRegistryId,
425-
Consumer<String> progress, GatewayListOptions gatewayListOptions) {
413+
Consumer<String> progress, boolean chattyProgress, GatewayListOptions gatewayListOptions) {
426414
requireNonNull(progress, "fetchDevices has null progress");
427415
String location = getRegistryLocation(deviceRegistryId);
428416
String registryFullName =
@@ -448,7 +436,8 @@ private HashMap<String, CloudModel> fetchDevices(String deviceRegistryId,
448436
collect.putAll(responseMap);
449437
pageToken = response.getNextPageToken();
450438
queryCount++;
451-
progress.accept(getProgressMessage(collect, gatewayListOptions));
439+
ifTrueThen(pageToken != null || chattyProgress,
440+
() -> progress.accept(getProgressMessage(collect, gatewayListOptions)));
452441
debug(format("fetchDevices %s #%d found %d total %d more %s", deviceRegistryId,
453442
queryCount, responseMap.size(), collect.size(), pageToken != null));
454443
} while (pageToken != null);
@@ -479,7 +468,8 @@ private CloudModel findDevicesForGateway(String registryId, Device device) {
479468

480469
private CloudModel findGatewaysForDevice(String registryId, Device device) {
481470
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();
483473
if (boundGateways.isEmpty()) {
484474
throw new RuntimeException("Was expecting at least one bound gateway!");
485475
}
@@ -537,10 +527,16 @@ private String hashedDeviceId(String registryId, String deviceId) {
537527

538528
private CloudModel listRegistryDevices(String registryId, String gatewayId,
539529
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) {
540535
try {
541536
CloudModel cloudModel = new CloudModel();
542537
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);
544540
debug(format("Fetched %d devices from %s gateway %s", boundDevices.size(), registryId,
545541
gatewayId));
546542
if (gatewayId != null) {
@@ -562,8 +558,7 @@ private Map<String, CloudModel> augmentGatewayModels(String registryId,
562558
boundDevices.entrySet().stream().filter(this::isGateway).collect(Collectors.toSet());
563559
AtomicInteger count = new AtomicInteger();
564560
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);
567562
progress.accept(format("Augmented gateway %s (%d/%d) with %d entries",
568563
entry.getKey(), count.incrementAndGet(), gateways.size(), added));
569564
});
@@ -587,7 +582,7 @@ private void augmentProxiedModel(Entry<String, CloudModel> entry,
587582
private int augmentGatewayModel(String registryId, Entry<String, CloudModel> model,
588583
HashMap<String, String> proxyDeviceGateways, Consumer<String> progress) {
589584
String gatewayId = model.getKey();
590-
CloudModel gatewayModel = listRegistryDevices(registryId, gatewayId, progress);
585+
CloudModel gatewayModel = listRegistryDevices(registryId, gatewayId, progress, false);
591586
model.getValue().gateway = gatewayModel.gateway;
592587
gatewayModel.gateway.proxy_ids.forEach(proxyId -> proxyDeviceGateways.put(proxyId, gatewayId));
593588
return gatewayModel.gateway.proxy_ids.size();

validator/src/main/java/com/google/daq/mqtt/registrar/Registrar.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
import com.google.udmi.util.ExceptionMap;
7070
import com.google.udmi.util.ExceptionMap.ErrorTree;
7171
import com.google.udmi.util.ExceptionMap.ExceptionCategory;
72-
import com.google.udmi.util.GeneralUtils;
7372
import com.google.udmi.util.JsonUtil;
7473
import com.google.udmi.util.SiteModel;
7574
import com.google.udmi.util.ValidationError;
@@ -139,6 +138,7 @@ public class Registrar {
139138
private static final String TOOL_NAME = "registrar";
140139
private static final long DELETE_FLUSH_DELAY_MS = 10 * SEC_TO_MS;
141140
public static final String REGISTRAR_TOOL_NAME = "registrar";
141+
private static final int UNBIND_SET_SIZE = 1000;
142142
private boolean autoAltRegistry;
143143
private final Map<String, JsonSchema> schemas = new HashMap<>();
144144
private final String generation = JsonUtil.isoConvert();
@@ -769,9 +769,9 @@ private void unbindDevicesFromGateways(Set<String> allDevices, Set<String> bound
769769
Map<String, CloudModel> boundDevices = cloudIotManager.fetchDevice(gatewayId).device_ids;
770770
Set<String> toUnbind = new HashSet<>(intersection(allDevices, boundDevices.keySet()));
771771
System.err.printf("Unbinding from gateway %s: %s%n", gatewayId, setOrSize(toUnbind));
772-
boolean multiple = toUnbind.size() > GeneralUtils.SET_SIZE_THRESHOLD;
772+
boolean multiple = toUnbind.size() > UNBIND_SET_SIZE;
773773
while (!toUnbind.isEmpty()) {
774-
Set<String> limitedSet = limitSetSize(toUnbind, GeneralUtils.SET_SIZE_THRESHOLD);
774+
Set<String> limitedSet = limitSetSize(toUnbind, UNBIND_SET_SIZE);
775775
ifTrueThen(multiple, () -> System.err.printf("Unbinding subset from %s: %s%n", gatewayId,
776776
setOrSize(limitedSet)));
777777
cloudIotManager.bindDevices(limitedSet, gatewayId, false);

0 commit comments

Comments
 (0)