@POST @Path("/topology/shift") @Produces(MediaType.TEXT_HTML) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public Response shiftTopologies( @FormParam("logicalName") String logicalName, @FormParam("direction") int direction, @FormParam("unhealthyPct") @DefaultValue("0.24") float unhealthyPct, @FormParam("probability") @DefaultValue("0.10") float probability) { try { ShiftPredicate shiftPredicate; boolean caterpillar; if (direction == 0) { // "zero" means evac caterpillar = false; shiftPredicate = new UnhealthyTopologyShiftPredicate(unhealthyPct); // TODO should be passed in } else { // "non-zero" means shift by N places caterpillar = true; shiftPredicate = new RandomShiftPredicate(probability); } rebalanceDirector.shiftTopologies( Optional.of(new MiruHost(logicalName)), shiftPredicate, new CaterpillarSelectHostsStrategy(caterpillar, direction, false)); return Response.ok("success").build(); } catch (Throwable t) { LOG.error( "POST /topology/shift {} {} {} {} {}", new Object[] {logicalName, direction, unhealthyPct, probability}, t); return Response.serverError().entity(t.getMessage()).build(); } }
@POST @Path("/topology/repair") @Produces(MediaType.TEXT_HTML) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public Response repairTopologies() { try { rebalanceDirector.shiftTopologies( Optional.<MiruHost>absent(), (tenantId, partitionId, hostHeartbeats, partitions) -> true, new CaterpillarSelectHostsStrategy(true, 0, false)); return Response.ok("success").build(); } catch (Throwable t) { LOG.error("POST /topology/repair", t); return Response.serverError().entity(t.getMessage()).build(); } }