Skip to content
Permalink
Browse files

perf(elasticsearch): fixes

  • Loading branch information...
polonel committed Apr 19, 2019
1 parent dccb695 commit eddc577ee52de4e517fc464f47398a659abe3d06
@@ -25,6 +25,7 @@ import Button from 'components/Button'
import PageContent from 'components/PageContent'

import UIKit from 'uikit'
import helpers from 'lib/helpers'

class DepartmentsContainer extends React.Component {
componentDidMount () {
@@ -60,10 +61,6 @@ class DepartmentsContainer extends React.Component {
}

render () {
const mappedDepartments = this.props.departments.map(department => {
return department.name
})

return (
<div>
<PageTitle
@@ -157,19 +154,23 @@ class DepartmentsContainer extends React.Component {
</td>
<td>
<ButtonGroup>
<Button
text={'Edit'}
small={true}
waves={true}
onClick={() => this.onEditDepartmentClick(department)}
/>
<Button
text={'Delete'}
style={'danger'}
small={true}
waves={true}
onClick={() => this.onDeleteDepartmentClick(department.get('_id'))}
/>
{helpers.canUser('departments:update', true) && (
<Button
text={'Edit'}
small={true}
waves={true}
onClick={() => this.onEditDepartmentClick(department)}
/>
)}
{helpers.canUser('departments:delete', true) && (
<Button
text={'Delete'}
style={'danger'}
small={true}
waves={true}
onClick={() => this.onDeleteDepartmentClick(department.get('_id'))}
/>
)}
</ButtonGroup>
</td>
</tr>
@@ -29,6 +29,7 @@ import TableCell from 'components/Table/TableCell'
import ButtonGroup from 'components/ButtonGroup'

import UIKit from 'uikit'
import helpers from 'lib/helpers'

class GroupsContainer extends React.Component {
componentDidMount () {
@@ -106,14 +107,18 @@ class GroupsContainer extends React.Component {
</TableCell>
<TableCell style={{ textAlign: 'right', paddingRight: 15 }}>
<ButtonGroup>
<Button text={'Edit'} small={true} waves={true} onClick={() => this.onEditGroupClick(group.toJS())} />
<Button
text={'Delete'}
style={'danger'}
small={true}
waves={true}
onClick={() => this.onDeleteGroupClick(group.get('_id'))}
/>
{helpers.canUser('groups:update', true) && (
<Button text={'Edit'} small={true} waves={true} onClick={() => this.onEditGroupClick(group.toJS())} />
)}
{helpers.canUser('groups:delete', true) && (
<Button
text={'Delete'}
style={'danger'}
small={true}
waves={true}
onClick={() => this.onDeleteGroupClick(group.get('_id'))}
/>
)}
</ButtonGroup>
</TableCell>
</TableRow>
@@ -129,8 +129,8 @@ class ElasticsearchSettingsContainer extends React.Component {

getStatus () {
const self = this
self.esStatus = 'Please Wait...'
self.inSyncText = 'Please Wait...'
// self.esStatus = 'Please Wait...'
// self.inSyncText = 'Please Wait...'
// if (!this.state.configured) {
// this.esStatus = 'Not Configured'
// this.indexCount = 0
@@ -144,7 +144,10 @@ class ElasticsearchSettingsContainer extends React.Component {
.get('/api/v2/es/status')
.then(res => {
const data = res.data
self.esStatus = data.status.esStatus
if (data.status.isRebuilding) {
self.esStatus = 'Rebuilding...'
self.esStatusClass = ''
} else self.esStatus = data.status.esStatus
if (self.esStatus.toLowerCase() === 'connected') self.esStatusClass = 'text-success'
else if (self.esStatus.toLowerCase() === 'error') self.esStatusClass = 'text-danger'

@@ -158,7 +161,7 @@ class ElasticsearchSettingsContainer extends React.Component {
}

if (data.status.isRebuilding) {
setTimeout(self.getStatus, 5000)
setTimeout(self.getStatus, 3000)
self.disableRebuild = true
} else self.disableRebuild = false
})
@@ -207,7 +210,7 @@ class ElasticsearchSettingsContainer extends React.Component {
return (
<div className={this.props.active ? '' : 'hide'}>
<SettingItem
title={'Elasticsearch'}
title={'Elasticsearch - Beta'}
subtitle={'Enable the Elasticsearch engine'}
component={
<EnableSwitch
@@ -236,7 +239,7 @@ class ElasticsearchSettingsContainer extends React.Component {
/>
<SettingItem
title={'Elasticsearch Server Configuration'}
tooltip={'Changing server settings will require a rebuild of the index'}
tooltip={'Changing server settings will require a rebuild of the index and server restart.'}
subtitle={'The connection settings to the Elasticsearch server.'}
>
<form onSubmit={e => this.onFormSubmit(e)}>
@@ -124,14 +124,18 @@ class TeamsContainer extends React.Component {
</TableCell>
<TableCell style={{ textAlign: 'right', paddingRight: 15 }}>
<ButtonGroup>
<Button text={'Edit'} small={true} waves={true} onClick={() => this.onEditTeamClick(team.toJS())} />
<Button
text={'Delete'}
style={'danger'}
small={true}
waves={true}
onClick={() => this.onDeleteTeamClick(team.get('_id'))}
/>
{helpers.canUser('teams:update', true) && (
<Button text={'Edit'} small={true} waves={true} onClick={() => this.onEditTeamClick(team.toJS())} />
)}
{helpers.canUser('teams:delete', true) && (
<Button
text={'Delete'}
style={'danger'}
small={true}
waves={true}
onClick={() => this.onDeleteTeamClick(team.get('_id'))}
/>
)}
</ButtonGroup>
</TableCell>
</TableRow>
@@ -32,6 +32,9 @@ apiElasticSearch.status = function (req, res) {

async.parallel(
[
function (done) {
return es.checkConnection(done)
},
function (done) {
es.getIndexCount(function (err, data) {
if (err) return done(err)
@@ -51,7 +54,7 @@ apiElasticSearch.status = function (req, res) {
if (err) return res.status(500).json({ success: false, error: err })

response.esStatus = global.esStatus
response.isRebuilding = global.esRebuilding || false
response.isRebuilding = global.esRebuilding === true
response.inSync = response.dbCount === response.indexCount

res.json({ success: true, status: response })
@@ -203,7 +203,9 @@ installController.install = function (req, res) {
)
}
],
next
function (err) {
return next(err)
}
)
},
function (next) {
@@ -298,33 +300,18 @@ installController.install = function (req, res) {
)
},
function (roleResults, next) {
GroupSchema.getGroupByName('Administrators', function (err, group) {
if (err) {
winston.error('Database Error: ' + err.message)
return next('Database Error:' + err.message)
}

if (!_.isNull(group) && !_.isUndefined(group) && !_.isEmpty(group)) {
return next(null, group)
}

// Create Admin Group
var adminGroup = new GroupSchema({
name: 'Administrators',
var TeamSchema = require('../models/team')
TeamSchema.create(
{
name: 'Support (Default)',
members: []
})

adminGroup.save(function (err) {
if (err) {
winston.error('Database Error:' + err.message)
return next('Database Error:' + err.message)
}

return next(null, adminGroup, roleResults)
})
})
},
function (err, team) {
return next(err, team, roleResults)
}
)
},
function (adminGroup, roleResults, next) {
function (defaultTeam, roleResults, next) {
UserSchema.getUserByUsername(user.username, function (err, admin) {
if (err) {
winston.error('Database Error: ' + err.message)
@@ -356,7 +343,7 @@ installController.install = function (req, res) {
return next('Database Error: ' + err.message)
}

adminGroup.addMember(savedUser._id, function (err, success) {
defaultTeam.addMember(savedUser._id, function (err, success) {
if (err) {
winston.error('Database Error: ' + err.message)
return next('Database Error: ' + err.message)
@@ -366,18 +353,32 @@ installController.install = function (req, res) {
return next('Unable to add user to Administrator group!')
}

adminGroup.save(function (err) {
defaultTeam.save(function (err) {
if (err) {
winston.error('Database Error: ' + err.message)
return next('Database Error: ' + err.message)
}

return next(null)
return next(null, defaultTeam)
})
})
})
})
},
function (defaultTeam, next) {
var DepartmentSchema = require('../models/department')
DepartmentSchema.create(
{
name: 'Support - All Groups (Default)',
teams: [defaultTeam._id],
allGroups: true,
groups: []
},
function (err) {
return next(err)
}
)
},
function (next) {
if (!process.env.TRUDESK_DOCKER) return next()
var S = require('../models/setting')
@@ -411,10 +412,6 @@ installController.install = function (req, res) {
database: database,
shard: port === '---'
},
elasticsearch: {
host: eHost,
port: ePort
},
tokens: {
secret: chance.hash() + chance.md5(),
expires: 900 // 15min
@@ -39,16 +39,16 @@ function checkConnection (callback) {
)
}

ES.testConnection = function (callback) {
if (process.env.ELATICSEARCH_URI) ES.host = process.env.ELATICSEARCH_URI
else ES.host = nconf.get('elasticsearch:host') + ':' + nconf.get('elasticsearch:port')

ES.esclient = new elasticsearch.Client({
host: ES.host
})

checkConnection(callback)
}
// ES.testConnection = function (callback) {
// if (process.env.ELATICSEARCH_URI) ES.host = process.env.ELATICSEARCH_URI
// else ES.host = nconf.get('elasticsearch:host') + ':' + nconf.get('elasticsearch:port')
//
// ES.esclient = new elasticsearch.Client({
// host: ES.host
// })
//
// checkConnection(callback)
// }

ES.setupHooks = function () {
var ticketSchema = require('../models/ticket')
@@ -208,6 +208,7 @@ ES.rebuildIndex = function () {

esFork.once('message', function (data) {
global.esStatus = data.success ? 'Connected' : 'Error'
global.esRebuilding = false
})

esFork.on('exit', function () {
@@ -275,4 +276,18 @@ ES.init = function (callback) {
})
}

ES.checkConnection = function (callback) {
// global.esStatus = 'Please Wait...'
return checkConnection(function (err) {
if (err) {
global.esStatus = 'Error'
winston.warn(err)
return callback()
}

global.esStatus = 'Connected'
return callback()
})
}

module.exports = ES
@@ -210,7 +210,7 @@ function sendAndEmptyQueue (bulk, callback) {
}
}
)
}
} else if (typeof callback === 'function') return callback()

return []
}
@@ -370,14 +370,13 @@ function rebuild (callback) {
setupClient()
rebuild(function (err) {
if (err) {
process.send({ success: false, error: err })
process.kill(0)
return process.send({ success: false, error: err })
}

process.send({ success: true })
// Kill it in 10sec to offset refresh timers
setTimeout(function () {
process.kill(0)
}, 10000)
process.send({ success: true })
return process.kill(0)
}, 6000)
})
})()
Oops, something went wrong.

0 comments on commit eddc577

Please sign in to comment.
You can’t perform that action at this time.