How to use @cumulus/common - 10 common examples

To help you get started, we’ve selected a few @cumulus/common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nasa / cumulus / example / spec / parallel / testAPI / snsRuleSpec.js View on Github external
afterAll(async () => {
    await SNS.deleteTopic({ TopicArn: snsTopicArn }).promise();

    try {
      const permissionParams = {
        FunctionName: consumerName,
        StatementId: `${ruleName}Permission`
      };
      await lambda().removePermission(permissionParams).promise();
    } catch (err) {
      // If the deletion test passed, this _should_ fail.  This is just handling
      // the case where the deletion test did not properly clean this up.
    }
  });
github nasa / cumulus / packages / api / lib / testUtils.js View on Github external
function fakeUserFactory(params = {}) {
  const user = {
    userName: randomId('userName'),
    password: randomId('password'),
    expires: Date.now() + (60 * 60 * 1000) // Default to 1 hour
  };

  return { ...user, ...params };
}
github nasa / cumulus / packages / integration-tests / index.js View on Github external
async function waitForTestExecutionStart({
  workflowName,
  stackName,
  bucket,
  findExecutionFn,
  findExecutionFnParams,
  startTask,
  maxWaitSeconds = maxWaitForStartedExecutionSecs
}) {
  let timeWaitedSecs = 0;
  /* eslint-disable no-await-in-loop */
  while (timeWaitedSecs < maxWaitSeconds) {
    await sleep(waitPeriodMs);
    timeWaitedSecs += (waitPeriodMs / 1000);
    const executions = await getExecutions(workflowName, stackName, bucket);

    for (let executionCtr = 0; executionCtr < executions.length; executionCtr += 1) {
      const execution = executions[executionCtr];
      let taskInput = await lambdaStep.getStepInput(execution.executionArn, startTask);
      if (taskInput) {
        taskInput = await pullStepFunctionEvent(taskInput);
      }
      if (taskInput && findExecutionFn(taskInput, findExecutionFnParams)) {
        return execution;
      }
    }
  }
  /* eslint-enable no-await-in-loop */
  throw new Error('Never found started workflow.');
github nasa / cumulus / example / spec / parallel / testAPI / sqsRuleSpec.js View on Github external
async function ingestGranule(queue) {
  const inputPayloadJson = fs.readFileSync(inputPayloadFilename, 'utf8');
  // update test data filepaths
  const inputPayload = await setupTestGranuleForIngest(config.bucket, inputPayloadJson, granuleRegex, testSuffix, testDataFolder);
  const granuleId = inputPayload.granules[0].granuleId;
  await sqs().sendMessage({ QueueUrl: queue, MessageBody: JSON.stringify(inputPayload) }).promise();
  return granuleId;
}
github nasa / cumulus / example / spec / parallel / kinesisTests / KinesisTestTriggerSpec.js View on Github external
beforeAll(async () => {
      const badRecord = { ...record };
      const badRecordIdentifier = randomString();
      badRecord.identifier = badRecordIdentifier;
      // Need to delete a property that will cause TranslateMessage to fail,
      // but not CnmResponseFail so that a failure message is still written
      // to the response stream
      delete badRecord.product.name;

      await tryCatchExit(cleanUp, async () => {
        console.log(`Dropping bad record onto ${streamName}, recordIdentifier: ${badRecordIdentifier}.`);
        await putRecordOnStream(streamName, badRecord);

        console.log('Waiting for step function to start...');
        failingWorkflowExecution = await waitForTestSf(badRecordIdentifier, testWorkflow, maxWaitForSFExistSecs, 'CNMToCMA');

        console.log(`Waiting for completed execution of ${failingWorkflowExecution.executionArn}.`);
        executionStatus = await waitForCompletedExecution(failingWorkflowExecution.executionArn, maxWaitForExecutionSecs);
      });
github nasa / cumulus / example / spec / parallel / helloWorld / HelloWorldKesCmaECSServiceAutoScalingSpec.js View on Github external
it('performs ECS Service Autoscaling', async () => {
    // wait for the event messages
    await sleep(180 * 1000);
    const { cluster, service } = await getEcsClusterService(awsConfig.stackName, 'EcsTaskHelloWorldKesCma');
    console.log('getEcsServiceEvents', cluster, service, startTime);
    const serviceEvents = await getEcsServiceEvents(cluster, service, startTime);
    expect(serviceEvents.length).toBeGreaterThan(2);
    expect(serviceEvents.filter((event) => event.message.includes('has started 1 tasks')).length).toBeGreaterThanOrEqual(1);
    expect(serviceEvents.filter((event) => event.message.includes('has stopped 1 running tasks')).length).toBeGreaterThanOrEqual(1);
  });
});
github nasa / cumulus / example / spec / scaling / activityScalingSpec.js View on Github external
HonorCooldown: true
        };
        await autoscaling().setDesiredCapacity(setDesiredCapacityParams).promise()
          .catch((err) => {
            console.log(`err ${JSON.stringify(err, null, 2)}`);
            if (err.code === 'ScalingActivityInProgress') {
              console.log('ScalingActivityInProgress. Cannot make update.');
            }
            else {
              throw (err);
            }
          });

        // wait for instances to be active
        const listContainerInstancesParams = { cluster: clusterArn };
        let containerInstanceIds = (await ecs().listContainerInstances(listContainerInstancesParams).promise()).containerInstanceArns;
        const waitTime = 30000;
        /* eslint-disable no-await-in-loop */
        while (containerInstanceIds.length < 2) {
          console.log('waiting for instances to become active');
          await sleep(waitTime);
          containerInstanceIds = (await ecs().listContainerInstances(listContainerInstancesParams).promise()).containerInstanceArns;
        }
        /* eslint-enable no-await-in-loop */

        // set desired tasks to 2
        const services = await ecs().listServices({ cluster: clusterArn }).promise();
        const serviceName = services.serviceArns[0].split('/').pop();
        const updateServiceParams = {
          desiredCount: 2,
          cluster: clusterArn,
          service: serviceName
github nasa / cumulus / example / spec / scaling / activityScalingSpec.js View on Github external
});

        // wait for instances to be active
        const listContainerInstancesParams = { cluster: clusterArn };
        let containerInstanceIds = (await ecs().listContainerInstances(listContainerInstancesParams).promise()).containerInstanceArns;
        const waitTime = 30000;
        /* eslint-disable no-await-in-loop */
        while (containerInstanceIds.length < 2) {
          console.log('waiting for instances to become active');
          await sleep(waitTime);
          containerInstanceIds = (await ecs().listContainerInstances(listContainerInstancesParams).promise()).containerInstanceArns;
        }
        /* eslint-enable no-await-in-loop */

        // set desired tasks to 2
        const services = await ecs().listServices({ cluster: clusterArn }).promise();
        const serviceName = services.serviceArns[0].split('/').pop();
        const updateServiceParams = {
          desiredCount: 2,
          cluster: clusterArn,
          service: serviceName
        };
        await ecs().updateService(updateServiceParams).promise();

        // Check there is a task running on each instance
        const describeContainerInstanceParams = {
          cluster: clusterArn,
          containerInstances: containerInstanceIds
        };
        let instanceData = await ecs().describeContainerInstances(describeContainerInstanceParams).promise();
        let firstInstanceRunningTasks = instanceData.containerInstances[0].runningTasksCount;
        let secondInstanceRunningTasks = instanceData.containerInstances[1].runningTasksCount;
