-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document embedded entities addition and removal tracking (PR #8091)
# Description Documentation pr for inmanta/lsm#788 # Self Check: Strike through any lines that are not applicable (`~~line~~`) then check the box - [ ] Attached issue to pull request - [ ] Changelog entry - [ ] Type annotations are present - [ ] Code is clear and sufficiently documented - [ ] No (preventable) type errors (check using make mypy or make mypy-diff) - [ ] Sufficient test cases (reproduces the bug/tests the requested feature) - [ ] Correct, in line with design - [ ] End user documentation is included or an issue is created for end-user documentation (add ref to issue here: ) - [ ] If this PR fixes a race condition in the test suite, also push the fix to the relevant stable branche(s) (see [test-fixes](https://internal.inmanta.com/development/core/tasks/build-master.html#test-fixes) for more info)
- Loading branch information
1 parent
e950630
commit 015915d
Showing
5 changed files
with
236 additions
and
8 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
changelogs/unreleased/788-document-embedded-entities-tracking.yml
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,3 @@ | ||
description: "Document embedded entities addition and removal tracking" | ||
change-type: patch | ||
destination-branches: [master, iso7] |
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
83 changes: 83 additions & 0 deletions
83
docs/lsm/embedded_entities/embedded_entities_sources/example_files_in_folder.cf
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,83 @@ | ||
import std::testing | ||
import lsm | ||
import lsm::fsm | ||
import fs | ||
import mitogen | ||
|
||
entity Folder extends lsm::ServiceEntity: | ||
""" | ||
Top-level service representing a folder on a file system. | ||
|
||
:attr path: Unique path to this folder | ||
""" | ||
string path | ||
end | ||
|
||
index Folder(path) | ||
Folder.files [0:] lsm::__rwplus__ File._folder [1] | ||
|
||
entity File extends lsm::EmbeddedEntity: | ||
""" | ||
Embedded entity representing a file in a folder. | ||
|
||
:attr name: name of this line | ||
:attr content: Content of this file | ||
|
||
""" | ||
string name = "" | ||
string content | ||
lsm::attribute_modifier content__modifier="rw+" | ||
|
||
# These private attributes keep track of added/removed | ||
# embedded entities across updates | ||
bool _added = false | ||
bool _removed = false | ||
end | ||
|
||
index File(_folder, name) | ||
|
||
binding = lsm::ServiceEntityBindingV2( | ||
service_entity="__config__::Folder", | ||
lifecycle=lsm::fsm::simple, | ||
service_entity_name="folder", | ||
) | ||
|
||
# We wrap the call to lsm:all() with the plugin call: | ||
for instance in lsm::insert_removed_embedded_entities(lsm::all(binding)): | ||
folder = Folder( | ||
instance_id=instance["id"], | ||
entity_binding=binding, | ||
path=instance["attributes"]["path"], | ||
) | ||
for file in instance["attributes"]["files"]: | ||
folder.files += File(**file) | ||
end | ||
end | ||
|
||
implementation folder for Folder: | ||
self.resources += std::testing::NullResource(name=self.path) | ||
end | ||
|
||
mitogen_local = mitogen::Local() | ||
|
||
implementation file for File: | ||
self._folder.resources += fs::File( | ||
path=self._folder.path+"/"+self.name, | ||
host=std::Host( | ||
via=mitogen_local, name="internal", os=std::linux, | ||
), | ||
mode=777, | ||
owner="inmanta", | ||
group="inmanta", | ||
content = self.content, | ||
# By keeping track of embedded entities removed during an update | ||
# we can purge the underlying resources accordingly. | ||
# Alternatively, if the parent folder is removed, we want to | ||
# purge all embedded entities. | ||
purged=self._removed or self._folder.purge_resources, | ||
) | ||
end | ||
|
||
implement File using parents | ||
implement File using file | ||
implement Folder using parents, folder |
74 changes: 74 additions & 0 deletions
74
docs/lsm/embedded_entities/embedded_entities_sources/example_lines_in_file.cf
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,74 @@ | ||
import std::testing | ||
import lsm | ||
import lsm::fsm | ||
import fs | ||
import mitogen | ||
|
||
entity File extends lsm::ServiceEntity: | ||
""" | ||
Top-level service representing a file on a file system. | ||
|
||
:attr path: Unique path to this file | ||
""" | ||
string path | ||
end | ||
|
||
index File(path) | ||
File.lines [0:] lsm::__rwplus__ Line | ||
|
||
entity Line extends lsm::EmbeddedEntity: | ||
""" | ||
Embedded entity representing a single line in a file. | ||
|
||
:attr line_no: The line number | ||
:attr content: Content of this line | ||
""" | ||
int line_no | ||
string content = "" | ||
lsm::attribute_modifier content__modifier="rw+" | ||
|
||
# These private attributes keep track of added/removed | ||
# embedded entities across updates | ||
bool _added = false | ||
bool _removed = false | ||
end | ||
|
||
index Line(line_no) | ||
|
||
binding = lsm::ServiceEntityBindingV2( | ||
service_entity="__config__::File", | ||
lifecycle=lsm::fsm::simple, | ||
service_entity_name="file", | ||
) | ||
|
||
# We wrap the call to lsm:all() with the plugin call: | ||
for instance in lsm::insert_removed_embedded_entities(lsm::all(binding)): | ||
file = File( | ||
instance_id=instance["id"], | ||
entity_binding=binding, | ||
path=instance["attributes"]["path"], | ||
) | ||
for line in instance["attributes"]["lines"]: | ||
file.lines += Line(**line) | ||
end | ||
end | ||
|
||
mitogen_local=mitogen::Local() | ||
|
||
implementation file for File: | ||
self.resources += std::testing::NullResource(name=self.path) | ||
self.resources += fs::File( | ||
path=self.path, | ||
host=std::Host( | ||
via=mitogen_local, name="internal", os=std::linux, | ||
), | ||
mode=777, | ||
owner="inmanta", | ||
group="inmanta", | ||
content = string([string(l.content) for l in std::key_sort(self.lines, 'line_no')]), | ||
) | ||
end | ||
|
||
implement File using parents | ||
implement File using file | ||
implement Line using parents |
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