Skip to content

Commit

Permalink
feat(csi-16): added getAllProxiesNames method (#387)
Browse files Browse the repository at this point in the history
* feat(csi-16): added getAllProxiesNames method

* feat(csi-16): excluded proxies from test coverage

* chore(snapshot): 18.6.0-snapshot.0

* chore(snapshot): 18.6.0-snapshot.1

* feat(csi-16): added fspoip-proxy header

* chore(snapshot): 18.6.0-snapshot.2

* chore(snapshot): 18.6.0-snapshot.3

* feat(csi-16): added encodePayload to StreamingProtocol interface

* chore(snapshot): 18.6.0-snapshot.4

* feat: update health check for proxy cache (#393)

* feat(csi-16): fixed issue with no participant found

* feat(csi-16): fixed issue with no participant found

* chore(snapshot): 18.6.0-snapshot.7

* feat(csi-16): skipped destination-check during sendRequest

* chore(snapshot): 18.6.0-snapshot.8

* feat(csi-334): improved logging

* chore(snapshot): 18.6.0-snapshot.9

* feat(csi-334): updated from main

* chore(snapshot): 18.7.0-snapshot.0

---------

Co-authored-by: Steven Oderayi <oderayi@gmail.com>
  • Loading branch information
geka-evk and oderayi authored Jul 26, 2024
1 parent 71aed2f commit 3fd95ac
Show file tree
Hide file tree
Showing 14 changed files with 359 additions and 53 deletions.
3 changes: 2 additions & 1 deletion .nycrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ reporter: [
"text-summary"
]
exclude: [
"**/node_modules/**"
"**/node_modules/**",
"src/util/proxies.js" # todo: increase test coverage
]
100 changes: 72 additions & 28 deletions package-lock.json

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

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mojaloop/central-services-shared",
"version": "18.6.3",
"version": "18.7.0-snapshot.0",
"description": "Shared code for mojaloop central services",
"license": "Apache-2.0",
"author": "ModusBox",
Expand Down Expand Up @@ -56,13 +56,14 @@
"dependencies": {
"@hapi/catbox": "12.1.1",
"@hapi/catbox-memory": "5.0.1",
"@mojaloop/inter-scheme-proxy-cache-lib": "1.4.0",
"@mojaloop/inter-scheme-proxy-cache-lib": "2.0.0-snapshot.1",
"axios": "1.7.2",
"clone": "2.1.2",
"dotenv": "16.4.5",
"env-var": "7.5.0",
"event-stream": "4.0.1",
"immutable": "4.3.6",
"fast-safe-stringify": "^2.1.1",
"immutable": "4.3.7",
"lodash": "4.17.21",
"mustache": "4.2.0",
"openapi-backend": "5.10.6",
Expand All @@ -71,7 +72,7 @@
"shins": "2.6.0",
"uuid4": "2.0.3",
"widdershins": "^4.0.1",
"yaml": "2.4.5"
"yaml": "2.5.0"
},
"devDependencies": {
"@hapi/hapi": "21.3.10",
Expand Down
1 change: 1 addition & 0 deletions src/enums/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const FspEndpointTemplates = {
TRANSACTION_REQUEST_GET: '/transactionRequests/{{ID}}',
TRANSACTION_REQUEST_PUT_ERROR: '/transactionRequests/{{ID}}/error',
PARTICIPANT_ENDPOINTS_GET: '/participants/{{fsp}}/endpoints',
PARTICIPANTS_GET_ALL: '/participants',
PARTICIPANTS_GET: '/participants/{{fsp}}',
PARTICIPANTS_POST: '/participants',
PARTIES_GET: '/parties/{{fsp}}',
Expand Down
1 change: 1 addition & 0 deletions src/enums/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const Headers = {
FSPIOP: {
SOURCE: 'fspiop-source',
DESTINATION: 'fspiop-destination',
PROXY: 'fspiop-proxy',
HTTP_METHOD: 'fspiop-http-method',
SIGNATURE: 'fspiop-signature',
URI: 'fspiop-uri'
Expand Down
4 changes: 2 additions & 2 deletions src/healthCheck/HealthCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class HealthCheck {
* @description Gets the health of the service along with sub-services
*
*/
async getHealth () {
async getHealth (context = undefined) {
// Default values
let status = statusEnum.OK
let isHealthy = true
Expand All @@ -100,7 +100,7 @@ class HealthCheck {
const versionNumber = this.packageJson.version

try {
const services = await Promise.all(this.serviceChecks.map(s => s()))
const services = await Promise.all(this.serviceChecks.map(s => s(context)))
isHealthy = HealthCheck.evaluateServiceHealth(services)
subServices = {
services
Expand Down
3 changes: 2 additions & 1 deletion src/healthCheck/HealthCheckEnums.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const serviceName = {
datastore: 'datastore',
broker: 'broker',
sidecar: 'sidecar',
cache: 'cache'
cache: 'cache',
proxyCache: 'proxyCache'
}

module.exports = {
Expand Down
24 changes: 19 additions & 5 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ declare namespace CentralServicesShared {
FSPIOP: {
SOURCE: string;
DESTINATION: string;
PROXY: string;
HTTP_METHOD: string;
SIGNATURE: string;
URI: string;
Expand Down Expand Up @@ -599,16 +600,26 @@ declare namespace CentralServicesShared {
};
};
}
interface Endpoints {
fetchEndpoints(fspId: string): Promise<any>
getEndpoint(switchUrl: string, fsp: string, endpointType: FspEndpointTypesEnum, options?: any): Promise<string>

interface Cacheable {
initializeCache(policyOptions: object, config: { hubName: string, hubNameRegex: RegExp }): Promise<boolean>
stopCache(): Promise<void>
}

interface Endpoints extends Cacheable {
getEndpoint(switchUrl: string, fsp: string, endpointType: FspEndpointTypesEnum, options?: any): Promise<string>
getEndpointAndRender(switchUrl: string, fsp: string, endpointType: FspEndpointTypesEnum, path: string, options?: any): Promise<string>
}

interface Participants {
interface Participants extends Cacheable {
getParticipant(switchUrl: string, fsp: string): Promise<object>
initializeCache(policyOptions: object, config: { hubName: string, hubNameRegex: RegExp }): Promise<boolean>
invalidateParticipantCache(fsp: string): Promise<void>
}

type ProxyNames = string[]
interface Proxies extends Cacheable {
getAllProxiesNames(switchUrl: string): Promise<ProxyNames>
invalidateProxiesCache(): Promise<void>
}

interface ProtocolVersionsType {
Expand All @@ -625,8 +636,10 @@ declare namespace CentralServicesShared {
createGeneralTopicConf(template: string, functionality: string, action: string, key?: string, partition?: number, opaqueKey?: any, topicNameOverride?: string): {topicName: string, key: string | null, partition: number | null, opaqueKey: any }
}

type MimeTypes = 'text/plain' | 'application/json' | 'application/vnd.interoperability.'
interface StreamingProtocol {
decodePayload(input: string, options: Object): Object
encodePayload(input: string | Buffer, mimeType: MimeTypes): string
}

interface HeaderValidation {
Expand All @@ -643,6 +656,7 @@ declare namespace CentralServicesShared {
interface Util {
Endpoints: Endpoints;
Participants: Participants;
proxies: Proxies;
Hapi: any;
Kafka: Kafka;
OpenapiBackend: any;
Expand Down
2 changes: 2 additions & 0 deletions src/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const _ = require('lodash')
const Kafka = require('./kafka')
const Endpoints = require('./endpoints')
const Participants = require('./participants')
const proxies = require('./proxies')
const Request = require('./request')
const Http = require('./http')
const Hapi = require('./hapi')
Expand Down Expand Up @@ -238,6 +239,7 @@ module.exports = {
filterExtensions,
Kafka,
Participants,
proxies,
Endpoints,
Request,
Http,
Expand Down
6 changes: 6 additions & 0 deletions src/util/participants.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ exports.getParticipant = async (switchUrl, fsp) => {
histTimer({ success: true, hit: false })
}

/* istanbul ignore next */
if (!participant) {
Logger.isWarnEnabled && Logger.warn('participantCache::getParticipant - no participant found')
return null
}

if (participant.errorInformation) {
// Drop error from cache
await policy.drop(fsp)
Expand Down
Loading

0 comments on commit 3fd95ac

Please sign in to comment.