Search in sources :

Example 1 with PhysicalPlanProvider

use of org.apache.heron.healthmgr.common.PhysicalPlanProvider in project heron by twitter.

the class ScaleUpResolverTest method createPhysicalPlanProvider.

private PhysicalPlanProvider createPhysicalPlanProvider(TopologyAPI.Topology topology) {
    PhysicalPlan pp = PhysicalPlan.newBuilder().setTopology(topology).build();
    PhysicalPlanProvider physicalPlanProvider = mock(PhysicalPlanProvider.class);
    when(physicalPlanProvider.get()).thenReturn(pp);
    return physicalPlanProvider;
}
Also used : PhysicalPlan(org.apache.heron.proto.system.PhysicalPlans.PhysicalPlan) PhysicalPlanProvider(org.apache.heron.healthmgr.common.PhysicalPlanProvider)

Example 2 with PhysicalPlanProvider

use of org.apache.heron.healthmgr.common.PhysicalPlanProvider in project heron by twitter.

the class BufferSizeSensorTest method providesBufferSizeMetricForBolts.

@Test
public void providesBufferSizeMetricForBolts() {
    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_WAIT_Q_SIZE + boltId + MetricName.METRIC_WAIT_Q_SIZE_SUFFIX;
        BackPressureSensorTest.registerStMgrInstanceMetricResponse(metricsProvider, metric, boltId.length());
    }
    BufferSizeSensor bufferSizeSensor = new BufferSizeSensor(null, packingPlanProvider, topologyProvider, metricsProvider);
    PoliciesExecutor.ExecutionContext context = mock(PoliciesExecutor.ExecutionContext.class);
    when(context.checkpoint()).thenReturn(Instant.now());
    bufferSizeSensor.initialize(context);
    Collection<Measurement> componentMetrics = bufferSizeSensor.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_WAIT_Q_SIZE.text()).sum(), 0.01);
    assertEquals(2, table.component("bolt-2").size());
    assertEquals(boltIds[1].length(), table.component("bolt-2").instance(boltIds[1]).type(METRIC_WAIT_Q_SIZE.text()).sum(), 0.01);
    assertEquals(boltIds[2].length(), table.component("bolt-2").instance(boltIds[2]).type(METRIC_WAIT_Q_SIZE.text()).sum(), 0.01);
}
Also used : Measurement(com.microsoft.dhalion.core.Measurement) MeasurementsTable(com.microsoft.dhalion.core.MeasurementsTable) PhysicalPlanProvider(org.apache.heron.healthmgr.common.PhysicalPlanProvider) PackingPlanProvider(org.apache.heron.healthmgr.common.PackingPlanProvider) PoliciesExecutor(com.microsoft.dhalion.policy.PoliciesExecutor) MetricsProvider(com.microsoft.dhalion.api.MetricsProvider) Test(org.junit.Test)

Example 3 with PhysicalPlanProvider

use of org.apache.heron.healthmgr.common.PhysicalPlanProvider 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 4 with PhysicalPlanProvider

use of org.apache.heron.healthmgr.common.PhysicalPlanProvider in project heron by twitter.

the class ExecuteCountSensorTest method providesBoltExecutionCountMetrics.

