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

registrar command line fixes for working with single devices #780

Merged
merged 9 commits into from
Dec 5, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ jobs:
- name: base setup
run: bin/run_tests install_dependencies
- name: registrar clean
run: bin/test_regclean $TARGET_PROJECT
run: bin/test_regclean solo $TARGET_PROJECT
- name: telemetry validator
run: bin/test_validator $TARGET_PROJECT
- name: validator result
Expand Down
15 changes: 12 additions & 3 deletions bin/registrar
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ shift

cd $UDMI_ROOT

if [[ -z $1 || $1 =~ ^- ]]; then
if [[ -z $1 || $1 =~ ^- || -f $site_path ]]; then
[[ -f $site_path ]] || echo No project ID supplied with site directory.
else
project_id=$1
Expand All @@ -25,8 +25,7 @@ fi

iot_config=$site_path/cloud_iot_config.json
if [[ -d $site_path && ! -f $iot_config ]]; then
echo Config file not found: $iot_config
false
fail Config file not found: $iot_config
elif [[ -d $site_path && -z $project_id ]]; then
echo No project defined, dry run only.
fi
Expand All @@ -49,6 +48,14 @@ echo Running tools version `git describe`
quoted_namespace=null
quoted_bridge=null
iot_provider=null
if [[ -f $site_path ]]; then
if [[ $1 =~ ^// || $1 =~ @ ]]; then
project_id=$1
shift
fi
echo Project_id is $project_id
fi

if [[ $project_id =~ ^// ]]; then
no_prefix=${project_id#//}
iot_provider=\"${no_prefix%%/*}\"
Expand Down Expand Up @@ -92,3 +99,5 @@ echo
validator/bin/registrar $config_file $* 2>&1 | tee $OUT_DIR/registrar.log

bin/check_version

search "Registrar complete, exit 0" $OUT_DIR/registrar.log
41 changes: 37 additions & 4 deletions bin/test_regclean
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@
# Force consistent sort order
export LC_ALL=C

ROOT_DIR=$(dirname $0)/..
cd $ROOT_DIR
UDMI_ROOT=$(dirname $0)/..
cd $UDMI_ROOT

if [[ $# -ne 1 ]]; then
source etc/shell_common.sh

solo_arg=

if [[ $# -lt 1 ]]; then
echo Usage: $0 PROJECT_ID[@BROKER]
false
fi

if [[ $1 == solo ]]; then
solo_arg=AHU-1
shift
fi

project_id=$1
shift

Expand Down Expand Up @@ -119,11 +128,35 @@ pubber/bin/run $pubber_config

echo Successful pubber check passed on clean registry.

if [[ -n $solo_arg ]]; then
echo Deleting singular entry $solo_arg...
echo bin/registrar $site_arg $registrar_project -d $solo_arg
bin/registrar $site_arg $registrar_project -d $solo_arg
search "Deleting device $solo_arg \(1/1)" out/registrar.log
search "Deleted 1 devices" out/registrar.log

echo Sleeping to avoid IoT Core race condition...
sleep 20

echo bin/registrar /tmp/registrar_config.json $solo_arg
bin/registrar /tmp/registrar_config.json $solo_arg

echo Checking creation of one device
search "Processing 1 new devices..." out/registrar.log
search "Processed $solo_arg \(1/1) in [0-9.]+s \(add)" out/registrar.log
search "Processed 1 \(skipped 0) devices in " out/registrar.log
search "Updating 0 existing devices" out/registrar.log
search "Processed 0 \(skipped 0) devices in " out/registrar.log
echo Done with solo update test for $solo_arg
fi

if [[ -n $UDMI_ALT_REGISTRY ]]; then
echo Registering alt registry...
echo Registering alt registry $UDMI_ALT_REGISTRY...
site_file=$site_arg/cloud_iot_config.json
cp $site_file $site_file-tmp
jq ".registry_id = \"$UDMI_ALT_REGISTRY\"" $site_file-tmp > $site_file
echo bin/registrar $site_arg $registrar_project -u
bin/registrar $site_arg $registrar_project -u
mv $site_file-tmp $site_file
echo Done with registering alt registry
fi
4 changes: 4 additions & 0 deletions etc/shell_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ function find_site_model_root {
done
}

function search {
egrep "$1" $2 || fail Could not find in $2: $1
}

function fail {
echo error: $*
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public Set<String> fetchDeviceIds(String forGatewayId) {
private CloudModel fetchCloudModel(String deviceId) {
try {
Map<String, Object> message = transaction(deviceId, CLOUD_QUERY_TOPIC, EMPTY_MESSAGE,
MessagePublisher.QuerySpeed.LONG);
QuerySpeed.ETERNITY);
return convertToStrict(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 @@ -35,7 +35,7 @@ static MessagePublisher from(ExecutionConfiguration iotConfig,
BiConsumer<String, String> messageHandler, Consumer<Throwable> errorHandler) {
IotAccess.IotProvider iotProvider = ofNullable(iotConfig.iot_provider).orElse(IMPLICIT);
if (iotConfig.reflector_endpoint != null && iotProvider != IMPLICIT) {
throw new RuntimeException("Explicit endpoint conflicts with iot_provider " + iotProvider);
iotConfig.reflector_endpoint = null;
}
if (PUBSUB == iotConfig.iot_provider) {
return PubSubReflector.from(iotConfig, messageHandler, errorHandler);
Expand Down Expand Up @@ -76,7 +76,8 @@ default Credential getCredential() {
enum QuerySpeed {
QUICK(1),
SHORT(15),
LONG(30);
LONG(30),
ETERNITY(90);

private final int seconds;

Expand Down