Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test function for listing devices in a site registry #889

Merged
merged 3 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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