Skip to content

Commit

Permalink
fix(shared): HAWNG-612 jmx tree should keep rendering even in presenc…
Browse files Browse the repository at this point in the history
…e of malformed mbeans
  • Loading branch information
tadayosi committed Apr 2, 2024
1 parent df6f7bb commit 3ee4368
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/hawtio/src/plugins/shared/tree/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ export class MBeanNode implements TreeViewDataItem {
// final mbean node
const path = paths[0]
if (!path) {
throw new Error('path should not be empty')
log.error('Failed to process MBean. Malformed ObjectName:', `"${props.objectName()}"`)
return
}
const mbeanNode = this.create(path, false)
mbeanNode.configureMBean(props, mbean)
Expand All @@ -134,7 +135,8 @@ export class MBeanNode implements TreeViewDataItem {

const path = paths.shift()
if (path === undefined) {
throw new Error('path should not be empty')
log.error('Failed to process MBean. Malformed ObjectName:', `"${props.objectName()}"`)
return
}
const child = this.getOrCreate(path, true)
child.createMBeanNode(paths, props, mbean)
Expand Down
28 changes: 28 additions & 0 deletions packages/hawtio/src/plugins/shared/tree/tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,34 @@ describe('MBeanTree', () => {
expect(xnio2Addr.childCount()).toEqual(0)
})

test('createFromDomains should be robust in presence of malformed mbeans', async () => {
const domains = {
'java.lang': { 'type=Memory': { desc: '' } },
'malformed.mbean': { '': { desc: '' } },
}
const tree = (await MBeanTree.createFromDomains('test', domains)).getTree()

expect(tree.length).toEqual(2)

const javaLang = tree[0] as MBeanNode
expect(javaLang.id).toEqual('java.lang-folder')
expect(javaLang.name).toEqual('java.lang')
expect(javaLang.mbean).toBeUndefined()
expect(javaLang.childCount()).toEqual(1)

const memory = javaLang.getChildren()[0] as MBeanNode
expect(memory.id).toEqual('java.lang-folder-Memory')
expect(memory.name).toEqual('Memory')
expect(memory.mbean).toBeDefined()
expect(memory.childCount()).toEqual(0)

const malformed = tree[1] as MBeanNode
expect(malformed.id).toEqual('malformed.mbean-folder')
expect(malformed.name).toEqual('malformed.mbean')
expect(malformed.mbean).toBeUndefined()
expect(malformed.childCount()).toEqual(0)
})

test('flatten empty tree', () => {
const tree = MBeanTree.createFromNodes('test', [])
expect(tree.flatten()).toEqual({})
Expand Down
4 changes: 2 additions & 2 deletions packages/hawtio/src/plugins/shared/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class Workspace implements IWorkspace {
this.maybeMonitorTree()

return tree
} catch (response) {
log.error('A request to list the JMX tree failed: ' + response)
} catch (error) {
log.error('A request to list the JMX tree failed:', error)
return MBeanTree.createEmpty(pluginName)
}
}
Expand Down

0 comments on commit 3ee4368

Please sign in to comment.