@cumulus/async-operations 19.0.0 → 19.2.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cumulus/async-operations",
3
- "version": "19.0.0",
3
+ "version": "19.2.0-alpha.0",
4
4
  "description": "Cumulus Core internal async operations module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -32,19 +32,19 @@
32
32
  "dependencies": {
33
33
  "@aws-sdk/client-ecs": "^3.621.0",
34
34
  "@aws-sdk/client-lambda": "^3.621.0",
35
- "@cumulus/aws-client": "19.0.0",
36
- "@cumulus/db": "19.0.0",
37
- "@cumulus/errors": "19.0.0",
38
- "@cumulus/es-client": "19.0.0",
39
- "@cumulus/logger": "19.0.0",
40
- "@cumulus/types": "19.0.0",
35
+ "@cumulus/aws-client": "19.2.0-alpha.0",
36
+ "@cumulus/db": "19.2.0-alpha.0",
37
+ "@cumulus/errors": "19.2.0-alpha.0",
38
+ "@cumulus/es-client": "19.2.0-alpha.0",
39
+ "@cumulus/logger": "19.2.0-alpha.0",
40
+ "@cumulus/types": "19.2.0-alpha.0",
41
41
  "knex": "2.4.1",
42
42
  "uuid": "8.3.2"
43
43
  },
44
44
  "devDependencies": {
45
- "@cumulus/common": "19.0.0",
45
+ "@cumulus/common": "19.2.0-alpha.0",
46
46
  "@types/aws-sdk": "2.7.0",
47
47
  "@types/uuid": "^8.0.0"
48
48
  },
49
- "gitHead": "3a619db6e6fa20846eb75802e89d5a065fd62fcc"
49
+ "gitHead": "533280b62564b6ce89fabcde5cbe653afb964205"
50
50
  }
@@ -1,5 +1,4 @@
1
1
  import { RunTaskCommandOutput } from '@aws-sdk/client-ecs';
2
- import { Knex } from 'knex';
3
2
  import { FunctionConfiguration, GetFunctionConfigurationCommand } from '@aws-sdk/client-lambda';
4
3
  import { ecs, s3, lambda } from '@cumulus/aws-client/services';
5
4
 
@@ -8,7 +7,6 @@ import {
8
7
  translateApiAsyncOperationToPostgresAsyncOperation,
9
8
  translatePostgresAsyncOperationToApiAsyncOperation,
10
9
  AsyncOperationPgModel,
11
- createRejectableTransaction,
12
10
  } from '@cumulus/db';
13
11
  import Logger from '@cumulus/logger';
14
12
  import { ApiAsyncOperation, AsyncOperationType } from '@cumulus/types/api/async_operations';
@@ -19,13 +17,6 @@ import type {
19
17
  } from './types';
20
18
 
21
19
  const { EcsStartTaskError, MissingRequiredArgument } = require('@cumulus/errors');
22
- const {
23
- indexAsyncOperation,
24
- } = require('@cumulus/es-client/indexer');
25
- const {
26
- getEsClient, EsClient,
27
- } = require('@cumulus/es-client/search');
28
-
29
20
  const logger = new Logger({ sender: '@cumulus/async-operation' });
30
21
 
31
22
  type StartEcsTaskReturnType = Promise<RunTaskCommandOutput>;
@@ -127,7 +118,6 @@ export const createAsyncOperation = async (
127
118
  stackName: string,
128
119
  systemBucket: string,
129
120
  knexConfig?: NodeJS.ProcessEnv,
130
- esClient?: typeof EsClient,
131
121
  asyncOperationPgModel?: AsyncOperationPgModelObject
132
122
  }
