Search in sources :

Example 1 with ExecutionContext

use of com.microsoft.dhalion.policy.PoliciesExecutor.ExecutionContext in project heron by twitter.

the class ScaleUpResolverTest method testScaleUpFactorComputation.

@Test
public void testScaleUpFactorComputation() {
    Instant now = Instant.now();
    Collection<Measurement> result = new ArrayList<>();
    ExecutionContext context = Mockito.mock(ExecutionContext.class);
    when(context.checkpoint()).thenReturn(now);
    when(context.previousCheckpoint()).thenReturn(now);
    ScaleUpResolver resolver = new ScaleUpResolver(null, null, null, eventManager, null);
    resolver.initialize(context);
    result.add(new Measurement("bolt", "i1", METRIC_BACK_PRESSURE.text(), now, 500));
    result.add(new Measurement("bolt", "i2", METRIC_BACK_PRESSURE.text(), now, 0));
    when(context.measurements()).thenReturn(MeasurementsTable.of(result));
    int factor = resolver.computeScaleUpFactor("bolt");
    assertEquals(4, factor);
    result.clear();
    result.add(new Measurement("bolt", "i1", METRIC_BACK_PRESSURE.text(), now, 750));
    result.add(new Measurement("bolt", "i2", METRIC_BACK_PRESSURE.text(), now, 0));
    when(context.measurements()).thenReturn(MeasurementsTable.of(result));
    factor = resolver.computeScaleUpFactor("bolt");
    assertEquals(8, factor);
    result.clear();
    result.add(new Measurement("bolt", "i1", METRIC_BACK_PRESSURE.text(), now, 400));
    result.add(new Measurement("bolt", "i2", METRIC_BACK_PRESSURE.text(), now, 100));
    result.add(new Measurement("bolt", "i3", METRIC_BACK_PRESSURE.text(), now, 0));
    when(context.measurements()).thenReturn(MeasurementsTable.of(result));
    factor = resolver.computeScaleUpFactor("bolt");
    assertEquals(6, factor);
}
Also used : Measurement(com.microsoft.dhalion.core.Measurement) ExecutionContext(com.microsoft.dhalion.policy.PoliciesExecutor.ExecutionContext) Instant(java.time.Instant) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with ExecutionContext

use of com.microsoft.dhalion.policy.PoliciesExecutor.ExecutionContext in project heron by twitter.

the class BackPressureSensorTest method providesBackPressureMetricForBolts.

@Test
public void providesBackPressureMetricForBolts() throws IOException {
    PhysicalPlanProvider topologyProvider = mock(PhysicalPlanProvider.class);
    when(topologyProvider.getBoltNames()).thenReturn(Arrays.asList(new String[] { "bolt-1", "bolt-2" }));
    String[] boltIds = new String[] { "container_1_bolt-1_1", "container_2_bolt-2_22", "container_1_bolt-2_333" };
    PackingPlanProvider packingPlanProvider = mock(PackingPlanProvider.class);
    when(packingPlanProvider.getBoltInstanceNames("bolt-1")).thenReturn(new String[] { boltIds[0] });
    when(packingPlanProvider.getBoltInstanceNames("bolt-2")).thenReturn(new String[] { boltIds[1], boltIds[2] });
    MetricsProvider metricsProvider = mock(MetricsProvider.class);
    for (String boltId : boltIds) {
        String metric = METRIC_BACK_PRESSURE + boltId;
        // the back pressure sensor will return average bp per second, so multiply by duration
        registerStMgrInstanceMetricResponse(metricsProvider, metric, boltId.length() * DEFAULT_METRIC_DURATION.getSeconds());
    }
    HealthManagerMetrics publishingMetrics = mock(HealthManagerMetrics.class);
    BackPressureSensor backPressureSensor = new BackPressureSensor(packingPlanProvider, topologyProvider, null, metricsProvider, publishingMetrics);
    ExecutionContext context = mock(ExecutionContext.class);
    when(context.checkpoint()).thenReturn(Instant.now());
    backPressureSensor.initialize(context);
    Collection<Measurement> componentMetrics = backPressureSensor.fetch();
    assertEquals(3, componentMetrics.size());
    MeasurementsTable table = MeasurementsTable.of(componentMetrics);
    assertEquals(1, table.component("bolt-1").size());
    assertEquals(boltIds[0].length(), table.component("bolt-1").instance(boltIds[0]).type(METRIC_BACK_PRESSURE.text()).sum(), 0.01);
    assertEquals(2, table.component("bolt-2").size());
    assertEquals(boltIds[1].length(), table.component("bolt-2").instance(boltIds[1]).type(METRIC_BACK_PRESSURE.text()).sum(), 0.01);
    assertEquals(boltIds[2].length(), table.component("bolt-2").instance(boltIds[2]).type(METRIC_BACK_PRESSURE.text()).sum(), 0.01);
}
Also used : Measurement(com.microsoft.dhalion.core.Measurement) ExecutionContext(com.microsoft.dhalion.policy.PoliciesExecutor.ExecutionContext) MeasurementsTable(com.microsoft.dhalion.core.MeasurementsTable) PhysicalPlanProvider(org.apache.heron.healthmgr.common.PhysicalPlanProvider) HealthManagerMetrics(org.apache.heron.healthmgr.HealthManagerMetrics) PackingPlanProvider(org.apache.heron.healthmgr.common.PackingPlanProvider) MetricsProvider(com.microsoft.dhalion.api.MetricsProvider) Test(org.junit.Test)

