Search in sources :

Example 1 with Data

use of io.gravitee.repository.analytics.query.response.histogram.Data in project gravitee-management-rest-api by gravitee-io.

the class HealthCheckServiceImpl method convertBucket.

private io.gravitee.management.model.analytics.Bucket convertBucket(List<Long> timestamps, long from, long interval, io.gravitee.repository.analytics.query.response.histogram.Bucket bucket) {
    io.gravitee.management.model.analytics.Bucket analyticsBucket = new io.gravitee.management.model.analytics.Bucket();
    analyticsBucket.setName(bucket.name());
    analyticsBucket.setField(bucket.field());
    List<io.gravitee.management.model.analytics.Bucket> childBuckets = new ArrayList<>();
    for (io.gravitee.repository.analytics.query.response.histogram.Bucket childBucket : bucket.buckets()) {
        childBuckets.add(convertBucket(timestamps, from, interval, childBucket));
    }
    for (Map.Entry<String, List<Data>> dataBucket : bucket.data().entrySet()) {
        io.gravitee.management.model.analytics.Bucket analyticsDataBucket = new io.gravitee.management.model.analytics.Bucket();
        analyticsDataBucket.setName(dataBucket.getKey());
        final Number[] values = new Number[timestamps.size()];
        for (int i = 0; i < timestamps.size(); i++) {
            values[i] = 0;
        }
        for (Data data : dataBucket.getValue()) {
            values[(int) ((data.timestamp() - from) / interval)] = data.value();
        }
        analyticsDataBucket.setData(values);
        childBuckets.add(analyticsDataBucket);
    }
    analyticsBucket.setBuckets(childBuckets);
    return analyticsBucket;
}
Also used : Data(io.gravitee.repository.analytics.query.response.histogram.Data) Endpoint(io.gravitee.definition.model.Endpoint) FieldBucket(io.gravitee.repository.healthcheck.query.FieldBucket) Bucket(io.gravitee.repository.healthcheck.query.Bucket)

Example 2 with Data

use of io.gravitee.repository.analytics.query.response.histogram.Data in project gravitee-management-rest-api by gravitee-io.

the class AnalyticsServiceImpl method convertBucket.

private Bucket convertBucket(List<Long> timestamps, long from, long interval, io.gravitee.repository.analytics.query.response.histogram.Bucket bucket) {
    Bucket analyticsBucket = new Bucket();
    analyticsBucket.setName(bucket.name());
    analyticsBucket.setField(bucket.field());
    List<Bucket> childBuckets = new ArrayList<>();
    for (io.gravitee.repository.analytics.query.response.histogram.Bucket childBucket : bucket.buckets()) {
        childBuckets.add(convertBucket(timestamps, from, interval, childBucket));
    }
    if (analyticsBucket.getField().equals("application")) {
        // Prepare metadata
        Map<String, Map<String, String>> metadata = new HashMap<>();
        bucket.data().keySet().stream().forEach(app -> {
            metadata.put(app, getApplicationMetadata(app));
        });
        analyticsBucket.setMetadata(metadata);
    } else if (analyticsBucket.getField().equals("api")) {
        // Prepare metadata
        Map<String, Map<String, String>> metadata = new HashMap<>();
        bucket.data().keySet().stream().forEach(api -> {
            metadata.put(api, getAPIMetadata(api));
        });
        analyticsBucket.setMetadata(metadata);
    } else if (analyticsBucket.getField().equals("tenant")) {
        // Prepare metadata
        Map<String, Map<String, String>> metadata = new HashMap<>();
        bucket.data().keySet().stream().forEach(tenant -> {
            metadata.put(tenant, getTenantMetadata(tenant));
        });
        analyticsBucket.setMetadata(metadata);
    }
    for (Map.Entry<String, List<Data>> dataBucket : bucket.data().entrySet()) {
        Bucket analyticsDataBucket = new Bucket();
        analyticsDataBucket.setName(dataBucket.getKey());
        Number[] values = new Number[timestamps.size()];
        for (int i = 0; i < timestamps.size(); i++) {
            values[i] = 0;
        }
        for (Data data : dataBucket.getValue()) {
            values[(int) ((data.timestamp() - from) / interval)] = data.value();
        }
        analyticsDataBucket.setData(values);
        childBuckets.add(analyticsDataBucket);
    }
    analyticsBucket.setBuckets(childBuckets);
    return analyticsBucket;
}
Also used : io.gravitee.management.model.analytics(io.gravitee.management.model.analytics) java.util(java.util) ApiEntity(io.gravitee.management.model.ApiEntity) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ApplicationEntity(io.gravitee.management.model.ApplicationEntity) CountResponse(io.gravitee.repository.analytics.query.count.CountResponse) DateHistogramResponse(io.gravitee.repository.analytics.query.response.histogram.DateHistogramResponse) io.gravitee.repository.analytics.query(io.gravitee.repository.analytics.query) io.gravitee.management.service.exceptions(io.gravitee.management.service.exceptions) DateHistogramQuery(io.gravitee.management.model.analytics.query.DateHistogramQuery) CountQuery(io.gravitee.management.model.analytics.query.CountQuery) GroupByQueryBuilder(io.gravitee.repository.analytics.query.groupby.GroupByQueryBuilder) TenantEntity(io.gravitee.management.model.TenantEntity) AnalyticsRepository(io.gravitee.repository.analytics.api.AnalyticsRepository) Logger(org.slf4j.Logger) AnalyticsException(io.gravitee.repository.analytics.AnalyticsException) GroupByResponse(io.gravitee.repository.analytics.query.groupby.GroupByResponse) Collectors(java.util.stream.Collectors) GroupByQuery(io.gravitee.management.model.analytics.query.GroupByQuery) Component(org.springframework.stereotype.Component) PlanEntity(io.gravitee.management.model.PlanEntity) io.gravitee.management.service(io.gravitee.management.service) Data(io.gravitee.repository.analytics.query.response.histogram.Data) ApplicationStatus(io.gravitee.repository.management.model.ApplicationStatus) io.gravitee.repository.analytics.query(io.gravitee.repository.analytics.query) Data(io.gravitee.repository.analytics.query.response.histogram.Data)

