Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to support Bulk release: #313

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"POOL_MAX": 30
},
"MONGODB": {
"DISABLED": false,
"URI": "mongodb://localhost:27017/mlos"
},
"HANDLERS": {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mojaloop/central-ledger",
"version": "7.1.0",
"version": "7.1.1",
"description": "Central ledger hosted by a scheme to record and settle transfers",
"license": "Apache-2.0",
"author": "ModusBox",
Expand Down
1 change: 1 addition & 0 deletions src/handlers/bulk/fulfil/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,5 +265,6 @@ const registerAllHandlers = async () => {

module.exports = {
bulkFulfil,
registerBulkFulfilHandler,
registerAllHandlers
}
62 changes: 62 additions & 0 deletions src/handlers/bulk/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*****
* @file This registers all handlers for the central-ledger API
License
--------------
Copyright © 2017 Bill & Melinda Gates Foundation
The Mojaloop files are made available by the Bill & Melinda Gates Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files 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, the Mojaloop files are 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.

Contributors
--------------
This is the official list of the Mojaloop project contributors for this file.
Names of the original copyright holders (individuals or organizations)
should be listed with a '*' in the first column. People who have
contributed from an organization can be listed under the organization
that actually holds the copyright for their contributions (see the
Gates Foundation organization for an example). Those individuals should have
their names indented and be marked with a '-'. Email address can be added
optionally within square brackets <email>.

* Gates Foundation
- Name Surname <name.surname@gatesfoundation.com>

* ModusBox
- Miguel de Barros <miguel.debarros@modusbox.com>

--------------
******/

'use strict'

const BulkPrepareHandlers = require('./prepare/handler')
const BulkFulfilHandlers = require('./fulfil/handler')
const BulkProcessingHandlers = require('./processing/handler')

/**
* @function RegisterAllHandlers
*
* @async
* @description Registers all module handlers
*
* @returns {boolean} - Returns a boolean: true if successful, or throws and error if failed
*/
const registerAllHandlers = async () => {
try {
await BulkPrepareHandlers.registerAllHandlers()
await BulkFulfilHandlers.registerAllHandlers()
await BulkProcessingHandlers.registerAllHandlers()
return true
} catch (e) {
throw e
}
}

module.exports = {
registerBulkPrepareHandler: BulkPrepareHandlers.registerBulkPrepareHandler,
registerBulkFulfilHandler: BulkFulfilHandlers.registerBulkFulfilHandler,
registerBulkProcessingHandler: BulkProcessingHandlers.registerBulkProcessingHandler,
registerAllHandlers
}
1 change: 1 addition & 0 deletions src/handlers/bulk/prepare/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,5 +265,6 @@ const registerAllHandlers = async () => {
module.exports = {
bulkPrepare,
getBulkMessage,
registerBulkPrepareHandler,
registerAllHandlers
}
1 change: 1 addition & 0 deletions src/handlers/bulk/processing/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,5 +360,6 @@ const registerAllHandlers = async () => {

module.exports = {
bulkProcessing,
registerBulkProcessingHandler,
registerAllHandlers
}
27 changes: 27 additions & 0 deletions src/handlers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ Program.command('handler') // sub-command name, coffeeType = type, required
.option('--fulfil', 'Start the Fulfil Handler')
.option('--timeout', 'Start the Timeout Handler')
.option('--admin', 'Start the Admin Handler')
.option('--bulkprepare', 'Start the Bulk Prepare Handler')
.option('--bulkfulfil', 'Start the Bulk Fulfil Handler')
.option('--bulkprocessing', 'Start the Bulk Processing Handler')
// .option('--reject', 'Start the Reject Handler')

// function to execute when command is uses
Expand Down Expand Up @@ -109,6 +112,30 @@ Program.command('handler') // sub-command name, coffeeType = type, required
}
handlerList.push(handler)
}
if (args.bulkprepare) {
Logger.debug(`CLI: Executing --bulkprepare`)
let handler = {
type: 'bulkprepare',
enabled: true
}
handlerList.push(handler)
}
if (args.bulkfulfil) {
Logger.debug(`CLI: Executing --bulkfulfil`)
let handler = {
type: 'bulkfulfil',
enabled: true
}
handlerList.push(handler)
}
if (args.bulkprocessing) {
Logger.debug(`CLI: Executing --bulkprocessing`)
let handler = {
type: 'bulkprocessing',
enabled: true
}
handlerList.push(handler)
}

module.exports = Setup.initialize({
service: 'handler',
Expand Down
15 changes: 9 additions & 6 deletions src/handlers/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
* Gates Foundation
- Name Surname <name.surname@gatesfoundation.com>

* Georgi Georgiev <georgi.georgiev@modusbox.com>
* Lazola Lucas <lazola.lucas@modusbox.com>
* Rajiv Mothilal <rajiv.mothilal@modusbox.com>
* Miguel de Barros <miguel.debarros@modusbox.com>
* ModusBox
- Georgi Georgiev <georgi.georgiev@modusbox.com>
- Lazola Lucas <lazola.lucas@modusbox.com>
- Rajiv Mothilal <rajiv.mothilal@modusbox.com>
- Miguel de Barros <miguel.debarros@modusbox.com>

--------------
******/
Expand All @@ -51,7 +52,7 @@ const TransferHandlers = require('./transfers/handler')
const PositionHandlers = require('./positions/handler')
const TimeoutHandlers = require('./timeouts/handler')
const AdminHandlers = require('./admin/handler')
const BulkPrepareHandlers = require('./bulk/prepare/handler')
const BulkHandlers = require('./bulk')

const registerAllHandlers = async () => {
try {
Expand Down Expand Up @@ -98,6 +99,8 @@ module.exports = {
registerAdminHandlers: AdminHandlers.registerAllHandlers
},
bulk: {
registerBulkHandlers: BulkPrepareHandlers.registerAllHandlers
registerBulkPrepareHandler: BulkHandlers.registerBulkPrepareHandler,
registerBulkFulfilHandler: BulkHandlers.registerBulkFulfilHandler,
registerBulkProcessingHandler: BulkHandlers.registerBulkProcessingHandler
}
}
11 changes: 6 additions & 5 deletions src/handlers/transfers/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
* Gates Foundation
- Name Surname <name.surname@gatesfoundation.com>

* Georgi Georgiev <georgi.georgiev@modusbox.com>
* Rajiv Mothilal <rajiv.mothilal@modusbox.com>
* Miguel de Barros <miguel.debarros@modusbox.com>
* Deon Botha <deon.botha@modusbox.com>
* Shashikant Hirugade <shashikant.hirugade@modusbox.com>
* ModusBox
- Georgi Georgiev <georgi.georgiev@modusbox.com>
- Rajiv Mothilal <rajiv.mothilal@modusbox.com>
- Miguel de Barros <miguel.debarros@modusbox.com>
- Deon Botha <deon.botha@modusbox.com>
- Shashikant Hirugade <shashikant.hirugade@modusbox.com>

--------------
******/
Expand Down
1 change: 1 addition & 0 deletions src/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
DB_CONNECTION_POOL_MIN: RC.DB_CONNECTION.POOL_MIN,
DB_CONNECTION_POOL_MAX: RC.DB_CONNECTION.POOL_MAX,
MONGODB_URI: RC.MONGODB.URI,
MONGODB_DISABLED: RC.MONGODB.DISABLED,
AMOUNT: RC.AMOUNT,
EXPIRES_TIMEOUT: RC.EXPIRES_TIMEOUT,
SIDECAR: RC.SIDECAR,
Expand Down
34 changes: 24 additions & 10 deletions src/shared/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
* Gates Foundation
- Name Surname <name.surname@gatesfoundation.com>

* Georgi Georgiev <georgi.georgiev@modusbox.com>
* Rajiv Mothilal <rajiv.mothilal@modusbox.com>
* Miguel de Barros <miguel.debarros@modusbox.com>
* ModusBox
- Georgi Georgiev <georgi.georgiev@modusbox.com>
- Rajiv Mothilal <rajiv.mothilal@modusbox.com>
- Miguel de Barros <miguel.debarros@modusbox.com>

--------------
******/
Expand Down Expand Up @@ -61,13 +62,17 @@ const connectDatabase = async () => {
return result
}
const connectMongoose = async () => {
try {
let db = await ObjStoreDb.connect(Config.MONGODB_URI, {
promiseLibrary: global.Promise
})
return db
} catch (error) {
Logger.error(`error - ${error}`) // TODO: ADD PROPER ERROR HANDLING HERE POST-POC
if (!Config.MONGODB_DISABLED) {
try {
let db = await ObjStoreDb.connect(Config.MONGODB_URI, {
promiseLibrary: global.Promise
})
return db
} catch (error) {
Logger.error(`error - ${error}`) // TODO: ADD PROPER ERROR HANDLING HERE POST-POC
return null
}
} else {
return null
}
}
Expand Down Expand Up @@ -188,6 +193,15 @@ const createHandlers = async (handlers) => {
case 'get':
await RegisterHandlers.transfers.registerGetHandler()
break
case 'bulkprepare':
await RegisterHandlers.bulk.registerBulkPrepareHandler()
break
case 'bulkfulfil':
await RegisterHandlers.bulk.registerBulkFulfilHandler()
break
case 'bulkprocessing':
await RegisterHandlers.bulk.registerBulkProcessingHandler()
break
default:
let error = `Handler Setup - ${JSON.stringify(handler)} is not a valid handler to register!`
Logger.error(error)
Expand Down
1 change: 1 addition & 0 deletions test/integration-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"POOL_MAX": 30
},
"MONGODB": {
"DISABLED": false,
"URI": "mongodb://localhost:27017/mlos"
},
"HANDLERS": {
Expand Down
25 changes: 23 additions & 2 deletions test/unit/handlers/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ Test('cli', async (cliTest) => {
'--get',
'--fulfil',
'--timeout',
'--admin'
'--admin',
'--bulkprepare',
'--bulkfulfil',
'--bulkprocessing'
]

process.argv = argv
Expand Down Expand Up @@ -97,13 +100,31 @@ Test('cli', async (cliTest) => {
enabled: true
}

const bulkprepareHandler = {
type: 'bulkprepare',
enabled: true
}

const bulkfulfilHandler = {
type: 'bulkfulfil',
enabled: true
}

const bulkprocessingHandler = {
type: 'bulkprocessing',
enabled: true
}

const modulesList = [
prepareHandler,
positionHandler,
getHandler,
fulfilHandler,
timeoutHandler,
adminHandler
adminHandler,
bulkprepareHandler,
bulkfulfilHandler,
bulkprocessingHandler
// rejectHandler
]

Expand Down
39 changes: 37 additions & 2 deletions test/unit/shared/setup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Test('setup', setupTest => {
const ConfigStub = Config
ConfigStub.HANDLERS_API_DISABLED = false
ConfigStub.HANDLERS_CRON_DISABLED = false
ConfigStub.MONGODB_DISABLED = false

Setup = Proxyquire('../../../src/shared/setup', {
'uuid4': uuidStub,
Expand Down Expand Up @@ -182,7 +183,7 @@ Test('setup', setupTest => {
})

setupTest.test('initialize should', async (initializeTest) => {
initializeTest.test('connect to sidecar', async (test) => {
initializeTest.test('connect to Database, Sidecar & ObjStore', async (test) => {
const service = 'api'

Setup.initialize({ service }).then(s => {
Expand All @@ -198,6 +199,40 @@ Test('setup', setupTest => {
})
})

initializeTest.test('connect to Database & Sidecar, but NOT too ObjStore', async (test) => {
const ConfigStub = Config
ConfigStub.MONGODB_DISABLED = true

const service = 'api'

Setup = Proxyquire('../../../src/shared/setup', {
'uuid4': uuidStub,
'../handlers/register': RegisterHandlersStub,
'../lib/db': DbStub,
'@mojaloop/central-object-store': ObjStoreStub,
'../lib/migrator': MigratorStub,
'../lib/sidecar': SidecarStub,
'../lib/requestLogger': requestLoggerStub,
'./plugins': PluginsStub,
'../lib/urlParser': UrlParserStub,
'hapi': HapiStub,
'../lib/config': ConfigStub
// '../handlers/lib/kafka': KafkaCronStub
})

Setup.initialize({ service }).then(s => {
test.ok(DbStub.connect.calledWith(databaseUri))
test.notOk(ObjStoreStub.Db.connect.called)
test.ok(SidecarStub.connect.calledWith(service))
test.notOk(MigratorStub.migrate.called)
test.equal(s, serverStub)
test.end()
}).catch(err => {
test.fail(`Should have not received an error: ${err}`)
test.end()
})
})

initializeTest.test('connect to db and return hapi server for "api"', async (test) => {
const service = 'api'

Expand Down Expand Up @@ -360,7 +395,7 @@ Test('setup', setupTest => {
'./plugins': PluginsStub,
'../lib/urlParser': UrlParserStub,
'hapi': HapiStub,
'../lib/config': Config
'../lib/config': ConfigStub
// '../handlers/lib/kafka': KafkaCronStub
})

Expand Down
3 changes: 2 additions & 1 deletion test/util/scripts/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
export KAFKA_ID=kafka
export MOCKSERVER_ID=mockserver
export DB_ID=mysql
export SLEEP_FACTOR_IN_SECONDS=5
export DBUSER=central_ledger
export DBPASS=password
export DBNAME=central_ledger
export DB_SLEEPTIME=15
export OBJ_ID=objstore
export SLEEP_FACTOR_IN_SECONDS=5
export MESSAGES_BATCH_SIZE=1000
export SCRIPT_DIR=scripts
export FSPList=("dfsp1" "dfsp2")
Expand Down
Loading