import { ml } from '../services/ml_api_service' ; import { MlNodeCount } from '../../../common/types/ml_server_info' ; let mlNodeCount = 0 ; let lazyMlNodeCount = 0 ; let userHasPermissionToViewMlNodeCount = false ; export async function checkMlNodesAvailable ( redirectToJobsManagementPage ) { try { const { count , lazyNodeCount } = await getMlNodeCount ( ) ; if ( count > 0 || lazyNodeCount > 0 ) { Promise . resolve ( ) ; } else { throw Error ( 'Cannot load count of ML nodes' ) ; } } catch ( error ) { console . error ( error ) ; await redirectToJobsManagementPage ( ) ; Promise . reject ( ) ; } } export async function getMlNodeCount ( ) { try { const nodes = await ml . mlNodeCount ( ) ; mlNodeCount = nodes . count ; lazyMlNodeCount = nodes . lazyNodeCount ; userHasPermissionToViewMlNodeCount = true ; return nodes ; } catch ( error ) { mlNodeCount = 0 ; if ( error . statusCode === 403 ) { userHasPermissionToViewMlNodeCount = false ; } return { count : 0 , lazyNodeCount : 0 } ; } } export function mlNodesAvailable ( ) { return mlNodeCount !== 0 || lazyMlNodeCount !== 0 ; } export function currentMlNodesAvailable ( ) { return mlNodeCount !== 0 ; } export function lazyMlNodesAvailable ( ) { return lazyMlNodeCount !== 0 ; } export function permissionToViewMlNodeCount ( ) { return userHasPermissionToViewMlNodeCount ; }