Search in sources :

Example 1 with QueryResult

use of org.influxdb.dto.QueryResult in project camel by apache.

the class InfluxDbProducer method doQuery.

private void doQuery(Exchange exchange, String dataBaseName, String retentionPolicy) {
    String query = calculateQuery(exchange);
    Query influxdbQuery = new Query(query, dataBaseName);
    QueryResult resultSet = connection.query(influxdbQuery);
    exchange.getOut().setBody(resultSet);
}
Also used : QueryResult(org.influxdb.dto.QueryResult) Query(org.influxdb.dto.Query)

Example 2 with QueryResult

use of org.influxdb.dto.QueryResult in project cas by apereo.

the class InfluxDbCasEventRepository method load.

@Override
public Collection<? extends CasEvent> load() {
    final List<CasEvent> events = new ArrayList<>();
    final QueryResult results = influxDbConnectionFactory.query(MEASUREMENT);
    results.getResults().stream().forEach(r -> r.getSeries().forEach(s -> {
        try {
            final Iterator<List<Object>> it = s.getValues().iterator();
            while (it.hasNext()) {
                final CasEvent event = new CasEvent();
                final List<Object> row = it.next();
                for (int i = 0; i < s.getColumns().size(); i++) {
                    final String colName = s.getColumns().get(i);
                    switch(colName) {
                        case "time":
                            break;
                        case "id":
                            event.putId(row.get(i).toString());
                            break;
                        case "type":
                            event.setType(row.get(i).toString());
                            break;
                        case "principalId":
                            event.setPrincipalId(row.get(i).toString());
                            break;
                        case "creationTime":
                            event.setCreationTime(row.get(i).toString());
                            break;
                        default:
                            event.put(colName, row.get(i).toString());
                    }
                }
                events.add(event);
            }
        } catch (final Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
    }));
    return events;
}
Also used : Iterator(java.util.Iterator) SneakyThrows(lombok.SneakyThrows) Collection(java.util.Collection) QueryResult(org.influxdb.dto.QueryResult) InfluxDbConnectionFactory(org.apereo.cas.influxdb.InfluxDbConnectionFactory) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) PreDestroy(javax.annotation.PreDestroy) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ReflectionUtils(org.springframework.util.ReflectionUtils) Map(java.util.Map) Point(org.influxdb.dto.Point) AllArgsConstructor(lombok.AllArgsConstructor) QueryResult(org.influxdb.dto.QueryResult) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with QueryResult

use of org.influxdb.dto.QueryResult in project cas by apereo.

the class InfluxDbConnectionFactoryTests method verifyWritePoint.

@Test
public void verifyWritePoint() {
    final Point p = Point.measurement("events").time(System.currentTimeMillis(), TimeUnit.MILLISECONDS).addField("hostname", "cas.example.org").build();
    factory.write(p, CAS_EVENTS_DATABASE);
    final QueryResult result = factory.query("*", "events", CAS_EVENTS_DATABASE);
    final InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
    final List<InfluxEvent> resultEvents = resultMapper.toPOJO(result, InfluxEvent.class);
    assertNotNull(resultEvents);
    assertEquals(1, resultEvents.size());
    assertEquals("cas.example.org", resultEvents.iterator().next().hostname);
}
Also used : QueryResult(org.influxdb.dto.QueryResult) InfluxDBResultMapper(org.influxdb.impl.InfluxDBResultMapper) Point(org.influxdb.dto.Point) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

QueryResult (org.influxdb.dto.QueryResult)3 Point (org.influxdb.dto.Point)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 TimeUnit (java.util.concurrent.TimeUnit)1 PreDestroy (javax.annotation.PreDestroy)1 AllArgsConstructor (lombok.AllArgsConstructor)1 SneakyThrows (lombok.SneakyThrows)1 Slf4j (lombok.extern.slf4j.Slf4j)1 InfluxDbConnectionFactory (org.apereo.cas.influxdb.InfluxDbConnectionFactory)1 Query (org.influxdb.dto.Query)1 InfluxDBResultMapper (org.influxdb.impl.InfluxDBResultMapper)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 ReflectionUtils (org.springframework.util.ReflectionUtils)1