use of com.yahoo.elide.modelconfig.DynamicConfiguration in project elide by yahoo.
the class ElideAutoConfiguration method buildQueryEngine.
/**
* Create a QueryEngine instance for aggregation data store to use.
* @param defaultDataSource DataSource for JPA.
* @param dynamicConfig An instance of DynamicConfiguration.
* @param settings Elide configuration settings.
* @param dataSourceConfiguration DataSource Configuration
* @param dbPasswordExtractor Password Extractor Implementation
* @return An instance of a QueryEngine
*/
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(name = "elide.aggregation-store.enabled", havingValue = "true")
@Scope(SCOPE_PROTOTYPE)
public QueryEngine buildQueryEngine(DataSource defaultDataSource, @Autowired(required = false) DynamicConfiguration dynamicConfig, ElideConfigProperties settings, ClassScanner scanner, DataSourceConfiguration dataSourceConfiguration, DBPasswordExtractor dbPasswordExtractor) {
boolean enableMetaDataStore = settings.getAggregationStore().isEnableMetaDataStore();
ConnectionDetails defaultConnectionDetails = new ConnectionDetails(defaultDataSource, SQLDialectFactory.getDialect(settings.getAggregationStore().getDefaultDialect()));
if (isDynamicConfigEnabled(settings)) {
MetaDataStore metaDataStore = new MetaDataStore(scanner, dynamicConfig.getTables(), dynamicConfig.getNamespaceConfigurations(), enableMetaDataStore);
Map<String, ConnectionDetails> connectionDetailsMap = new HashMap<>();
dynamicConfig.getDatabaseConfigurations().forEach(dbConfig -> {
connectionDetailsMap.put(dbConfig.getName(), new ConnectionDetails(dataSourceConfiguration.getDataSource(dbConfig, dbPasswordExtractor), SQLDialectFactory.getDialect(dbConfig.getDialect())));
});
Function<String, ConnectionDetails> connectionDetailsLookup = (name) -> {
if (StringUtils.isEmpty(name)) {
return defaultConnectionDetails;
}
return Optional.ofNullable(connectionDetailsMap.get(name)).orElseThrow(() -> new IllegalStateException("ConnectionDetails undefined for connection: " + name));
};
return new SQLQueryEngine(metaDataStore, connectionDetailsLookup, new HashSet<>(Arrays.asList(new AggregateBeforeJoinOptimizer(metaDataStore))), new DefaultQueryPlanMerger(metaDataStore), new DefaultQueryValidator(metaDataStore.getMetadataDictionary()));
}
MetaDataStore metaDataStore = new MetaDataStore(scanner, enableMetaDataStore);
return new SQLQueryEngine(metaDataStore, (unused) -> defaultConnectionDetails);
}
use of com.yahoo.elide.modelconfig.DynamicConfiguration in project elide by yahoo.
the class ElideStandaloneSettings method getEntityDictionary.
/**
* Gets the EntityDictionary for elide.
* @param injector Service locator for web service for dependency injection.
* @param dynamicConfiguration optional dynamic config object.
* @param entitiesToExclude set of Entities to exclude from binding.
* @return EntityDictionary object initialized.
*/
default EntityDictionary getEntityDictionary(ServiceLocator injector, ClassScanner scanner, Optional<DynamicConfiguration> dynamicConfiguration, Set<Type<?>> entitiesToExclude) {
Map<String, Class<? extends Check>> checks = new HashMap<>();
if (getAnalyticProperties().enableDynamicModelConfigAPI()) {
checks.put(ConfigChecks.CAN_CREATE_CONFIG, ConfigChecks.CanNotCreate.class);
checks.put(ConfigChecks.CAN_READ_CONFIG, ConfigChecks.CanNotRead.class);
checks.put(ConfigChecks.CAN_DELETE_CONFIG, ConfigChecks.CanNotDelete.class);
checks.put(ConfigChecks.CAN_UPDATE_CONFIG, ConfigChecks.CanNotUpdate.class);
}
EntityDictionary dictionary = new EntityDictionary(// Checks
new HashMap<>(), // Role Checks
new HashMap<>(), new Injector() {
@Override
public void inject(Object entity) {
injector.inject(entity);
}
@Override
public <T> T instantiate(Class<T> cls) {
return injector.create(cls);
}
}, // Serde Lookup
CoerceUtil::lookup, entitiesToExclude, scanner);
dynamicConfiguration.map(DynamicConfiguration::getRoles).orElseGet(Collections::emptySet).forEach(role -> dictionary.addRoleCheck(role, new Role.RoleMemberCheck(role)));
return dictionary;
}
use of com.yahoo.elide.modelconfig.DynamicConfiguration in project elide by yahoo.
the class ElideStandaloneConfigStoreTest method init.
@BeforeAll
public void init() throws Exception {
configRoot = Files.createTempDirectory("test");
settings = new ElideStandaloneTestSettings() {
@Override
public EntityDictionary getEntityDictionary(ServiceLocator injector, ClassScanner scanner, Optional<DynamicConfiguration> dynamicConfiguration, Set<Type<?>> entitiesToExclude) {
Map<String, Class<? extends Check>> checks = new HashMap<>();
if (getAnalyticProperties().enableDynamicModelConfigAPI()) {
checks.put(ConfigChecks.CAN_CREATE_CONFIG, ConfigChecks.CanCreate.class);
checks.put(ConfigChecks.CAN_READ_CONFIG, ConfigChecks.CanRead.class);
checks.put(ConfigChecks.CAN_DELETE_CONFIG, ConfigChecks.CanDelete.class);
checks.put(ConfigChecks.CAN_UPDATE_CONFIG, ConfigChecks.CanNotUpdate.class);
}
EntityDictionary dictionary = new EntityDictionary(// Checks
checks, // Role Checks
new HashMap<>(), new Injector() {
@Override
public void inject(Object entity) {
injector.inject(entity);
}
@Override
public <T> T instantiate(Class<T> cls) {
return injector.create(cls);
}
}, // Serde Lookup
CoerceUtil::lookup, entitiesToExclude, scanner);
dynamicConfiguration.map(DynamicConfiguration::getRoles).orElseGet(Collections::emptySet).forEach(role -> dictionary.addRoleCheck(role, new Role.RoleMemberCheck(role)));
return dictionary;
}
@Override
public ElideStandaloneAnalyticSettings getAnalyticProperties() {
return new ElideStandaloneAnalyticSettings() {
@Override
public boolean enableDynamicModelConfig() {
return true;
}
@Override
public boolean enableDynamicModelConfigAPI() {
return true;
}
@Override
public String getDynamicConfigPath() {
return configRoot.toFile().getAbsolutePath();
}
@Override
public boolean enableAggregationDataStore() {
return true;
}
@Override
public boolean enableMetaDataStore() {
return true;
}
};
}
};
elide = new ElideStandalone(settings);
elide.start(false);
}
use of com.yahoo.elide.modelconfig.DynamicConfiguration in project elide by yahoo.
the class ElideStandaloneSettings method getQueryEngine.
/**
* Gets the QueryEngine for elide.
* @param metaDataStore MetaDataStore object.
* @param defaultConnectionDetails default DataSource Object and SQLDialect Object.
* @param dynamicConfiguration Optional dynamic config.
* @param dataSourceConfiguration DataSource Configuration.
* @param dbPasswordExtractor Password Extractor Implementation.
* @return QueryEngine object initialized.
*/
default QueryEngine getQueryEngine(MetaDataStore metaDataStore, ConnectionDetails defaultConnectionDetails, Optional<DynamicConfiguration> dynamicConfiguration, DataSourceConfiguration dataSourceConfiguration, DBPasswordExtractor dbPasswordExtractor) {
if (dynamicConfiguration.isPresent()) {
Map<String, ConnectionDetails> connectionDetailsMap = new HashMap<>();
dynamicConfiguration.get().getDatabaseConfigurations().forEach(dbConfig -> connectionDetailsMap.put(dbConfig.getName(), new ConnectionDetails(dataSourceConfiguration.getDataSource(dbConfig, dbPasswordExtractor), SQLDialectFactory.getDialect(dbConfig.getDialect()))));
Function<String, ConnectionDetails> connectionDetailsLookup = (name) -> {
if (StringUtils.isEmpty(name)) {
return defaultConnectionDetails;
}
return Optional.ofNullable(connectionDetailsMap.get(name)).orElseThrow(() -> new IllegalStateException("ConnectionDetails undefined for connection: " + name));
};
return new SQLQueryEngine(metaDataStore, connectionDetailsLookup, new HashSet<>(Arrays.asList(new AggregateBeforeJoinOptimizer(metaDataStore))), new DefaultQueryPlanMerger(metaDataStore), new DefaultQueryValidator(metaDataStore.getMetadataDictionary()));
}
return new SQLQueryEngine(metaDataStore, (unused) -> defaultConnectionDetails);
}
Aggregations