Skip to content

Commit

Permalink
Merge branch 'master' into documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
grafnu committed May 15, 2024
2 parents 0f73c20 + 3883d16 commit 775bafd
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 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
19 changes: 19 additions & 0 deletions udmis/.idea/runConfigurations/ClearBladeIotAccessProvider.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@
import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.udmi.util.JsonUtil;
import java.util.AbstractMap.SimpleEntry;
import java.util.Base64;
import java.util.Date;
Expand Down Expand Up @@ -95,7 +97,8 @@
public class ClearBladeIotAccessProvider extends IotAccessBase {

public static final String REGISTRIES_FIELD_MASK = "id,name";
private static final Set<String> CLOUD_REGIONS = ImmutableSet.of("us-central1");
public static final String DEFAULT_REGION = "us-central1";
private static final Set<String> CLOUD_REGIONS = ImmutableSet.of(DEFAULT_REGION);
private static final String EMPTY_JSON = "{}";
private static final BiMap<Key_format, PublicKeyFormat> AUTH_TYPE_MAP = ImmutableBiMap.of(
Key_format.RS_256, PublicKeyFormat.RSA_PEM,
Expand All @@ -117,9 +120,31 @@ public class ClearBladeIotAccessProvider extends IotAccessBase {
private static final String UDMI_STATE_TOPIC = "udmi_state"; // TODO: Make this not hardcoded.
private static final String TOPIC_NAME_FORMAT = "projects/%s/topics/%s";
private static final CharSequence BOUND_TO_GATEWAY_MARKER = " it's associated ";
public static final String CONFIG_ENV = "CLEARBLADE_CONFIGURATION";
private final String projectId;
private final DeviceManagerInterface deviceManager;

/**
* Core test function for listing the devices in a registry.
*/
public static void main(String[] args) {
requireNonNull(System.getenv(CONFIG_ENV), CONFIG_ENV + " not defined");
IotAccess iotAccess = new IotAccess();
if (args.length != 1) {
System.err.println("Usage: registry_id");
return;
}
final String registryId = args[0];
Map<String, Object> stringObjectMap = JsonUtil.loadMap(System.getenv(CONFIG_ENV));
iotAccess.project_id = (String) requireNonNull(stringObjectMap.get("project"));
System.err.println("Extracted project from ClearBlade config file: " + iotAccess.project_id);
ClearBladeIotAccessProvider clearBladeIotAccessProvider =
new ClearBladeIotAccessProvider(iotAccess);
clearBladeIotAccessProvider.populateRegistryRegions();
CloudModel cloudModel = clearBladeIotAccessProvider.listDevices(registryId);
System.err.printf("Found %d results%n", cloudModel.device_ids.size());
}

/**
* Create a new instance for interfacing with GCP IoT Core.
*/
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 775bafd

Please sign in to comment.