Skip to content

Commit

Permalink
fix(deps): Upgrade to jolokia.js 2.1.7 (typescript, fetch(), no jquer…
Browse files Browse the repository at this point in the history
…y) (closes #1101) (#1111)
  • Loading branch information
grgrzybek authored Sep 12, 2024
1 parent c6fe03c commit 1658a7b
Show file tree
Hide file tree
Showing 31 changed files with 659 additions and 431 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module.exports = {
'warn',
{
args: 'none',
argsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
Expand Down
3 changes: 2 additions & 1 deletion packages/hawtio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"dependencies": {
"@hawtio/camel-model-v4_0": "npm:@hawtio/camel-model@~4.0.5",
"@hawtio/camel-model-v4_4": "npm:@hawtio/camel-model@~4.4.2",
"@jolokia.js/simple": "^2.1.7",
"@module-federation/utilities": "^3.1.7",
"@patternfly/react-charts": "~7.3.0",
"@patternfly/react-code-editor": "~5.3.3",
Expand All @@ -55,7 +56,7 @@
"@types/react-router-dom": "^5.3.3",
"dagre": "^0.8.5",
"eventemitter3": "^5.0.1",
"jolokia.js": "^2.0.3",
"jolokia.js": "^2.1.7",
"jquery": "^3.7.1",
"js-logger": "^1.6.1",
"jwt-decode": "^4.0.0",
Expand Down
25 changes: 16 additions & 9 deletions packages/hawtio/src/plugins/camel/CamelContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
EmptyStateHeader,
} from '@patternfly/react-core'
import { CubesIcon } from '@patternfly/react-icons'
import { Response } from 'jolokia.js'
import Jolokia, { JolokiaSuccessResponse, JolokiaErrorResponse } 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 @@ -209,14 +209,21 @@ const CamelContentContextToolbar: React.FunctionComponent = () => {
const attr = await contextsService.getContext(selectedNode)
if (attr) setContextState(attr)

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
const attrs = response.value as AttributeValues
const newAttrs = contextsService.toContextState(selectedNode, attrs)
if (newAttrs) setContextState(newAttrs)
})
contextsService.register(
{ type: 'read', mbean: objectName },
(response: JolokiaSuccessResponse | JolokiaErrorResponse) => {
if (Jolokia.isError(response)) {
log.debug('Scheduler - Contexts (error):', response.error)
return
}
log.debug('Scheduler - Contexts:', response.value)

// Replace the context in the existing set with the new one
const attrs = response.value as AttributeValues
const newAttrs = contextsService.toContextState(selectedNode, attrs)
if (newAttrs) setContextState(newAttrs)
},
)
}
readAttributes()

Expand Down
33 changes: 20 additions & 13 deletions packages/hawtio/src/plugins/camel/contexts/Contexts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AttributeValues } from '@hawtiosrc/plugins/shared/jolokia-service'
import { Card, CardBody, Text } from '@patternfly/react-core'
import { InfoCircleIcon } from '@patternfly/react-icons'
import { Table, Tbody, Td, Th, Thead, Tr } from '@patternfly/react-table'
import { Response } from 'jolokia.js'
import Jolokia, { JolokiaSuccessResponse, JolokiaErrorResponse } from 'jolokia.js'
import React, { useContext, useEffect, useState } from 'react'
import { log } from '../globals'
import { ContextToolbar } from './ContextToolbar'
Expand Down Expand Up @@ -60,18 +60,25 @@ export const Contexts: React.FunctionComponent = () => {
if (!objectName) {
return
}
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
const attrs = response.value as AttributeValues
const newCtx = contextsService.toContextState(ctx.node, attrs)

// Replace the context in the contexts array
const newContexts = [...contexts]
newContexts.splice(idx, 1, newCtx)
setContexts(newContexts)
})
contextsService.register(
{ type: 'read', mbean: objectName },
(r: JolokiaSuccessResponse | JolokiaErrorResponse) => {
if (Jolokia.isError(r)) {
log.warn('Scheduler - Contexts (error):', r.error)
return
}
log.debug('Scheduler - Contexts:', r.value)

// Replace the context in the existing set with the new one
const attrs = r.value as AttributeValues
const newCtx = contextsService.toContextState(ctx.node, attrs)

// Replace the context in the contexts array
const newContexts = [...contexts]
newContexts.splice(idx, 1, newCtx)
setContexts(newContexts)
},
)
})

