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 4 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
6 changes: 1 addition & 5 deletions src/clients/jobManagerWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { Tracer } from '@opentelemetry/api';
import { SERVICES } from '../common/constants';
import {
CreateExportJobBody,
ExportVersion,
ICreateExportJobResponse,
IJobExportParameters,
ITaskParameters,
Expand Down Expand Up @@ -55,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 @@ -175,9 +173,7 @@ export class JobManagerWrapper extends JobManagerClient {
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 job;
});
return exportJobs;
}
Expand Down
67 changes: 8 additions & 59 deletions src/common/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MultiPolygon, Polygon, BBox, FeatureCollection, Geometry } from '@turf/turf';
import { BBox, FeatureCollection, Geometry } from '@turf/turf';
import { ICreateJobBody, ICreateTaskBody, IJobResponse, ITaskResponse, OperationStatus } from '@map-colonies/mc-priority-queue';
import { IHttpRetryConfig, ITileRange } from '@map-colonies/mc-utils';
import { TileOutputFormat } from '@map-colonies/mc-model-types';
Expand All @@ -16,41 +16,28 @@ export interface OpenApiConfig {
uiPath: string;
}

export interface IBaseCreatePackage {
dbId: string;
crs?: string;
priority?: number;
}

export interface ICleanupData {
directoryPath?: string;
cleanupExpirationTimeUTC?: Date;
}

export interface ICreatePackage extends IBaseCreatePackage {
targetResolution?: number;
bbox?: BBox | Polygon | MultiPolygon;
callbackURLs: string[];
}

