import { Observable , merge , of } from 'rxjs' ; import { map } from 'rxjs/operators' ; import { ServiceStatus , ServiceStatusLevels } from '../status' ; import { OpenSearchStatusMeta } from './types' ; import { NodesVersionCompatibility } from './version_check/ensure_opensearch_version' ; export const calculateStatus$ = ( opensearchNodesCompatibility$ ) : Observable < ServiceStatus < OpenSearchStatusMeta > > => merge ( of ( { level : ServiceStatusLevels . unavailable , summary : `Waiting for OpenSearch` , meta : { warningNodes : [ ] , incompatibleNodes : [ ] , } , } ) , opensearchNodesCompatibility$ . pipe ( map ( ( { isCompatible , message , incompatibleNodes , warningNodes , } ) : ServiceStatus < OpenSearchStatusMeta > => { if ( ! isCompatible ) { return { level : ServiceStatusLevels . critical , summary : message ?? `Some OpenSearch nodes are not compatible with this version of OpenSearch Dashboards` , meta : { warningNodes , incompatibleNodes } , } ; } else if ( warningNodes . length > 0 ) { return { level : ServiceStatusLevels . available , summary : message ?? `Some OpenSearch nodes are running different versions than this version of OpenSearch Dashboards` , meta : { warningNodes , incompatibleNodes } , } ; } return { level : ServiceStatusLevels . available , summary : `OpenSearch is available` , meta : { warningNodes : [ ] , incompatibleNodes : [ ] , } , } ; } ) ) ) ;