Esempio n. 1
0
 @Override
 public Map<String, Table> loadAll(Collection<String> keys) {
   logger.info("Load all called for multiple keys");
   MultiGetResponse response =
       elasticsearchConnection
           .getClient()
           .prepareMultiGet()
           .add(TABLE_META_INDEX, TABLE_META_TYPE, keys)
           .execute()
           .actionGet();
   Map<String, Table> tables = Maps.newHashMap();
   for (MultiGetItemResponse multiGetItemResponse : response) {
     try {
       Table table =
           objectMapper.readValue(
               multiGetItemResponse.getResponse().getSourceAsString(), Table.class);
       tables.put(table.getName(), table);
     } catch (Exception e) {
       throw new RuntimeException("Error getting data for table: " + multiGetItemResponse.getId());
     }
   }
   logger.info("Loaded value count: " + tables.size());
   return tables;
 }
Esempio n. 2
0
 @Override
 public void store(String key, Table value) {
   if (key == null || value == null || value.getName() == null) {
     throw new RuntimeException(String.format("Illegal Store Request - %s - %s", key, value));
   }
   logger.info("Storing key: " + key);
   try {
     elasticsearchConnection
         .getClient()
         .prepareIndex()
         .setIndex(TABLE_META_INDEX)
         .setType(TABLE_META_TYPE)
         .setConsistencyLevel(WriteConsistencyLevel.ALL)
         .setSource(objectMapper.writeValueAsString(value))
         .setId(key)
         .setRefresh(true)
         .execute()
         .actionGet();
   } catch (JsonProcessingException e) {
     throw new RuntimeException("Error saving meta: ", e);
   }
 }