clusters.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { ClustersApi, Configuration, Cluster } from 'generated-sources';
  2. import { PromiseThunkResult, ClusterName } from 'redux/interfaces';
  3. import { BASE_PARAMS } from 'lib/constants';
  4. import * as actions from 'redux/actions/actions';
  5. const apiClientConf = new Configuration(BASE_PARAMS);
  6. export const clustersApiClient = new ClustersApi(apiClientConf);
  7. export const fetchClustersList = (): PromiseThunkResult => async (dispatch) => {
  8. dispatch(actions.fetchClusterListAction.request());
  9. try {
  10. const clusters: Cluster[] = await clustersApiClient.getClusters();
  11. dispatch(actions.fetchClusterListAction.success(clusters));
  12. } catch (e) {
  13. dispatch(actions.fetchClusterListAction.failure());
  14. }
  15. };
  16. export const fetchClusterStats =
  17. (clusterName: ClusterName): PromiseThunkResult =>
  18. async (dispatch) => {
  19. dispatch(actions.fetchClusterStatsAction.request());
  20. try {
  21. const payload = await clustersApiClient.getClusterStats({ clusterName });
  22. dispatch(actions.fetchClusterStatsAction.success(payload));
  23. } catch (e) {
  24. dispatch(actions.fetchClusterStatsAction.failure());
  25. }
  26. };
  27. export const fetchClusterMetrics =
  28. (clusterName: ClusterName): PromiseThunkResult =>
  29. async (dispatch) => {
  30. dispatch(actions.fetchClusterMetricsAction.request());
  31. try {
  32. const payload = await clustersApiClient.getClusterMetrics({
  33. clusterName,
  34. });
  35. dispatch(actions.fetchClusterMetricsAction.success(payload));
  36. } catch (e) {
  37. dispatch(actions.fetchClusterMetricsAction.failure());
  38. }
  39. };