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'; import { Statement } from '../statement';
describe('Statement class', () => { describe('Statement class', () => {
let vertex;
let meta; let meta;
beforeEach(() => { beforeEach(() => {
@ -18,21 +19,25 @@ describe('Statement class', () => {
password: 'password' password: 'password'
} }
}; };
vertex = {
meta,
id: 'statement_id',
hasExplicitId: true,
stats: { }
};
}); });
describe('Statement from constructor', () => { describe('Statement from constructor', () => {
it('creates a new Statement instance', () => { it('creates a new Statement instance', () => {
const statement = new Statement( const statement = new Statement(
'statement_id', vertex
true,
{},
meta
); );
expect(statement.id).to.be('statement_id'); expect(statement.id).to.be('statement_id');
expect(statement.hasExplicitId).to.be(true); expect(statement.hasExplicitId).to.be(true);
expect(statement.stats).to.eql({}); expect(statement.stats).to.eql({});
expect(statement.meta).to.equal(meta); 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'; import { isVertexPipelineStage } from './utils';
export class IfStatement extends Statement { export class IfStatement extends Statement {
constructor(id, hasExplicitId, stats, meta, condition, trueStatements, elseStatements) { constructor(vertex, trueStatements, elseStatements) {
super(id, hasExplicitId, stats, meta); super(vertex);
this.condition = condition; const { name } = vertex;
this.condition = name;
this.trueStatements = trueStatements; this.trueStatements = trueStatements;
this.elseStatements = elseStatements; this.elseStatements = elseStatements;
} }
@ -38,11 +40,7 @@ export class IfStatement extends Statement {
} }
return new IfStatement( return new IfStatement(
ifVertex.id, ifVertex,
ifVertex.hasExplicitId,
ifVertex.stats,
ifVertex.meta,
ifVertex.name,
trueStatements, trueStatements,
elseStatements elseStatements
); );

View file

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

View file

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

View file

@ -5,10 +5,21 @@
*/ */
export class Statement { export class Statement {
constructor(id, hasExplicitId, stats, meta) { constructor(vertex) {
const {
id,
hasExplicitId,
stats,
meta
} = vertex;
this.id = id; this.id = id;
this.hasExplicitId = hasExplicitId; this.hasExplicitId = hasExplicitId;
this.stats = stats; this.stats = stats;
this.meta = meta; 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;
} }
} }