Search in sources :

Example 1 with Action

use of com.microsoft.dhalion.resolver.Action 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 Action

use of com.microsoft.dhalion.resolver.Action in project incubator-heron by apache.

the class RestartContainerResolver method resolve.

@Override
public List<Action> resolve(List<Diagnosis> diagnosis) {
    List<Action> actions = new ArrayList<>();
    for (Diagnosis diagnoses : diagnosis) {
        Symptom bpSymptom = diagnoses.getSymptoms().get(SYMPTOM_SLOW_INSTANCE.text());
        if (bpSymptom == null || bpSymptom.getComponents().isEmpty()) {
            // nothing to fix as there is no back pressure
            continue;
        }
        if (bpSymptom.getComponents().size() > 1) {
            throw new UnsupportedOperationException("Multiple components with back pressure symptom");
        }
        // want to know which stmgr has backpressure
        String stmgrId = null;
        for (InstanceMetrics im : bpSymptom.getComponent().getMetrics().values()) {
            if (im.hasMetricAboveLimit(METRIC_BACK_PRESSURE.text(), noiseFilterMillis)) {
                String instanceId = im.getName();
                int fromIndex = instanceId.indexOf('_') + 1;
                int toIndex = instanceId.indexOf('_', fromIndex);
                stmgrId = instanceId.substring(fromIndex, toIndex);
                break;
            }
        }
        LOG.info("Restarting container: " + stmgrId);
        boolean b = schedulerClient.restartTopology(RestartTopologyRequest.newBuilder().setContainerIndex(Integer.valueOf(stmgrId)).setTopologyName(topologyName).build());
        LOG.info("Restarted container result: " + b);
        ContainerRestart action = new ContainerRestart();
        LOG.info("Broadcasting container restart event");
        eventManager.onEvent(action);
        actions.add(action);
        return actions;
    }
    return actions;
}
Also used : InstanceMetrics(com.microsoft.dhalion.metrics.InstanceMetrics) Action(com.microsoft.dhalion.resolver.Action) ArrayList(java.util.ArrayList) Diagnosis(com.microsoft.dhalion.diagnoser.Diagnosis) Symptom(com.microsoft.dhalion.detector.Symptom) ContainerRestart(com.twitter.heron.healthmgr.common.HealthManagerEvents.ContainerRestart)

Example 3 with Action

use of com.microsoft.dhalion.resolver.Action in project incubator-heron by apache.

the class ScaleUpResolver method resolve.

@Override
public List<Action> resolve(List<Diagnosis> diagnosis) {
    for (Diagnosis diagnoses : diagnosis) {
        Symptom bpSymptom = diagnoses.getSymptoms().get(SYMPTOM_UNDER_PROVISIONING.text());
        if (bpSymptom == null || bpSymptom.getComponents().isEmpty()) {
            // nothing to fix as there is no back pressure
            continue;
        }
        if (bpSymptom.getComponents().size() > 1) {
            throw new UnsupportedOperationException("Multiple components with back pressure symptom");
        }
        ComponentMetrics bpComponent = bpSymptom.getComponent();
        int newParallelism = computeScaleUpFactor(bpComponent);
        Map<String, Integer> changeRequest = new HashMap<>();
        changeRequest.put(bpComponent.getName(), newParallelism);
        PackingPlan currentPackingPlan = packingPlanProvider.get();
        PackingPlan newPlan = buildNewPackingPlan(changeRequest, currentPackingPlan);
        if (newPlan == null) {
            return null;
        }
        Scheduler.UpdateTopologyRequest updateTopologyRequest = Scheduler.UpdateTopologyRequest.newBuilder().setCurrentPackingPlan(getSerializedPlan(currentPackingPlan)).setProposedPackingPlan(getSerializedPlan(newPlan)).build();
        LOG.info("Sending Updating topology request: " + updateTopologyRequest);
        if (!schedulerClient.updateTopology(updateTopologyRequest)) {
            throw new RuntimeException(String.format("Failed to update topology with Scheduler, " + "updateTopologyRequest=%s", updateTopologyRequest));
        }
        TopologyUpdate action = new TopologyUpdate();
        LOG.info("Broadcasting topology update event");
        eventManager.onEvent(action);
        LOG.info("Scheduler updated topology successfully.");
        List<Action> actions = new ArrayList<>();
        actions.add(action);
        return actions;
    }
    return null;
}
Also used : Action(com.microsoft.dhalion.resolver.Action) HashMap(java.util.HashMap) Scheduler(com.twitter.heron.proto.scheduler.Scheduler) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) ArrayList(java.util.ArrayList) TopologyUpdate(com.twitter.heron.healthmgr.common.HealthManagerEvents.TopologyUpdate) Diagnosis(com.microsoft.dhalion.diagnoser.Diagnosis) Symptom(com.microsoft.dhalion.detector.Symptom) ComponentMetrics(com.microsoft.dhalion.metrics.ComponentMetrics)

Aggregations

Symptom (com.microsoft.dhalion.detector.Symptom)3 Diagnosis (com.microsoft.dhalion.diagnoser.Diagnosis)3 Action (com.microsoft.dhalion.resolver.Action)3 ArrayList (java.util.ArrayList)3 ComponentMetrics (com.microsoft.dhalion.metrics.ComponentMetrics)2 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)2 HashMap (java.util.HashMap)2 InstanceMetrics (com.microsoft.dhalion.metrics.InstanceMetrics)1 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)1 ContainerRestart (com.twitter.heron.healthmgr.common.HealthManagerEvents.ContainerRestart)1 TopologyUpdate (com.twitter.heron.healthmgr.common.HealthManagerEvents.TopologyUpdate)1 PackingPlanProvider (com.twitter.heron.healthmgr.common.PackingPlanProvider)1 Scheduler (com.twitter.heron.proto.scheduler.Scheduler)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 Test (org.junit.Test)1