From b3e815f76055b4a5743cbcecf79bf2a266a2aa9b Mon Sep 17 00:00:00 2001 From: Kumar Rishabh Date: Tue, 28 Mar 2017 01:14:31 +0530 Subject: Add docker-compose files and requirements This adds docker-compose file to define a multi-container vnf_catalogue service alongwith helper service to migrate the schema. Requires docker-compose installation To run :: docker-compose up The webapp by default would be accessible at ip_address:3000 Change-Id: I32daf7f76fb1d82116545187395cd96535c94541 Signed-off-by: Kumar Rishabh --- .../test/vnfcatalogue/VNF_Catalogue/.dockerignore | 2 + utils/test/vnfcatalogue/VNF_Catalogue/Dockerfile | 35 +++++ utils/test/vnfcatalogue/VNF_Catalogue/README.md | 11 +- utils/test/vnfcatalogue/VNF_Catalogue/database.js | 8 +- .../vnfcatalogue/VNF_Catalogue/docker-compose.yml | 49 +++++++ .../vnfcatalogue/VNF_Catalogue/docker_commands.sh | 2 + .../migration/3rd_party/wait-for-it/LICENSE | 20 +++ .../migration/3rd_party/wait-for-it/README.md | 75 ++++++++++ .../migration/3rd_party/wait-for-it/wait-for-it.sh | 161 +++++++++++++++++++++ .../VNF_Catalogue/migration/Dockerfile | 34 +++++ .../VNF_Catalogue/migration/migrate.js | 86 +++++++++++ .../VNF_Catalogue/migration/package.json | 15 ++ .../vnfcatalogue/VNF_Catalogue/migration/schema.js | 57 ++++++++ utils/test/vnfcatalogue/VNF_Catalogue/package.json | 6 +- utils/test/vnfcatalogue/helpers/migrate.js | 8 +- 15 files changed, 555 insertions(+), 14 deletions(-) create mode 100644 utils/test/vnfcatalogue/VNF_Catalogue/.dockerignore create mode 100644 utils/test/vnfcatalogue/VNF_Catalogue/Dockerfile create mode 100644 utils/test/vnfcatalogue/VNF_Catalogue/docker-compose.yml create mode 100644 utils/test/vnfcatalogue/VNF_Catalogue/docker_commands.sh create mode 100644 utils/test/vnfcatalogue/VNF_Catalogue/migration/3rd_party/wait-for-it/LICENSE create mode 100644 utils/test/vnfcatalogue/VNF_Catalogue/migration/3rd_party/wait-for-it/README.md create mode 100755 utils/test/vnfcatalogue/VNF_Catalogue/migration/3rd_party/wait-for-it/wait-for-it.sh create mode 100644 utils/test/vnfcatalogue/VNF_Catalogue/migration/Dockerfile create mode 100644 utils/test/vnfcatalogue/VNF_Catalogue/migration/migrate.js create mode 100644 utils/test/vnfcatalogue/VNF_Catalogue/migration/package.json create mode 100644 utils/test/vnfcatalogue/VNF_Catalogue/migration/schema.js (limited to 'utils/test') diff --git a/utils/test/vnfcatalogue/VNF_Catalogue/.dockerignore b/utils/test/vnfcatalogue/VNF_Catalogue/.dockerignore new file mode 100644 index 000000000..93f136199 --- /dev/null +++ b/utils/test/vnfcatalogue/VNF_Catalogue/.dockerignore @@ -0,0 +1,2 @@ +node_modules +npm-debug.log diff --git a/utils/test/vnfcatalogue/VNF_Catalogue/Dockerfile b/utils/test/vnfcatalogue/VNF_Catalogue/Dockerfile new file mode 100644 index 000000000..5df8eb5da --- /dev/null +++ b/utils/test/vnfcatalogue/VNF_Catalogue/Dockerfile @@ -0,0 +1,35 @@ +############################################# +# Docker container for VNF_Catalogue WebApp +############################################# +# Purpose: Don't run it from here! Use docker-compose(See README.md) +# +# Maintained by Kumar Rishabh :: penguinRaider +## +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +# + +FROM node:boron +MAINTAINER KumarRishabh::penguinRaider +LABEL version="v0.0.1" description="Open Source VNF_Catalogue for OPNFV" + +ENV DB_HOST mysql +ENV DB_USER vnf_user +ENV DB_PASSWORD vnf_password +ENV DB_DATABASE vnf_catalogue + +RUN mkdir -p /usr/src/app +WORKDIR /usr/src/app + +COPY package.json /usr/src/app/ + +RUN npm install + +COPY . /usr/src/app + +EXPOSE 3000 + +# We wait for mysql service to come up before starting the server using a 3rd_party script. +CMD [ "./migration/3rd_party/wait-for-it/wait-for-it.sh", "mysql:3306", "-t", "0", "--", "npm", "start" ] diff --git a/utils/test/vnfcatalogue/VNF_Catalogue/README.md b/utils/test/vnfcatalogue/VNF_Catalogue/README.md index 22d429072..91179f514 100644 --- a/utils/test/vnfcatalogue/VNF_Catalogue/README.md +++ b/utils/test/vnfcatalogue/VNF_Catalogue/README.md @@ -3,15 +3,16 @@ ## Quickstart -First install the dependencies +First install docker and docker-compose. This multicontainer app uses +docker-compose to organize the vnf_catalogue web_app - ```npm install``` +The use + ```docker-compose up``` -set time zone(Important) +set time zone(optional) Set same timezone in both nodejs server and mysql server. Something similar to below can be used: ``` SET GLOBAL time_zone = '+00:00'; ``` -Then Start the Server - ```npm start``` +The server would be accessible at ```ip_address:3000``` diff --git a/utils/test/vnfcatalogue/VNF_Catalogue/database.js b/utils/test/vnfcatalogue/VNF_Catalogue/database.js index b31310480..4fa8be10c 100644 --- a/utils/test/vnfcatalogue/VNF_Catalogue/database.js +++ b/utils/test/vnfcatalogue/VNF_Catalogue/database.js @@ -10,10 +10,10 @@ var mysql = require('mysql'); var pool = mysql.createPool({ - host: 'localhost', - user: 'myuser', - password: 'mypassword', - database: 'vnf_catalogue', + host: process.env.DB_HOST, + user: process.env.DB_USER, + password: process.env.DB_PASSWORD, + database: process.env.DB_DATABASE, connectionLimit: 50, supportBigNumbers: true, multipleStatements: true, diff --git a/utils/test/vnfcatalogue/VNF_Catalogue/docker-compose.yml b/utils/test/vnfcatalogue/VNF_Catalogue/docker-compose.yml new file mode 100644 index 000000000..a0ddfa480 --- /dev/null +++ b/utils/test/vnfcatalogue/VNF_Catalogue/docker-compose.yml @@ -0,0 +1,49 @@ +################################################################## +# Docker-Compose for setting up and running vnf_catalogue webapp +################################################################## +# Purpose: To setup and run vnf_catalogue webapp +# Usage: docker-compose up +# +# The webapp would be accessible at ip_address:3000 +# +# Maintained by Kumar Rishabh :: penguinRaider +## +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +# + +version: "2" +services: + mysql: + # mysql service built on top of vanilla mysql container. + # Defines mysql credentials. + + image: mysql + container_name: vnf_catalogue_database + environment: + - MYSQL_USER=vnf_user + - MYSQL_PASSWORD=vnf_password + - MYSQL_DATABASE=vnf_catalogue + - MYSQL_ROOT_PASSWORD=root + vnf_catalogue: + # The vnf_catalogue webapp service. + build: . + container_name: vnf_catalogue_webapp + depends_on: + - mysql + # Port on which the node.js server would be exposed + # To change host port to say 80 use 80:3000 + + ports: + - "3000:3000" + vnf_catalogue_migrate: + # We define another service for database migration. This service will + # migrate the database schema.(Dockerfile resides in migration + # directory). + + build: ./migration + container_name: vnf_catalogue_migrate + depends_on: + - mysql diff --git a/utils/test/vnfcatalogue/VNF_Catalogue/docker_commands.sh b/utils/test/vnfcatalogue/VNF_Catalogue/docker_commands.sh new file mode 100644 index 000000000..3be98ce8b --- /dev/null +++ b/utils/test/vnfcatalogue/VNF_Catalogue/docker_commands.sh @@ -0,0 +1,2 @@ +sh ./3rd_party/wait-for-it/wait-for-it.sh mysql:3306 -t 0 +node migrate diff --git a/utils/test/vnfcatalogue/VNF_Catalogue/migration/3rd_party/wait-for-it/LICENSE b/utils/test/vnfcatalogue/VNF_Catalogue/migration/3rd_party/wait-for-it/LICENSE new file mode 100644 index 000000000..bd18d0c45 --- /dev/null +++ b/utils/test/vnfcatalogue/VNF_Catalogue/migration/3rd_party/wait-for-it/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) +Copyright (c) 2016 Giles Hall + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/utils/test/vnfcatalogue/VNF_Catalogue/migration/3rd_party/wait-for-it/README.md b/utils/test/vnfcatalogue/VNF_Catalogue/migration/3rd_party/wait-for-it/README.md new file mode 100644 index 000000000..900b75735 --- /dev/null +++ b/utils/test/vnfcatalogue/VNF_Catalogue/migration/3rd_party/wait-for-it/README.md @@ -0,0 +1,75 @@ +# HELP NEEDED + +### March 13, 2017 update + +Since I posted this request for help, I've had a dozen or so responses which I am now sorting through. Applicants need to fill out [this](https://goo.gl/forms/GKCBFxaloaU47aky1) survey by March 17th. I will select, notify and announce the new volunteer(s) on March 19th. Once this is done, me and my team will work through the backlog of issues amd pull requests. Thanks for your paitence. + +### Old request follows: + +Hi there! I wrote `wait-for-it` in order to help me orchestrate containers I operate at my day job. I thought it was a neat little script, so I published it. I assumed I would be its only user, but that's not what happened! `wait-for-it` has received more stars then all of my other public repositories put together. I had no idea this tool would solicit such an audience, and I was equally unprepared to carve out the time required to address my user's issues and patches. I would like to solicit a volunteer from the community who would be willing to be a co-maintainer of this repository. If this is something you might be interested in, please email me at `waitforit@polymerase.org`. Thanks! + +## wait-for-it + +`wait-for-it.sh` is a pure bash script that will wait on the availability of a host and TCP port. It is useful for synchronizing the spin-up of interdependent services, such as linked docker containers. Since it is a pure bash script, it does not have any external dependencies. + +## Usage + +``` +wait-for-it.sh host:port [-s] [-t timeout] [-- command args] +-h HOST | --host=HOST Host or IP under test +-p PORT | --port=PORT TCP port under test + Alternatively, you specify the host and port as host:port +-s | --strict Only execute subcommand if the test succeeds +-q | --quiet Don't output any status messages +-t TIMEOUT | --timeout=TIMEOUT + Timeout in seconds, zero for no timeout +-- COMMAND ARGS Execute command with args after the test finishes +``` + +## Examples + +For example, let's test to see if we can access port 80 on www.google.com, and if it is available, echo the message `google is up`. + +``` +$ ./wait-for-it.sh www.google.com:80 -- echo "google is up" +wait-for-it.sh: waiting 15 seconds for www.google.com:80 +wait-for-it.sh: www.google.com:80 is available after 0 seconds +google is up +``` + +You can set your own timeout with the `-t` or `--timeout=` option. Setting the timeout value to 0 will disable the timeout: + +``` +$ ./wait-for-it.sh -t 0 www.google.com:80 -- echo "google is up" +wait-for-it.sh: waiting for www.google.com:80 without a timeout +wait-for-it.sh: www.google.com:80 is available after 0 seconds +google is up +``` + +The subcommand will be executed regardless if the service is up or not. If you wish to execute the subcommand only if the service is up, add the `--strict` argument. In this example, we will test port 81 on www.google.com which will fail: + +``` +$ ./wait-for-it.sh www.google.com:81 --timeout=1 --strict -- echo "google is up" +wait-for-it.sh: waiting 1 seconds for www.google.com:81 +wait-for-it.sh: timeout occurred after waiting 1 seconds for www.google.com:81 +wait-for-it.sh: strict mode, refusing to execute subprocess +``` + +If you don't want to execute a subcommand, leave off the `--` argument. This way, you can test the exit condition of `wait-for-it.sh` in your own scripts, and determine how to proceed: + +``` +$ ./wait-for-it.sh www.google.com:80 +wait-for-it.sh: waiting 15 seconds for www.google.com:80 +wait-for-it.sh: www.google.com:80 is available after 0 seconds +$ echo $? +0 +$ ./wait-for-it.sh www.google.com:81 +wait-for-it.sh: waiting 15 seconds for www.google.com:81 +wait-for-it.sh: timeout occurred after waiting 15 seconds for www.google.com:81 +$ echo $? +124 +``` + +## Thanks + +I wrote this script for my employer, [Ginkgo Bioworks](http://www.ginkgobioworks.com/), who was kind enough to let me release it as an open source tool. We are always looking to [hire](https://jobs.lever.co/ginkgobioworks) talented folks who are interested in working in the field of synthetic biology. diff --git a/utils/test/vnfcatalogue/VNF_Catalogue/migration/3rd_party/wait-for-it/wait-for-it.sh b/utils/test/vnfcatalogue/VNF_Catalogue/migration/3rd_party/wait-for-it/wait-for-it.sh new file mode 100755 index 000000000..eca6c3b9c --- /dev/null +++ b/utils/test/vnfcatalogue/VNF_Catalogue/migration/3rd_party/wait-for-it/wait-for-it.sh @@ -0,0 +1,161 @@ +#!/usr/bin/env bash +# Use this script to test if a given TCP host/port are available + +cmdname=$(basename $0) + +echoerr() { if [[ $QUIET -ne 1 ]]; then echo "$@" 1>&2; fi } + +usage() +{ + cat << USAGE >&2 +Usage: + $cmdname host:port [-s] [-t timeout] [-- command args] + -h HOST | --host=HOST Host or IP under test + -p PORT | --port=PORT TCP port under test + Alternatively, you specify the host and port as host:port + -s | --strict Only execute subcommand if the test succeeds + -q | --quiet Don't output any status messages + -t TIMEOUT | --timeout=TIMEOUT + Timeout in seconds, zero for no timeout + -- COMMAND ARGS Execute command with args after the test finishes +USAGE + exit 1 +} + +wait_for() +{ + if [[ $TIMEOUT -gt 0 ]]; then + echoerr "$cmdname: waiting $TIMEOUT seconds for $HOST:$PORT" + else + echoerr "$cmdname: waiting for $HOST:$PORT without a timeout" + fi + start_ts=$(date +%s) + while : + do + (echo > /dev/tcp/$HOST/$PORT) >/dev/null 2>&1 + result=$? + if [[ $result -eq 0 ]]; then + end_ts=$(date +%s) + echoerr "$cmdname: $HOST:$PORT is available after $((end_ts - start_ts)) seconds" + break + fi + sleep 1 + done + return $result +} + +wait_for_wrapper() +{ + # In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692 + if [[ $QUIET -eq 1 ]]; then + timeout $TIMEOUT $0 --quiet --child --host=$HOST --port=$PORT --timeout=$TIMEOUT & + else + timeout $TIMEOUT $0 --child --host=$HOST --port=$PORT --timeout=$TIMEOUT & + fi + PID=$! + trap "kill -INT -$PID" INT + wait $PID + RESULT=$? + if [[ $RESULT -ne 0 ]]; then + echoerr "$cmdname: timeout occurred after waiting $TIMEOUT seconds for $HOST:$PORT" + fi + return $RESULT +} + +# process arguments +while [[ $# -gt 0 ]] +do + case "$1" in + *:* ) + hostport=(${1//:/ }) + HOST=${hostport[0]} + PORT=${hostport[1]} + shift 1 + ;; + --child) + CHILD=1 + shift 1 + ;; + -q | --quiet) + QUIET=1 + shift 1 + ;; + -s | --strict) + STRICT=1 + shift 1 + ;; + -h) + HOST="$2" + if [[ $HOST == "" ]]; then break; fi + shift 2 + ;; + --host=*) + HOST="${1#*=}" + shift 1 + ;; + -p) + PORT="$2" + if [[ $PORT == "" ]]; then break; fi + shift 2 + ;; + --port=*) + PORT="${1#*=}" + shift 1 + ;; + -t) + TIMEOUT="$2" + if [[ $TIMEOUT == "" ]]; then break; fi + shift 2 + ;; + --timeout=*) + TIMEOUT="${1#*=}" + shift 1 + ;; + --) + shift + CLI="$@" + break + ;; + --help) + usage + ;; + *) + echoerr "Unknown argument: $1" + usage + ;; + esac +done + +if [[ "$HOST" == "" || "$PORT" == "" ]]; then + echoerr "Error: you need to provide a host and port to test." + usage +fi + +TIMEOUT=${TIMEOUT:-15} +STRICT=${STRICT:-0} +CHILD=${CHILD:-0} +QUIET=${QUIET:-0} + +if [[ $CHILD -gt 0 ]]; then + wait_for + RESULT=$? + exit $RESULT +else + if [[ $TIMEOUT -gt 0 ]]; then + wait_for_wrapper + RESULT=$? + else + wait_for + RESULT=$? + fi +fi + +if [[ $CLI != "" ]]; then + if [[ $RESULT -ne 0 && $STRICT -eq 1 ]]; then + echoerr "$cmdname: strict mode, refusing to execute subprocess" + exit $RESULT + fi + exec $CLI +else + exit $RESULT +fi diff --git a/utils/test/vnfcatalogue/VNF_Catalogue/migration/Dockerfile b/utils/test/vnfcatalogue/VNF_Catalogue/migration/Dockerfile new file mode 100644 index 000000000..a04666493 --- /dev/null +++ b/utils/test/vnfcatalogue/VNF_Catalogue/migration/Dockerfile @@ -0,0 +1,34 @@ +############################################################### +# Docker container for VNF_Catalogue Schema Migration Service +############################################################### +# Purpose: Don't run it from here! Use docker-compose(See README.md) +# +# Maintained by Kumar Rishabh :: penguinRaider +## +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +# + +FROM node:boron +MAINTAINER KumarRishabh::penguinRaider +LABEL version="v0.0.1" description="Open Source VNF_Catalogue for OPNFV" + +ENV DB_HOST mysql +ENV DB_USER vnf_user +ENV DB_PASSWORD vnf_password +ENV DB_DATABASE vnf_catalogue + +RUN mkdir -p /usr/src/app +WORKDIR /usr/src/app + +COPY package.json /usr/src/app/ + +RUN npm install + +COPY . /usr/src/app + +# The ordering of events should be coming up of mysql service and then migration +# of schema for the database. To enforce this causal relationship we use a 3rd_party script. +CMD [ "./3rd_party/wait-for-it/wait-for-it.sh", "mysql:3306", "-t", "0", "--", "node", "migrate"] diff --git a/utils/test/vnfcatalogue/VNF_Catalogue/migration/migrate.js b/utils/test/vnfcatalogue/VNF_Catalogue/migration/migrate.js new file mode 100644 index 000000000..3f4d892dc --- /dev/null +++ b/utils/test/vnfcatalogue/VNF_Catalogue/migration/migrate.js @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2017 Kumar Rishabh(penguinRaider) and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Apache License, Version 2.0 + * which accompanies this distribution, and is available at + * http://www.apache.org/licenses/LICENSE-2.0 + *******************************************************************************/ + +var knex = require('knex')({ + client: 'mysql', + connection: { + host : process.env.DB_HOST, + user : process.env.DB_USER, + password : process.env.DB_PASSWORD, + database : process.env.DB_DATABASE, + charset : 'utf8' + } +}); +var Schema = require('./schema'); +var sequence = require('when/sequence'); +var _ = require('lodash'); +function createTable(tableName) { + return knex.schema.createTable(tableName, function (table) { + var column; + var columnKeys = _.keys(Schema[tableName]); + _.each(columnKeys, function (key) { + if (Schema[tableName][key].type === 'text' && Schema[tableName][key].hasOwnProperty('fieldtype')) { + column = table[Schema[tableName][key].type](key, Schema[tableName][key].fieldtype); + } + else if (Schema[tableName][key].type === 'enum' && Schema[tableName][key].hasOwnProperty('values') && Schema[tableName][key].nullable === true) { + console.log(Schema[tableName][key].values); + column = table[Schema[tableName][key].type](key, Schema[tableName][key].values).nullable(); + } + else if (Schema[tableName][key].type === 'enum' && Schema[tableName][key].hasOwnProperty('values')) { + console.log(Schema[tableName][key].values); + column = table[Schema[tableName][key].type](key, Schema[tableName][key].values).notNullable(); + } + else if (Schema[tableName][key].type === 'string' && Schema[tableName][key].hasOwnProperty('maxlength')) { + column = table[Schema[tableName][key].type](key, Schema[tableName][key].maxlength); + } + else { + column = table[Schema[tableName][key].type](key); + } + if (Schema[tableName][key].hasOwnProperty('nullable') && Schema[tableName][key].nullable === true) { + column.nullable(); + } + else { + column.notNullable(); + } + if (Schema[tableName][key].hasOwnProperty('primary') && Schema[tableName][key].primary === true) { + column.primary(); + } + if (Schema[tableName][key].hasOwnProperty('unique') && Schema[tableName][key].unique) { + column.unique(); + } + if (Schema[tableName][key].hasOwnProperty('unsigned') && Schema[tableName][key].unsigned) { + column.unsigned(); + } + if (Schema[tableName][key].hasOwnProperty('references')) { + column.references(Schema[tableName][key].references); + } + if (Schema[tableName][key].hasOwnProperty('defaultTo')) { + column.defaultTo(Schema[tableName][key].defaultTo); + } + }); + }); +} +function createTables () { + var tables = []; + var tableNames = _.keys(Schema); + tables = _.map(tableNames, function (tableName) { + return function () { + return createTable(tableName); + }; + }); + return sequence(tables); +} +createTables() +.then(function() { + console.log('Tables created!!'); + process.exit(0); +}) +.catch(function (error) { + throw error; +}); diff --git a/utils/test/vnfcatalogue/VNF_Catalogue/migration/package.json b/utils/test/vnfcatalogue/VNF_Catalogue/migration/package.json new file mode 100644 index 000000000..65ff32483 --- /dev/null +++ b/utils/test/vnfcatalogue/VNF_Catalogue/migration/package.json @@ -0,0 +1,15 @@ +{ + "name": "VNF_Catalogue_migration", + "version": "0.0.1", + "private": true, + "scripts": { + "start": "node ./bin/www" + }, + "dependencies": { + "bookshelf": "*", + "knex": "*", + "lodash": "*", + "mysql": "^2.13.0", + "when": "*" + } +} diff --git a/utils/test/vnfcatalogue/VNF_Catalogue/migration/schema.js b/utils/test/vnfcatalogue/VNF_Catalogue/migration/schema.js new file mode 100644 index 000000000..4a7559ad0 --- /dev/null +++ b/utils/test/vnfcatalogue/VNF_Catalogue/migration/schema.js @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2017 Kumar Rishabh(penguinRaider) and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Apache License, Version 2.0 + * which accompanies this distribution, and is available at + * http://www.apache.org/licenses/LICENSE-2.0 + *******************************************************************************/ +var Schema = { + photo: { + photo_id: {type: 'increments', nullable: false, primary: true}, + photo_url: {type: 'string', maxlength: 254, nullable: false} + }, + user: { + user_id: {type: 'increments', nullable: false, primary: true}, + user_name: {type: 'string', maxlength: 254, nullable: false}, + password: {type: 'string', maxlength: 150, nullable: false}, + email_id: {type: 'string', maxlength: 254, nullable: false, unique: true, validations: {isEmail: true}}, + photo_id: {type: 'integer', nullable: true, unsigned: true, references: 'photo.photo_id'}, + company: {type: 'string', maxlength: 254, nullable: false}, + introduction: {type: 'string', maxlength: 510, nullable: false}, + last_login: {type: 'dateTime', nullable: true}, + created_at: {type: 'dateTime', nullable: false}, + }, + vnf: { + vnf_id: {type: 'increments', nullable: false, primary: true}, + vnf_name: {type: 'string', maxlength: 254, nullable: false}, + repo_url: {type: 'string', maxlength: 254, nullable: false}, + photo_id: {type: 'integer', nullable: true, unsigned: true, references: 'photo.photo_id'}, + submitter_id: {type: 'integer', nullable: false, unsigned: true, references: 'user.user_id'}, + lines_of_code: {type: 'integer', nullable: true, unsigned: true}, + versions: {type: 'integer', nullable: true, unsigned: true}, + no_of_developers: {type: 'integer', nullable: true, unsigned: true}, + no_of_stars: {type: 'integer', nullable: true, unsigned: true}, + license: {type: 'enum', nullable: false, values: ['MIT', 'GPL', 'GPL_V2', 'BSD', 'APACHE']}, + opnfv_indicator: {type: 'enum', nullable: false, values: ['gold', 'silver', 'platinum']}, + complexity: {type: 'enum', nullable: true, values: ['low', 'medium', 'high']}, + activity: {type: 'enum', nullable: true, values: ['low', 'medium', 'high']}, + last_updated: {type: 'dateTime', nullable: true}, + }, + tag: { + tag_id: {type: 'increments', nullable: false, primary: true}, + tag_name: {type: 'string', maxlength: 150, nullable: false} + }, + vnf_tags: { + vnf_tag_id: {type: 'increments', nullable: false, primary: true}, + tag_id: {type: 'integer', nullable: false, unsigned: true, references: 'tag.tag_id'}, + vnf_id: {type: 'integer', nullable: false, unsigned: true, references: 'vnf.vnf_id'}, + }, + vnf_contributors: { + vnf_contributors_id: {type: 'increments', nullable: false, primary: true}, + user_id: {type: 'integer', nullable: false, unsigned: true, references: 'user.user_id'}, + vnf_id: {type: 'integer', nullable: false, unsigned: true, references: 'vnf.vnf_id'}, + created_at: {type: 'dateTime', nullable: false}, + } +}; +module.exports = Schema; diff --git a/utils/test/vnfcatalogue/VNF_Catalogue/package.json b/utils/test/vnfcatalogue/VNF_Catalogue/package.json index 414b42425..b7a6c2385 100644 --- a/utils/test/vnfcatalogue/VNF_Catalogue/package.json +++ b/utils/test/vnfcatalogue/VNF_Catalogue/package.json @@ -18,6 +18,10 @@ "nodemon": "*", "async": "*", "multer": "*", - "octonode": "*" + "octonode": "*", + "bookshelf": "*", + "knex": "*", + "when": "*", + "lodash": "*" } } diff --git a/utils/test/vnfcatalogue/helpers/migrate.js b/utils/test/vnfcatalogue/helpers/migrate.js index d884d9c68..3f4d892dc 100644 --- a/utils/test/vnfcatalogue/helpers/migrate.js +++ b/utils/test/vnfcatalogue/helpers/migrate.js @@ -10,10 +10,10 @@ var knex = require('knex')({ client: 'mysql', connection: { - host : 'localhost', - user : 'myuser', - password : 'mypassword', - database : 'vnf_catalogue', + host : process.env.DB_HOST, + user : process.env.DB_USER, + password : process.env.DB_PASSWORD, + database : process.env.DB_DATABASE, charset : 'utf8' } }); -- cgit 1.2.3-korg