-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISPN-14230 Download server report from cluster membership list
* Table changed to TableComposable * Labels exported
- Loading branch information
Showing
5 changed files
with
206 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as DownloadServerReport from '@app/services/clusterHook'; | ||
|
||
jest.mock('@app/services/clusterHook'); | ||
const mockedClusterHook = DownloadServerReport as jest.Mocked<typeof DownloadServerReport>; | ||
|
||
let onDownloadReport; | ||
|
||
beforeEach(() => { | ||
onDownloadReport = 0; | ||
mockedClusterHook.useDownloadServerReport.mockClear(); | ||
}); | ||
|
||
mockedClusterHook.useDownloadServerReport.mockImplementation(() => { | ||
return { | ||
downloadServerReport: () => onDownloadReport++ | ||
}; | ||
}); | ||
|
||
describe('downloadReport', () => { | ||
test('To download server report and check download calls', () => { | ||
const { downloadServerReport } = DownloadServerReport.useDownloadServerReport(); | ||
downloadServerReport('node1'); | ||
expect(onDownloadReport).toBe(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { ConsoleServices } from '@services/ConsoleServices'; | ||
import { useApiAlert } from '@app/utils/useApiAlert'; | ||
|
||
export function useFetchClusterMembers() { | ||
const [cacheManager, setCacheManager] = useState<CacheManager>(); | ||
const [clusterMembers, setClusterMembers] = useState<ClusterMember[]>([]); | ||
const [error, setError] = useState(''); | ||
const [loading, setLoading] = useState(true); | ||
|
||
useEffect(() => { | ||
if (loading) { | ||
ConsoleServices.dataContainer() | ||
.getDefaultCacheManager() | ||
.then((eitherDefaultCm) => { | ||
if (eitherDefaultCm.isRight()) { | ||
setCacheManager(eitherDefaultCm.value); | ||
setClusterMembers(eitherDefaultCm.value.cluster_members); | ||
} else { | ||
setError(eitherDefaultCm.value.message); | ||
} | ||
}) | ||
.finally(() => setLoading(false)); | ||
} | ||
}, [loading]); | ||
|
||
const reload = () => { | ||
setLoading(true); | ||
}; | ||
|
||
return { | ||
clusterMembers, | ||
cacheManager, | ||
loading, | ||
error, | ||
reload | ||
}; | ||
} | ||
|
||
export function useDownloadServerReport() { | ||
const { addAlert } = useApiAlert(); | ||
const [downloading, setDownloading] = useState(false); | ||
|
||
const downloadServerReport = (nodeName) => { | ||
setDownloading(true); | ||
ConsoleServices.server() | ||
.downloadReport(nodeName) | ||
.then((response) => { | ||
if (response.isRight()) { | ||
const blob = new Blob([response.value], { type: 'application/gzip' }); | ||
const url = URL.createObjectURL(blob); | ||
const link = document.createElement('a'); | ||
link.href = url; | ||
link.setAttribute('download', nodeName + '-report.tar.gz'); | ||
document.body.appendChild(link); | ||
link.click(); | ||
} else { | ||
addAlert(response.value); | ||
} | ||
}) | ||
.finally(() => setDownloading(false)); | ||
}; | ||
return { | ||
downloadServerReport, | ||
downloading | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters