Search in sources :

Example 11 with DynamicConfigValidator

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));
}
Also used : ConfigFile(com.yahoo.elide.modelconfig.store.models.ConfigFile) File(java.io.File) DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator) Validator(com.yahoo.elide.modelconfig.validator.Validator) DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator) Test(org.junit.jupiter.api.Test)

Example 12 with DynamicConfigValidator

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());
}
Also used : ConfigFile(com.yahoo.elide.modelconfig.store.models.ConfigFile) RequestScope(com.yahoo.elide.core.RequestScope) DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator) Validator(com.yahoo.elide.modelconfig.validator.Validator) DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator) Test(org.junit.jupiter.api.Test)

Example 13 with DynamicConfigValidator

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);
}
Also used : ConfigFile(com.yahoo.elide.modelconfig.store.models.ConfigFile) RequestScope(com.yahoo.elide.core.RequestScope) DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator) Validator(com.yahoo.elide.modelconfig.validator.Validator) DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator) Test(org.junit.jupiter.api.Test)

Example 14 with DynamicConfigValidator

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;
}
Also used : DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator) ConditionalOnExpression(org.springframework.boot.autoconfigure.condition.ConditionalOnExpression) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Scope(org.springframework.context.annotation.Scope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 15 with DynamicConfigValidator

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);
}
Also used : DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator)

Aggregations

DynamicConfigValidator (com.yahoo.elide.modelconfig.validator.DynamicConfigValidator)15 Validator (com.yahoo.elide.modelconfig.validator.Validator)11 Test (org.junit.jupiter.api.Test)11 ConfigFile (com.yahoo.elide.modelconfig.store.models.ConfigFile)9 RequestScope (com.yahoo.elide.core.RequestScope)7 File (java.io.File)3 DefaultQueryValidator (com.yahoo.elide.datastores.aggregation.DefaultQueryValidator)1 MetaDataStore (com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore)1 DefaultQueryPlanMerger (com.yahoo.elide.datastores.aggregation.query.DefaultQueryPlanMerger)1 SQLQueryEngine (com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 ConditionalOnExpression (org.springframework.boot.autoconfigure.condition.ConditionalOnExpression)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)1 Bean (org.springframework.context.annotation.Bean)1 Scope (org.springframework.context.annotation.Scope)1