Skip to content

Commit

Permalink
Merge pull request #2 from rmothilal/master
Browse files Browse the repository at this point in the history
Changes made based on Migules comments on previous PR
  • Loading branch information
rmothilal authored Jul 11, 2019
2 parents b351b6f + 5a5320c commit 029564e
Show file tree
Hide file tree
Showing 29 changed files with 3,368 additions and 2,717 deletions.
22 changes: 22 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"nyc": {
"temp-directory": "./.nyc_output",
"check-coverage": true,
"per-file": true,
"lines": 90,
"statements": 90,
"functions": 90,
"branches": 90,
"all": true,
"include": [
"src/**/*.js"
],
"reporter": [
"lcov",
"text-summary"
],
"exclude": [
"**/node_modules/**"
]
}
}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ RUN apk del build-dependencies
COPY config /opt/event-sidecar/config
COPY src /opt/event-sidecar/src

EXPOSE 4000
EXPOSE 4001
CMD ["npm", "run", "start"]
1 change: 1 addition & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ The Mojaloop files are made available by the Bill & Melinda Gates Foundation und
[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](http://www.apache.org/licenses/LICENSE-2.0).

19 changes: 0 additions & 19 deletions api.Dockerfile

This file was deleted.

2 changes: 2 additions & 0 deletions config/default.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"PORT": 4001,
"EVENT_LOGGER_GRPC_HOST": "localhost",
"EVENT_LOGGER_GRPC_PORT": 50051,
"INSTRUMENTATION": {
"METRICS": {
"DISABLED": false,
Expand Down
5,026 changes: 2,649 additions & 2,377 deletions package-lock.json

Large diffs are not rendered by default.

37 changes: 10 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "event-sidecar",
"description": "Event Sidecar is used to route and events to Kafka",
"version": "1.0.0",
"version": "6.4.0",
"author": "Rajiv Mothilal <rajiv.mothilal@modusbox.com>",
"contributors": [
"Rajiv Mothilal <rajiv.mothilal@modusbox.com>"
Expand All @@ -22,35 +22,16 @@
"src/**/*.js"
]
},
"nyc": {
"temp-directory": "./.nyc_output",
"check-coverage": true,
"per-file": true,
"lines": 90,
"statements": 90,
"functions": 90,
"branches": 90,
"all": true,
"include": [
"src/**/*.js"
],
"reporter": [
"lcov",
"text-summary"
],
"exclude": [
"**/node_modules/**"
]
},
"dependencies": {
"@hapi/boom": "7.4.2",
"@hapi/good": "8.2.0",
"@hapi/hapi": "18.3.1",
"@hapi/inert": "5.2.0",
"@hapi/inert": "5.2.1",
"@hapi/vision": "5.5.2",
"@mojaloop/central-services-metrics": "5.2.0",
"@mojaloop/central-services-shared": "5.2.0",
"@mojaloop/central-services-shared": "6.4.1",
"@mojaloop/central-services-stream": "6.2.2",
"@mojaloop/event-sdk": "6.4.8-snapshot",
"blipp": "4.0.0",
"glob": "7.1.4",
"hapi-openapi": "1.2.2",
Expand All @@ -59,19 +40,21 @@
"uuid4": "1.1.4"
},
"devDependencies": {
"ava": "2.1.0",
"eslint": "5.16.0",
"ava": "2.2.0",
"eslint": "6.0.1",
"get-port": "5.0.0",
"nyc": "14.1.1",
"proxyquire": "2.1.0",
"rewire": "4.0.1",
"sinon": "7.3.2",
"standard": "13.0.0",
"swagmock": "1.0.0"
},
"scripts": {
"start": "node src/index.js api",
"test": "npx ava test/unit/ match=.test.js",
"start": "node src/index.js server --api",
"test": "npx ava test/unit/**/*.test.js",
"cover": "npx nyc --all report --reporter=lcov npm run test",
"test:coverage": "nyc ava",
"lint": "eslint .",
"regenerate": "yo swaggerize:test --framework hapi --apiPath './src/interface/swagger.json'"
},
Expand Down
14 changes: 7 additions & 7 deletions src/domain/event/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

const kafkaUtil = require('../../lib/kafka/util')
const Enums = require('../../lib/enum')
const Boom = require('@hapi/boom')
const Logger = require('@mojaloop/central-services-shared').Logger

/**
* @function logEvent
Expand All @@ -38,7 +38,7 @@ const Boom = require('@hapi/boom')
* @returns {Promise<true>} Returns if the logging of the event is successful or not
*/
const logEvent = async (message) => {
return await kafkaUtil.produceGeneralMessage(Enums.eventType.EVENT, message, message.metadata.trace.traceId)
return kafkaUtil.produceGeneralMessage(Enums.eventType.EVENT, message, message.metadata.trace.traceId)
}

/**
Expand All @@ -48,16 +48,16 @@ const logEvent = async (message) => {
*
* @returns {boolean} Returns if the logging of the event is successful or not
*/
const handleRestRequest = async (request, h) => {
const handleRestRequest = async (payload) => {
try {
await logEvent(request.payload)
return h.response().code(200)
return logEvent(payload)
} catch (e) {
throw Boom.badRequest(e.message)
Logger.error(e)
throw e
}
}

module.exports = {
logEvent,
handleRestRequest
}
}
30 changes: 15 additions & 15 deletions src/domain/metadata/health.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@
const packageJson = require('../../../package.json')
// const Util = require('../lib//kafka/util')
// const Kafka = require('../lib/kafka')
const Enum = require('../../lib/enum')
// const Enum = require('../../lib/enum')

const eventType = Enum.eventType
const eventAction = Enum.eventAction
// const eventType = Enum.eventType
// const eventAction = Enum.eventAction

const statusEnum = {
OK: 'OK',
DOWN: 'DOWN'
}

const serviceName = {
datastore: 'datastore',
broker: 'broker',
sidecar: 'sidecar',
cache: 'cache'
}
// const serviceName = {
// datastore: 'datastore',
// broker: 'broker',
// sidecar: 'sidecar',
// cache: 'cache'
// }

/**
* getHealth
Expand Down Expand Up @@ -69,9 +69,9 @@ const serviceName = {
*/
const getHealth = async function (request, h) {
// Default values
let statusCode = 200
let status = statusEnum.OK
let isHealthy = true
const statusCode = 200
const status = statusEnum.OK
// const isHealthy = true
// let services = []
// let subServices = {}

Expand Down Expand Up @@ -102,10 +102,10 @@ const getHealth = async function (request, h) {
status,
uptime,
startTime,
versionNumber,
versionNumber
// ...subServices
}
return {response, statusCode}
return { response, statusCode }
}

// /**
Expand Down Expand Up @@ -178,4 +178,4 @@ module.exports = {
getHealth
// getSubServiceHealth,
// evaluateServiceHealth
}
}
24 changes: 24 additions & 0 deletions src/handlers/event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict'

const Boom = require('@hapi/boom')
const handler = require('../domain/event/handler')
/**
* Operations on /event
*/
module.exports = {
/**
* summary: Post Event
* description: The HTTP request POST /event is a REST endpoint to add an event to a Kafka Topic.
* parameters: body
* produces: application/json
* responses: 200, 400, 401, 403, 404, 405, 406, 501, 503
*/
post: async function (request, h) {
try {
await handler.handleRestRequest(request.payload)
return h.response().code(201)
} catch (e) {
return Boom.badRequest(e.message)
}
}
}
4 changes: 2 additions & 2 deletions src/handlers/health.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ module.exports = {
*/
get: async (request, h) => {
try {
let {response, statusCode} = await handler.getHealth()
const { response, statusCode } = await handler.getHealth()
return h.response(response).code(statusCode)
} catch (e) {
throw Boom.badRequest(e.message)
return Boom.badRequest(e.message)
}
}
}
47 changes: 0 additions & 47 deletions src/handlers/routes.js

This file was deleted.

21 changes: 11 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,28 @@

const Server = require('./server')
const PJson = require('../package.json')
const {Command} = require('commander')
const { Command } = require('commander')
const Config = require('./lib/config')
const Logger = require('@mojaloop/central-services-shared').Logger

const Program = new Command()

Program
.version(PJson.version)
.description('CLI to manage Servers')

Program.command('api') // sub-command name, coffeeType = type, required
.alias('a') // alternative sub-command is `o`
Program.command('server')
.alias('a')
.description('Start the Event Sidecar. Use options to specify server type of none to run both') // command description

// function to execute when command is uses
.option('--api', 'Start API server')
// function to execute when command is used
.action(async (args) => {
let options = {
port: Config.PORT,
serviceName: args
let options = {}
if (args.api) {
options = {
port: Config.PORT
}
}
module.exports = Server.initialize(options.port, options.serviceName)
module.exports = Server.initialize(options.port || 4002)
})

if (Array.isArray(process.argv) && process.argv.length > 1) {
Expand Down
Loading

0 comments on commit 029564e

Please sign in to comment.