import { DataTierRole , ListNodesRouteResponse , PhaseWithAllocation , } from '../../../../common/types' ; import { phaseToNodePreferenceMap } from '../../../../common/constants' ; /**
 * Given a phase and current cluster node roles, determine which nodes the phase
 * will allocate data to. For instance, for the warm phase, with warm
 * tier nodes, we would expect "data_warm".
 *
 * If no nodes can be identified for allocation (very special case) then
 * we return "none".
 */ export const getAvailableNodeRoleForPhase = ( phase , nodesByRoles ) : DataTierRole | undefined => { const preferredNodeRoles = phaseToNodePreferenceMap [ phase ] ; if ( nodesByRoles . data ?. length ) { return preferredNodeRoles [ 0 ] ; } return preferredNodeRoles . find ( ( role ) => Boolean ( nodesByRoles [ role ] ?. length ) ) ; } ;