use of org.apache.inlong.manager.common.pojo.audit.AuditInfo in project incubator-inlong by apache.
the class AuditServiceTest method testQueryFromMySQL.
@Test
public void testQueryFromMySQL() throws IOException {
AuditRequest request = new AuditRequest();
request.setAuditIds(Arrays.asList("3", "4"));
request.setInlongGroupId("g1");
request.setInlongStreamId("s1");
request.setDt("2022-01-01");
List<AuditVO> result = new ArrayList<>();
AuditVO auditVO = new AuditVO();
auditVO.setAuditId("3");
auditVO.setAuditSet(Arrays.asList(new AuditInfo("2022-01-01 00:00:00", 123L), new AuditInfo("2022-01-01 00:01:00", 124L)));
result.add(auditVO);
Assert.assertNotNull(result);
// close real test for testQueryFromMySQL due to date_format function not support in h2
// Assert.assertNotNull(auditService.listByCondition(request));
}
use of org.apache.inlong.manager.common.pojo.audit.AuditInfo in project incubator-inlong by apache.
the class AuditServiceImpl method listByCondition.
/**
* Query audit data for list by condition
*
* @param request The audit request of query condition
* @return The result of query
*/
@Override
public List<AuditVO> listByCondition(AuditRequest request) throws IOException {
LOGGER.info("begin query audit list request={}", request);
Preconditions.checkNotNull(request, "request is null");
List<AuditVO> result = new ArrayList<>();
AuditQuerySource querySource = AuditQuerySource.valueOf(auditQuerySource);
for (String auditId : request.getAuditIds()) {
if (AuditQuerySource.MYSQL == querySource) {
String format = "%Y-%m-%d %H:%i:00";
// Support min agg at now
DateTimeFormatter forPattern = DateTimeFormat.forPattern("yyyy-MM-dd");
DateTime dtDate = forPattern.parseDateTime(request.getDt());
String eDate = dtDate.plusDays(1).toString(forPattern);
List<Map<String, Object>> sumList = auditEntityMapper.sumByLogTs(request.getInlongGroupId(), request.getInlongStreamId(), auditId, request.getDt(), eDate, format);
List<AuditInfo> auditSet = sumList.stream().map(s -> {
AuditInfo vo = new AuditInfo();
vo.setLogTs((String) s.get("logTs"));
vo.setCount(((BigDecimal) s.get("total")).longValue());
return vo;
}).collect(Collectors.toList());
result.add(new AuditVO(auditId, auditSet));
} else if (AuditQuerySource.ELASTICSEARCH == querySource) {
String index = String.format("%s_%s", request.getDt().replaceAll("-", ""), auditId);
if (elasticsearchApi.indexExists(index)) {
SearchResponse response = elasticsearchApi.search(toAuditSearchRequest(index, request.getInlongGroupId(), request.getInlongStreamId()));
final List<Aggregation> aggregations = response.getAggregations().asList();
if (CollectionUtils.isNotEmpty(aggregations)) {
ParsedTerms terms = (ParsedTerms) aggregations.get(0);
if (CollectionUtils.isNotEmpty(terms.getBuckets())) {
List<AuditInfo> auditSet = terms.getBuckets().stream().map(bucket -> {
AuditInfo vo = new AuditInfo();
vo.setLogTs(bucket.getKeyAsString());
vo.setCount((long) ((ParsedSum) bucket.getAggregations().asList().get(0)).getValue());
return vo;
}).collect(Collectors.toList());
result.add(new AuditVO(auditId, auditSet));
}
}
} else {
LOGGER.warn("Elasticsearch index={} not exists", index);
}
}
}
LOGGER.info("success to query audit list for request={}", request);
return result;
}
Aggregations