Open
Description
Describe your feature request
Currently, the autoscaler code is quite difficult to read since it directly manipulates resources dicts, cluster load dicts, individual node ids directly. This results in a lot of low level code in the main loop of the autoscaler / resource demand scheduler classes. We can extract some of this generic resource manipulation code into a utility class, for instance,
# Calculate nodes to launch
ec = bin_pack.EmulatedCluster(node_type_config, cur_nodes, cur_resource_usage)
ec.apply_min_worker_constraint(min_worker_config)
ec.apply_resource_demands(resource_bundle_demands)
nodes_to_launch = ec.get_nodes_to_launch(cur_pending_nodes)
# Calculate nodes to keep
ec = bin_pack.EmulatedCluster(node_type_config, cur_nodes, cur_resource_usage)
ec.apply_min_worker_constraint(min_worker_config)
ec.apply_resource_demands(request_resource_demands)
allowed_to_terminate = ec.get_unused_nodes()