Search in sources :

Example 1 with PackingPlanProvider

use of com.twitter.heron.healthmgr.common.PackingPlanProvider in project incubator-heron by apache.

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);
    ComponentMetrics metrics = new ComponentMetrics("bolt", "i1", METRIC_BACK_PRESSURE.text(), 123);
    Symptom symptom = new Symptom(SYMPTOM_UNDER_PROVISIONING.text(), metrics);
    List<Diagnosis> diagnosis = new ArrayList<>();
    diagnosis.add(new Diagnosis("test", symptom));
    ScaleUpResolver resolver = new ScaleUpResolver(null, packingPlanProvider, scheduler, eventManager, null);
    ScaleUpResolver spyResolver = spy(resolver);
    doReturn(2).when(spyResolver).computeScaleUpFactor(metrics);
    doReturn(currentPlan).when(spyResolver).buildNewPackingPlan(any(HashMap.class), eq(currentPlan));
    List<Action> result = spyResolver.resolve(diagnosis);
    verify(scheduler, times(1)).updateTopology(any(UpdateTopologyRequest.class));
    assertEquals(1, result.size());
}
Also used : Action(com.microsoft.dhalion.resolver.Action) HashMap(java.util.HashMap) Config(com.twitter.heron.spi.common.Config) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) ArrayList(java.util.ArrayList) PackingPlanProvider(com.twitter.heron.healthmgr.common.PackingPlanProvider) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI) UpdateTopologyRequest(com.twitter.heron.proto.scheduler.Scheduler.UpdateTopologyRequest) ISchedulerClient(com.twitter.heron.scheduler.client.ISchedulerClient) Diagnosis(com.microsoft.dhalion.diagnoser.Diagnosis) Symptom(com.microsoft.dhalion.detector.Symptom) ComponentMetrics(com.microsoft.dhalion.metrics.ComponentMetrics) Test(org.junit.Test)

Example 2 with PackingPlanProvider

use of com.twitter.heron.healthmgr.common.PackingPlanProvider in project incubator-heron by apache.

the class BufferSizeSensorTest method providesBufferSizeMetricForBolts.

@Test
public void providesBufferSizeMetricForBolts() {
    TopologyProvider topologyProvider = mock(TopologyProvider.class);
    when(topologyProvider.getBoltNames()).thenReturn(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 = MetricName.METRIC_BUFFER_SIZE + boltId + MetricName.METRIC_BUFFER_SIZE_SUFFIX;
        registerStMgrInstanceMetricResponse(metricsProvider, metric, boltId.length());
    }
    BufferSizeSensor bufferSizeSensor = new BufferSizeSensor(null, packingPlanProvider, topologyProvider, metricsProvider);
    Map<String, ComponentMetrics> componentMetrics = bufferSizeSensor.get();
    assertEquals(2, componentMetrics.size());
    assertEquals(1, componentMetrics.get("bolt-1").getMetrics().size());
    assertEquals(boltIds[0].length(), componentMetrics.get("bolt-1").getMetrics(boltIds[0]).getMetricValueSum(MetricName.METRIC_BUFFER_SIZE.text()).intValue());
    assertEquals(2, componentMetrics.get("bolt-2").getMetrics().size());
    assertEquals(boltIds[1].length(), componentMetrics.get("bolt-2").getMetrics(boltIds[1]).getMetricValueSum(MetricName.METRIC_BUFFER_SIZE.text()).intValue());
    assertEquals(boltIds[2].length(), componentMetrics.get("bolt-2").getMetrics(boltIds[2]).getMetricValueSum(MetricName.METRIC_BUFFER_SIZE.text()).intValue());
}
Also used : TopologyProvider(com.twitter.heron.healthmgr.common.TopologyProvider) PackingPlanProvider(com.twitter.heron.healthmgr.common.PackingPlanProvider) MetricsProvider(com.microsoft.dhalion.api.MetricsProvider) ComponentMetrics(com.microsoft.dhalion.metrics.ComponentMetrics) Test(org.junit.Test)

Example 3 with PackingPlanProvider

use of com.twitter.heron.healthmgr.common.PackingPlanProvider in project incubator-heron by apache.

the class BackPressureSensorTest method providesBackPressureMetricForBolts.

@Test
public void providesBackPressureMetricForBolts() {
    TopologyProvider topologyProvider = mock(TopologyProvider.class);
    when(topologyProvider.getBoltNames()).thenReturn(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 = MetricName.METRIC_BACK_PRESSURE + boltId;
        // the back pressure sensor will return average bp per second, so multiply by duration
        BufferSizeSensorTest.registerStMgrInstanceMetricResponse(metricsProvider, metric, boltId.length() * DEFAULT_METRIC_DURATION.getSeconds());
    }
    BackPressureSensor backPressureSensor = new BackPressureSensor(packingPlanProvider, topologyProvider, null, metricsProvider);
    Map<String, ComponentMetrics> componentMetrics = backPressureSensor.get();
    assertEquals(2, componentMetrics.size());
    assertEquals(1, componentMetrics.get("bolt-1").getMetrics().size());
    assertEquals(boltIds[0].length(), componentMetrics.get("bolt-1").getMetrics(boltIds[0]).getMetricValueSum(MetricName.METRIC_BACK_PRESSURE.text()).intValue());
    assertEquals(2, componentMetrics.get("bolt-2").getMetrics().size());
    assertEquals(boltIds[1].length(), componentMetrics.get("bolt-2").getMetrics(boltIds[1]).getMetricValueSum(MetricName.METRIC_BACK_PRESSURE.text()).intValue());
    assertEquals(boltIds[2].length(), componentMetrics.get("bolt-2").getMetrics(boltIds[2]).getMetricValueSum(MetricName.METRIC_BACK_PRESSURE.text()).intValue());
}
Also used : TopologyProvider(com.twitter.heron.healthmgr.common.TopologyProvider) PackingPlanProvider(com.twitter.heron.healthmgr.common.PackingPlanProvider) MetricsProvider(com.microsoft.dhalion.api.MetricsProvider) ComponentMetrics(com.microsoft.dhalion.metrics.ComponentMetrics) Test(org.junit.Test)

Aggregations

ComponentMetrics (com.microsoft.dhalion.metrics.ComponentMetrics)3 PackingPlanProvider (com.twitter.heron.healthmgr.common.PackingPlanProvider)3 Test (org.junit.Test)3 MetricsProvider (com.microsoft.dhalion.api.MetricsProvider)2 TopologyProvider (com.twitter.heron.healthmgr.common.TopologyProvider)2 Symptom (com.microsoft.dhalion.detector.Symptom)1 Diagnosis (com.microsoft.dhalion.diagnoser.Diagnosis)1 Action (com.microsoft.dhalion.resolver.Action)1 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)1 UpdateTopologyRequest (com.twitter.heron.proto.scheduler.Scheduler.UpdateTopologyRequest)1 ISchedulerClient (com.twitter.heron.scheduler.client.ISchedulerClient)1 Config (com.twitter.heron.spi.common.Config)1 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1