Source:
<code>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", <START> stateManager.updatePackingPlan(proposedProtoPackingPlan, topologyName)); <END> if (initiallyRunning) { SysUtils.sleep(Duration.ofSeconds(10)); reactivateTopology(stateManager, updatedTopology, removableContainerCount); } if (removableContainerCount > 0 && scalableScheduler.isPresent()) { scalableScheduler.get().removeContainers(containerDelta.getContainersToRemove()); } }</code><technical_language>If remove topology-update stateManager, remove clean a lot of codes, like: private TopologyAPI.Topology getUpdatedTopology(...) static TopologyAPI.Topology mergeTopology(...) private static boolean updateComponent(...) a lot of unit tests. do that</technical_language>

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()); } }