Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Remove deprecation (MAPCO-4117) #90

Merged
merged 21 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 0 additions & 95 deletions openapi3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,50 +26,6 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/internalError'
/create:
post:
tags:
- createGpkg
summary: Trigger export geopackage process
operationId: exportTilesToGpkg
deprecated: true
requestBody:
$ref: '#/components/requestBodies/ExportGetmapBody'
responses:
'200':
description: OK
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/createGpkgJobResponse'
- $ref: '#/components/schemas/naiveCacheJobResponse'
discriminator:
propertyName: response
'400':
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/error'
'404':
description: Could not find layer with matched dbId
content:
application/json:
schema:
$ref: '#/components/schemas/error'
'500':
description: Internal Server Error
content:
application/json:
schema:
$ref: '#/components/schemas/internalError'
'507':
description: Insufficient Storage on disk for exporting
content:
application/json:
schema:
$ref: '#/components/schemas/error'
/create/roi:
post:
tags:
Expand Down Expand Up @@ -155,13 +111,6 @@ paths:
$ref: '#/components/schemas/internalError'
components:
requestBodies:
ExportGetmapBody:
description: Export to gpkg via GetMap
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/exportGetMap'
ExportByRoiBody:
description: Export to gpkg via FeatureCollection
required: true
Expand Down Expand Up @@ -193,50 +142,6 @@ components:
- Completed
discriminator:
propertyName: response
exportGetMap:
type: object
properties:
dbId:
type: string
format: uuid
description: ID as the primary key from the Raster Catalog
bbox:
oneOf:
- $ref: '#/components/schemas/BBox'
- $ref: '#/components/schemas/Geometry'
targetResolution:
type: number
description: >-
The target resolution in which the tiles will be created - DEGREE to
PIXEL. If empty - original layer's resolution is taken.
callbackURLs:
type: array
items:
type: string
description: The callback URL to notify the process if finished
crs:
$ref: '#/components/schemas/CRS'
priority:
type: number
description: The priority of the record. Maximum priority = most urgent.
minimum: 0
maximum: 999999999
required:
- dbId
- callbackURLs
example:
dbId: ef03ca54-c68e-4ca8-8432-50ae5ad7a7f8
bbox:
- 34.811938017107494
- 31.95475033759175
- 34.82237261707599
- 31.96426962177354
targetResolution: 0.0000429153442382812
callbackURLs:
- http://example.getmap.com/callback
- http://example.getmap.com/callback2
crs: EPSG:4326
priority: 0
exportFromFeatures:
type: object
properties:
Expand Down
4 changes: 2 additions & 2 deletions src/clients/callbackClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { inject, singleton } from 'tsyringe';
import { HttpClient, IHttpRetryConfig } from '@map-colonies/mc-utils';
import { Logger } from '@map-colonies/js-logger';
import { SERVICES } from '../common/constants';
import { ICallbackData, ICallbackExportData, IConfig } from '../common/interfaces';
import { ICallbackExportData, IConfig } from '../common/interfaces';

@singleton()
export class CallbackClient extends HttpClient {
Expand All @@ -16,7 +16,7 @@ export class CallbackClient extends HttpClient {
);
}

