From c39da54306f83086fa2c369a518c0e61945ce355 Mon Sep 17 00:00:00 2001 From: vamsee Date: Wed, 11 Sep 2019 16:40:33 +0530 Subject: [PATCH 1/6] Using NPM_REGISTRY and CI_JOB_ID --- .gitlab-ci.yml | 18 ++++++++---------- package.json | 8 ++++---- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 542915b..0a65407 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -20,8 +20,8 @@ npminstall: - status_eslint=0 - exit_status=0 - npm set progress=false - #- npm config set registry http://10.188.25.62:9002/ - - npm config set registry http://registry.npmjs.org/ + - npm config set registry ${NPM_REGISTRY} + # - npm config set registry http://registry.npmjs.org/ - time npm install eslint babel-eslint --no-optional - if npm run lint; then status_eslint=0; else status_eslint=1; fi - if [ $status_eslint == 1 ]; then exit_status=1 && echo "esLint errors exist"; fi @@ -35,7 +35,6 @@ npminstall: - if [ $status_vulnerabilities == 1 ]; then echo "Dependency vulnerabilities exist"; fi - if [ $exit_status == 1 ]; then exit $exit_status; fi artifacts: - untracked: true expire_in: 2h paths: - node_modules/ @@ -50,12 +49,11 @@ mongotest: - export NODE_ENV=mongo - export MONGO_HOST="10.73.53.144" - export DB=mongo - - export DB_NAME=${CI_PIPELINE_ID}_mongo - - npm config set registry http://10.188.25.62:9002/ + - export DB_NAME=${CI_JOB_ID}_mongo + - npm config set registry ${NPM_REGISTRY} - time npm install --no-optional - npm run grunt-cover artifacts: - untracked: true expire_in: 2h paths: - coverage/ @@ -70,9 +68,9 @@ postgrestest: - export NODE_ENV=postgres - export DB=postgres - export POSTGRES_HOST="10.73.53.144" - - export DB_NAME=${CI_PIPELINE_ID}_pg + - export DB_NAME=${CI_JOB_ID}_pg - export ENABLE_DS_AUTOUPDATE=true - - npm config set registry http://10.188.25.62:9002/ + - npm config set registry ${NPM_REGISTRY} - time npm install --no-optional - npm run grunt-cover tags: @@ -90,8 +88,8 @@ oracletest: - export ORACLE_SYSUSER=oeadmin - export ORACLE_SYSPASSWORD=oeadmin - export ORACLE_SID=ORCLCDB - - export DB_NAME=${CI_PIPELINE_ID}_pg - - npm config set registry http://10.188.25.62:9002/ + - export DB_NAME=${CI_JOB_ID}_pg + - npm config set registry ${NPM_REGISTRY} - time npm install git+http://evgit/atul/oe-connector-oracle.git --no-optional - time npm install --no-optional - mv /oracledb node_modules/ diff --git a/package.json b/package.json index 19de288..3a5cd0d 100644 --- a/package.json +++ b/package.json @@ -34,11 +34,11 @@ "mocha": "5.2.0", "superagent-defaults": "0.1.14", "supertest": "3.4.2", - "oe-metadata-ui": "git+http://evgit/oecloud.io/oe-metadata-ui.git#2.1.0", - "oe-cloud": "git+http://evgit/oecloud.io/oe-cloud.git#2.1.0", + "oe-metadata-ui": "git+http://evgit/oecloud.io/oe-metadata-ui.git#master", + "oe-cloud": "git+http://evgit/oecloud.io/oe-cloud.git#master", "loopback-connector-mongodb": "3.9.2", - "oe-connector-oracle": "git+http://evgit/oecloud.io/oe-connector-oracle.git#2.0.1", - "oe-connector-postgresql": "git+http://evgit/oecloud.io/oe-connector-postgresql.git#2.0.0" + "oe-connector-oracle": "git+http://evgit/oecloud.io/oe-connector-oracle.git#master", + "oe-connector-postgresql": "git+http://evgit/oecloud.io/oe-connector-postgresql.git#master" }, "repository": { "type": "git", From fac56809c3b621e1eaf513ec6a5f8513e49da0ad Mon Sep 17 00:00:00 2001 From: vamsee Date: Mon, 23 Sep 2019 11:21:14 +0530 Subject: [PATCH 2/6] Using node 10.16.0 in CI --- .gitlab-ci.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0a65407..50e2e13 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,15 +3,19 @@ stages: - pre-build-test - cleanup -image: $REGISTRY/debian-node-oracle-docker variables: + DOMAIN_NAME: oecloud.local + PERF_DOMAIN_NAME: oecloud.perf REGISTRY: registry.${DOMAIN_NAME} + EXECUTOR_IMAGE: oecloud-executor:10.x + EXECUTOR_IMAGE_ORACLE: debian-node-oracle-docker:10.x + +image: ${REGISTRY}/${EXECUTOR_IMAGE} before_script: - export project=${CI_PROJECT_NAME//[^[:alnum:]]/} - export group=${CI_PROJECT_NAMESPACE//[^[:alnum:]]/} - export branch=${CI_BUILD_REF_NAME//[^[:alnum:]]/} - - export pipelineId=${CI_PIPELINE_ID//[^[:alnum:]]/} npminstall: stage: pre-build @@ -79,6 +83,7 @@ postgrestest: - CEP_RUNNER oracletest: + image: ${REGISTRY}/${EXECUTOR_IMAGE_ORACLE} stage: pre-build-test script: - echo 'Performing Oracle Test' From 1d6e2a8fb41241aa5ad1cbc7bf4f82a6d3e7d87a Mon Sep 17 00:00:00 2001 From: vamsee Date: Fri, 8 Nov 2019 11:05:34 +0530 Subject: [PATCH 3/6] Using node 12.13.0 in CI --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 50e2e13..086d595 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,8 +7,8 @@ variables: DOMAIN_NAME: oecloud.local PERF_DOMAIN_NAME: oecloud.perf REGISTRY: registry.${DOMAIN_NAME} - EXECUTOR_IMAGE: oecloud-executor:10.x - EXECUTOR_IMAGE_ORACLE: debian-node-oracle-docker:10.x + EXECUTOR_IMAGE: oecloud-executor:12.x + EXECUTOR_IMAGE_ORACLE: debian-node-oracle-docker:12.x image: ${REGISTRY}/${EXECUTOR_IMAGE} From f6868543732edf414aca9dac54f895dfccc52217 Mon Sep 17 00:00:00 2001 From: vamsee Date: Fri, 8 Nov 2019 11:46:28 +0530 Subject: [PATCH 4/6] Removing user and password from mongo db config --- test/datasources.mongo.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/test/datasources.mongo.js b/test/datasources.mongo.js index ec1c56c..4fa045f 100644 --- a/test/datasources.mongo.js +++ b/test/datasources.mongo.js @@ -17,15 +17,13 @@ module.exports = "connector": "transient" }, "db": { - "host": mongoHost, - "port": 27017, - "url": "mongodb://" + mongoHost + ":27017/" + dbName, - "database": dbName, - "password": "admin", - "name": "db", - "connector": "mongodb", - "user": "admin", - "connectionTimeout": 500000 + 'host': mongoHost, + 'port': 27017, + 'url': 'mongodb://' + mongoHost + ':27017/' + dbName, + 'database': dbName, + 'name': 'db', + 'connector': 'mongodb', + 'connectionTimeout': 500000 } }; From bc0aeb7edaf2702f39bb1fca9c2f9a2987e051f0 Mon Sep 17 00:00:00 2001 From: vamsee Date: Fri, 10 Jan 2020 16:52:27 +0530 Subject: [PATCH 5/6] removed unneeded packages and updated ci --- .eslintignore | 13 +-- .eslintrc | 2 +- .gitignore | 1 + .gitlab-ci.yml | 144 +++++++++++++++++++--------- Gruntfile.js | 38 +------- package.json | 14 +-- test/datasources.json | 3 +- test/datasources.mongo.js | 26 +++--- test/datasources.oracle.js | 10 +- test/datasources.postgres.js | 41 ++++---- test/oracle-utility.js | 176 +++++++++++++++++++---------------- test/server.js | 2 +- test/test.js | 35 ++++--- 13 files changed, 264 insertions(+), 241 deletions(-) diff --git a/.eslintignore b/.eslintignore index 398a1eb..9c8d714 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,6 +1,7 @@ -/client/ -/coverage/ -/node_modules/ -server/dropdb.js -/lib/expression-language/expression-syntax-parser.js -/test/ +build/ +client/ +coverage/ +node_modules/ +test/ +drop.js +Gruntfile.js diff --git a/.eslintrc b/.eslintrc index 8f2f7cc..6edc78f 100644 --- a/.eslintrc +++ b/.eslintrc @@ -111,7 +111,7 @@ "no-undefined": 1, // http://eslint.org/docs/rules/no-undefined "no-with": 2, // http://eslint.org/docs/rules/no-with "handle-callback-err": 1, // http://eslint.org/docs/rules/handle-callback-err - "radix": 2, // http://eslint.org/docs/rules/radix + "radix": 0, // http://eslint.org/docs/rules/radix "wrap-iife": [2, "any"], // http://eslint.org/docs/rules/wrap-iife "yoda": 2, // http://eslint.org/docs/rules/yoda diff --git a/.gitignore b/.gitignore index d1a30b1..2de00d8 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,4 @@ out/ /common/models/test /node_modules package-lock.json +oracle-user.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 086d595..88ce548 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,8 @@ stages: - pre-build - pre-build-test - - cleanup + - push-artifacts + - performance variables: DOMAIN_NAME: oecloud.local @@ -16,25 +17,31 @@ before_script: - export project=${CI_PROJECT_NAME//[^[:alnum:]]/} - export group=${CI_PROJECT_NAMESPACE//[^[:alnum:]]/} - export branch=${CI_BUILD_REF_NAME//[^[:alnum:]]/} + - if [ ${group} == "oecloudio" ]; then export APP_IMAGE_NAME=$project; else export APP_IMAGE_NAME=$group"-"$project; fi + - export APP_IMAGE_NAME=$(echo $APP_IMAGE_NAME | tr '[:upper:]' '[:lower:]') + - if [ ${branch} == "master" ]; then export APP_TAG=latest; else export APP_TAG=${branch}; fi + - export APP_TAG=$(echo $APP_TAG | tr '[:upper:]' '[:lower:]') + + - npm config set unsafe-perm true + - npm config set progress false + - npm config set registry ${NPM_REGISTRY} + # - npm config set registry https://registry.npmjs.org/ npminstall: stage: pre-build script: - echo "Performing code style check..." - - status_eslint=0 - - exit_status=0 - - npm set progress=false - - npm config set registry ${NPM_REGISTRY} - # - npm config set registry http://registry.npmjs.org/ + - export status_eslint=0 + - export exit_status=0 - time npm install eslint babel-eslint --no-optional - if npm run lint; then status_eslint=0; else status_eslint=1; fi - - if [ $status_eslint == 1 ]; then exit_status=1 && echo "esLint errors exist"; fi + - if [ $status_eslint == 1 ]; then export exit_status=1 && echo "esLint errors exist"; fi - if [ $exit_status == 1 ]; then exit $exit_status; fi - echo "Code style check done successfully" - time npm install --no-optional - echo "Node Modules Installed" - - mkdir -p ./artifacts/${CI_PROJECT_NAME}/ - - npm audit --json > ./artifacts/${CI_PROJECT_NAME}/vulnerabilities.json || true + - npm config rm registry + - npm audit --json > vulnerabilities.json || true - if npm audit; then status_vulnerabilities=0; else status_vulnerabilities=1; fi - if [ $status_vulnerabilities == 1 ]; then echo "Dependency vulnerabilities exist"; fi - if [ $exit_status == 1 ]; then exit $exit_status; fi @@ -42,78 +49,129 @@ npminstall: expire_in: 2h paths: - node_modules/ + - vulnerabilities.json tags: - CEP_RUNNER - mongotest: + coverage: /Statements.*?(\d+(?:\.\d+)?)%/ stage: pre-build-test + variables: + NODE_ENV: mongo + DB: mongo + MONGO_HOST: 10.73.53.144 + MONGO_PORT: '27017' + DB_NAME: ${CI_JOB_ID}_mongo script: - echo 'Performing MongoDB Test' - - export NODE_ENV=mongo - - export MONGO_HOST="10.73.53.144" - - export DB=mongo - - export DB_NAME=${CI_JOB_ID}_mongo - - npm config set registry ${NPM_REGISTRY} - time npm install --no-optional - npm run grunt-cover artifacts: expire_in: 2h paths: - coverage/ - when: on_failure tags: - CEP_RUNNER postgrestest: + coverage: /Statements.*?(\d+(?:\.\d+)?)%/ stage: pre-build-test + variables: + NODE_ENV: postgres + DB: postgres + POSTGRES_HOST: 10.73.53.144 + POSTGRES_PORT: '5432' + DB_NAME: ${CI_JOB_ID}_pg + ENABLE_DS_AUTOUPDATE: 'true' script: - echo 'Performing PostgreSQL Test' - - export NODE_ENV=postgres - - export DB=postgres - - export POSTGRES_HOST="10.73.53.144" - - export DB_NAME=${CI_JOB_ID}_pg - - export ENABLE_DS_AUTOUPDATE=true - - npm config set registry ${NPM_REGISTRY} - time npm install --no-optional - npm run grunt-cover - tags: - - CEP_RUNNER tags: - CEP_RUNNER oracletest: + coverage: /Statements.*?(\d+(?:\.\d+)?)%/ image: ${REGISTRY}/${EXECUTOR_IMAGE_ORACLE} stage: pre-build-test + variables: + NODE_ENV: oracle + DB: oracle + ORACLE_HOST: 10.73.53.144 + ORACLE_PORT: '1521' + ORACLE_SYSUSER: oeadmin + ORACLE_SYSPASSWORD: oeadmin + ORACLE_SID: ORCLCDB + ENABLE_DS_AUTOUPDATE: 'true' script: - echo 'Performing Oracle Test' - - export APP_TAG=oracle - - export NODE_ENV=oracle - - export ORACLE_HOST=10.73.53.144 - - export ORACLE_SYSUSER=oeadmin - - export ORACLE_SYSPASSWORD=oeadmin - - export ORACLE_SID=ORCLCDB - - export DB_NAME=${CI_JOB_ID}_pg - - npm config set registry ${NPM_REGISTRY} - - time npm install git+http://evgit/atul/oe-connector-oracle.git --no-optional + # - export DB_NAME=${CI_JOB_ID}_pg + # - time npm install git+http://evgit/oecloud.io/oe-connector-oracle.git#master --no-optional - time npm install --no-optional - mv /oracledb node_modules/ - - export CI_PROJECT_NAMESPACE=${group} - node test/oracle-utility.js - - export ORACLE_USERNAME=${CI_PROJECT_NAMESPACE}"-"${CI_PROJECT_NAME} - - export ORACLE_USERNAME=$(echo $ORACLE_USERNAME | tr '[:lower:]' '[:upper:]') - - export ORACLE_PASSWORD=$(echo $CI_PROJECT_NAMESPACE | tr '[:upper:]' '[:lower:]') - - export ENABLE_DS_AUTOUPDATE=true + # - export ORACLE_USERNAME=${group}"_"${project} + # - export ORACLE_USERNAME=$(echo $ORACLE_USERNAME | tr '[:lower:]' '[:upper:]') + # - export ORACLE_PASSWORD=$(echo $group | tr '[:upper:]' '[:lower:]') + - . ./oracle-user.sh + - env | grep -i oracle - echo "Oracle user details:"${ORACLE_USERNAME}"/"${ORACLE_PASSWORD} - npm run grunt-cover tags: - - CEP_RUNNER - + - CEP_RUNNER -lastcleanup: - stage: cleanup +pushartifacts: + stage: push-artifacts script: - - echo "Finishing CI CD" + - echo "Copying all artifacts" + - mkdir -p ./artifacts/${CI_PROJECT_NAME}/${CI_BUILD_REF_NAME}/ + - cp vulnerabilities.json ./artifacts/${CI_PROJECT_NAME}/${CI_BUILD_REF_NAME}/ + - cp -r coverage/ ./artifacts/${CI_PROJECT_NAME}/${CI_BUILD_REF_NAME}/ + - git clone http://10.73.97.24/oecloud.io/build-tools.git + - sh ./build-tools/push_artifacts.sh tags: - CEP_RUNNER + only: + - /^.*/@oecloud.io/oe-studio-service +.performancejob: + image: $REGISTRY/jmeter:docker + stage: performance + variables: + NODE_ENV: "mongo" + MONGO_HOST: "10.73.97.17" + MONGO_PORT: "27017" + DB_NAME: "${CI_JOB_ID}_mongo" + APP_PROTOCOL: "https" + APP_PORT: "443" + PERF_USERS: "1" + PERF_LOOPCOUNT: "50000" + script: + - export STACK_NAME=${APP_IMAGE_NAME}-${APP_TAG} + - export APP_URL=${APP_IMAGE_NAME}-${APP_TAG}.${PERF_DOMAIN_NAME} + - if [ ${branch} == "master" ]; then export STACK_NAME=${APP_IMAGE_NAME}; export APP_URL=${APP_IMAGE_NAME}.${PERF_DOMAIN_NAME}; fi + - if docker stack rm ${STACK_NAME}; then echo "stack removed"; else echo "nothing found in stack"; fi + - time npm install --no-optional + - git clone http://10.73.97.24/oecloud.io/build-tools.git + - sed 's/\$REGISTRY/'"$REGISTRY"'/g' ./build-tools/performance/Dockerfile > Dockerfile + - echo "Building ${APP_IMAGE_NAME}:${APP_TAG} image and pushing to registry..." + - time docker image build -t ${REGISTRY}/${APP_IMAGE_NAME}:${APP_TAG} --no-cache --pull . + - time docker image push ${REGISTRY}/${APP_IMAGE_NAME}:${APP_TAG} + - echo "Image (${REGISTRY}/${APP_IMAGE_NAME}:${APP_TAG}) built and pushed to registry" + - docker stack deploy --compose-file ./build-tools/performance/docker-compose.yml ${STACK_NAME} + - export HTTP_RESPONSE_CODE=200 + - export countElapsed=0 + - export app_exit_status=0 + - export no_proxy=$no_proxy,${APP_URL} + - export NO_PROXY=$no_proxy + - echo "${DOCKER_ROUTER_HOST} ${APP_URL}" >> /etc/hosts + - export isStarted=$(curl -k --write-out %{http_code} --output curl.out --silent https://${APP_URL}/api/ModelDefinitions) + - while [ ${isStarted} -ne ${HTTP_RESPONSE_CODE} ]; do let countElapsed=countElapsed+1; echo ""; sleep 10; export isStarted=$(curl -k --write-out %{http_code} --output curl.out --silent https://${APP_URL}/api/ModelDefinitions); echo -n "Waiting till the URL is up..."; echo ${isStarted}; if [ $countElapsed -eq 18 ] ; then export app_exit_status=1; export isStarted=${HTTP_RESPONSE_CODE}; fi; done + - if [ $app_exit_status -eq 1 ]; then echo "App failed to start....."; docker stack ps ${STACK_NAME}; docker service logs ${STACK_NAME}_web; docker stack rm ${STACK_NAME}; exit $app_exit_status; else echo "Your application URL is accessible @ https://${APP_URL}/"; fi + - mkdir -p ./artifacts/${CI_PROJECT_NAME}/${CI_BUILD_REF_NAME}/performance + - sh ./build-tools/performance/performance.sh + - sh ./build-tools/push_artifacts.sh + - if docker stack rm ${STACK_NAME}; then echo "stack removed"; else echo "nothing found in stack"; fi + when: manual + tags: + - PERF_RUNNER diff --git a/Gruntfile.js b/Gruntfile.js index 7c246f9..f68e7a7 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -10,38 +10,6 @@ module.exports = function GruntConfig(grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), - mkdir: { - all: { - options: { - create: ['dist'] - } - } - }, - - copy: { - main: { - files: [ - // includes files within path and its sub-directories - { - expand: true, - src: ['**', '!node_modules/**', '!coverage/**'], - dest: 'dist/' - } - ] - } - }, - - mochaTest: { - test: { - options: { - quiet: false, - clearRequireCache: true, - timeout: 100000 - }, - src: ['test/test.js'] - } - }, - clean: { coverage: { src: ['coverage/'] @@ -72,12 +40,8 @@ module.exports = function GruntConfig(grunt) { }); // Add the grunt-mocha-test tasks. - grunt.loadNpmTasks('grunt-mocha-test'); - grunt.loadNpmTasks('grunt-mocha-istanbul'); grunt.loadNpmTasks('grunt-contrib-clean'); - - grunt.loadNpmTasks('grunt-mkdir'); - grunt.loadNpmTasks('grunt-contrib-copy'); + grunt.loadNpmTasks('grunt-mocha-istanbul'); grunt.registerTask('test-with-coverage', ['clean:coverage', 'mocha_istanbul']); }; diff --git a/package.json b/package.json index 3a5cd0d..d65a028 100644 --- a/package.json +++ b/package.json @@ -20,25 +20,21 @@ "devDependencies": { "babel-eslint": "7.2.3", "chai": "3.4.1", - "chai-datetime": "1.4.0", "chai-things": "0.2.0", "chalk": "1.1.1", "eslint": "4.10.0", "grunt": "1.0.4", "grunt-contrib-clean": "2.0.0", - "grunt-contrib-copy": "1.0.0", - "grunt-mkdir": "1.0.0", "grunt-mocha-istanbul": "5.0.2", - "grunt-mocha-test": "0.13.3", "istanbul": "0.4.5", "mocha": "5.2.0", - "superagent-defaults": "0.1.14", - "supertest": "3.4.2", - "oe-metadata-ui": "git+http://evgit/oecloud.io/oe-metadata-ui.git#master", "oe-cloud": "git+http://evgit/oecloud.io/oe-cloud.git#master", - "loopback-connector-mongodb": "3.9.2", + "oe-connector-mongodb": "git+http://evgit/oecloud.io/oe-connector-mongodb.git#master", "oe-connector-oracle": "git+http://evgit/oecloud.io/oe-connector-oracle.git#master", - "oe-connector-postgresql": "git+http://evgit/oecloud.io/oe-connector-postgresql.git#master" + "oe-connector-postgresql": "git+http://evgit/oecloud.io/oe-connector-postgresql.git#master", + "oe-metadata-ui": "git+http://evgit/oecloud.io/oe-metadata-ui.git#master", + "superagent-defaults": "0.1.14", + "supertest": "3.4.2" }, "repository": { "type": "git", diff --git a/test/datasources.json b/test/datasources.json index 88434ec..058e985 100644 --- a/test/datasources.json +++ b/test/datasources.json @@ -7,7 +7,6 @@ "name": "transient", "connector": "transient" }, - "db": { "host": "localhost", "port": 27017, @@ -15,7 +14,7 @@ "database": "oe-studio", "password": "admin", "name": "db", - "connector": "mongodb", + "connector": "oe-connector-mongodb", "user": "admin", "connectionTimeout": 500000, "connectTimeoutMS": 500000, diff --git a/test/datasources.mongo.js b/test/datasources.mongo.js index 4fa045f..f896a7c 100644 --- a/test/datasources.mongo.js +++ b/test/datasources.mongo.js @@ -5,24 +5,24 @@ * */ var mongoHost = process.env.MONGO_HOST || 'localhost'; -var dbName = process.env.DB_NAME || 'oe-studio'; -module.exports = -{ - "memdb": { - "name": "memdb", - "connector": "memory" +var mongoPort = process.env.MONGO_PORT ? parseInt(process.env.MONGO_PORT) : 27017; +var dbName = process.env.DB_NAME || 'oe-studio-test'; +module.exports = { + 'memdb': { + 'name': 'memdb', + 'connector': 'memory' }, - "transient": { - "name": "transient", - "connector": "transient" + 'transient': { + 'name': 'transient', + 'connector': 'transient' }, - "db": { + 'db': { 'host': mongoHost, - 'port': 27017, - 'url': 'mongodb://' + mongoHost + ':27017/' + dbName, + 'port': mongoPort, + 'url': 'mongodb://' + mongoHost + ':' + mongoPort + '/' + dbName, 'database': dbName, 'name': 'db', - 'connector': 'mongodb', + 'connector': 'oe-connector-mongodb', 'connectionTimeout': 500000 } }; diff --git a/test/datasources.oracle.js b/test/datasources.oracle.js index 8792ffd..a5db290 100644 --- a/test/datasources.oracle.js +++ b/test/datasources.oracle.js @@ -4,16 +4,10 @@ * Bangalore, India. All Rights Reserved. * */ -/** - ** - ** ©2016-2017 EdgeVerve Systems Limited (a fully owned Infosys subsidiary), - ** Bangalore, India. All Rights Reserved. - ** - **/ -var oracleSID = process.env.ORACLE_SID || 'orclpdb.ad.infosys.com'; +var oracleSID = process.env.ORACLE_SID || 'ORCLCDB'; var oracleHost = process.env.ORACLE_HOST || 'localhost'; -var oraclePort = process.env.ORACLE_PORT || 1521; +var oraclePort = process.env.ORACLE_PORT ? parseInt(process.env.ORACLE_PORT) : 1521; var oracleUserName = process.env.ORACLE_USERNAME || 'oeadmin'; var oracleUserPassword = process.env.ORACLE_PASSWORD || 'oeadmin'; diff --git a/test/datasources.postgres.js b/test/datasources.postgres.js index 9275f58..de181a1 100644 --- a/test/datasources.postgres.js +++ b/test/datasources.postgres.js @@ -5,29 +5,28 @@ * */ var postgresHost = process.env.POSTGRES_HOST || 'localhost'; -var dbName = process.env.DB_NAME || 'oe-studio'; -module.exports = -{ - "memdb": { - "name": "memdb", - "connector": "memory" +var postgresPort = process.env.POSTGRES_PORT ? parseInt(process.env.POSTGRES_PORT) : 5432; +var dbName = process.env.DB_NAME || 'oe-studio-test'; +module.exports = { + 'memdb': { + 'name': 'memdb', + 'connector': 'memory' }, - "transient": { - "name": "transient", - "connector": "transient" + 'transient': { + 'name': 'transient', + 'connector': 'transient' }, - - "db": { - "host": postgresHost, - "port": 5432, - "url": "postgres://postgres:postgres@" + postgresHost + ":5432/" + dbName, - "database": dbName, - "password": "postgres", - "name": "db", - "connector": "oe-connector-postgresql", - "user": "postgres", - "max": 50, - "connectionTimeout": 50000 + 'db': { + 'host': postgresHost, + 'port': postgresPort, + 'url': 'postgres://postgres:postgres@' + postgresHost + ':' + postgresPort + '/' + dbName, + 'database': dbName, + 'password': 'postgres', + 'name': 'db', + 'connector': 'oe-connector-postgresql', + 'user': 'postgres', + 'max': 50, + 'connectionTimeout': 50000 } }; diff --git a/test/oracle-utility.js b/test/oracle-utility.js index 153da7f..40a1734 100644 --- a/test/oracle-utility.js +++ b/test/oracle-utility.js @@ -15,22 +15,29 @@ // ORACLE_SYSUSER // ORACLE_SYSPASSWORD // ORACLE_SID -// CI_PROJECT_NAME // CI_PROJECT_NAMESPACE +// CI_PROJECT_NAME var oracledb = require('oracledb'); var async = require('async'); +var fs = require('fs'); +var os = require('os'); + var oracleHost = process.env.ORACLE_HOST || 'localhost'; -var oraclePort = process.env.ORACLE_PORT || 1521; +var oraclePort = process.env.ORACLE_PORT ? parseInt(process.env.ORACLE_PORT) : 1521; +var oracleSID = process.env.ORACLE_SID || 'ORCLCDB'; var oracleConnectSettings = { 'password': process.env.ORACLE_SYSPASSWORD || 'manager1', 'user': process.env.ORACLE_SYSUSER || 'sys', - 'connectString': oracleHost + ':' + oraclePort + '/' + (process.env.ORACLE_SID || 'orclpdb.ad.infosys.com') + 'connectString': oracleHost + ':' + oraclePort + '/' + oracleSID }; -var userName = process.env.CI_PROJECT_NAMESPACE.toUpperCase() + '-' + (process.env.CI_PROJECT_NAME || 'oecloud').toUpperCase(); -var password = process.env.CI_PROJECT_NAMESPACE.toLowerCase(); +var namespace = process.env.CI_PROJECT_NAMESPACE ? process.env.CI_PROJECT_NAMESPACE.replace(/[^a-zA-Z0-9]/g, '') : 'oecloudio'; +var name = process.env.CI_PROJECT_NAME ? process.env.CI_PROJECT_NAME.replace(/[^a-zA-Z0-9]/g, '') : 'oecloud'; + +var userName = namespace.toUpperCase() + '_' + name.toUpperCase(); +var password = namespace.toLowerCase(); var grants = [ 'CREATE VIEW', @@ -44,30 +51,32 @@ var grants = [ ]; function createUser(connection, cb) { - var sql = 'alter session set "_ORACLE_SCRIPT"=true'; - connection.execute(sql, function (e, r) { - if (e) { - console.error('Ignoring error of alter session. UserName : ' + userName + ' Error :' + e); + var alterSQL = 'alter session set "_ORACLE_SCRIPT"=true'; + connection.execute(alterSQL, function (alterErr, alterRes) { + if (alterErr) { + console.error('Ignoring error of alter session. UserName : ' + userName + ' Error :' + alterErr); } - console.log(sql, ' ......... ok'); - var sql = 'CREATE USER "' + userName + '" IDENTIFIED BY ' + password; + console.log(alterSQL, ' ......... ok'); - connection.execute(sql, function (err, result) { - if (err) { - throw new Error('Unable to create user ' + userName + ' Error :' + err); + var createUserSQL = 'CREATE USER "' + userName + '" IDENTIFIED BY ' + password; + connection.execute(createUserSQL, function (createErr, createRes) { + if (createErr) { + console.error(createErr); + throw new Error('Unable to create user ' + userName); } - console.log(sql, ' ......... ok'); - async.each(grants, function (g, callback) { - var sql = 'GRANT ' + g + ' to "' + userName + '"'; + console.log(createUserSQL, ' ......... ok'); - connection.execute(sql, function (err2, result2) { - if (err2) { - throw new Error('Unable to execute grant ' + sql); + async.each(grants, function (g, callback) { + var grantSQL = 'GRANT ' + g + ' to "' + userName + '"'; + connection.execute(grantSQL, function (grantErr, grantRes) { + if (grantErr) { + console.error(grantErr); + throw new Error('Unable to execute grant ' + grantSQL); } - console.log(sql, ' ......... ok'); + console.log(grantSQL, ' ......... ok'); return callback(); }); - }, function (err) { + }, function (grantAsyncErr) { console.log('User ' + userName + ' Created successfully'); return cb(); }); @@ -75,78 +84,83 @@ function createUser(connection, cb) { }); } - function dropTables(cb) { - var oracleConnectSettings2 = Object.assign({}, oracleConnectSettings); - oracleConnectSettings2.user = userName; - oracleConnectSettings2.password = password; - - oracledb.getConnection( - oracleConnectSettings2, - function (err, connection) { - if (err) { - throw new Error('Unable to connect to Oracle Database ' + JSON.stringify(oracleConnectSettings)); + var oracleUserConnectSettings = { + 'password': password, + 'user': userName, + 'connectString': oracleHost + ':' + oraclePort + '/' + oracleSID + }; + + oracledb.getConnection(oracleUserConnectSettings, function (userConnectionErr, connection) { + if (userConnectionErr) { + console.error(userConnectionErr); + throw new Error('Unable to connect to Oracle Database ' + JSON.stringify(oracleUserConnectSettings)); + } + + var totalRows = 1000; + var selectDropTableSQL = "select 'drop table \"' || table_name || '\"' from all_tables where owner = '" + userName + "'"; + connection.execute(selectDropTableSQL, {}, { maxRows: totalRows }, function (selectDropErr, selectDropRes) { + if (selectDropErr) { + console.error(selectDropErr); + throw new Error('Unable to find tables ' + userName); } - var sql = "select 'drop table \"' || table_name || '\"' from all_tables where owner = '" + userName + "'"; - var totalRows = 1000; - connection.execute(sql, {}, {maxRows: totalRows}, function (err, result) { - if (err) { - throw new Error('Unable to find tables ' + userName + ' Error :' + err); - } - connection.execute(sql, {}, {maxRows: totalRows}, function (err2, result2) { - if (err2) { - throw new Error('Unable to execute droping of table ' + sql); - } - if (!result2 || !result2.rows || result2.rows.length === 0) { - return cb(); + if (!selectDropRes || !selectDropRes.rows || selectDropRes.rows.length === 0) { + return cb(); + } + + async.each(selectDropRes.rows, function (row, callback) { + var dropTableSQL = row[0]; + connection.execute(dropTableSQL, function (dropTableErr, dropTableRes) { + if (dropTableErr) { + console.error(dropTableErr); + throw new Error('Unable to drop table\nSQL: ' + sql); } - async.each(result2.rows, function (row, callback) { - var sql = row[0]; - connection.execute(sql, function (err2, result2) { - if (err2) { - throw new Error('Unable to drop table\nERROR : ' + err2 + '\nSQL : ' + sql); - } - console.log(sql, ' ......... ok'); - return callback(); - }); - }, function (err) { - console.log('Tables of user ' + userName + ' dropped successfully'); - return cb(); - }); + console.log(dropTableSQL, ' ......... ok'); + return callback(); }); + }, function (dropAsyncErr) { + console.log('Tables of user ' + userName + ' dropped successfully'); + return cb(); }); }); + }); } -oracledb.getConnection( - oracleConnectSettings, - function (err, connection) { +function generateUserBundle() { + console.log("Generating oracle user details shell script"); + fs.writeFileSync('./oracle-user.sh', '#!/bin/sh' + os.EOL); + fs.appendFileSync('./oracle-user.sh', 'export ORACLE_USERNAME=' + userName + os.EOL); + fs.appendFileSync('./oracle-user.sh', 'export ORACLE_PASSWORD=' + password + os.EOL); +} + +oracledb.getConnection(oracleConnectSettings, function (connectionErr, connection) { + if (connectionErr) { + console.error(connectionErr); + throw new Error('Unable to connect to Oracle Database ' + JSON.stringify(oracleConnectSettings)); + } + var sql = "select username, user_id from dba_users where username = '" + userName + "'"; + console.log(sql); + connection.execute(sql, function (err, result) { if (err) { - throw new Error('Unable to connect to Oracle Database ' + JSON.stringify(oracleConnectSettings)); + console.error(err); return; } - var sql = "select username, user_id from dba_users where username = '" + userName + "'"; - console.log(sql); - connection.execute(sql, - function (err, result) { + if (!result.rows || result.rows.length == 0) { + createUser(connection, function (err) { if (err) { - console.error(err); return; + return process.exit(1); } - if (!result.rows || result.rows.length == 0) { - createUser(connection, function (err) { - if (err) { - return process.exit(1); - } - return process.exit(); - }); - } else { - dropTables(function (err) { - if (err) { - return process.exit(1); - } - return process.exit(); - }); + generateUserBundle(); + return process.exit(); + }); + } else { + dropTables(function (err) { + if (err) { + return process.exit(1); } + generateUserBundle(); + return process.exit(); }); + } }); - +}); diff --git a/test/server.js b/test/server.js index 7d9e6be..dcd65d7 100644 --- a/test/server.js +++ b/test/server.js @@ -2,7 +2,7 @@ var oecloud = require('oe-cloud'); oecloud.observe('loaded', function (ctx, next) { return next(); -}) +}); oecloud.boot(__dirname, function (err) { oecloud.start(); diff --git a/test/test.js b/test/test.js index 7220b9b..eb65bf2 100644 --- a/test/test.js +++ b/test/test.js @@ -7,9 +7,9 @@ var oecloud = require('oe-cloud'); oecloud.observe('loaded', function (ctx, next) { - console.log("oe-cloud modules loaded"); + console.log('oe-cloud modules loaded'); return next(); -}) +}); oecloud.boot(__dirname, function (err) { if (err) { @@ -21,7 +21,6 @@ oecloud.boot(__dirname, function (err) { }); - var chalk = require('chalk'); var chai = require('chai'); var expect = chai.expect; @@ -38,17 +37,17 @@ var accessToken; describe(chalk.blue('oe-studio-test'), function () { this.timeout(10000); - before("wait for server to start",function(done){ - oecloud.on("test-start",function(){ + before('wait for server to start', function (done) { + oecloud.on('test-start', function () { done(); - }) + }); }); it('t1 create user admin/admin with /default tenant', function (done) { var url = basePath + '/users'; api.set('Accept', 'application/json') .post(url) - .send([{ username: "admin", password: "admin", email: "admin@admin.com" }]) + .send([{ username: 'admin', password: 'admin', email: 'admin@admin.com' }]) .end(function (err, response) { var result = response.body; expect(result[0].id).to.be.defined; @@ -60,7 +59,7 @@ describe(chalk.blue('oe-studio-test'), function () { var url = basePath + '/users/login'; api.set('Accept', 'application/json') .post(url) - .send({ username: "admin", password: "admin" }) + .send({ username: 'admin', password: 'admin' }) .end(function (err, response) { var result = response.body; accessToken = result.id; @@ -97,9 +96,9 @@ describe(chalk.blue('oe-studio-test'), function () { }); it('returns designer index page with subPath', function (done) { - oecloud.set('subPath', "/test"); - var designerConfig = oecloud.get("designer"); - designerConfig.subPath = "/test"; + oecloud.set('subPath', '/test'); + var designerConfig = oecloud.get('designer'); + designerConfig.subPath = '/test'; oecloud.set('designer', designerConfig); var getUrl = designerMountPath; api.set('Authorization', accessToken) @@ -120,7 +119,6 @@ describe(chalk.blue('oe-studio-test'), function () { .get(getUrl) .expect(302) .end(function (err, result) { - if (err) { done(err); } else { @@ -326,7 +324,7 @@ describe(chalk.blue('oe-studio-test'), function () { .set('Content-Type', 'application/json') .set('Accept', 'application/json') .post(postUrl) - .send({ file: "client/test.html", data: "my-file-dummy-content" }) + .send({ file: 'client/test.html', data: 'my-file-dummy-content' }) .expect(200) .end(function (err, result) { if (err) { @@ -345,7 +343,7 @@ describe(chalk.blue('oe-studio-test'), function () { .set('Content-Type', 'application/json') .set('Accept', 'application/json') .post(postUrl) - .send({ data: "Test-theme file" }) + .send({ data: 'Test-theme file' }) .expect(200) .end(function (err, result) { if (err) { @@ -364,7 +362,7 @@ describe(chalk.blue('oe-studio-test'), function () { .set('Content-Type', 'application/json') .set('Accept', 'application/json') .post(postUrl) - .send({ file: "client/test.html", data: "my-file-dummy-content" }) + .send({ file: 'client/test.html', data: 'my-file-dummy-content' }) .expect(200) .end(function (err, result) { if (err) { @@ -403,7 +401,7 @@ describe(chalk.blue('oe-studio-test'), function () { .set('Content-Type', 'application/json') .set('Accept', 'application/json') .post(postUrl) - .send({ modelName: "TestUIModel" }) + .send({ modelName: 'TestUIModel' }) .expect(500) .end(function (err, result) { if (err) { @@ -422,7 +420,7 @@ describe(chalk.blue('oe-studio-test'), function () { .set('Content-Type', 'application/json') .set('Accept', 'application/json') .post(postUrl) - .send({ modelName: "ModelDefinition" }) + .send({ modelName: 'ModelDefinition' }) .expect(200) .end(function (err, result) { if (err) { @@ -434,7 +432,7 @@ describe(chalk.blue('oe-studio-test'), function () { .set('Content-Type', 'application/json') .set('Accept', 'application/json') .post(postUrl) - .send({ modelName: "ModelDefinition" }) + .send({ modelName: 'ModelDefinition' }) .expect(200) .end(function (err, result) { if (err) { @@ -448,5 +446,4 @@ describe(chalk.blue('oe-studio-test'), function () { } }); }); - }); From f115d57f42ab8fc3ddb7bd65a669c9c156612893 Mon Sep 17 00:00:00 2001 From: vamsee Date: Thu, 23 Jan 2020 14:32:28 +0530 Subject: [PATCH 6/6] commit for version 2.2.0 --- package.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index d65a028..103559c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "oe-studio-service", - "version": "2.1.0", + "version": "2.2.0", "description": "oe-cloud module for enabling and supporting oe-studio", "engines": { "node": ">=6" @@ -28,11 +28,11 @@ "grunt-mocha-istanbul": "5.0.2", "istanbul": "0.4.5", "mocha": "5.2.0", - "oe-cloud": "git+http://evgit/oecloud.io/oe-cloud.git#master", - "oe-connector-mongodb": "git+http://evgit/oecloud.io/oe-connector-mongodb.git#master", - "oe-connector-oracle": "git+http://evgit/oecloud.io/oe-connector-oracle.git#master", - "oe-connector-postgresql": "git+http://evgit/oecloud.io/oe-connector-postgresql.git#master", - "oe-metadata-ui": "git+http://evgit/oecloud.io/oe-metadata-ui.git#master", + "oe-cloud": "git+http://evgit/oecloud.io/oe-cloud.git#2.2.0", + "oe-connector-mongodb": "git+http://evgit/oecloud.io/oe-connector-mongodb.git#2.2.0", + "oe-connector-oracle": "git+http://evgit/oecloud.io/oe-connector-oracle.git#2.2.0", + "oe-connector-postgresql": "git+http://evgit/oecloud.io/oe-connector-postgresql.git#2.2.0", + "oe-metadata-ui": "git+http://evgit/oecloud.io/oe-metadata-ui.git#2.2.0", "superagent-defaults": "0.1.14", "supertest": "3.4.2" },