@Transactional
  UpgradeEntity createUpgradeInsideTransaction(Cluster cluster,
      RequestStageContainer request,
      UpgradeEntity upgradeEntity, UpgradeContext upgradeContext) throws AmbariException {

    // if this is a patch reversion, then we must unset the revertable flag of
    // the upgrade being reverted
    if (upgradeContext.isPatchRevert()) {
      UpgradeEntity upgradeBeingReverted = s_upgradeDAO.findUpgrade(
          upgradeContext.getPatchRevertUpgradeId());

      upgradeBeingReverted.setRevertAllowed(false);
      upgradeBeingReverted = s_upgradeDAO.merge(upgradeBeingReverted);
    }

    request.persist();
    RequestEntity requestEntity = s_requestDAO.findByPK(request.getId());

    upgradeEntity.setRequestEntity(requestEntity);
    s_upgradeDAO.create(upgradeEntity);

    STOMPUpdatePublisher.publish(UpgradeUpdateEvent
        .formFullEvent(s_hostRoleCommandDAO, s_requestDAO, upgradeEntity, UpdateEventType.CREATE));
    cluster.setUpgradeEntity(upgradeEntity);

    return upgradeEntity;
  }
Creates the Request/Stage/Task entities and the Upgrade entities inside of
a single transaction. We break this out since the work to get us to this
point could take a very long time and involve many queries to the database
as the commands are being built.

@param cluster
         the cluster (not {@code null}).
@param request
         the request to persist with all stages and tasks created in memory
         (not {@code null}).
@param upgradeEntity
         the upgrade to create and associate with the newly created request
         (not {@code null}).
@param upgradeContext
         the upgrade context associated with the upgrade being created.
@return the persisted {@link UpgradeEntity} encapsulating all
        {@link UpgradeGroupEntity} and {@link UpgradeItemEntity}.
@throws AmbariException
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java