Skip to content

Commit

Permalink
feat: add job domain (MAPCO-2709) (#43)
Browse files Browse the repository at this point in the history
* feat: add job domain

* fix: fix cr comments

Co-authored-by: Asaf Masa <[email protected]>
  • Loading branch information
asafMasa and asafmas-rnd authored Dec 4, 2022
1 parent 454535f commit 92f6075
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 16 deletions.
1 change: 1 addition & 0 deletions config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
},
"jobManager": {
"url": "JOB_MANAGER_URL",
"jobDomain": "JOB_DOMAIN",
"expirationDays": {
"__name": "JOB_MANAGER_EXPIRATION_DAYS",
"__format": "number"
Expand Down
1 change: 1 addition & 0 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
},
"jobManager": {
"url": "http://job-manager-job-manager",
"jobDomain": "RASTER",
"expirationDays": 30
},
"rasterCatalogManager": {
Expand Down
1 change: 1 addition & 0 deletions helm/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ data:
JOB_MANAGER_URL: {{ .Values.rasterCommon.serviceUrls.jobManager | quote }}
JOB_MANAGER_EXPIRATION_DAYS: {{ .Values.env.jobManager.expirationDays | quote }}
RASTER_CATALOG_MANAGER_URL: {{ .Values.rasterCommon.serviceUrls.catalogManager | quote }}
JOB_DOMAIN: {{ .Values.rasterCommon.jobManagement.jobDomain | quote }}
WORKER_TYPES_TILES_JOB_TYPE: {{ .Values.rasterCommon.jobManagement.exporter.jobType | quote }}
WORKER_TYPES_TILES_TASK_TYPE: {{ .Values.rasterCommon.jobManagement.exporter.taskType | quote }}
HTTP_RETRY_ATTEMPTS: {{ .Values.env.httpRetry.attempts | quote }}
Expand Down
1 change: 1 addition & 0 deletions helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ rasterCommon:
jobManager: "http://job-manager-raster-dev-discrete-ingestion-db"
downloadServer: "http://files-server-raster-dev-files-server"
jobManagement:
jobDomain: RASTER
exporter:
jobType: tilesExport
taskType: tilesExport
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@map-colonies/express-access-log-middleware": "^0.0.3",
"@map-colonies/js-logger": "^0.0.3",
"@map-colonies/mc-model-types": "^13.4.2",
"@map-colonies/mc-priority-queue": "^4.0.1",
"@map-colonies/mc-priority-queue": "^4.0.2",
"@map-colonies/mc-utils": "^1.5.0",
"@map-colonies/openapi-express-viewer": "^2.0.1",
"@map-colonies/read-pkg": "0.0.1",
Expand Down
3 changes: 3 additions & 0 deletions src/clients/jobManagerWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class JobManagerWrapper extends JobManagerClient {
private readonly tilesJobType: string;
private readonly tilesTaskType: string;
private readonly expirationDays: number;
private readonly jobDomain: string;

public constructor(@inject(SERVICES.LOGGER) protected readonly logger: Logger) {
super(
Expand All @@ -45,6 +46,7 @@ export class JobManagerWrapper extends JobManagerClient {
this.expirationDays = config.get<number>('jobManager.expirationDays');
this.tilesJobType = config.get<string>('workerTypes.tiles.jobType');
this.tilesTaskType = config.get<string>('workerTypes.tiles.taskType');
this.jobDomain = config.get<string>('jobManager.jobDomain');
}

public async create(data: IWorkerInput): Promise<ICreateJobResponse> {
Expand All @@ -56,6 +58,7 @@ export class JobManagerWrapper extends JobManagerClient {
version: data.version,
type: this.tilesJobType,
expirationDate,
domain: this.jobDomain,
parameters: {
sanitizedBbox: data.sanitizedBbox,
targetResolution: data.targetResolution,
Expand Down
10 changes: 5 additions & 5 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { promises as fsPromise } from 'fs';
import { join } from 'path';
import { sep } from 'path';
import { BBox } from '@turf/turf';
import checkDiskSpace from 'check-disk-space';
import { ITileRange } from '@map-colonies/mc-utils';
Expand All @@ -22,15 +22,15 @@ export const getGpkgNameWithoutExt = (packageName: string): string => {
return gpkgNameArr.join('.');
};

export const getGpkgRelativePath = (packageName: string): string => {
export const getGpkgRelativePath = (packageName: string, separator: string = sep): string => {
const packageDirectoryName = getGpkgNameWithoutExt(packageName);
const packageRelativePath = join(packageDirectoryName, packageName);
const packageRelativePath = `${packageDirectoryName}${separator}${packageName}`;
return packageRelativePath;
};

export const getGpkgFullPath = (gpkgsLocation: string, packageName: string): string => {
export const getGpkgFullPath = (gpkgsLocation: string, packageName: string, separator: string = sep): string => {
const packageDirectoryName = getGpkgNameWithoutExt(packageName);
const packageFullPath = join(gpkgsLocation, packageDirectoryName, packageName);
const packageFullPath = `${gpkgsLocation}${separator}${packageDirectoryName}${separator}${packageName}`;
return packageFullPath;
};

Expand Down
5 changes: 3 additions & 2 deletions src/createPackage/models/createPackageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class CreatePackageManager {
}
const separator = this.getSeparator();
const packageName = generatePackageName(dbId, zoomLevel, sanitizedBbox);
const packageRelativePath = getGpkgRelativePath(packageName);
const packageRelativePath = getGpkgRelativePath(packageName, separator);
const sources: IMapSource[] = [
{
path: packageRelativePath,
Expand All @@ -111,7 +111,7 @@ export class CreatePackageManager {
},
},
{
path: (layerMetadata.id as string) + separator + (layerMetadata.displayPath as string), //tiles path
path: `${layerMetadata.id as string}${separator}${layerMetadata.displayPath as string}`, //tiles path
type: this.tilesProvider,
},
];
Expand Down Expand Up @@ -169,6 +169,7 @@ export class CreatePackageManager {
this.logger.debug(`Estimated requested gpkg size: ${estimatesGpkgSize}, Estimated free space: ${diskFreeSpace}`);
return diskFreeSpace - estimatesGpkgSize >= 0;
}

private getSeparator(): string {
return this.tilesProvider === 'S3' ? '/' : sep;
}
Expand Down
1 change: 1 addition & 0 deletions tests/mocks/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const registerDefaultConfig = (): void => {
},
jobManager: {
url: 'http://job-manager-job-manager',
jobDomain: 'testDomain',
expirationDays: 30,
},
rasterCatalogManager: {
Expand Down
2 changes: 2 additions & 0 deletions tests/mocks/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ const completedJob: IJobResponse<IJobParameters, ITaskParameters> = {
resourceId: 'string',
version: '1.0',
type: 'rasterTilesExporter',
domain: 'testDomain',
description: '',
parameters: {
crs: 'EPSG:4326',
Expand Down Expand Up @@ -173,6 +174,7 @@ const completedJob: IJobResponse<IJobParameters, ITaskParameters> = {

const inProgressJob: IJobResponse<IJobParameters, ITaskParameters> = {
id: 'fa3ab609-377a-4d96-bf0b-e0bb72f683b8',
domain: 'testDomain',
resourceId: 'string',
version: '1.0',
type: 'rasterTilesExporter',
Expand Down
1 change: 1 addition & 0 deletions tests/mocks/data/mockJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { JobResponse } from '../../../src/common/interfaces';
export const mockJob: JobResponse = {
id: 'b729f0e0-af64-4c2c-ba4e-e799e2f3df0f',
resourceId: 'test',
domain: 'testDomain',
version: '1.0',
type: 'rasterTilesExporter',
description: '',
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/createPackage/models/tasksModel.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { sep } from 'path';
import jsLogger from '@map-colonies/js-logger';
import { OperationStatus } from '@map-colonies/mc-priority-queue';
import { NotFoundError } from '@map-colonies/error-types';
Expand Down Expand Up @@ -171,7 +172,7 @@ describe('TasksManager', () => {
getFileSizeSpy.mockResolvedValue(2000);
const expirationTime = new Date();
const expectedCallbackData: ICallbackDataBase = {
fileUri: 'http://download-service/downloads/test/test.gpkg',
fileUri: `http://download-service/downloads/test${sep}test.gpkg`,
expirationTime: expirationTime,
fileSize: 2000,
dbId: '880a9316-0f10-4874-92e2-a62d587a1169',
Expand Down

0 comments on commit 92f6075

Please sign in to comment.