return () => contextsService.unregisterAll()
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 { Request, Response } from 'jolokia.js'
import { JolokiaRequest, JolokiaSuccessResponse, JolokiaErrorResponse } 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: Request, callback: (response: Response) => void) {
async register(request: JolokiaRequest, callback: (response: JolokiaSuccessResponse | JolokiaErrorResponse) => void) {
const handle = await jolokiaService.register(request, callback)
log.debug('Register handle:', handle)
this.handles.push(handle)
Expand Down
8 changes: 6 additions & 2 deletions packages/hawtio/src/plugins/camel/debug/Debug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
TimesCircleIcon,
} from '@patternfly/react-icons'
import { Table, Tbody, Td, Th, Thead, Tr } from '@patternfly/react-table'
import { Response } from 'jolokia.js'
import Jolokia, { JolokiaSuccessResponse, JolokiaErrorResponse } 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 @@ -225,7 +225,11 @@ export const Debug: React.FunctionComponent = () => {
mbean: debugNode.objectName,
operation: 'getDebugCounter',
},
(response: Response) => {
(response: JolokiaSuccessResponse | JolokiaErrorResponse) => {
if (Jolokia.isError(response)) {
log.warn('Scheduler - Debug (error):', response.error)
return
}
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 { Request, Response } from 'jolokia.js'
import { JolokiaRequest, JolokiaSuccessResponse, JolokiaErrorResponse } 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: Request, callback: (response: Response) => void) {
async register(request: JolokiaRequest, callback: (response: JolokiaSuccessResponse | JolokiaErrorResponse) => void) {
const handle = await jolokiaService.register(request, callback)
log.debug('Register handle:', handle)
this.handles.push(handle)
Expand Down
10 changes: 7 additions & 3 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 { Panel, PanelHeader, PanelMain, PanelMainBody, Title } from '@patternfly/react-core'
import { Table, Tbody, Td, Th, Thead, Tr } from '@patternfly/react-table'
import { Response } from 'jolokia.js'
import Jolokia, { JolokiaSuccessResponse, JolokiaErrorResponse } from 'jolokia.js'
import React, { useContext, useEffect, useState } from 'react'
import { CamelContext } from '../context'
import { log } from '../globals'
Expand Down Expand Up @@ -33,8 +33,12 @@ export const Profile: React.FunctionComponent = () => {
mbean: selectedNode.objectName as string,
operation: 'dumpRouteStatsAsXml()',
},
(response: Response) => {
log.debug('Scheduler - Debug:', response.value)
(response: JolokiaSuccessResponse | JolokiaErrorResponse) => {
if (Jolokia.isError(response)) {
log.warn('Scheduler - Profile (error):', response.error)
return
}
log.debug('Scheduler - Profile:', 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 { Request, Response } from 'jolokia.js'
import { JolokiaRequest, JolokiaSuccessResponse, JolokiaErrorResponse } 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: Request, callback: (response: Response) => void) {
async register(request: JolokiaRequest, callback: (response: JolokiaSuccessResponse | JolokiaErrorResponse) => void) {
const handle = await jolokiaService.register(request, callback)
log.debug('Register handle:', handle)
this.handles.push(handle)
Expand Down
12 changes: 8 additions & 4 deletions packages/hawtio/src/plugins/camel/rest-services/RestServices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '@patternfly/react-core'

import { Table, Tbody, Td, Th, Thead, Tr } from '@patternfly/react-table'
import { Response } from 'jolokia.js'
import Jolokia, { JolokiaSuccessResponse, JolokiaErrorResponse } 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,8 +75,12 @@ export const RestServices: React.FunctionComponent = () => {
mbean: selectedNode.objectName as string,
operation: 'listRestServices()',
},
(response: Response) => {
log.debug('Scheduler - Debug:', response.value)
(response: JolokiaSuccessResponse | JolokiaErrorResponse) => {
if (Jolokia.isError(response)) {
log.warn('Scheduler - RestService:', response.error)
return
}
log.debug('Scheduler - RestService:', response.value)
fetchRest()
},
)
Expand Down Expand Up @@ -162,7 +166,7 @@ export const RestServices: React.FunctionComponent = () => {
filterRestSvcData(restSvcData, removed)
}

const onSelectFilterType = (event?: ChangeEvent<Element> | MouseEvent<Element>, value?: string | number) => {
const onSelectFilterType = (_event?: ChangeEvent<Element> | MouseEvent<Element>, value?: string | number) => {
if (!value) return

setFilterType(value as string)
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 { Request, Response } from 'jolokia.js'
import { JolokiaRequest, JolokiaSuccessResponse, JolokiaErrorResponse } 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: Request, callback: (response: Response) => void) {
async register(request: JolokiaRequest, callback: (response: JolokiaSuccessResponse | JolokiaErrorResponse) => void) {
const handle = await jolokiaService.register(request, callback)
log.debug('Register handle:', handle)
this.handles.push(handle)
Expand Down
10 changes: 7 additions & 3 deletions packages/hawtio/src/plugins/camel/trace/Trace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { childText, parseXML } from '@hawtiosrc/util/xml'
import { Button, Divider, Panel, PanelHeader, PanelMain, PanelMainBody, Text, Title } from '@patternfly/react-core'
import { BanIcon, PlayIcon } from '@patternfly/react-icons'
import { Table, Tbody, Td, Th, Thead, Tr } from '@patternfly/react-table'
import { Response } from 'jolokia.js'
import Jolokia, { JolokiaSuccessResponse, JolokiaErrorResponse } 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 @@ -110,8 +110,12 @@ export const Trace: React.FunctionComponent = () => {
mbean: tracingNode.objectName as string,
operation: 'dumpAllTracedMessagesAsXml()',
},
(response: Response) => {
log.debug('Scheduler - Debug:', response.value)
(response: JolokiaSuccessResponse | JolokiaErrorResponse) => {
if (Jolokia.isError(response)) {
log.debug('Scheduler - Trace (error):', response.error)
return
}
log.debug('Scheduler - Trace:', 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 { Request, Response } from 'jolokia.js'
import { JolokiaRequest, JolokiaSuccessResponse, JolokiaErrorResponse } 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: Request, callback: (response: Response) => void) {
async register(request: JolokiaRequest, callback: (response: JolokiaSuccessResponse | JolokiaErrorResponse) => 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 @@ -76,10 +76,14 @@ class DiscoverService {
}
// One-off Jolokia instance to connect to the agent
const jolokia = connectService.createJolokia(this.agentToConnection(agent))
agent.startTime = jolokia.getAttribute('java.lang:type=Runtime', 'StartTime') as number
agent.startTime = (await jolokia.getAttribute('java.lang:type=Runtime', 'StartTime')) as number
if (!this.hasName(agent)) {
// Only look for command if agent vm is not known
agent.command = jolokia.getAttribute('java.lang:type=Runtime', 'SystemProperties', 'sun.java.command') as string
agent.command = (await jolokia.getAttribute(
'java.lang:type=Runtime',
'SystemProperties',
'sun.java.command',
)) as string
}
}
}
Expand Down
19 changes: 16 additions & 3 deletions packages/hawtio/src/plugins/quartz/quartz-service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { eventService } from '@hawtiosrc/core'
import { AttributeValues, MBeanNode, jolokiaService, workspace } from '@hawtiosrc/plugins/shared'
import { getQueryParameterValue } from '@hawtiosrc/util/urls'
import { Request } from 'jolokia.js'
import { JolokiaRequest } from 'jolokia.js'
import Jolokia from '@jolokia.js/simple'
import { attributeService } from '../shared/attributes/attribute-service'
import { jmxDomain, log } from './globals'

Expand Down Expand Up @@ -126,6 +127,10 @@ class QuartzService {

registerTriggersLoad(schedulerMBean: string, callback: (triggers: Trigger[]) => void) {
attributeService.register({ type: 'read', mbean: schedulerMBean }, async response => {
if (Jolokia.isError(response)) {
log.warn('Scheduler - Attributes (error):', response.error)
return
}
const attrs = response.value as AttributeValues
log.debug('Scheduler - Attributes:', attrs)
const triggers = attrs['AllTriggers'] as Trigger[]
Expand All @@ -138,6 +143,10 @@ class QuartzService {

registerJobsLoad(schedulerMBean: string, callback: (jobs: Job[]) => void) {
attributeService.register({ type: 'read', mbean: schedulerMBean }, async response => {
if (Jolokia.isError(response)) {
log.warn('Scheduler - Attributes (error):', response.error)
return
}
const attrs = response.value as AttributeValues
log.debug('Scheduler - Attributes:', attrs)
const jobDetails = attrs['AllJobDetails'] as JobDetails
Expand All @@ -159,15 +168,19 @@ class QuartzService {
return
}

const requests: Request[] = triggers.map(trigger => ({
const requests: JolokiaRequest[] = triggers.map(trigger => ({
type: 'exec',
mbean: schedulerMBean,
operation: QUARTZ_OPERATIONS.getTriggerState,
arguments: [trigger.name, trigger.group],
}))
const responses = await jolokiaService.bulkRequest(requests)
triggers.forEach((trigger, index) => {
trigger.state = (responses[index]?.value ?? 'unknown') as string
const response = responses[index]
if (!response || (response && Jolokia.isError(response))) {
return
}
trigger.state = (response?.value ?? 'unknown') as string
this.applyJobDetails(trigger, jobDetails)
})
}
Expand Down
5 changes: 5 additions & 0 deletions packages/hawtio/src/plugins/quartz/scheduler/Scheduler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { QuartzContext } from '../context'
import { log } from '../globals'
import { QUARTZ_OPERATIONS, quartzService } from '../quartz-service'
import './Scheduler.css'
import Jolokia from 'jolokia.js'

export const Scheduler: React.FunctionComponent = () => {
const { selectedNode } = useContext(QuartzContext)
Expand All @@ -39,6 +40,10 @@ export const Scheduler: React.FunctionComponent = () => {
})

attributeService.register({ type: 'read', mbean: objectName }, response => {
if (Jolokia.isError(response)) {
log.warn('Scheduler - Attributes (error):', response.error)
return
}
log.debug('Scheduler - Attributes:', response.value)
setAttributes(response.value as AttributeValues)
})
Expand Down
Loading

0 comments on commit 1658a7b

Please sign in to comment.