diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 7e8d2b2..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = { - "env": { - "browser": true, - "es2021": true - }, - "extends": "eslint:recommended", - "parserOptions": { - "ecmaVersion": 12, - "sourceType": "module" - }, - "rules": { - } -}; diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..0972d56 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,22 @@ +{ + "env": { + "browser": true, + "commonjs": true, + "es2021": true + }, + "extends": ["standard"], + "parserOptions": { + "ecmaVersion": "latest" + }, + "rules": { + "indent": ["error", 4], + "space-before-function-paren": [ + "error", + { + "anonymous": "always", + "named": "never", + "asyncArrow": "always" + } + ] + } +} diff --git a/packages/aws/README.md b/packages/aws/README.md index 0284b6b..b4f81b5 100644 --- a/packages/aws/README.md +++ b/packages/aws/README.md @@ -474,7 +474,10 @@ If a queue name is used, a regex search will be done to find the queue. ### `When at least one task is running for service {string} in cluster {string}` -Checks if the service in a cluster has at least one task running on ecs +Checks if the service in an AWS cluster has at least one task running on ECS. Returns the number of running tasks to `lastRun` + +### `When image name for service {string} in cluster {string} is retrieved` +Retrieves the task definition image name / version of the running service in the cluster and set it to `lastRun`. Fails if the service is not running, or if there are no tasks running ### `When ecs taskDefinition {string} exists` ### `When ecs taskDefinition {string} does not exist` diff --git a/packages/aws/features/ecs.feature b/packages/aws/features/ecs.feature index 2f49f9c..37fc4ee 100644 --- a/packages/aws/features/ecs.feature +++ b/packages/aws/features/ecs.feature @@ -7,5 +7,9 @@ # When ecs taskDefinition "telematics-us-qa-fcra-vei-fgs-000000" exists # And ecs taskDefinition "telematics-us-qa-fcra-vei-fgs-000003" does not exist -# Scenario: -# When information from ecs cluster "telematics-us-qa-fcra-ecs-cluster" is retrieved \ No newline at end of file +# Scenario: Get ECS infomation +# When information from ecs cluster "telematics-us-qa-fcra-ecs-cluster" is retrieved + +# Scenario: Get image name for service +# Given set "servicePrefix" to "telematics-us-qa" +# When image name for service '${servicePrefix}-kia-tno-fgs-0' in cluster '${servicePrefix}-kia-ecs-cluster' is retrieved \ No newline at end of file diff --git a/packages/aws/package.json b/packages/aws/package.json index 31c6bc5..851aee2 100644 --- a/packages/aws/package.json +++ b/packages/aws/package.json @@ -3,7 +3,7 @@ "publishConfig": { "access": "public" }, - "version": "2.2.1", + "version": "2.2.2", "description": "AWS steps for MAF. This contains S3, DynamoDB, SQS, ECS, Cloudwatch, and Lambda stepDefinitions", "main": "index.js", "scripts": { @@ -39,5 +39,5 @@ "multiple-cucumber-html-reporter": "^3.5.0", "nyc": "^15.1.0" }, - "gitHead": "9c565ac48ddb32311b115a463c45625de3ff29e4" + "gitHead": "c1cb2220ce18a8e3ceee4b375950a0beec4f3a6f" } diff --git a/packages/aws/stepDefinitions/ecs.js b/packages/aws/stepDefinitions/ecs.js index b008f67..0192c19 100644 --- a/packages/aws/stepDefinitions/ecs.js +++ b/packages/aws/stepDefinitions/ecs.js @@ -1,6 +1,6 @@ const { setDefaultTimeout } = require('@cucumber/cucumber') const { MAFWhen, performJSONObjectTransform, filltemplate } = require('@ln-maf/core') -const { ECSClient, ListTaskDefinitionsCommand, ListClustersCommand, RunTaskCommand, DescribeClustersCommand, DescribeServicesCommand } = require('@aws-sdk/client-ecs') +const { ECSClient, ListTaskDefinitionsCommand, ListClustersCommand, RunTaskCommand, DescribeClustersCommand, DescribeServicesCommand, DescribeTaskDefinitionCommand } = require('@aws-sdk/client-ecs') setDefaultTimeout(15 * 60 * 1000) @@ -198,19 +198,45 @@ MAFWhen('ecs run-task is performed', async function () { /** * Check that at least one task for a service is running + * Returns the number of running tasks + * @param {String} serviceName the name of the service + * @param {String} clusterName the name of the cluster */ MAFWhen('at least one task is running for service {string} in cluster {string}', async function (serviceName, clusterName) { serviceName = filltemplate(serviceName, this.results) clusterName = filltemplate(clusterName, this.results) const ecsClient = new ECSClient({ maxAttempts: 2 }) - const res = await ecsClient.send(new DescribeServicesCommand({ + const serviceDetails = await ecsClient.send(new DescribeServicesCommand({ cluster: clusterName, services: [serviceName] })) - if (res.services.length === 0) { + if (serviceDetails.services.length === 0) { throw new Error('Can\'t find service ' + serviceName + ' in cluster ' + clusterName) } - if (res.services[0].runningCount < 1) { + const runningCount = serviceDetails.services[0].runningCount + if (runningCount < 1) { throw new Error('Service ' + serviceName + ' is not currently running in cluster ' + clusterName) } + return runningCount +}) + +/** + * Retrieves the image name / version of the running task in the service + * Fails if the service is not running, or if there are no tasks running + * @param {String} serviceName the name of the service + * @param {String} clusterName the name of the cluster + */ +MAFWhen('image name for service {string} in cluster {string} is retrieved', async function (serviceName, clusterName) { + serviceName = filltemplate(serviceName, this.results) + clusterName = filltemplate(clusterName, this.results) + const serviceDetails = await ecsClient.send(new DescribeServicesCommand({ + cluster: clusterName, + services: [serviceName] + })) + if (serviceDetails.services[0].runningCount <= 0) { + throw new Error('Service ' + serviceName + ' is not currently running in cluster ' + clusterName) + } + const taskDefinitionDetails = await ecsClient.send(new DescribeTaskDefinitionCommand({ taskDefinition: serviceDetails.services[0].taskDefinition })) + const containerImageName = taskDefinitionDetails.taskDefinition.containerDefinitions[0].image + return containerImageName })