import { GetMetricConfig } from '../components/metric-config' ; import { CriterionState , Formstate } from '../modes/state-models' ; function getCriteriaModel ( definedCriteria ) { let criteriaArr = [ ] ; for ( let i = 0 ; i < definedCriteria . length ; i ++ ) { let newMetric = definedCriteria [ i ] ; if ( newMetric . name === '' ) { continue ; } else if ( newMetric . limitType === '' ) { criteriaArr . push ( { id : i , metric_id : newMetric . name , is_reward : newMetric . reward } ) ; } else { criteriaArr . push ( { id : i , metric_id : newMetric . name , is_reward : newMetric . reward , threshold : { type : newMetric . limitType , value : newMetric . limitValue } } ) ; } } return criteriaArr ; } function getCandModel ( namespace , candList ) { let candObjs = [ ] ; for ( let i = 0 ; i < candList . length ; i ++ ) { candObjs . push ( { id : `${ candList [ i ] }` , version_labels : { destination_workload_namespace : namespace , destination_workload : candList [ i ] } } ) ; } return candObjs ; } export default function getRequestModel ( time , formstate , args ) { return { start_time : time , service_name : formstate . service , metric_specs : { counter_metrics : formstate . countMetricsList , ratio_metrics : formstate . ratioMetricsList } , criteria : getCriteriaModel ( formstate . criteria ) , baseline : { id : `${ formstate . baseline }` , version_labels : { destination_workload_namespace : formstate . namespace , destination_workload : formstate . baseline } } , candidates : getCandModel ( formstate . namespace , formstate . candidates ) , traffic_control : { max_increment : 25 } , edgeServiceInformation : { edgeService : formstate . edgeService , hostGateways : formstate . hostGateways } } ; }