-
Notifications
You must be signed in to change notification settings - Fork 485
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
feat(metadata): implement Unit of Measure (UoM) ADR #4119
Conversation
@hahattan we merged a PR which should resolved the snap test issue. please rebase it. |
if container.ConfigurationFrom(dic.Get).Writable.UoM.Validation { | ||
uom := container.UnitsOfMeasureFrom(dic.Get) | ||
for _, dr := range d.DeviceResources { | ||
if ok := uom.Validate(dr.Properties.Units); !ok { | ||
return errors.NewCommonEdgeX(errors.KindServerError, fmt.Sprintf("DeviceResource %s units %s is invalid", dr.Name, dr.Properties.Units), nil) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create helper function to reduce duplicated code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hahattan , please complete PR check list with link to PR for the Doc updates for this new capability. THX!
Signed-off-by: Chris Hung <chris@iotechsys.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@hahattan , FYI I have escalated the snap testing failure to @farshidtz |
document PR updated: edgexfoundry/edgex-docs#834 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
"core-metadata") | ||
install -DT "./cmd/core-metadata/res/configuration.toml" "$SNAPCRAFT_PART_INSTALL/config/core-metadata/res/configuration.toml" | ||
install -DT "./cmd/core-metadata/res/uom.toml" "$SNAPCRAFT_PART_INSTALL/config/core-metadata/res/uom.toml" | ||
;; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good as it copies also uom.toml
to the snap package (readonly, SNAP
env var). But we also need to add code to copy it over to the snap's writable area (SNAP_DATA
env var) on install time. The given path UOM_UOMFILE: $SNAP_DATA/config/core-metadata/res/uom.toml
expects it to be under the writable area.
Currently only configuration.toml
files get copied:
edgex-go/snap/local/hooks/cmd/install/install.go
Lines 118 to 143 in e3ca38a
destDir := hooks.SnapDataConf + "/" | |
srcDir := hooks.SnapConf + "/" | |
// handle exceptions (i.e. config in non-std dirs) | |
if v == "security-bootstrap-redis" { | |
destDir = destDir + "security-bootstrapper/res-bootstrap-redis" | |
srcDir = srcDir + "security-bootstrapper/res-bootstrap-redis" | |
} else if v == "app-service-configurable" { | |
destDir = destDir + v + "/res/rules-engine" | |
srcDir = srcDir + "/res/rules-engine" | |
} else { | |
destDir = destDir + v + "/res" | |
srcDir = srcDir + v + "/res" | |
} | |
if err = os.MkdirAll(destDir, 0755); err != nil { | |
return err | |
} | |
srcPath := srcDir + "/configuration.toml" | |
destPath := destDir + "/configuration.toml" | |
err = hooks.CopyFile(srcPath, destPath) | |
if err != nil { | |
return err | |
} |
This is really an unnecessary complication in how the snap is packaged. Maybe we should refactor and simply copy the whole res
directory.
For now, a quick fix would be to update the referenced code to copy uom.toml
from SNAP
to SNAP_DATA
for core-metadata. I'll work on it and commit to the same PR (since the permission has been granted by the author during PR submission.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry I wasn't aware you're working on it.
I've added a quick fix: https://github.com/edgexfoundry/edgex-go/compare/4c4951218dd81a254464f99d357ca8617bed2473..3aaec565c9b77e4c31d71bd8720703868403a2fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix. I was wondering why I couldn't push. I was testing locally so it took some time.
You force-pushed so it isn't clear what exactly you changed. But the install.go part looks good.
Signed-off-by: Chris Hung <chris@iotechsys.com>
3aaec56
Kudos, SonarCloud Quality Gate passed! |
Signed-off-by: Chris Hung chris@iotechsys.com
If your build fails due to your commit message not passing the build checks, please review the guidelines here: https://github.com/edgexfoundry/edgex-go/blob/main/.github/Contributing.md
PR Checklist
Please check if your PR fulfills the following requirements:
BREAKING CHANGE:
describing the break)feat: document core metadata units of measure capability edgex-docs#834
Testing Instructions
WRITABLE_UOM_VALIDATION: "true"
res/uom.toml
Also,
I updated the sample uom TOML in ADR from
to
so that it can be correctly unmarshaled
New Dependency Instructions (If applicable)