|
| 1 | +<script> |
| 2 | + import { goto } from '$app/navigation'; |
| 3 | + import { AlertError } from '$lib/common/errors'; |
| 4 | + import StandardErrorAlert from '$lib/components/common/StandardErrorAlert.svelte'; |
| 5 | +
|
| 6 | + let zarrDir = ''; |
| 7 | + let inProgress = false; |
| 8 | + let stepMessage = ''; |
| 9 | + let invalidZarrDir = false; |
| 10 | + let error = undefined; |
| 11 | +
|
| 12 | + async function startTest() { |
| 13 | + error = undefined; |
| 14 | + stepMessage = ''; |
| 15 | + if (!zarrDir) { |
| 16 | + invalidZarrDir = true; |
| 17 | + return; |
| 18 | + } |
| 19 | + invalidZarrDir = false; |
| 20 | + inProgress = true; |
| 21 | + try { |
| 22 | + const projectId = await createProject(); |
| 23 | + const datasetId = await createDataset(projectId); |
| 24 | + const workflowId = await createWorkflow(projectId); |
| 25 | + const taskId = await createHealthCheckTaskIfNeeded(); |
| 26 | + await addTaskToWorkflow(projectId, workflowId, taskId); |
| 27 | + await submitWorkflow(projectId, workflowId, datasetId); |
| 28 | + await goto(`/v2/projects/${projectId}/workflows/${workflowId}`); |
| 29 | + } catch (err) { |
| 30 | + error = err; |
| 31 | + } finally { |
| 32 | + inProgress = false; |
| 33 | + } |
| 34 | + } |
| 35 | +
|
| 36 | + const headers = new Headers(); |
| 37 | + headers.set('Content-Type', 'application/json'); |
| 38 | +
|
| 39 | + async function createProject() { |
| 40 | + const randomPart = new Date().getTime(); |
| 41 | + const projectName = `test_${randomPart}`; |
| 42 | +
|
| 43 | + stepMessage = `Creating project ${projectName}`; |
| 44 | +
|
| 45 | + const response = await fetch(`/api/v2/project`, { |
| 46 | + method: 'POST', |
| 47 | + credentials: 'include', |
| 48 | + headers, |
| 49 | + body: JSON.stringify({ |
| 50 | + name: projectName |
| 51 | + }) |
| 52 | + }); |
| 53 | +
|
| 54 | + const result = await response.json(); |
| 55 | + if (!response.ok) { |
| 56 | + throw new AlertError(result); |
| 57 | + } |
| 58 | + return result.id; |
| 59 | + } |
| 60 | +
|
| 61 | + /** |
| 62 | + * @param {number} projectId |
| 63 | + */ |
| 64 | + async function createDataset(projectId) { |
| 65 | + stepMessage = `Creating test dataset`; |
| 66 | +
|
| 67 | + const response = await fetch(`/api/v2/project/${projectId}/dataset`, { |
| 68 | + method: 'POST', |
| 69 | + credentials: 'include', |
| 70 | + headers, |
| 71 | + body: JSON.stringify({ |
| 72 | + name: 'test', |
| 73 | + zarr_dir: zarrDir, |
| 74 | + filters: { attributes: {}, types: {} } |
| 75 | + }) |
| 76 | + }); |
| 77 | +
|
| 78 | + const result = await response.json(); |
| 79 | + if (!response.ok) { |
| 80 | + throw new AlertError(result); |
| 81 | + } |
| 82 | + return result.id; |
| 83 | + } |
| 84 | +
|
| 85 | + /** |
| 86 | + * @param {number} projectId |
| 87 | + */ |
| 88 | + async function createWorkflow(projectId) { |
| 89 | + stepMessage = `Creating test workflow`; |
| 90 | +
|
| 91 | + const response = await fetch(`/api/v2/project/${projectId}/workflow`, { |
| 92 | + method: 'POST', |
| 93 | + credentials: 'include', |
| 94 | + headers, |
| 95 | + body: JSON.stringify({ name: 'test' }) |
| 96 | + }); |
| 97 | +
|
| 98 | + const result = await response.json(); |
| 99 | + if (!response.ok) { |
| 100 | + throw new AlertError(result); |
| 101 | + } |
| 102 | + return result.id; |
| 103 | + } |
| 104 | +
|
| 105 | + async function createHealthCheckTaskIfNeeded() { |
| 106 | + stepMessage = `Checking if health check test task exists`; |
| 107 | + const taskId = await getHealthCheckTask(); |
| 108 | + if (taskId !== undefined) { |
| 109 | + return taskId; |
| 110 | + } |
| 111 | +
|
| 112 | + stepMessage = `Creating health check test task`; |
| 113 | +
|
| 114 | + const response = await fetch(`/api/v2/task`, { |
| 115 | + method: 'POST', |
| 116 | + credentials: 'include', |
| 117 | + headers, |
| 118 | + body: JSON.stringify({ |
| 119 | + name: 'job_submission_health_check', |
| 120 | + command_non_parallel: 'echo', |
| 121 | + source: 'job_submission_health_check', |
| 122 | + input_types: {}, |
| 123 | + output_types: {} |
| 124 | + }) |
| 125 | + }); |
| 126 | +
|
| 127 | + const result = await response.json(); |
| 128 | + if (!response.ok) { |
| 129 | + throw new AlertError(result); |
| 130 | + } |
| 131 | + return result.id; |
| 132 | + } |
| 133 | +
|
| 134 | + async function getHealthCheckTask() { |
| 135 | + const response = await fetch(`/api/v2/task`, { |
| 136 | + method: 'GET', |
| 137 | + credentials: 'include' |
| 138 | + }); |
| 139 | + const result = await response.json(); |
| 140 | + if (!response.ok) { |
| 141 | + throw new AlertError(result); |
| 142 | + } |
| 143 | + const tasks = result.filter((t) => t.source.endsWith(':job_submission_health_check')); |
| 144 | + return tasks.length > 0 ? tasks[0].id : undefined; |
| 145 | + } |
| 146 | +
|
| 147 | + /** |
| 148 | + * @param {number} projectId |
| 149 | + * @param {number} workflowId |
| 150 | + * @param {number} taskId |
| 151 | + */ |
| 152 | + async function addTaskToWorkflow(projectId, workflowId, taskId) { |
| 153 | + stepMessage = `Adding task to workflow`; |
| 154 | +
|
| 155 | + const response = await fetch( |
| 156 | + `/api/v2/project/${projectId}/workflow/${workflowId}/wftask?task_id=${taskId}`, |
| 157 | + { |
| 158 | + method: 'POST', |
| 159 | + credentials: 'include', |
| 160 | + headers, |
| 161 | + body: JSON.stringify({ is_legacy_task: false }) |
| 162 | + } |
| 163 | + ); |
| 164 | + const result = await response.json(); |
| 165 | + if (!response.ok) { |
| 166 | + throw new AlertError(result); |
| 167 | + } |
| 168 | + } |
| 169 | +
|
| 170 | + /** |
| 171 | + * @param {number} projectId |
| 172 | + * @param {number} workflowId |
| 173 | + * @param {number} datasetId |
| 174 | + */ |
| 175 | + async function submitWorkflow(projectId, workflowId, datasetId) { |
| 176 | + stepMessage = `Submitting workflow`; |
| 177 | +
|
| 178 | + const response = await fetch( |
| 179 | + `/api/v2/project/${projectId}/job/submit?workflow_id=${workflowId}&dataset_id=${datasetId}`, |
| 180 | + { |
| 181 | + method: 'POST', |
| 182 | + credentials: 'include', |
| 183 | + headers, |
| 184 | + body: JSON.stringify({ first_task_index: 0 }) |
| 185 | + } |
| 186 | + ); |
| 187 | + const result = await response.json(); |
| 188 | + if (!response.ok) { |
| 189 | + throw new AlertError(result); |
| 190 | + } |
| 191 | + } |
| 192 | +</script> |
| 193 | + |
| 194 | +<div> |
| 195 | + <h1 class="fw-light mb-3">Job submission healthcheck</h1> |
| 196 | + |
| 197 | + <p>This page performs the following steps:</p> |
| 198 | + |
| 199 | + <ul> |
| 200 | + <li>creates a project with name <code>test_{random_integer}</code>;</li> |
| 201 | + <li>creates a dataset, with the provided zarr directory;</li> |
| 202 | + <li>creates a workflow;</li> |
| 203 | + <li> |
| 204 | + if not existing, creates a non-parallel task with a source named |
| 205 | + <code>job_submission_health_check</code>, with <code>command_non_parallel="echo"</code>. |
| 206 | + </li> |
| 207 | + <li>adds the task to the workflow;</li> |
| 208 | + <li>submits the workflow;</li> |
| 209 | + <li> |
| 210 | + if all up to here was successful, redirects to the workflow page; if anything failed, stops the |
| 211 | + procedure and displays an error. |
| 212 | + </li> |
| 213 | + </ul> |
| 214 | + |
| 215 | + <div class="row mt-4"> |
| 216 | + <div class="col"> |
| 217 | + <div class="input-group mb-3" class:has-validation={invalidZarrDir}> |
| 218 | + <label class="input-group-text" for="zarrDir">Zarr directory</label> |
| 219 | + <input |
| 220 | + type="text" |
| 221 | + class="form-control" |
| 222 | + id="zarrDir" |
| 223 | + bind:value={zarrDir} |
| 224 | + class:is-invalid={invalidZarrDir} |
| 225 | + /> |
| 226 | + {#if invalidZarrDir} |
| 227 | + <div class="invalid-feedback">Zarr directory is required</div> |
| 228 | + {/if} |
| 229 | + </div> |
| 230 | + </div> |
| 231 | + </div> |
| 232 | + |
| 233 | + <StandardErrorAlert {error}> |
| 234 | + <p>An error happened while executing the following step: <strong>{stepMessage}</strong></p> |
| 235 | + </StandardErrorAlert> |
| 236 | + |
| 237 | + <div class="row"> |
| 238 | + <div class="col"> |
| 239 | + <button class="btn btn-primary" disabled={inProgress} on:click={startTest}> |
| 240 | + {#if inProgress} |
| 241 | + <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" /> |
| 242 | + {/if} |
| 243 | + Test |
| 244 | + </button> |
| 245 | + </div> |
| 246 | + </div> |
| 247 | +</div> |
0 commit comments