import { ml } from './ml_api_service' ; import { MlServerDefaults , MlServerLimits } from '../../../common/types/ml_server_info' ; export interface CloudInfo { cloudId : string | null ; isCloud : boolean ; deploymentId : string | null ; } let defaults = { anomaly_detectors : { } , datafeeds : { } , } ; let limits = { } ; const cloudInfo = { cloudId : null , isCloud : false , deploymentId : null , } ; export async function loadMlServerInfo ( ) { try { const resp = await ml . mlInfo ( ) ; defaults = resp . defaults ; limits = resp . limits ; cloudInfo . cloudId = resp . cloudId || null ; cloudInfo . isCloud = resp . cloudId !== undefined ; cloudInfo . deploymentId = ! resp . cloudId ? null : extractDeploymentId ( resp . cloudId ) ; return { defaults , limits , cloudId : cloudInfo } ; } catch ( error ) { return { defaults , limits , cloudId : cloudInfo } ; } } export function getNewJobDefaults ( ) { return defaults ; } export function getNewJobLimits ( ) { return limits ; } export function getCloudId ( ) { return cloudInfo . cloudId ; } export function isCloud ( ) { return cloudInfo . isCloud ; } export function getCloudDeploymentId ( ) { return cloudInfo . deploymentId ; } export function extractDeploymentId ( cloudId ) { const tempCloudId = cloudId . replace ( /^(.+)?:/ , '' ) ; try { const matches = atob ( tempCloudId ) . match ( /^.+\$(.+)(?=\$)/ ) ; return matches !== null && matches . length === 2 ? matches [ 1 ] : null ; } catch ( error ) { return null ; } }