Implement NextCatalogBuilder.addEntityProvider

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2021-06-16 11:30:15 +02:00
parent 95dfa3340a
commit cb09e445ea
2 changed files with 34 additions and 3 deletions
@@ -63,7 +63,11 @@ import {
} from '../ingestion/processors/PlaceholderProcessor';
import { defaultEntityDataParser } from '../ingestion/processors/util/parse';
import { LocationAnalyzer } from '../ingestion/types';
import { CatalogProcessingEngine, LocationService } from '../next/types';
import {
CatalogProcessingEngine,
EntityProvider,
LocationService,
} from '../next/types';
import { ConfigLocationEntityProvider } from './ConfigLocationEntityProvider';
import { DefaultProcessingDatabase } from './database/DefaultProcessingDatabase';
import { DefaultCatalogProcessingEngine } from './DefaultCatalogProcessingEngine';
@@ -105,6 +109,7 @@ export class NextCatalogBuilder {
private entityPoliciesReplace: boolean;
private placeholderResolvers: Record<string, PlaceholderResolver>;
private fieldFormatValidators: Partial<Validators>;
private entityProviders: EntityProvider[];
private processors: CatalogProcessor[];
private processorsReplace: boolean;
private parser: CatalogProcessorParser | undefined;
@@ -116,6 +121,7 @@ export class NextCatalogBuilder {
this.entityPoliciesReplace = false;
this.placeholderResolvers = {};
this.fieldFormatValidators = {};
this.entityProviders = [];
this.processors = [];
this.processorsReplace = false;
this.parser = undefined;
@@ -198,6 +204,20 @@ export class NextCatalogBuilder {
return this;
}
/**
* Adds or replaces entity providers. These are responsible for bootstrapping
* the list of entities out of original data sources. For example, there is
* one entity source for the config locations, and one for the database
* stored locations. If you ingest entities out of a third party system, you
* may want to implement that in terms of an entity provider as well.
*
* @param providers One or more entity providers
*/
addEntityProvider(...providers: EntityProvider[]): NextCatalogBuilder {
this.entityProviders.push(...providers);
return this;
}
/**
* Adds entity processors. These are responsible for reading, parsing, and
* processing entities before they are persisted in the catalog.
@@ -277,13 +297,18 @@ export class NextCatalogBuilder {
policy,
});
const entitiesCatalog = new NextEntitiesCatalog(dbClient);
const stitcher = new Stitcher(dbClient, logger);
const locationStore = new DefaultLocationStore(dbClient);
const stitcher = new Stitcher(dbClient, logger);
const configLocationProvider = new ConfigLocationEntityProvider(config);
const entityProviders = lodash.uniqBy(
[...this.entityProviders, locationStore, configLocationProvider],
provider => provider.getProviderName(),
);
const processingEngine = new DefaultCatalogProcessingEngine(
logger,
[locationStore, configLocationProvider],
entityProviders,
processingDatabase,
orchestrator,
stitcher,
@@ -295,6 +320,7 @@ export class NextCatalogBuilder {
locationStore,
orchestrator,
);
return {
entitiesCatalog,
locationsCatalog,