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

fix: cannot build ml-api-adapter with current version of central-services-stream #141

Merged
merged 30 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
337e50c
fix: restore function for checking if all producers are connected
kalinkrustev May 13, 2024
4e53a61
fix: typo
kalinkrustev May 13, 2024
ebd8048
fix: use bash
kalinkrustev May 13, 2024
c17b799
fix: use bash
kalinkrustev May 13, 2024
7f0975b
fix: use bash
kalinkrustev May 13, 2024
def2e95
chore(release): [ci-skip] null
May 13, 2024
b9b8644
fix: typo
kalinkrustev May 13, 2024
a0c2619
fix: use bash
kalinkrustev May 13, 2024
e2395b1
fix: use bash
kalinkrustev May 13, 2024
b1c2503
fix: use bash
kalinkrustev May 13, 2024
2eb3459
chore(release): [ci-skip] 11.2.6-140.0
May 13, 2024
d6f649f
chore(release): [ci-skip] 11.2.6-140.1
May 13, 2024
f33e9ec
chore(release): [ci-skip] 11.2.6-140.2
May 13, 2024
ad90009
chore(release): [ci-skip] 11.2.6-140.3
May 13, 2024
81b6d6f
chore(release): [ci-skip] 11.2.6-140.4
May 13, 2024
5500cc0
chore(release): [ci-skip] 11.2.6-140.5
May 13, 2024
b7e6501
chore(release): [ci-skip] 11.2.6-140.6
May 13, 2024
44cde9a
chore(release): [ci-skip] 11.2.6-140.7
May 13, 2024
2747124
chore(release): [ci-skip] 11.2.6-140.8
May 13, 2024
8244bac
chore(release): [ci-skip] 11.2.6-140.9
May 13, 2024
650ba6b
chore(release): [ci-skip] 11.2.6-140.10
May 13, 2024
d445cf3
fix: npm tag
kalinkrustev May 13, 2024
946a2ea
fix: skip
kalinkrustev May 13, 2024
29bc24e
chore(release): [ci skip] 11.2.6-140.11
May 13, 2024
5dc2f8a
fix: skip tag
kalinkrustev May 13, 2024
ef27e02
chore(release): [ci skip] 11.2.6-140.12
May 13, 2024
28e1392
chore: configure git
kalinkrustev May 14, 2024
0edeeda
chore(release): [ci skip] 11.2.6-140.13
May 14, 2024
a3c838e
chore: deps
kalinkrustev May 16, 2024
29cb18c
chore(release): [ci skip] 11.2.6-140.14
May 16, 2024
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
66 changes: 65 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ defaults_configure_nvm: &defaults_configure_nvm

if [ -f "$NVM_DIR" ]; then
echo "==> $NVM_DIR exists. Skipping steps 2-4!"
else
else
echo "==> $NVM_DIR does not exists. Executing steps 2-4!"

echo "2. Installing NVM"
Expand Down Expand Up @@ -448,6 +448,57 @@ jobs:
- slack/notify:
event: fail
template: SLACK_TEMP_RELEASE_FAILURE
publish-prerelease:
executor: default-machine
steps:
- run:
name: Install git
command: |
sudo apt-get update && sudo apt-get install -y git
- gh/install
- checkout
- restore_cache:
key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
- run:
<<: *defaults_configure_git
- run:
name: Setup for pre-release
command: |
if [[ $CIRCLE_BRANCH =~ ^(major|minor|patch)/(.*)$ ]]; then
echo "export RELEASE_TAG=${BASH_REMATCH[1]}-${BASH_REMATCH[2]}" >> $BASH_ENV
echo "RELEASE_TAG=${BASH_REMATCH[1]}-${BASH_REMATCH[2]}"
echo "Pre-releasing ${BASH_REMATCH[1]} version ${BASH_REMATCH[2]}"
npx standard-version --prerelease "${BASH_REMATCH[2]}" --release-as "${BASH_REMATCH[1]}" --message "chore(release): [ci skip] %s" --skip.changelog --no-verify