133
123
  ): Promise<Partial<ApiAsyncOperation>> => {
@@ -136,7 +126,6 @@ export const createAsyncOperation = async (
136
126
  stackName,
137
127
  systemBucket,
138
128
  knexConfig = process.env,
139
- esClient = await getEsClient(),
140
129
  asyncOperationPgModel = new AsyncOperationPgModel(),
141
130
  } = params;
142
131
 
@@ -144,14 +133,9 @@ export const createAsyncOperation = async (
144
133
  if (!systemBucket) throw new TypeError('systemBucket is required');
145
134
 
146
135
  const knex = await getKnexClient({ env: knexConfig });
147
- return await createRejectableTransaction(knex, async (trx: Knex.Transaction) => {
148
- const pgCreateObject = translateApiAsyncOperationToPostgresAsyncOperation(createObject);
149
- const pgRecord = await asyncOperationPgModel.create(trx, pgCreateObject, ['*']);
150
- const apiRecord = translatePostgresAsyncOperationToApiAsyncOperation(pgRecord[0]);
151
- await indexAsyncOperation(esClient, apiRecord, process.env.ES_INDEX);
152
-
153
- return apiRecord;
154
- });
136
+ const pgCreateObject = translateApiAsyncOperationToPostgresAsyncOperation(createObject);
137
+ const pgRecord = await asyncOperationPgModel.create(knex, pgCreateObject, ['*']);
138
+ return translatePostgresAsyncOperationToApiAsyncOperation(pgRecord[0]);
155
139
  };
156
140
 
157
141
  /**
@@ -23,11 +23,6 @@ const {
23
23
  migrationDir,
24
24
  } = require('@cumulus/db');
25
25
  const { EcsStartTaskError, MissingRequiredArgument } = require('@cumulus/errors');
26
- const { Search } = require('@cumulus/es-client/search');
27
- const {
28
- createTestIndex,
29
- cleanupTestIndex,
30
- } = require('@cumulus/es-client/testUtils');
31
26
  const {
32
27
  getLambdaConfiguration,
33
28
  getLambdaEnvironmentVariables,
@@ -55,15 +50,6 @@ test.before(async (t) => {
55
50
  systemBucket = randomString();
56
51
  await s3().createBucket({ Bucket: systemBucket });
57
52
 
58
- const { esIndex, esClient } = await createTestIndex();
59
- t.context.esIndex = esIndex;
60
- t.context.esClient = esClient;
61
- t.context.esAsyncOperationsClient = new Search(
62
- {},
63
- 'asyncOperation',
64
- t.context.esIndex
65
- );
66
-
67
53
  // Set up the mock ECS client
68
54
  ecsClient = ecs();
69
55
  ecsClient.runTask = (params) => {
@@ -103,7 +89,6 @@ test.beforeEach((t) => {
103
89
  test.after.always(async (t) => {
104
90
  sinon.restore();
105
91
  await recursivelyDeleteS3Bucket(systemBucket);
106
- await cleanupTestIndex(t.context);
107
92
  await destroyLocalTestDb({
108
93
  knex: t.context.testKnex,
109
94
  knexAdmin: t.context.testKnexAdmin,
@@ -272,7 +257,7 @@ test.serial('The startAsyncOperation method throws error and calls createAsyncOp
272
257
  );
273
258
  });
274
259
 
275
- test('The startAsyncOperation writes records to all data stores', async (t) => {
260
+ test('The startAsyncOperation writes records to the database', async (t) => {
276
261
  const description = randomString();
277
262
  const stackName = randomString();
278
263
  const operationType = 'ES Index';
@@ -312,51 +297,6 @@ test('The startAsyncOperation writes records to all data stores', async (t) => {
312
297
  omit(asyncOperationPgRecord, omitList),
313
298
  translateApiAsyncOperationToPostgresAsyncOperation(omit(expected, omitList))
314
299
  );
315
- const esRecord = await t.context.esAsyncOperationsClient.get(id);
316
- t.deepEqual(
317
- await t.context.esAsyncOperationsClient.get(id),
318
- {
319
- ...expected,
320
- _id: esRecord._id,
321
- timestamp: esRecord.timestamp,
322
- updatedAt: esRecord.updatedAt,
323
- createdAt: esRecord.createdAt,
324
- }
325
- );
326
- });
327
-
328
- test.serial('The startAsyncOperation writes records with correct timestamps', async (t) => {
329
- const description = randomString();
330
- const stackName = randomString();
331
- const operationType = 'ES Index';
332
- const taskArn = randomString();
333
-
334
- stubbedEcsRunTaskResult = {
335
- tasks: [{ taskArn }],
336
- failures: [],
337
- };
338
-
339
- const { id } = await startAsyncOperation({
340
- asyncOperationTaskDefinition: randomString(),
341
- cluster: randomString(),
342
- callerLambdaName: randomString(),
343
- lambdaName: randomString(),
344
- description,
345
- operationType,
346
- payload: {},
347
- stackName,
348
- knexConfig: knexConfig,
349
- systemBucket,
350
- });
351
-
352
- const asyncOperationPgRecord = await t.context.asyncOperationPgModel.get(
353
- t.context.testKnex,
354
- { id }
355
- );
356
-
357
- const esRecord = await t.context.esAsyncOperationsClient.get(id);
358
- t.is(asyncOperationPgRecord.created_at.getTime(), esRecord.createdAt);
359
- t.is(asyncOperationPgRecord.updated_at.getTime(), esRecord.updatedAt);
360
300
  });
361
301
 
362
302
  test.serial('The startAsyncOperation method returns the newly-generated record', async (t) => {
@@ -492,63 +432,3 @@ test('createAsyncOperation throws if systemBucket is not provided', async (t) =>
492
432
  { name: 'TypeError' }
493
433
  );
494
434
  });
495
-
496
- test.serial('createAsyncOperation() does not write to Elasticsearch if writing to PostgreSQL fails', async (t) => {
497
- const { id, createObject } = t.context;
498
-
499
- const fakeAsyncOpPgModel = {
500
- create: () => {
501
- throw new Error('something bad');
502
- },
503
- };
504
-
505
- const createParams = {
506
- knex: t.context.testKnex,
507
- asyncOperationPgModel: fakeAsyncOpPgModel,
508
- createObject,
509
- stackName: 'FakeStack',
510
- systemBucket: 'FakeBucket',
511
- };
512
- await t.throwsAsync(
513
- createAsyncOperation(createParams),
514
- { message: 'something bad' }
515
- );
516
-
517
- const dbRecords = await t.context.asyncOperationPgModel
518
- .search(t.context.testKnex, { id });
519
- t.is(dbRecords.length, 0);
520
- t.false(await t.context.esAsyncOperationsClient.exists(
521
- id
522
- ));
523
- });
524
-
525
- test.serial('createAsyncOperation() does not write to PostgreSQL if writing to Elasticsearch fails', async (t) => {
526
- const { id, createObject } = t.context;
527
- const fakeEsClient = {
528
- initializeEsClient: () => Promise.resolve(),
529
- client: {
530
- index: () => {
531
- throw new Error('ES something bad');
532
- },
533
- },
534
- };
535
-
536
- const createParams = {
537
- knex: t.context.testKnex,
538
- createObject,
539
- esClient: fakeEsClient,
540
- stackName: 'FakeStack',
541
- systemBucket: 'FakeBucket',
542
- };
543
- await t.throwsAsync(
544
- createAsyncOperation(createParams),
545
- { message: 'ES something bad' }
546
- );
547
-
548
- const dbRecords = await t.context.asyncOperationPgModel
549
- .search(t.context.testKnex, { id });
550
- t.is(dbRecords.length, 0);
551
- t.false(await t.context.esAsyncOperationsClient.exists(
552
- id
553
- ));
554
- });