Search in sources :

Example 1 with Action

use of com.microsoft.dhalion.core.Action in project heron by twitter.

the class ScaleUpResolver method resolve.

@Override
public Collection<Action> resolve(Collection<Diagnosis> diagnosis) {
    List<Action> actions = new ArrayList<>();
    DiagnosisTable table = DiagnosisTable.of(diagnosis);
    table = table.type(DIAGNOSIS_UNDER_PROVISIONING.text());
    if (table.size() == 0) {
        LOG.fine("No under-previsioning diagnosis present, ending as there's nothing to fix");
        return actions;
    }
    // Scale the first assigned component
    Diagnosis diagnoses = table.first();
    // verify diagnoses instance is valid
    if (diagnoses.assignments().isEmpty()) {
        LOG.warning(String.format("Diagnosis %s is missing assignments", diagnoses.id()));
        return actions;
    }
    String component = diagnoses.assignments().iterator().next();
    int newParallelism = computeScaleUpFactor(component);
    Map<String, Integer> changeRequest = new HashMap<>();
    changeRequest.put(component, 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));
    }
    LOG.info("Scheduler updated topology successfully.");
    LOG.info("Broadcasting topology update event");
    TopologyUpdate action = new TopologyUpdate(context.checkpoint(), Collections.singletonList(component));
    eventManager.onEvent(action);
    actions.add(action);
    return actions;
}
Also used : Action(com.microsoft.dhalion.core.Action) HashMap(java.util.HashMap) Scheduler(org.apache.heron.proto.scheduler.Scheduler) PackingPlan(org.apache.heron.spi.packing.PackingPlan) ArrayList(java.util.ArrayList) DiagnosisTable(com.microsoft.dhalion.core.DiagnosisTable) TopologyUpdate(org.apache.heron.healthmgr.common.HealthManagerEvents.TopologyUpdate) Diagnosis(com.microsoft.dhalion.core.Diagnosis)

Example 2 with Action

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

Action (com.microsoft.dhalion.core.Action)2 Diagnosis (com.microsoft.dhalion.core.Diagnosis)2 HashMap (java.util.HashMap)2 PackingPlan (org.apache.heron.spi.packing.PackingPlan)2 DiagnosisTable (com.microsoft.dhalion.core.DiagnosisTable)1 Measurement (com.microsoft.dhalion.core.Measurement)1 ExecutionContext (com.microsoft.dhalion.policy.PoliciesExecutor.ExecutionContext)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 TopologyAPI (org.apache.heron.api.generated.TopologyAPI)1 TopologyUpdate (org.apache.heron.healthmgr.common.HealthManagerEvents.TopologyUpdate)1 PackingPlanProvider (org.apache.heron.healthmgr.common.PackingPlanProvider)1 Scheduler (org.apache.heron.proto.scheduler.Scheduler)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 Test (org.junit.Test)1