use of com.yahoo.elide.modelconfig.validator.DynamicConfigValidator in project elide by yahoo.
the class ConfigDataStoreTest method testCreateWithPermissionError.
@Test
public void testCreateWithPermissionError(@TempDir Path configPath) {
String configRoot = configPath.toFile().getPath();
Validator validator = new DynamicConfigValidator(DefaultClassScanner.getInstance(), configRoot);
ConfigDataStore store = new ConfigDataStore(configRoot, validator);
File file = configPath.toFile();
boolean blockFailed = blockWrites(file);
if (blockFailed) {
// We can't actually test because setting permissions isn't working.
return;
}
assertThrows(UnsupportedOperationException.class, () -> createFile("test", store, false));
}
use of com.yahoo.elide.modelconfig.validator.DynamicConfigValidator in project elide by yahoo.
the class ConfigDataStoreTest method testMultipleFileOperations.
@Test
public void testMultipleFileOperations(@TempDir Path configPath) {
String configRoot = configPath.toFile().getPath();
Validator validator = new DynamicConfigValidator(DefaultClassScanner.getInstance(), configRoot);
ConfigDataStore store = new ConfigDataStore(configRoot, validator);
ConfigDataStoreTransaction tx = store.beginTransaction();
RequestScope scope = mock(RequestScope.class);
String[] tables = { "table1", "table2", "table3" };
for (String tableName : tables) {
Supplier<String> contentProvider = () -> String.format("{ \n" + " tables: [{ \n" + " name: %s\n" + " table: test\n" + " schema: test\n" + " measures : [\n" + " {\n" + " name : measure\n" + " type : INTEGER\n" + " definition: 'MAX({{$measure}})'\n" + " }\n" + " ] \n" + " dimensions : [\n" + " {\n" + " name : dimension\n" + " type : TEXT\n" + " definition : '{{$dimension}}'\n" + " }\n" + " ]\n" + " }]\n" + "}", tableName);
ConfigFile newFile = ConfigFile.builder().type(TABLE).contentProvider(contentProvider).path(String.format("models/tables/%s.hjson", tableName)).build();
tx.createObject(newFile, scope);
}
ConfigFile invalid = ConfigFile.builder().path("/tmp").contentProvider((() -> "Invalid")).build();
tx.createObject(invalid, scope);
tx.delete(invalid, scope);
tx.flush(scope);
tx.commit(scope);
ConfigDataStoreTransaction readTx = store.beginReadTransaction();
DataStoreIterable<ConfigFile> loaded = readTx.loadObjects(EntityProjection.builder().type(ClassType.of(ConfigFile.class)).build(), scope);
List<ConfigFile> configFiles = Lists.newArrayList(loaded.iterator());
assertEquals(3, configFiles.size());
assertEquals("models/tables/table1.hjson", configFiles.get(0).getPath());
assertEquals(TABLE, configFiles.get(0).getType());
assertEquals("models/tables/table2.hjson", configFiles.get(1).getPath());
assertEquals(TABLE, configFiles.get(1).getType());
assertEquals("models/tables/table3.hjson", configFiles.get(2).getPath());
assertEquals(TABLE, configFiles.get(2).getType());
}
use of com.yahoo.elide.modelconfig.validator.DynamicConfigValidator in project elide by yahoo.
the class ConfigDataStoreTest method testDelete.
@Test
public void testDelete(@TempDir Path configPath) {
String configRoot = configPath.toFile().getPath();
Validator validator = new DynamicConfigValidator(DefaultClassScanner.getInstance(), configRoot);
ConfigDataStore store = new ConfigDataStore(configRoot, validator);
ConfigFile newFile = createFile("test", store, false);
ConfigDataStoreTransaction tx = store.beginTransaction();
RequestScope scope = mock(RequestScope.class);
tx.delete(newFile, scope);
tx.flush(scope);
tx.commit(scope);
ConfigDataStoreTransaction readTx = store.beginReadTransaction();
ConfigFile loaded = readTx.loadObject(EntityProjection.builder().type(ClassType.of(ConfigFile.class)).build(), toId("models/tables/test.hjson", NO_VERSION), scope);
assertNull(loaded);
}
use of com.yahoo.elide.modelconfig.validator.DynamicConfigValidator in project elide by yahoo.
the class ElideAutoConfiguration method buildDynamicConfiguration.
/**
* Creates dynamic configuration for models, security roles, and database connections.
* @param settings Config Settings.
* @throws IOException if there is an error reading the configuration.
* @return An instance of DynamicConfiguration.
*/
@Bean
@Scope(SCOPE_PROTOTYPE)
@ConditionalOnMissingBean
@ConditionalOnExpression("${elide.aggregation-store.enabled:false} and ${elide.dynamic-config.enabled:false}")
public DynamicConfiguration buildDynamicConfiguration(ClassScanner scanner, ElideConfigProperties settings) throws IOException {
DynamicConfigValidator validator = new DynamicConfigValidator(scanner, settings.getDynamicConfig().getPath());
validator.readAndValidateConfigs();
return validator;
}
use of com.yahoo.elide.modelconfig.validator.DynamicConfigValidator in project elide by yahoo.
the class ElideStandaloneSettings method getDynamicConfiguration.
/**
* Gets the dynamic configuration for models, security roles, and database connection.
* @param scanner Class scanner
* @return Optional DynamicConfiguration
* @throws IOException thrown when validator fails to read configuration.
*/
default Optional<DynamicConfiguration> getDynamicConfiguration(ClassScanner scanner) throws IOException {
DynamicConfigValidator validator = null;
if (getAnalyticProperties().enableAggregationDataStore() && getAnalyticProperties().enableDynamicModelConfig()) {
validator = new DynamicConfigValidator(scanner, getAnalyticProperties().getDynamicConfigPath());
validator.readAndValidateConfigs();
}
return Optional.ofNullable(validator);
}
Aggregations