Skip to content

Commit

Permalink
fix(shared): upgrade jolokia.js to 2.0.0-dev.9
Browse files Browse the repository at this point in the history
The new official jolokia.js should be backward compatible with Jolokia
1.x, so it should be fine to upgrade the js client library in advance
for the coming Jolokia 2.0 release.

The new jolokia.js should also support both Jolokia 1.x and 2.x agents
with a single distribution.
  • Loading branch information
tadayosi committed Sep 25, 2023
1 parent 95add8a commit 31d0978
Show file tree
Hide file tree
Showing 28 changed files with 266 additions and 220 deletions.
3 changes: 2 additions & 1 deletion packages/hawtio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@
"@types/dagre": "^0.7.50",
"@types/dagre-layout": "^0.8.3",
"@types/jest": "^29.5.5",
"@types/jquery": "^3.5.19",
"@types/node": "^18.17.18",
"@types/react": "^18.2.21",
"@types/react-dom": "^18.2.7",
"@types/react-router-dom": "^5.3.3",
"dagre": "^0.8.5",
"eventemitter3": "^5.0.1",
"jolokia.js": "^1.7.3-2",
"jolokia.js": "^2.0.0-dev.9",
"jquery": "^3.7.1",
"js-logger": "^1.6.1",
"keycloak-js": "^22.0.3",
Expand Down
4 changes: 2 additions & 2 deletions packages/hawtio/src/plugins/camel/CamelContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
Title,
} from '@patternfly/react-core'
import { CubesIcon } from '@patternfly/react-icons'
import { IResponse } from 'jolokia.js'
import { Response } from 'jolokia.js'
import React, { useContext, useEffect, useState } from 'react'
import { NavLink, Navigate, Route, Routes, useLocation, useNavigate } from 'react-router-dom'
import './CamelContent.css'
Expand Down Expand Up @@ -198,7 +198,7 @@ const CamelContentContextToolbar: React.FunctionComponent = () => {
const attr = await contextsService.getContext(selectedNode)
if (attr) setContextState(attr)

contextsService.register({ type: 'read', mbean: objectName }, (response: IResponse) => {
contextsService.register({ type: 'read', mbean: objectName }, (response: Response) => {
log.debug('Scheduler - Contexts:', response.value)

// Replace the context in the existing set with the new one
Expand Down
12 changes: 6 additions & 6 deletions packages/hawtio/src/plugins/camel/contexts/Contexts.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { eventService } from '@hawtiosrc/core'
import { CamelContext } from '@hawtiosrc/plugins/camel/context'
import { AttributeValues } from '@hawtiosrc/plugins/shared/jolokia-service'
import { HawtioLoadingCard } from '@hawtiosrc/plugins/shared'
import { AttributeValues } from '@hawtiosrc/plugins/shared/jolokia-service'
import { Card, CardBody, Text } from '@patternfly/react-core'
import { InfoCircleIcon } from '@patternfly/react-icons'
import { Table, TableBody, TableHeader, TableProps, wrappable } from '@patternfly/react-table'
import { IResponse } from 'jolokia.js'
import { Response } from 'jolokia.js'
import React, { useContext, useEffect, useState } from 'react'
import { log } from '../globals'
import { ContextToolbar } from './ContextToolbar'
Expand Down Expand Up @@ -56,12 +56,12 @@ export const Contexts: React.FunctionComponent = () => {

// TODO: we should not invoke setContexts separately from multiple scheduler.
// It should cause a bug of overwriting the other updates when we have multiple contexts.
for (const [idx, ctx] of contexts.entries()) {
contexts.forEach((ctx, idx) => {
const { objectName } = ctx.node
if (!objectName) {
continue
return
}
contextsService.register({ type: 'read', mbean: objectName }, (response: IResponse) => {
contextsService.register({ type: 'read', mbean: objectName }, (response: Response) => {
log.debug('Scheduler - Contexts:', response.value)

// Replace the context in the existing set with the new one
Expand All @@ -73,7 +73,7 @@ export const Contexts: React.FunctionComponent = () => {
newContexts.splice(idx, 1, newCtx)
setContexts(newContexts)
})
}
})

return () => contextsService.unregisterAll()
}, [selectedNode, contexts])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MBeanNode } from '@hawtiosrc/plugins/shared'
import { AttributeValues, jolokiaService } from '@hawtiosrc/plugins/shared/jolokia-service'
import { IRequest, IResponseFn } from 'jolokia.js'
import { Request, Response } from 'jolokia.js'
import { log } from '../globals'

export const CONTEXT_STATE_STARTED = 'Started'
Expand Down Expand Up @@ -49,7 +49,7 @@ class ContextsService {
return ctxAttributes
}

async register(request: IRequest, callback: IResponseFn) {
async register(request: Request, callback: (response: Response) => void) {
const handle = await jolokiaService.register(request, callback)
log.debug('Register handle:', handle)
this.handles.push(handle)
Expand Down
4 changes: 2 additions & 2 deletions packages/hawtio/src/plugins/camel/debug/Debug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
TimesCircleIcon,
} from '@patternfly/react-icons'
import { TableComposable, Tbody, Td, Th, Thead, Tr } from '@patternfly/react-table'
import { IResponse } from 'jolokia.js'
import { Response } from 'jolokia.js'
import React, { useCallback, useContext, useEffect, useRef, useState } from 'react'
import * as camelService from '../camel-service'
import { CamelContext } from '../context'
Expand Down Expand Up @@ -230,7 +230,7 @@ export const Debug: React.FunctionComponent = () => {
mbean: debugNode.objectName,
operation: 'getDebugCounter',
},
(response: IResponse) => {
(response: Response) => {
log.debug('Scheduler - Debug:', response.value)
applyBreakpointCounter(response?.value as number, contextNode)
},
Expand Down
4 changes: 2 additions & 2 deletions packages/hawtio/src/plugins/camel/debug/debug-service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MBeanNode, jolokiaService } from '@hawtiosrc/plugins/shared'
import { isBlank } from '@hawtiosrc/util/strings'
import { childText, xmlText } from '@hawtiosrc/util/xml'
import { IRequest, IResponseFn } from 'jolokia.js'
import { Request, Response } from 'jolokia.js'
import { camelPreferencesService } from '../camel-preferences-service'
import * as camelService from '../camel-service'
import { log } from '../globals'
Expand All @@ -27,7 +27,7 @@ export interface MessageData {
class DebugService {
private handles: number[] = []

async register(request: IRequest, callback: IResponseFn) {
async register(request: Request, callback: (response: Response) => void) {
const handle = await jolokiaService.register(request, callback)
log.debug('Register handle:', handle)
this.handles.push(handle)
Expand Down
4 changes: 2 additions & 2 deletions packages/hawtio/src/plugins/camel/profile/Profile.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HawtioEmptyCard, HawtioLoadingCard } from '@hawtiosrc/plugins/shared'
import { Card, CardBody, CardHeader, CardTitle } from '@patternfly/react-core'
import { TableComposable, Tbody, Td, Th, Thead, Tr } from '@patternfly/react-table'
import { IResponse } from 'jolokia.js'
import { Response } from 'jolokia.js'
import React, { useContext, useEffect, useState } from 'react'
import { CamelContext } from '../context'
import { log } from '../globals'
Expand Down Expand Up @@ -33,7 +33,7 @@ export const Profile: React.FunctionComponent = () => {
mbean: selectedNode.objectName as string,
operation: 'dumpRouteStatsAsXml()',
},
(response: IResponse) => {
(response: Response) => {
log.debug('Scheduler - Debug:', response.value)
profile()
},
Expand Down
4 changes: 2 additions & 2 deletions packages/hawtio/src/plugins/camel/profile/profile-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MBeanNode, jolokiaService } from '@hawtiosrc/plugins/shared'
import { IRequest, IResponseFn } from 'jolokia.js'
import { Request, Response } from 'jolokia.js'
import { log } from '../globals'
import { routesService } from '../routes-service'

Expand All @@ -18,7 +18,7 @@ export type ProfileData = {
class ProfileService {
private handles: number[] = []

async register(request: IRequest, callback: IResponseFn) {
async register(request: Request, callback: (response: Response) => void) {
const handle = await jolokiaService.register(request, callback)
log.debug('Register handle:', handle)
this.handles.push(handle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
ToolbarItem,
} from '@patternfly/react-core'
import { TableComposable, Tbody, Td, Th, Thead, Tr } from '@patternfly/react-table'
import { IResponse } from 'jolokia.js'
import { Response } from 'jolokia.js'
import React, { ChangeEvent, MouseEvent, useCallback, useContext, useEffect, useRef, useState } from 'react'
import { CamelContext } from '../context'
import { log } from '../globals'
Expand Down Expand Up @@ -75,7 +75,7 @@ export const RestServices: React.FunctionComponent = () => {
mbean: selectedNode.objectName as string,
operation: 'listRestServices()',
},
(response: IResponse) => {
(response: Response) => {
log.debug('Scheduler - Debug:', response.value)
fetchRest()
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MBeanNode, jolokiaService } from '@hawtiosrc/plugins/shared'
import { isObject } from '@hawtiosrc/util/objects'
import { IRequest, IResponseFn } from 'jolokia.js'
import { Request, Response } from 'jolokia.js'
import * as camelService from '../camel-service'
import { log } from '../globals'

Expand All @@ -15,7 +15,7 @@ export interface RestService {
class RestServicesService {
private handles: number[] = []

async register(request: IRequest, callback: IResponseFn) {
async register(request: Request, callback: (response: Response) => void) {
const handle = await jolokiaService.register(request, callback)
log.debug('Register handle:', handle)
this.handles.push(handle)
Expand Down
4 changes: 2 additions & 2 deletions packages/hawtio/src/plugins/camel/trace/Trace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '@patternfly/react-core'
import { BanIcon, PlayIcon } from '@patternfly/react-icons'
import { TableComposable, Tbody, Td, Th, Thead, Tr } from '@patternfly/react-table'
import { IResponse } from 'jolokia.js'
import { Response } from 'jolokia.js'
import React, { useCallback, useContext, useEffect, useRef, useState } from 'react'
import * as camelService from '../camel-service'
import { CamelContext } from '../context'
Expand Down Expand Up @@ -123,7 +123,7 @@ export const Trace: React.FunctionComponent = () => {
mbean: tracingNode.objectName as string,
operation: 'dumpAllTracedMessagesAsXml()',
},
(response: IResponse) => {
(response: Response) => {
log.debug('Scheduler - Debug:', response.value)
populateRouteMessages(response?.value as string, selectedNode)
},
Expand Down
4 changes: 2 additions & 2 deletions packages/hawtio/src/plugins/camel/trace/tracing-service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { MBeanNode, jolokiaService } from '@hawtiosrc/plugins/shared'
import { IRequest, IResponseFn } from 'jolokia.js'
import { Request, Response } from 'jolokia.js'
import { camelPreferencesService } from '../camel-preferences-service'
import * as camelService from '../camel-service'
import { log } from '../globals'

class TracingService {
private handles: number[] = []

async register(request: IRequest, callback: IResponseFn) {
async register(request: Request, callback: (response: Response) => void) {
const handle = await jolokiaService.register(request, callback)
log.debug('Register handle:', handle)
this.handles.push(handle)
Expand Down
8 changes: 4 additions & 4 deletions packages/hawtio/src/plugins/quartz/quartz-service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AttributeValues, MBeanNode, jolokiaService, workspace } from '@hawtiosrc/plugins/shared'
import { jmxDomain, log } from './globals'
import { eventService } from '@hawtiosrc/core'
import { IRequest } from 'jolokia.js'
import { AttributeValues, MBeanNode, jolokiaService, workspace } from '@hawtiosrc/plugins/shared'
import { getQueryParameterValue } from '@hawtiosrc/util/urls'
import { Request } from 'jolokia.js'
import { attributeService } from '../shared/attributes/attribute-service'
import { jmxDomain, log } from './globals'

export type Trigger = {
group: string
Expand Down Expand Up @@ -159,7 +159,7 @@ class QuartzService {
return
}

const requests: IRequest[] = triggers.map(trigger => ({
const requests: Request[] = triggers.map(trigger => ({
type: 'exec',
mbean: schedulerMBean,
operation: QUARTZ_OPERATIONS.getTriggerState,
Expand Down
19 changes: 13 additions & 6 deletions packages/hawtio/src/plugins/rbac/tree-processor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { JolokiaListMethod, MBeanNode, MBeanTree, TreeProcessor, jolokiaService } from '@hawtiosrc/plugins/shared'
import {
JolokiaListMethod,
MBeanNode,
MBeanTree,
OptimisedMBeanOperation,
TreeProcessor,
jolokiaService,
} from '@hawtiosrc/plugins/shared'
import { operationToString } from '@hawtiosrc/util/jolokia'
import { isString } from '@hawtiosrc/util/objects'
import { isBlank } from '@hawtiosrc/util/strings'
import { IJmxOperation, IRequest, IResponse } from 'jolokia.js'
import { Request, Response } from 'jolokia.js'
import { log } from './globals'
import { rbacService } from './rbac-service'

Expand Down Expand Up @@ -67,7 +74,7 @@ export const rbacTreeProcessor: TreeProcessor = async (tree: MBeanTree) => {
type BulkRequest = { [name: string]: string[] }

async function processRBAC(aclMBean: string, mbeans: Record<string, MBeanNode>) {
const requests: IRequest[] = []
const requests: Request[] = []
const bulkRequest: BulkRequest = {}
// register canInvoke requests for each MBean and accumulate bulkRequest for all ops
Object.entries(mbeans).forEach(([mbeanName, node]) => {
Expand All @@ -91,7 +98,7 @@ function addCanInvokeRequests(
aclMBean: string,
mbeanName: string,
node: MBeanNode,
requests: IRequest[],
requests: Request[],
bulkRequest: BulkRequest,
) {
// request for MBean
Expand Down Expand Up @@ -119,7 +126,7 @@ function addCanInvokeRequests(
}
}

function addOperation(node: MBeanNode, opList: string[], opName: string, op: IJmxOperation) {
function addOperation(node: MBeanNode, opList: string[], opName: string, op: OptimisedMBeanOperation) {
if (!node.mbean) {
return
}
Expand All @@ -139,7 +146,7 @@ type BulkResponse = { [name: string]: Operations }
type Operations = { [name: string]: Operation }
type Operation = { ObjectName: string; Method: string; CanInvoke: boolean }

function applyCanInvoke(mbeans: Record<string, MBeanNode>, response: IResponse) {
function applyCanInvoke(mbeans: Record<string, MBeanNode>, response: Response) {
if (response.request.type !== 'exec') {
return
}
Expand Down
18 changes: 9 additions & 9 deletions packages/hawtio/src/plugins/runtime/runtime-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jolokiaService } from '@hawtiosrc/plugins/shared'
import { Request, Response } from 'jolokia.js'
import { Metric, SystemProperty, Thread } from './types'
import { IRequest, IResponse } from 'jolokia.js'

class RuntimeService {
handlers: number[] = []
Expand Down Expand Up @@ -76,15 +76,15 @@ class RuntimeService {
return dumpedThreads
}

getRegisterRequest(mbean: string, attribute?: string, args?: string[]): IRequest {
const request: IRequest = { type: 'read', mbean: mbean }
getRegisterRequest(mbean: string, attribute?: string, args?: string[]): Request {
const request: Request = { type: 'read', mbean: mbean }
if (attribute) {
request.attribute = attribute
}
return request
}

responseCallback(response: IResponse, callback: (metric: Metric) => void) {
responseCallback(response: Response, callback: (metric: Metric) => void) {
const req = response.request as { type: 'read'; mbean: string; attribute?: string | string[]; path?: string }
switch (req.mbean) {
case 'java.lang:type=Threading': {
Expand Down Expand Up @@ -154,8 +154,8 @@ class RuntimeService {
}
}

getJolokiaRequests(): IRequest[] {
const requests: IRequest[] = []
getJolokiaRequests(): Request[] {
const requests: Request[] = []
requests.push(this.getRegisterRequest('java.lang:type=Threading', 'ThreadCount'))
requests.push(this.getRegisterRequest('java.lang:type=Memory', 'HeapMemoryUsage'))
requests.push(this.getRegisterRequest('java.lang:type=Runtime'))
Expand Down Expand Up @@ -188,11 +188,11 @@ class RuntimeService {
if (bytes === 0) {
return [0, 'Bytes']
}
const killobyte = 1024
const kilobytes = 1024
const decimalPlaces = 2
const units = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
const i = Math.floor(Math.log(bytes) / Math.log(killobyte))
const value = parseFloat((bytes / Math.pow(killobyte, i)).toFixed(decimalPlaces))
const i = Math.floor(Math.log(bytes) / Math.log(kilobytes))
const value = parseFloat((bytes / Math.pow(kilobytes, i)).toFixed(decimalPlaces))
const unit = units[i]
return [value, unit ?? '']
}
Expand Down
10 changes: 5 additions & 5 deletions packages/hawtio/src/plugins/shared/__mocks__/jolokia-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IRequest, IResponse, IResponseFn, ISimpleOptions } from 'jolokia.js'
import { AttributeValues, IJolokiaService, JolokiaStoredOptions, JolokiaListMethod } from '../jolokia-service'
import { ListRequestOptions, Request, Response } from 'jolokia.js'
import { AttributeValues, IJolokiaService, JolokiaListMethod, JolokiaStoredOptions } from '../jolokia-service'
import jmxCamelResponse from './jmx-camel-tree.json'

class MockJolokiaService implements IJolokiaService {
Expand All @@ -15,7 +15,7 @@ class MockJolokiaService implements IJolokiaService {
return 0
}

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

Expand All @@ -35,11 +35,11 @@ class MockJolokiaService implements IJolokiaService {
return []
}

async bulkRequest(requests: IRequest[]): Promise<IResponse[]> {
async bulkRequest(requests: Request[]): Promise<Response[]> {
return []
}

async register(request: IRequest, callback: IResponseFn): Promise<number> {
async register(request: Request, callback: (response: Response) => void): Promise<number> {
return 0
}

Expand Down
Loading

0 comments on commit 31d0978

Please sign in to comment.