Skip to content

Commit

Permalink
feat(marxan-run): expose endpoints for starting/cancelling marxan exe…
Browse files Browse the repository at this point in the history
…cution
  • Loading branch information
kgajowy committed Jul 5, 2021
1 parent a92bc48 commit 9c228bc
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
43 changes: 43 additions & 0 deletions api/apps/api/src/modules/scenarios/scenarios.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
ApiUnauthorizedResponse,
ApiForbiddenResponse,
ApiParam,
ApiAcceptedResponse,
} from '@nestjs/swagger';
import { apiGlobalPrefixes } from '@marxan-api/api.config';
import { JwtAuthGuard } from '@marxan-api/guards/jwt-auth.guard';
Expand Down Expand Up @@ -64,6 +65,9 @@ import { ProxyService } from '@marxan-api/modules/proxy/proxy.service';
const basePath = `${apiGlobalPrefixes.v1}/scenarios`;
const solutionsSubPath = `:id/marxan/run/:runId/solutions`;

const marxanRunTag = 'Marxan Run';
const marxanFilesTag = 'Marxan Run - Files';

@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiTags(scenarioResource.className)
Expand Down Expand Up @@ -245,6 +249,7 @@ export class ScenariosController {
);
}

@ApiTags(marxanFilesTag)
@ApiOperation({ description: `Resolve scenario's input parameter file.` })
@Get(':id/marxan/dat/input.dat')
@ApiProduces('text/plain')
Expand All @@ -255,6 +260,7 @@ export class ScenariosController {
return await this.service.getInputParameterFile(id);
}

@ApiTags(marxanFilesTag)
@ApiOperation({ description: `Resolve scenario's spec file.` })
@Get(':id/marxan/dat/spec.dat')
@ApiProduces('text/plain')
Expand Down Expand Up @@ -310,6 +316,41 @@ export class ScenariosController {
);
}

@ApiOperation({
description: `Request start of the Marxan execution.`,
summary: `Request start of the Marxan execution.`,
})
@ApiTags(marxanRunTag)
@ApiQuery({
name: `blm`,
required: false,
type: Number,
})
@ApiAcceptedResponse({
description: `No content.`,
})
@Post(`:id/marxan`)
async executeMarxanRun(
@Param(`id`, ParseUUIDPipe) id: string,
@Query(`blm`) blm?: number,
) {
await this.service.run(id, blm);
}

@ApiOperation({
description: `Cancel running Marxan execution.`,
summary: `Cancel running Marxan execution.`,
})
@ApiTags(marxanRunTag)
@ApiAcceptedResponse({
description: `No content.`,
})
@Delete(`:id/marxan`)
async cancelMaraxnRun(@Param(`id`, ParseUUIDPipe) id: string) {
await this.service.cancel(id);
}

@ApiTags(marxanRunTag)
@ApiOkResponse({
type: ScenarioSolutionResultDto,
})
Expand All @@ -324,6 +365,7 @@ export class ScenariosController {
);
}

@ApiTags(marxanRunTag)
@ApiOkResponse({
type: ScenarioSolutionResultDto,
})
Expand All @@ -345,6 +387,7 @@ export class ScenariosController {
);
}

@ApiTags(marxanFilesTag)
@Header('Content-Type', 'text/csv')
@ApiOkResponse({
schema: {
Expand Down
20 changes: 19 additions & 1 deletion api/apps/api/src/modules/scenarios/scenarios.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { BadRequestException, HttpService, Injectable } from '@nestjs/common';
import {
BadRequestException,
HttpService,
Injectable,
NotImplementedException,
} from '@nestjs/common';
import { FetchSpecification } from 'nestjs-base-service';
import { classToClass } from 'class-transformer';
import * as stream from 'stream';
Expand Down Expand Up @@ -150,6 +155,19 @@ export class ScenariosService {
return this.specDatService.getSpecDatContent(scenarioId);
}

async run(scenarioId: string, _blm?: number): Promise<void> {
await this.assertScenario(scenarioId);
// TODO ensure not running yet
// TODO submit
throw new NotImplementedException();
}

async cancel(scenarioId: string): Promise<void> {
await this.assertScenario(scenarioId);
// TODO ensure it is running
throw new NotImplementedException();
}

private async assertScenario(scenarioId: string) {
await this.crudService.getById(scenarioId);
}
Expand Down

0 comments on commit 9c228bc

Please sign in to comment.