Skip to content

Commit

Permalink
Merge pull request #1336 from tulios/remove-admin-gettopicmetadata
Browse files Browse the repository at this point in the history
Remove deprecated method admin.getTopicMetadata
  • Loading branch information
Nevon committed May 2, 2022
2 parents 2c15fd7 + 0e78b7a commit dd6ce4d
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 168 deletions.
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

0 comments on commit dd6ce4d

Please sign in to comment.