public async send(callbackUrl: string, data: ICallbackData | ICallbackExportData): Promise<void> {
public async send(callbackUrl: string, data: ICallbackExportData): Promise<void> {
this.logger.info({ data, msg: `Sending callback request to URL: "${callbackUrl}"` });
await this.post(callbackUrl, data);
}
Expand Down
168 changes: 5 additions & 163 deletions src/clients/jobManagerWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
import { inject, injectable } from 'tsyringe';
import config from 'config';
import { Logger } from '@map-colonies/js-logger';
import booleanEqual from '@turf/boolean-equal';
import bboxPolygon from '@turf/bbox-polygon';
import { IFindJobsRequest, JobManagerClient, OperationStatus } from '@map-colonies/mc-priority-queue';
import { featureCollectionBooleanEqual, getUTCDate, IHttpRetryConfig } from '@map-colonies/mc-utils';
import { withSpanAsyncV4 } from '@map-colonies/telemetry';
import { Tracer } from '@opentelemetry/api';
import { SERVICES } from '../common/constants';
import {
CreateExportJobBody,
CreateJobBody,
ExportVersion,
ICreateJobResponse,
ICreateExportJobResponse,
IJobExportParameters,
IJobParameters,
ITaskParameters,
IWorkerExportInput,
IWorkerInput,
JobDuplicationParams,
JobExportDuplicationParams,
JobExportResponse,
JobResponse,
TaskResponse,
} from '../common/interfaces';

Expand Down Expand Up @@ -63,7 +54,6 @@ export class JobManagerWrapper extends JobManagerClient {
roi: data.roi,
callbacks: data.callbacks,
crs: data.crs,
exportVersion: ExportVersion.ROI,
fileNamesTemplates: data.fileNamesTemplates,
relativeDirectoryPath: data.relativeDirectoryPath,
gpkgEstimatedSize: data.gpkgEstimatedSize,
Expand Down Expand Up @@ -103,77 +93,6 @@ export class JobManagerWrapper extends JobManagerClient {
return createJobResponse;
}

/**
* @deprecated The method should not be used
*/
public async create(data: IWorkerInput): Promise<ICreateJobResponse> {
const expirationDate = new Date();
expirationDate.setDate(expirationDate.getDate() + this.expirationDays);

const createJobRequest: CreateJobBody = {
resourceId: data.cswProductId,
version: data.version,
type: this.tilesJobType,
domain: this.jobDomain,
parameters: {
sanitizedBbox: data.sanitizedBbox,
targetResolution: data.targetResolution,
exportVersion: ExportVersion.GETMAP,
zoomLevel: data.zoomLevel,
callbacks: data.callbacks,
crs: data.crs,
fileName: data.fileName,
relativeDirectoryPath: data.relativeDirectoryPath,
gpkgEstimatedSize: data.gpkgEstimatedSize,
},
internalId: data.dbId,
productType: data.productType,
productName: data.cswProductId,
priority: data.priority,
status: OperationStatus.IN_PROGRESS,
additionalIdentifiers: data.sanitizedBbox.toString() + String(data.zoomLevel),
tasks: [
{
type: this.tilesTaskType,
parameters: {
isNewTarget: true,
targetFormat: data.targetFormat,
batches: data.batches,
sources: data.sources,
},
},
],
};

const res = await this.createJob<IJobParameters, ITaskParameters>(createJobRequest);
return {
id: res.id,
taskIds: res.taskIds,
status: OperationStatus.IN_PROGRESS,
};
}

/**
* @deprecated The method should not be used
*/
public async findCompletedJob(jobParams: JobDuplicationParams): Promise<JobResponse | undefined> {
const queryParams: IFindJobsRequest = {
resourceId: jobParams.resourceId,
version: jobParams.version,
isCleaned: false,
type: this.tilesJobType,
shouldReturnTasks: false,
status: OperationStatus.COMPLETED,
};
const jobs = await this.getGetMapJobs(queryParams);
if (jobs) {
const matchingJob = this.findJobWithMatchingParams(jobs, jobParams);
return matchingJob;
}

return undefined;
}

public async findExportJob(
status: OperationStatus,
jobParams: JobExportDuplicationParams,
Expand All @@ -196,61 +115,14 @@ export class JobManagerWrapper extends JobManagerClient {
return undefined;
}

/**
* @deprecated The method should not be used
*/
public async findInProgressJob(jobParams: JobDuplicationParams): Promise<JobResponse | undefined> {
const queryParams: IFindJobsRequest = {
resourceId: jobParams.resourceId,
version: jobParams.version,
isCleaned: false,
type: this.tilesJobType,
shouldReturnTasks: true,
status: OperationStatus.IN_PROGRESS,
};

const jobs = await this.getGetMapJobs(queryParams);
if (jobs) {
const matchingJob = this.findJobWithMatchingParams(jobs, jobParams);
return matchingJob;
}

return undefined;
}

/**
* @deprecated The method should not be used
*/
public async findPendingJob(jobParams: JobDuplicationParams): Promise<JobResponse | undefined> {
const queryParams: IFindJobsRequest = {
resourceId: jobParams.resourceId,
version: jobParams.version,
isCleaned: false,
type: this.tilesJobType,
shouldReturnTasks: true,
status: OperationStatus.PENDING,
};

const jobs = await this.getGetMapJobs(queryParams);
if (jobs) {
const matchingJob = this.findJobWithMatchingParams(jobs, jobParams);
return matchingJob;
}

return undefined;
}

/**
* @deprecated GetMap API - will be deprecated on future
*/
public async getInProgressJobs(shouldReturnTasks = false): Promise<JobResponse[] | undefined> {
public async getInProgressJobs(shouldReturnTasks = false): Promise<JobExportResponse[] | undefined> {
const queryParams: IFindJobsRequest = {
isCleaned: false,
type: this.tilesJobType,
shouldReturnTasks,
status: OperationStatus.IN_PROGRESS,
};
const jobs = await this.getGetMapJobs(queryParams);
const jobs = await this.getExportJobs(queryParams);
return jobs;
}

Expand All @@ -272,7 +144,7 @@ export class JobManagerWrapper extends JobManagerClient {
const getOrUpdateURL = `/jobs/${jobId}`;
const newExpirationDate = getUTCDate();
newExpirationDate.setDate(newExpirationDate.getDate() + this.expirationDays);
const job = await this.get<JobResponse | JobExportResponse>(getOrUpdateURL);
const job = await this.get<JobExportResponse>(getOrUpdateURL);
const oldExpirationDate = new Date(job.parameters.cleanupData?.cleanupExpirationTimeUTC as Date);
if (oldExpirationDate < newExpirationDate) {
this.logger.info({ jobId, oldExpirationDate, newExpirationDate, msg: 'update expirationDate' });
Expand All @@ -296,46 +168,16 @@ export class JobManagerWrapper extends JobManagerClient {
}
}

//TODO: once will be only one kind of exported jobs, no need to filter by ROI's
asafMasa marked this conversation as resolved.
Show resolved Hide resolved
public async getExportJobs(queryParams: IFindJobsRequest): Promise<JobExportResponse[] | undefined> {
this.logger.debug({ ...queryParams }, `Getting jobs that match these parameters`);
const jobs = await this.get<JobExportResponse[] | undefined>('/jobs', queryParams as unknown as Record<string, unknown>);
const exportJobs = jobs?.filter((job) => {
if (job.parameters.exportVersion === ExportVersion.ROI) {
return job;
}
});
return exportJobs;
}

/**
* @deprecated GetMap API - will be deprecated on future
*/
private async getGetMapJobs(queryParams: IFindJobsRequest): Promise<JobResponse[] | undefined> {
this.logger.debug({ ...queryParams }, `Getting jobs that match these parameters`);
const jobs = await this.get<JobResponse[] | undefined>('/jobs', queryParams as unknown as Record<string, unknown>);
const exportJobs = jobs?.filter((job) => {
if (job.parameters.exportVersion === ExportVersion.GETMAP) {
return job;
}
return job;
});
return exportJobs;
}

/**
* @deprecated GetMap API - will be deprecated on future
*/
private findJobWithMatchingParams(jobs: JobResponse[], jobParams: JobDuplicationParams): JobResponse | undefined {
const matchingJob = jobs.find(
(job) =>
job.internalId === jobParams.dbId &&
job.version === jobParams.version &&
job.parameters.zoomLevel === jobParams.zoomLevel &&
job.parameters.crs === jobParams.crs &&
booleanEqual(bboxPolygon(job.parameters.sanitizedBbox), bboxPolygon(jobParams.sanitizedBbox))
);
return matchingJob;
}

private findExportJobWithMatchingParams(jobs: JobExportResponse[], jobParams: JobExportDuplicationParams): JobExportResponse | undefined {
const matchingJob = jobs.find(
(job) =>
Expand Down
Loading
Loading