From 1f6b18a1974c1b53a079b21b6be39af86deb2432 Mon Sep 17 00:00:00 2001 From: Kumar Rishabh Date: Thu, 29 Jun 2017 11:54:06 +0530 Subject: [PATCH] VNF_Catalogue Codebase Catalogue of Open Source VNFs consist in helping the end users to get information of the VNF we can deploy on top of an OPNFV solution [Deepak]: Removed all swp files. Change-Id: Ib2ea7330e964f1b684f32aedf631accd580df968 Signed-off-by: Kumar Rishabh Signed-off-by: Deepak S --- VNF_Catalogue/.dockerignore | 2 + VNF_Catalogue/Dockerfile | 44 + VNF_Catalogue/README.md | 18 + VNF_Catalogue/app.js | 110 + VNF_Catalogue/bin/www | 9 + .../cronjob/3rd_party/wait-for-it/LICENSE | 20 + .../cronjob/3rd_party/wait-for-it/README.md | 75 + .../3rd_party/wait-for-it/wait-for-it.sh | 161 + VNF_Catalogue/cronjob/Dockerfile | 55 + VNF_Catalogue/cronjob/crontab | 3 + VNF_Catalogue/cronjob/database.js | 16 + VNF_Catalogue/cronjob/git_count_loc.sh | 11 + VNF_Catalogue/cronjob/github.js | 159 + VNF_Catalogue/cronjob/package.json | 10 + VNF_Catalogue/cronjob/script.sh | 2 + VNF_Catalogue/database.js | 23 + VNF_Catalogue/docker-compose.yml | 80 + VNF_Catalogue/docker.sh | 8 + VNF_Catalogue/docker_commands.sh | 2 + VNF_Catalogue/env.sh | 1 + .../migration/3rd_party/wait-for-it/LICENSE | 20 + .../migration/3rd_party/wait-for-it/README.md | 75 + .../3rd_party/wait-for-it/wait-for-it.sh | 161 + VNF_Catalogue/migration/Dockerfile | 37 + VNF_Catalogue/migration/bash.sh | 4 + VNF_Catalogue/migration/migrate.js | 100 + VNF_Catalogue/migration/package.json | 16 + VNF_Catalogue/migration/schema.js | 58 + VNF_Catalogue/minio.js | 11 + VNF_Catalogue/package.json | 29 + .../3rd_party/materialize-pagination.js | 288 + .../3rd_party/materialize-pagination.min.js | 12 + .../public/3rd_party/materialize/.DS_Store | Bin 0 -> 6148 bytes .../public/3rd_party/materialize/LICENSE | 21 + .../public/3rd_party/materialize/README.md | 49 + .../3rd_party/materialize/css/materialize.css | 8582 +++++++++++++++++ .../materialize/css/materialize.min.css | 16 + .../3rd_party/materialize/fonts/.DS_Store | Bin 0 -> 6148 bytes .../materialize/fonts/roboto/Roboto-Bold.eot | Bin 0 -> 20966 bytes .../materialize/fonts/roboto/Roboto-Bold.ttf | Bin 0 -> 127744 bytes .../materialize/fonts/roboto/Roboto-Bold.woff | Bin 0 -> 62876 bytes .../fonts/roboto/Roboto-Bold.woff2 | Bin 0 -> 49976 bytes .../materialize/fonts/roboto/Roboto-Light.eot | Bin 0 -> 20940 bytes .../materialize/fonts/roboto/Roboto-Light.ttf | Bin 0 -> 126792 bytes .../fonts/roboto/Roboto-Light.woff | Bin 0 -> 62316 bytes .../fonts/roboto/Roboto-Light.woff2 | Bin 0 -> 49380 bytes .../fonts/roboto/Roboto-Medium.eot | Bin 0 -> 21364 bytes .../fonts/roboto/Roboto-Medium.ttf | Bin 0 -> 127488 bytes .../fonts/roboto/Roboto-Medium.woff | Bin 0 -> 62980 bytes .../fonts/roboto/Roboto-Medium.woff2 | Bin 0 -> 50224 bytes .../fonts/roboto/Roboto-Regular.eot | Bin 0 -> 21320 bytes .../fonts/roboto/Roboto-Regular.ttf | Bin 0 -> 126072 bytes .../fonts/roboto/Roboto-Regular.woff | Bin 0 -> 61736 bytes .../fonts/roboto/Roboto-Regular.woff2 | Bin 0 -> 49236 bytes .../materialize/fonts/roboto/Roboto-Thin.eot | Bin 0 -> 21659 bytes .../materialize/fonts/roboto/Roboto-Thin.ttf | Bin 0 -> 127584 bytes .../materialize/fonts/roboto/Roboto-Thin.woff | Bin 0 -> 61628 bytes .../fonts/roboto/Roboto-Thin.woff2 | Bin 0 -> 48524 bytes .../3rd_party/materialize/js/materialize.js | 8031 +++++++++++++++ .../materialize/js/materialize.min.js | 10 + .../public/3rd_party/rating/rating.css | 27 + .../public/3rd_party/rating/rating.js | 131 + VNF_Catalogue/public/3rd_party/typeahead.js | 7 + .../public/images/3rd_party/commits.png | Bin 0 -> 1437 bytes VNF_Catalogue/public/images/logo.png | Bin 0 -> 12138 bytes VNF_Catalogue/public/javascripts/global.js | 110 + VNF_Catalogue/public/javascripts/index.js | 109 + .../public/javascripts/index_search_max.js | 145 + VNF_Catalogue/public/javascripts/mode_edit.js | 82 + .../public/javascripts/mode_edit_project.js | 105 + .../public/javascripts/search_results.js | 227 + .../stylesheets/3rd_party/bootstrap.css | 6757 +++++++++++++ .../public/stylesheets/project_profile.css | 12 + .../public/stylesheets/search_form.css | 58 + .../public/stylesheets/search_projects.css | 116 + VNF_Catalogue/public/stylesheets/style.css | 329 + .../public/stylesheets/style_project.css | 238 + VNF_Catalogue/public/uploads/logo.png | Bin 0 -> 12138 bytes VNF_Catalogue/routes/add_project.js | 185 + VNF_Catalogue/routes/add_tag.js | 60 + VNF_Catalogue/routes/edit_project.js | 117 + VNF_Catalogue/routes/index.js | 58 + VNF_Catalogue/routes/project_profile.js | 115 + VNF_Catalogue/routes/search_max.js | 36 + VNF_Catalogue/routes/search_projects.js | 119 + .../routes/search_projects_results.js | 120 + VNF_Catalogue/routes/search_tag.js | 41 + VNF_Catalogue/routes/search_vnf.js | 39 + VNF_Catalogue/routes/vnf_tag_association.js | 75 + VNF_Catalogue/style.css | 316 + VNF_Catalogue/views/add_project.jade | 164 + VNF_Catalogue/views/edit_project.jade | 159 + VNF_Catalogue/views/error.jade | 12 + VNF_Catalogue/views/index.jade | 67 + VNF_Catalogue/views/index_back.jade | 136 + VNF_Catalogue/views/layout.jade | 54 + VNF_Catalogue/views/project_profile.jade | 122 + VNF_Catalogue/views/search.jade | 5 + VNF_Catalogue/views/search_projects.jade | 96 + VNF_Catalogue/views/vnf_tag_association.jade | 167 + 100 files changed, 29045 insertions(+) create mode 100644 VNF_Catalogue/.dockerignore create mode 100644 VNF_Catalogue/Dockerfile create mode 100644 VNF_Catalogue/README.md create mode 100644 VNF_Catalogue/app.js create mode 100644 VNF_Catalogue/bin/www create mode 100644 VNF_Catalogue/cronjob/3rd_party/wait-for-it/LICENSE create mode 100644 VNF_Catalogue/cronjob/3rd_party/wait-for-it/README.md create mode 100755 VNF_Catalogue/cronjob/3rd_party/wait-for-it/wait-for-it.sh create mode 100644 VNF_Catalogue/cronjob/Dockerfile create mode 100644 VNF_Catalogue/cronjob/crontab create mode 100644 VNF_Catalogue/cronjob/database.js create mode 100755 VNF_Catalogue/cronjob/git_count_loc.sh create mode 100644 VNF_Catalogue/cronjob/github.js create mode 100644 VNF_Catalogue/cronjob/package.json create mode 100644 VNF_Catalogue/cronjob/script.sh create mode 100644 VNF_Catalogue/database.js create mode 100644 VNF_Catalogue/docker-compose.yml create mode 100755 VNF_Catalogue/docker.sh create mode 100644 VNF_Catalogue/docker_commands.sh create mode 100644 VNF_Catalogue/env.sh create mode 100644 VNF_Catalogue/migration/3rd_party/wait-for-it/LICENSE create mode 100644 VNF_Catalogue/migration/3rd_party/wait-for-it/README.md create mode 100755 VNF_Catalogue/migration/3rd_party/wait-for-it/wait-for-it.sh create mode 100644 VNF_Catalogue/migration/Dockerfile create mode 100644 VNF_Catalogue/migration/bash.sh create mode 100644 VNF_Catalogue/migration/migrate.js create mode 100644 VNF_Catalogue/migration/package.json create mode 100644 VNF_Catalogue/migration/schema.js create mode 100644 VNF_Catalogue/minio.js create mode 100644 VNF_Catalogue/package.json create mode 100644 VNF_Catalogue/public/3rd_party/materialize-pagination.js create mode 100644 VNF_Catalogue/public/3rd_party/materialize-pagination.min.js create mode 100644 VNF_Catalogue/public/3rd_party/materialize/.DS_Store create mode 100644 VNF_Catalogue/public/3rd_party/materialize/LICENSE create mode 100644 VNF_Catalogue/public/3rd_party/materialize/README.md create mode 100644 VNF_Catalogue/public/3rd_party/materialize/css/materialize.css create mode 100644 VNF_Catalogue/public/3rd_party/materialize/css/materialize.min.css create mode 100644 VNF_Catalogue/public/3rd_party/materialize/fonts/.DS_Store create mode 100644 VNF_Catalogue/public/3rd_party/materialize/fonts/roboto/Roboto-Bold.eot create mode 100644 VNF_Catalogue/public/3rd_party/materialize/fonts/roboto/Roboto-Bold.ttf create mode 100644 VNF_Catalogue/public/3rd_party/materialize/fonts/roboto/Roboto-Bold.woff create mode 100644 VNF_Catalogue/public/3rd_party/materialize/fonts/roboto/Roboto-Bold.woff2 create mode 100644 VNF_Catalogue/public/3rd_party/materialize/fonts/roboto/Roboto-Light.eot create mode 100644 VNF_Catalogue/public/3rd_party/materialize/fonts/roboto/Roboto-Light.ttf create mode 100644 VNF_Catalogue/public/3rd_party/materialize/fonts/roboto/Roboto-Light.woff create mode 100644 VNF_Catalogue/public/3rd_party/materialize/fonts/roboto/Roboto-Light.woff2 create mode 100644 VNF_Catalogue/public/3rd_party/materialize/fonts/roboto/Roboto-Medium.eot create mode 100644 VNF_Catalogue/public/3rd_party/materialize/fonts/roboto/Roboto-Medium.ttf create mode 100644 VNF_Catalogue/public/3rd_party/materialize/fonts/roboto/Roboto-Medium.woff create mode 100644 VNF_Catalogue/public/3rd_party/materialize/fonts/roboto/Roboto-Medium.woff2 create mode 100644 VNF_Catalogue/public/3rd_party/materialize/fonts/roboto/Roboto-Regular.eot create mode 100644 VNF_Catalogue/public/3rd_party/materialize/fonts/roboto/Roboto-Regular.ttf create mode 100644 VNF_Catalogue/public/3rd_party/materialize/fonts/roboto/Roboto-Regular.woff create mode 100644 VNF_Catalogue/public/3rd_party/materialize/fonts/roboto/Roboto-Regular.woff2 create mode 100644 VNF_Catalogue/public/3rd_party/materialize/fonts/roboto/Roboto-Thin.eot create mode 100644 VNF_Catalogue/public/3rd_party/materialize/fonts/roboto/Roboto-Thin.ttf create mode 100644 VNF_Catalogue/public/3rd_party/materialize/fonts/roboto/Roboto-Thin.woff create mode 100644 VNF_Catalogue/public/3rd_party/materialize/fonts/roboto/Roboto-Thin.woff2 create mode 100644 VNF_Catalogue/public/3rd_party/materialize/js/materialize.js create mode 100644 VNF_Catalogue/public/3rd_party/materialize/js/materialize.min.js create mode 100755 VNF_Catalogue/public/3rd_party/rating/rating.css create mode 100755 VNF_Catalogue/public/3rd_party/rating/rating.js create mode 100644 VNF_Catalogue/public/3rd_party/typeahead.js create mode 100644 VNF_Catalogue/public/images/3rd_party/commits.png create mode 100644 VNF_Catalogue/public/images/logo.png create mode 100644 VNF_Catalogue/public/javascripts/global.js create mode 100644 VNF_Catalogue/public/javascripts/index.js create mode 100644 VNF_Catalogue/public/javascripts/index_search_max.js create mode 100644 VNF_Catalogue/public/javascripts/mode_edit.js create mode 100644 VNF_Catalogue/public/javascripts/mode_edit_project.js create mode 100644 VNF_Catalogue/public/javascripts/search_results.js create mode 100755 VNF_Catalogue/public/stylesheets/3rd_party/bootstrap.css create mode 100644 VNF_Catalogue/public/stylesheets/project_profile.css create mode 100644 VNF_Catalogue/public/stylesheets/search_form.css create mode 100644 VNF_Catalogue/public/stylesheets/search_projects.css create mode 100644 VNF_Catalogue/public/stylesheets/style.css create mode 100644 VNF_Catalogue/public/stylesheets/style_project.css create mode 100644 VNF_Catalogue/public/uploads/logo.png create mode 100644 VNF_Catalogue/routes/add_project.js create mode 100644 VNF_Catalogue/routes/add_tag.js create mode 100644 VNF_Catalogue/routes/edit_project.js create mode 100644 VNF_Catalogue/routes/index.js create mode 100644 VNF_Catalogue/routes/project_profile.js create mode 100644 VNF_Catalogue/routes/search_max.js create mode 100644 VNF_Catalogue/routes/search_projects.js create mode 100644 VNF_Catalogue/routes/search_projects_results.js create mode 100644 VNF_Catalogue/routes/search_tag.js create mode 100644 VNF_Catalogue/routes/search_vnf.js create mode 100644 VNF_Catalogue/routes/vnf_tag_association.js create mode 100644 VNF_Catalogue/style.css create mode 100644 VNF_Catalogue/views/add_project.jade create mode 100644 VNF_Catalogue/views/edit_project.jade create mode 100644 VNF_Catalogue/views/error.jade create mode 100644 VNF_Catalogue/views/index.jade create mode 100644 VNF_Catalogue/views/index_back.jade create mode 100644 VNF_Catalogue/views/layout.jade create mode 100644 VNF_Catalogue/views/project_profile.jade create mode 100644 VNF_Catalogue/views/search.jade create mode 100644 VNF_Catalogue/views/search_projects.jade create mode 100644 VNF_Catalogue/views/vnf_tag_association.jade diff --git a/VNF_Catalogue/.dockerignore b/VNF_Catalogue/.dockerignore new file mode 100644 index 00000000..93f13619 --- /dev/null +++ b/VNF_Catalogue/.dockerignore @@ -0,0 +1,2 @@ +node_modules +npm-debug.log diff --git a/VNF_Catalogue/Dockerfile b/VNF_Catalogue/Dockerfile new file mode 100644 index 00000000..85a68b8e --- /dev/null +++ b/VNF_Catalogue/Dockerfile @@ -0,0 +1,44 @@ +############################################# +# 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 +ENV MINIO_ACCESS_KEY vnf_minio +ENV MINIO_SECRET_KEY vnf_minio +ENV MINIO_HOST minio + +RUN apt-get update +RUN apt-get install vim -y + +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 + +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", "--", "./migration/3rd_party/wait-for-it/wait-for-it.sh", "minio:9000", "-t", "0", "--", "npm", "start" ] diff --git a/VNF_Catalogue/README.md b/VNF_Catalogue/README.md new file mode 100644 index 00000000..91179f51 --- /dev/null +++ b/VNF_Catalogue/README.md @@ -0,0 +1,18 @@ +#VNF_Catalogue Nodejs + Jade + MySql server + + +## Quickstart + +First install docker and docker-compose. This multicontainer app uses +docker-compose to organize the vnf_catalogue web_app + +The use + ```docker-compose up``` + +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'; ``` + + +The server would be accessible at ```ip_address:3000``` diff --git a/VNF_Catalogue/app.js b/VNF_Catalogue/app.js new file mode 100644 index 00000000..67b280de --- /dev/null +++ b/VNF_Catalogue/app.js @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (c) 2017 Kumar Rishabh 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 express = require('express'); +var path = require('path'); +var favicon = require('serve-favicon'); +var logger = require('morgan'); +var cookieParser = require('cookie-parser'); +var bodyParser = require('body-parser'); +var validator = require('express-validator'); + +var routes = require('./routes/index'); +var search_projects = require('./routes/search_projects'); +var search_projects_results = require('./routes/search_projects_results'); +var search_max = require('./routes/search_max'); +var project_profile = require('./routes/project_profile'); +var add_project = require('./routes/add_project'); +var add_tag = require('./routes/add_tag'); +var search_tag = require('./routes/search_tag'); +var search_vnf = require('./routes/search_vnf'); +var vnf_tag_association = require('./routes/vnf_tag_association'); +//var project_profile = require('./routes/project_profile'); + +var app = express(); + +// view engine setup +app.set('views', path.join(__dirname, 'views')); +app.set('view engine', 'jade'); + +db_pool = require('./database').pool; +minio_client = require('./minio').minio_client; +// Database +//var db = require('mysql2'); + +// uncomment after placing your favicon in /public +//app.use(favicon(__dirname + '/public/favicon.ico')); +app.use(logger('dev')); +app.use(bodyParser.json()); +app.use(bodyParser.urlencoded({ extended: false })); +app.use(validator()); +app.use(cookieParser()); +app.use(express.static(path.join(__dirname, 'public'))); + +// create minio bucket if it does not exist +minio_client.makeBucket('opnfv-vnfcatalogue', 'us-east-1', function(err) { + if (err) { + return console.log(err); + } else { + console.log('Bucket created successfully in "us-east-1".'); + } +}); + +// Make our db accessible to our router +app.use(function(req,res,next){ + //db_pool size 50 default + req.db_pool = db_pool; + req.minio = minio_client; + next(); +}); + +app.use('/', routes); +app.use('/search_projects', search_projects); +app.use('/search_projects_results', search_projects_results); +app.use('/project_profile', project_profile); +app.use('/add_project', add_project); +app.use('/add_tag', add_tag); +app.use('/search_tag', search_tag); +app.use('/search_vnf', search_vnf); +app.use('/vnf_tag_association', vnf_tag_association); +app.use('/search_max', search_max); +//app.use('/', project_profile); +// Some Error handling for now #TODO Remove + +/// catch 404 and forwarding to error handler +app.use(function(req, res, next) { + var err = new Error('Not Found'); + err.status = 404; + next(err); +}); + + +// development error handler +// will print stacktrace +if (app.get('env') === 'development') { + app.use(function(err, req, res, next) { + res.status(err.status || 500); + res.render('error', { + message: err.message, + error: err + }); + }); +} + +// production error handler +// no stacktraces leaked to user +app.use(function(err, req, res, next) { + res.status(err.status || 500); + res.render('error', { + message: err.message, + error: {} + }); +}); + +module.exports = app; diff --git a/VNF_Catalogue/bin/www b/VNF_Catalogue/bin/www new file mode 100644 index 00000000..3cfbf779 --- /dev/null +++ b/VNF_Catalogue/bin/www @@ -0,0 +1,9 @@ +#!/usr/bin/env node +var debug = require('debug')('my-application'); +var app = require('../app'); + +app.set('port', process.env.PORT || 3000); + +var server = app.listen(app.get('port'), function() { + debug('Express server listening on port ' + server.address().port); +}); diff --git a/VNF_Catalogue/cronjob/3rd_party/wait-for-it/LICENSE b/VNF_Catalogue/cronjob/3rd_party/wait-for-it/LICENSE new file mode 100644 index 00000000..bd18d0c4 --- /dev/null +++ b/VNF_Catalogue/cronjob/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/cronjob/3rd_party/wait-for-it/README.md b/VNF_Catalogue/cronjob/3rd_party/wait-for-it/README.md new file mode 100644 index 00000000..900b7573 --- /dev/null +++ b/VNF_Catalogue/cronjob/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/cronjob/3rd_party/wait-for-it/wait-for-it.sh b/VNF_Catalogue/cronjob/3rd_party/wait-for-it/wait-for-it.sh new file mode 100755 index 00000000..eca6c3b9 --- /dev/null +++ b/VNF_Catalogue/cronjob/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/cronjob/Dockerfile b/VNF_Catalogue/cronjob/Dockerfile new file mode 100644 index 00000000..350411aa --- /dev/null +++ b/VNF_Catalogue/cronjob/Dockerfile @@ -0,0 +1,55 @@ +############################################################### +# Docker container for VNF_Catalogue cronjob 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" + +RUN apt-get update +RUN apt-get install vim -y +RUN apt-get install cron -y + +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 + +# ADD crontab /etc/cron.d/simple-cron + +COPY . /usr/src/app + +RUN chmod +x git_count_loc.sh +RUN chmod +x script.sh + +RUN crontab crontab +RUN sed -i '/session required pam_loginuid.so/c\#session required pam_loginuid.so' /etc/pam.d/cron + +# Give execution rights on the cron job +# RUN chmod 0644 /etc/cron.d/simple-cron +# +# # Create the log file to be able to run tail +RUN touch /var/log/cron.log + +# The ordering of events should be coming up of mysql service and then running +# of cronjob. 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", "--", "cron", "&&", "tail", "-f", "/var/log/cron.log"] diff --git a/VNF_Catalogue/cronjob/crontab b/VNF_Catalogue/cronjob/crontab new file mode 100644 index 00000000..892f149d --- /dev/null +++ b/VNF_Catalogue/cronjob/crontab @@ -0,0 +1,3 @@ +0 * * * * /usr/src/app/script.sh +# * * * * * root /usr/local/bin/node github +# An empty line is required at the end of this file for a valid cron file. diff --git a/VNF_Catalogue/cronjob/database.js b/VNF_Catalogue/cronjob/database.js new file mode 100644 index 00000000..8c6d0bbf --- /dev/null +++ b/VNF_Catalogue/cronjob/database.js @@ -0,0 +1,16 @@ +var mysql = require('mysql'); + +// Hardcoding some variables for now as crontab does not seem to support +// environment variables. +var pool = mysql.createPool({ + host: 'mysql', + user: 'vnf_user', + password: 'vnf_password', + database: 'vnf_catalogue', + connectionLimit: 50, + supportBigNumbers: true, + multipleStatements: true, + dateStrings: 'date' +}); + +exports.pool = pool; diff --git a/VNF_Catalogue/cronjob/git_count_loc.sh b/VNF_Catalogue/cronjob/git_count_loc.sh new file mode 100755 index 00000000..3b316666 --- /dev/null +++ b/VNF_Catalogue/cronjob/git_count_loc.sh @@ -0,0 +1,11 @@ +folder_name=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13 ; echo ''); + +git clone $1 $folder_name 2> /dev/null +if [ "$?" -ne "0" ]; then + echo 0; + exit 1; +fi +cd $folder_name; +(git ls-files | xargs cat | wc -l) 2> /dev/null; +cd ../; +rm -rf $folder_name; diff --git a/VNF_Catalogue/cronjob/github.js b/VNF_Catalogue/cronjob/github.js new file mode 100644 index 00000000..cc6e35f6 --- /dev/null +++ b/VNF_Catalogue/cronjob/github.js @@ -0,0 +1,159 @@ +// Important Add your access token here default rate of github is limited to 60 API calls per hour +var access_token = '523825265638c8f2b5b9f1d1f5af31d71bceb49c'; +// Important set the delta threshold for repo details updation. For instance if the threshold is +// set to 1 day(60 * 60 * 24), the cronjob will only update the row if the difference between current +// time and last_updated time stamp of a repo is greater than one day +var delta = 60 * 60 * 24; + + +var github = require('octonode'); +db_pool = require('/usr/src/app/database').pool; +async = require('async'); + +var current_time = Math.floor(new Date().getTime() / 1000);//toISOString().slice(0, 19).replace('T', ' '); +console.log(current_time); + +var get_val_from_header = function(header_link) { + // small hack by parsing the header and setting per_page = 1, hence no pagination fetch required + result_intermediate = header_link.split(';'); + result_intermediate = result_intermediate[result_intermediate.length - 2]; + var reg = /&page=([0-9].*)>/g; + var match = reg.exec(result_intermediate); + return parseInt(match[1]); +} + +var get_stargazers = function(result, ghrepo, orig_repo, primary_callback, cb) { + ghrepo.stargazers({per_page: 1}, function(err, data, headers) { + //console.log(JSON.stringify(data)); + try { + result['no_of_stars'] = get_val_from_header(headers['link']); + cb(null, result, ghrepo, orig_repo, primary_callback); + } catch(err) { + result['no_of_stars'] = null; + cb(null, result, ghrepo, orig_repo, primary_callback); + } + }); +} + +var get_branches = function(result, ghrepo, orig_repo, primary_callback, cb) { + ghrepo.branches({per_page: 1}, function(err, data, headers) { + try { + result['versions'] = get_val_from_header(headers['link']); + cb(null, result, ghrepo, orig_repo, primary_callback); + } catch(err) { + result['versions'] = null; + cb(null, result, ghrepo, orig_repo, primary_callback); + } + }); +} + +var get_contributors = function(result, ghrepo, orig_repo, primary_callback, cb) { + ghrepo.contributors({per_page: 1}, function(err, data, headers) { + try { + result['no_of_developers'] = get_val_from_header(headers['link']); + cb(null, result, ghrepo, orig_repo, primary_callback); + } catch(err) { + result['no_of_developers'] = null; + cb(null, result, ghrepo, orig_repo, primary_callback); + } + }); +} + +var get_lines_of_code = function(result, ghrepo, orig_repo, primary_callback, cb) { + // #TODO + console.log('here'); + + console.log(orig_repo); + const + spawn = require( 'child_process' ).spawn, + ls = spawn( 'bash', ['/usr/src/app/git_count_loc.sh', orig_repo] ); + + ls.stdout.on( 'data', data => { + console.log( `stdout: ${data}` ); + result['lines_of_code'] = parseInt(`${data}`.replace(/\n$/, ''), 10); + //cb(null, result, primary_callback); + }); + + ls.stderr.on( 'data', data => { + //console.log( `stderr: ${data}` ); + //cb(null, result, primary_callback); + }); + + ls.on( 'close', code => { + console.log( `child process exited with code ${code}` ); + cb(null, result, primary_callback); + }); +} + +var secondary_callback = function (err, result, primary_callback) { + console.log(result); + if((result['last_updated'] == null) || (current_time - result['last_updated'] > delta)) { + db_pool.getConnection(function(err, connection) { + //Use the connection + var last_updated = current_time; + var no_of_stars = result['no_of_stars']; + var versions = result['versions']; + var no_of_developers = result['no_of_developers']; + var lines_of_code = result['lines_of_code']; + console.log('here'); + console.log(lines_of_code); + sql_query = 'update vnf set last_updated = FROM_UNIXTIME(' + last_updated; + sql_query += '), no_of_stars = ' + no_of_stars + ', versions = ' + versions; + sql_query += ', lines_of_code = ' + lines_of_code; + sql_query += ', no_of_developers = ' + no_of_developers + ' where vnf_id = '; + sql_query += result['vnf_id']; + console.log(sql_query); + connection.query(sql_query, function (error, results, fields) { + //if (error) throw error; + //And done with the connection. + connection.release(); + if(error) { + primary_callback(null, result['vnf_id'] + ' not updated'); + } else { + primary_callback(null, result['vnf_id'] + ' updated'); + } + // Handle error after the release. + // Don't use the connection here, it has been returned to the pool. + }); + }); + } else { + primary_callback(null, result['vnf_id'] + ' not updated'); + } +} + +var get_stats = function(vnf_details, callback) { + repo = vnf_details['repo_url']; + orig_repo = repo; + repo = repo.split("/"); + github_id = repo[repo.length - 2] + '/' + repo[repo.length - 1]; + + var async = require('async'); + var client = github.client(access_token); + var ghrepo = client.repo(github_id); + + result = {} + result['vnf_id'] = vnf_details['vnf_id']; + result['last_updated'] = vnf_details['last_updated']; + + async.waterfall([ + async.apply(get_stargazers, result, ghrepo, orig_repo, callback), + get_branches, + get_contributors, + get_lines_of_code, + ], secondary_callback); +} + +db_pool.getConnection(function(err, connection) { + sql_query = 'select vnf_id, repo_url, UNIX_TIMESTAMP(last_updated) last_updated from vnf'; + console.log(sql_query); + connection.query(sql_query, function (error, results, fields) { + if (error) throw error; + async.map(results, get_stats, function(error, results) { + //console.log(results); + console.log(results); + process.exit(); + + }); + }); +}); + diff --git a/VNF_Catalogue/cronjob/package.json b/VNF_Catalogue/cronjob/package.json new file mode 100644 index 00000000..1b7fb1b5 --- /dev/null +++ b/VNF_Catalogue/cronjob/package.json @@ -0,0 +1,10 @@ +{ + "name": "VNF_Catalogue_cron_jobs", + "version": "0.0.1", + "private": true, + "dependencies": { + "octonode": "*", + "async": "*", + "mysql": "*" + } +} diff --git a/VNF_Catalogue/cronjob/script.sh b/VNF_Catalogue/cronjob/script.sh new file mode 100644 index 00000000..4b5a8d26 --- /dev/null +++ b/VNF_Catalogue/cronjob/script.sh @@ -0,0 +1,2 @@ +#!/bin/bash +/usr/local/bin/node /usr/src/app/github >> /tmp/mybacklog 2>&1 diff --git a/VNF_Catalogue/database.js b/VNF_Catalogue/database.js new file mode 100644 index 00000000..4fa8be10 --- /dev/null +++ b/VNF_Catalogue/database.js @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2017 Kumar Rishabh 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 mysql = require('mysql'); + +var pool = mysql.createPool({ + 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, + dateStrings: 'date' +}); + +exports.pool = pool; diff --git a/VNF_Catalogue/docker-compose.yml b/VNF_Catalogue/docker-compose.yml new file mode 100644 index 00000000..2efba431 --- /dev/null +++ b/VNF_Catalogue/docker-compose.yml @@ -0,0 +1,80 @@ +################################################################## +# 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 + volumes: + - ./persistent_data/database/mysql:/var/lib/mysql + phpmyadmin: + image: phpmyadmin/phpmyadmin + links: + - "mysql:mysql" + ports: + - "8181:80" + environment: + PMA_ARBITRARY: 1 + MYSQL_USERNAME: vnf_user + MYSQL_PASSWORD: vnf_password + MYSQL_ROOT_PASSWORD: root + #- MYSQL_USERNAME=root + minio: + image: minio/minio + environment: + - MINIO_ACCESS_KEY=vnf_minio + - MINIO_SECRET_KEY=vnf_minio + ports: + - "9000:9000" + volumes: + - ./persistent_data/minio/images:/export + command: server /export + vnf_catalogue: + # The vnf_catalogue webapp service. + build: . + container_name: vnf_catalogue_webapp + depends_on: + - mysql + - minio + # Port on which the node.js server would be exposed + # To change host port to say 80 use 80:3000 + + ports: + - "3000:3000" + volumes: + - ./persistent_data/nodejs_server/public_images/:/usr/src/app/public/uploads + 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 + vnf_catalogue_cronjob: + build: ./cronjob + container_name: vnf_catalogue_cronjob + depends_on: + - mysql diff --git a/VNF_Catalogue/docker.sh b/VNF_Catalogue/docker.sh new file mode 100755 index 00000000..8a6622e5 --- /dev/null +++ b/VNF_Catalogue/docker.sh @@ -0,0 +1,8 @@ +sudo chmod -R 777 persistent_data +docker rmi $(docker images -f dangling=true -q) +docker rm $(docker ps -a -f status=exited -q) +docker volume rm $(docker volume ls -f dangling=true -q) +docker-compose stop +docker-compose rm -f +docker-compose build +docker-compose up diff --git a/VNF_Catalogue/docker_commands.sh b/VNF_Catalogue/docker_commands.sh new file mode 100644 index 00000000..3be98ce8 --- /dev/null +++ b/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/VNF_Catalogue/env.sh b/VNF_Catalogue/env.sh new file mode 100644 index 00000000..c1a2ebf7 --- /dev/null +++ b/VNF_Catalogue/env.sh @@ -0,0 +1 @@ +MINIO_HOST='localhost' 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 +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; diff --git a/VNF_Catalogue/minio.js b/VNF_Catalogue/minio.js new file mode 100644 index 00000000..acf5f117 --- /dev/null +++ b/VNF_Catalogue/minio.js @@ -0,0 +1,11 @@ +var Minio = require("minio"); + +var minio_client = new Minio.Client({ + endPoint: 'localhost',//process.env.MINIO_HOST, + port: 9000, + secure: false, + accessKey: process.env.MINIO_ACCESS_KEY, + secretKey: process.env.MINIO_SECRET_KEY +}); + +exports.minio_client = minio_client; diff --git a/VNF_Catalogue/package.json b/VNF_Catalogue/package.json new file mode 100644 index 00000000..8d97069f --- /dev/null +++ b/VNF_Catalogue/package.json @@ -0,0 +1,29 @@ +{ + "name": "VNF_Catalogue", + "version": "0.0.1", + "private": true, + "scripts": { + "start": "node ./bin/www" + }, + "dependencies": { + "body-parser": "~1.15.1", + "cookie-parser": "~1.4.3", + "debug": "~2.2.0", + "express": "~4.13.4", + "jade": "~1.11.0", + "morgan": "~1.7.0", + "serve-favicon": "~2.3.0", + "mysql": "*", + "express-validator": "*", + "nodemon": "*", + "async": "*", + "multer": "*", + "octonode": "*", + "bookshelf": "*", + "knex": "*", + "when": "*", + "lodash": "*", + "moment": "*", + "minio": "*" + } +} diff --git a/VNF_Catalogue/public/3rd_party/materialize-pagination.js b/VNF_Catalogue/public/3rd_party/materialize-pagination.js new file mode 100644 index 00000000..d4509044 --- /dev/null +++ b/VNF_Catalogue/public/3rd_party/materialize-pagination.js @@ -0,0 +1,288 @@ +/* + materialize Pagination v0.2.2 + http://mirjamsk.github.io/materialize-pagination/ + + Sample usage: + $('#pagination').materializePagination({ + align: 'left', + lastPage: 10, + firstPage: 1, + urlParameter: 'page', + useUrlParameter: true, + onClickCallback: function(requestedPage){ + console.log('Requested page is '+ requestedPage) + } + }); +*/ +;(function($, window, document, undefined) { + + var MaterializePagination = function(elem, options) { + this.$elem = $(elem); + this.options = options; + this.$container = null; + this.$prevEllipsis = null; + this.$nextEllipsis = null; + this.currentPage = null; + this.visiblePages = []; + this.maxVisiblePages = 3; + }; + + MaterializePagination.prototype = { + defaults: { + align: 'center', + lastPage: 1, + firstPage: 1, + urlParameter: 'page', + useUrlParameter: true, + onClickCallback: function(){} + }, + + init: function() { + // Combine defaults with user-specified options + this.config = $.extend({}, this.defaults, this.options); + // Get page defined by the urlParameter + var requestedPage = this.config.useUrlParameter ? this.parseUrl() : this.config.firstPage; + // Create initial pagination and add it to the DOM + if(this.createPaginationBase(requestedPage)) + this.bindClickEvent(); + }, + + createPaginationBase: function(requestedPage) { + //alert('getting called'); + if (isNaN(this.config.firstPage) || isNaN(this.config.lastPage) ){ + console.error('Both firstPage and lastPage attributes need to be integer values'); + return false; + } + else if (this.config.firstPage > this.config.lastPage ){ + console.error('Value of firstPage must be less than the value of lastPage'); + return false; + } + this.config.firstPage = parseInt(this.config.firstPage); + this.config.lastPage = parseInt(this.config.lastPage); + this.currentPage = this.config.firstPage - this.maxVisiblePages; + + this.$container = $('