A Layered Coordination Framework for Optimizing Resource Allocation in Adapting Cloud-based Applications