Example 3 with Data

use of io.gravitee.repository.analytics.query.response.histogram.Data in project gravitee-management-rest-api by gravitee-io.

the class AnalyticsServiceImpl method convertBucket.

private Bucket convertBucket(List<Long> timestamps, long from, long interval, io.gravitee.repository.analytics.query.response.histogram.Bucket bucket) {
    Bucket analyticsBucket = new Bucket();
    analyticsBucket.setName(bucket.name());
    analyticsBucket.setField(bucket.field());
    List<Bucket> childBuckets = new ArrayList<>();
    for (io.gravitee.repository.analytics.query.response.histogram.Bucket childBucket : bucket.buckets()) {
        childBuckets.add(convertBucket(timestamps, from, interval, childBucket));
    }
    if (FIELD_APPLICATION.equals(analyticsBucket.getField())) {
        // Prepare metadata
        Map<String, Map<String, String>> metadata = new HashMap<>();
        bucket.data().keySet().forEach(app -> metadata.put(app, getApplicationMetadata(app)));
        analyticsBucket.setMetadata(metadata);
    } else if (FIELD_API.equals(analyticsBucket.getField())) {
        // Prepare metadata
        Map<String, Map<String, String>> metadata = new HashMap<>();
        bucket.data().keySet().forEach(api -> metadata.put(api, getAPIMetadata(api)));
        analyticsBucket.setMetadata(metadata);
    } else if (FIELD_TENANT.equals(analyticsBucket.getField())) {
        // Prepare metadata
        Map<String, Map<String, String>> metadata = new HashMap<>();
        bucket.data().keySet().forEach(tenant -> metadata.put(tenant, getTenantMetadata(tenant)));
        analyticsBucket.setMetadata(metadata);
    }
    for (Map.Entry<String, List<Data>> dataBucket : bucket.data().entrySet()) {
        Bucket analyticsDataBucket = new Bucket();
        analyticsDataBucket.setName(dataBucket.getKey());
        Number[] values = new Number[timestamps.size()];
        for (int i = 0; i < timestamps.size(); i++) {
            values[i] = 0;
        }
        for (Data data : dataBucket.getValue()) {
            values[(int) ((data.timestamp() - from) / interval)] = data.value();
        }
        analyticsDataBucket.setData(values);
        childBuckets.add(analyticsDataBucket);
    }
    analyticsBucket.setBuckets(childBuckets);
    return analyticsBucket;
}
Also used : io.gravitee.rest.api.service(io.gravitee.rest.api.service) java.util(java.util) ApiLifecycleState(io.gravitee.rest.api.model.api.ApiLifecycleState) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) GraviteeContext(io.gravitee.rest.api.service.common.GraviteeContext) CountResponse(io.gravitee.repository.analytics.query.count.CountResponse) DateHistogramResponse(io.gravitee.repository.analytics.query.response.histogram.DateHistogramResponse) DateHistogramQuery(io.gravitee.rest.api.model.analytics.query.DateHistogramQuery) io.gravitee.repository.analytics.query(io.gravitee.repository.analytics.query) GroupByQueryBuilder(io.gravitee.repository.analytics.query.groupby.GroupByQueryBuilder) io.gravitee.rest.api.model.analytics(io.gravitee.rest.api.model.analytics) io.gravitee.rest.api.model.analytics.query(io.gravitee.rest.api.model.analytics.query) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) AnalyticsRepository(io.gravitee.repository.analytics.api.AnalyticsRepository) Logger(org.slf4j.Logger) TenantReferenceType(io.gravitee.rest.api.model.TenantReferenceType) AnalyticsException(io.gravitee.repository.analytics.AnalyticsException) StatsResponse(io.gravitee.repository.analytics.query.stats.StatsResponse) GroupByResponse(io.gravitee.repository.analytics.query.groupby.GroupByResponse) PlanEntity(io.gravitee.rest.api.model.PlanEntity) TenantEntity(io.gravitee.rest.api.model.TenantEntity) Collectors(java.util.stream.Collectors) AggregationType(io.gravitee.repository.analytics.query.AggregationType) Component(org.springframework.stereotype.Component) io.gravitee.rest.api.service.exceptions(io.gravitee.rest.api.service.exceptions) Data(io.gravitee.repository.analytics.query.response.histogram.Data) ApplicationStatus(io.gravitee.repository.management.model.ApplicationStatus) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) io.gravitee.repository.analytics.query(io.gravitee.repository.analytics.query) io.gravitee.rest.api.model.analytics.query(io.gravitee.rest.api.model.analytics.query) Data(io.gravitee.repository.analytics.query.response.histogram.Data)

