Search in sources :

Example 1 with AtlasModuleInfoRegistry

use of io.atlasmap.spi.AtlasModuleInfoRegistry in project atlasmap by atlasmap.

the class DefaultAtlasContext method init.

/**
 * TODO: For dynamic re-load. This needs lock()
 *
 * @throws AtlasException
 */
protected void init() throws AtlasException {
    registerJmx(this);
    if (this.atlasMappingUri != null) {
        this.mappingDefinition = factory.getMappingService().loadMapping(this.atlasMappingUri, atlasMappingFormat);
    }
    sourceModules.clear();
    ConstantModule constant = new ConstantModule();
    constant.setConversionService(factory.getConversionService());
    constant.setFieldActionService(factory.getFieldActionService());
    sourceModules.put(CONSTANTS_DOCUMENT_ID, constant);
    PropertyModule propSource = new PropertyModule(factory.getPropertyStrategy());
    propSource.setMode(AtlasModuleMode.SOURCE);
    propSource.setConversionService(factory.getConversionService());
    propSource.setFieldActionService(factory.getFieldActionService());
    sourceModules.put(PROPERTIES_DOCUMENT_ID, propSource);
    targetModules.clear();
    lookupTables.clear();
    if (mappingDefinition.getLookupTables() != null && mappingDefinition.getLookupTables().getLookupTable() != null) {
        for (LookupTable table : mappingDefinition.getLookupTables().getLookupTable()) {
            lookupTables.put(table.getName(), table);
        }
    }
    AtlasModuleInfoRegistry moduleInfoRegistry = factory.getModuleInfoRegistry();
    for (DataSource ds : mappingDefinition.getDataSource()) {
        AtlasModuleInfo moduleInfo = moduleInfoRegistry.lookupByUri(ds.getUri());
        if (moduleInfo == null) {
            LOG.error("Cannot find module info for the DataSource uri '{}'", ds.getUri());
            continue;
        }
        if (ds.getDataSourceType() != DataSourceType.SOURCE && ds.getDataSourceType() != DataSourceType.TARGET) {
            LOG.error("Unsupported DataSource type '{}'", ds.getDataSourceType());
            continue;
        }
        String docId = ds.getId();
        if (docId == null || docId.isEmpty()) {
            docId = ds.getDataSourceType() == DataSourceType.SOURCE ? AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID : AtlasConstants.DEFAULT_TARGET_DOCUMENT_ID;
        }
        if (ds.getDataSourceType() == DataSourceType.SOURCE && sourceModules.containsKey(docId)) {
            LOG.error("Duplicated {} DataSource ID '{}' was detected, ignoring...", ds.getDataSourceType(), ds.getId());
            continue;
        }
        if (ds.getDataSourceType() == DataSourceType.TARGET && targetModules.containsKey(docId)) {
            LOG.error("Duplicated {} DataSource ID '{}' was detected, ignoring...", ds.getDataSourceType(), docId);
            continue;
        }
        try {
            AtlasModule module = moduleInfo.getModuleClass().newInstance();
            module.setConversionService(factory.getConversionService());
            module.setFieldActionService(factory.getFieldActionService());
            module.setUri(ds.getUri());
            if (ds.getDataSourceType() == DataSourceType.SOURCE) {
                module.setMode(AtlasModuleMode.SOURCE);
                getSourceModules().put(docId, module);
            } else if (ds.getDataSourceType() == DataSourceType.TARGET) {
                module.setMode(AtlasModuleMode.TARGET);
                getTargetModules().put(docId, module);
            }
            module.setDocId(docId);
            module.init();
        } catch (Throwable t) {
            LOG.error("Unable to initialize {} module: {}", ds.getDataSourceType(), moduleInfo.toString());
            LOG.error(t.getMessage(), t);
            throw new AtlasException(String.format("Unable to initialize %s module: %s", ds.getDataSourceType(), moduleInfo.toString()), t);
        }
    }
}
Also used : AtlasModule(io.atlasmap.spi.AtlasModule) AtlasModuleInfo(io.atlasmap.spi.AtlasModuleInfo) AtlasModuleInfoRegistry(io.atlasmap.spi.AtlasModuleInfoRegistry) LookupTable(io.atlasmap.v2.LookupTable) AtlasException(io.atlasmap.api.AtlasException) DataSource(io.atlasmap.v2.DataSource)

Aggregations

AtlasException (io.atlasmap.api.AtlasException)1 AtlasModule (io.atlasmap.spi.AtlasModule)1 AtlasModuleInfo (io.atlasmap.spi.AtlasModuleInfo)1 AtlasModuleInfoRegistry (io.atlasmap.spi.AtlasModuleInfoRegistry)1 DataSource (io.atlasmap.v2.DataSource)1 LookupTable (io.atlasmap.v2.LookupTable)1