PACKAGE_VERSION=$(cat package-lock.json | jq -r .version)
echo "export PACKAGE_VERSION=${PACKAGE_VERSION}" >> $BASH_ENV
echo "PACKAGE_VERSION=${PACKAGE_VERSION}"
else
echo "unsupported branch $CIRCLE_BRANCH for pre-release"
exit 1
fi
- run:
name: Push the pre-release
command: git push --follow-tags origin ${CIRCLE_BRANCH}
- run:
name: Setup Slack config
command: |
echo "export SLACK_PROJECT_NAME=${CIRCLE_PROJECT_REPONAME}" >> $BASH_ENV
echo "export SLACK_RELEASE_TYPE='NPM pre-release'" >> $BASH_ENV
echo "export SLACK_RELEASE_TAG=v${CIRCLE_TAG:1}" >> $BASH_ENV
echo "export SLACK_RELEASE_URL=https://www.npmjs.com/package/@mojaloop/${CIRCLE_PROJECT_REPONAME}/v/${CIRCLE_TAG:1}" >> $BASH_ENV
echo "export SLACK_BUILD_ID=${CIRCLE_BUILD_NUM}" >> $BASH_ENV
echo "export SLACK_CI_URL=${CIRCLE_BUILD_URL}" >> $BASH_ENV
- run:
<<: *defaults_npm_auth
- run:
<<: *defaults_npm_publish_release
- slack/notify:
event: pass
template: SLACK_TEMP_RELEASE_SUCCESS
- slack/notify:
event: fail
template: SLACK_TEMP_RELEASE_FAILURE

workflows:
build_and_test:
Expand Down Expand Up @@ -585,3 +636,16 @@ workflows:
branches:
ignore:
- /.*/
- publish-prerelease:
context: org-global
requires:
- pr-tools/pr-title-check
- test-lint
- test-unit
- test-coverage
- vulnerability-check
- audit-licenses
filters:
branches:
only:
- /(major|minor|patch)/.*/
kalinkrustev marked this conversation as resolved.
Show resolved Hide resolved
46 changes: 23 additions & 23 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mojaloop/central-services-stream",
"version": "11.2.5",
"version": "11.2.6-140.14",
"description": "Streaming library code for central services.",
"license": "Apache-2.0",
"bugs": {
Expand Down Expand Up @@ -57,12 +57,12 @@
},
"devDependencies": {
"audit-ci": "^6.6.1",
"npm-check-updates": "16.14.18",
"npm-check-updates": "16.14.20",
"nyc": "15.1.0",
"pre-commit": "1.2.2",
"replace": "^1.2.2",
"rewire": "7.0.0",
"sinon": "17.0.1",
"sinon": "18.0.0",
"standard": "17.1.0",
"standard-version": "^9.5.0",
"tap-spec": "^5.0.0",
Expand Down
37 changes: 37 additions & 0 deletions src/util/producer.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,48 @@ const isConnected = async (topicName = undefined) => {
return producer.isConnected()
}

/**
* @function getMetadataPromise
*
* @param {object} producer - the producer class
* @param {string} topic - the topic name of the producer to check
*
* @description Use this to determine whether or not we are connected to the broker. Internally, it calls `getMetadata` to determine
* if the broker client is connected.
*
* @returns object - resolve metadata object
* @throws {Error} - if Producer can't be found or the producer is not connected
*/
const getMetadataPromise = async (producer, topic) => {
return new Promise((resolve, reject) => {
const cb = async (err, metadata) => {
if (err) {
return reject(new Error(`Error connecting to producer: ${err.message}`))
}
return resolve(metadata)
}
producer.getMetadata({ topic, timeout: 6000 }, cb)
})
}

const allConnected = async () => {
for (const [key, value] of Object.entries(listOfProducers)) {
const metadata = await getMetadataPromise(value._producer, key)
const foundTopics = metadata.topics.map(topic => topic.name)
if (foundTopics.indexOf(key) === -1) {
Logger.isDebugEnabled && Logger.debug(`Connected to producer, but ${key} not found.`)
throw ErrorHandler.Factory.createInternalServerFSPIOPError(`Connected to producer, but ${key} not found.`)
}
}
return stateList.OK
}

module.exports = {
getProducer,
produceMessage,
disconnect,
isConnected,
allConnected,
stateList,
connectAll
}
33 changes: 33 additions & 0 deletions test/unit/util/producer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,39 @@ Test('Producer', producerTest => {
test.end()
})

isConnectedTest.test('pass if the topicName is not supplied', async test => {
// Arrange
const ProducerProxy = rewire(`${src}/util/producer`)
const metadata = {
orig_broker_id: 0,
orig_broker_name: 'kafka:9092/0',
topics: [
{ name: 'admin', partitions: [] }
],
brokers: [{ id: 0, host: 'kafka', port: 9092 }]
}
ProducerProxy.__set__('listOfProducers', {
admin: {
_producer: {
// Callback with error
getMetadata: (options, cb) => cb(null, metadata)
}
}
})

// Act
let result
try {
result = await ProducerProxy.allConnected()
} catch (err) {
test.fail(err.message)
}

// Assert
test.equal(result, Producer.stateList.OK, 'isConnected should return true')
test.end()
})

isConnectedTest.end()
})

Expand Down