use of com.yahoo.elide.modelconfig.store.models.ConfigFile in project elide by yahoo.
the class FileLoader method loadResources.
/**
* Load resources from the filesystem/classpath.
* @return A map from the path to the resource.
* @throws IOException If something goes boom.
*/
public Map<String, ConfigFile> loadResources() throws IOException {
Map<String, ConfigFile> resourceMap = new LinkedHashMap<>();
int configDirURILength = resolver.getResources(this.rootURL)[0].getURI().toString().length();
Resource[] hjsonResources = resolver.getResources(this.rootURL + HJSON_EXTN);
for (Resource resource : hjsonResources) {
if (!resource.exists()) {
log.error("Missing resource during HJSON configuration load: {}", resource.getURI());
continue;
}
String path = resource.getURI().toString().substring(configDirURILength);
resourceMap.put(path, ConfigFile.builder().type(toType(path)).contentProvider(() -> CONTENT_PROVIDER.apply(resource)).path(path).version(NO_VERSION).build());
}
return resourceMap;
}
use of com.yahoo.elide.modelconfig.store.models.ConfigFile in project elide by yahoo.
the class ConfigDataStoreTest method testUpdate.
@Test
public void testUpdate(@TempDir Path configPath) {
String configRoot = configPath.toFile().getPath();
Validator validator = new DynamicConfigValidator(DefaultClassScanner.getInstance(), configRoot);
ConfigDataStore store = new ConfigDataStore(configRoot, validator);
createFile("test", store, false);
ConfigFile updateFile = updateFile(configRoot, store);
ConfigDataStoreTransaction readTx = store.beginReadTransaction();
RequestScope scope = mock(RequestScope.class);
ConfigFile loaded = readTx.loadObject(EntityProjection.builder().type(ClassType.of(ConfigFile.class)).build(), toId("models/tables/test.hjson", NO_VERSION), scope);
assertTrue(compare(updateFile, loaded));
}
use of com.yahoo.elide.modelconfig.store.models.ConfigFile in project elide by yahoo.
the class ConfigDataStoreTest method testUpdateWithPermissionError.
@Test
public void testUpdateWithPermissionError(@TempDir Path configPath) {
String configRoot = configPath.toFile().getPath();
Validator validator = new DynamicConfigValidator(DefaultClassScanner.getInstance(), configRoot);
ConfigDataStore store = new ConfigDataStore(configRoot, validator);
ConfigFile createdFile = createFile("test", store, false);
String createdFilePath = Path.of(configPath.toFile().getPath(), createdFile.getPath()).toFile().getPath();
File file = new File(createdFilePath);
boolean blockFailed = blockWrites(file);
if (blockFailed) {
// We can't actually test because setting permissions isn't working.
return;
}
assertThrows(UnsupportedOperationException.class, () -> updateFile(configRoot, store));
}
use of com.yahoo.elide.modelconfig.store.models.ConfigFile in project elide by yahoo.
the class ConfigDataStoreTest method testCreateValidateOnly.
@Test
public void testCreateValidateOnly(@TempDir Path configPath) {
String configRoot = configPath.toFile().getPath();
Validator validator = new DynamicConfigValidator(DefaultClassScanner.getInstance(), configRoot);
ConfigDataStore store = new ConfigDataStore(configRoot, validator);
ConfigDataStoreTransaction readTx = store.beginReadTransaction();
RequestScope scope = mock(RequestScope.class);
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.store.models.ConfigFile in project elide by yahoo.
the class ConfigDataStoreTransaction method createObject.
@Override
public <T> void createObject(T entity, RequestScope scope) {
ConfigFile file = (ConfigFile) entity;
if (readOnly || !canCreate(file.getPath())) {
log.error("Attempt to modify a read only configuration");
throw new UnsupportedOperationException("Configuration is read only.");
}
dirty.add(file);
todo.add(() -> {
// We have to assign the ID here during commit so it gets sent back in the response.
file.setId(ConfigFile.toId(file.getPath(), file.getVersion()));
createFile(file.getPath());
updateFile(file.getPath(), file.getContent());
});
}
Aggregations