Search in sources :

Example 11 with ConfigFile

use of com.yahoo.elide.modelconfig.store.models.ConfigFile in project elide by yahoo.

the class ConfigDataStoreTest method testLoadObjects.

@Test
public void testLoadObjects() {
    String configRoot = "src/test/resources/validator/valid";
    Validator validator = new DynamicConfigValidator(DefaultClassScanner.getInstance(), configRoot);
    ConfigDataStore store = new ConfigDataStore(configRoot, validator);
    ConfigDataStoreTransaction tx = store.beginReadTransaction();
    RequestScope scope = mock(RequestScope.class);
    DataStoreIterable<ConfigFile> loaded = tx.loadObjects(EntityProjection.builder().type(ClassType.of(ConfigFile.class)).build(), scope);
    List<ConfigFile> configFiles = Lists.newArrayList(loaded.iterator());
    Supplier<String> contentProvider = () -> "{\n" + "  dbconfigs:\n" + "  [\n" + "    {\n" + "      name: MyDB2Connection\n" + "      url: jdbc:db2:localhost:50000/testdb\n" + "      driver: COM.ibm.db2.jdbc.net.DB2Driver\n" + "      user: guestdb2\n" + "      dialect: com.yahoo.elide.datastores.aggregation.queryengines.sql.dialects.impl.PrestoDBDialect\n" + "      propertyMap:\n" + "      {\n" + "        hibernate.show_sql: true\n" + "        hibernate.default_batch_fetch_size: 100.1\n" + "        hibernate.hbm2ddl.auto: create\n" + "      }\n" + "    }\n" + "    {\n" + "      name: MySQLConnection\n" + "      url: jdbc:mysql://localhost/testdb?serverTimezone=UTC\n" + "      driver: com.mysql.jdbc.Driver\n" + "      user: guestmysql\n" + "      dialect: com.yahoo.elide.datastores.aggregation.queryengines.sql.dialects.impl.HiveDialect\n" + "    }\n" + "  ]\n" + "}\n";
    assertEquals(10, configFiles.size());
    assertTrue(compare(ConfigFile.builder().version("").type(ConfigFile.ConfigFileType.DATABASE).contentProvider(contentProvider).path("db/sql/multiple_db_no_variables.hjson").build(), configFiles.get(1)));
    assertEquals("db/sql/multiple_db.hjson", configFiles.get(0).getPath());
    assertEquals(DATABASE, configFiles.get(0).getType());
    assertEquals("db/sql/single_db.hjson", configFiles.get(2).getPath());
    assertEquals(DATABASE, configFiles.get(2).getType());
    assertEquals("db/variables.hjson", configFiles.get(3).getPath());
    assertEquals(VARIABLE, configFiles.get(3).getType());
    assertEquals("models/namespaces/player.hjson", configFiles.get(4).getPath());
    assertEquals(NAMESPACE, configFiles.get(4).getType());
    assertEquals("models/security.hjson", configFiles.get(5).getPath());
    assertEquals(SECURITY, configFiles.get(5).getType());
    assertEquals("models/tables/player_stats.hjson", configFiles.get(6).getPath());
    assertEquals(TABLE, configFiles.get(6).getType());
    assertEquals("models/tables/player_stats_extends.hjson", configFiles.get(7).getPath());
    assertEquals(TABLE, configFiles.get(7).getType());
    assertEquals("models/tables/referred_model.hjson", configFiles.get(8).getPath());
    assertEquals(TABLE, configFiles.get(8).getType());
    assertEquals("models/variables.hjson", configFiles.get(9).getPath());
    assertEquals(VARIABLE, configFiles.get(9).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 12 with ConfigFile

use of com.yahoo.elide.modelconfig.store.models.ConfigFile in project elide by yahoo.

the class ConfigDataStoreTest method createInvalidFile.

protected ConfigFile createInvalidFile(String configRoot, ConfigDataStore store) {
    Supplier<String> contentProvider = () -> "{            \n" + "  tables: [{     \n" + "      name: Test\n" + "      table: test\n" + "      schema: test\n" + "      measures : [\n" + "         {\n" + "          name : measure\n" + "          type : INVALID_TYPE\n" + "          definition: 'MAX({{$measure}})'\n" + "         }\n" + "      ]      \n" + "      dimensions : [\n" + "         {\n" + "           name : dimension\n" + "           type : TEXT\n" + "           definition : '{{$dimension}}'\n" + "         }\n" + "      ]\n" + "  }]\n" + "}";
    ConfigFile newFile = ConfigFile.builder().type(TABLE).contentProvider(contentProvider).path("models/tables/test.hjson").build();
    ConfigDataStoreTransaction tx = store.beginTransaction();
    RequestScope scope = mock(RequestScope.class);
    tx.createObject(newFile, scope);
    tx.save(newFile, scope);
    tx.flush(scope);
    tx.commit(scope);
    return newFile;
}
Also used : ConfigFile(com.yahoo.elide.modelconfig.store.models.ConfigFile) RequestScope(com.yahoo.elide.core.RequestScope)

Example 13 with ConfigFile

use of com.yahoo.elide.modelconfig.store.models.ConfigFile 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 14 with ConfigFile

use of com.yahoo.elide.modelconfig.store.models.ConfigFile in project elide by yahoo.

the class ConfigDataStoreTest method updateFile.

protected ConfigFile updateFile(String configRoot, ConfigDataStore store) {
    Supplier<String> contentProvider = () -> "{            \n" + "  tables: [{     \n" + "      name: Test2\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" + "}";
    ConfigFile updatedFile = ConfigFile.builder().type(TABLE).contentProvider(contentProvider).path("models/tables/test.hjson").build();
    ConfigDataStoreTransaction tx = store.beginTransaction();
    RequestScope scope = mock(RequestScope.class);
    tx.save(updatedFile, scope);
    tx.flush(scope);
    tx.commit(scope);
    return updatedFile;
}
Also used : ConfigFile(com.yahoo.elide.modelconfig.store.models.ConfigFile) RequestScope(com.yahoo.elide.core.RequestScope)

Example 15 with ConfigFile

use of com.yahoo.elide.modelconfig.store.models.ConfigFile 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)

Aggregations

ConfigFile (com.yahoo.elide.modelconfig.store.models.ConfigFile)16 RequestScope (com.yahoo.elide.core.RequestScope)10 DynamicConfigValidator (com.yahoo.elide.modelconfig.validator.DynamicConfigValidator)8 Validator (com.yahoo.elide.modelconfig.validator.Validator)8 Test (org.junit.jupiter.api.Test)8 File (java.io.File)2 Include (com.yahoo.elide.annotation.Include)1 SecurityCheck (com.yahoo.elide.annotation.SecurityCheck)1 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)1 NO_VERSION (com.yahoo.elide.core.dictionary.EntityDictionary.NO_VERSION)1 EntityPermissions (com.yahoo.elide.core.dictionary.EntityPermissions)1 BadRequestException (com.yahoo.elide.core.exceptions.BadRequestException)1 Check (com.yahoo.elide.core.security.checks.Check)1 FilterExpressionCheck (com.yahoo.elide.core.security.checks.FilterExpressionCheck)1 UserCheck (com.yahoo.elide.core.security.checks.UserCheck)1 Type (com.yahoo.elide.core.type.Type)1 ClassScanner (com.yahoo.elide.core.utils.ClassScanner)1 DefaultClassScanner (com.yahoo.elide.core.utils.DefaultClassScanner)1 Config (com.yahoo.elide.modelconfig.Config)1 DynamicConfigHelpers (com.yahoo.elide.modelconfig.DynamicConfigHelpers)1