export interface ICreatePackageRoi extends IBaseCreatePackage {
export interface ICreatePackageRoi {
dbId: string;
crs?: string;
priority?: number;
roi?: FeatureCollection;
callbackURLs?: string[];
description?: string;
}

export interface ICallbackBase {
export interface ICallbackTargetExport {
url: string;
}

export interface ICallbackTargetExport extends ICallbackBase {
roi: FeatureCollection;
}

export interface IWorkerInputBase {
export interface IWorkerExportInput {
dbId: string;
relativeDirectoryPath: string;
exportVersion: ExportVersion;
priority?: number;
crs: string;
version: string;
Expand All @@ -60,9 +47,6 @@ export interface IWorkerInputBase {
sources: IMapSource[];
gpkgEstimatedSize?: number;
targetFormat?: TileOutputFormat;
}

export interface IWorkerExportInput extends IWorkerInputBase {
callbacks?: ICallbackTargetExport[];
roi: FeatureCollection;
fileNamesTemplates: ILinkDefinition;
Expand All @@ -80,7 +64,7 @@ export interface ICreateExportJobResponse {
isDuplicated?: boolean;
}

export interface ICallbackDataExportBase {
export interface ICallbackExportData {
links?: ILinkDefinition;
expirationTime?: Date;
fileSize?: number;
Expand All @@ -89,9 +73,6 @@ export interface ICallbackDataExportBase {
errorReason?: string;
description?: string;
artifacts?: IArtifactDefinition[];
}

export interface ICallbackExportData extends ICallbackDataExportBase {
roi: FeatureCollection;
}

Expand Down Expand Up @@ -123,22 +104,9 @@ export interface JobExportDuplicationParams {
roi: FeatureCollection;
}

export interface IJobParameters {
targetResolution: number;
relativeDirectoryPath: string;
crs: string;
exportVersion: ExportVersion;
sanitizedBbox: BBox;
zoomLevel: number;
fileName: string;
gpkgEstimatedSize?: number;
cleanupData?: ICleanupData;
}

export interface IJobExportParameters {
relativeDirectoryPath: string;
crs: string;
exportVersion: ExportVersion;
roi: FeatureCollection;
callbacks?: ICallbackTargetExport[];
callbackParams?: ICallbackExportResponse;
Expand Down Expand Up @@ -171,19 +139,6 @@ export interface ITaskParameters {
sources: IMapSource[];
}

/**
* @deprecated GetMap API - will be deprecated on future
*/
export interface IInput {
jobId: string;
footprint?: Polygon | MultiPolygon;
bbox: BBox | true;
zoomLevel: number;
packageName: string;
callbackURLs: string[];
dbId: string;
}

export interface IExportJobStatusResponse {
completedJobs: JobExportResponse[] | undefined;
failedJobs: JobExportResponse[] | undefined;
Expand Down Expand Up @@ -214,12 +169,6 @@ export interface IGeometryRecord extends IGeometryRecordBase {
minZoomLevel: number;
}

// todo - Temporary enum to define old\new api - will be removed after deleting getMap API
export enum ExportVersion {
GETMAP = 'GETMAP',
ROI = 'ROI',
}

export type TaskResponse = ITaskResponse<ITaskParameters>;

// new API based on multi resolution
Expand Down
48 changes: 46 additions & 2 deletions src/createPackage/models/createPackageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { sep } from 'path';
import { Logger } from '@map-colonies/js-logger';
import { Tracer } from '@opentelemetry/api';
import { withSpanAsyncV4 } from '@map-colonies/telemetry';
// import { TileRanger } from '@map-colonies/mc-utils';
asafMasa marked this conversation as resolved.
Show resolved Hide resolved
import {
Polygon,
MultiPolygon,
Expand All @@ -22,7 +23,6 @@ import { BBox2d } from '@turf/helpers/dist/js/lib/geojson';
import { ProductType, TileOutputFormat } from '@map-colonies/mc-model-types';
import { feature, featureCollection } from '@turf/helpers';
import {
ExportVersion,
ICallbackExportResponse,
ICallbackTargetExport,
IConfig,
Expand Down Expand Up @@ -220,7 +220,6 @@ export class CreatePackageManager {
fileNamesTemplates: fileNamesTemplates,
relativeDirectoryPath: additionalIdentifiers,
dbId,
exportVersion: ExportVersion.ROI,
version: version,
cswProductId: resourceId,
crs: crs ?? DEFAULT_CRS,
Expand Down Expand Up @@ -462,4 +461,49 @@ export class CreatePackageManager {
}
return combinedFootprint;
}

// TODO: remove and replace with generateTileGroups that is commented, when multiple tasks for GPKG target is possible
/* private generateTileGroups(polygon: Polygon | MultiPolygon, footprint: Polygon | MultiPolygon, zoom: number): ITileRange[] {
let intersaction: Feature<Polygon | MultiPolygon> | null;

try {
intersaction = intersect(polygon, footprint);
if (intersaction === null) {
throw new BadRequestError(
`Requested ${JSON.stringify(polygon)} has no intersection with requested layer footprint: ${JSON.stringify(footprint)}`
);
}
} catch (error) {
const message = `Error occurred while trying to generate tiles batches - intersaction error: ${JSON.stringify(error)}`;
this.logger.error({
firstPolygon: polygon,
secondPolygon: footprint,
zoom: zoom,
message: message,
});
throw new Error(message);
}

try {
const tileRanger = new TileRanger();
const tilesGroups: ITileRange[] = [];

for (let i = 0; i <= zoom; i++) {
const zoomTilesGroups = tileRanger.encodeFootprint(intersaction, i);
for (const group of zoomTilesGroups) {
tilesGroups.push(group);
}
}
return tilesGroups;
} catch (error) {
const message = `Error occurred while trying to generate tiles batches - encodeFootprint error: ${JSON.stringify(error)}`;
this.logger.error({
firstPolygon: polygon,
secondPolygon: footprint,
zoom: zoom,
message: message,
});
throw new Error(message);
}
} */
}
18 changes: 4 additions & 14 deletions src/finalizationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@ import { withSpanAsyncV4 } from '@map-colonies/telemetry';
import { SERVICES } from './common/constants';
import { TasksManager } from './tasks/models/tasksManager';
import { QueueClient } from './clients/queueClient';
import {
ICallbackDataExportBase,
ICallbackExportData,
ICallbackExportResponse,
ITaskFinalizeParameters,
JobExportResponse,
JobFinalizeResponse,
} from './common/interfaces';
import { ICallbackExportData, ICallbackExportResponse, ITaskFinalizeParameters, JobExportResponse, JobFinalizeResponse } from './common/interfaces';
import { JobManagerWrapper } from './clients/jobManagerWrapper';
import { CallbackClient } from './clients/callbackClient';

Expand Down Expand Up @@ -119,10 +112,7 @@ export class FinalizationManager {
return true;
}

public async sendExportCallbacks(
job: JobExportResponse | JobFinalizeResponse,
callbackParams: ICallbackDataExportBase | ICallbackExportResponse
): Promise<void> {
public async sendExportCallbacks(job: JobExportResponse | JobFinalizeResponse, callbackParams: ICallbackExportResponse): Promise<void> {
try {
this.logger.info({ jobId: job.id, callbacks: job.parameters.callbacks, msg: `Sending callback for job: ${job.id}` });
const targetCallbacks = job.parameters.callbacks;
Expand Down Expand Up @@ -156,11 +146,11 @@ export class FinalizationManager {
}

public async jobStatusPoll(): Promise<boolean> {
const roiExistsJobs = await this.handleROIJobs();
const roiExistsJobs = await this.handleExportJobs();
return roiExistsJobs;
}

private async handleROIJobs(): Promise<boolean> {
private async handleExportJobs(): Promise<boolean> {
let existsJobs = false;
const roiJobs = await this.taskManager.getExportJobsByTaskStatus(); // new api by roi,
this.logger.debug({ ...roiJobs, msg: `Handling ROI jobs` });
Expand Down
14 changes: 7 additions & 7 deletions src/tasks/models/tasksManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { JobManagerWrapper } from '../../clients/jobManagerWrapper';
import {
CreateFinalizeTaskBody,
IArtifactDefinition,
ICallbackDataExportBase,
ICallbackExportData,
ICallbackExportResponse,
ICleanupData,
Expand Down Expand Up @@ -109,10 +108,7 @@ export class TasksManager {
return jobsStatus;
}

public async sendExportCallbacks(
job: JobExportResponse | JobFinalizeResponse,
callbackParams: ICallbackDataExportBase | ICallbackExportResponse
): Promise<void> {
public async sendExportCallbacks(job: JobExportResponse | JobFinalizeResponse, callbackParams: ICallbackExportData): Promise<void> {
try {
this.logger.info({ jobId: job.id, callbacks: job.parameters.callbacks, msg: `Sending callback for job: ${job.id}` });
const targetCallbacks = job.parameters.callbacks;
Expand Down Expand Up @@ -216,7 +212,7 @@ export class TasksManager {
job: JobExportResponse | JobFinalizeResponse,
expirationDate: Date,
errorReason?: string
): Promise<ICallbackDataExportBase> {
): Promise<ICallbackExportData> {
let links: ILinkDefinition = { ...job.parameters.fileNamesTemplates }; // default file names in case of failure
this.logger.info({ jobId: job.id, msg: `generate callback body for job: ${job.id}` });

Expand Down Expand Up @@ -263,7 +259,7 @@ export class TasksManager {
},
];

const callbackParams: ICallbackDataExportBase = {
const callbackParams: ICallbackExportData = {
links,
expirationTime: expirationDate,
fileSize,
Expand All @@ -272,6 +268,10 @@ export class TasksManager {
errorReason,
description: job.description,
artifacts,
roi: {
type: 'FeatureCollection',
features: [],
},
};
this.logger.info({
links: callbackParams.links,
Expand Down
9 changes: 2 additions & 7 deletions tests/mocks/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { LayerMetadata, ProductType, RecordType, TileOutputFormat } from '@map-colonies/mc-model-types';
import { IJobResponse, OperationStatus } from '@map-colonies/mc-priority-queue';
import { FeatureCollection } from '@turf/helpers';
import { ExportVersion, ICreatePackage, IJobExportParameters, ITaskParameters, IWorkerExportInput } from '../../src/common/interfaces';
import { ICreatePackageRoi, IJobExportParameters, ITaskParameters, IWorkerExportInput } from '../../src/common/interfaces';

const layerMetadata: LayerMetadata = {
type: 'RECORD_RASTER',
Expand Down Expand Up @@ -193,11 +193,9 @@ const layerFromCatalogSample = {
metadata: layerMetadataSample,
};

const userInput: ICreatePackage = {
const userInput: ICreatePackageRoi = {
dbId: '0c3e455f-4aeb-4258-982d-f7773469a92d',
targetResolution: 0.00439453125,
callbackURLs: ['http://callback-url.com'],
bbox: [-5, 3, 25, 41],
crs: 'EPSG:4326',
};

Expand Down Expand Up @@ -413,7 +411,6 @@ const workerExportInput: IWorkerExportInput = {
},
relativeDirectoryPath: '1a26c1661df10eee54f9727fcdb8b71d',
dbId: '0c3e455f-4aeb-4258-982d-f7773469a92d',
exportVersion: ExportVersion.ROI,
version: '1.0',
cswProductId: 'string',
crs: 'EPSG:4326',
Expand Down Expand Up @@ -501,7 +498,6 @@ const completedExportJob: IJobResponse<IJobExportParameters, ITaskParameters> =
roi: fc1,
},
],
exportVersion: ExportVersion.ROI,
callbackParams: {
roi: fc1,
links: {
Expand Down Expand Up @@ -578,7 +574,6 @@ const inProgressExportJob: IJobResponse<IJobExportParameters, ITaskParameters> =
crs: 'EPSG:4326',
roi: fc1,
callbacks: [{ url: 'http://localhost:6969', roi: fc1 }],
exportVersion: ExportVersion.ROI,
gpkgEstimatedSize: 187500,
fileNamesTemplates: {
dataURI: 'Orthophoto_testArea_1_0_2023_03_01T15_09_50_924Z.gpkg',
Expand Down
3 changes: 1 addition & 2 deletions tests/mocks/data/mockJob.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-magic-numbers */
import { OperationStatus } from '@map-colonies/mc-priority-queue';
import { ExportVersion, JobFinalizeResponse } from '../../../src/common/interfaces';
import { JobFinalizeResponse } from '../../../src/common/interfaces';
import { fc1 } from '../data';

export const mockCompletedJob: JobFinalizeResponse = {
Expand All @@ -23,7 +23,6 @@ export const mockCompletedJob: JobFinalizeResponse = {
roi: fc1,
},
],
exportVersion: ExportVersion.ROI,
gpkgEstimatedSize: 187500,
fileNamesTemplates: {
dataURI: 'Orthophoto_testArea_1_0_2023_02_28T15_09_50_924Z.gpkg',
Expand Down
Loading
Loading