@Override public boolean removeConfiguration(final ConfigGroup configGroup) { final Path filePath = resolveConfigGroupPath(configGroup); if (!ioService.exists(filePath)) { return true; } boolean result; try { ioService.startBatch(filePath.getFileSystem()); result = ioService.deleteIfExists(filePath); if (result) { updateLastModified(); } } catch (Exception ex) { throw new RuntimeException(ex); } finally { ioService.endBatch(); } invalidateCacheAfterUpdatingConfigGroup(configGroup); return result; }
@Override public boolean removeConfiguration(final ConfigGroup configGroup) { //Invalidate cache if an item has been removed; otherwise cached value is stale configuration.remove(configGroup.getType()); String filename = configGroup.getName().replaceAll(INVALID_FILENAME_CHARS, "_"); final Path filePath = ioService.get(systemRepository.getUri()).resolve(filename + configGroup.getType().getExt()); // avoid duplicated writes to not cause cyclic cluster sync if (!ioService.exists(filePath)) { return true; } boolean result; try { ioService.startBatch(filePath.getFileSystem()); result = ioService.deleteIfExists(filePath); if (result) { updateLastModified(); } } catch (Exception ex) { throw new RuntimeException(ex); } finally { ioService.endBatch(); } return result; }
@Override public boolean updateConfiguration(ConfigGroup configGroup) { String filename = configGroup.getName().replaceAll(INVALID_FILENAME_CHARS, "_"); final Path filePath = ioService.get(systemRepository.getUri()).resolve(filename + configGroup.getType().getExt()); final CommentedOption commentedOption = new CommentedOption(getIdentityName(), "Updated config " + filePath.getFileName()); try { ioService.startBatch(filePath.getFileSystem()); ioService.write(filePath, marshaller.marshall(configGroup), commentedOption); updateLastModified(); } catch (Exception ex) { throw new RuntimeException(ex); } finally { ioService.endBatch(); } //Invalidate cache if a new item has been created; otherwise cached value is stale configuration.remove(configGroup.getType()); return true; }
private boolean saveConfiguration(final ConfigGroup configGroup, final Path path, final String commitMessage, final boolean isNew) { // avoid duplicated writes to not cause cyclic cluster sync if (isNew && ioService.exists(path)) { return true; } final CommentedOption commentedOption = new CommentedOption(getIdentityName(), commitMessage); try { ioService.startBatch(path.getFileSystem()); ioService.write(path, marshaller.marshall(configGroup), commentedOption); updateLastModified(); } catch (Exception ex) { throw new RuntimeException(ex); } finally { ioService.endBatch(); } invalidateCacheAfterUpdatingConfigGroup(configGroup); return true; }
@Override public boolean addConfiguration(final ConfigGroup configGroup) { String filename = configGroup.getName().replaceAll(INVALID_FILENAME_CHARS, "_"); final Path filePath = ioService.get(systemRepository.getUri()).resolve(filename + configGroup.getType().getExt()); // avoid duplicated writes to not cause cyclic cluster sync if (ioService.exists(filePath)) { return true; } final CommentedOption commentedOption = new CommentedOption(getIdentityName(), "Created config " + filePath.getFileName()); try { ioService.startBatch(filePath.getFileSystem()); ioService.write(filePath, marshaller.marshall(configGroup), commentedOption); updateLastModified(); } catch (Exception ex) { throw new RuntimeException(ex); } finally { ioService.endBatch(); } //Invalidate cache if a new item has been created; otherwise cached value is stale configuration.remove(configGroup.getType()); return true; }