This repository has been archived by the owner on Nov 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
workflow-gtfs-catalog-validator.yaml
148 lines (145 loc) · 7.51 KB
/
workflow-gtfs-catalog-validator.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#
# Validates a GTFS dataset executing the GTFS validator on Cloud Run.
#
## Input:
# {
# "results_bucket_path": "gs://gtfs-validator-results-playground/reports",
# "concurrency_limits": 20
# }
## Output:
# No output
main:
params: [args]
steps:
- validate:
try:
steps:
- init:
assign:
# example: gs://gtfs-validator-results-playground/reports
- resultsBucketPath: $${args.results_bucket_path}
# Extrating the bucket's name from the bucket's path
# example: gtfs-validator-results-playground
- resultsBucketName: $${text.replace_all(resultsBucketPath, "gs://","")}
- resultsBucketName: $${text.split(resultsBucketName, "/")[0]}
# Path refix included in the resultsBucketPath
# example: reports
- resultsBucketPrefixPath: $${text.substring(resultsBucketPath, len("gs://") + len(resultsBucketName) + 1, len(resultsBucketPath))}
- catalogUrl: ${configCatalogFunctionUrl}
- validateWorkflow: "workflow-gtfs-validator3"
- location: $${default(map.get(args, "region"), "us-central1")}
- concurrencyLimits: $${default(map.get(args, "concurrency_limits"), 20)}
- dateTime: $${text.substring(time.format(sys.now()), 0, 16)}
- reportsExportPath: $${dateTime + "/" + sys.get_env("GOOGLE_CLOUD_WORKFLOW_EXECUTION_ID")}
- totalSucceeded: 0
- totalFailed: 0
- failedDatasets: []
- initLog:
call: sys.log
args:
text: $${"Validating catalog from " + catalogUrl + ". Reports added to " + reportsExportPath }
severity: INFO
- retrieveCatalog:
call: http.get
args:
url: $${catalogUrl}
auth:
type: OIDC
result: catalogResponse
- datasetResponseLog:
call: sys.log
args:
text: $${"Loaded catalog database with " + len(catalogResponse.body) + " datasets"}
severity: INFO
- datasetCounter:
assign:
- datasetCount: $${len(catalogResponse.body)}
- validationLoop:
parallel:
concurrency_limit: $${concurrencyLimits}
shared: [totalSucceeded, totalFailed, failedDatasets]
for:
value: datasetIndex
range: [0, $${len(catalogResponse.body) -1}] # inclusive beginning and ending values
steps:
- datasetVars:
assign:
- validatorImage: "us-central1-docker.pkg.dev/md-poc-playground3/gtfs-validator-registry/gtfs-validator:5.0.0"
- feedUrl: $${catalogResponse.body[datasetIndex]["urls.latest"]}
- feedId: $${catalogResponse.body[datasetIndex]["mdb_source_id"]}
- feedKey: $${catalogResponse.body[datasetIndex]["source_key"]}
- reference_validator_version: "4.2.0"
- target_validator_version: "5.0.0"
- reportFilename: $${ resultsBucketPath + "/" + reportsExportPath + "/" + feedKey + ".json"}
- datasetLog:
call: sys.log
args:
text: $${"Validating dataset " + feedKey }
severity: INFO
- callValidateWorkflow:
try:
steps:
- callValidate:
call: googleapis.workflowexecutions.v1beta.projects.locations.workflows.executions.run
args:
workflow_id: $${validateWorkflow}
location: $${location}
project_id: $${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
argument:
validator_image: $${validatorImage}
feed_url: $${feedUrl}
feed_id: $${feedId}
feed_key: $${feedKey}
reports_bucket_path: $${resultsBucketPath + "/" + reportsExportPath + "/" + feedKey}
reference_validator_version: $${reference_validator_version}
target_validator_version: $${target_validator_version}
result: validateDatasetResponse
- validateDatasetResponseLog:
call: sys.log
args:
text: $${"Dataset validation response " + json.encode_to_string(validateDatasetResponse)}
severity: INFO
- summarySucceeded:
assign:
- totalSucceeded: $${totalSucceeded + 1}
except:
as: e
steps:
- summaryFailed:
assign:
- totalFailed: $${totalFailed + 1}
- logException:
call: sys.log
args:
text: $${"Error validating dataset " + feedId + " exception " + json.encode_to_string(e)}
severity: ERROR
- addErrorValidation:
assign:
- failedDatasets[len(failedDatasets) - 1]: feedId
except:
as: e
steps:
- unhandled_exception:
raise: $${e}
- persistSummary:
call: googleapis.storage.v1.objects.insert
args:
bucket: $${resultsBucketName}
uploadType: "media"
name: $${resultsBucketPrefixPath + "/" + reportsExportPath + "/" + "summary.json"}
body:
succeeded: $${totalSucceeded}
failed: $${totalFailed}
failedDatasets: $${failedDatasets}
total: $${totalSucceeded + totalFailed}
concurrencyLimits: $${concurrencyLimits}
resultsBucketPath: $${resultsBucketPath}
- return:
return:
summary:
succeeded: $${totalSucceeded}
failed: $${totalFailed}
failedDatasets: $${failedDatasets}
total: $${totalSucceeded + totalFailed}
concurrencyLimits: $${concurrencyLimits}
resultsBucketPath: $${resultsBucketPath}