@Test
public void providesBoltExecutionCountMetrics() {
    Instant now = Instant.now();
    String metric = METRIC_EXE_COUNT.text();
    PhysicalPlanProvider topologyProvider = mock(PhysicalPlanProvider.class);
    when(topologyProvider.getBoltNames()).thenReturn(Arrays.asList(new String[] { "bolt-1", "bolt-2" }));
    MetricsProvider metricsProvider = mock(MetricsProvider.class);
    Collection<Measurement> result = new ArrayList<>();
    result.add(new Measurement("bolt-1", "container_1_bolt-1_1", metric, now, 123));
    result.add(new Measurement("bolt-1", "container_1_bolt-1_2", metric, now, 345));
    result.add(new Measurement("bolt-2", "container_1_bolt-2_3", metric, now, 321));
    result.add(new Measurement("bolt-2", "container_1_bolt-2_4", metric, now, 543));
    Collection<String> comps = Arrays.asList("bolt-1", "bolt-2");
    when(metricsProvider.getMeasurements(any(Instant.class), eq(DEFAULT_METRIC_DURATION), eq(Collections.singletonList(metric)), eq(comps))).thenReturn(result);
    ExecuteCountSensor executeCountSensor = new ExecuteCountSensor(topologyProvider, null, metricsProvider);
    PoliciesExecutor.ExecutionContext context = mock(PoliciesExecutor.ExecutionContext.class);
    when(context.checkpoint()).thenReturn(now);
    executeCountSensor.initialize(context);
    Collection<Measurement> componentMetrics = executeCountSensor.fetch();
    assertEquals(4, componentMetrics.size());
    MeasurementsTable table = MeasurementsTable.of(componentMetrics);
    assertEquals(123, table.component("bolt-1").instance("container_1_bolt-1_1").type(metric).sum(), 0.01);
    assertEquals(345, table.component("bolt-1").instance("container_1_bolt-1_2").type(metric).sum(), 0.01);
    assertEquals(321, table.component("bolt-2").instance("container_1_bolt-2_3").type(metric).sum(), 0.01);
    assertEquals(543, table.component("bolt-2").instance("container_1_bolt-2_4").type(metric).sum(), 0.01);
}
Also used : Measurement(com.microsoft.dhalion.core.Measurement) MeasurementsTable(com.microsoft.dhalion.core.MeasurementsTable) PhysicalPlanProvider(org.apache.heron.healthmgr.common.PhysicalPlanProvider) Instant(java.time.Instant) ArrayList(java.util.ArrayList) PoliciesExecutor(com.microsoft.dhalion.policy.PoliciesExecutor) MetricsProvider(com.microsoft.dhalion.api.MetricsProvider) Test(org.junit.Test)

Example 5 with PhysicalPlanProvider

use of org.apache.heron.healthmgr.common.PhysicalPlanProvider in project heron by twitter.

the class ScaleUpResolverTest method testBuildPackingPlan.

@Test
public void testBuildPackingPlan() {
    TopologyAPI.Topology topology = createTestTopology();
    PhysicalPlanProvider topologyProvider = createPhysicalPlanProvider(topology);
    Config config = createConfig(topology);
    PackingPlan currentPlan = createPacking(topology, config);
    Map<String, Integer> changeRequest = new HashMap<>();
    changeRequest.put("bolt-2", 4);
    Map<String, Integer> deltaChange = new HashMap<>();
    deltaChange.put("bolt-2", 3);
    IRepacking repacking = mock(IRepacking.class);
    when(repacking.repack(currentPlan, deltaChange)).thenReturn(currentPlan);
    ScaleUpResolver resolver = new ScaleUpResolver(topologyProvider, null, null, eventManager, config);
    ScaleUpResolver spyResolver = spy(resolver);
    doReturn(repacking).when(spyResolver).getRepackingClass("Repacking");
    PackingPlan newPlan = spyResolver.buildNewPackingPlan(changeRequest, currentPlan);
    assertEquals(currentPlan, newPlan);
}
Also used : PhysicalPlanProvider(org.apache.heron.healthmgr.common.PhysicalPlanProvider) HashMap(java.util.HashMap) IRepacking(org.apache.heron.spi.packing.IRepacking) Config(org.apache.heron.spi.common.Config) PackingPlan(org.apache.heron.spi.packing.PackingPlan) TopologyAPI(org.apache.heron.api.generated.TopologyAPI) Test(org.junit.Test)

Aggregations

PhysicalPlanProvider (org.apache.heron.healthmgr.common.PhysicalPlanProvider)5 Test (org.junit.Test)4 MetricsProvider (com.microsoft.dhalion.api.MetricsProvider)3 Measurement (com.microsoft.dhalion.core.Measurement)3 MeasurementsTable (com.microsoft.dhalion.core.MeasurementsTable)3 PoliciesExecutor (com.microsoft.dhalion.policy.PoliciesExecutor)2 PackingPlanProvider (org.apache.heron.healthmgr.common.PackingPlanProvider)2 ExecutionContext (com.microsoft.dhalion.policy.PoliciesExecutor.ExecutionContext)1 Instant (java.time.Instant)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 PhysicalPlan (org.apache.heron.proto.system.PhysicalPlans.PhysicalPlan)1 Config (org.apache.heron.spi.common.Config)1 IRepacking (org.apache.heron.spi.packing.IRepacking)1 PackingPlan (org.apache.heron.spi.packing.PackingPlan)1