Example 3 with ExecutionContext

use of com.microsoft.dhalion.policy.PoliciesExecutor.ExecutionContext in project heron by twitter.

the class ScaleUpResolverTest method testResolve.

@Test
public void testResolve() {
    TopologyAPI.Topology topology = createTestTopology();
    Config config = createConfig(topology);
    PackingPlan currentPlan = createPacking(topology, config);
    PackingPlanProvider packingPlanProvider = mock(PackingPlanProvider.class);
    when(packingPlanProvider.get()).thenReturn(currentPlan);
    ISchedulerClient scheduler = mock(ISchedulerClient.class);
    when(scheduler.updateTopology(any(UpdateTopologyRequest.class))).thenReturn(true);
    Instant now = Instant.now();
    Collections.singletonList(new Measurement("bolt", "i1", METRIC_BACK_PRESSURE.text(), now, 123));
    List<String> assignments = Collections.singletonList("bolt");
    Diagnosis diagnoses = new Diagnosis(DIAGNOSIS_UNDER_PROVISIONING.text(), now, assignments, null);
    List<Diagnosis> diagnosis = Collections.singletonList(diagnoses);
    ExecutionContext context = mock(ExecutionContext.class);
    when(context.checkpoint()).thenReturn(now);
    ScaleUpResolver resolver = new ScaleUpResolver(null, packingPlanProvider, scheduler, eventManager, null);
    resolver.initialize(context);
    ScaleUpResolver spyResolver = spy(resolver);
    doReturn(2).when(spyResolver).computeScaleUpFactor("bolt");
    doReturn(currentPlan).when(spyResolver).buildNewPackingPlan(any(HashMap.class), eq(currentPlan));
    Collection<Action> result = spyResolver.resolve(diagnosis);
    verify(scheduler, times(1)).updateTopology(any(UpdateTopologyRequest.class));
    assertEquals(1, result.size());
}
Also used : Measurement(com.microsoft.dhalion.core.Measurement) Action(com.microsoft.dhalion.core.Action) HashMap(java.util.HashMap) Config(org.apache.heron.spi.common.Config) PackingPlan(org.apache.heron.spi.packing.PackingPlan) Instant(java.time.Instant) PackingPlanProvider(org.apache.heron.healthmgr.common.PackingPlanProvider) TopologyAPI(org.apache.heron.api.generated.TopologyAPI) UpdateTopologyRequest(org.apache.heron.proto.scheduler.Scheduler.UpdateTopologyRequest) ExecutionContext(com.microsoft.dhalion.policy.PoliciesExecutor.ExecutionContext) ISchedulerClient(org.apache.heron.scheduler.client.ISchedulerClient) Diagnosis(com.microsoft.dhalion.core.Diagnosis) Test(org.junit.Test)

Aggregations

Measurement (com.microsoft.dhalion.core.Measurement)3 ExecutionContext (com.microsoft.dhalion.policy.PoliciesExecutor.ExecutionContext)3 Test (org.junit.Test)3 Instant (java.time.Instant)2 PackingPlanProvider (org.apache.heron.healthmgr.common.PackingPlanProvider)2 MetricsProvider (com.microsoft.dhalion.api.MetricsProvider)1 Action (com.microsoft.dhalion.core.Action)1 Diagnosis (com.microsoft.dhalion.core.Diagnosis)1 MeasurementsTable (com.microsoft.dhalion.core.MeasurementsTable)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 TopologyAPI (org.apache.heron.api.generated.TopologyAPI)1 HealthManagerMetrics (org.apache.heron.healthmgr.HealthManagerMetrics)1 PhysicalPlanProvider (org.apache.heron.healthmgr.common.PhysicalPlanProvider)1 UpdateTopologyRequest (org.apache.heron.proto.scheduler.Scheduler.UpdateTopologyRequest)1 ISchedulerClient (org.apache.heron.scheduler.client.ISchedulerClient)1 Config (org.apache.heron.spi.common.Config)1 PackingPlan (org.apache.heron.spi.packing.PackingPlan)1