Skip to content

Commit

Permalink
feat(shared): jolokiaService.list() to accept path for returning part…
Browse files Browse the repository at this point in the history
…ial set of MBeans

Fix #447

Depends on hawtio/hawtio#2965, hawtio/hawtio#2966
  • Loading branch information
tadayosi committed Oct 30, 2023
1 parent 013910a commit a31b682
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ class MockJolokiaService implements IJolokiaService {
return ''
}

async list(options: ListRequestOptions): Promise<unknown> {
async list(options?: ListRequestOptions): Promise<unknown> {
return jmxCamelResponse
}

async sublist(path: string, options?: ListRequestOptions): Promise<unknown> {
return jmxCamelResponse
}

Expand Down
72 changes: 38 additions & 34 deletions packages/hawtio/src/plugins/shared/jolokia-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ export interface IJolokiaService {
getJolokia(): Promise<Jolokia>
getListMethod(): Promise<JolokiaListMethod>
getFullJolokiaUrl(): Promise<string>
list(options: ListRequestOptions): Promise<unknown>
list(options?: ListRequestOptions): Promise<unknown>
sublist(path: string, options?: ListRequestOptions): Promise<unknown>
readAttributes(mbean: string): Promise<AttributeValues>
readAttribute(mbean: string, attribute: string): Promise<unknown>
execute(mbean: string, operation: string, args?: unknown[]): Promise<unknown>
Expand Down Expand Up @@ -414,57 +415,60 @@ class JolokiaService implements IJolokiaService {
return this.config.method
}

async list(options: ListRequestOptions): Promise<unknown> {
list(options?: ListRequestOptions): Promise<unknown> {
return this.doList(null, options)
}

sublist(path: string, options?: ListRequestOptions): Promise<unknown> {
return this.doList(path, options)
}

private async doList(path: string | null, options: ListRequestOptions = {}): Promise<unknown> {
const jolokia = await this.getJolokia()
const { method, mbean } = this.config

const { success, error: errorFn, ajaxError } = options

return new Promise((resolve, reject) => {
options.ajaxError = (xhr: JQueryXHR, text: string, error: string) => {
const listOptions = onListSuccessAndError(
value => {
success?.(value)
resolve(value)
},
error => {
errorFn?.(error)
reject(error)
},
options,
)
// Override ajaxError to make sure it terminates in case of ajax error
listOptions.ajaxError = (xhr, text, error) => {
ajaxError?.(xhr, text, error)
reject(error)
}
switch (method) {
case JolokiaListMethod.OPTIMISED:
log.debug('Invoke Jolokia list MBean in optimised mode')
// Overwrite max depth as listing MBeans requires some constant depth to work
options.maxDepth = OPTIMISED_JOLOKIA_LIST_MAX_DEPTH
jolokia.execute(
mbean,
'list()',
// This is execute operation but ListRequestOptions is compatible with
// ExecuteRequestOptions for list(), so this is intentional.
onListSuccessAndError(
value => {
success?.(value)
resolve(value)
},
error => {
errorFn?.(error)
reject(error)
},
options,
),
)
// TODO: Is this needed?
listOptions.maxDepth = OPTIMISED_JOLOKIA_LIST_MAX_DEPTH
// This is execute operation but ListRequestOptions is compatible with
// ExecuteRequestOptions for list(), so this usage is intentional.
if (path === null) {
jolokia.execute(mbean, 'list()', listOptions)
} else {
jolokia.execute(mbean, 'list(java.lang.String)', path, listOptions)
}
break
case JolokiaListMethod.DEFAULT:
case JolokiaListMethod.UNDETERMINED:
default:
log.debug('Invoke Jolokia list MBean in default mode')
jolokia.list(
onListSuccessAndError(
value => {
success?.(value)
resolve(value)
},
error => {
errorFn?.(error)
reject(error)
},
options,
),
)
if (path === null) {
jolokia.list(listOptions)
} else {
jolokia.list(path, listOptions)
}
}
})
}
Expand Down

0 comments on commit a31b682

Please sign in to comment.