-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(shared,jmx): support serialising long to string in JSON response…
… from Jolokia * Upgrade jolokia.js to 2.0.3 (that supports 'serializeLong' option) * Create JMX preferences and provide 'Serialize long to string' option, which can affect Jolokia requests within JMX plugin This fix limits the 'serializeLong=string' option to JMX, because the change of the bahaviour might cause unexpected errors in other plugins. JMX is a generic MBeans manipulation plugin, so it should make sense to have such an option plugin-wide. Each plugin should decide whether it's worth applying the option or not. Fix #292
- Loading branch information
Showing
11 changed files
with
160 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { JmxOptions, jmxPreferencesService } from '@hawtiosrc/plugins/shared/jmx-preferences-service' | ||
import { TooltipHelpIcon } from '@hawtiosrc/ui/icons' | ||
import { CardBody, Checkbox, Form, FormGroup } from '@patternfly/react-core' | ||
import React, { useState } from 'react' | ||
|
||
export const JmxPreferences: React.FunctionComponent = () => { | ||
const [options, setOptions] = useState(jmxPreferencesService.loadOptions()) | ||
|
||
const updateOptions = (updated: Partial<JmxOptions>) => { | ||
jmxPreferencesService.saveOptions(updated) | ||
setOptions({ ...options, ...updated }) | ||
} | ||
|
||
return ( | ||
<CardBody> | ||
<Form isHorizontal> | ||
<FormGroup | ||
label='Serialize long to string' | ||
fieldId='serialize-long-to-string' | ||
labelIcon={<TooltipHelpIcon tooltip='Serialize long values in the JSON responses from Jolokia to string' />} | ||
> | ||
<Checkbox | ||
id='serialize-long-to-string-input' | ||
isChecked={options.serializeLong} | ||
onChange={(_event, serializeLong) => updateOptions({ serializeLong })} | ||
/> | ||
</FormGroup> | ||
</Form> | ||
</CardBody> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/hawtio/src/plugins/shared/jmx-preferences-service.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { DEFAULT_OPTIONS, STORAGE_KEY_PREFERENCES, jmxPreferencesService } from './jmx-preferences-service' | ||
|
||
describe('JmxPreferencesService', () => { | ||
beforeEach(() => { | ||
localStorage.removeItem(STORAGE_KEY_PREFERENCES) | ||
}) | ||
|
||
test('loadOptions/saveOptions', () => { | ||
let options = jmxPreferencesService.loadOptions() | ||
expect(options).toEqual(DEFAULT_OPTIONS) | ||
|
||
jmxPreferencesService.saveOptions({ serializeLong: true }) | ||
options = jmxPreferencesService.loadOptions() | ||
expect(options).toEqual({ ...DEFAULT_OPTIONS, serializeLong: true }) | ||
}) | ||
}) |
29 changes: 29 additions & 0 deletions
29
packages/hawtio/src/plugins/shared/jmx-preferences-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export const STORAGE_KEY_PREFERENCES = 'jmx.preferences' | ||
|
||
export type JmxOptions = { | ||
serializeLong: boolean | ||
} | ||
|
||
export const DEFAULT_OPTIONS: JmxOptions = { | ||
serializeLong: false, | ||
} as const | ||
|
||
export interface IJmxPreferencesService { | ||
loadOptions(): JmxOptions | ||
saveOptions(options: Partial<JmxOptions>): void | ||
} | ||
|
||
class JmxPreferencesService implements IJmxPreferencesService { | ||
loadOptions(): JmxOptions { | ||
const item = localStorage.getItem(STORAGE_KEY_PREFERENCES) | ||
const savedOptions = item ? JSON.parse(item) : {} | ||
return { ...DEFAULT_OPTIONS, ...savedOptions } | ||
} | ||
|
||
saveOptions(options: Partial<JmxOptions>) { | ||
const updated = { ...this.loadOptions(), ...options } | ||
localStorage.setItem(STORAGE_KEY_PREFERENCES, JSON.stringify(updated)) | ||
} | ||
} | ||
|
||
export const jmxPreferencesService = new JmxPreferencesService() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 8 additions & 1 deletion
9
packages/hawtio/src/plugins/shared/operations/operation-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.