Skip to content

Commit

Permalink
[AMBARI-23989] Provide Patch or Maint Flag to Command JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate Cole committed May 30, 2018
1 parent b337817 commit 4292cab
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 10 deletions.
Expand Up @@ -22,7 +22,7 @@
from resource_management.libraries.script.script import Script
from resource_management.libraries.functions.constants import Direction

UpgradeSummary = namedtuple("UpgradeSummary", "type direction orchestration is_revert services is_downgrade_allowed")
UpgradeSummary = namedtuple("UpgradeSummary", "type direction orchestration is_revert services is_downgrade_allowed is_switch_bits")
UpgradeServiceSummary = namedtuple("UpgradeServiceSummary", "service_name source_stack source_version target_stack target_version")


Expand Down Expand Up @@ -101,7 +101,8 @@ def get_upgrade_summary():
return UpgradeSummary(type=upgrade_summary["type"], direction=upgrade_summary["direction"],
orchestration=upgrade_summary["orchestration"], is_revert = upgrade_summary["isRevert"],
services = service_summary_dict,
is_downgrade_allowed=upgrade_summary["isDowngradeAllowed"])
is_downgrade_allowed=upgrade_summary["isDowngradeAllowed"],
is_switch_bits=upgrade_summary["isSwitchBits"])


