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

Remove deprecated method admin.getTopicMetadata #1336

Merged
merged 1 commit into from
May 2, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/admin/__tests__/createAcls.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,15 @@ describe('Admin', () => {
admin = createSASLAdminClientForUser({ username: 'bob', password: 'bobbob' })
await admin.connect()

await expect(admin.getTopicMetadata({ topics: [topicName] })).rejects.toThrow(
await expect(admin.fetchTopicMetadata({ topics: [topicName] })).rejects.toThrow(
'Not authorized to access topics: [Topic authorization failed]'
)

await admin.disconnect()
admin = createSASLAdminClientForUser({ username: 'alice', password: 'alicealice' })
await admin.connect()

await expect(admin.getTopicMetadata({ topics: [topicName] })).resolves.toBeTruthy()
await expect(admin.fetchTopicMetadata({ topics: [topicName] })).resolves.toBeTruthy()
})
})
})
3 changes: 1 addition & 2 deletions src/admin/__tests__/deleteTopics.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ describe('Admin', () => {
admin = createAdmin({ cluster, logger: newLogger() })
await admin.connect()

await expect(admin.getTopicMetadata({ topics: [topicName] })).resolves.toBeTruthy()
await expect(admin.fetchTopicOffsets(topicName)).resolves.toBeTruthy()
expect(cluster.targetTopics.size).toEqual(1)

await admin.deleteTopics({ topics: [topicName] })
await expect(admin.getTopicMetadata()).resolves.toBeTruthy()
expect(cluster.targetTopics.size).toEqual(0)
})

Expand Down
102 changes: 0 additions & 102 deletions src/admin/__tests__/getTopicMetadata.spec.js

This file was deleted.

62 changes: 0 additions & 62 deletions src/admin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,67 +765,6 @@ module.exports = ({
})
}

/**
* @deprecated - This method was replaced by `fetchTopicMetadata`. This implementation
* is limited by the topics in the target group, so it can't fetch all topics when
* necessary.
*
* Fetch metadata for provided topics.
*
* If no topics are provided fetch metadata for all topics of which we are aware.
* @see https://kafka.apache.org/protocol#The_Messages_Metadata
*
* @param {Object} [options]
* @param {string[]} [options.topics]
* @return {Promise<TopicsMetadata>}
*
* @typedef {Object} TopicsMetadata
* @property {Array<TopicMetadata>} topics
*
* @typedef {Object} TopicMetadata
* @property {String} name
* @property {Array<PartitionMetadata>} partitions
*
* @typedef {Object} PartitionMetadata
* @property {number} partitionErrorCode Response error code
* @property {number} partitionId Topic partition id
* @property {number} leader The id of the broker acting as leader for this partition.
* @property {Array<number>} replicas The set of all nodes that host this partition.
* @property {Array<number>} isr The set of nodes that are in sync with the leader for this partition.
*/
const getTopicMetadata = async options => {
const { topics } = options || {}

if (topics) {
await Promise.all(
topics.map(async topic => {
if (!topic) {
throw new KafkaJSNonRetriableError(`Invalid topic ${topic}`)
}

try {
await cluster.addTargetTopic(topic)
} catch (e) {
e.message = `Failed to add target topic ${topic}: ${e.message}`
throw e
}
})
)
}

await cluster.refreshMetadataIfNecessary()
const targetTopics = topics || [...cluster.targetTopics]

return {
topics: await Promise.all(
targetTopics.map(async topic => ({
name: topic,
partitions: cluster.findTopicPartitionMetadata(topic),
}))
),
}
}

/**
* Fetch metadata for provided topics.
*
Expand Down Expand Up @@ -1502,7 +1441,6 @@ module.exports = ({
createTopics,
deleteTopics,
createPartitions,
getTopicMetadata,
fetchTopicMetadata,
describeCluster,
events,
Expand Down