Refactor handling of exceptions in Resource actions

The code to set resource states and handle resulting exceptions (by
translating to ResourceException where appropriate) was duplicated in three
different places. This change consolidates these into a single context
manager.

Change-Id: I3994c7cb73300c4b13437a4b37cd12f5b0a20b35
Merge "Refactor handling of exceptions in Resource actions"