Source:
private void updateTopology(final PackingPlans.PackingPlan existingProtoPackingPlan, final PackingPlans.PackingPlan proposedProtoPackingPlan, SchedulerStateManagerAdaptor stateManager) throws ExecutionException, InterruptedException { String topologyName = Runtime.topologyName(runtime); PackingPlan existingPackingPlan = deserializer.fromProto(existingProtoPackingPlan); PackingPlan proposedPackingPlan = deserializer.fromProto(proposedProtoPackingPlan); Preconditions.checkArgument(proposedPackingPlan.getContainers().size() > 0, String.format( "proposed packing plan must have at least 1 container %s", proposedPackingPlan)); ContainerDelta containerDelta = new ContainerDelta( existingPackingPlan.getContainers(), proposedPackingPlan.getContainers()); int newContainerCount = containerDelta.getContainersToAdd().size(); int removableContainerCount = containerDelta.getContainersToRemove().size(); String message = String.format("Topology change requires %s new containers and removing %s " + "existing containers, but the scheduler does not support scaling, aborting. " + "Existing packing plan: %s, proposed packing plan: %s", newContainerCount, removableContainerCount, existingPackingPlan, proposedPackingPlan); Preconditions.checkState(newContainerCount + removableContainerCount == 0 || scalableScheduler.isPresent(), message); TopologyAPI.Topology topology = getTopology(stateManager, topologyName); boolean initiallyRunning = topology.getState() == TopologyAPI.TopologyState.RUNNING; TopologyAPI.Topology updatedTopology = getUpdatedTopology(topologyName, proposedPackingPlan, stateManager); if (initiallyRunning) { updatedTopology = deactivateTopology(stateManager, updatedTopology, proposedPackingPlan); } if (newContainerCount > 0 && scalableScheduler.isPresent()) { scalableScheduler.get().addContainers(containerDelta.getContainersToAdd()); } logInfo("Update new PackingPlan: %s", stateManager.updatePackingPlan(proposedProtoPackingPlan, topologyName)); if (initiallyRunning) { SysUtils.sleep(Duration.ofSeconds(10)); reactivateTopology(stateManager, updatedTopology, removableContainerCount); } if (removableContainerCount > 0 && scalableScheduler.isPresent()) { scalableScheduler.get().removeContainers(containerDelta.getContainersToRemove()); } }

Target:
private void updateTopology(final PackingPlans.PackingPlan existingProtoPackingPlan, final PackingPlans.PackingPlan proposedProtoPackingPlan, SchedulerStateManagerAdaptor stateManager) throws ExecutionException, InterruptedException { String topologyName = Runtime.topologyName(runtime); PackingPlan existingPackingPlan = deserializer.fromProto(existingProtoPackingPlan); PackingPlan proposedPackingPlan = deserializer.fromProto(proposedProtoPackingPlan); Preconditions.checkArgument(proposedPackingPlan.getContainers().size() > 0, String.format( "proposed packing plan must have at least 1 container %s", proposedPackingPlan)); ContainerDelta containerDelta = new ContainerDelta( existingPackingPlan.getContainers(), proposedPackingPlan.getContainers()); int newContainerCount = containerDelta.getContainersToAdd().size(); int removableContainerCount = containerDelta.getContainersToRemove().size(); String message = String.format("Topology change requires %s new containers and removing %s " + "existing containers, but the scheduler does not support scaling, aborting. " + "Existing packing plan: %s, proposed packing plan: %s", newContainerCount, removableContainerCount, existingPackingPlan, proposedPackingPlan); Preconditions.checkState(newContainerCount + removableContainerCount == 0 || scalableScheduler.isPresent(), message); TopologyAPI.Topology topology = getTopology(stateManager, topologyName); boolean initiallyRunning = topology.getState() == TopologyAPI.TopologyState.RUNNING; if (initiallyRunning) { deactivateTopology(stateManager, topology, proposedPackingPlan); } if (newContainerCount > 0 && scalableScheduler.isPresent()) { scalableScheduler.get().addContainers(containerDelta.getContainersToAdd()); } logInfo("Update new PackingPlan: %s", stateManager.updatePackingPlan(proposedProtoPackingPlan, topologyName)); if (initiallyRunning) { SysUtils.sleep(Duration.ofSeconds(10)); reactivateTopology(stateManager, topology, removableContainerCount); } if (removableContainerCount > 0 && scalableScheduler.isPresent()) { scalableScheduler.get().removeContainers(containerDelta.getContainersToRemove()); } }