Skip to content

Commit

Permalink
PLT-2899 adding clustering of app servers (mattermost#3682)
Browse files Browse the repository at this point in the history
* PLT-2899 adding clustering of app servers

* PLT-2899 base framework

* PLT-2899 HA backend

* PLT-2899 Fixing config file

* PLT-2899 adding config syncing

* PLT-2899 set System console to readonly when clustering enabled.

* PLT-2899 Fixing publish API

* PLT-2899 fixing strings
  • Loading branch information
coreyhulen authored and hmhealey committed Aug 4, 2016
1 parent 0f0732d commit e177ef2
Show file tree
Hide file tree
Showing 13 changed files with 521 additions and 2 deletions.
16 changes: 16 additions & 0 deletions client/client.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import request from 'superagent';

const HEADER_X_VERSION_ID = 'x-version-id';
const HEADER_X_CLUSTER_ID = 'x-cluster-id';
const HEADER_TOKEN = 'token';
const HEADER_BEARER = 'BEARER';
const HEADER_AUTH = 'Authorization';
Expand All @@ -12,6 +13,7 @@ export default class Client {
constructor() {
this.teamId = '';
this.serverVersion = '';
this.clusterId = '';
this.logToConsole = false;
this.useToken = false;
this.token = '';
Expand Down Expand Up @@ -152,6 +154,11 @@ export default class Client {
if (res.header[HEADER_X_VERSION_ID]) {
this.serverVersion = res.header[HEADER_X_VERSION_ID];
}

this.clusterId = res.header[HEADER_X_CLUSTER_ID];
if (res.header[HEADER_X_CLUSTER_ID]) {
this.clusterId = res.header[HEADER_X_CLUSTER_ID];
}
}

if (err) {
Expand Down Expand Up @@ -295,6 +302,15 @@ export default class Client {
end(this.handleResponse.bind(this, 'getLogs', success, error));
}

getClusterStatus(success, error) {
return request.
get(`${this.getAdminRoute()}/cluster_status`).
set(this.defaultHeaders).
type('application/json').
accept('application/json').
end(this.handleResponse.bind(this, 'getClusterStatus', success, error));
}

getServerAudits(success, error) {
return request.
get(`${this.getAdminRoute()}/audits`).
Expand Down
16 changes: 16 additions & 0 deletions components/admin_console/admin_sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export default class AdminSidebar extends React.Component {
let oauthSettings = null;
let ldapSettings = null;
let samlSettings = null;
let clusterSettings = null;
let complianceSettings = null;

let license = null;
Expand Down Expand Up @@ -213,6 +214,20 @@ export default class AdminSidebar extends React.Component {
);
}

if (global.window.mm_license.Cluster === 'true') {
clusterSettings = (
<AdminSidebarSection
name='cluster'
title={
<FormattedMessage
id='admin.sidebar.cluster'
defaultMessage='High Availability'
/>
}
/>
);
}

if (global.window.mm_license.SAML === 'true') {
samlSettings = (
<AdminSidebarSection
Expand Down Expand Up @@ -656,6 +671,7 @@ export default class AdminSidebar extends React.Component {
/>
}
/>
{clusterSettings}
</AdminSidebarSection>
</AdminSidebarCategory>
{this.renderTeams()}
Expand Down
188 changes: 188 additions & 0 deletions components/admin_console/cluster_settings.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import React from 'react';

import AdminSettings from './admin_settings.jsx';
import BooleanSetting from './boolean_setting.jsx';
import TextSetting from './text_setting.jsx';

import {FormattedMessage, FormattedHTMLMessage} from 'react-intl';
import SettingsGroup from './settings_group.jsx';
import ClusterTableContainer from './cluster_table_container.jsx';

import AdminStore from 'stores/admin_store.jsx';
import * as Utils from 'utils/utils.jsx';

export default class ClusterSettings extends AdminSettings {
constructor(props) {
super(props);

this.getConfigFromState = this.getConfigFromState.bind(this);
this.renderSettings = this.renderSettings.bind(this);
}

getConfigFromState(config) {
config.ClusterSettings.Enable = this.state.enable;
config.ClusterSettings.InterNodeListenAddress = this.state.interNodeListenAddress;

config.ClusterSettings.InterNodeUrls = this.state.interNodeUrls.split(',');
config.ClusterSettings.InterNodeUrls = config.ClusterSettings.InterNodeUrls.map((url) => {
return url.trim();
});

if (config.ClusterSettings.InterNodeUrls.length === 1 && config.ClusterSettings.InterNodeUrls[0] === '') {
config.ClusterSettings.InterNodeUrls = [];
}

return config;
}

getStateFromConfig(config) {
const settings = config.ClusterSettings;

return {
enable: settings.Enable,
interNodeUrls: settings.InterNodeUrls.join(', '),
interNodeListenAddress: settings.InterNodeListenAddress,
showWarning: false
};
}

renderTitle() {
return (
<h3>
<FormattedMessage
id='admin.advance.cluster'
defaultMessage='High Availability'
/>
</h3>
);
}

overrideHandleChange = (id, value) => {
this.setState({
showWarning: true
});

this.handleChange(id, value);
}

renderSettings() {
const licenseEnabled = global.window.mm_license.IsLicensed === 'true' && global.window.mm_license.Cluster === 'true';
if (!licenseEnabled) {
return null;
}

var configLoadedFromCluster = null;

if (AdminStore.getClusterId()) {
configLoadedFromCluster = (
<div
style={{marginBottom: '10px'}}
className='alert alert-warning'
>
<i className='fa fa-warning'></i>
<FormattedHTMLMessage
id='admin.cluster.loadedFrom'
defaultMessage='This configuration file was loaded from Node ID {clusterId}. Please see the Troubleshooting Guide in our <a href="http:https://docs.mattermost.com/deployment/cluster.html" target="_blank">documentation</a> if you are accessing the System Console through a load balancer and experiencing issues.'
values={{
clusterId: AdminStore.getClusterId()
}}
/>
</div>
);
}

var warning = null;
if (this.state.showWarning) {
warning = (
<div
style={{marginBottom: '10px'}}
className='alert alert-warning'
>
<i className='fa fa-warning'></i>
<FormattedMessage
id='admin.cluster.should_not_change'
defaultMessage='WARNING: These settings may not sync with the other servers in the cluster. High Availability inter-node communication will not start until you modify the config.json to be identical on all servers and restart Mattermost. Please see the <a href="http:https://docs.mattermost.com/deployment/cluster.html" target="_blank">documentation</a> on how to add or remove a server from the cluster. If you are accessing the System Console through a load balancer and experiencing issues, please see the Troubleshooting Guide in our <a href="http:https://docs.mattermost.com/deployment/cluster.html" target="_blank">documentation</a>.'
/>
</div>
);
}

var clusterTableContainer = null;
if (this.state.enable) {
clusterTableContainer = (<ClusterTableContainer/>);
}

return (
<SettingsGroup>
{configLoadedFromCluster}
{clusterTableContainer}
<p>
<FormattedMessage
id='admin.cluster.noteDescription'
defaultMessage='Changing properties in this section will require a server restart before taking effect. When High Availability mode is enabled, the System Console is set to read-only and can only be changed from the configuration file.'
/>
</p>
{warning}
<BooleanSetting
id='enable'
label={
<FormattedMessage
id='admin.cluster.enableTitle'
defaultMessage='Enable High Availability Mode:'
/>
}
helpText={
<FormattedHTMLMessage
id='admin.cluster.enableDescription'
defaultMessage='When true, Mattermost will run in High Availability mode. Please see <a href="http:https://docs.mattermost.com/deployment/cluster.html" target="_blank">documentation</a> to learn more about configuring High Availability for Mattermost.'
/>
}
value={this.state.enable}
onChange={this.overrideHandleChange}
disabled={true}
/>
<TextSetting
id='interNodeListenAddress'
label={
<FormattedMessage
id='admin.cluster.interNodeListenAddressTitle'
defaultMessage='Inter-Node Listen Address:'
/>
}
placeholder={Utils.localizeMessage('admin.cluster.interNodeListenAddressEx', 'Ex ":8075"')}
helpText={
<FormattedMessage
id='admin.cluster.interNodeListenAddressDesc'
defaultMessage='The address the server will listen on for communicating with other servers.'
/>
}
value={this.state.interNodeListenAddress}
onChange={this.overrideHandleChange}
disabled={true}
/>
<TextSetting
id='interNodeUrls'
label={
<FormattedMessage
id='admin.cluster.interNodeUrlsTitle'
defaultMessage='Inter-Node URLs:'
/>
}
placeholder={Utils.localizeMessage('admin.cluster.interNodeUrlsEx', 'Ex "http:https://10.10.10.30, http:https://10.10.10.31"')}
helpText={
<FormattedMessage
id='admin.cluster.interNodeUrlsDesc'
defaultMessage='The internal/private URLs of all the Mattermost servers separated by commas.'
/>
}
value={this.state.interNodeUrls}
onChange={this.overrideHandleChange}
disabled={true}
/>
</SettingsGroup>
);
}
}
Loading

0 comments on commit e177ef2

Please sign in to comment.