Skip to content

Commit

Permalink
Feature/add retrigger model extraction (#1349)
Browse files Browse the repository at this point in the history
* update model "extracting" logic
* use gateway endpoint to retrigger model extraction
  • Loading branch information
duranb authored Jul 1, 2024
1 parent 36d81dc commit c9dbcdb
Show file tree
Hide file tree
Showing 9 changed files with 303 additions and 33 deletions.
1 change: 1 addition & 0 deletions src/components/console/views/ModelErrors.svelte.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('Model Errors Console', () => {
{
error: JSON.stringify({ error: 'This is an error' }),
error_message: 'This is a Test Error',
pending: false,
success: false,
},
],
Expand Down
74 changes: 73 additions & 1 deletion src/components/model/ModelForm.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<svelte:options immutable={true} />

<script lang="ts">
import RefreshIcon from '@nasa-jpl/stellar/icons/refresh.svg?component';
import { createEventDispatcher } from 'svelte';
import type { User, UserId } from '../../types/app';
import type { ModelLog, ModelSlim } from '../../types/model';
import effects from '../../utilities/effects';
import { getModelStatusRollup } from '../../utilities/model';
import { permissionHandler } from '../../utilities/permissionHandler';
import { featurePermissions } from '../../utilities/permissions';
import { getShortISOForDate } from '../../utilities/time';
Expand Down Expand Up @@ -38,17 +41,20 @@
const updateModelPermissionError: string = 'You do not have permission to update this model';
const deleteModelPermissionError: string = 'You do not have permission to delete this model';
const createPlanPermissionError: string = 'You do not have permission to create a plan';
const extractionPermissionError: string = 'You do not have permission to re-trigger a model extraction';
let hasUpdateModelPermission: boolean = false;
let hasDeleteModelPermission: boolean = false;
let hasCreatePlanPermission: boolean = false;
let hasExtractionPermission: boolean = false;
let name: string = '';
let owner: UserId | null = null;
let version: string = '';
let description: string = '';
let modelLogs:
| Pick<ModelSlim, 'refresh_activity_type_logs' | 'refresh_model_parameter_logs' | 'refresh_resource_type_logs'>
| undefined = undefined;
let modelHasExtractionError: boolean = false;
$: description = initialModelDescription;
$: name = initialModelName;
Expand All @@ -59,11 +65,21 @@
refresh_model_parameter_logs: modelParameterLogs ?? [],
refresh_resource_type_logs: resourceTypeLogs ?? [],
};
$: {
const { activityLogStatus, parameterLogStatus, resourceLogStatus } = getModelStatusRollup(modelLogs);
if (activityLogStatus === 'error' || parameterLogStatus === 'error' || resourceLogStatus === 'error') {
modelHasExtractionError = true;
} else {
modelHasExtractionError = false;
}
}
$: if (user) {
hasUpdateModelPermission = featurePermissions.model.canUpdate(user);
hasDeleteModelPermission = featurePermissions.model.canDelete(user);
hasCreatePlanPermission = featurePermissions.plan.canCreate(user);
hasExtractionPermission = featurePermissions.model.canUpdate(user);
}
$: dispatch('hasModelChanged', {
Expand All @@ -90,6 +106,26 @@
function onClearOwner() {
owner = null;
}
function onRetriggerModelExtraction() {
const prevLogs = modelLogs;
modelLogs = {
refresh_activity_type_logs: [{ error: null, error_message: null, pending: true, success: false }],
refresh_model_parameter_logs: [{ error: null, error_message: null, pending: true, success: false }],
refresh_resource_type_logs: [{ error: null, error_message: null, pending: true, success: false }],
} as Pick<ModelSlim, 'refresh_activity_type_logs' | 'refresh_model_parameter_logs' | 'refresh_resource_type_logs'>;
// introduce delay to allow users to see a transition in case retriggering is instantaneous
setTimeout(async () => {
if (modelId != null) {
const extractionResponse = await effects.retriggerModelExtraction(modelId, user);
if (extractionResponse == null) {
modelLogs = prevLogs;
}
}
}, 200);
}
</script>

<div class="model-form-container">
Expand Down Expand Up @@ -164,7 +200,25 @@
{/if}
{#if modelId}
<Input layout="inline">
<label class="model-metadata-item-label" for="status">Jar file status</label>
<div class="model-jar-label">
<label class="model-metadata-item-label" for="status">Jar file status</label>
{#if modelHasExtractionError}
<button
class="icon-button"
on:click={onRetriggerModelExtraction}
use:permissionHandler={{
hasPermission: hasExtractionPermission,
permissionError: extractionPermissionError,
}}
use:tooltip={{
content: 'Re-run extraction',
disabled: !hasExtractionPermission,
}}
>
<RefreshIcon />
</button>
{/if}
</div>
<ModelStatusRollup mode="rollup" model={modelLogs} />
</Input>
<div class="model-status-full">
Expand Down Expand Up @@ -207,7 +261,25 @@
row-gap: 8px;
}
.model-jar-label {
display: grid;
grid-template-columns: auto min-content;
}
.model-status-full {
margin: 8px 0;
}
button.icon-button {
align-items: center;
background: none;
border: none;
color: var(--st-primary-70);
cursor: pointer;
display: flex;
}
button.icon-button:hover {
color: var(--st-primary-100);
}
</style>
54 changes: 50 additions & 4 deletions src/components/model/ModelStatusRollup.svelte.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('Model Status Rollup', () => {
{
error: '',
error_message: testError,
pending: false,
success: false,
},
],
Expand All @@ -40,6 +41,7 @@ describe('Model Status Rollup', () => {
{
error: '',
error_message: testError,
pending: false,
success: false,
},
],
Expand All @@ -62,6 +64,7 @@ describe('Model Status Rollup', () => {
{
error: '',
error_message: testError,
pending: false,
success: false,
},
],
Expand All @@ -78,7 +81,14 @@ describe('Model Status Rollup', () => {
props: {
mode: 'rollup',
model: {
refresh_activity_type_logs: [],
refresh_activity_type_logs: [
{
error: null,
error_message: null,
pending: true,
success: false,
},
],
refresh_model_parameter_logs: [],
refresh_resource_type_logs: [],
},
Expand All @@ -97,20 +107,23 @@ describe('Model Status Rollup', () => {
{
error: '',
error_message: '',
pending: false,
success: true,
},
],
refresh_model_parameter_logs: [
{
error: '',
error_message: '',
pending: false,
success: true,
},
],
refresh_resource_type_logs: [
{
error: '',
error_message: '',
pending: false,
success: true,
},
],
Expand All @@ -130,20 +143,23 @@ describe('Model Status Rollup', () => {
{
error: '',
error_message: '',
pending: false,
success: true,
},
],
refresh_model_parameter_logs: [
{
error: '',
error_message: 'Test Error',
pending: false,
success: false,
},
],
refresh_resource_type_logs: [
{
error: '',
error_message: '',
pending: false,
success: true,
},
],
Expand All @@ -164,6 +180,7 @@ describe('Model Status Rollup', () => {
{
error: '',
error_message: testError,
pending: false,
success: false,
},
],
Expand All @@ -186,6 +203,7 @@ describe('Model Status Rollup', () => {
{
error: '',
error_message: testError,
pending: false,
success: false,
},
],
Expand All @@ -208,6 +226,7 @@ describe('Model Status Rollup', () => {
{
error: '',
error_message: testError,
pending: false,
success: false,
},
],
Expand All @@ -224,9 +243,30 @@ describe('Model Status Rollup', () => {
props: {
mode: 'iconOnly',
model: {
refresh_activity_type_logs: [],
refresh_model_parameter_logs: [],
refresh_resource_type_logs: [],
refresh_activity_type_logs: [
{
error: '',
error_message: '',
pending: true,
success: false,
},
],
refresh_model_parameter_logs: [
{
error: '',
error_message: '',
pending: true,
success: false,
},
],
refresh_resource_type_logs: [
{
error: '',
error_message: '',
pending: true,
success: false,
},
],
},
},
});
Expand All @@ -243,20 +283,23 @@ describe('Model Status Rollup', () => {
{
error: '',
error_message: '',
pending: false,
success: true,
},
],
refresh_model_parameter_logs: [
{
error: '',
error_message: '',
pending: false,
success: true,
},
],
refresh_resource_type_logs: [
{
error: '',
error_message: '',
pending: false,
success: true,
},
],
Expand All @@ -276,20 +319,23 @@ describe('Model Status Rollup', () => {
{
error: '',
error_message: '',
pending: false,
success: true,
},
],
refresh_model_parameter_logs: [
{
error: '',
error_message: 'Test Error',
pending: false,
success: false,
},
],
refresh_resource_type_logs: [
{
error: '',
error_message: '',
pending: false,
success: true,
},
],
Expand Down
Loading

0 comments on commit c9dbcdb

Please sign in to comment.