Add vertex reference to pipeline statement classes. (#19134)

This commit is contained in:
Justin Kambic 2018-05-16 14:31:18 -04:00 committed by GitHub
parent 0b03166d2d
commit 748d152354
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 25 deletions

View file

@ -8,6 +8,7 @@ import expect from 'expect.js';
import { Statement } from '../statement';
describe('Statement class', () => {
let vertex;
let meta;
beforeEach(() => {
@ -18,21 +19,25 @@ describe('Statement class', () => {
password: 'password'
}
};
vertex = {
meta,
id: 'statement_id',
hasExplicitId: true,
stats: { }
};
});
describe('Statement from constructor', () => {
it('creates a new Statement instance', () => {
const statement = new Statement(
'statement_id',
true,
{},
meta
vertex
);
expect(statement.id).to.be('statement_id');
expect(statement.hasExplicitId).to.be(true);
expect(statement.stats).to.eql({});
expect(statement.meta).to.equal(meta);
expect(statement.vertex).to.eql(vertex);
});
});
});

View file

@ -9,10 +9,12 @@ import { makeStatement } from './make_statement';
import { isVertexPipelineStage } from './utils';
export class IfStatement extends Statement {
constructor(id, hasExplicitId, stats, meta, condition, trueStatements, elseStatements) {
super(id, hasExplicitId, stats, meta);
constructor(vertex, trueStatements, elseStatements) {
super(vertex);
this.condition = condition;
const { name } = vertex;
this.condition = name;
this.trueStatements = trueStatements;
this.elseStatements = elseStatements;
}
@ -38,11 +40,7 @@ export class IfStatement extends Statement {
}
return new IfStatement(
ifVertex.id,
ifVertex.hasExplicitId,
ifVertex.stats,
ifVertex.meta,
ifVertex.name,
ifVertex,
trueStatements,
elseStatements
);

View file

@ -7,20 +7,21 @@
import { Statement } from './statement';
export class PluginStatement extends Statement {
constructor(id, hasExplicitId, stats, meta, pluginType, name) {
super(id, hasExplicitId, stats, meta);
constructor(vertex) {
super(vertex);
const {
pluginType,
name
} = vertex;
this.pluginType = pluginType; // input, filter, or output
this.name = name; // twitter, grok, elasticsearch, etc.
}
static fromPipelineGraphVertex(pluginVertex) {
return new PluginStatement(
pluginVertex.id,
pluginVertex.hasExplicitId,
pluginVertex.stats,
pluginVertex.meta,
pluginVertex.pluginType,
pluginVertex.name
pluginVertex
);
}
}

View file

@ -9,10 +9,7 @@ import { Statement } from './statement';
export class Queue extends Statement {
static fromPipelineGraphVertex(queueVertex) {
return new Queue(
queueVertex.id,
queueVertex.hasExplicitId,
queueVertex.stats,
queueVertex.meta
queueVertex
);
}
}

View file

@ -5,10 +5,21 @@
*/
export class Statement {
constructor(id, hasExplicitId, stats, meta) {
constructor(vertex) {
const {
id,
hasExplicitId,
stats,
meta
} = vertex;
this.id = id;
this.hasExplicitId = hasExplicitId;
this.stats = stats;
this.meta = meta;
// storing a direct reference to the source vertex is convenient
// for interoperability with components that use the existing graph
this.vertex = vertex;
}
}