Move datastores logic to models.

Change-Id: Ia6333cb70dd62085bc6ad1f24250c8930bb915a3