Refactor: queryProcessor renamend to queryBuilder.

This commit is contained in:
Alexander Zobnin
2016-11-13 13:16:07 +03:00
parent 88ddcd0c42
commit 032927cf8f
6 changed files with 31 additions and 31 deletions

View File

@@ -8,13 +8,13 @@ import DataProcessor from './DataProcessor';
import responseHandler from './responseHandler';
import './zabbixAPI.service.js';
import './zabbixCache.service.js';
import './queryProcessor.service.js';
import './queryBuilder.js';
import {ZabbixAPIError} from './zabbixAPICore.service.js';
class ZabbixAPIDatasource {
/** @ngInject */
constructor(instanceSettings, $q, templateSrv, alertSrv, zabbixAPIService, ZabbixCachingProxy, QueryProcessor) {
constructor(instanceSettings, $q, templateSrv, alertSrv, zabbixAPIService, ZabbixCachingProxy, QueryBuilder) {
// General data source settings
this.name = instanceSettings.name;
@@ -42,7 +42,7 @@ class ZabbixAPIDatasource {
this.zabbixCache = new ZabbixCachingProxy(this.zabbixAPI, this.cacheTTL);
// Initialize query builder
this.queryProcessor = new QueryProcessor(this.zabbixCache);
this.queryBuilder = new QueryBuilder(this.zabbixCache);
// Dependencies
this.q = $q;
@@ -149,7 +149,7 @@ class ZabbixAPIDatasource {
let options = {
itemtype: 'num'
};
return this.queryProcessor.build(target, options)
return this.queryBuilder.build(target, options)
.then(items => {
// Add hostname for items from multiple hosts
var addHostName = utils.isRegex(target.host.filter);
@@ -228,7 +228,7 @@ class ZabbixAPIDatasource {
let options = {
itemtype: 'text'
};
return this.queryProcessor.build(target, options)
return this.queryBuilder.build(target, options)
.then(items => {
if (items.length) {
return this.zabbixAPI.getHistory(items, timeFrom, timeTo)
@@ -318,13 +318,13 @@ class ZabbixAPIDatasource {
if (template.app === '/.*/') {
template.app = '';
}
result = this.queryProcessor.getItems(template.group, template.host, template.app);
result = this.queryBuilder.getItems(template.group, template.host, template.app);
} else if (parts.length === 3) {
// Get applications
result = this.queryProcessor.getApps(template.group, template.host);
result = this.queryBuilder.getApps(template.group, template.host);
} else if (parts.length === 2) {
// Get hosts
result = this.queryProcessor.getHosts(template.group);
result = this.queryBuilder.getHosts(template.group);
} else if (parts.length === 1) {
// Get groups
result = this.zabbixCache.getGroups(template.group);
@@ -350,7 +350,7 @@ class ZabbixAPIDatasource {
// Show all triggers
var showTriggers = [0, 1];
var buildQuery = this.queryProcessor
var buildQuery = this.queryBuilder
.buildTriggerQuery(this.replaceTemplateVars(annotation.group, {}),
this.replaceTemplateVars(annotation.host, {}),
this.replaceTemplateVars(annotation.application, {}));

View File

@@ -20,7 +20,7 @@ export class ZabbixQueryController extends QueryCtrl {
this.zabbix = this.datasource.zabbixAPI;
this.cache = this.datasource.zabbixCache;
this.queryProcessor = this.datasource.queryProcessor;
this.queryBuilder = this.datasource.queryBuilder;
this.$q = $q;
// Use custom format for template variables
@@ -116,7 +116,7 @@ export class ZabbixQueryController extends QueryCtrl {
}
suggestGroups() {
return this.queryProcessor.getAllGroups()
return this.queryBuilder.getAllGroups()
.then(groups => {
this.metric.groupList = groups;
return groups;
@@ -125,7 +125,7 @@ export class ZabbixQueryController extends QueryCtrl {
suggestHosts() {
let groupFilter = this.replaceTemplateVars(this.target.group.filter);
return this.queryProcessor.getAllHosts(groupFilter)
return this.queryBuilder.getAllHosts(groupFilter)
.then(hosts => {
this.metric.hostList = hosts;
return hosts;
@@ -135,7 +135,7 @@ export class ZabbixQueryController extends QueryCtrl {
suggestApps() {
let groupFilter = this.replaceTemplateVars(this.target.group.filter);
let hostFilter = this.replaceTemplateVars(this.target.host.filter);
return this.queryProcessor.getAllApps(groupFilter, hostFilter)
return this.queryBuilder.getAllApps(groupFilter, hostFilter)
.then(apps => {
this.metric.appList = apps;
return apps;
@@ -151,7 +151,7 @@ export class ZabbixQueryController extends QueryCtrl {
showDisabledItems: this.target.options.showDisabledItems
};
return this.queryProcessor
return this.queryBuilder
.getAllItems(groupFilter, hostFilter, appFilter, options)
.then(items => {
this.metric.itemList = items;

View File

@@ -2,9 +2,9 @@ import angular from 'angular';
import _ from 'lodash';
import * as utils from './utils';
function QueryProcessorFactory() {
function QueryBuilderFactory() {
class QueryProcessor {
class QueryBuilder {
constructor(zabbixCacheInstance) {
this.cache = zabbixCacheInstance;
}
@@ -149,12 +149,12 @@ function QueryProcessorFactory() {
}
}
return QueryProcessor;
return QueryBuilder;
}
angular
.module('grafana.services')
.factory('QueryProcessor', QueryProcessorFactory);
.factory('QueryBuilder', QueryBuilderFactory);
/**
* Find group, host, app or item by given name.

View File

@@ -22,10 +22,10 @@ describe('ZabbixDatasource', () => {
ctx.alertSrv = {};
ctx.zabbixAPIService = () => {};
ctx.ZabbixCachingProxy = () => {};
ctx.QueryProcessor = () => {};
ctx.queryBuilder = () => {};
ctx.ds = new Datasource(ctx.instanceSettings, ctx.$q, ctx.templateSrv, ctx.alertSrv,
ctx.zabbixAPIService, ctx.ZabbixCachingProxy, ctx.QueryProcessor);
ctx.zabbixAPIService, ctx.ZabbixCachingProxy, ctx.queryBuilder);
});
describe('When querying data', () => {
@@ -147,7 +147,7 @@ describe('ZabbixDatasource', () => {
ctx.ds.zabbixCache = {
getGroups: () => Q.when([])
};
ctx.ds.queryProcessor = {
ctx.ds.queryBuilder = {
getGroups: () => Q.when([]),
getHosts: () => Q.when([]),
getApps: () => Q.when([]),
@@ -180,7 +180,7 @@ describe('ZabbixDatasource', () => {
{query: 'Back*.', expect: 'Back*'}
];
let getHosts = sinon.spy(ctx.ds.queryProcessor, 'getHosts');
let getHosts = sinon.spy(ctx.ds.queryBuilder, 'getHosts');
for (const test of tests) {
ctx.ds.metricFindQuery(test.query);
expect(getHosts).to.have.been.calledWith(test.expect);
@@ -197,7 +197,7 @@ describe('ZabbixDatasource', () => {
{query: 'Back*.*.', expect: ['Back*', '/.*/']}
];
let getApps = sinon.spy(ctx.ds.queryProcessor, 'getApps');
let getApps = sinon.spy(ctx.ds.queryBuilder, 'getApps');
for (const test of tests) {
ctx.ds.metricFindQuery(test.query);
expect(getApps).to.have.been.calledWith(test.expect[0], test.expect[1]);
@@ -214,7 +214,7 @@ describe('ZabbixDatasource', () => {
{query: 'Back*.*.cpu.*', expect: ['Back*', '/.*/', 'cpu']}
];
let getItems = sinon.spy(ctx.ds.queryProcessor, 'getItems');
let getItems = sinon.spy(ctx.ds.queryBuilder, 'getItems');
for (const test of tests) {
ctx.ds.metricFindQuery(test.query);
expect(getItems)
@@ -227,7 +227,7 @@ describe('ZabbixDatasource', () => {
it('should invoke method with proper arguments', (done) => {
let query = '*.*';
let getHosts = sinon.spy(ctx.ds.queryProcessor, 'getHosts');
let getHosts = sinon.spy(ctx.ds.queryBuilder, 'getHosts');
ctx.ds.metricFindQuery(query);
expect(getHosts).to.have.been.calledWith('/.*/');
done();