diff --git a/bin/sequencer b/bin/sequencer index 07e012fe51..2e8128c9fd 100755 --- a/bin/sequencer +++ b/bin/sequencer @@ -83,7 +83,8 @@ if [[ -d $site_path ]]; then elif [[ -f $site_path ]]; then echo Using site config file $site_path site_model=`jq -r .site_model $site_path` - [[ $site_model == null ]] && site_model=$(dirname $site_path) + [[ $site_model == null ]] && site_model=. + [[ $site_model =~ ^/ ]] || site_model=$(realpath $(dirname $site_path)/$site_model) project_id=`jq -r .project_id $site_path` [[ $project_id == null ]] && project_id= device_id=`jq -r .device_id $site_path` diff --git a/bin/test_regclean b/bin/test_regclean index 1e1089da64..55231ba92d 100755 --- a/bin/test_regclean +++ b/bin/test_regclean @@ -104,6 +104,8 @@ cat $pubber_config echo Corrupting site model to check error handling... mkdir -p $site_path/devices/XXX-1 echo { > $site_path/devices/XXX-1/metadata.json +mkdir -p $site_path/devices/XXX-2/out +echo hello > $site_path/devices/XXX-2/out/exceptions.txt echo Clean out the registry to make sure devices get removed... bin/registrar $site_arg $registrar_project -d diff --git a/common/src/main/java/com/google/udmi/util/SiteModel.java b/common/src/main/java/com/google/udmi/util/SiteModel.java index bea6765c19..0cf165cc9b 100644 --- a/common/src/main/java/com/google/udmi/util/SiteModel.java +++ b/common/src/main/java/com/google/udmi/util/SiteModel.java @@ -13,6 +13,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import java.io.File; +import java.io.FileNotFoundException; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -121,18 +122,25 @@ private static boolean validDeviceDirectory(String dirName) { } public static Metadata loadDeviceMetadata(String sitePath, String deviceId, Class container) { - Preconditions.checkState(sitePath != null, "sitePath not defined"); - File deviceDir = getDeviceDir(sitePath, deviceId); - File deviceMetadataFile = new File(deviceDir, "metadata.json"); - Metadata metadata = captureLoadErrors(deviceMetadataFile); - if (metadata != null) { + try { + Preconditions.checkState(sitePath != null, "sitePath not defined"); + File deviceDir = getDeviceDir(sitePath, deviceId); + File deviceMetadataFile = new File(deviceDir, "metadata.json"); + if (!deviceMetadataFile.exists()) { + return new MetadataException(deviceMetadataFile, new FileNotFoundException()); + } + Metadata metadata = requireNonNull(captureLoadErrors(deviceMetadataFile), "bad metadata"); + // Missing arrays are automatically parsed to an empty list, which is not what // we want, so hacky go through and convert an empty list to null. if (metadata.gateway != null && metadata.gateway.proxy_ids.isEmpty()) { metadata.gateway.proxy_ids = null; } + + return metadata; + } catch (Exception e) { + throw new RuntimeException("While loading device metadata for " + deviceId, e); } - return metadata; } private static Metadata captureLoadErrors(File deviceMetadataFile) {