Skip to content

Commit

Permalink
Support dataset validation in ValidateAction
Browse files Browse the repository at this point in the history
During a `create` operation, the `validate` action can take a
`datasets` option listing path/schema pairs that will be applied
to any datasets in jobParams.datasetList.

Datasets are fetched from the database during the DTO validation step
if needed.

Validation of archive/retrieve/public lifecycle properties is no longer
done automatically, but must be configured in the jobConfig file.

Details:
- Separate ValidateCreateJobAction (create) and ValidateJobAction (update)
- Fix 'Internal Server Error' from job controller if a session timed out.
  If the session times out then only public jobs will be visible.
- Update documentation for validate action
- Remove checkDatasetState from the job controller.
  This must now be configured with a validate action
- Add unit test
- Remove hard-coded job types and dataset states
  • Loading branch information
sbliven committed Dec 18, 2024
1 parent 4d92d47 commit be8fe75
Show file tree
Hide file tree
Showing 13 changed files with 533 additions and 276 deletions.
23 changes: 20 additions & 3 deletions jobConfig.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ configVersion: v1.0 2024-03-01 6f3f38
jobs:
- jobType: archive
create:
auth: "#all"
auth: "#datasetOwner"
actions:
- actionType: log
- actionType: validate
datasets:
"datasetlifecycle.archivable":
const: true
- actionType: url
url: http://localhost:3000/api/v3/health?jobid={{id}}
headers:
Expand Down Expand Up @@ -36,6 +39,17 @@ jobs:
exchange: jobs.write
queue: client.jobs.write
key: jobqueue
- jobType: retrieve
create:
auth: "#datasetOwner"
actions:
- actionType: validate
datasets:
"datasetlifecycle.retrievable":
const: true
statusUpdate:
auth: "archivemanager"
actions: []
- jobType: public
create:
auth: "#all"
Expand All @@ -47,5 +61,8 @@ jobs:
required:
- pid
- files
datasets:
isPublished:
const: true
statusUpdate:
auth: "#all"
auth: "archivemanager"
8 changes: 4 additions & 4 deletions src/config/job-config/actions/corejobactioncreators.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { actionType as logActionType } from "./logaction/logaction.interface";
import { actionType as emailActionType } from "./emailaction/emailaction.interface";
import { ValidateJobActionModule } from "./validateaction/validateaction.module";
import { actionType as validateActionType } from "./validateaction/validateaction.interface";
import { ValidateJobActionCreator } from "./validateaction/validateaction.service";
import { ValidateCreateJobActionCreator, ValidateJobActionCreator } from "./validateaction/validateaction.service";

Check failure on line 10 in src/config/job-config/actions/corejobactioncreators.module.ts

View workflow job for this annotation

GitHub Actions / eslint

