Refactor set domain-id and mapping code

Applied function separation refactorings to the
_set_domain_id_and_mapping function in the identity/core module in an
attempt to make it more readable.

Change-Id: I921a05b0164bc6afa329e98c26faf4cf4f336f2f
Do not consume trust uses when create token fails

Currently, remaining trust uses are consumed even when create token
fails. We should only consume trust uses when successfully creating
a token.

Change-Id: I55a726250312fa81ed9556dfd530e96f72548930
Closes-Bug: #1335037
Merge "Do not consume trust uses when create token fails"
Merge "Refactor set domain-id and mapping code"