-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): pass assets to marxan run job
- Loading branch information
Showing
23 changed files
with
347 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
api/apps/api/src/modules/scenarios/marxan-run/assets.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { PromiseType } from 'utility-types'; | ||
import { Test } from '@nestjs/testing'; | ||
import { apiUrlToken, AssetsService } from './assets.service'; | ||
import { IoSettings, ioSettingsToken } from './io-settings'; | ||
|
||
let fixtures: PromiseType<ReturnType<typeof getFixtures>>; | ||
let service: AssetsService; | ||
|
||
beforeEach(async () => { | ||
fixtures = await getFixtures(); | ||
|
||
service = fixtures.getAssetsService(); | ||
}); | ||
|
||
it(`should return valid config`, async () => { | ||
const random = fixtures.random; | ||
expect(await service.forScenario(`scenario-${random}`)).toStrictEqual([ | ||
{ | ||
url: `https://api-endpoint${random}.test:3000/api/v1/marxan-run/scenarios/scenario-${random}/marxan/dat/input.dat`, | ||
relativeDestination: `input.dat`, | ||
}, | ||
{ | ||
url: `https://api-endpoint${random}.test:3000/api/v1/marxan-run/scenarios/scenario-${random}/marxan/dat/pu.dat`, | ||
relativeDestination: `inputDir${random}/pu-name-file${random}`, | ||
}, | ||
{ | ||
url: `https://api-endpoint${random}.test:3000/api/v1/marxan-run/scenarios/scenario-${random}/marxan/dat/bound.dat`, | ||
relativeDestination: `inputDir${random}/bound-name-file${random}`, | ||
}, | ||
{ | ||
url: `https://api-endpoint${random}.test:3000/api/v1/marxan-run/scenarios/scenario-${random}/marxan/dat/spec.dat`, | ||
relativeDestination: `inputDir${random}/spec-name-file${random}`, | ||
}, | ||
{ | ||
url: `https://api-endpoint${random}.test:3000/api/v1/marxan-run/scenarios/scenario-${random}/marxan/dat/puvspr.dat`, | ||
relativeDestination: `inputDir${random}/puv-spr-name-file${random}`, | ||
}, | ||
]); | ||
}); | ||
|
||
async function getFixtures() { | ||
const random = Math.random().toString(36); | ||
const ioSettings: IoSettings = { | ||
BOUNDNAME: `bound-name-file${random}`, | ||
INPUTDIR: `inputDir${random}`, | ||
OUTPUTDIR: `OUTPUTDIR.file${random}`, | ||
PUNAME: `pu-name-file${random}`, | ||
PUVSPRNAME: `puv-spr-name-file${random}`, | ||
SPECNAME: `spec-name-file${random}`, | ||
}; | ||
const testingModule = await Test.createTestingModule({ | ||
providers: [ | ||
{ | ||
provide: ioSettingsToken, | ||
useValue: ioSettings, | ||
}, | ||
{ | ||
provide: apiUrlToken, | ||
useValue: `https://api-endpoint${random}.test:3000`, | ||
}, | ||
AssetsService, | ||
], | ||
}).compile(); | ||
return { | ||
random, | ||
getAssetsService() { | ||
return testingModule.get(AssetsService); | ||
}, | ||
}; | ||
} |
45 changes: 45 additions & 0 deletions
45
api/apps/api/src/modules/scenarios/marxan-run/assets.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Assets } from '@marxan/scenario-run-queue'; | ||
import { FactoryProvider, Inject, Injectable } from '@nestjs/common'; | ||
import { AppConfig } from '@marxan-api/utils/config.utils'; | ||
import { IoSettings, ioSettingsToken } from './io-settings'; | ||
|
||
export const apiUrlToken = Symbol('api url token'); | ||
export const apiUrlProvider: FactoryProvider<string> = { | ||
provide: apiUrlToken, | ||
useFactory: () => AppConfig.get<string>('api.url'), | ||
}; | ||
|
||
@Injectable() | ||
export class AssetsService { | ||
constructor( | ||
@Inject(ioSettingsToken) | ||
private readonly settings: IoSettings, | ||
@Inject(apiUrlToken) | ||
private readonly apiUrlToken: string, | ||
) {} | ||
|
||
async forScenario(id: string): Promise<Assets> { | ||
return [ | ||
{ | ||
url: `${this.apiUrlToken}/api/v1/marxan-run/scenarios/${id}/marxan/dat/input.dat`, | ||
relativeDestination: 'input.dat', | ||
}, | ||
{ | ||
url: `${this.apiUrlToken}/api/v1/marxan-run/scenarios/${id}/marxan/dat/pu.dat`, | ||
relativeDestination: `${this.settings.INPUTDIR}/${this.settings.PUNAME}`, | ||
}, | ||
{ | ||
url: `${this.apiUrlToken}/api/v1/marxan-run/scenarios/${id}/marxan/dat/bound.dat`, | ||
relativeDestination: `${this.settings.INPUTDIR}/${this.settings.BOUNDNAME}`, | ||
}, | ||
{ | ||
url: `${this.apiUrlToken}/api/v1/marxan-run/scenarios/${id}/marxan/dat/spec.dat`, | ||
relativeDestination: `${this.settings.INPUTDIR}/${this.settings.SPECNAME}`, | ||
}, | ||
{ | ||
url: `${this.apiUrlToken}/api/v1/marxan-run/scenarios/${id}/marxan/dat/puvspr.dat`, | ||
relativeDestination: `${this.settings.INPUTDIR}/${this.settings.PUVSPRNAME}`, | ||
}, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export { | ||
RunService, | ||
notFound, | ||
NotFound, | ||
runQueueProvider, | ||
runQueueEventsProvider, | ||
} from './run.service'; | ||
export { InputParameterFileProvider } from './input-parameter-file.provider'; | ||
export { MarxanRunModule } from './marxan-run.module'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
api/apps/api/src/modules/scenarios/marxan-run/io-settings.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { AppConfig } from '@marxan-api/utils/config.utils'; | ||
import { assertDefined } from '@marxan/utils'; | ||
|
||
export const ioSettingsToken = Symbol('Marxan IO settings token'); | ||
|
||
export interface IoSettings { | ||
INPUTDIR: string; | ||
PUNAME: string; | ||
SPECNAME: string; | ||
PUVSPRNAME: string; | ||
BOUNDNAME: string; | ||
OUTPUTDIR: string; | ||
} | ||
|
||
export const ioSettingsProvider = { | ||
provide: ioSettingsToken, | ||
useFactory: () => { | ||
const config = AppConfig.get<IoSettings>( | ||
'marxan.inputFiles.inputDat.ioSettings', | ||
); | ||
assertDefined(config); | ||
return config; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
api/apps/api/src/modules/scenarios/marxan-run/marxan-run.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { MarxanRunController } from './marxan-run.controller'; | ||
import { MarxanFilesService } from './marxan-files.service'; | ||
import { | ||
runQueueEventsProvider, | ||
runQueueProvider, | ||
RunService, | ||
} from './run.service'; | ||
import { apiUrlProvider, AssetsService } from './assets.service'; | ||
import { ioSettingsProvider } from './io-settings'; | ||
import { InputParameterFileProvider } from './input-parameter-file.provider'; | ||
import { QueueModule } from '@marxan-api/modules/queue'; | ||
import { ApiEventsModule } from '@marxan-api/modules/api-events/api-events.module'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { Scenario } from '../scenario.api.entity'; | ||
import { CostSurfaceViewModule } from '../cost-surface-readmodel/cost-surface-view.module'; | ||
import { SpecDatModule } from '@marxan-api/modules/scenarios/input-files/spec.dat.module'; | ||
import { PuvsprDatModule } from '@marxan-api/modules/scenarios/input-files/puvspr.dat.module'; | ||
import { BoundDatModule } from '@marxan-api/modules/scenarios/input-files/bound.dat.module'; | ||
|
||
@Module({ | ||
imports: [ | ||
QueueModule.register(), | ||
ApiEventsModule, | ||
TypeOrmModule.forFeature([Scenario]), | ||
CostSurfaceViewModule, | ||
SpecDatModule, | ||
PuvsprDatModule, | ||
BoundDatModule, | ||
], | ||
providers: [ | ||
MarxanFilesService, | ||
runQueueProvider, | ||
runQueueEventsProvider, | ||
RunService, | ||
AssetsService, | ||
ioSettingsProvider, | ||
apiUrlProvider, | ||
InputParameterFileProvider, | ||
], | ||
controllers: [MarxanRunController], | ||
exports: [RunService, InputParameterFileProvider], | ||
}) | ||
export class MarxanRunModule {} |
Oops, something went wrong.