Skip to content

Commit 442dd3b

Browse files
author
Chris Wiechmann
committed
Fix - Previous transform is not deleted
1 parent 76c46c1 commit 442dd3b

4 files changed

Lines changed: 33 additions & 5 deletions

File tree

api-builder-plugin-fn-elasticsearch/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7-
## [2.2.0] 2022-03-11
7+
## [2.2.1] 2022-03-11
8+
### Fixed
9+
- Previous transform was not deleted as requested
10+
11+
## [2.2.1] 2022-03-11
812
### Changed
913
- When updating an existing transform, the last checkpoint of the existing transform is taken over as a query limitation to the new transform
1014
- to avoid re-indexing the same documents again

api-builder-plugin-fn-elasticsearch/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@axway-api-builder-ext/api-builder-plugin-fn-elasticsearch",
3-
"version": "2.2.0",
3+
"version": "2.2.1",
44
"description": "Integrate Elasticsearch into your API-Builder flow to combine search data for instance with other data available in your flow.",
55
"author": "Chris Wiechmann <cwiechmann@axway.com> (http://www.axway.com)",
66
"license": "Apache-2.0",

api-builder-plugin-fn-elasticsearch/src/actions/transform.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ async function putTransform(params, options) {
130130
options.logger.info(`Starting created transform with ID: ${params.transformId}`);
131131
await client.transform.startTransform( {transformId: params.transformId}, { ignore: [404], maxRetries: 3 });
132132
}
133-
if(deletePreviousTransform && actualTransformId) {
134-
options.logger.info(`Deleting previous transform with ID: ${actualTransformId}`);
135-
await client.transform.deleteTransform( {transformId: actualTransformId}, { ignore: [404], maxRetries: 3 });
133+
if(deletePreviousTransform && runningTransforms.length == 1) {
134+
options.logger.info(`Deleting previous transform with ID: ${runningTransforms[0].id}`);
135+
await client.transform.deleteTransform( {transformId: runningTransforms[0].id}, { ignore: [404], maxRetries: 3 });
136136
}
137137
return putTransformResult;
138138
} catch (e) {

api-builder-plugin-fn-elasticsearch/test/transform/Transform-Tests.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,30 @@ describe('Transform tests', () => {
8383
expect(mockedStopTransform.callCount).to.equals(1); // There is nothing to stop
8484
});
8585

86+
it('should pass - 1 running transform (is the actual transform) - Created & Started new transform - Old deleted - Checkpoint taken over as query limition to new transform', async () => {
87+
const mockedGetTransformStats = setupElasticsearchMock(client, 'transform.getTransformStats', './test/mock/transform/getTransformStatsResponseOneStarted.json', false);
88+
const mockedPutTransform = setupElasticsearchMock(client, 'transform.putTransform', './test/mock/transform/putTransformResponse.json', false);
89+
const mockedDeleteTransform = setupElasticsearchMock(client, 'transform.deleteTransform', './test/mock/transform/stopTransformResponse.json', false);
90+
const mockedStartTransform = setupElasticsearchMock(client, 'transform.startTransform', './test/mock/transform/startTransformResponse.json', false);
91+
const mockedStopTransform = setupElasticsearchMock(client, 'transform.stopTransform', './test/mock/transform/stopTransformResponse.json', false);
92+
93+
const inputParameter = {
94+
transformId: 'traffic-summary-hourly',
95+
idSuffix: "v1",
96+
deletePreviousTransform: true,
97+
body: JSON.parse(fs.readFileSync('./test/mock/transform/putTransformRequestBody.json')) };
98+
const { value, output } = await flowNode.putTransform(inputParameter);
99+
100+
expect(output).to.equal('next');
101+
expect(mockedGetTransformStats.callCount).to.equals(1); // should be called once to get all transforms
102+
expect(mockedPutTransform.callCount).to.equals(1); // a new transform should be created
103+
// Transform body should have been extended about a query limitation
104+
expect(mockedPutTransform.lastCall.arg.body.source.query).to.deep.equals({ "bool": { "should": [ { "range": { "@timestamp": { "gt": 1646913600000 } } } ],"minimum_should_match": 1 } });
105+
expect(mockedStartTransform.callCount).to.equals(1); // and started
106+
expect(mockedDeleteTransform.callCount).to.equals(1); // Previous transform should be deleted
107+
expect(mockedStopTransform.callCount).to.equals(1); // There is nothing to stop
108+
});
109+
86110
it('should return with noUpdate as the actual transform is still indexing', async () => {
87111
const mockedGetTransformStats = setupElasticsearchMock(client, 'transform.getTransformStats', './test/mock/transform/getTransformStatsResponseOneIndexing.json', false);
88112
const mockedPutTransform = setupElasticsearchMock(client, 'transform.putTransform', './test/mock/transform/putTransformResponse.json', false);

0 commit comments

Comments
 (0)