Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cluster role, db filename and total store size to sidebar #566

Merged
merged 2 commits into from
Jun 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/browser/modules/DatabaseInfo/DatabaseKernelInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,26 @@

import { connect } from 'preact-redux'
import { withBus } from 'preact-suber'
import { getVersion, getEdition } from 'shared/modules/dbMeta/dbMetaDuck'
import { getVersion, getEdition, getDbName, getStoreSize, getClusterRole } from 'shared/modules/dbMeta/dbMetaDuck'
import { executeCommand } from 'shared/modules/commands/commandsDuck'
import { toHumanReadableBytes } from 'services/utils'

import Render from 'browser-components/Render'
import {DrawerSection, DrawerSectionBody, DrawerSubHeader} from 'browser-components/drawer'
import {StyledTable, StyledKey, StyledValue, StyledValueUCFirst, Link} from './styled'

export const DatabaseKernelInfo = ({version, edition, onItemClick}) => {
export const DatabaseKernelInfo = ({role, version, edition, dbName, storeSize, onItemClick}) => {
return (
<DrawerSection className='database-kernel-info'>
<DrawerSubHeader>Database</DrawerSubHeader>
<DrawerSectionBody>
<StyledTable>
<tbody>
<Render if={role}>
<tr>
<StyledKey>Cluster role: </StyledKey><StyledValue>{role}</StyledValue>
</tr>
</Render>
<Render if={version}>
<tr>
<StyledKey>Version: </StyledKey><StyledValue>{version}</StyledValue>
Expand All @@ -44,6 +50,16 @@ export const DatabaseKernelInfo = ({version, edition, onItemClick}) => {
<StyledKey>Edition: </StyledKey><StyledValueUCFirst>{edition}</StyledValueUCFirst>
</tr>
</Render>
<Render if={dbName}>
<tr>
<StyledKey>Name: </StyledKey><StyledValue>{dbName}</StyledValue>
</tr>
</Render>
<Render if={storeSize}>
<tr>
<StyledKey>Size: </StyledKey><StyledValue>{toHumanReadableBytes(storeSize)}</StyledValue>
</tr>
</Render>
<tr>
<StyledKey>Information: </StyledKey><StyledValue><Link onClick={() => onItemClick(':sysinfo')}>:sysinfo</Link></StyledValue>
</tr>
Expand All @@ -60,7 +76,10 @@ export const DatabaseKernelInfo = ({version, edition, onItemClick}) => {
const mapStateToProps = (store) => {
return {
version: getVersion(store),
edition: getEdition(store)
edition: getEdition(store),
dbName: getDbName(store),
storeSize: getStoreSize(store),
role: getClusterRole(store)
}
}
const mapDispatchToProps = (dispatch, ownProps) => {
Expand Down
35 changes: 35 additions & 0 deletions src/shared/modules/dbMeta/__snapshots__/dbMetaDuck.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,38 @@ Object {
"procedures": Array [],
"properties": Array [],
"relationshipTypes": Array [],
"role": null,
"server": Object {
"dbName": null,
"edition": null,
"storeId": null,
"storeSize": null,
"version": null,
},
"settings": Object {
"browser.allow_outgoing_connections": false,
"browser.remote_content_hostname_whitelist": "guides.neo4j.com, localhost",
},
}
`;

exports[`updating metadata can update meta values with UPDATE 1`] = `
Object {
"functions": Array [],
"hydrated": true,
"labels": Array [],
"myKey": "yo",
"noKey": true,
"procedures": Array [],
"properties": Array [],
"relationshipTypes": Array [],
"role": null,
"secondKey": true,
"server": Object {
"dbName": null,
"edition": null,
"storeId": null,
"storeSize": null,
"version": null,
},
"settings": Object {
Expand All @@ -27,9 +56,12 @@ Object {
"procedures": Array [],
"properties": Array [],
"relationshipTypes": Array [],
"role": null,
"server": Object {
"dbName": undefined,
"edition": "enterprise",
"storeId": "xxxx",
"storeSize": undefined,
"version": "3.2.0-RC2",
},
"settings": Object {
Expand All @@ -48,9 +80,12 @@ Object {
"procedures": Array [],
"properties": Array [],
"relationshipTypes": Array [],
"role": null,
"server": Object {
"dbName": null,
"edition": null,
"storeId": null,
"storeSize": null,
"version": null,
},
"settings": Object {
Expand Down
48 changes: 42 additions & 6 deletions src/shared/modules/dbMeta/dbMetaDuck.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
} from 'shared/modules/connections/connectionsDuck'

export const NAME = 'meta'
export const UPDATE = 'meta/UPDATE'
export const UPDATE_META = 'meta/UPDATE_META'
export const UPDATE_SERVER = 'meta/UPDATE_SERVER'
export const UPDATE_SETTINGS = 'meta/UPDATE_SETTINGS'
Expand Down Expand Up @@ -63,6 +64,9 @@ export function getMetaInContext (state, context) {

export const getVersion = (state) => state[NAME].server.version
export const getEdition = (state) => state[NAME].server.edition
export const getDbName = (state) => state[NAME].server.dbName
export const getStoreSize = (state) => state[NAME].server.storeSize
export const getClusterRole = (state) => state[NAME].role
export const isEnterprise = (state) => state[NAME].server.edition === 'enterprise'
export const isBeta = (state) => /-/.test(state[NAME].server.version)
export const getStoreId = (state) => state[NAME].server.storeId
Expand Down Expand Up @@ -133,10 +137,13 @@ const initialState = {
properties: [],
functions: [],
procedures: [],
role: null,
server: {
version: null,
edition: null,
storeId: null
storeId: null,
dbName: null,
storeSize: null
},
settings: {
'browser.allow_outgoing_connections': false,
Expand All @@ -151,10 +158,14 @@ export default function meta (state = initialState, action) {
state = hydrate(initialState, state)

switch (action.type) {
case UPDATE:
const { type, ...rest } = action // eslint-disable-line
return { ...state, ...rest }
case UPDATE_META:
return {...state, ...updateMetaForContext(state, action.meta, action.context)}
case UPDATE_SERVER:
return {...state, server: { version: action.version, edition: action.edition, storeId: action.storeId }}
const { version, edition, storeId, dbName, storeSize } = action
return {...state, server: { version, edition, storeId, dbName, storeSize }}
case UPDATE_SETTINGS:
return {...state, settings: { ...action.settings }}
case CLEAR:
Expand All @@ -178,6 +189,13 @@ export function fetchMetaData () {
}
}

export const update = (obj) => {
return {
type: UPDATE,
...obj
}
}

export const updateSettings = (settings) => {
return {
type: UPDATE_SETTINGS,
Expand Down Expand Up @@ -228,22 +246,28 @@ export const dbMetaEpic = (some$, store) =>
.fromPromise(getJmxValues([
['Kernel', 'KernelVersion'],
['Kernel', 'StoreId'],
['Configuration', 'unsupported.dbms.edition']
['Kernel', 'DatabaseName'],
['Configuration', 'unsupported.dbms.edition'],
['Store file sizes', 'TotalStoreSize']
]))
.catch((e) => Rx.Observable.of(null))
})
.do((res) => {
if (!res) return
const [ kvObj, storeObj, edObj ] = res
const [ kvObj, storeObj, nameObj, edObj, sizeObj ] = res
const versionMatch = kvObj.KernelVersion.match(/version:\s([^,$]+)/)
const version = (versionMatch !== null && versionMatch.length > 1) ? versionMatch[1] : null
const edition = edObj['unsupported.dbms.edition']
const storeId = storeObj['StoreId']
const dbName = nameObj['DatabaseName']
const storeSize = sizeObj['TotalStoreSize']
store.dispatch({
type: UPDATE_SERVER,
version,
edition,
storeId
storeId,
dbName,
storeSize
})
})
// Server config for browser
Expand All @@ -262,7 +286,6 @@ export const dbMetaEpic = (some$, store) =>
store.dispatch(updateSettings(settings))
})
})
.takeUntil(some$.ofType(LOST_CONNECTION).filter(connectionLossFilter))
// Server security settings
.mergeMap(() => {
return getServerConfig(['dbms.security'])
Expand All @@ -276,6 +299,19 @@ export const dbMetaEpic = (some$, store) =>
store.dispatch(setAuthEnabled(authEnabled))
})
})
// Cluster role
.mergeMap(() =>
Rx.Observable
.fromPromise(bolt.directTransaction('CALL dbms.cluster.role() YIELD role'))
.catch((e) => Rx.Observable.of(null))
.do((res) => {
if (!res) return Rx.Observable.of(null)
const role = res.records[0].get(0)
store.dispatch(update({ role }))
return Rx.Observable.of(null)
})
)

.takeUntil(some$.ofType(LOST_CONNECTION).filter(connectionLossFilter))
.mapTo({ type: 'NOOP' })
})
Expand Down
15 changes: 15 additions & 0 deletions src/shared/modules/dbMeta/dbMetaDuck.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,19 @@ describe('updating metadata', () => {
// Then
expect(nextState).toMatchSnapshot()
})

test('can update meta values with UPDATE', () => {
// Given
const initState = {
myKey: 'val',
noKey: true
}
const action = { type: meta.UPDATE, myKey: 'yo', secondKey: true }

// When
const nextState = reducer(initState, action)

// Then
expect(nextState).toMatchSnapshot()
})
})