IGNITE-8891 Web Console: Replace IGNITE_MODULES with node_modules.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/4c295f8f Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/4c295f8f Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/4c295f8f Branch: refs/heads/ignite-8446 Commit: 4c295f8f468ddfce458948c17c13b1748b13e918 Parents: 817370e Author: Alexander Kalinin <verba...@yandex.ru> Authored: Thu Jun 28 11:26:25 2018 +0700 Committer: Alexey Kuznetsov <akuznet...@apache.org> Committed: Thu Jun 28 11:27:00 2018 +0700 ---------------------------------------------------------------------- modules/web-console/.dockerignore | 8 +- modules/web-console/.gitignore | 4 +- modules/web-console/DEVNOTES.txt | 86 +- modules/web-console/assembly/README.txt | 11 +- .../web-console/backend/agent_dists/README.txt | 5 +- modules/web-console/backend/app/mongo.js | 5 +- .../ignite_modules/migrations/README.txt | 4 - modules/web-console/backend/index.js | 122 +- modules/web-console/backend/injector.js | 3 +- modules/web-console/backend/launch-tools.js | 109 + modules/web-console/backend/middlewares/api.js | 7 +- modules/web-console/backend/package-lock.json | 6888 ++++++++++++++++++ modules/web-console/backend/package.json | 42 +- .../web-console/backend/services/clusters.js | 15 +- modules/web-console/backend/test/app/db.js | 6 +- .../web-console/backend/test/app/httpAgent.js | 2 +- .../web-console/backend/test/data/caches.json | 60 +- .../web-console/backend/test/data/clusters.json | 6 +- .../web-console/backend/test/data/domains.json | 21 +- modules/web-console/backend/test/index.js | 4 - modules/web-console/backend/test/injector.js | 41 +- .../web-console/backend/test/routes/clusters.js | 13 +- .../web-console/backend/test/routes/public.js | 4 +- .../backend/test/unit/AuthService.test.js | 11 - .../backend/test/unit/CacheService.test.js | 4 +- .../backend/test/unit/ClusterService.test.js | 22 +- .../web-console/backend/test/unit/Utils.test.js | 48 + .../docker/compose/backend/.dockerignore | 3 - .../docker/compose/backend/Dockerfile | 15 +- .../web-console/docker/compose/backend/build.sh | 57 - .../docker/compose/docker-compose.yml | 70 +- .../docker/compose/frontend/.dockerignore | 3 - .../docker/compose/frontend/Dockerfile | 23 +- .../docker/compose/frontend/DockerfileBuild | 30 - .../docker/compose/frontend/build.sh | 59 - .../compose/frontend/nginx/web-console.conf | 5 - .../web-console/docker/standalone/.dockerignore | 2 - .../web-console/docker/standalone/Dockerfile | 73 +- .../web-console/docker/standalone/README.txt | 24 - .../docker/standalone/docker-entrypoint.sh | 23 + .../web-console/docker/standalone/entrypoint.sh | 23 - .../docker/standalone/nginx/web-console.conf | 2 +- modules/web-console/e2e/docker-compose.yml | 2 +- modules/web-console/e2e/testcafe/Dockerfile | 10 +- .../e2e/testcafe/components/FormField.js | 3 + .../e2e/testcafe/components/Table.js | 23 +- .../e2e/testcafe/environment/envtools.js | 196 + .../e2e/testcafe/environment/launch-env.js | 26 + modules/web-console/e2e/testcafe/envtools.js | 192 - .../e2e/testcafe/fixtures/admin-panel.js | 2 +- .../testcafe/fixtures/auth/forgot-password.js | 2 +- .../e2e/testcafe/fixtures/auth/logout.js | 2 +- .../fixtures/auth/signup-validation-local.js | 2 +- .../e2e/testcafe/fixtures/auth/signup.js | 2 +- .../testcafe/fixtures/configuration/basic.js | 5 +- .../testcafe/fixtures/configuration/overview.js | 2 +- .../e2e/testcafe/fixtures/menu-smoke.js | 4 +- .../testcafe/fixtures/queries/notebooks-list.js | 2 +- .../fixtures/user-profile/credentials.js | 2 +- .../testcafe/fixtures/user-profile/profile.js | 2 +- modules/web-console/e2e/testcafe/index.js | 38 + .../web-console/e2e/testcafe/package-lock.json | 2486 +++++++ modules/web-console/e2e/testcafe/package.json | 16 +- modules/web-console/e2e/testcafe/roles.js | 6 +- .../web-console/e2e/testcafe/testcafe-runner.js | 62 + modules/web-console/e2e/testcafe/testcafe.js | 86 - modules/web-console/e2e/testenv/Dockerfile | 71 +- modules/web-console/e2e/testenv/entrypoint.sh | 21 - .../web-console/e2e/testenv/nginx/nginx.conf | 58 +- modules/web-console/frontend/.gitignore | 7 +- modules/web-console/frontend/app/app.js | 9 +- .../list-editable-cols/cols.style.scss | 4 +- .../components/user-notifications/style.scss | 2 +- .../frontend/app/primitives/switcher/index.scss | 2 +- .../frontend/ignite_modules/README.txt | 6 - .../frontend/ignite_modules/index.js | 22 - modules/web-console/frontend/index.js | 22 + modules/web-console/frontend/package-lock.json | 6739 +++++++++++------ modules/web-console/frontend/package.json | 90 +- .../frontend/test/check-doc-links/Dockerfile | 2 +- modules/web-console/frontend/test/ci/Dockerfile | 15 +- .../frontend/test/karma.conf.babel.js | 8 +- modules/web-console/frontend/views/index.pug | 2 +- .../frontend/webpack/webpack.common.js | 46 +- .../frontend/webpack/webpack.dev.babel.js | 4 +- .../frontend/webpack/webpack.prod.babel.js | 10 +- modules/web-console/pom.xml | 565 +- parent/pom.xml | 24 +- 88 files changed, 15321 insertions(+), 3544 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/4c295f8f/modules/web-console/.dockerignore ---------------------------------------------------------------------- diff --git a/modules/web-console/.dockerignore b/modules/web-console/.dockerignore index bcac98f..1958528 100644 --- a/modules/web-console/.dockerignore +++ b/modules/web-console/.dockerignore @@ -1,4 +1,10 @@ .git *Dockerfile* *docker-compose* -*/node_modules* \ No newline at end of file +**/build/ +**/node_modules/ +**/target/ +!web-agent/target/*.zip +**/backend/agent_dists/*.zip +**/backend/config/*.json +**/backend/test \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/4c295f8f/modules/web-console/.gitignore ---------------------------------------------------------------------- diff --git a/modules/web-console/.gitignore b/modules/web-console/.gitignore index 8648ae5..5865cce 100644 --- a/modules/web-console/.gitignore +++ b/modules/web-console/.gitignore @@ -1,5 +1,3 @@ .npmrc -package-lock.json build/ -node_modules/ -data/ +node_modules/ \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/4c295f8f/modules/web-console/DEVNOTES.txt ---------------------------------------------------------------------- diff --git a/modules/web-console/DEVNOTES.txt b/modules/web-console/DEVNOTES.txt index f720611..53aed02 100644 --- a/modules/web-console/DEVNOTES.txt +++ b/modules/web-console/DEVNOTES.txt @@ -1,7 +1,7 @@ Ignite Web Console Build Instructions ===================================== -1. Install locally MongoDB (version >=3.2.x) follow instructions from site http://docs.mongodb.org/manual/installation. -2. Install locally NodeJS (version >=6.5.x) using installer from site https://nodejs.org/en/download/current for your OS. +1. Install MongoDB (version >=3.2.0 <=3.4.15) using instructions from http://docs.mongodb.org/manual/installation. +2. Install Node.js (version >=8.0.0) using installer from https://nodejs.org/en/download/current for your OS. 3. Change directory to '/modules/web-console/backend' and run "npm install --no-optional" for download backend dependencies. 4. Change directory to '/modules/web-console/frontend' and @@ -35,19 +35,69 @@ How to migrate model: Ignite Web Console Direct-Install Maven Build Instructions ========================================================== To build direct-install archive from sources run following command in Ignite project root folder: -"mvn clean package -pl :ignite-web-agent,:ignite-web-console -am -P web-console -DskipTests=true -DskipClientDocs -Dmaven.javadoc.skip=true" +"mvn clean package -pl :ignite-web-console -am -P web-console,direct-install -DskipTests=true -DskipClientDocs -Dmaven.javadoc.skip=true" -Assembled archive can be found here: `/modules/web-console/target/ignite-web-console-direct-install-*.zip`. +Assembled archive can be found here: `modules/web-console/target/ignite-web-console-direct-install-*.zip`. + + +Ignite Web Console Docker Images Build Instructions +=================================================== +Install Docker (version >=17.05) using instructions from https://www.docker.com/community-edition. + +To build docker images from sources run following command in Ignite project root folder: + +"mvn clean package -pl :ignite-web-console -am -P web-console,docker-image -DskipTests=true -DskipClientDocs -Dmaven.javadoc.skip=true" + +Prepared image can be listed with `docker images` command. + + +Ignite Web Console Standalone Docker Image Build Manual Instructions +==================================================================== +Install Docker (version >=17.05) using instructions from https://www.docker.com/community-edition. + +1. Build Apache Ignite Web Agent archive as described in `modules/web-console/web-agent/README.txt`. +2. Goto Web Console's module directory: `cd modules/web-console` +3. Build docker image: + +"docker build . -t apacheignite/web-console-standalone[:<version>] -f docker/standalone/Dockerfile" + +Prepared image can be listed in `docker images` command output. + + +Ignite Web Console Backend Docker Image Build Manual Instructions +==================================================================== +Install Docker (version >=17.05) using instructions from https://www.docker.com/community-edition. + +1. Build Apache Ignite Web Agent archive as described in `modules/web-console/web-agent/README.txt`. +2. Goto Web Console's module directory: `cd modules/web-console` +3. Build docker image: + +"docker build . -t apacheignite/web-console-backend[:<version>] -f docker/compose/backend/Dockerfile" + +Prepared image can be listed in `docker images` command output. + + +Ignite Web Console Frontend Docker Image Build Manual Instructions +==================================================================== +Install Docker (version >=17.05) using instructions from https://www.docker.com/community-edition. + +1. Build Apache Ignite Web Agent archive as described in `modules/web-console/web-agent/README.txt`. +2. Goto Web Console's module directory: `cd modules/web-console` +3. Build docker image: + +"docker build . -t apacheignite/web-console-frontend[:<version>] -f docker/compose/frontend/Dockerfile" + +Prepared image can be listed in `docker images` command output. End-to-end tests ================ -E2E tests are performed with TestCafe framework - https://testcafe.devexpress.com/. +E2E tests are performed with TestCafe framework - https://testcafe.devexpress.com To launch tests on your local machine you will need: 1. Install and launch MongoDB. 2. Optionally install Chromium (https://www.chromium.org/getting-involved/download-chromium or https://chromium.woolyss.com). - You may use any other browser, just set 'BROWSERS' constant in 'modules\web-console\e2e\testcafe.js'. + You may use any other browser, just set 'BROWSERS' constant in 'modules/web-console/e2e/testcafe/index.js'. 3. In new terminal change directory to 'modules/web-console/e2e/testcafe' folder and execute: "npm install". 4. To start test environment and tests execute: "npm run test". @@ -57,7 +107,7 @@ To perform it do the following: 1. Ensure that MongoDB is up and running and all dependencies for backend and frontend are installed. 2. Open directory "modules/web-console/e2e/testcafe" in terminal. Install dependencies for E2E testing with "npm install" command. 3. Execute command "npm run env". This will start backend and frontend environment. -4. Open another terminal window and run command "node testcafe.js" in the same directory. This will run only tests without launching environment. +4. Open another terminal window and run command "node index.js" in the same directory. This will run only tests without launching environment. Please refer to TestCafe documentation at https://devexpress.github.io/testcafe/documentation/test-api/test-code-structure.html#skipping-tests upon how to specify which particular test should be run or skipped. @@ -65,9 +115,27 @@ Please refer to TestCafe documentation at https://devexpress.github.io/testcafe/ You can modify the following params with environment variables: - DB_URL - connection string to test MongoDB. Default: mongodb://localhost/console-e2e - APP_URL - URL for test environment applications. Default: http://localhost:9001 -- TEAMCITY - Whether to use TeamCity reporter. Default: false (native Testcafe "spec" reporter is used) +- REPORTER - Which "TestCafe" reporter to use. Set to 'teamcity' to use Teamcity reporter. Default: "spec" (native Testcafe reporter) You can run tests in docker: 1. Install docker and docker-compose. -2. Execute in terminal: "docker-compose up --abort-on-container-exit" in directory "modules/web-console/e2e". +2. Execute in terminal: "docker-compose up --build --abort-on-container-exit" in directory "modules/web-console/e2e". 3. If you need to cleanup docker container then execute "docker-compose down". + + +Frontend unit tests +=================== +Unit tests are performed with Mocha framework - https://mochajs.org + +To launch tests on your local machine you will need: +1. In new terminal change directory to 'modules/web-console/frontend' folder and execute: "npm install". +2. To start test environment and tests execute: "npm run test". + + +Backend unit tests +================== +Unit tests are performed with Mocha framework - https://mochajs.org + +To launch tests on your local machine you will need: +1. In new terminal change directory to 'modules/web-console/backend' folder and execute: "npm install". +2. To start test environment and tests execute: "npm run test". http://git-wip-us.apache.org/repos/asf/ignite/blob/4c295f8f/modules/web-console/assembly/README.txt ---------------------------------------------------------------------- diff --git a/modules/web-console/assembly/README.txt b/modules/web-console/assembly/README.txt index 540aa9f..9699a48 100644 --- a/modules/web-console/assembly/README.txt +++ b/modules/web-console/assembly/README.txt @@ -1,6 +1,6 @@ Requirements ------------------------------------- -1. JDK 7 bit for your platform, or newer. +1. JDK 8 bit for your platform, or newer. 2. Supported browsers: Chrome, Firefox, Safari, Edge. 3. Ignite cluster should be started with `ignite-rest-http` module in classpath. For this copy `ignite-rest-http` folder from `libs\optional` to `libs` folder. @@ -8,16 +8,17 @@ Requirements How to run ------------------------------------- 1. Unpack ignite-web-console-x.x.x.zip to some folder. -2. Start ignite-web-console-xxx executable for you platform: +2. Change work directory to folder where Web Console was unpacked. +3. Start ignite-web-console-xxx executable for you platform: For Linux: ignite-web-console-linux For MacOS: ignite-web-console-macos For Windows: ignite-web-console-win.exe Note: on Linux and Mac OS X `root` permission is required to bind to 80 port, but you may always start Web Console on another port if you don't have such permission. -3. Open URL `localhost` in browser. -4. Login with user `admin@admin` and password `admin`. -5. Start web agent from folder `web agent`. For Web Agent settings see `web-agent\README.txt`. +4. Open URL `localhost` in browser. +5. Login with user `admin@admin` and password `admin`. +6. Start web agent from folder `web agent`. For Web Agent settings see `web-agent\README.txt`. Cluster URL should be specified in `web-agent\default.properties` in `node-uri` parameter. Technical details http://git-wip-us.apache.org/repos/asf/ignite/blob/4c295f8f/modules/web-console/backend/agent_dists/README.txt ---------------------------------------------------------------------- diff --git a/modules/web-console/backend/agent_dists/README.txt b/modules/web-console/backend/agent_dists/README.txt index d51bdf9..e0a67c6 100644 --- a/modules/web-console/backend/agent_dists/README.txt +++ b/modules/web-console/backend/agent_dists/README.txt @@ -1,7 +1,6 @@ Ignite Web Console ====================================== -This is default folder for agent distributives. - -Also, you could specify custom folder in `serve/config/settings.json` +This is a default directory for agent distributions. +A custom directory can be set in `backend/config/settings.json`. http://git-wip-us.apache.org/repos/asf/ignite/blob/4c295f8f/modules/web-console/backend/app/mongo.js ---------------------------------------------------------------------- diff --git a/modules/web-console/backend/app/mongo.js b/modules/web-console/backend/app/mongo.js index 61f1484..6a843db 100644 --- a/modules/web-console/backend/app/mongo.js +++ b/modules/web-console/backend/app/mongo.js @@ -18,6 +18,8 @@ 'use strict'; const _ = require('lodash'); +const {MongodHelper} = require('mongodb-prebuilt'); +const {MongoDBDownload} = require('mongodb-download'); // Fire me up! @@ -64,9 +66,6 @@ module.exports.factory = function(settings, mongoose, schemas) { .catch((err) => { console.log('Failed to connect to local MongoDB, will try to download and start embedded MongoDB', err); - const {MongodHelper} = require('mongodb-prebuilt'); - const {MongoDBDownload} = require('mongodb-download'); - const helper = new MongodHelper(['--port', '27017', '--dbpath', `${process.cwd()}/user_data`]); helper.mongoBin.mongoDBPrebuilt.mongoDBDownload = new MongoDBDownload({ http://git-wip-us.apache.org/repos/asf/ignite/blob/4c295f8f/modules/web-console/backend/ignite_modules/migrations/README.txt ---------------------------------------------------------------------- diff --git a/modules/web-console/backend/ignite_modules/migrations/README.txt b/modules/web-console/backend/ignite_modules/migrations/README.txt deleted file mode 100644 index daeae36..0000000 --- a/modules/web-console/backend/ignite_modules/migrations/README.txt +++ /dev/null @@ -1,4 +0,0 @@ -Ignite Web Console -====================================== - -This folder contains scripts for modules model migration. http://git-wip-us.apache.org/repos/asf/ignite/blob/4c295f8f/modules/web-console/backend/index.js ---------------------------------------------------------------------- diff --git a/modules/web-console/backend/index.js b/modules/web-console/backend/index.js index ad334bc..4697de9 100644 --- a/modules/web-console/backend/index.js +++ b/modules/web-console/backend/index.js @@ -17,138 +17,22 @@ 'use strict'; -const fs = require('fs'); const path = require('path'); const appPath = require('app-module-path'); appPath.addPath(__dirname); appPath.addPath(path.join(__dirname, 'node_modules')); -const _ = require('lodash'); -const getos = require('getos'); -const http = require('http'); -const https = require('https'); -const MigrateMongoose = require('migrate-mongoose'); +const { migrate, init } = require('./launch-tools'); - -const packaged = __dirname.startsWith('/snapshot/') || __dirname.startsWith('C:\\snapshot\\'); - -const igniteModules = !packaged && process.env.IGNITE_MODULES ? - path.join(path.normalize(process.env.IGNITE_MODULES), 'backend') : path.join(__dirname, 'ignite_modules'); - -let injector; - -try { - const igniteModulesInjector = path.resolve(path.join(igniteModules, 'injector.js')); - - fs.accessSync(igniteModulesInjector, fs.F_OK); - - process.env.NODE_PATH = path.join(__dirname, 'node_modules'); - - injector = require(igniteModulesInjector); -} -catch (ignore) { - injector = require(path.join(__dirname, 'injector')); -} - -/** - * Event listener for HTTP server "error" event. - */ -const _onError = (addr, error) => { - if (error.syscall !== 'listen') - throw error; - - // Handle specific listen errors with friendly messages. - switch (error.code) { - case 'EACCES': - console.error(`Requires elevated privileges for bind to ${addr}`); - process.exit(1); - - break; - case 'EADDRINUSE': - console.error(`${addr} is already in use`); - process.exit(1); - - break; - default: - throw error; - } -}; - -/** - * @param settings - * @param {ApiServer} apiSrv - * @param {AgentsHandler} agentsHnd - * @param {BrowsersHandler} browsersHnd - */ -const init = ([settings, apiSrv, agentsHnd, browsersHnd]) => { - // Start rest server. - const srv = settings.server.SSLOptions ? https.createServer(settings.server.SSLOptions) : http.createServer(); - - srv.listen(settings.server.port, settings.server.host); - - const addr = `${settings.server.host}:${settings.server.port}`; - - srv.on('error', _onError.bind(null, addr)); - srv.on('listening', () => console.log(`Start listening on ${addr}`)); - - apiSrv.attach(srv); - - agentsHnd.attach(srv, browsersHnd); - browsersHnd.attach(srv, agentsHnd); - - // Used for automated test. - if (process.send) - process.send('running'); -}; - -/** - * Run mongo model migration. - * - * @param dbConnectionUri Mongo connection url. - * @param group Migrations group. - * @param migrationsPath Migrations path. - * @param collectionName Name of collection where migrations write info about applied scripts. - */ -const migrate = (dbConnectionUri, group, migrationsPath, collectionName) => { - const migrator = new MigrateMongoose({ - migrationsPath, - dbConnectionUri, - collectionName, - autosync: true - }); - - console.log(`Running ${group} migrations...`); - - return migrator.run('up') - .then(() => console.log(`All ${group} migrations finished successfully.`)) - .catch((err) => { - const msg = _.get(err, 'message'); - - if (_.startsWith(msg, 'There are no migrations to run') || _.startsWith(msg, 'There are no pending migrations.')) { - console.log(`There are no ${group} migrations to run.`); - - return; - } - - throw err; - }); -}; - -getos(function(e, os) { - if (e) - return console.log(e); - - console.log('Your OS is: ' + JSON.stringify(os)); -}); +const injector = require('./injector'); injector.log.info = () => {}; injector.log.debug = () => {}; Promise.all([injector('settings'), injector('mongo')]) .then(([{mongoUrl}]) => { - return migrate(mongoUrl, 'Ignite', path.join(__dirname, 'migrations')) - .then(() => migrate(mongoUrl, 'Ignite Modules', path.join(igniteModules, 'migrations'), 'migrationsModules')); + return migrate(mongoUrl, 'Ignite', path.join(__dirname, 'migrations')); }) .then(() => Promise.all([injector('settings'), injector('api-server'), injector('agents-handler'), injector('browsers-handler')])) .then(init) http://git-wip-us.apache.org/repos/asf/ignite/blob/4c295f8f/modules/web-console/backend/injector.js ---------------------------------------------------------------------- diff --git a/modules/web-console/backend/injector.js b/modules/web-console/backend/injector.js index 754967f..c30609a 100644 --- a/modules/web-console/backend/injector.js +++ b/modules/web-console/backend/injector.js @@ -24,7 +24,6 @@ module.exports = fireUp.newInjector({ './errors/**/*.js', './middlewares/**/*.js', './routes/**/*.js', - './services/**/*.js', - './ignite_modules/**/*.js' + './services/**/*.js' ] }); http://git-wip-us.apache.org/repos/asf/ignite/blob/4c295f8f/modules/web-console/backend/launch-tools.js ---------------------------------------------------------------------- diff --git a/modules/web-console/backend/launch-tools.js b/modules/web-console/backend/launch-tools.js new file mode 100644 index 0000000..f1f3b2f --- /dev/null +++ b/modules/web-console/backend/launch-tools.js @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +const _ = require('lodash'); +const http = require('http'); +const https = require('https'); +const MigrateMongoose = require('migrate-mongoose'); + +/** + * Event listener for HTTP server "error" event. + */ +const _onError = (addr, error) => { + if (error.syscall !== 'listen') + throw error; + + // Handle specific listen errors with friendly messages. + switch (error.code) { + case 'EACCES': + console.error(`Requires elevated privileges for bind to ${addr}`); + process.exit(1); + + break; + case 'EADDRINUSE': + console.error(`${addr} is already in use`); + process.exit(1); + + break; + default: + throw error; + } +}; + +/** + * @param settings + * @param {ApiServer} apiSrv + * @param {AgentsHandler} agentsHnd + * @param {BrowsersHandler} browsersHnd + */ +const init = ([settings, apiSrv, agentsHnd, browsersHnd]) => { + // Start rest server. + const srv = settings.server.SSLOptions ? https.createServer(settings.server.SSLOptions) : http.createServer(); + + srv.listen(settings.server.port, settings.server.host); + + const addr = `${settings.server.host}:${settings.server.port}`; + + srv.on('error', _onError.bind(null, addr)); + srv.on('listening', () => console.log(`Start listening on ${addr}`)); + + apiSrv.attach(srv); + + agentsHnd.attach(srv, browsersHnd); + browsersHnd.attach(srv, agentsHnd); + + // Used for automated test. + if (process.send) + process.send('running'); +}; + +/** + * Run mongo model migration. + * + * @param dbConnectionUri Mongo connection url. + * @param group Migrations group. + * @param migrationsPath Migrations path. + * @param collectionName Name of collection where migrations write info about applied scripts. + */ +const migrate = (dbConnectionUri, group, migrationsPath, collectionName) => { + const migrator = new MigrateMongoose({ + migrationsPath, + dbConnectionUri, + collectionName, + autosync: true + }); + + console.log(`Running ${group} migrations...`); + + return migrator.run('up') + .then(() => console.log(`All ${group} migrations finished successfully.`)) + .catch((err) => { + const msg = _.get(err, 'message'); + + if (_.startsWith(msg, 'There are no migrations to run') || _.startsWith(msg, 'There are no pending migrations.')) { + console.log(`There are no ${group} migrations to run.`); + + return; + } + + throw err; + }); +}; + +module.exports = { migrate, init }; http://git-wip-us.apache.org/repos/asf/ignite/blob/4c295f8f/modules/web-console/backend/middlewares/api.js ---------------------------------------------------------------------- diff --git a/modules/web-console/backend/middlewares/api.js b/modules/web-console/backend/middlewares/api.js index e901ec4..464471b 100644 --- a/modules/web-console/backend/middlewares/api.js +++ b/modules/web-console/backend/middlewares/api.js @@ -19,12 +19,13 @@ // Fire me up! +const _ = require('lodash'); + module.exports = { - implements: 'middlewares:api', - inject: ['require(lodash)'] + implements: 'middlewares:api' }; -module.exports.factory = (_) => { +module.exports.factory = () => { return (req, res, next) => { // Set headers to avoid API caching in browser (esp. IE) res.header('Cache-Control', 'must-revalidate');