Skip to content

Commit

Permalink
[UA] Show different interstital text when cluster is upgraded (#34762)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdover committed Apr 9, 2019
1 parent 6a72bcb commit 5e32992
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 15 deletions.
46 changes: 40 additions & 6 deletions x-pack/plugins/upgrade_assistant/public/components/tabs.tsx
Expand Up @@ -26,13 +26,19 @@ import { CheckupTab } from './tabs/checkup';
import { OverviewTab } from './tabs/overview';
import { LoadingState, TelemetryState, UpgradeAssistantTabProps } from './types';

enum ClusterUpgradeState {
needsUpgrade,
partiallyUpgraded,
upgraded,
}

interface TabsState {
loadingState: LoadingState;
loadingError?: Error;
checkupData?: UpgradeAssistantStatus;
selectedTabIndex: number;
telemetryState: TelemetryState;
upgradeableCluster: boolean;
clusterUpgradeState: ClusterUpgradeState;
}

export class UpgradeAssistantTabsUI extends React.Component<
Expand All @@ -44,7 +50,7 @@ export class UpgradeAssistantTabsUI extends React.Component<

this.state = {
loadingState: LoadingState.Loading,
upgradeableCluster: true,
clusterUpgradeState: ClusterUpgradeState.needsUpgrade,
selectedTabIndex: 0,
telemetryState: TelemetryState.Complete,
};
Expand All @@ -58,10 +64,10 @@ export class UpgradeAssistantTabsUI extends React.Component<
}

public render() {
const { selectedTabIndex, telemetryState, upgradeableCluster } = this.state;
const { selectedTabIndex, telemetryState, clusterUpgradeState } = this.state;
const tabs = this.tabs;

if (!upgradeableCluster) {
if (clusterUpgradeState === ClusterUpgradeState.partiallyUpgraded) {
return (
<EuiPageContent>
<EuiPageContentBody>
Expand All @@ -80,7 +86,33 @@ export class UpgradeAssistantTabsUI extends React.Component<
<FormattedMessage
id="xpack.upgradeAssistant.tabs.upgradingInterstitial.upgradingDescription"
defaultMessage="One or more Elasticsearch nodes have a newer version of
Elasticsearch than Kibana. Once all your nodes are upgraded, install the latest version of Kibana."
Elasticsearch than Kibana. Once all your nodes are upgraded, upgrade Kibana."
/>
</p>
}
/>
</EuiPageContentBody>
</EuiPageContent>
);
} else if (clusterUpgradeState === ClusterUpgradeState.upgraded) {
return (
<EuiPageContent>
<EuiPageContentBody>
<EuiEmptyPrompt
iconType="logoElasticsearch"
title={
<h2>
<FormattedMessage
id="xpack.upgradeAssistant.tabs.upgradingInterstitial.upgradeCompleteTitle"
defaultMessage="Your cluster has been upgraded"
/>
</h2>
}
body={
<p>
<FormattedMessage
id="xpack.upgradeAssistant.tabs.upgradingInterstitial.upgradeCompleteDescription"
defaultMessage="All Elasticsearch nodes have been upgraded. You may now upgrade Kibana."
/>
</p>
}
Expand Down Expand Up @@ -134,7 +166,9 @@ export class UpgradeAssistantTabsUI extends React.Component<
if (get(e, 'response.status') === 426) {
this.setState({
loadingState: LoadingState.Success,
upgradeableCluster: false,
clusterUpgradeState: get(e, 'response.data.attributes.allNodesUpgraded', false)
? ClusterUpgradeState.upgraded
: ClusterUpgradeState.partiallyUpgraded,
});
} else {
this.setState({ loadingState: LoadingState.Error, loadingError: e });
Expand Down
Expand Up @@ -71,24 +71,43 @@ describe('EsVersionPrecheck', () => {
);
});

it('throws a 426 message when nodes are not on same version', async () => {
it('throws a 426 message w/ allNodesUpgraded = false when nodes are not on same version', async () => {
const fakeCallWithRequest = jest.fn().mockResolvedValue({
nodes: {
node1: { version: CURRENT_VERSION.raw },
node2: { version: CURRENT_VERSION.inc('major').raw },
node2: { version: new SemVer(CURRENT_VERSION.raw).inc('major').raw },
},
});
const fakeGetCluster = jest.fn(() => ({ callWithRequest: fakeCallWithRequest }));
const fakeRequest = {
server: { plugins: { elasticsearch: { getCluster: fakeGetCluster } } },
} as any;

await expect(EsVersionPrecheck.method(fakeRequest, {} as any)).rejects.toHaveProperty(
'output.statusCode',
426
const result = EsVersionPrecheck.method(fakeRequest, {} as any);
await expect(result).rejects.toHaveProperty('output.statusCode', 426);
await expect(result).rejects.toHaveProperty(
'output.payload.attributes.allNodesUpgraded',
false
);
});

it('throws a 426 message w/ allNodesUpgraded = true when nodes are on next version', async () => {
const fakeCallWithRequest = jest.fn().mockResolvedValue({
nodes: {
node1: { version: new SemVer(CURRENT_VERSION.raw).inc('major').raw },
node2: { version: new SemVer(CURRENT_VERSION.raw).inc('major').raw },
},
});
const fakeGetCluster = jest.fn(() => ({ callWithRequest: fakeCallWithRequest }));
const fakeRequest = {
server: { plugins: { elasticsearch: { getCluster: fakeGetCluster } } },
} as any;

const result = EsVersionPrecheck.method(fakeRequest, {} as any);
await expect(result).rejects.toHaveProperty('output.statusCode', 426);
await expect(result).rejects.toHaveProperty('output.payload.attributes.allNodesUpgraded', true);
});

it('returns true when nodes are on same version', async () => {
const fakeCallWithRequest = jest.fn().mockResolvedValue({
nodes: {
Expand Down
14 changes: 10 additions & 4 deletions x-pack/plugins/upgrade_assistant/server/lib/es_version_precheck.ts
Expand Up @@ -31,15 +31,21 @@ export const getAllNodeVersions = async (callCluster: CallCluster) => {

export const verifyAllMatchKibanaVersion = (allNodeVersions: SemVer[]) => {
// Determine if all nodes in the cluster are running the same major version as Kibana.
const anyDifferentEsNodes = !!allNodeVersions.find(
const numDifferentVersion = allNodeVersions.filter(
esNodeVersion => esNodeVersion.major !== CURRENT_VERSION.major
);
).length;
const numSameVersion = allNodeVersions.filter(
esNodeVersion => esNodeVersion.major === CURRENT_VERSION.major
).length;

if (anyDifferentEsNodes) {
throw new Boom(`There are some nodes running a different version of Elasticsearch`, {
if (numDifferentVersion) {
const error = new Boom(`There are some nodes running a different version of Elasticsearch`, {
// 426 means "Upgrade Required" and is used when semver compatibility is not met.
statusCode: 426,
});

error.output.payload.attributes = { allNodesUpgraded: !numSameVersion };
throw error;
}
};

Expand Down

0 comments on commit 5e32992

Please sign in to comment.