refactor testDataSource() method

This commit is contained in:
Alexander Zobnin
2018-08-28 17:22:50 +03:00
parent 8a51d1d854
commit 056d9bcd26
4 changed files with 83 additions and 24 deletions

View File

@@ -1,7 +1,5 @@
import _ from 'lodash';
const NOT_IMPLEMENTED = 'Method should be implemented in subclass of DBConnector';
/**
* Base class for external history database connectors. Subclasses should implement `getHistory()`, `getTrends()` and
* `testDataSource()` methods, which describe how to fetch data from source other than Zabbix API.
@@ -12,7 +10,8 @@ export default class DBConnector {
this.datasourceSrv = datasourceSrv;
this.datasourceId = options.datasourceId;
this.datasourceName = options.datasourceName;
this.datasourceType = null;
this.datasourceTypeId = null;
this.datasourceTypeName = null;
}
loadDBDataSource() {
@@ -20,7 +19,9 @@ export default class DBConnector {
if (ds) {
return this.datasourceSrv.loadDatasource(ds.name)
.then(ds => {
this.datasourceType = ds.meta.id;
this.datasourceName = ds.name;
this.datasourceTypeId = ds.meta.id;
this.datasourceTypeName = ds.meta.name;
return ds;
});
} else {
@@ -32,20 +33,33 @@ export default class DBConnector {
* Send test request to datasource in order to ensure it's working.
*/
testDataSource() {
throw NOT_IMPLEMENTED;
throw new ZabbixNotImplemented('testDataSource()');
}
/**
* Get history data from external sources.
*/
getHistory() {
throw NOT_IMPLEMENTED;
throw new ZabbixNotImplemented('getHistory()');
}
/**
* Get trends data from external sources.
*/
getTrends() {
throw NOT_IMPLEMENTED;
throw new ZabbixNotImplemented('getTrends()');
}
}
// Define Zabbix DB Connector exception type for non-implemented methods
export class ZabbixNotImplemented {
constructor(methodName) {
this.code = null;
this.name = 'ZabbixNotImplemented';
this.message = `Zabbix DB Connector Error: method ${methodName || ''} should be implemented in subclass of DBConnector`;
}
toString() {
return this.message;
}
}