private UpgradeEntity createRevert(Cluster cluster, UpgradeEntity upgradeToRevert)
      throws Exception {

    // create some entities for the finalize action to work with for patch
    // history
    RequestEntity requestEntity = new RequestEntity();
    requestEntity.setClusterId(cluster.getClusterId());
    requestEntity.setRequestId(2L);
    requestEntity.setStartTime(System.currentTimeMillis());
    requestEntity.setCreateTime(System.currentTimeMillis());
    requestDAO.create(requestEntity);

    UpgradeEntity revert = new UpgradeEntity();
    revert.setId(2L);
    revert.setDirection(Direction.DOWNGRADE);
    revert.setClusterId(cluster.getClusterId());
    revert.setRequestEntity(requestEntity);
    revert.setUpgradePackage("");
    revert.setUpgradePackStackId(new StackId((String) null));
    revert.setRepositoryVersion(upgradeToRevert.getRepositoryVersion());
    revert.setUpgradeType(upgradeToRevert.getUpgradeType());
    revert.setOrchestration(upgradeToRevert.getOrchestration());


    for (UpgradeHistoryEntity historyToRevert : upgradeToRevert.getHistory()) {
      UpgradeHistoryEntity history = new UpgradeHistoryEntity();
      history.setUpgrade(revert);
      history.setServiceName(historyToRevert.getServiceName());
      history.setComponentName(historyToRevert.getComponentName());
      history.setFromRepositoryVersion(upgradeToRevert.getRepositoryVersion());
      history.setTargetRepositoryVersion(historyToRevert.getFromReposistoryVersion());
      revert.addHistory(history);

    }
    upgradeDAO.create(revert);
    cluster.setUpgradeEntity(revert);
    return revert;
  }
Creates a revert based on an existing upgrade.
ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java