Replace `·ValidateCreateJobActionCreator,·ValidateJobActionCreator·` with `⏎··ValidateCreateJobActionCreator,⏎··ValidateJobActionCreator,⏎`
import { URLJobActionModule } from "./urlaction/urlaction.module";
import { URLJobActionCreator } from "./urlaction/urlaction.service";
import { actionType as urlActionType } from "./urlaction/urlaction.interface";
Expand Down Expand Up @@ -39,22 +39,22 @@ import {
useFactory: (
logJobActionCreator,
emailJobActionCreator,
validateJobActionCreator,
validateCreateJobActionCreator,
urlJobActionCreator,
rabbitMQJobActionCreator,
) => {
return {
[logActionType]: logJobActionCreator,
[emailActionType]: emailJobActionCreator,
[validateActionType]: validateJobActionCreator,
[validateActionType]: validateCreateJobActionCreator,
[urlActionType]: urlJobActionCreator,
[rabbitmqActionType]: rabbitMQJobActionCreator,
};
},
inject: [
LogJobActionCreator,
EmailJobActionCreator,
ValidateJobActionCreator,
ValidateCreateJobActionCreator,
URLJobActionCreator,
RabbitMQJobActionCreator,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ export const actionType = "validate";

export interface ValidateJobActionOptions extends JobActionOptions {
actionType: typeof actionType;
request: Record<string, unknown>;
request?: Record<string, unknown>;
}

export interface ValidateCreateJobActionOptions extends ValidateJobActionOptions {

Check failure on line 10 in src/config/job-config/actions/validateaction/validateaction.interface.ts

View workflow job for this annotation

GitHub Actions / eslint

Insert `⏎·`
actionType: typeof actionType;
request?: Record<string, unknown>;
datasets?: Record<string, unknown>;
}

/**
Expand All @@ -15,7 +21,20 @@ export function isValidateJobActionOptions(
): options is ValidateJobActionOptions {
if (typeof options === "object" && options !== null) {
const opts = options as ValidateJobActionOptions;
return opts.actionType === actionType && typeof opts.request === "object";
return opts.actionType === actionType && (opts.request === undefined || typeof opts.request === "object");

Check failure on line 24 in src/config/job-config/actions/validateaction/validateaction.interface.ts

View workflow job for this annotation

GitHub Actions / eslint

Replace `opts.actionType·===·actionType·&&·(opts.request·===·undefined·||·typeof·opts.request·===·"object"` with `(⏎······opts.actionType·===·actionType·&&⏎······(opts.request·===·undefined·||·typeof·opts.request·===·"object")⏎····`
}
return false;
}

/**
* Type guard for EmailJobActionOptions
*/
export function isValidateCreateJobActionOptions(
options: unknown,
): options is ValidateJobActionOptions {
if (typeof options === "object" && options !== null) {
const opts = options as ValidateCreateJobActionOptions;
return opts.actionType === actionType && (opts.request === undefined || typeof opts.request === "object") && (opts.datasets === undefined || typeof opts.datasets === "object");

Check failure on line 37 in src/config/job-config/actions/validateaction/validateaction.interface.ts

View workflow job for this annotation

GitHub Actions / eslint

Replace `opts.actionType·===·actionType·&&·(opts.request·===·undefined·||·typeof·opts.request·===·"object")·&&·(opts.datasets·===·undefined·||·typeof·opts.datasets·===·"object"` with `(⏎······opts.actionType·===·actionType·&&⏎······(opts.request·===·undefined·||·typeof·opts.request·===·"object")·&&⏎······(opts.datasets·===·undefined·||·typeof·opts.datasets·===·"object")⏎····`
}
return false;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Module } from "@nestjs/common";
import { ValidateJobActionCreator } from "./validateaction.service";
import { ValidateCreateJobActionCreator, ValidateJobActionCreator } from "./validateaction.service";

Check failure on line 2 in src/config/job-config/actions/validateaction/validateaction.module.ts

View workflow job for this annotation

GitHub Actions / eslint

Replace `·ValidateCreateJobActionCreator,·ValidateJobActionCreator·` with `⏎··ValidateCreateJobActionCreator,⏎··ValidateJobActionCreator,⏎`

@Module({
providers: [ValidateJobActionCreator],
exports: [ValidateJobActionCreator],
providers: [ValidateJobActionCreator, ValidateCreateJobActionCreator],
exports: [ValidateJobActionCreator, ValidateCreateJobActionCreator],
})
export class ValidateJobActionModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import {
JobActionOptions,
JobDto,
} from "../../jobconfig.interface";
import { ValidateJobAction } from "./validateaction";
import { ValidateCreateJobAction, ValidateJobAction } from "./validateaction";
import { isValidateJobActionOptions } from "./validateaction.interface";
import { DatasetsService } from "src/datasets/datasets.service";
import { CreateJobDto } from "src/jobs/dto/create-job.dto";

@Injectable()
export class ValidateJobActionCreator implements JobActionCreator<JobDto> {
constructor() {}
constructor(private datasetService: DatasetsService) {}

public create<Options extends JobActionOptions>(options: Options) {
if (!isValidateJobActionOptions(options)) {
Expand All @@ -18,3 +20,15 @@ export class ValidateJobActionCreator implements JobActionCreator<JobDto> {
return new ValidateJobAction(options);
}
}

@Injectable()
export class ValidateCreateJobActionCreator implements JobActionCreator<CreateJobDto> {

Check failure on line 25 in src/config/job-config/actions/validateaction/validateaction.service.ts

View workflow job for this annotation

GitHub Actions / eslint

Replace `·implements·JobActionCreator<CreateJobDto>·` with `⏎··implements·JobActionCreator<CreateJobDto>⏎`
constructor(private datasetService: DatasetsService) {}

public create<Options extends JobActionOptions>(options: Options) {
if (!isValidateJobActionOptions(options)) {
throw new Error("Invalid options for ValidateJobAction.");
}
return new ValidateCreateJobAction(this.datasetService, options);
}
}
Loading

0 comments on commit be8fe75

Please sign in to comment.