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

Refactor try catch in Management > Status #3434

Merged
merged 11 commits into from
Jul 16, 2021
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Added try catch strategy with ErrorOrchestrator service on FIM & SCA sections [#3417](https://github.com/wazuh/wazuh-kibana-app/pull/3417)
- Added try-catch strategy in Configuration section [#3451](https://github.com/wazuh/wazuh-kibana-app/pull/3451)
- Added try catch strategy with ErrorOrchestrator service on Components > Overview [#3442](https://github.com/wazuh/wazuh-kibana-app/pull/3442)
- Added try catch strategy with ErrorOrchestrator service on Management > Status [#3434](https://github.com/wazuh/wazuh-kibana-app/pull/3434)

### Changed

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Status component renders correctly to match the snapshot 1`] = `
<WzStatus>
<WzReduxProvider>
<Provider
store={
Object {
"dispatch": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
Symbol(observable): [Function],
}
}
>
<Component>
<Component>
<div
className="withUserLogged"
>
<img
alt=""
className="withUserLogged-logo"
src="/plugins/wazuh/assets/icon_blue.svg"
/>
<EuiSpacer
size="s"
>
<div
className="euiSpacer euiSpacer--s"
/>
</EuiSpacer>
<EuiText
className="subdued-color"
>
<div
className="euiText euiText--medium subdued-color"
>
Loading ...
</div>
</EuiText>
<EuiSpacer
size="s"
>
<div
className="euiSpacer euiSpacer--s"
/>
</EuiSpacer>
<EuiProgress
className="withUserLogged-loader"
color="primary"
size="xs"
>
<div
className="euiProgress euiProgress--indeterminate euiProgress--xs euiProgress--primary withUserLogged-loader"
/>
</EuiProgress>
</div>
</Component>
</Component>
</Provider>
</WzReduxProvider>
</WzStatus>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ import StatusHandler from './utils/status-handler';
import { getToasts } from '../../../../../kibana-services';
import { WzButtonPermissions } from '../../../../../components/common/permissions/button';

import { UI_ERROR_SEVERITIES } from '../../../../../react-services/error-orchestrator/types';
import { UI_LOGGER_LEVELS } from '../../../../../../common/constants';
import { getErrorOrchestrator } from '../../../../../react-services/common-services';

class WzStatusActionButtons extends Component {
_isMounted = false;

Expand Down Expand Up @@ -73,7 +77,17 @@ class WzStatusActionButtons extends Component {
);
} catch (error) {
this.setState({ isRestarting: false });
this.showToast('danger', `Error restarting cluster: ${error.message || error}`, 3000);
const options = {
context: `${WzStatusActionButtons.name}.restartCluster`,
level: UI_LOGGER_LEVELS.ERROR,
severity: UI_ERROR_SEVERITIES.BUSINESS,
error: {
error: error,
message: error.message || error,
title: `${error.name}: Error restarting cluster`,
},
};
getErrorOrchestrator().handleError(options);
}
}

Expand All @@ -88,7 +102,17 @@ class WzStatusActionButtons extends Component {
this.showToast('success', 'Restarting manager.', 3000);
} catch (error) {
this.setState({ isRestarting: false });
this.showToast('danger', `Error restarting manager: ${error.message || error}`, 3000);
const options = {
context: `${WzStatusActionButtons.name}.restartManager`,
level: UI_LOGGER_LEVELS.ERROR,
severity: UI_ERROR_SEVERITIES.BUSINESS,
error: {
error: error,
message: error.message || error,
title: `${error.name}: Error restarting manager`,
},
};
getErrorOrchestrator().handleError(options);
}
}

Expand Down Expand Up @@ -136,9 +160,18 @@ class WzStatusActionButtons extends Component {
this.props.updateLoadingStatus(false);
} catch (error) {
this.props.updateLoadingStatus(false);
this.showToast('danger', `Node ${node} is down`, 3000);
const options = {
context: `${WzStatusActionButtons.name}.changeNode`,
level: UI_LOGGER_LEVELS.ERROR,
severity: UI_ERROR_SEVERITIES.BUSINESS,
error: {
error: error,
message: error.message || error,
title: `${error.name}: Node ${node} is down`
},
};
getErrorOrchestrator().handleError(options);
}

return;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Wazuh app - React test for Status component.
*
* Copyright (C) 2015-2021 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*
*/

import React from 'react';
import { mount } from 'enzyme';
import WzStatus from './status-main';

jest.mock('../../../../../kibana-services', () => ({
getAngularModule: jest.fn(),
getHttp: () => ({
basePath: {
prepend: (str) => str,
},
}),
}));

describe('Status component', () => {
it('renders correctly to match the snapshot', () => {
const wrapper = mount(<WzStatus />);
expect(wrapper).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ import { getToasts } from '../../../../../kibana-services';

import { withUserAuthorizationPrompt, withGlobalBreadcrumb } from '../../../../../components/common/hocs';
import { compose } from 'redux';
import { ToastNotifications } from '../../../../../react-services/toast-notifications';

import { UI_ERROR_SEVERITIES } from '../../../../../react-services/error-orchestrator/types';
import { UI_LOGGER_LEVELS } from '../../../../../../common/constants';
import { getErrorOrchestrator } from '../../../../../react-services/common-services';

export class WzStatusOverview extends Component {
_isMounted = false;
Expand Down Expand Up @@ -159,7 +162,17 @@ export class WzStatusOverview extends Component {

this.props.updateAgentInfo(lastAgent);
} catch (error) {
getToasts().error('management:status:overview.fetchData', error);
const options = {
context: `${WzStatusOverview.name}.fetchData`,
level: UI_LOGGER_LEVELS.ERROR,
severity: UI_ERROR_SEVERITIES.BUSINESS,
error: {
error: error,
message: error.message || error,
title: `${error.name}: management:status:overview`
},
};
getErrorOrchestrator().handleError(options);
}
this.props.updateLoadingStatus(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class StatusHandler {
const result = await WzRequest.apiReq('GET', `/agents/summary/status`, {});
return result;
} catch (error) {
return Promise.reject(error);
throw error;
}
}

Expand All @@ -33,7 +33,7 @@ export default class StatusHandler {
const result = await WzRequest.apiReq('GET', `/cluster/status`, {});
return result;
} catch (error) {
return Promise.reject(error);
throw error;
}
}

Expand All @@ -45,7 +45,7 @@ export default class StatusHandler {
const result = await WzRequest.apiReq('GET', `/cluster/nodes`, {});
return result;
} catch (error) {
return Promise.reject(error);
throw error;
}
}

Expand All @@ -61,7 +61,7 @@ export default class StatusHandler {
);
return result;
} catch (error) {
return Promise.reject(error);
throw error;
}
}

Expand All @@ -77,7 +77,7 @@ export default class StatusHandler {
);
return result;
} catch (error) {
return Promise.reject(error);
throw error;
}
}

Expand All @@ -93,7 +93,7 @@ export default class StatusHandler {
);
return result;
} catch (error) {
return Promise.reject(error);
throw error;
}
}

Expand All @@ -105,7 +105,7 @@ export default class StatusHandler {
const result = await WzRequest.apiReq('GET', `/manager/info`, {});
return result;
} catch (error) {
return Promise.reject(error);
throw error;
}
}

Expand All @@ -117,7 +117,7 @@ export default class StatusHandler {
const result = await WzRequest.apiReq('GET', `/manager/status`, {});
return result;
} catch (error) {
return Promise.reject(error);
throw error;
}
}

Expand All @@ -135,7 +135,7 @@ export default class StatusHandler {
});
return result;
} catch (error) {
return Promise.reject(error);
throw error;
}
}

Expand All @@ -159,7 +159,7 @@ export default class StatusHandler {
await WzRequest.apiReq('PUT', `/cluster/restart`, { delay: 15000 });
return { data: { data: 'Restarting cluster' } };
} catch (error) {
return Promise.reject(error);
throw error;
}
}

Expand All @@ -184,7 +184,7 @@ export default class StatusHandler {
const result = await WzRequest.apiReq('PUT', `/manager/restart`, {});
return result;
} catch (error) {
return Promise.reject(error);
throw error;
}
}
}