Skip to content

Commit

Permalink
Automatic longer timeout for large sites (#890)
Browse files Browse the repository at this point in the history
  • Loading branch information
grafnu authored May 15, 2024
1 parent 9234c45 commit 3883d16
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion common/src/main/java/com/google/udmi/util/SiteModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public EndpointConfiguration makeEndpointConfig(String iotProject, String device
return makeEndpointConfig(iotProject, exeConfig, deviceId);
}

private Set<String> getDeviceIds() {
public Set<String> getDeviceIds() {
checkState(sitePath != null, "sitePath not defined");
File devicesFile = new File(new File(sitePath), "devices");
File[] files = Objects.requireNonNull(devicesFile.listFiles(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ public class IotReflectorClient implements IotProvider {
// Requires functions that support cloud device manager support.
private static final String CONFIG_TOPIC_FORMAT = "%s/config";
private static final File ERROR_DIR = new File("out");
public static final double SLOW_QUERY_THRESHOLD = 10000;
private final com.google.bos.iot.core.proxy.IotReflectorClient messageClient;
private final Map<String, CompletableFuture<Map<String, Object>>> futures =
new ConcurrentHashMap<>();
private final ExecutorService executor = Executors.newSingleThreadExecutor();
private final boolean isSlow;

/**
* Create a new client.
Expand All @@ -67,6 +69,11 @@ public IotReflectorClient(ExecutionConfiguration executionConfiguration) {
messageClient = new com.google.bos.iot.core.proxy.IotReflectorClient(executionConfiguration,
Validator.TOOLS_FUNCTIONS_VERSION);
executor.execute(this::processReplies);
isSlow = siteModel.getDeviceIds().size() > SLOW_QUERY_THRESHOLD;
if (isSlow) {
// TODO: Replace this with a dynamic mechanism that gets incremental progress from UDMIS.
System.err.println("Using very long list devices timeout because of large number of devices");
}
}

@Override
Expand Down Expand Up @@ -156,8 +163,8 @@ public Map<String, CloudModel> fetchCloudModels(String forGatewayId) {
@Nullable
private CloudModel fetchCloudModel(String deviceId) {
try {
Map<String, Object> message = transaction(deviceId, CLOUD_QUERY_TOPIC, EMPTY_MESSAGE,
QuerySpeed.ETERNITY);
QuerySpeed speed = isSlow ? QuerySpeed.ETERNITY : QuerySpeed.SLOW;
Map<String, Object> message = transaction(deviceId, CLOUD_QUERY_TOPIC, EMPTY_MESSAGE, speed);
return convertTo(CloudModel.class, message);
} catch (Exception e) {
if (e.getMessage().contains("NOT_FOUND")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ enum QuerySpeed {
QUICK(1),
SHORT(15),
LONG(30),
ETERNITY(90);
SLOW(90),
ETERNITY(600);

private final int seconds;

Expand Down

0 comments on commit 3883d16

Please sign in to comment.