Skip to content

Instantly share code, notes, and snippets.

@mateumann

mateumann/events.py

Last active May 8, 2020
Embed
What would you like to do?
alchemia
events_n_logs = reduce(
lambda left, right: left.union_all(right),
subqueries,
)
query = db.session.query(
literal_column('events_n_logs.id'),
literal_column('events_n_logs._storage_id'),
literal_column('events_n_logs.timestamp'),
literal_column('events_n_logs.reported_timestamp'),
Blueprint.id.label('blueprint_id'),
Deployment.id.label('deployment_id'),
Execution.id.label('execution_id'),
Execution.workflow_id.label('workflow_id'),
literal_column('events_n_logs.message'),
literal_column('events_n_logs.message_code'),
literal_column('events_n_logs.error_causes'),
literal_column('events_n_logs.event_type'),
literal_column('events_n_logs.operation'),
literal_column('events_n_logs.node_id'),
literal_column('events_n_logs.source_id'),
literal_column('events_n_logs.target_id'),
NodeInstance.id.label('node_instance_id'),
Node.id.label('node_name'),
literal_column('events_n_logs.logger'),
literal_column('events_n_logs.level'),
literal_column('events_n_logs.type').label('type'),
literal_column('events_n_logs._tenant_id'),
literal_column('events_n_logs.visibility'),
literal_column('events_n_logs._execution_fk'),
).select_from(
events_n_logs.subquery(name='events_n_logs')
).outerjoin(NodeInstance, NodeInstance.id == literal_column('events_n_logs.id')
).outerjoin(Node, Node._storage_id == NodeInstance._node_fk
).outerjoin(Execution, Execution._storage_id == literal_column('events_n_logs._execution_fk')
).outerjoin(Deployment, Deployment._storage_id == Execution._deployment_fk
).outerjoin(Blueprint, Blueprint._storage_id == Deployment._blueprint_fk
).filter(
sql_or(literal_column('events_n_logs._tenant_id') == tenant_id,
literal_column('events_n_logs.visibility') == VisibilityState.GLOBAL)
)
SELECT count(*) AS count_1
FROM (SELECT events_n_logs.id,
events_n_logs._storage_id,
events_n_logs.timestamp,
events_n_logs.reported_timestamp,
blueprints.id AS blueprint_id,
deployments.id AS deployment_id,
executions.id AS execution_id,
executions.workflow_id AS workflow_id,
events_n_logs.message,
events_n_logs.message_code,
events_n_logs.error_causes,
events_n_logs.event_type,
events_n_logs.operation,
events_n_logs.node_id,
events_n_logs.source_id,
events_n_logs.target_id,
node_instances.id AS node_instance_id,
nodes.id AS node_name,
events_n_logs.logger,
events_n_logs.level,
events_n_logs.type AS type,
events_n_logs._tenant_id,
events_n_logs.visibility,
events_n_logs._execution_fk
FROM (SELECT anon_2.id AS id,
anon_2._storage_id AS _storage_id,
anon_2.timestamp AS timestamp,
anon_2.reported_timestamp AS reported_timestamp,
anon_2.message AS message,
anon_2.message_code AS message_code,
anon_2.error_causes AS error_causes,
anon_2.event_type AS event_type,
anon_2.operation AS operation,
anon_2.node_id AS node_id,
anon_2.source_id AS source_id,
anon_2.target_id AS target_id,
anon_2.logger AS logger,
anon_2.level AS level,
anon_2.type AS type,
anon_2._tenant_id AS _tenant_id,
anon_2.visibility AS visibility,
anon_2._execution_fk AS _execution_fk
FROM (SELECT events.id AS id,
events._storage_id AS _storage_id,
events.timestamp AS timestamp,
events.reported_timestamp AS reported_timestamp,
events.message AS message,
events.message_code AS message_code,
events.error_causes AS error_causes,
events.event_type AS event_type,
events.operation AS operation,
events.node_id AS node_id,
events.source_id AS source_id,
events.target_id AS target_id,
NULL AS logger,
NULL AS level,
'cloudify_event' AS type,
events._tenant_id AS _tenant_id,
events.visibility AS visibility,
events._execution_fk AS _execution_fk
FROM events
UNION ALL
SELECT logs.id AS id,
logs._storage_id AS _storage_id,
logs.timestamp AS timestamp,
logs.reported_timestamp AS reported_timestamp,
logs.message AS message,
logs.message_code AS message_code,
NULL AS error_causes,
NULL AS event_type,
logs.operation AS operation,
logs.node_id AS node_id,
logs.source_id AS source_id,
logs.target_id AS target_id,
logs.logger AS logger,
logs.level AS level,
'cloudify_log' AS type,
logs._tenant_id AS _tenant_id,
logs.visibility AS visibility,
logs._execution_fk AS _execution_fk
FROM logs) AS anon_2) AS events_n_logs
LEFT OUTER JOIN node_instances ON node_instances.id = events_n_logs.id
LEFT OUTER JOIN nodes ON nodes._storage_id = node_instances._node_fk
LEFT OUTER JOIN executions ON executions._storage_id = events_n_logs._execution_fk
LEFT OUTER JOIN deployments ON deployments._storage_id = executions._deployment_fk
LEFT OUTER JOIN blueprints ON blueprints._storage_id = deployments._blueprint_fk
WHERE events_n_logs._tenant_id = 0
OR events_n_logs.visibility = 'global') AS anon_1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.