Search in sources :

Example 1 with AnalyticsCommonConfiguration

use of org.wso2.carbon.apimgt.common.analytics.AnalyticsCommonConfiguration in project carbon-apimgt by wso2.

the class AnalyticsDataPublisher method initialize.

public void initialize(AnalyticsCommonConfiguration commonConfig) {
    Map<String, String> configs = commonConfig.getConfigurations();
    String reporterClass = configs.get("publisher.reporter.class");
    try {
        MetricReporter metricReporter;
        if (reporterClass != null) {
            metricReporter = MetricReporterFactory.getInstance().createMetricReporter(reporterClass, configs);
        } else {
            metricReporter = MetricReporterFactory.getInstance().createMetricReporter(configs);
        }
        if (!StringUtils.isEmpty(commonConfig.getResponseSchema())) {
            this.successMetricReporter = metricReporter.createCounterMetric(Constants.RESPONSE_METRIC_NAME, MetricSchema.valueOf(commonConfig.getResponseSchema()));
        } else {
            this.successMetricReporter = metricReporter.createCounterMetric(Constants.RESPONSE_METRIC_NAME, MetricSchema.RESPONSE);
        }
        if (!StringUtils.isEmpty(commonConfig.getFaultSchema())) {
            this.faultyMetricReporter = metricReporter.createCounterMetric(Constants.FAULTY_METRIC_NAME, MetricSchema.valueOf(commonConfig.getFaultSchema()));
        } else {
            this.faultyMetricReporter = metricReporter.createCounterMetric(Constants.FAULTY_METRIC_NAME, MetricSchema.ERROR);
        }
    // Illegal Argument is possible as the enum conversion could fail
    } catch (MetricCreationException | IllegalArgumentException e) {
        log.error("Error initializing event publisher.", e);
    }
}
Also used : MetricCreationException(org.wso2.am.analytics.publisher.exception.MetricCreationException) MetricReporter(org.wso2.am.analytics.publisher.reporter.MetricReporter)

Example 2 with AnalyticsCommonConfiguration

use of org.wso2.carbon.apimgt.common.analytics.AnalyticsCommonConfiguration in project carbon-apimgt by wso2.

the class APIHandlerServiceComponent method setAPIManagerConfigurationService.

@Reference(name = "api.manager.config.service", service = org.wso2.carbon.apimgt.impl.APIManagerConfigurationService.class, cardinality = ReferenceCardinality.MANDATORY, policy = ReferencePolicy.DYNAMIC, unbind = "unsetAPIManagerConfigurationService")
protected void setAPIManagerConfigurationService(APIManagerConfigurationService amcService) {
    if (log.isDebugEnabled()) {
        log.debug("API manager configuration service bound to the API handlers");
    }
    ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(amcService);
    if (amcService.getAPIAnalyticsConfiguration().isAnalyticsEnabled()) {
        AnalyticsCommonConfiguration commonConfiguration = new AnalyticsCommonConfiguration(amcService.getAPIAnalyticsConfiguration().getReporterProperties());
        commonConfiguration.setResponseSchema(amcService.getAPIAnalyticsConfiguration().getResponseSchemaName());
        commonConfiguration.setFaultSchema(amcService.getAPIAnalyticsConfiguration().getFaultSchemaName());
        AnalyticsServiceReferenceHolder.getInstance().setConfigurations(commonConfiguration);
    }
}
Also used : AnalyticsCommonConfiguration(org.wso2.carbon.apimgt.common.analytics.AnalyticsCommonConfiguration) Reference(org.osgi.service.component.annotations.Reference)

Aggregations

Reference (org.osgi.service.component.annotations.Reference)1 MetricCreationException (org.wso2.am.analytics.publisher.exception.MetricCreationException)1 MetricReporter (org.wso2.am.analytics.publisher.reporter.MetricReporter)1 AnalyticsCommonConfiguration (org.wso2.carbon.apimgt.common.analytics.AnalyticsCommonConfiguration)1