Merge pull request #5517 from backstage/freben/more-catalog-refactor

Minor catalog cleanups continue
This commit is contained in:
Fredrik Adelöw
2021-04-29 11:31:19 +02:00
committed by GitHub
10 changed files with 34 additions and 40 deletions
@@ -14,13 +14,13 @@
* limitations under the License.
*/
import { ConfigLocationProvider } from './ConfigLocationProvider';
import { EntityProviderConnection } from './types';
import { ConfigReader } from '@backstage/config';
import { resolvePackagePath } from '@backstage/backend-common';
import { ConfigReader } from '@backstage/config';
import path from 'path';
import { ConfigLocationEntityProvider } from './ConfigLocationEntityProvider';
import { EntityProviderConnection } from './types';
describe('Config Location Provider', () => {
describe('ConfigLocationEntityProvider', () => {
it('should apply mutation with the correct paths in the config', async () => {
const mockConfig = new ConfigReader({
catalog: {
@@ -34,7 +34,7 @@ describe('Config Location Provider', () => {
const mockConnection = ({
applyMutation: jest.fn(),
} as unknown) as EntityProviderConnection;
const locationProvider = new ConfigLocationProvider(mockConfig);
const locationProvider = new ConfigLocationEntityProvider(mockConfig);
await locationProvider.connect(mockConnection);
@@ -14,12 +14,12 @@
* limitations under the License.
*/
import { EntityProviderConnection, EntityProvider } from './types';
import path from 'path';
import { Config } from '@backstage/config';
import path from 'path';
import { EntityProvider, EntityProviderConnection } from './types';
import { locationSpecToLocationEntity } from './util';
export class ConfigLocationProvider implements EntityProvider {
export class ConfigLocationEntityProvider implements EntityProvider {
private connection: EntityProviderConnection | undefined;
constructor(private readonly config: Config) {}
@@ -14,19 +14,18 @@
* limitations under the License.
*/
import { stringifyEntityRef } from '@backstage/catalog-model';
import { Logger } from 'winston';
import { Stitcher } from './Stitcher';
import {
CatalogProcessingEngine,
CatalogProcessingOrchestrator,
EntityProvider,
EntityProviderConnection,
EntityProviderMutation,
ProcessingStateManager,
CatalogProcessingOrchestrator,
} from './types';
import { Logger } from 'winston';
import { stringifyEntityRef } from '@backstage/catalog-model';
import { Stitcher } from './Stitcher';
class Connection implements EntityProviderConnection {
constructor(
private readonly config: {
@@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { v4 as uuid } from 'uuid';
import { DatabaseManager } from './database/DatabaseManager';
import { DefaultLocationStore } from './DefaultLocationStore';
import { v4 } from 'uuid';
/* eslint-disable */
xdescribe('Default Location Store', () => {
xdescribe('DefaultLocationStore', () => {
const createLocationStore = async () => {
const db = await DatabaseManager.createTestDatabase();
const connection = { applyMutation: jest.fn() };
@@ -111,7 +111,7 @@ xdescribe('Default Location Store', () => {
it('throws if the location does not exist', async () => {
const { store } = await createLocationStore();
const id = v4();
const id = uuid();
await expect(() => store.deleteLocation(id)).rejects.toThrow(
new RegExp(`Found no location with ID ${id}`),
@@ -21,7 +21,7 @@ import {
EntityProvider,
EntityProviderConnection,
} from './types';
import { v4 as uuidv4 } from 'uuid';
import { v4 as uuid } from 'uuid';
import { locationSpecToLocationEntity } from './util';
import { ConflictError } from '@backstage/errors';
@@ -50,7 +50,7 @@ export class DefaultLocationStore implements LocationStore, EntityProvider {
// TODO: id should really be type and target combined and not a uuid.
const location = await this.db.addLocation(tx, {
id: uuidv4(),
id: uuid(),
type: spec.type,
target: spec.target,
});
@@ -19,7 +19,6 @@ import {
resolvePackagePath,
UrlReader,
} from '@backstage/backend-common';
import fs from 'fs-extra';
import {
DefaultNamespaceEntityPolicy,
EntityPolicies,
@@ -39,6 +38,7 @@ import {
EntitiesCatalog,
LocationsCatalog,
} from '../catalog';
import { CommonDatabase } from '../database/CommonDatabase';
import {
AnnotateLocationEntityProcessor,
BitbucketDiscoveryProcessor,
@@ -63,16 +63,15 @@ import {
} from '../ingestion/processors/PlaceholderProcessor';
import { defaultEntityDataParser } from '../ingestion/processors/util/parse';
import { LocationAnalyzer } from '../ingestion/types';
import { CatalogProcessingEngine } from '../next/types';
import { ConfigLocationEntityProvider } from './ConfigLocationEntityProvider';
import { DefaultProcessingDatabase } from './database/DefaultProcessingDatabase';
import { DefaultCatalogProcessingEngine } from './DefaultCatalogProcessingEngine';
import { DefaultCatalogProcessingOrchestrator } from './DefaultCatalogProcessingOrchestrator';
import { DefaultProcessingDatabase } from './database/DefaultProcessingDatabase';
import { DefaultLocationStore } from './DefaultLocationStore';
import { DefaultProcessingStateManager } from './DefaultProcessingStateManager';
import { CatalogProcessingEngine } from '../next/types';
import { NextEntitiesCatalog } from './NextEntitiesCatalog';
import { Stitcher } from './Stitcher';
import { CommonDatabase } from '../database/CommonDatabase';
import { ConfigLocationProvider } from './ConfigLocationProvider';
export type CatalogEnvironment = {
logger: Logger;
@@ -243,19 +242,13 @@ export class NextCatalogBuilder {
const parser = this.parser || defaultEntityDataParser;
const dbClient = await database.getClient();
const allMigrations = resolvePackagePath(
'@backstage/plugin-catalog-backend',
'migrations',
);
const migrationsDir = resolvePackagePath(
'@backstage/plugin-catalog-backend',
'migrationsv2',
);
await fs.copy(allMigrations, migrationsDir);
await dbClient.migrate.latest({
directory: migrationsDir,
directory: resolvePackagePath(
'@backstage/plugin-catalog-backend',
'migrationsv2',
),
});
const db = new CommonDatabase(dbClient, logger);
const processingDatabase = new DefaultProcessingDatabase(dbClient, logger);
@@ -272,7 +265,7 @@ export class NextCatalogBuilder {
const locationStore = new DefaultLocationStore(db);
const stitcher = new Stitcher(dbClient, logger);
const configLocationProvider = new ConfigLocationProvider(config);
const configLocationProvider = new ConfigLocationEntityProvider(config);
const processingEngine = new DefaultCatalogProcessingEngine(
logger,
[locationStore, configLocationProvider],
@@ -16,7 +16,7 @@
import { getVoidLogger, resolvePackagePath } from '@backstage/backend-common';
import knexFactory, { Knex } from 'knex';
import { v4 as uuidv4 } from 'uuid';
import { v4 as uuid } from 'uuid';
import { Logger } from 'winston';
import { CommonDatabase } from '../../database/CommonDatabase';
import { Database } from '../../database/types';
@@ -79,7 +79,7 @@ export class DatabaseManager {
let knex = knexFactory(config);
if (typeof config.connection !== 'string') {
const tempDbName = `d${uuidv4().replace(/-/g, '')}`;
const tempDbName = `d${uuid().replace(/-/g, '')}`;
await knex.raw(`CREATE DATABASE ${tempDbName};`);
knex = knexFactory({
...config,
@@ -52,8 +52,9 @@ describe('search', () => {
it('skips over special keys', () => {
const input = {
state: { x: 1 },
relations: [{ y: 2 }],
status: { x: 1 },
attachments: [{ y: 2 }],
relations: [{ z: 3 }],
a: 'a',
metadata: {
b: 'b',
+2 -1
View File
@@ -30,8 +30,9 @@ export type DbSearchRow = {
// to index, or because they are special-case always inserted whether they are
// null or not
const SPECIAL_KEYS = [
'state',
'attachments',
'relations',
'status',
'metadata.name',
'metadata.namespace',
'metadata.uid',