Skip to content

Commit

Permalink
chore(deps): update jolokia.js to 2.0.1
Browse files Browse the repository at this point in the history
Relates #902
  • Loading branch information
tadayosi committed Apr 26, 2024
1 parent 745f875 commit c3928fe
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 27 deletions.
2 changes: 1 addition & 1 deletion packages/hawtio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"@types/react-router-dom": "^5.3.3",
"dagre": "^0.8.5",
"eventemitter3": "^5.0.1",
"jolokia.js": "^2.0.0",
"jolokia.js": "^2.0.1",
"jquery": "^3.7.1",
"js-logger": "^1.6.1",
"jwt-decode": "^4.0.0",
Expand Down
27 changes: 6 additions & 21 deletions packages/hawtio/src/plugins/shared/jolokia-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import Jolokia, {
} from 'jolokia.js'
import 'jolokia.js/simple'
import $ from 'jquery'
import { define, func, is, object, optional, record, string, type } from 'superstruct'
import { func, is, object, type } from 'superstruct'
import { PARAM_KEY_CONNECTION, PARAM_KEY_REDIRECT, connectService } from '../shared/connect-service'
import { log } from './globals'
import { OptimisedJmxDomain, OptimisedJmxDomains, OptimisedMBeanInfo } from './tree'
import { OptimisedJmxDomains, OptimisedMBeanInfo, isJmxDomain, isJmxDomains, isMBeanInfo } from './tree'

export const DEFAULT_MAX_DEPTH = 7
export const DEFAULT_MAX_COLLECTION_SIZE = 50000
Expand Down Expand Up @@ -71,6 +71,9 @@ export type OptimisedListResponse = {
cache: OptimisedMBeanInfoCache
domains: CacheableOptimisedJmxDomains
}
function isOptimisedListResponse(value: unknown): value is OptimisedListResponse {
return is(value, object({ cache: object(), domains: object() }))
}
export type OptimisedMBeanInfoCache = Record<string, OptimisedMBeanInfo>
export type CacheableOptimisedJmxDomains = Record<string, CacheableOptimisedJmxDomain>
export type CacheableOptimisedJmxDomain = Record<string, OptimisedMBeanInfo | string>
Expand Down Expand Up @@ -366,7 +369,7 @@ class JolokiaService implements IJolokiaService {
const successFn: NonNullable<ListRequestOptions['success']> = (value: ListResponse) => {
// check if the MBean exists by testing whether the returned value has
// the 'op' property
if (isObject(value?.op)) {
if (isMBeanInfo(value) && isObject(value.op)) {
this.config.method = JolokiaListMethod.OPTIMISED
} else {
// we could get 403 error, mark the method as special case,
Expand Down Expand Up @@ -541,24 +544,6 @@ class JolokiaService implements IJolokiaService {
* @param path optional path information to restore the response to {@link OptimisedJmxDomains}
*/
private unwindListResponse(response: unknown, path?: string[]): OptimisedJmxDomains {
const isOptimisedListResponse = (value: unknown): value is OptimisedListResponse =>
is(value, object({ cache: object(), domains: object() }))
const isMBeanInfo = (value: unknown): value is OptimisedMBeanInfo =>
is(
value,
type({
desc: string(),
class: optional(string()),
attr: optional(record(string(), object())),
op: optional(record(string(), object())),
notif: optional(record(string(), object())),
}),
)
const isJmxDomain = (value: unknown): value is OptimisedJmxDomain =>
is(value, record(string(), define('MBeanInfo', isMBeanInfo)))
const isJmxDomains = (value: unknown): value is OptimisedJmxDomains =>
is(value, record(string(), define('JmxDomain', isJmxDomain)))

if (isOptimisedListResponse(response)) {
// Post process cached MBean info
const { cache, domains } = response
Expand Down
22 changes: 22 additions & 0 deletions packages/hawtio/src/plugins/shared/tree/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { TreeViewDataItem } from '@patternfly/react-core'
import { CubeIcon, FolderIcon, FolderOpenIcon, LockIcon } from '@patternfly/react-icons'
import { MBeanAttribute, MBeanInfo, MBeanOperation } from 'jolokia.js'
import React from 'react'
import { define, is, object, optional, record, string, type } from 'superstruct'
import { log } from './globals'

export const Icons = {
Expand All @@ -16,15 +17,36 @@ export const Icons = {

export type OptimisedJmxDomains = Record<string, OptimisedJmxDomain>

export function isJmxDomains(value: unknown): value is OptimisedJmxDomains {
return is(value, record(string(), define('JmxDomain', isJmxDomain)))
}

export type OptimisedJmxDomain = Record<string, OptimisedMBeanInfo>

export function isJmxDomain(value: unknown): value is OptimisedJmxDomain {
return is(value, record(string(), define('MBeanInfo', isMBeanInfo)))
}

export interface OptimisedMBeanInfo extends Omit<MBeanInfo, 'attr' | 'op'> {
attr?: Record<string, OptimisedMBeanAttribute>
op?: OptimisedMBeanOperations
opByString?: Record<string, OptimisedMBeanOperation>
canInvoke?: boolean
}

export function isMBeanInfo(value: unknown): value is OptimisedMBeanInfo {
return is(
value,
type({
desc: string(),
class: optional(string()),
attr: optional(record(string(), object())),
op: optional(record(string(), object())),
notif: optional(record(string(), object())),
}),
)
}

export interface OptimisedMBeanAttribute extends MBeanAttribute {
canInvoke?: boolean
}
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ __metadata:
jest-environment-jsdom: "npm:^29.7.0"
jest-fetch-mock: "npm:^3.0.3"
jest-watch-typeahead: "npm:^2.2.2"
jolokia.js: "npm:^2.0.0"
jolokia.js: "npm:^2.0.1"
jquery: "npm:^3.7.1"
js-logger: "npm:^1.6.1"
jwt-decode: "npm:^4.0.0"
Expand Down Expand Up @@ -8706,9 +8706,9 @@ __metadata:
languageName: node
linkType: hard

"jolokia.js@npm:^2.0.0":
version: 2.0.0
resolution: "jolokia.js@npm:2.0.0"
"jolokia.js@npm:^2.0.1":
version: 2.0.1
resolution: "jolokia.js@npm:2.0.1"
dependencies:
jquery: "npm:^3.7.1"
peerDependencies:
Expand All @@ -8719,7 +8719,7 @@ __metadata:
optional: true
jsdom:
optional: true
checksum: 10/d530e54ce076804d233d4294dec10098defd1307d1973b42e673006070fb2a7e8ff6c8e181467a5fceb2149c2426e38acca9a33312124ecf76235c564734dd3c
checksum: 10/2286502549a51a0df6e6151d4d117ccdc4cd5c26965121ac58a954de64ff43437083c05aa1b1769581d7840d07c67f0f27152e77355d27e30fac4a6e13f89903
languageName: node
linkType: hard

Expand Down

0 comments on commit c3928fe

Please sign in to comment.