@Test public void testGetSingleInvalidId() throws Exception { Table table = tableMetadataManager.get(TestUtils.TEST_TABLE_NAME); doThrow(FoxtrotExceptions.createMissingDocumentException(table, UUID.randomUUID() .toString())).when(dataStore) .get(any(Table.class), anyString()); try { queryStore.get(TestUtils.TEST_TABLE_NAME, UUID.randomUUID() .toString()); fail(); } catch (FoxtrotException dse) { assertEquals(ErrorCode.DOCUMENT_NOT_FOUND, dse.getCode()); } }
@Override @Timed public Document get(String table, String id) { table = ElasticsearchUtils.getValidTableName(table); Table fxTable; if(!tableMetadataManager.exists(table)) { throw FoxtrotExceptions.createBadRequestException(table, String.format(UNKNOWN_TABLE_ERROR_MESSAGE, table)); } fxTable = tableMetadataManager.get(table); String lookupKey; SearchResponse searchResponse = connection.getClient() .prepareSearch(ElasticsearchUtils.getIndices(table)) .setTypes(ElasticsearchUtils.DOCUMENT_TYPE_NAME) .setQuery(boolQuery().filter(termQuery(ElasticsearchUtils.DOCUMENT_META_ID_FIELD_NAME, id))) .setFetchSource(false) .setSize(1) .execute() .actionGet(); if(searchResponse.getHits() .getTotalHits() == 0) { logger.warn("Going into compatibility mode, looks using passed in ID as the data store id: {}", id); lookupKey = id; } else { lookupKey = searchResponse.getHits() .getHits()[0].getId(); logger.debug("Translated lookup key for {} is {}.", id, lookupKey); } return dataStore.get(fxTable, lookupKey); }
ElasticsearchQueryStore implements QueryStore { @Override @Timed public Document get(String table, String id) { table = ElasticsearchUtils.getValidTableName(table); Table fxTable; if(!tableMetadataManager.exists(table)) { throw FoxtrotExceptions.createBadRequestException(table, String.format(UNKNOWN_TABLE_ERROR_MESSAGE, table)); } fxTable = tableMetadataManager.get(table); String lookupKey; SearchResponse searchResponse = connection.getClient() .prepareSearch(ElasticsearchUtils.getIndices(table)) .setTypes(ElasticsearchUtils.DOCUMENT_TYPE_NAME) .setQuery(boolQuery().filter(termQuery(ElasticsearchUtils.DOCUMENT_META_ID_FIELD_NAME, id))) .setFetchSource(false) .setSize(1) .execute() .actionGet(); if(searchResponse.getHits() .getTotalHits() == 0) { logger.warn("Going into compatibility mode, looks using passed in ID as the data store id: {}", id); lookupKey = id; } else { lookupKey = searchResponse.getHits() .getHits()[0].getId(); logger.debug("Translated lookup key for {} is {}.", id, lookupKey); } return dataStore.get(fxTable, lookupKey); } }
ElasticsearchQueryStore implements QueryStore { @Override @Timed public Document get(String table, String id) { table = ElasticsearchUtils.getValidTableName(table); Table fxTable; if(!tableMetadataManager.exists(table)) { throw FoxtrotExceptions.createBadRequestException(table, String.format(UNKNOWN_TABLE_ERROR_MESSAGE, table)); } fxTable = tableMetadataManager.get(table); String lookupKey; SearchResponse searchResponse = connection.getClient() .prepareSearch(ElasticsearchUtils.getIndices(table)) .setTypes(ElasticsearchUtils.DOCUMENT_TYPE_NAME) .setQuery(boolQuery().filter(termQuery(ElasticsearchUtils.DOCUMENT_META_ID_FIELD_NAME, id))) .setFetchSource(false) .setSize(1) .execute() .actionGet(); if(searchResponse.getHits() .getTotalHits() == 0) { logger.warn("Going into compatibility mode, looks using passed in ID as the data store id: {}", id); lookupKey = id; } else { lookupKey = searchResponse.getHits() .getHits()[0].getId(); logger.debug("Translated lookup key for {} is {}.", id, lookupKey); } return dataStore.get(fxTable, lookupKey); } @Inject  ElasticsearchQueryStore(TableMetadataManager tableMetadataManager,
                                   ElasticsearchConnection connection,
                                   DataStore dataStore,
                                   List<IndexerEventMutator> mutators,
                                   ObjectMapper mapper,
                                   CardinalityConfig cardinalityConfig); }
