private void deleteAllIndex() throws ClientProtocolException, URISyntaxException, IOException { Set<String> invnames = getAllInventoryNames(); for (String invname : invnames) { deleteIndex(invname); } }
private void createIndexIfNotExists() throws Exception { for (IndexerInfo info : voClassToIndexerMapping.values()) { try { doCreateIndexIfNotExists(info.inventoryName); } catch (Exception ex) { if (stopIfCreateIndexFailed) { throw ex; } else { logger.warn(ex.getMessage(), ex); } } } }
private void generateSqlTriggerText(Class<?> clazz, StringBuilder sb) { SqlTrigger st = clazz.getAnnotation(SqlTrigger.class); if (st != null) { doGenerateSqlTriggerText(st, clazz, sb); } SqlTriggers sts = clazz.getAnnotation(SqlTriggers.class); if (sts != null) { for (SqlTrigger stt : sts.triggers()) { doGenerateSqlTriggerText(stt, clazz, sb); } } }
@Override public boolean start() { try { httpClient = new DefaultHttpClient(new PoolingClientConnectionManager()); bulkUri = makeURI(elasticSearchBaseUrl, "_bulk"); /* only for debugging */ if (deleteAllIndexWhenStart) { try { deleteIndex(null); } catch (Exception ex) { logger.warn(String.format("Failed to delete all index"), ex); } } populateExtensions(); populateTriggerVOs(); populateInventoryIndexer(); dumpInventoryIndexer(); createIndexIfNotExists(); bus.registerService(this); } catch (Exception e) { throw new CloudRuntimeException(e); } return true; }
Set<String> validInventoryNames = getAllInventoryNames(); deleteIndex(invname); doCreateIndexIfNotExists(invname); fireSearchIndexRecreateExtension(invname); deleteAllIndex(); createIndexIfNotExists(); for (String invname : getAllInventoryNames()) { fireSearchIndexRecreateExtension(invname);
@Override public void afterCommit(Operation op, Class<?>... entityClass) { ESBulkBuilder bbuilder = new ESBulkBuilder(); for (Class<?> vo : entityClass) { if (!triggerVOs.contains(vo)) { logger.trace(String.format("Class[%s] is not annotated by @TriggerIndex, no index operation will be proceeded", vo.getName())); continue; } if (op == Operation.PERSIST || op == Operation.UPDATE) { Map<String, Set<String>> vmap = getUuidsOfVOToIndexFromInsertVOUpdateVO(vo, op); bbuilder = addDocToIndexToESBuilder(bbuilder, vmap); } else if (op == Operation.REMOVE) { Pair<Map<String, Set<String>>, Map<String, Set<String>>> pair = getVOUuidsToDeleteOrIndexFromDeleteVO(vo); Map<String, Set<String>> toIndex = pair.second(); bbuilder = addDocToIndexToESBuilder(bbuilder, toIndex); Map<String, Set<String>> toDelete = pair.first(); bbuilder = addDocToDeleteToESBuilder(bbuilder, toDelete); } } if (!bbuilder.isEmpty()) { sendBulk(bbuilder.toString(), bbuilder.getAffectedInventoryNames()); } }
private void reindexInventory(String inventoryName, Set<String> uuids) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { IndexerInfo info = getIndexerInfoByInventoryName(inventoryName); ESBulkBuilder bbuilder = new ESBulkBuilder(); List<InventoryDoc> docs = buildDoc(info, uuids); if (docs.isEmpty()) { return; } for (InventoryDoc doc : docs) { bbuilder.addIndexBulk(doc.getInventoryName().toLowerCase(), doc.getInventoryName(), doc); } if (!bbuilder.isEmpty()) { sendBulk(bbuilder.toString(), bbuilder.getAffectedInventoryNames()); logger.debug(String.format("successfully reindex all data for inventory[%s]", inventoryName)); } }
private void doCreateIndexIfNotExists(String inventoryName) throws URISyntaxException, ClientProtocolException, IOException, JSONException { final String indexName = inventoryName.toLowerCase(); URI uri = makeURI(elasticSearchBaseUrl, indexName); HttpHead head = new HttpHead(uri); ResponseHandler<Boolean> rspHandler = new ResponseHandler<Boolean>() { if (!ret) { HttpPut put = new HttpPut(uri); String body = createIndexSetting().toString(); put.setEntity(new StringEntity(body)); ResponseHandler<Void> putHandler = new ResponseHandler<Void>() {
private void handle(final APIDeleteSearchIndexMsg msg) throws URISyntaxException, ClientProtocolException, IOException { if (msg.getIndexName() != null) { deleteIndex(msg.getIndexName()); } else { deleteAllIndex(); } APIDeleteSearchIndexEvent evt = new APIDeleteSearchIndexEvent(msg.getId()); bus.publish(evt); }
private ESBulkBuilder addDocToIndexToESBuilder(ESBulkBuilder bbuilder, Map<String, Set<String>> vmap) { try { for (Map.Entry<String, Set<String>> e : vmap.entrySet()) { IndexerInfo info = voClassToIndexerMapping.get(e.getKey()); if (info == null) { String err = String .format("%s has an entry in InsertVO/UpdateVO table, but there is no indexer matching it. It can be intended if the entity inherits from another entity but itself is not wanted to be indexed. Otherwise it's most likely a bug", e.getKey()); logger.warn(err); continue; } List<InventoryDoc> docs = buildDoc(info, e.getValue()); if (docs.isEmpty()) { continue; } for (InventoryDoc doc : docs) { bbuilder.addIndexBulk(doc.getInventoryName().toLowerCase(), doc.getInventoryName(), doc); } } } catch (Exception e) { throw new CloudRuntimeException(e); } return bbuilder; }