diff --git a/packages/backend/src/plugins/catalog.ts b/packages/backend/src/plugins/catalog.ts index 8474478f9e..57afe4fefd 100644 --- a/packages/backend/src/plugins/catalog.ts +++ b/packages/backend/src/plugins/catalog.ts @@ -14,13 +14,9 @@ * limitations under the License. */ -import { useHotCleanup } from '@backstage/backend-common'; import { CatalogBuilder, createRouter, - NextCatalogBuilder, - runPeriodically, - createNextRouter, } from '@backstage/plugin-catalog-backend'; import { Router } from 'express'; import { PluginEnvironment } from '../types'; @@ -28,36 +24,7 @@ import { PluginEnvironment } from '../types'; export default async function createPlugin( env: PluginEnvironment, ): Promise { - /* - * This environment variable exists as an emergency option during the release - * of the new catalog processing engine. - * If you experience any issues, make sure to report them as this flag - * will be removed in a subsequent release. - */ - if (process.env.LEGACY_CATALOG === '1') { - const builder = new CatalogBuilder(env); - const { - entitiesCatalog, - locationsCatalog, - higherOrderOperation, - locationAnalyzer, - } = await builder.build(); - - useHotCleanup( - module, - runPeriodically(() => higherOrderOperation.refreshAllLocations(), 100000), - ); - - return await createRouter({ - entitiesCatalog, - locationsCatalog, - higherOrderOperation, - locationAnalyzer, - logger: env.logger, - config: env.config, - }); - } - const builder = new NextCatalogBuilder(env); + const builder = await CatalogBuilder.create(env); const { entitiesCatalog, locationAnalyzer, @@ -65,10 +32,9 @@ export default async function createPlugin( locationService, } = await builder.build(); - // TODO(jhaals): run and manage in background. await processingEngine.start(); - return await createNextRouter({ + return await createRouter({ entitiesCatalog, locationAnalyzer, locationService, diff --git a/plugins/catalog-backend/src/service/CatalogBuilder.ts b/plugins/catalog-backend/src/service/CatalogBuilder.ts index f742e3c0db..9bec4442d7 100644 --- a/plugins/catalog-backend/src/service/CatalogBuilder.ts +++ b/plugins/catalog-backend/src/service/CatalogBuilder.ts @@ -66,6 +66,7 @@ import { } from '../ingestion/processors/PlaceholderProcessor'; import { defaultEntityDataParser } from '../ingestion/processors/util/parse'; import { LocationAnalyzer } from '../ingestion/types'; +import { NextCatalogBuilder } from '../next'; export type CatalogEnvironment = { logger: Logger; @@ -103,6 +104,10 @@ export class CatalogBuilder { private processorsReplace: boolean; private parser: CatalogProcessorParser | undefined; + static async create(env: CatalogEnvironment): Promise { + return new NextCatalogBuilder(env); + } + constructor(env: CatalogEnvironment) { this.env = env; this.entityPolicies = []; @@ -112,6 +117,10 @@ export class CatalogBuilder { this.processors = []; this.processorsReplace = false; this.parser = undefined; + + env.logger.warn( + "Creating the catalog with 'new CatalogBuilder(env)' is deprecated! Use CatalogBuilder.create(env) instead", + ); } /** diff --git a/plugins/catalog-backend/src/service/router.ts b/plugins/catalog-backend/src/service/router.ts index ae58255a4e..525ba76c0c 100644 --- a/plugins/catalog-backend/src/service/router.ts +++ b/plugins/catalog-backend/src/service/router.ts @@ -28,6 +28,7 @@ import { Logger } from 'winston'; import yn from 'yn'; import { EntitiesCatalog, LocationsCatalog } from '../catalog'; import { HigherOrderOperation, LocationAnalyzer } from '../ingestion/types'; +import { LocationService } from '../next/types'; import { basicEntityFilter, parseEntityFilterParams, @@ -45,6 +46,7 @@ export interface RouterOptions { locationsCatalog?: LocationsCatalog; higherOrderOperation?: HigherOrderOperation; locationAnalyzer?: LocationAnalyzer; + locationService?: LocationService; logger: Logger; config: Config; } @@ -57,6 +59,7 @@ export async function createRouter( locationsCatalog, higherOrderOperation, locationAnalyzer, + locationService, config, logger, } = options; @@ -145,6 +148,40 @@ export async function createRouter( }); } + if (locationService) { + router + .post('/locations', async (req, res) => { + const input = await validateRequestBody(req, locationSpecSchema); + const dryRun = yn(req.query.dryRun, { default: false }); + + // when in dryRun addLocation is effectively a read operation so we don't + // need to disallow readonly + if (!dryRun) { + disallowReadonlyMode(readonlyEnabled); + } + + const output = await locationService.createLocation(input, dryRun); + res.status(201).json(output); + }) + .get('/locations', async (_req, res) => { + const locations = await locationService.listLocations(); + res.status(200).json(locations.map(l => ({ data: l }))); + }) + + .get('/locations/:id', async (req, res) => { + const { id } = req.params; + const output = await locationService.getLocation(id); + res.status(200).json(output); + }) + .delete('/locations/:id', async (req, res) => { + disallowReadonlyMode(readonlyEnabled); + + const { id } = req.params; + await locationService.deleteLocation(id); + res.status(204).end(); + }); + } + if (higherOrderOperation) { router.post('/locations', async (req, res) => { const input = await validateRequestBody(req, locationSpecSchema);