-
Notifications
You must be signed in to change notification settings - Fork 61
feat: [AAP-64171] Backport project sync feature branch to main #1482
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
base: main
Are you sure you want to change the base?
Changes from all commits
7d64d23
bd88216
60e287d
d317ea6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -279,6 +279,7 @@ class Meta: | |
| "is_enabled", | ||
| "status", | ||
| "git_hash", | ||
| "restart_on_project_update", | ||
| "extra_var", | ||
| "decision_environment_id", | ||
| "project_id", | ||
|
|
@@ -341,6 +342,7 @@ class Meta: | |
| "description", | ||
| "is_enabled", | ||
| "status", | ||
| "restart_on_project_update", | ||
| "extra_var", | ||
| "decision_environment_id", | ||
| "project_id", | ||
|
|
@@ -406,6 +408,9 @@ def to_representation(self, activation): | |
| "rulebook_id": activation.rulebook_id, | ||
| "extra_var": extra_var, | ||
| "organization_id": activation.organization_id, | ||
| "restart_on_project_update": ( | ||
| activation.restart_on_project_update | ||
| ), | ||
| "restart_policy": activation.restart_policy, | ||
| "restart_count": activation.restart_count, | ||
| "rulebook_name": activation.rulebook_name, | ||
|
|
@@ -441,6 +446,7 @@ class Meta: | |
| "name", | ||
| "description", | ||
| "is_enabled", | ||
| "restart_on_project_update", | ||
| "decision_environment_id", | ||
| "rulebook_id", | ||
| "extra_var", | ||
|
|
@@ -509,6 +515,9 @@ def create(self, validated_data): | |
| validated_data["user_id"] = validated_data["user"].id | ||
| validated_data["rulebook_name"] = rulebook.name | ||
| validated_data["rulebook_rulesets"] = rulebook.rulesets | ||
| validated_data["rulebook_rulesets_sha256"] = get_rulebook_hash( | ||
| rulebook.rulesets | ||
| ) | ||
| validated_data["git_hash"] = rulebook.project.git_hash | ||
| validated_data["project_id"] = rulebook.project.id | ||
| validated_data["log_tracking_id"] = str(uuid.uuid4()) | ||
|
|
@@ -572,6 +581,7 @@ def copy(self) -> dict: | |
| "skip_audit_events": activation.skip_audit_events, | ||
| "rulebook_name": activation.rulebook.name, | ||
| "rulebook_rulesets": activation.rulebook_rulesets, | ||
| "rulebook_rulesets_sha256": activation.rulebook_rulesets_sha256, | ||
| "git_hash": activation.rulebook.project.git_hash, | ||
| "project": activation.rulebook.project, | ||
| "log_tracking_id": str(uuid.uuid4()), | ||
|
|
@@ -602,6 +612,7 @@ class Meta: | |
| "name", | ||
| "description", | ||
| "is_enabled", | ||
| "restart_on_project_update", | ||
| "decision_environment_id", | ||
| "rulebook_id", | ||
| "extra_var", | ||
|
|
@@ -687,6 +698,9 @@ def prepare_update(self, activation: models.Activation): | |
| rulebook = models.Rulebook.objects.get(id=rulebook_id) | ||
| self.validated_data["rulebook_name"] = rulebook.name | ||
| self.validated_data["rulebook_rulesets"] = rulebook.rulesets | ||
| self.validated_data[ | ||
| "rulebook_rulesets_sha256" | ||
| ] = get_rulebook_hash(rulebook.rulesets) | ||
| self.validated_data["git_hash"] = rulebook.project.git_hash | ||
| self.validated_data["project_id"] = rulebook.project.id | ||
|
|
||
|
|
@@ -701,9 +715,11 @@ def prepare_update(self, activation: models.Activation): | |
| if yaml.safe_load(self.validated_data.get("source_mappings", "")): | ||
| if not rulebook_id: | ||
| # load the original ruleset | ||
| rulesets = activation.rulebook.rulesets | ||
| self.validated_data["rulebook_rulesets"] = rulesets | ||
| self.validated_data[ | ||
| "rulebook_rulesets" | ||
| ] = activation.rulebook.rulesets | ||
| "rulebook_rulesets_sha256" | ||
| ] = get_rulebook_hash(rulesets) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The argument in the definition of get_rulebook_hash is called 'rulebook'. Here we call it rulesets, which implies plural rule set where as the function definition argument implies a singular rulebook. I understand that this function returns a hash, but I don't really understand how that hash applies to project sync.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good observation on the naming. The Regarding project sync: when a project sync occurs, it re-imports the git repo and updates each |
||
|
|
||
| _update_event_streams_and_credential(self.validated_data) | ||
| else: | ||
|
|
@@ -875,6 +891,7 @@ class Meta: | |
| "decision_environment", | ||
| "status", | ||
| "git_hash", | ||
| "restart_on_project_update", | ||
| "project", | ||
| "rulebook", | ||
| "extra_var", | ||
|
|
@@ -973,6 +990,28 @@ def to_representation(self, activation): | |
| else "" | ||
| ) | ||
|
|
||
| warnings = [] | ||
| if activation.source_mappings: | ||
| if not activation.rulebook: | ||
| warnings.append( | ||
| "The rulebook associated with this activation " | ||
| "no longer exists. Source mappings may be " | ||
| "invalid." | ||
| ) | ||
| elif ( | ||
| activation.rulebook_rulesets_sha256 | ||
| and activation.rulebook.rulesets_sha256 | ||
| and ( | ||
| activation.rulebook_rulesets_sha256 | ||
| != activation.rulebook.rulesets_sha256 | ||
| ) | ||
| ): | ||
| warnings.append( | ||
| "Rulebook content has changed since event " | ||
| "stream sources were mapped. Please update " | ||
| "source mappings." | ||
| ) | ||
|
|
||
| return { | ||
| "id": activation.id, | ||
| "name": activation.name, | ||
|
|
@@ -988,6 +1027,9 @@ def to_representation(self, activation): | |
| "instances": ActivationInstanceSerializer( | ||
| activation_instances, many=True | ||
| ).data, | ||
| "restart_on_project_update": ( | ||
| activation.restart_on_project_update | ||
| ), | ||
| "restart_policy": activation.restart_policy, | ||
| "restart_count": activation.restart_count, | ||
| "rulebook_name": activation.rulebook_name, | ||
|
|
@@ -1006,6 +1048,7 @@ def to_representation(self, activation): | |
| "k8s_service_name": activation.k8s_service_name, | ||
| "event_streams": event_streams, | ||
| "source_mappings": activation.source_mappings, | ||
| "warnings": warnings, | ||
| "skip_audit_events": activation.skip_audit_events, | ||
| "log_tracking_id": activation.log_tracking_id, | ||
| "created_by": BasicUserSerializer(activation.created_by).data, | ||
|
|
||
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.
Is this the revision hash? If so, is this what controller calls it? It doesn't seem familiar to me as a field that controller sends.
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.
No, this is not the Git revision hash (that's
git_hash).rulebook_rulesets_sha256is a SHA256 hash of the rulebook's YAML rulesets content, computed locally by EDA usingget_rulebook_hash(). It's not sent by controller — it's generated at activation create/update time and stored so we can later detect if the upstream rulebook content changed after a project sync. The naming follows the existingrulebook_rulesetsfield, with_sha256appended to indicate it's a content hash of that field.