@Test( expected = IllegalStateException.class ) public void shouldNotEvaluateWhenThereIsNoAdaptation () { final PipelineMetrics pipelineMetrics1 = mock( PipelineMetrics.class ); when( pipelineMetrics1.getPipelineId() ).thenReturn( pipelineId0 ); context.isAdaptationSuccessful( singletonList( pipelineMetrics1 ), adaptationEvaluationPredicate ); }
boolean isAdaptationSuccessful ( final List<PipelineMetrics> metrics, final BiPredicate<PipelineMetrics, PipelineMetrics> adaptationEvaluationPredicate ) { checkArgument( metrics != null ); checkArgument( adaptationEvaluationPredicate != null ); metrics.stream().map( PipelineMetrics::getPipelineId ).forEach( this::checkPipelineId ); checkState( !adaptationActions.isEmpty(), "Cannot evaluate metrics: %s for Region %s has no adaptation action", metrics, getRegionId() ); final PipelineMetrics newInboundMetrics = metrics.get( 0 ); final PipelineMetrics bottleneckInboundMetrics = metricsByPipelineId.get( newInboundMetrics.getPipelineId() ); checkState( bottleneckInboundMetrics != null ); final boolean success = adaptationEvaluationPredicate.test( bottleneckInboundMetrics, newInboundMetrics ); if ( success ) { LOGGER.info( "Adaptations are beneficial for Region {} with new metrics: {} bottleneck metrics: {} and adaptation actions: {}", getRegionId(), newInboundMetrics, bottleneckInboundMetrics, adaptationActions ); } else { LOGGER.info( "Adaptations are not beneficial for Region {} with new metrics: {} bottleneck metrics: {} and adaptation actions: {}", getRegionId(), newInboundMetrics, bottleneckInboundMetrics, adaptationActions ); } return success; }
RegionAdaptationContext { boolean isAdaptationSuccessful ( final List<PipelineMetrics> metrics, final BiPredicate<PipelineMetrics, PipelineMetrics> adaptationEvaluationPredicate ) { checkArgument( metrics != null ); checkArgument( adaptationEvaluationPredicate != null ); metrics.stream().map( PipelineMetrics::getPipelineId ).forEach( this::checkPipelineId ); checkState( !adaptationActions.isEmpty(), "Cannot evaluate metrics: %s for Region %s has no adaptation action", metrics, getRegionId() ); final PipelineMetrics newInboundMetrics = metrics.get( 0 ); final PipelineMetrics bottleneckInboundMetrics = metricsByPipelineId.get( newInboundMetrics.getPipelineId() ); checkState( bottleneckInboundMetrics != null ); final boolean success = adaptationEvaluationPredicate.test( bottleneckInboundMetrics, newInboundMetrics ); if ( success ) { LOGGER.info( "Adaptations are beneficial for Region {} with new metrics: {} bottleneck metrics: {} and adaptation actions: {}", getRegionId(), newInboundMetrics, bottleneckInboundMetrics, adaptationActions ); } else { LOGGER.info( "Adaptations are not beneficial for Region {} with new metrics: {} bottleneck metrics: {} and adaptation actions: {}", getRegionId(), newInboundMetrics, bottleneckInboundMetrics, adaptationActions ); } return success; } }
RegionAdaptationContext { boolean isAdaptationSuccessful ( final List<PipelineMetrics> metrics, final BiPredicate<PipelineMetrics, PipelineMetrics> adaptationEvaluationPredicate ) { checkArgument( metrics != null ); checkArgument( adaptationEvaluationPredicate != null ); metrics.stream().map( PipelineMetrics::getPipelineId ).forEach( this::checkPipelineId ); checkState( !adaptationActions.isEmpty(), "Cannot evaluate metrics: %s for Region %s has no adaptation action", metrics, getRegionId() ); final PipelineMetrics newInboundMetrics = metrics.get( 0 ); final PipelineMetrics bottleneckInboundMetrics = metricsByPipelineId.get( newInboundMetrics.getPipelineId() ); checkState( bottleneckInboundMetrics != null ); final boolean success = adaptationEvaluationPredicate.test( bottleneckInboundMetrics, newInboundMetrics ); if ( success ) { LOGGER.info( "Adaptations are beneficial for Region {} with new metrics: {} bottleneck metrics: {} and adaptation actions: {}", getRegionId(), newInboundMetrics, bottleneckInboundMetrics, adaptationActions ); } else { LOGGER.info( "Adaptations are not beneficial for Region {} with new metrics: {} bottleneck metrics: {} and adaptation actions: {}", getRegionId(), newInboundMetrics, bottleneckInboundMetrics, adaptationActions ); } return success; } RegionAdaptationContext( final RegionExecPlan currentExecPlan ); }
RegionAdaptationContext { boolean isAdaptationSuccessful ( final List<PipelineMetrics> metrics, final BiPredicate<PipelineMetrics, PipelineMetrics> adaptationEvaluationPredicate ) { checkArgument( metrics != null ); checkArgument( adaptationEvaluationPredicate != null ); metrics.stream().map( PipelineMetrics::getPipelineId ).forEach( this::checkPipelineId ); checkState( !adaptationActions.isEmpty(), "Cannot evaluate metrics: %s for Region %s has no adaptation action", metrics, getRegionId() ); final PipelineMetrics newInboundMetrics = metrics.get( 0 ); final PipelineMetrics bottleneckInboundMetrics = metricsByPipelineId.get( newInboundMetrics.getPipelineId() ); checkState( bottleneckInboundMetrics != null ); final boolean success = adaptationEvaluationPredicate.test( bottleneckInboundMetrics, newInboundMetrics ); if ( success ) { LOGGER.info( "Adaptations are beneficial for Region {} with new metrics: {} bottleneck metrics: {} and adaptation actions: {}", getRegionId(), newInboundMetrics, bottleneckInboundMetrics, adaptationActions ); } else { LOGGER.info( "Adaptations are not beneficial for Region {} with new metrics: {} bottleneck metrics: {} and adaptation actions: {}", getRegionId(), newInboundMetrics, bottleneckInboundMetrics, adaptationActions ); } return success; } RegionAdaptationContext( final RegionExecPlan currentExecPlan ); int getRegionId(); RegionDef getRegionDef(); }
RegionAdaptationContext { boolean isAdaptationSuccessful ( final List<PipelineMetrics> metrics, final BiPredicate<PipelineMetrics, PipelineMetrics> adaptationEvaluationPredicate ) { checkArgument( metrics != null ); checkArgument( adaptationEvaluationPredicate != null ); metrics.stream().map( PipelineMetrics::getPipelineId ).forEach( this::checkPipelineId ); checkState( !adaptationActions.isEmpty(), "Cannot evaluate metrics: %s for Region %s has no adaptation action", metrics, getRegionId() ); final PipelineMetrics newInboundMetrics = metrics.get( 0 ); final PipelineMetrics bottleneckInboundMetrics = metricsByPipelineId.get( newInboundMetrics.getPipelineId() ); checkState( bottleneckInboundMetrics != null ); final boolean success = adaptationEvaluationPredicate.test( bottleneckInboundMetrics, newInboundMetrics ); if ( success ) { LOGGER.info( "Adaptations are beneficial for Region {} with new metrics: {} bottleneck metrics: {} and adaptation actions: {}", getRegionId(), newInboundMetrics, bottleneckInboundMetrics, adaptationActions ); } else { LOGGER.info( "Adaptations are not beneficial for Region {} with new metrics: {} bottleneck metrics: {} and adaptation actions: {}", getRegionId(), newInboundMetrics, bottleneckInboundMetrics, adaptationActions ); } return success; } RegionAdaptationContext( final RegionExecPlan currentExecPlan ); int getRegionId(); RegionDef getRegionDef();  }