forked from faucetsdn/udmi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create upversioning utility to upgrade schema and test messages versi…
…on and change these to 1.4.0 (faucetsdn#477)
- Loading branch information
Showing
155 changed files
with
471 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
#!/bin/bash -e | ||
# | ||
# Usage: | ||
# bin/upversion NEW_VERSION | ||
# | ||
# Changes the version where it is hardcoded in UDMI files, performing checks | ||
# that the new version is available, and that the files can be safely updated. | ||
# Modifications: | ||
# - schema/*.json (all files) | ||
# - etc/categories.json | ||
# - tests/**/*.json and validator/traces/**/*.out - | ||
# all files must be added to etc/upversion.txt only files preceeded | ||
# with a 'y' are updated. Only works with "pretty"/non-minified JSON | ||
# - documentation in-line exammples | ||
# - specific java files (Pubber.java, ConfigUtil.java, LocalDevice.java) | ||
|
||
UPVERSION_LIST=etc/upversion.txt | ||
TESTS_REGEX="^(\s{0,4}\"version\"\s*:\s*)([0-9.\"]*)(,?)" | ||
SCHEMA_VERSION_IDENTIFIER=\$udmi_version # must start with $ | ||
ERROR_MARKER=.upversion_error | ||
|
||
# Updates existing $udmi_version in a JSON file. | ||
# Usage: update_existing_schema_version FILE_TO_UPDATE NEW_VERSION | ||
function update_existing_schema_version(){ | ||
file=$1 | ||
version=$2 | ||
sed -i -E "s/\"\\$SCHEMA_VERSION_IDENTIFIER\"\s*:\s*\"[0-9.]*\"/\"$SCHEMA_VERSION_IDENTIFIER\": \"$version\"/" $file | ||
} | ||
|
||
# Updates an existing $udmi_version, or adds if missing | ||
# Usage: update_schema_version FILE_TO_UPDATE NEW_VERSION | ||
function update_schema_version(){ | ||
file=$1 | ||
version=$2 | ||
if [[ $(jq -r ".[\"$SCHEMA_VERSION_IDENTIFIER\"]" $file) == "null" ]]; then | ||
sed -i "s/^{/{\n \"$SCHEMA_VERSION_IDENTIFIER\": \"$version\",/" $file | ||
else | ||
update_existing_schema_version $file $version | ||
fi | ||
} | ||
|
||
# Updates UDMI_VERSION variable in a java file | ||
# Usage: update_java_file FILE_TO_UPDATE NEW_VERSION | ||
function update_java_file(){ | ||
file=$1 | ||
version=$2 | ||
[[ $(grep -c "UDMI_VERSION\s*=\s*\"" $file) != 1 ]] && return 1 | ||
sed -i -e "s/UDMI_VERSION\s*=\s*\"[0-9.]*\"/UDMI_VERSION = \"$version\"/" $file | ||
} | ||
|
||
if [[ "$#" != 1 ]]; then | ||
echo Usage: $0 NEW_VERSION | ||
exit 1 | ||
fi | ||
NEW_VERSION=$1 | ||
shift 1 | ||
|
||
rm .upversion_error | ||
|
||
if ! [[ $NEW_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
echo ERROR Invalid version: $NEW_VERSION | ||
exit 1 | ||
fi | ||
|
||
bin/check_version | ||
if [[ -n $(git tag -l $NEW_VERSION) ]]; then | ||
echo ERROR New version $NEW_VERSION already exists in upstream repo. | ||
exit 1 | ||
fi | ||
|
||
if [[ -n $(git status --untracked-files=no --porcelain) ]]; then | ||
echo ERROR Git not clean .. commit/stash all changes first | ||
exit 1 | ||
fi | ||
|
||
# Check test files exist in the upversion list | ||
for test_file in tests/*.tests/*.json; do | ||
if [[ $(grep -P -c "^[^#] $test_file" $UPVERSION_LIST) != 1 ]]; then | ||
echo $test_file | ||
err_upversion_list=1 | ||
fi | ||
done | ||
if [[ -n $err_upversion_list ]]; then | ||
echo ERROR .. above files not found in upversion list or listed more than once | ||
touch $ERROR_MARKER | ||
fi | ||
|
||
for schema_file in schema/*.json; do | ||
if (( $(grep -c "\"\$udmi_version\"" $schema_file) > 1 )); then | ||
echo $schema_file | ||
err_schema_version=1 | ||
fi | ||
done | ||
if [[ -n $err_schema_version ]]; then | ||
echo ERROR .. above files have more than one \$udmi_version | ||
touch $ERROR_MARKER | ||
fi | ||
|
||
[[ -f $ERROR_MARKER ]] && exit 1 | ||
|
||
# Check files in upversion list still exist | ||
while read action file comment; do | ||
if [[ $action != "#" ]] && ! [[ -f $file ]]; then | ||
err_stale_file=1 | ||
echo $file | ||
fi | ||
done <$UPVERSION_LIST | ||
if [[ -n $err_stale_file ]]; then | ||
echo ERROR .. above files etc/upversion.txt no longer exist | ||
fi | ||
|
||
# Check files have exactly 1 matched version fields to avoid unexpected | ||
# updates. Uses indents to try and match the top level field | ||
while read action file comment; do | ||
if ! [[ -f $file && $action == "y" ]]; then | ||
continue | ||
fi | ||
|
||
if [[ $(grep -E -c $TESTS_REGEX $file) != 1 ]]; then | ||
echo $file | ||
err_one_version=1 | ||
fi | ||
done <$UPVERSION_LIST | ||
if [[ -n $err_one_version ]]; then | ||
echo ERROR above files do not have exactly one version field | ||
fi | ||
|
||
echo -n Updating files .. | ||
|
||
# NOTE using sed because jq reformats text | ||
for schema_file in schema/*.json; do | ||
update_schema_version $schema_file $NEW_VERSION | ||
done | ||
|
||
# Update tests using sed because jq does not handle files with comments | ||
cat $UPVERSION_LIST | grep "^y" | awk '{print $2}' \ | ||
| xargs sed -i -E "s/$TESTS_REGEX/\1\"$NEW_VERSION\"\3/g" | ||
|
||
update_existing_schema_version etc/category.json $NEW_VERSION | ||
|
||
bin/gencode_docs_examples | ||
|
||
# TODO a proper way of updating/managing these files | ||
|
||
# Version in Pubber payloads | ||
update_java_file pubber/src/main/java/daq/pubber/Pubber.java $NEW_VERSION | ||
# Version in validator messages messages | ||
update_java_file validator/src/main/java/com/google/daq/mqtt/util/ConfigUtil.java $NEW_VERSION | ||
# Version in for generated_configs which are NOT upgraded | ||
update_java_file validator/src/main/java/com/google/daq/mqtt/registrar/LocalDevice.java $NEW_VERSION | ||
|
||
# NOTE messages & metadata are upgraded when there are schema changes, | ||
# So they do not necesarily end up at the latest version when upgraded | ||
|
||
echo Done! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# Manually maintained list of all files in tests/*.tests/*.json | ||
# consumed by bin/upversion when upgrading versions | ||
# | ||
# Syntax: ACTION FILE [COMMENT] | ||
# | ||
# ACTIONS: | ||
# y - update the top level "version" in the files | ||
# n - do not update the file | ||
# | ||
n tests/event_discovery.tests/empty.json | ||
n tests/event_system.tests/empty.json | ||
n tests/event_pointset.tests/empty.json | ||
n tests/state.tests/empty.json | ||
n tests/config.tests/empty.json | ||
n tests/config.tests/delta_x1_gateway.json | ||
n tests/config.tests/delta_x1_target.json | ||
n tests/metadata.tests/empty.json | ||
n tests/state.tests/delta_x1_gateway.json | ||
n tests/state.tests/delta_x1_target.json | ||
n tests/configuration_endpoint.tests/simple.json | ||
n tests/configuration_endpoint.tests/delta.json | ||
n tests/model_pointset.tests/example.json | ||
n tests/envelope.tests/lgtw.json | ||
n tests/envelope.tests/empty.json | ||
n tests/envelope.tests/errors2.json | ||
n tests/envelope.tests/example.json | ||
n tests/envelope.tests/gateway.json | ||
n tests/envelope.tests/example2.json | ||
n tests/envelope.tests/errors1.json | ||
n tests/state.tests/makemodel_upgrade.json # tests message upgrade from v 1 | ||
n tests/config.tests/errors.json | ||
n tests/state.tests/errors.json # test complete message upgrade pathway | ||
y tests/state_validation.tests/report.json | ||
y tests/event_discovery.tests/from_bacnet.json | ||
y tests/event_discovery.tests/scan_error.json | ||
y tests/event_discovery.tests/point_error.json | ||
y tests/event_discovery.tests/errors.json | ||
y tests/event_discovery.tests/enumeration.json | ||
y tests/event_discovery.tests/continuous.json | ||
y tests/event_discovery.tests/discovery.json | ||
y tests/event_discovery.tests/implicit.json | ||
y tests/event_system.tests/metrics.json | ||
y tests/event_system.tests/errors.json | ||
y tests/event_system.tests/example.json | ||
y tests/event_system.tests/fcu.json | ||
y tests/event_validation.tests/simple_ok.json | ||
y tests/event_validation.tests/simple_error.json | ||
y tests/config_mapping.tests/mapping.json | ||
y tests/event_pointset.tests/errors.json | ||
y tests/event_pointset.tests/writeback.json | ||
y tests/event_pointset.tests/example.json | ||
y tests/event_pointset.tests/fcu.json | ||
y tests/event_pointset.tests/smartprimus.json | ||
y tests/event_pointset.tests/partial.json | ||
y tests/config_pointset.tests/example.json | ||
y tests/state.tests/scan_stop.json | ||
y tests/state.tests/scan_error.json | ||
y tests/state.tests/enumeration.json | ||
y tests/state.tests/writeback.json | ||
y tests/state.tests/continuous.json | ||
y tests/state.tests/periodic.json | ||
y tests/state.tests/scan_bad.json | ||
y tests/state.tests/discovery.json | ||
y tests/state.tests/example.json | ||
y tests/state.tests/endpoint_reconfiguration_failed.json | ||
y tests/state.tests/endpoint_reconfiguration.json | ||
y tests/state.tests/makemodel_error.json # current version but with makemodel, validation error | ||
y tests/state.tests/blobset_updating.json | ||
y tests/state.tests/blobset_received.json | ||
y tests/state.tests/fcu.json | ||
y tests/state.tests/gateway.json | ||
y tests/state.tests/restart.json | ||
y tests/state_pointset.tests/example.json | ||
y tests/config.tests/blobset_final_incomplete_url.json | ||
y tests/config.tests/enumeration.json | ||
y tests/config.tests/writeback.json | ||
y tests/config.tests/proxy.json | ||
y tests/config.tests/continuous.json | ||
y tests/config.tests/delta_endpoint.json | ||
y tests/config.tests/periodic.json | ||
y tests/config.tests/discovery.json | ||
y tests/config.tests/example.json | ||
y tests/config.tests/endpoint_reconfiguration.json | ||
y tests/config.tests/fcu.json | ||
y tests/config.tests/gateway.json | ||
y tests/config.tests/smartprimus.json | ||
y tests/config.tests/restart.json | ||
y tests/config.tests/blobset_final_incomplete_payload.json | ||
y tests/config.tests/implicit.json | ||
y tests/state_mapping.tests/mapping.json | ||
y tests/command_discovery.tests/provision.json | ||
y tests/event_mapping.tests/mapping.json | ||
y tests/event_mapping.tests/prediction.json | ||
y tests/metadata.tests/toomany.json | ||
y tests/metadata.tests/proxy.json | ||
y tests/metadata.tests/example.json | ||
y tests/metadata.tests/gateway.json | ||
y tests/command_mapping.tests/mapping.json | ||
y tests/metadata.tests/errors.json | ||
y tests/config.tests/blobset_final.json | ||
n tests/configuration_execution.tests/cloud_iot_config.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.