github nasa / cumulus / example / spec / scaling / activityScalingSpec.js View on Github external
while (containerInstanceIds.length < 2) {
          console.log('waiting for instances to become active');
          await sleep(waitTime);
          containerInstanceIds = (await ecs().listContainerInstances(listContainerInstancesParams).promise()).containerInstanceArns;
        }
        /* eslint-enable no-await-in-loop */

        // set desired tasks to 2
        const services = await ecs().listServices({ cluster: clusterArn }).promise();
        const serviceName = services.serviceArns[0].split('/').pop();
        const updateServiceParams = {
          desiredCount: 2,
          cluster: clusterArn,
          service: serviceName
        };
        await ecs().updateService(updateServiceParams).promise();

        // Check there is a task running on each instance
        const describeContainerInstanceParams = {
          cluster: clusterArn,
          containerInstances: containerInstanceIds
        };
        let instanceData = await ecs().describeContainerInstances(describeContainerInstanceParams).promise();
        let firstInstanceRunningTasks = instanceData.containerInstances[0].runningTasksCount;
        let secondInstanceRunningTasks = instanceData.containerInstances[1].runningTasksCount;
        /* eslint-disable no-await-in-loop */
        while (!(firstInstanceRunningTasks === 1 && secondInstanceRunningTasks === 1)) {
          await sleep(waitTime);
          instanceData = await ecs().describeContainerInstances(describeContainerInstanceParams).promise();
          firstInstanceRunningTasks = instanceData.containerInstances[0].runningTasksCount;
          secondInstanceRunningTasks = instanceData.containerInstances[1].runningTasksCount;
        }
github nasa / cumulus / example / spec / parallel / emsReport / emsProductMetadataReportSpec.js View on Github external
it('generates EMS product metadata reports through the Cumulus API', async () => {
      const collection = { name: 'A2_SI25_NRT', version: '0' };
      const inputPayload = {
        reportType: 'metadata',
        startTime: moment.utc().subtract(1, 'days').startOf('day').format(),
        endTime: moment.utc().add(1, 'days').startOf('day').format(),
        collectionId: constructCollectionId(collection.name, collection.version),
        invocationType: 'RequestResponse'
      };

      const response = await emsApi.createEmsReports({
        prefix: config.stackName,
        request: inputPayload
      });

      // verify the report has the specified collection
      const reports = JSON.parse(response.body).reports;
      expect(reports.length).toEqual(1);

      const parsed = parseS3Uri(reports[0].file);
      expect(await fileExists(parsed.Bucket, parsed.Key)).not.toBe(false);
      const obj = await getS3Object(parsed.Bucket, parsed.Key);
      const reportRecords = obj.Body.toString().split('\n');