private boolean hasDefinitionChange(Index index) { return metadataIndex.getHash(index.getName()) .map(hash -> { String defHash = IndexDefinitionHash.of(index); return !StringUtils.equals(hash, defHash); }).orElse(true); }
private static void appendObject(StringBuilder sb, Object value) { if (value instanceof IndexDefinition.Type) { appendIndexType(sb, (IndexDefinition.Type) value); } else if (value instanceof Map) { appendMap(sb, (Map) value); } else if (value instanceof Iterable) { appendIterable(sb, (Iterable) value); } else { sb.append(String.valueOf(value)); } }
private static void appendMap(StringBuilder sb, Map attributes) { for (Object entry : sort(attributes).entrySet()) { sb.append(((Map.Entry) entry).getKey()); sb.append(DELIMITER); appendObject(sb, ((Map.Entry) entry).getValue()); sb.append(DELIMITER); } }
private static String of(Map... maps) { StringBuilder sb = new StringBuilder(); for (Map map : maps) { appendMap(sb, map); } return DigestUtils.sha256Hex(sb.toString()); }
private static void appendIterable(StringBuilder sb, Iterable value) { List sorted = Lists.newArrayList(value); Collections.sort(sorted); for (Object o : sorted) { appendObject(sb, o); sb.append(DELIMITER); } }
private static void appendIndexType(StringBuilder sb, IndexDefinition.Type type) { appendMap(sb, type.getAttributes()); }
private static void appendIterable(StringBuilder sb, Iterable value) { List sorted = Lists.newArrayList(value); Collections.sort(sorted); for (Object o : sorted) { appendObject(sb, o); sb.append(DELIMITER); } }
static String of(IndexDefinition.Index index) { return of(index.getSettings().getAsMap(), index.getTypes()); }
private static void appendObject(StringBuilder sb, Object value) { if (value instanceof IndexDefinitions.IndexType) { appendIndexType(sb, (IndexDefinitions.IndexType) value); } else if (value instanceof Map) { appendMap(sb, (Map) value); } else if (value instanceof Iterable) { appendIterable(sb, (Iterable) value); } else { sb.append(String.valueOf(value)); } }
private static void appendMap(StringBuilder sb, Map attributes) { for (Object entry : sort(attributes).entrySet()) { sb.append(((Map.Entry) entry).getKey()); sb.append(DELIMITER); appendObject(sb, ((Map.Entry) entry).getValue()); sb.append(DELIMITER); } }
private static String of(Map... maps) { StringBuilder sb = new StringBuilder(); for (Map map : maps) { appendMap(sb, map); } return DigestUtils.sha256Hex(sb.toString()); }
@Test public void of() { IndexDefinition.Index indexV1 = new IndexDefinition.Index(createIndex()); String hashV1 = IndexDefinitionHash.of(indexV1); assertThat(hashV1).isNotEmpty(); // always the same assertThat(hashV1).isEqualTo(IndexDefinitionHash.of(indexV1)); NewIndex newIndexV2 = createIndex(); newIndexV2.getTypes().get("fake").createIntegerField("max"); String hashV2 = IndexDefinitionHash.of(new IndexDefinition.Index(newIndexV2)); assertThat(hashV2).isNotEmpty().isNotEqualTo(hashV1); }
private static void appendIndexType(StringBuilder sb, IndexDefinitions.IndexType type) { appendMap(sb, type.getAttributes()); }
settings.put(index.getSettings()); if (useMetadata) { metadataIndex.setHash(index.getName(), IndexDefinitionHash.of(index)); for (IndexDefinition.Type type : index.getTypes().values()) { metadataIndex.setInitialized(new IndexType(index.getName(), type.getName()), false);
private boolean hasDefinitionChange(Index index) { return metadataIndex.getHash(index.getName()) .map(hash -> { String defHash = IndexDefinitionHash.of(index); return !StringUtils.equals(hash, defHash); }).orElse(true); }
static String of(IndexDefinitions.Index index) { return of(index.getSettings().getAsMap(), index.getTypes()); }
settings.put(index.getSettings()); if (useMetadata) { metadataIndex.setHash(index.getName(), IndexDefinitionHash.of(index)); for (IndexDefinitions.IndexType type : index.getTypes().values()) { metadataIndex.setInitialized(new IndexType(index.getName(), type.getName()), false);