ElasticsearchQueryStore implements QueryStore { @Override @Timed public Document get(String table, String id) { table = ElasticsearchUtils.getValidTableName(table); Table fxTable; if(!tableMetadataManager.exists(table)) { throw FoxtrotExceptions.createBadRequestException(table, String.format(UNKNOWN_TABLE_ERROR_MESSAGE, table)); } fxTable = tableMetadataManager.get(table); String lookupKey; SearchResponse searchResponse = connection.getClient() .prepareSearch(ElasticsearchUtils.getIndices(table)) .setTypes(ElasticsearchUtils.DOCUMENT_TYPE_NAME) .setQuery(boolQuery().filter(termQuery(ElasticsearchUtils.DOCUMENT_META_ID_FIELD_NAME, id))) .setFetchSource(false) .setSize(1) .execute() .actionGet(); if(searchResponse.getHits() .getTotalHits() == 0) { logger.warn("Going into compatibility mode, looks using passed in ID as the data store id: {}", id); lookupKey = id; } else { lookupKey = searchResponse.getHits() .getHits()[0].getId(); logger.debug("Translated lookup key for {} is {}.", id, lookupKey); } return dataStore.get(fxTable, lookupKey); } @Inject  ElasticsearchQueryStore(TableMetadataManager tableMetadataManager,
                                   ElasticsearchConnection connection,
                                   DataStore dataStore,
                                   List<IndexerEventMutator> mutators,
                                   ObjectMapper mapper,
                                   CardinalityConfig cardinalityConfig); @Override @Timed void initializeTable(String table); @Override @Timed void save(String table, Document document); @Override @Timed void save(String table, List<Document> documents); @Override @Timed Document get(String table, String id); @Override List<Document> getAll(String table, List<String> ids); @Override @Timed List<Document> getAll(String table, List<String> ids, boolean bypassMetalookup); @Override void cleanupAll(); @Override @Timed void cleanup(final String table); @Override @Timed void cleanup(Set<String> tables); @Override ClusterHealthResponse getClusterHealth(); @Override NodesStatsResponse getNodeStats(); @Override IndicesStatsResponse getIndicesStats(); @Override TableFieldMapping getFieldMappings(String table); }
ElasticsearchQueryStore implements QueryStore { @Override @Timed public Document get(String table, String id) { table = ElasticsearchUtils.getValidTableName(table); Table fxTable; if(!tableMetadataManager.exists(table)) { throw FoxtrotExceptions.createBadRequestException(table, String.format(UNKNOWN_TABLE_ERROR_MESSAGE, table)); } fxTable = tableMetadataManager.get(table); String lookupKey; SearchResponse searchResponse = connection.getClient() .prepareSearch(ElasticsearchUtils.getIndices(table)) .setTypes(ElasticsearchUtils.DOCUMENT_TYPE_NAME) .setQuery(boolQuery().filter(termQuery(ElasticsearchUtils.DOCUMENT_META_ID_FIELD_NAME, id))) .setFetchSource(false) .setSize(1) .execute() .actionGet(); if(searchResponse.getHits() .getTotalHits() == 0) { logger.warn("Going into compatibility mode, looks using passed in ID as the data store id: {}", id); lookupKey = id; } else { lookupKey = searchResponse.getHits() .getHits()[0].getId(); logger.debug("Translated lookup key for {} is {}.", id, lookupKey); } return dataStore.get(fxTable, lookupKey); } @Inject  ElasticsearchQueryStore(TableMetadataManager tableMetadataManager,
                                   ElasticsearchConnection connection,
                                   DataStore dataStore,
                                   List<IndexerEventMutator> mutators,
                                   ObjectMapper mapper,
                                   CardinalityConfig cardinalityConfig); @Override @Timed void initializeTable(String table); @Override @Timed void save(String table, Document document); @Override @Timed void save(String table, List<Document> documents); @Override @Timed Document get(String table, String id); @Override List<Document> getAll(String table, List<String> ids); @Override @Timed List<Document> getAll(String table, List<String> ids, boolean bypassMetalookup); @Override void cleanupAll(); @Override @Timed void cleanup(final String table); @Override @Timed void cleanup(Set<String> tables); @Override ClusterHealthResponse getClusterHealth(); @Override NodesStatsResponse getNodeStats(); @Override IndicesStatsResponse getIndicesStats(); @Override TableFieldMapping getFieldMappings(String table);  }