@Override public Map<String, DataCenter> loadAll() { Map<String, Object> json = _dataStore.get(TABLE, ROW); return deserializeAll(json); }
@Override public boolean getTableExists(String table) { return _delegate.getTableExists(table); }
@Override public void createTable(String table, TableOptions options, Map<String, ?> template, Audit audit) throws TableExistsException { // delegate to system data center _system.get().createTable(table, options, template, audit); }
@Override public String get() { // Lazily ensure the table exists on the first use. String tableName = tableNameSupplier.get(); if (!_dataStore.getTableExists(tableName)) { _dataStore.createTable(tableName, new TableOptionsBuilder().setPlacement(placement).build(), ImmutableMap.<String, String>of(), new AuditBuilder().setLocalHost().setComment("create table").build() ); } return tableName; } }
@Override public void revokePermissions(String id) { checkNotNull(id, "id"); validateTable(); _dataStore.update( _tableName, id, TimeUUIDs.newUUID(), Deltas.delete(), new AuditBuilder().setLocalHost().setComment("delete permissions").build(), WriteConsistency.GLOBAL); }
@Override public Iterator<Map<String, Object>> get(String fromToken, long limit) { return dataStore.scan(table, fromToken, limit, includeDeletes, consistency); }
@Override public void updateAll(Iterable<Update> updates) { _local.get().updateAll(updates); }
@Override public List<Role> getRolesByGroup(@Nullable String group) { String groupKey = checkGroup(group); List<Role> roles = null; validateTables(); Map<String, Object> record = _dataStore.get(_groupTableName, groupKey); if (!Intrinsic.isDeleted(record)) { //noinspection unchecked List<String> names = (List<String>) record.get(IDS_ATTR); if (names != null && !names.isEmpty()) { List<Coordinate> coordinates = names.stream() .map(name -> Coordinate.of(_roleTableName, new RoleIdentifier(group, name).toString())) .collect(Collectors.toList()); Iterator<Map<String, Object>> records = _dataStore.multiGet(coordinates, ReadConsistency.STRONG); roles = StreamSupport.stream(Spliterators.spliteratorUnknownSize(records, 0), false) .map(this::convertRecordToRole) .filter(Objects::nonNull) .collect(Collectors.toList()); } } return roles != null ? roles : ImmutableList.of(); }
@Override public URI getStashRoot() throws StashNotAvailableException { return _delegate.getStashRoot(); } }
private SuccessResponse doSimpleUpdateStream(final Optional<String> tableParam, final TimeUUIDParam changeIdParam, AuditParam auditParam, WriteConsistencyParam consistencyParam, Reader in, BooleanParam facade, Subject subject) { final Audit audit = getRequired(auditParam, "audit"); final WriteConsistency consistency = consistencyParam.get(); Iterator<Update> updates = Iterators.transform(Deltas.fromStream(in), new Function<Delta, Update>() { @Override public Update apply(Delta delta) { String table = tableParam.isPresent() ? tableParam.get() : extractKey(delta, Intrinsic.TABLE, String.class); checkArgument(table != null, "JSON object is missing field required by streaming update: %s", Intrinsic.TABLE); String key = extractKey(delta, Intrinsic.ID, String.class); checkArgument(key != null, "JSON object is missing field required by streaming update: %s", Intrinsic.ID); UUID changeId = (changeIdParam != null) ? changeIdParam.get() : TimeUUIDs.newUUID(); // optional, defaults to new uuid return new Update(table, key, changeId, delta, audit, consistency); } }); if (facade != null && facade.get()) { _dataStore.updateAllForFacade(asSubjectSafeUpdateIterable(updates, subject, true)); } else { // Parse and iterate through the deltas such that we never hold all the deltas in memory at once. _dataStore.updateAll(asSubjectSafeUpdateIterable(updates, subject, false)); } return SuccessResponse.instance(); }
@Override public Iterator<Map<String, Object>> multiGet(List<Coordinate> coordinates) { return _delegate.multiGet(coordinates); }
@Override public Iterator<Table> get(String fromToken, long limit) { return dataStore.listTables(fromToken, limit); }
@Override public Iterator<Map<String, Object>> get(String fromToken, long limit) { return dataStore.getSplit(table, split, fromToken, limit, includeDeletes, consistency); }
@Override public String get() { // Lazily ensure the table exists on the first use. String tableName = tableNameSupplier.get(); if (!_dataStore.getTableExists(tableName)) { _dataStore.createTable(tableName, new TableOptionsBuilder().setPlacement(placement).build(), ImmutableMap.<String, String>of(), new AuditBuilder().setLocalHost().setComment("create table").build() ); } return tableName; } }
private <T> void set(SettingMetadata<T> metadata, T value) { checkNotNull(value, "value"); Delta delta = Deltas.mapBuilder() .put(VALUE_ATTRIBUTE, JsonHelper.asJson(value)) .put(VERSION_ATTRIBUTE, CURRENT_SETTING_VERSION) .build(); // Write the delta to the store _dataStore.get().update(_settingsTable.get(), metadata.getName(), TimeUUIDs.newUUID(), delta, new AuditBuilder().setLocalHost().setComment("Updated setting").build(), WriteConsistency.GLOBAL); // Notify all instances that the setting value has changed _cacheHandle.invalidate(InvalidationScope.GLOBAL, metadata.getName()); }
@Override public Iterator<Map<String, Object>> scan(String table, @Nullable String fromKeyExclusive, long limit, boolean includeDeletes, ReadConsistency consistency) { return _delegate.scan(table, fromKeyExclusive, limit, includeDeletes, consistency); }
@Override public void updateAll(Iterable<Update> updates, Set<String> tags) { _local.get().updateAll(updates, tags); }
@Override public List<Role> getRolesByGroup(@Nullable String group) { String groupKey = checkGroup(group); List<Role> roles = null; validateTables(); Map<String, Object> record = _dataStore.get(_groupTableName, groupKey); if (!Intrinsic.isDeleted(record)) { //noinspection unchecked List<String> names = (List<String>) record.get(IDS_ATTR); if (names != null && !names.isEmpty()) { List<Coordinate> coordinates = names.stream() .map(name -> Coordinate.of(_roleTableName, new RoleIdentifier(group, name).toString())) .collect(Collectors.toList()); Iterator<Map<String, Object>> records = _dataStore.multiGet(coordinates, ReadConsistency.STRONG); roles = StreamSupport.stream(Spliterators.spliteratorUnknownSize(records, 0), false) .map(this::convertRecordToRole) .filter(Objects::nonNull) .collect(Collectors.toList()); } } return roles != null ? roles : ImmutableList.of(); }
@Override public URI getStashRoot() throws StashNotAvailableException { return _delegate.getStashRoot(); } }
@Override public Iterator<Map<String, Object>> multiGet(List<Coordinate> coordinates, ReadConsistency consistency) { return _delegate.multiGet(coordinates, consistency); }