Example 4 with Data

use of io.gravitee.repository.analytics.query.response.histogram.Data in project gravitee-management-rest-api by gravitee-io.

the class HealthCheckServiceImpl method convertBucket.

private io.gravitee.rest.api.model.analytics.Bucket convertBucket(List<Long> timestamps, long from, long interval, io.gravitee.repository.analytics.query.response.histogram.Bucket bucket) {
    io.gravitee.rest.api.model.analytics.Bucket analyticsBucket = new io.gravitee.rest.api.model.analytics.Bucket();
    analyticsBucket.setName(bucket.name());
    analyticsBucket.setField(bucket.field());
    List<io.gravitee.rest.api.model.analytics.Bucket> childBuckets = new ArrayList<>();
    for (io.gravitee.repository.analytics.query.response.histogram.Bucket childBucket : bucket.buckets()) {
        childBuckets.add(convertBucket(timestamps, from, interval, childBucket));
    }
    for (Map.Entry<String, List<Data>> dataBucket : bucket.data().entrySet()) {
        io.gravitee.rest.api.model.analytics.Bucket analyticsDataBucket = new io.gravitee.rest.api.model.analytics.Bucket();
        analyticsDataBucket.setName(dataBucket.getKey());
        final Number[] values = new Number[timestamps.size()];
        for (int i = 0; i < timestamps.size(); i++) {
            values[i] = 0;
        }
        for (Data data : dataBucket.getValue()) {
            values[(int) ((data.timestamp() - from) / interval)] = data.value();
        }
        analyticsDataBucket.setData(values);
        childBuckets.add(analyticsDataBucket);
    }
    analyticsBucket.setBuckets(childBuckets);
    return analyticsBucket;
}
Also used : Data(io.gravitee.repository.analytics.query.response.histogram.Data) Endpoint(io.gravitee.definition.model.Endpoint) FieldBucket(io.gravitee.repository.healthcheck.query.FieldBucket) Bucket(io.gravitee.repository.healthcheck.query.Bucket)

Aggregations

Data (io.gravitee.repository.analytics.query.response.histogram.Data)4 Endpoint (io.gravitee.definition.model.Endpoint)2 AnalyticsException (io.gravitee.repository.analytics.AnalyticsException)2 AnalyticsRepository (io.gravitee.repository.analytics.api.AnalyticsRepository)2 io.gravitee.repository.analytics.query (io.gravitee.repository.analytics.query)2 CountResponse (io.gravitee.repository.analytics.query.count.CountResponse)2 GroupByQueryBuilder (io.gravitee.repository.analytics.query.groupby.GroupByQueryBuilder)2 GroupByResponse (io.gravitee.repository.analytics.query.groupby.GroupByResponse)2 DateHistogramResponse (io.gravitee.repository.analytics.query.response.histogram.DateHistogramResponse)2 Bucket (io.gravitee.repository.healthcheck.query.Bucket)2 FieldBucket (io.gravitee.repository.healthcheck.query.FieldBucket)2 ApplicationStatus (io.gravitee.repository.management.model.ApplicationStatus)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Component (org.springframework.stereotype.Component)2 ApiEntity (io.gravitee.management.model.ApiEntity)1 ApplicationEntity (io.gravitee.management.model.ApplicationEntity)1