Skip to content

Commit

Permalink
Merge branch 'release-1.1' into ple-alerts-IFC-1026
Browse files Browse the repository at this point in the history
  • Loading branch information
pa-lem authored Dec 26, 2024
2 parents 208db12 + 3af41fa commit 8d2cd17
Show file tree
Hide file tree
Showing 11 changed files with 243 additions and 496 deletions.
3 changes: 3 additions & 0 deletions .vale/styles/spelling-exceptions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ schema_mapping
sdk
subcommand
subnet
subtyping
Subtyping
template_path
toml
Towncrier
Expand All @@ -123,5 +125,6 @@ Version Control
Vitest
Yaml
yamllint
YouTube
vscode
VSCode
77 changes: 50 additions & 27 deletions backend/infrahub/core/diff/query/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,29 @@ def __init__(
self.definition_rel_identifier = definition_rel_identifier

async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
self.params = {
"source_branch_name": self.branch.name,
"target_branch_name": self.target_branch.name,
"target_rel_identifier": self.target_rel_identifier,
"definition_rel_identifier": self.definition_rel_identifier,
}
source_branch_filter, branch_params = self.branch.get_query_filter_path(at=self.at.to_string())
self.params.update(branch_params)

self.params.update(
{
"source_branch_name": self.branch.name,
"target_branch_name": self.target_branch.name,
"target_rel_identifier": self.target_rel_identifier,
"definition_rel_identifier": self.definition_rel_identifier,
}
)
query = """
// -----------------------
// get the active artifacts on the source branch
// -----------------------
MATCH (source_artifact:%(artifact_kind)s)-[:IS_PART_OF {branch: $source_branch_name}]->(:Root)
MATCH (source_artifact:%(artifact_kind)s)-[r:IS_PART_OF]->(:Root)
WHERE r.branch IN [$source_branch_name, $target_branch_name]
CALL {
WITH source_artifact
MATCH (source_artifact)-[root_rel:IS_PART_OF {branch: $source_branch_name}]->(:Root)
RETURN root_rel
ORDER BY root_rel.from DESC
MATCH (source_artifact)-[r:IS_PART_OF]->(:Root)
WHERE %(source_branch_filter)s
RETURN r AS root_rel
ORDER BY r.branch_level DESC, r.from DESC
LIMIT 1
}
WITH source_artifact, root_rel
Expand All @@ -52,10 +59,12 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
WITH source_artifact
OPTIONAL MATCH (source_artifact)-[rrel1:IS_RELATED]-(rel_node:Relationship)-[rrel2:IS_RELATED]-(target_node:Node)
WHERE rel_node.name = $target_rel_identifier
AND rrel1.branch = $source_branch_name
AND rrel2.branch = $source_branch_name
RETURN target_node, (rrel1.status = "active" AND rrel2.status = "active") AS target_is_active
ORDER BY rrel1.from DESC, rrel2.from DESC
AND all(r IN [rrel1, rrel2] WHERE ( %(source_branch_filter)s ))
RETURN
target_node,
(rrel1.status = "active" AND rrel2.status = "active") AS target_is_active,
$source_branch_name IN [rrel1.branch, rrel2.branch] AS target_on_source_branch
ORDER BY rrel1.branch_level DESC, rrel1.branch_level DESC, rrel1.from DESC, rrel2.from DESC
LIMIT 1
}
// -----------------------
Expand All @@ -65,10 +74,12 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
WITH source_artifact
OPTIONAL MATCH (source_artifact)-[rrel1:IS_RELATED]-(rel_node:Relationship)-[rrel2:IS_RELATED]-(definition_node:Node)
WHERE rel_node.name = $definition_rel_identifier
AND rrel1.branch = $source_branch_name
AND rrel2.branch = $source_branch_name
RETURN definition_node, (rrel1.status = "active" AND rrel2.status = "active") AS definition_is_active
ORDER BY rrel1.from DESC, rrel2.from DESC
AND all(r IN [rrel1, rrel2] WHERE ( %(source_branch_filter)s ))
RETURN
definition_node,
(rrel1.status = "active" AND rrel2.status = "active") AS definition_is_active,
$source_branch_name IN [rrel1.branch, rrel2.branch] AS definition_on_source_branch
ORDER BY rrel1.branch_level DESC, rrel1.branch_level DESC, rrel1.from DESC, rrel2.from DESC
LIMIT 1
}
// -----------------------
Expand All @@ -78,10 +89,12 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
WITH source_artifact
OPTIONAL MATCH (source_artifact)-[attr_rel:HAS_ATTRIBUTE]->(attr:Attribute)-[value_rel:HAS_VALUE]->(attr_val:AttributeValue)
WHERE attr.name = "checksum"
AND attr_rel.branch = $source_branch_name
AND value_rel.branch = $source_branch_name
RETURN attr_val.value AS checksum, (attr_rel.status = "active" AND value_rel.status = "active") AS checksum_is_active
ORDER BY value_rel.from DESC, attr_rel.from DESC
AND all(r IN [attr_rel, value_rel] WHERE ( %(source_branch_filter)s ))
RETURN
attr_val.value AS checksum,
(attr_rel.status = "active" AND value_rel.status = "active") AS checksum_is_active,
$source_branch_name IN [attr_rel.branch, value_rel.branch] AS checksum_on_source_branch
ORDER BY value_rel.branch_level DESC, attr_rel.branch_level DESC, value_rel.from DESC, attr_rel.from DESC
LIMIT 1
}
// -----------------------
Expand All @@ -91,12 +104,22 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
WITH source_artifact
OPTIONAL MATCH (source_artifact)-[attr_rel:HAS_ATTRIBUTE]->(attr:Attribute)-[value_rel:HAS_VALUE]->(attr_val:AttributeValue)
WHERE attr.name = "storage_id"
AND attr_rel.branch = $source_branch_name
AND value_rel.branch = $source_branch_name
RETURN attr_val.value AS storage_id, (attr_rel.status = "active" AND value_rel.status = "active") AS storage_id_is_active
ORDER BY value_rel.from DESC, attr_rel.from DESC
AND all(r IN [attr_rel, value_rel] WHERE ( %(source_branch_filter)s ))
RETURN
attr_val.value AS storage_id,
(attr_rel.status = "active" AND value_rel.status = "active") AS storage_id_is_active,
$source_branch_name IN [attr_rel.branch, value_rel.branch] AS storage_id_on_source_branch
ORDER BY value_rel.branch_level DESC, attr_rel.branch_level DESC, value_rel.from DESC, attr_rel.from DESC
LIMIT 1
}
WITH target_node, target_is_active, target_on_source_branch,
definition_node, definition_is_active, definition_on_source_branch,
checksum, checksum_is_active, checksum_on_source_branch,
storage_id, storage_id_is_active, storage_id_on_source_branch
WHERE (target_is_active AND target_on_source_branch)
OR (definition_is_active AND definition_on_source_branch)
OR (checksum_is_active AND checksum_on_source_branch)
OR (storage_id_is_active AND storage_id_on_source_branch)
RETURN CASE
WHEN target_is_active = TRUE THEN target_node
ELSE NULL
Expand Down Expand Up @@ -175,7 +198,7 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
ELSE NULL
END AS target_storage_id
}
""" % {"artifact_kind": InfrahubKind.ARTIFACT}
""" % {"artifact_kind": InfrahubKind.ARTIFACT, "source_branch_filter": source_branch_filter}
self.return_labels = [
"source_artifact",
"target_node",
Expand Down
147 changes: 0 additions & 147 deletions backend/infrahub/graphql/mutations/task.py

This file was deleted.

14 changes: 2 additions & 12 deletions backend/infrahub/graphql/queries/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from infrahub_sdk.utils import extract_fields_first_node
from prefect.client.schemas.objects import StateType

from infrahub.core.task.task import Task as TaskNode
from infrahub.graphql.types.task import TaskNodes, TaskState
from infrahub.task_manager.task import PrefectTask
from infrahub.workflows.constants import WorkflowTag
Expand Down Expand Up @@ -76,14 +75,6 @@ async def query(
context: GraphqlContext = info.context
fields = await extract_fields_first_node(info)

# During the migration, query both Prefect and Infrahub to get the list of tasks
if not branch:
infrahub_tasks = await TaskNode.query(
db=context.db, fields=fields, limit=limit, offset=offset, ids=ids, related_nodes=related_nodes
)
else:
infrahub_tasks = {}

prefect_tasks = await PrefectTask.query(
db=context.db,
fields=fields,
Expand All @@ -97,11 +88,10 @@ async def query(
limit=limit,
offset=offset,
)
infrahub_count = infrahub_tasks.get("count", None)
prefect_count = prefect_tasks.get("count", None)
return {
"count": (infrahub_count or 0) + (prefect_count or 0),
"edges": infrahub_tasks.get("edges", []) + prefect_tasks.get("edges", []),
"count": prefect_count or 0,
"edges": prefect_tasks.get("edges", []),
}


Expand Down
6 changes: 0 additions & 6 deletions backend/infrahub/graphql/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
SchemaEnumAdd,
SchemaEnumRemove,
)
from .mutations.task import (
TaskCreate,
TaskUpdate,
)
from .queries import (
AccountPermissions,
AccountToken,
Expand Down Expand Up @@ -100,8 +96,6 @@ class InfrahubBaseMutation(ObjectType):

InfrahubRepositoryProcess = ProcessRepository.Field()
InfrahubRepositoryConnectivity = ValidateRepositoryConnectivity.Field()
InfrahubTaskCreate = TaskCreate.Field()
InfrahubTaskUpdate = TaskUpdate.Field()
InfrahubUpdateComputedAttribute = UpdateComputedAttribute.Field()

RelationshipAdd = RelationshipAdd.Field()
Expand Down
Loading

0 comments on commit 8d2cd17

Please sign in to comment.