@Test public void buildQueryStringOfLog() throws Exception { String result = store.buildQueryString(ElasticSearchStore.RecordType.LOG, "FLOWSTATS"); assertThat(result.contains(TsdrRecordPayload.ELK_DATA_CATEGORY + ":\\\"FLOWSTATS\\\"")).isTrue(); result = store.buildQueryString(ElasticSearchStore.RecordType.LOG, "[NID=][DC=FLOWSTATS][RK=][MN=]"); assertThat(result.contains(TsdrRecordPayload.ELK_DATA_CATEGORY + ":\\\"FLOWSTATS\\\"")).isTrue(); result = store.buildQueryString(ElasticSearchStore.RecordType.LOG, "[NID=][DC=FLOWSTATS][RK=][MN=PacketCount]"); assertThat(result.contains(TsdrRecordPayload.ELK_DATA_CATEGORY + ":\\\"FLOWSTATS\\\"")).isTrue(); assertThat(result.contains("PacketCount")).isFalse(); result = store.buildQueryString(ElasticSearchStore.RecordType.LOG, "[NID=][DC=FLOWSTATS][RK=][RA=key:value]"); assertThat(result.contains(TsdrRecordPayload.ELK_DATA_CATEGORY + ":\\\"FLOWSTATS\\\"")).isTrue(); assertThat(result.contains(TsdrRecordPayload.ELK_RA_KEY_NAME + ":\\\"key\\\"")).isTrue(); assertThat(result.contains(TsdrRecordPayload.ELK_RA_KEY_VALUE + ":\\\"value\\\"")).isTrue(); }
String buildQueryString(RecordType type, String tsdrKey) { StringBuffer queryBuffer = new StringBuffer(); appendCondition(queryBuffer, TsdrRecordPayload.ELK_DATA_CATEGORY, resolveDataCategory(tsdrKey)); try { Long timestamp = FormatUtil.getTimeStampFromTSDRKey(tsdrKey); if (timestamp != null) { appendCondition(queryBuffer, TsdrRecordPayload.ELK_TIMESTAMP, String.valueOf(timestamp)); } } catch (NumberFormatException e) { } if (type == RecordType.METRIC) { appendCondition(queryBuffer, TsdrRecordPayload.ELK_NODE_ID, FormatUtil.getNodeIdFromTSDRKey(tsdrKey)); appendCondition(queryBuffer, TsdrRecordPayload.ELK_METRIC_NAME, FormatUtil.getMetriNameFromTSDRKey(tsdrKey)); List<RecordKeys> recKeys = FormatUtil.getRecordKeysFromTSDRKey(tsdrKey); if (recKeys != null) { for (RecordKeys recKey : recKeys) { appendCondition(queryBuffer, TsdrRecordPayload.ELK_RK_KEY_NAME, recKey.getKeyName()); appendCondition(queryBuffer, TsdrRecordPayload.ELK_RK_KEY_VALUE, recKey.getKeyValue()); } } } if (type == RecordType.LOG) { List<RecordAttributes> recAttrs = FormatUtil.getRecordAttributesFromTSDRKey(tsdrKey); if (recAttrs != null) { for (RecordAttributes recAttr : recAttrs) { appendCondition(queryBuffer, TsdrRecordPayload.ELK_RA_KEY_NAME, recAttr.getName()); appendCondition(queryBuffer, TsdrRecordPayload.ELK_RA_KEY_VALUE, recAttr.getValue()); } } } return queryBuffer.toString(); }
ElasticSearchStore extends AbstractScheduledService implements AutoCloseable { String buildQueryString(RecordType type, String tsdrKey) { StringBuffer queryBuffer = new StringBuffer(); appendCondition(queryBuffer, TsdrRecordPayload.ELK_DATA_CATEGORY, resolveDataCategory(tsdrKey)); try { Long timestamp = FormatUtil.getTimeStampFromTSDRKey(tsdrKey); if (timestamp != null) { appendCondition(queryBuffer, TsdrRecordPayload.ELK_TIMESTAMP, String.valueOf(timestamp)); } } catch (NumberFormatException e) { } if (type == RecordType.METRIC) { appendCondition(queryBuffer, TsdrRecordPayload.ELK_NODE_ID, FormatUtil.getNodeIdFromTSDRKey(tsdrKey)); appendCondition(queryBuffer, TsdrRecordPayload.ELK_METRIC_NAME, FormatUtil.getMetriNameFromTSDRKey(tsdrKey)); List<RecordKeys> recKeys = FormatUtil.getRecordKeysFromTSDRKey(tsdrKey); if (recKeys != null) { for (RecordKeys recKey : recKeys) { appendCondition(queryBuffer, TsdrRecordPayload.ELK_RK_KEY_NAME, recKey.getKeyName()); appendCondition(queryBuffer, TsdrRecordPayload.ELK_RK_KEY_VALUE, recKey.getKeyValue()); } } } if (type == RecordType.LOG) { List<RecordAttributes> recAttrs = FormatUtil.getRecordAttributesFromTSDRKey(tsdrKey); if (recAttrs != null) { for (RecordAttributes recAttr : recAttrs) { appendCondition(queryBuffer, TsdrRecordPayload.ELK_RA_KEY_NAME, recAttr.getName()); appendCondition(queryBuffer, TsdrRecordPayload.ELK_RA_KEY_VALUE, recAttr.getValue()); } } } return queryBuffer.toString(); } }
ElasticSearchStore extends AbstractScheduledService implements AutoCloseable { String buildQueryString(RecordType type, String tsdrKey) { StringBuffer queryBuffer = new StringBuffer(); appendCondition(queryBuffer, TsdrRecordPayload.ELK_DATA_CATEGORY, resolveDataCategory(tsdrKey)); try { Long timestamp = FormatUtil.getTimeStampFromTSDRKey(tsdrKey); if (timestamp != null) { appendCondition(queryBuffer, TsdrRecordPayload.ELK_TIMESTAMP, String.valueOf(timestamp)); } } catch (NumberFormatException e) { } if (type == RecordType.METRIC) { appendCondition(queryBuffer, TsdrRecordPayload.ELK_NODE_ID, FormatUtil.getNodeIdFromTSDRKey(tsdrKey)); appendCondition(queryBuffer, TsdrRecordPayload.ELK_METRIC_NAME, FormatUtil.getMetriNameFromTSDRKey(tsdrKey)); List<RecordKeys> recKeys = FormatUtil.getRecordKeysFromTSDRKey(tsdrKey); if (recKeys != null) { for (RecordKeys recKey : recKeys) { appendCondition(queryBuffer, TsdrRecordPayload.ELK_RK_KEY_NAME, recKey.getKeyName()); appendCondition(queryBuffer, TsdrRecordPayload.ELK_RK_KEY_VALUE, recKey.getKeyValue()); } } } if (type == RecordType.LOG) { List<RecordAttributes> recAttrs = FormatUtil.getRecordAttributesFromTSDRKey(tsdrKey); if (recAttrs != null) { for (RecordAttributes recAttr : recAttrs) { appendCondition(queryBuffer, TsdrRecordPayload.ELK_RA_KEY_NAME, recAttr.getName()); appendCondition(queryBuffer, TsdrRecordPayload.ELK_RA_KEY_VALUE, recAttr.getValue()); } } } return queryBuffer.toString(); } @Inject  ElasticSearchStore(); @VisibleForTesting  ElasticSearchStore(Map<String, String> properties, JestClient client); }
ElasticSearchStore extends AbstractScheduledService implements AutoCloseable { String buildQueryString(RecordType type, String tsdrKey) { StringBuffer queryBuffer = new StringBuffer(); appendCondition(queryBuffer, TsdrRecordPayload.ELK_DATA_CATEGORY, resolveDataCategory(tsdrKey)); try { Long timestamp = FormatUtil.getTimeStampFromTSDRKey(tsdrKey); if (timestamp != null) { appendCondition(queryBuffer, TsdrRecordPayload.ELK_TIMESTAMP, String.valueOf(timestamp)); } } catch (NumberFormatException e) { } if (type == RecordType.METRIC) { appendCondition(queryBuffer, TsdrRecordPayload.ELK_NODE_ID, FormatUtil.getNodeIdFromTSDRKey(tsdrKey)); appendCondition(queryBuffer, TsdrRecordPayload.ELK_METRIC_NAME, FormatUtil.getMetriNameFromTSDRKey(tsdrKey)); List<RecordKeys> recKeys = FormatUtil.getRecordKeysFromTSDRKey(tsdrKey); if (recKeys != null) { for (RecordKeys recKey : recKeys) { appendCondition(queryBuffer, TsdrRecordPayload.ELK_RK_KEY_NAME, recKey.getKeyName()); appendCondition(queryBuffer, TsdrRecordPayload.ELK_RK_KEY_VALUE, recKey.getKeyValue()); } } } if (type == RecordType.LOG) { List<RecordAttributes> recAttrs = FormatUtil.getRecordAttributesFromTSDRKey(tsdrKey); if (recAttrs != null) { for (RecordAttributes recAttr : recAttrs) { appendCondition(queryBuffer, TsdrRecordPayload.ELK_RA_KEY_NAME, recAttr.getName()); appendCondition(queryBuffer, TsdrRecordPayload.ELK_RA_KEY_VALUE, recAttr.getValue()); } } } return queryBuffer.toString(); } @Inject  ElasticSearchStore(); @VisibleForTesting  ElasticSearchStore(Map<String, String> properties, JestClient client); @PostConstruct void init(); @Override @PreDestroy void close(); }
ElasticSearchStore extends AbstractScheduledService implements AutoCloseable { String buildQueryString(RecordType type, String tsdrKey) { StringBuffer queryBuffer = new StringBuffer(); appendCondition(queryBuffer, TsdrRecordPayload.ELK_DATA_CATEGORY, resolveDataCategory(tsdrKey)); try { Long timestamp = FormatUtil.getTimeStampFromTSDRKey(tsdrKey); if (timestamp != null) { appendCondition(queryBuffer, TsdrRecordPayload.ELK_TIMESTAMP, String.valueOf(timestamp)); } } catch (NumberFormatException e) { } if (type == RecordType.METRIC) { appendCondition(queryBuffer, TsdrRecordPayload.ELK_NODE_ID, FormatUtil.getNodeIdFromTSDRKey(tsdrKey)); appendCondition(queryBuffer, TsdrRecordPayload.ELK_METRIC_NAME, FormatUtil.getMetriNameFromTSDRKey(tsdrKey)); List<RecordKeys> recKeys = FormatUtil.getRecordKeysFromTSDRKey(tsdrKey); if (recKeys != null) { for (RecordKeys recKey : recKeys) { appendCondition(queryBuffer, TsdrRecordPayload.ELK_RK_KEY_NAME, recKey.getKeyName()); appendCondition(queryBuffer, TsdrRecordPayload.ELK_RK_KEY_VALUE, recKey.getKeyValue()); } } } if (type == RecordType.LOG) { List<RecordAttributes> recAttrs = FormatUtil.getRecordAttributesFromTSDRKey(tsdrKey); if (recAttrs != null) { for (RecordAttributes recAttr : recAttrs) { appendCondition(queryBuffer, TsdrRecordPayload.ELK_RA_KEY_NAME, recAttr.getName()); appendCondition(queryBuffer, TsdrRecordPayload.ELK_RA_KEY_VALUE, recAttr.getValue()); } } } return queryBuffer.toString(); } @Inject  ElasticSearchStore(); @VisibleForTesting  ElasticSearchStore(Map<String, String> properties, JestClient client); @PostConstruct void init(); @Override @PreDestroy void close();  }