summaryrefslogtreecommitdiffstats
path: root/VNF_Catalogue/migration
diff options
context:
space:
mode:
Diffstat (limited to 'VNF_Catalogue/migration')
-rw-r--r--VNF_Catalogue/migration/3rd_party/wait-for-it/LICENSE20
-rw-r--r--VNF_Catalogue/migration/3rd_party/wait-for-it/README.md75
-rwxr-xr-xVNF_Catalogue/migration/3rd_party/wait-for-it/wait-for-it.sh161
-rw-r--r--VNF_Catalogue/migration/Dockerfile37
-rw-r--r--VNF_Catalogue/migration/bash.sh4
-rw-r--r--VNF_Catalogue/migration/migrate.js100
-rw-r--r--VNF_Catalogue/migration/package.json16
-rw-r--r--VNF_Catalogue/migration/schema.js58
8 files changed, 471 insertions, 0 deletions
diff --git a/VNF_Catalogue/migration/3rd_party/wait-for-it/LICENSE b/VNF_Catalogue/migration/3rd_party/wait-for-it/LICENSE
new file mode 100644
index 00000000..bd18d0c4
--- /dev/null
+++ b/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/VNF_Catalogue/migration/3rd_party/wait-for-it/README.md b/VNF_Catalogue/migration/3rd_party/wait-for-it/README.md
new file mode 100644
index 00000000..900b7573
--- /dev/null
+++ b/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/VNF_Catalogue/migration/3rd_party/wait-for-it/wait-for-it.sh b/VNF_Catalogue/migration/3rd_party/wait-for-it/wait-for-it.sh
new file mode 100755
index 00000000..eca6c3b9
--- /dev/null
+++ b/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/VNF_Catalogue/migration/Dockerfile b/VNF_Catalogue/migration/Dockerfile
new file mode 100644
index 00000000..730b1ba7
--- /dev/null
+++ b/VNF_Catalogue/migration/Dockerfile
@@ -0,0 +1,37 @@
+###############################################################
+# 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 <shailrishabh@gmail.com>
+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 config set proxy http://10.4.20.103:8080
+# RUN npm config set https-proxy http://10.4.20.103:8080
+
+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/VNF_Catalogue/migration/bash.sh b/VNF_Catalogue/migration/bash.sh
new file mode 100644
index 00000000..1625a06a
--- /dev/null
+++ b/VNF_Catalogue/migration/bash.sh
@@ -0,0 +1,4 @@
+DB_HOST='localhost';
+DB_USER='root';
+DB_PASSWORD='iiit123';
+DB_DATABASE='vnf_catalogue';
diff --git a/VNF_Catalogue/migration/migrate.js b/VNF_Catalogue/migration/migrate.js
new file mode 100644
index 00000000..24332fd9
--- /dev/null
+++ b/VNF_Catalogue/migration/migrate.js
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * 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');
+var moment = require('moment');
+
+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);
+}
+
+function mysql_datetime() {
+ return moment(new Date()).format('YYYY-MM-DD HH:mm:ss');
+}
+
+createTables()
+.then(function() {
+ console.log('Tables created!!');
+ var current_time = mysql_datetime();
+ console.log(current_time);
+
+ knex.insert([{user_name: 'admin', password: 'admin', email_id: 'admin@opnfv.org', company: 'opnfv', introduction: 'hello world',
+ created_at: current_time}]).into('user').then(function() {
+ process.exit(0)});;
+})
+.catch(function (error) {
+ console.log('error creating the database perhaps it exists?(If yes congrats the persistance of mysql works :-D)');
+ process.exit(0);
+ //throw error;
+});
diff --git a/VNF_Catalogue/migration/package.json b/VNF_Catalogue/migration/package.json
new file mode 100644
index 00000000..3c636d8b
--- /dev/null
+++ b/VNF_Catalogue/migration/package.json
@@ -0,0 +1,16 @@
+{
+ "name": "VNF_Catalogue_migration",
+ "version": "0.0.1",
+ "private": true,
+ "scripts": {
+ "start": "node ./bin/www"
+ },
+ "dependencies": {
+ "bookshelf": "*",
+ "knex": "*",
+ "lodash": "*",
+ "mysql": "^2.13.0",
+ "when": "*",
+ "moment": "*"
+ }
+}
diff --git a/VNF_Catalogue/migration/schema.js b/VNF_Catalogue/migration/schema.js
new file mode 100644
index 00000000..9a1a5e76
--- /dev/null
+++ b/VNF_Catalogue/migration/schema.js
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * 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},
+ is_vnf_name: {type: 'boolean', defaultTo: '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;