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