boolean isDeleted() { return Intrinsic.isDeleted(getRawJson()); }
boolean isDeleted() { return Intrinsic.isDeleted(getRawJson()); }
@Override public Set<StashRequest> getRequestsForStash(String scanId) { Map<String, Object> map = _dataStore.get(getTable(), scanId); if (Intrinsic.isDeleted(map)) { return ImmutableSet.of(); } Map<String, Date> requestMap = JsonHelper.convert( map.getOrDefault("requests", ImmutableMap.of()), new TypeReference<Map<String, Date>>(){}); return requestMap.entrySet().stream() .map(entry -> new StashRequest(entry.getKey(), entry.getValue())) .collect(Collectors.toSet()); } }
private T convertDataStoreEntryToIdentity(Map<String, Object> map) { if (map == null || Intrinsic.isDeleted(map)) { return null; } // Make a copy of the map to avoid mutating the method parameter as a side-effect Map<String, Object> identityMap = Maps.newHashMap(map); // Historically the ID attribute used to be called "internalId". For backwards compatibility with the legacy // "internalId" attribute name and forwards compatibility with the "id" attribute name accept either one. String legacyInternalId = (String) identityMap.remove(INTERNAL_ID); if (!identityMap.containsKey(ID)) { if (legacyInternalId != null) { identityMap.put(ID, legacyInternalId); } else { // Identities have been in use since before non-authentication IDs were introduced. To grandfather in // those keys we'll use the hash of the identity's authentication ID as the identity's ID. identityMap.put(ID, Intrinsic.getId(map)); } } // Remove all intrinsics identityMap.keySet().removeAll(Intrinsic.DATA_FIELDS); return JsonHelper.convert(identityMap, _authIdentityClass); }
private T convertDataStoreEntryToIdentity(Map<String, Object> map) { if (map == null || Intrinsic.isDeleted(map)) { return null; } // Make a copy of the map to avoid mutating the method parameter as a side-effect Map<String, Object> identityMap = Maps.newHashMap(map); // Historically the ID attribute used to be called "internalId". For backwards compatibility with the legacy // "internalId" attribute name and forwards compatibility with the "id" attribute name accept either one. String legacyInternalId = (String) identityMap.remove(INTERNAL_ID); if (!identityMap.containsKey(ID)) { if (legacyInternalId != null) { identityMap.put(ID, legacyInternalId); } else { // Identities have been in use since before non-authentication IDs were introduced. To grandfather in // those keys we'll use the hash of the identity's authentication ID as the identity's ID. identityMap.put(ID, Intrinsic.getId(map)); } } // Remove all intrinsics identityMap.keySet().removeAll(Intrinsic.DATA_FIELDS); return JsonHelper.convert(identityMap, _authIdentityClass); }
@Nullable @Override public <Q, R> JobStatus<Q, R> getJobStatus(JobIdentifier<Q, R> jobId) { checkNotNull(jobId, "jobId"); Map<String, Object> result = _dataStore.get(getTableName(), jobId.toString(), ReadConsistency.STRONG); if (Intrinsic.isDeleted(result)) { return null; } Object status = result.get("status"); return narrow(status, jobId.getJobType()); }
@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(); }
@Nullable @Override public <Q, R> JobStatus<Q, R> getJobStatus(JobIdentifier<Q, R> jobId) { checkNotNull(jobId, "jobId"); Map<String, Object> result = _dataStore.get(getTableName(), jobId.toString(), ReadConsistency.STRONG); if (Intrinsic.isDeleted(result)) { return null; } Object status = result.get("status"); return narrow(status, jobId.getJobType()); }
@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 Object load(String name) throws Exception { RegisteredSetting<?> registeredSetting = _registeredSettings.get(name); checkNotNull(registeredSetting, "Cache value lookup for unregistered setting: %s", name); SettingMetadata<?> metadata = registeredSetting.metadata; Map<String, Object> valueMap = _dataStore.get().get( _settingsTable.get(), metadata.getName(), ReadConsistency.STRONG); if (Intrinsic.isDeleted(valueMap)) { return metadata.getDefaultValue(); } Object value; int version = Objects.firstNonNull((Integer) valueMap.get(VERSION_ATTRIBUTE), -1); if (version == CURRENT_SETTING_VERSION) { String rawValue = (String) valueMap.get(VALUE_ATTRIBUTE); value = JsonHelper.fromJson(rawValue, metadata.getTypeReference()); } else { throw new IllegalStateException("Setting stored with unparseable version: " + version); } _log.info("Setting {} updated: {}", name, value); return value; } });
/** * Accepts a row from the table report and returns it converted into a TableReportEntry. If the row is deleted * or if it doesn't match all of the configured filters then null is returned. */ @Nullable private TableReportEntry convertToTableReportEntry(Map<String, Object> map, Predicate<String> placementFilter, Predicate<Boolean> droppedFilter, Predicate<Boolean> facadeFilter) { if (Intrinsic.isDeleted(map)) { return null; } final String tableName = Intrinsic.getId(map); List<TableReportEntryTable> tables = Lists.newArrayListWithExpectedSize(map.size()); for (Map.Entry<String, Object> entry : toMap(map.get("tables")).entrySet()) { TableReportEntryTable entryTable = convertToTableReportEntryTable(entry.getKey(), toMap(entry.getValue()), placementFilter, droppedFilter, facadeFilter); if (entryTable != null) { tables.add(entryTable); } } // If all tables were filtered then return null if (tables.isEmpty()) { return null; } return new TableReportEntry(tableName, tables); }
private Role convertRecordToRole(Map<String, Object> record) { if (Intrinsic.isDeleted(record)) { return null; } RoleIdentifier id = RoleIdentifier.fromString(Intrinsic.getId(record)); return new Role(id.getGroup(), id.getId(), (String) record.get(NAME_ATTR), (String) record.get(DESCRIPTION_ATTR)); }
private Role convertRecordToRole(Map<String, Object> record) { if (Intrinsic.isDeleted(record)) { return null; } RoleIdentifier id = RoleIdentifier.fromString(Intrinsic.getId(record)); return new Role(id.getGroup(), id.getId(), (String) record.get(NAME_ATTR), (String) record.get(DESCRIPTION_ATTR)); }
private MigratorStatus fromMap(Map<String, Object> map) { if (Intrinsic.isDeleted(map)) { return null;
private ScanStatus fromMap(Map<String, Object> map) { if (Intrinsic.isDeleted(map)) { return null;
if (Intrinsic.isDeleted(metadata)) { throw new ReportNotFoundException(reportId);
private String newTableUuidString(String table, Audit audit) { // This function assumes that it runs inside the global lock implemented by the ExclusiveTableDAO metadata mutex. for (; ; ) { long value = RANDOM.nextLong(); // Never pick 0xffffffffffffffff since we can't use it in a range query for all rows between // (value, value+1) since value+1 overflows using unsigned math per the ByteOrderedPartitioner. if (value == -1) { continue; // pick another uuid } // Don't conflict with a bootstrap table. Reserve table IDs that end in 0xffff for future system tables. if (_reservedUuids.contains(value) || (value & 0xffff) == 0xffff) { continue; // pick another uuid } String uuid = TableUuidFormat.encode(value); // 64-bit numbers are unique enough that we can assume uniqueness. Check whether this uuid is in use. Map<String, Object> existing = _backingStore.get(_systemTableUuid, uuid, ReadConsistency.STRONG); if (!Intrinsic.isDeleted(existing)) { continue; // pick another uuid } // Nobody is using it. Record that we're about it. There's a small chance that the app crashes between // this write and the subsequent creation of the table with the uuid. If that happens, we'll leak a uuid // but it should be harmless otherwise. Map<String, ?> json = ImmutableMap.of("table", table); _backingStore.update(_systemTableUuid, uuid, TimeUUIDs.newUUID(), Deltas.literal(json), audit, WriteConsistency.GLOBAL); return uuid; } }
private String newTableUuidString(String table, Audit audit) { // This function assumes that it runs inside the global lock implemented by the ExclusiveTableDAO metadata mutex. for (; ; ) { long value = RANDOM.nextLong(); // Never pick 0xffffffffffffffff since we can't use it in a range query for all rows between // (value, value+1) since value+1 overflows using unsigned math per the ByteOrderedPartitioner. if (value == -1) { continue; // pick another uuid } // Don't conflict with a bootstrap table. Reserve table IDs that end in 0xffff for future system tables. if (_reservedUuids.contains(value) || (value & 0xffff) == 0xffff) { continue; // pick another uuid } String uuid = TableUuidFormat.encode(value); // 64-bit numbers are unique enough that we can assume uniqueness. Check whether this uuid is in use. Map<String, Object> existing = _backingStore.get(_systemTableUuid, uuid, ReadConsistency.STRONG); if (!Intrinsic.isDeleted(existing)) { continue; // pick another uuid } // Nobody is using it. Record that we're about it. There's a small chance that the app crashes between // this write and the subsequent creation of the table with the uuid. If that happens, we'll leak a uuid // but it should be harmless otherwise. Map<String, ?> json = ImmutableMap.of("table", table); _backingStore.update(_systemTableUuid, uuid, TimeUUIDs.newUUID(), Deltas.literal(json), audit, WriteConsistency.GLOBAL); return uuid; } }
if (!Intrinsic.isDeleted(idRecord)) { hashedAuthenticationId = (String) idRecord.get(HASHED_ID); Map<String, Object> identityEntry = _dataStore.get(_identityTableName, hashedAuthenticationId);
if (!Intrinsic.isDeleted(idRecord)) { hashedAuthenticationId = (String) idRecord.get(HASHED_ID); Map<String, Object> identityEntry = _dataStore.get(_identityTableName, hashedAuthenticationId);