def get_downgrade_from_version(service_name = None):
Expand Down
Expand Up @@ -971,6 +971,10 @@ public UpgradeSummary getUpgradeSummary() {

summary.isDowngradeAllowed = isDowngradeAllowed();

// !!! a) if we are reverting, that can only happen via PATCH or MAINT
// b) if orchestration is a revertible type (on upgrade)
summary.isSwitchBits = m_isRevert || m_orchestration.isRevertable();

summary.services = new HashMap<>();

for (String serviceName : m_services) {
Expand Down Expand Up @@ -1435,6 +1439,13 @@ public static class UpgradeSummary {

@SerializedName("services")
public Map<String, UpgradeServiceSummary> services;

/**
* MAINT or PATCH upgrades are meant to just be switching the bits and no other
* incompatible changes.
*/
@SerializedName("isSwitchBits")
public boolean isSwitchBits = false;
}

/**
Expand Down
Expand Up @@ -127,8 +127,11 @@ public void setup() throws Exception {

expect(m_sourceRepositoryVersion.getId()).andReturn(1L).anyTimes();
expect(m_sourceRepositoryVersion.getStackId()).andReturn(new StackId("HDP", "2.6")).anyTimes();
expect(m_sourceRepositoryVersion.getVersion()).andReturn("2.6.0.0").anyTimes();

expect(m_targetRepositoryVersion.getId()).andReturn(99L).anyTimes();
expect(m_targetRepositoryVersion.getStackId()).andReturn(new StackId("HDP", "2.6")).anyTimes();
expect(m_targetRepositoryVersion.getVersion()).andReturn("2.6.0.2").anyTimes();

UpgradeHistoryEntity upgradeHistoryEntity = createNiceMock(UpgradeHistoryEntity.class);
expect(upgradeHistoryEntity.getServiceName()).andReturn(HDFS_SERVICE_NAME).anyTimes();
Expand All @@ -153,7 +156,8 @@ public void setup() throws Exception {
expect(m_completedRevertableUpgrade.getUpgradePackage()).andReturn(null).anyTimes();

RepositoryVersionEntity hdfsRepositoryVersion = createNiceMock(RepositoryVersionEntity.class);

expect(hdfsRepositoryVersion.getId()).andReturn(1L).anyTimes();
expect(hdfsRepositoryVersion.getStackId()).andReturn(new StackId("HDP-2.6")).anyTimes();
expect(m_hdfsService.getDesiredRepositoryVersion()).andReturn(hdfsRepositoryVersion).anyTimes();
expect(m_zookeeperService.getDesiredRepositoryVersion()).andReturn(hdfsRepositoryVersion).anyTimes();
expect(m_cluster.getService(HDFS_SERVICE_NAME)).andReturn(m_hdfsService).anyTimes();
Expand Down Expand Up @@ -202,6 +206,7 @@ public void testFullUpgrade() throws Exception {
assertEquals(RepositoryType.STANDARD, context.getOrchestrationType());
assertEquals(1, context.getSupportedServices().size());
assertFalse(context.isPatchRevert());
assertFalse(context.getUpgradeSummary().isSwitchBits);

verifyAll();
}
Expand Down Expand Up @@ -248,6 +253,7 @@ public void testPatchUpgrade() throws Exception {
assertEquals(RepositoryType.PATCH, context.getOrchestrationType());
assertEquals(1, context.getSupportedServices().size());
assertFalse(context.isPatchRevert());
assertTrue(context.getUpgradeSummary().isSwitchBits);

verifyAll();
}
Expand Down Expand Up @@ -332,6 +338,7 @@ public void testRevert() throws Exception {
assertEquals(RepositoryType.PATCH, context.getOrchestrationType());
assertEquals(1, context.getSupportedServices().size());
assertTrue(context.isPatchRevert());
assertTrue(context.getUpgradeSummary().isSwitchBits);

verifyAll();
}
Expand Down
9 changes: 6 additions & 3 deletions ambari-server/src/test/python/TestStackFeature.py
Expand Up @@ -196,7 +196,8 @@ def _get_cluster_upgrade_restart_json():
"type":"rolling_upgrade",
"isRevert":False,
"orchestration":"STANDARD",
"isDowngradeAllowed": True
"isDowngradeAllowed": True,
"isSwitchBits": False
}
}

Expand Down Expand Up @@ -234,7 +235,8 @@ def _get_cluster_downgrade_restart_json():
"type":"rolling_upgrade",
"isRevert":False,
"orchestration":"STANDARD",
"isDowngradeAllowed": True
"isDowngradeAllowed": True,
"isSwitchBits": False
}
}

Expand Down Expand Up @@ -273,7 +275,8 @@ def _get_cluster_downgrade_stop_json():
"type":"rolling_upgrade",
"isRevert":False,
"orchestration":"STANDARD",
"isDowngradeAllowed": True
"isDowngradeAllowed": True,
"isSwitchBits": False
}
}

Expand Down
6 changes: 4 additions & 2 deletions ambari-server/src/test/python/TestStackSelect.py
Expand Up @@ -161,7 +161,8 @@ def _get_incomplete_cluster_simple_upgrade_json():
"type":"rolling_upgrade",
"isRevert":False,
"orchestration":"STANDARD",
"isDowngradeAllowed": True
"isDowngradeAllowed": True,
"isSwitchBits": False
}
}

Expand Down Expand Up @@ -200,7 +201,8 @@ def _get_cluster_simple_upgrade_json():
"type":"rolling_upgrade",
"isRevert":False,
"orchestration":"STANDARD",
"isDowngradeAllowed": True
"isDowngradeAllowed": True,
"isSwitchBits": False
}
}

Expand Down
6 changes: 4 additions & 2 deletions ambari-server/src/test/python/TestUpgradeSummary.py
Expand Up @@ -97,7 +97,8 @@ def _get_cluster_simple_upgrade_json():
"type":"rolling_upgrade",
"isRevert":False,
"orchestration":"STANDARD",
"isDowngradeAllowed": True
"isDowngradeAllowed": True,
"isSwitchBits": False
}
}

Expand Down Expand Up @@ -134,6 +135,7 @@ def _get_cluster_simple_downgrade_json():
"type":"rolling_upgrade",
"isRevert":False,
"orchestration":"STANDARD",
"isDowngradeAllowed": True
"isDowngradeAllowed": True,
"isSwitchBits": False
}
}

0 comments on commit 4292cab

Please sign in to comment.