Skip to content
Permalink
Browse files

feat(drift2): HZN-1559,HZN-1570,HZN-1571

- Drift 2.0 API Enhancements Frontend Work
  • Loading branch information...
mattixtech committed May 27, 2019
1 parent 4551e39 commit 77b094d16e7406a36e7f830ed9e8364327e4a4f2
@@ -43,7 +43,7 @@ export class OnmsHTTPOptions {
public headers = {} as IHash<string>;

/** HTTP parameters to be passed on the URL. */
public parameters = {} as IHash<string>;
public parameters = {} as IHash<string | string[]>;

/** HTTP data to be passed when POSTing */
public data: any;
@@ -75,7 +75,21 @@ export class OnmsHTTPOptions {
*/
public withParameter(key: string, value?: any): OnmsHTTPOptions {
if (value !== undefined) {
this.parameters[key] = '' + value;
// Since parameters can be repeated an arbitrary number of times we will store them in an array in the map
// as soon as the occurrence of a given key is > 1
if (this.parameters[key]) {
const currentValue = this.parameters[key];
if (Array.isArray(currentValue)) {
currentValue.push('' + value);
} else {
const newArrayValue = [];
newArrayValue.push(currentValue);
newArrayValue.push(value);
this.parameters[key] = newArrayValue;
}
} else {
this.parameters[key] = '' + value;
}
}
return this;
}
@@ -100,11 +100,21 @@ export class ServerMetadata {
}
}

/** Returs a convenient data structure with all capabilities listed. */
/** Does this version support the drift 2.0 flows enhancements? */
public enhancedFlows() {
if (this.type && this.type === ServerTypes.MERIDIAN) {
return this.version.ge('2020.0.0');
} else {
return this.version.ge('25.0.0');
}
}

/** Returns a convenient data structure with all capabilities listed. */
public capabilities() {
return {
ackAlarms: this.ackAlarms(),
apiVersion: this.apiVersion(),
enhancedFlows: this.enhancedFlows(),
flows: this.flows(),
graphs: this.graphs(),
outageSummaries: this.outageSummaries(),
@@ -121,6 +131,7 @@ export class ServerMetadata {
+ ',apiVersion=' + this.apiVersion()
+ ',type=' + this.type.toString()
+ ',ackAlarms=' + this.ackAlarms()
+ ',enhancedFlows=' + this.enhancedFlows()
+ ',flows=' + this.flows()
+ ',graphs=' + this.graphs()
+ ',outageSummaries=' + this.outageSummaries()

Large diffs are not rendered by default.

@@ -0,0 +1,122 @@
import {MockHTTP25} from '../rest/MockHTTP25';

declare const await, describe, beforeEach, it, xit, expect, jest, require;

import {Client} from '../../src/Client';

import {OnmsAuthConfig} from '../../src/api/OnmsAuthConfig';
import {OnmsServer} from '../../src/api/OnmsServer';

import {OnmsFlowExporter} from '../../src/model/OnmsFlowExporter';
import {OnmsFlowExporterSummary} from '../../src/model/OnmsFlowExporterSummary';
import {OnmsFlowTable} from '../../src/model/OnmsFlowTable';

import {FlowDAO} from '../../src/dao/FlowDAO';

/** @hidden */
// tslint:disable-next-line
const moment = require('moment');

const SERVER_NAME='Demo';
const SERVER_URL='http://demo.opennms.org/opennms/';
const SERVER_USER='demo';
const SERVER_PASSWORD='demo';

let opennms : Client, server, auth, mockHTTP, dao : FlowDAO;

describe('FlowDAO25', () => {
beforeEach((done) => {
auth = new OnmsAuthConfig(SERVER_USER, SERVER_PASSWORD);
server = new OnmsServer(SERVER_NAME, SERVER_URL, auth);
mockHTTP = new MockHTTP25(server);
opennms = new Client(mockHTTP);
dao = new FlowDAO(mockHTTP);
Client.getMetadata(server, mockHTTP).then((metadata) => {
server.metadata = metadata;
done();
});
});
it('FlowDao.getApplications()', () => {
return dao.getApplications().then((applications) => {
expect(['http', 'https', 'test']).toEqual(expect.arrayContaining(applications));
});
});
it('FlowDao.getSummaryForApplications()', () => {
return dao.getSummaryForApplications().then((summary) => {
expect(summary).toBeInstanceOf(OnmsFlowTable);
expect(summary.start).toBeInstanceOf(moment);
expect(summary.end).toBeInstanceOf(moment);
expect(summary.headers).toContain('Application');
});
});
it('FlowDao.getSeriesForApplications()', () => {
return dao.getSeriesForApplications().then((series) => {
expect(series.start).toBeInstanceOf(moment);
expect(series.end).toBeInstanceOf(moment);
expect(series.columns.length).toEqual(10);
expect(series.timestamps.length).toEqual(49);
expect(series.values.length).toEqual(10);
expect(series.values[0].length).toEqual(49);
});
});
it('FlowDao.getSummaryForConversations()', () => {
return dao.getSummaryForConversations().then((summary) => {
expect(summary).toBeInstanceOf(OnmsFlowTable);
expect(summary.start).toBeInstanceOf(moment);
expect(summary.end).toBeInstanceOf(moment);
expect(summary.headers).toContain('Location');
expect(summary.rows.length).toEqual(10);
});
});
it('FlowDao.getSeriesForConversations()', () => {
return dao.getSeriesForConversations().then((series) => {
expect(series.start).toBeInstanceOf(moment);
expect(series.end).toBeInstanceOf(moment);
expect(series.columns.length).toEqual(10);
expect(series.timestamps.length).toEqual(2);
expect(series.values.length).toEqual(10);
expect(series.values[0].length).toEqual(2);
});
});
it('FlowDao.getHosts()', () => {
return dao.getHosts().then((hosts) => {
expect(['10.1.1.1', '192.168.0.1', 'myhost']).toEqual(expect.arrayContaining(hosts));
});
});
it('FlowDao.getSummaryForTopNHosts()', () => {
return dao.getSummaryForTopNHosts().then((summary) => {
expect(summary).toBeInstanceOf(OnmsFlowTable);
expect(summary.start).toBeInstanceOf(moment);
expect(summary.end).toBeInstanceOf(moment);
expect(summary.headers).toContain('host');
});
});
it('FlowDao.getSummaryForHosts()', () => {
return dao.getSummaryForHosts().then((summary) => {
expect(summary).toBeInstanceOf(OnmsFlowTable);
expect(summary.start).toBeInstanceOf(moment);
expect(summary.end).toBeInstanceOf(moment);
expect(summary.headers).toContain('host');
});
});
it('FlowDao.getSeriesForTopNHosts()', () => {
return dao.getSeriesForTopNHosts().then((series) => {
expect(series.start).toBeInstanceOf(moment);
expect(series.end).toBeInstanceOf(moment);
expect(series.columns.length).toEqual(10);
expect(series.timestamps.length).toEqual(49);
expect(series.values.length).toEqual(10);
expect(series.values[0].length).toEqual(49);
});
});
it('FlowDao.getSeriesForHosts()', () => {
return dao.getSeriesForHosts().then((series) => {
expect(series.start).toBeInstanceOf(moment);
expect(series.end).toBeInstanceOf(moment);
expect(series.columns.length).toEqual(10);
expect(series.timestamps.length).toEqual(49);
expect(series.values.length).toEqual(10);
expect(series.values[0].length).toEqual(49);
});
});
});
@@ -0,0 +1,5 @@
[
"http",
"https",
"test"
]
@@ -0,0 +1,10 @@
{
"end": 1520374562644,
"headers": [
"host",
"Bytes In",
"Bytes Out"
],
"rows": [],
"start": 1520360162644
}
@@ -0,0 +1,5 @@
[
"10.1.1.1",
"192.168.0.1",
"myhost"
]

0 comments on commit 77b094d

Please sign in to comment.
You can’t perform that action at this time.