Repository: ambari Updated Branches: refs/heads/branch-feature-AMBARI-21348 2b147ea66 -> a5ce6b427
AMBARI-21402 - Fix Unit Test Failures Caused by AMBARI-21391 (jonathanhurley) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/a5ce6b42 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/a5ce6b42 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/a5ce6b42 Branch: refs/heads/branch-feature-AMBARI-21348 Commit: a5ce6b4271663167eb827e98436748d02bcefc2c Parents: 2b147ea Author: Jonathan Hurley <jhur...@hortonworks.com> Authored: Tue Jul 4 23:43:13 2017 -0400 Committer: Jonathan Hurley <jhur...@hortonworks.com> Committed: Tue Jul 4 23:43:13 2017 -0400 ---------------------------------------------------------------------- .../upgrades/FinalizeUpgradeAction.java | 5 +- .../4.2.5/upgrades/config-upgrade.xml | 11 ++--- .../BigInsights/4.2/upgrades/config-upgrade.xml | 11 ++--- .../actionmanager/TestActionDBAccessorImpl.java | 44 +++++++++--------- .../UpgradeResourceProviderHDP22Test.java | 13 ++++-- .../upgrades/UpgradeActionTest.java | 49 ++++++++++---------- 6 files changed, 66 insertions(+), 67 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/a5ce6b42/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FinalizeUpgradeAction.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FinalizeUpgradeAction.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FinalizeUpgradeAction.java index 8a54679..0e6f0c4 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FinalizeUpgradeAction.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FinalizeUpgradeAction.java @@ -391,9 +391,10 @@ public class FinalizeUpgradeAction extends AbstractServerAction { if (!StringUtils.equals(targetRepositoryVersion.getVersion(), clusterVersion.getRepositoryVersion().getVersion())) { throw new AmbariException( - String.format("Downgrade version %s is not the current cluster version of %s", + String.format("Downgrade version %s is not the current cluster version of %s. %s", targetRepositoryVersion.getVersion(), - clusterVersion.getRepositoryVersion().getVersion())); + clusterVersion.getRepositoryVersion().getVersion(), + PREVIOUS_UPGRADE_NOT_COMPLETED_MSG)); } else { out.append(String.format( "Downgrade version is the same as current. Searching " http://git-wip-us.apache.org/repos/asf/ambari/blob/a5ce6b42/ambari-server/src/main/resources/stacks/BigInsights/4.2.5/upgrades/config-upgrade.xml ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/stacks/BigInsights/4.2.5/upgrades/config-upgrade.xml b/ambari-server/src/main/resources/stacks/BigInsights/4.2.5/upgrades/config-upgrade.xml index 540c017..d1cd81f 100644 --- a/ambari-server/src/main/resources/stacks/BigInsights/4.2.5/upgrades/config-upgrade.xml +++ b/ambari-server/src/main/resources/stacks/BigInsights/4.2.5/upgrades/config-upgrade.xml @@ -16,7 +16,7 @@ limitations under the License. --> -<upgrade-config-changes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> +<upgrade-config-changes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="upgrade-config.xsd"> <services> <service name="HDFS"> <component name="NAMENODE"> @@ -100,12 +100,9 @@ <service name="OOZIE"> <component name="OOZIE_SERVER"> <changes> - <definition xsi:type="configure" id="biginsights_4_2_oozie_server_update_configurations" Summary="Updating oozie-site configurations"> - <condition type="oozie-site" key="oozie.services" value="org.apache.oozie.service.SchedulerService, org.apache.oozie.service.InstrumentationService, org.apache.oozie.service.CallableQueueService, org.apache.oozie.service.UUIDService, org.apache.oozie.service.ELService, org.apache.oozie.service.AuthorizationService, org.apache.oozie.service.UserGroupInformationService, org.apache.oozie.service.HadoopAccessorService, org.apache.oozie.service.JobsConcurrencyService, org.apache.oozie.service.URIHandlerService, org.apache.oozie.service.MemoryLocksService, org.apache.oozie.service.DagXLogInfoService, org.apache.oozie.service.SchemaService, org.apache.oozie.service.LiteWorkflowAppService, org.apache.oozie.service.JPAService, org.apache.oozie.service.StoreService, org.apache.oozie.service.SLAStoreService, org.apache.oozie.service.DBLiteWorkflowStoreService, org.apache.oozie.service.CallbackSer vice, org.apache.oozie.service.ActionService, org.apache.oozie.service.ShareLibService, org.apache.oozie.service.ActionCheckerService, org.apache.oozie.service.RecoveryService, org.apache.oozie.service.PurgeService, org.apache.oozie.service.CoordinatorEngineService, org.apache.oozie.service.BundleEngineService, org.apache.oozie.service.DagEngineService, org.apache.oozie.service.CoordMaterializeTriggerService, org.apache.oozie.service.StatusTransitService, org.apache.oozie.service.PauseTransitService, org.apache.oozie.service.GroupsService, org.apache.oozie.service.ProxyUserService, org.apache.oozie.service.XLogStreamingService, org.apache.oozie.service.JvmPauseMonitorService"> - <type>oozie-site</type> - <key>oozie.services</key> - <value>org.apache.oozie.service.SchedulerService, org.apache.oozie.service.InstrumentationService, org.apache.oozie.service.CallableQueueService, org.apache.oozie.service.UUIDService, org.apache.oozie.service.ELService, org.apache.oozie.service.AuthorizationService, org.apache.oozie.service.UserGroupInformationService, org.apache.oozie.service.HadoopAccessorService, org.apache.oozie.service.JobsConcurrencyService, org.apache.oozie.service.URIHandlerService, org.apache.oozie.service.MemoryLocksService, org.apache.oozie.service.DagXLogInfoService, org.apache.oozie.service.SchemaService, org.apache.oozie.service.LiteWorkflowAppService, org.apache.oozie.service.JPAService, org.apache.oozie.service.StoreService, org.apache.oozie.service.SLAStoreService, org.apache.oozie.service.DBLiteWorkflowStoreService, org.apache.oozie.service.CallbackService, org.apache.oozie.service.ActionService, org.apache.oozie.service.ShareLibService, org.apache.oozie.service.ActionCheckerService, org.apache.oozie.service.RecoveryService, org.apache.oozie.service.PurgeService, org.apache.oozie.service.CoordinatorEngineService, org.apache.oozie.service.BundleEngineService, org.apache.oozie.service.DagEngineService, org.apache.oozie.service.CoordMaterializeTriggerService, org.apache.oozie.service.StatusTransitService, org.apache.oozie.service.PauseTransitService, org.apache.oozie.service.GroupsService, org.apache.oozie.service.ProxyUserService, org.apache.oozie.service.XLogStreamingService, org.apache.oozie.service.JvmPauseMonitorService, org.apache.oozie.service.SparkConfigurationService</value> - </condition> + <definition xsi:type="configure" id="biginsights_4_2_oozie_server_update_configurations" summary="Updating oozie-site configurations"> + <type>oozie-site</type> + <replace key="oozie.services" find="org.apache.oozie.service.JvmPauseMonitorService" replace-with="org.apache.oozie.service.JvmPauseMonitorService, org.apache.oozie.service.SparkConfigurationService"/> </definition> <definition xsi:type="configure" id="biginsights_4_2_oozie_server_update_environment_configurations" summary="Update oozie env"> <type>oozie-env</type> http://git-wip-us.apache.org/repos/asf/ambari/blob/a5ce6b42/ambari-server/src/main/resources/stacks/BigInsights/4.2/upgrades/config-upgrade.xml ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/stacks/BigInsights/4.2/upgrades/config-upgrade.xml b/ambari-server/src/main/resources/stacks/BigInsights/4.2/upgrades/config-upgrade.xml index 540c017..d1cd81f 100644 --- a/ambari-server/src/main/resources/stacks/BigInsights/4.2/upgrades/config-upgrade.xml +++ b/ambari-server/src/main/resources/stacks/BigInsights/4.2/upgrades/config-upgrade.xml @@ -16,7 +16,7 @@ limitations under the License. --> -<upgrade-config-changes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> +<upgrade-config-changes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="upgrade-config.xsd"> <services> <service name="HDFS"> <component name="NAMENODE"> @@ -100,12 +100,9 @@ <service name="OOZIE"> <component name="OOZIE_SERVER"> <changes> - <definition xsi:type="configure" id="biginsights_4_2_oozie_server_update_configurations" Summary="Updating oozie-site configurations"> - <condition type="oozie-site" key="oozie.services" value="org.apache.oozie.service.SchedulerService, org.apache.oozie.service.InstrumentationService, org.apache.oozie.service.CallableQueueService, org.apache.oozie.service.UUIDService, org.apache.oozie.service.ELService, org.apache.oozie.service.AuthorizationService, org.apache.oozie.service.UserGroupInformationService, org.apache.oozie.service.HadoopAccessorService, org.apache.oozie.service.JobsConcurrencyService, org.apache.oozie.service.URIHandlerService, org.apache.oozie.service.MemoryLocksService, org.apache.oozie.service.DagXLogInfoService, org.apache.oozie.service.SchemaService, org.apache.oozie.service.LiteWorkflowAppService, org.apache.oozie.service.JPAService, org.apache.oozie.service.StoreService, org.apache.oozie.service.SLAStoreService, org.apache.oozie.service.DBLiteWorkflowStoreService, org.apache.oozie.service.CallbackSer vice, org.apache.oozie.service.ActionService, org.apache.oozie.service.ShareLibService, org.apache.oozie.service.ActionCheckerService, org.apache.oozie.service.RecoveryService, org.apache.oozie.service.PurgeService, org.apache.oozie.service.CoordinatorEngineService, org.apache.oozie.service.BundleEngineService, org.apache.oozie.service.DagEngineService, org.apache.oozie.service.CoordMaterializeTriggerService, org.apache.oozie.service.StatusTransitService, org.apache.oozie.service.PauseTransitService, org.apache.oozie.service.GroupsService, org.apache.oozie.service.ProxyUserService, org.apache.oozie.service.XLogStreamingService, org.apache.oozie.service.JvmPauseMonitorService"> - <type>oozie-site</type> - <key>oozie.services</key> - <value>org.apache.oozie.service.SchedulerService, org.apache.oozie.service.InstrumentationService, org.apache.oozie.service.CallableQueueService, org.apache.oozie.service.UUIDService, org.apache.oozie.service.ELService, org.apache.oozie.service.AuthorizationService, org.apache.oozie.service.UserGroupInformationService, org.apache.oozie.service.HadoopAccessorService, org.apache.oozie.service.JobsConcurrencyService, org.apache.oozie.service.URIHandlerService, org.apache.oozie.service.MemoryLocksService, org.apache.oozie.service.DagXLogInfoService, org.apache.oozie.service.SchemaService, org.apache.oozie.service.LiteWorkflowAppService, org.apache.oozie.service.JPAService, org.apache.oozie.service.StoreService, org.apache.oozie.service.SLAStoreService, org.apache.oozie.service.DBLiteWorkflowStoreService, org.apache.oozie.service.CallbackService, org.apache.oozie.service.ActionService, org.apache.oozie.service.ShareLibService, org.apache.oozie.service.ActionCheckerService, org.apache.oozie.service.RecoveryService, org.apache.oozie.service.PurgeService, org.apache.oozie.service.CoordinatorEngineService, org.apache.oozie.service.BundleEngineService, org.apache.oozie.service.DagEngineService, org.apache.oozie.service.CoordMaterializeTriggerService, org.apache.oozie.service.StatusTransitService, org.apache.oozie.service.PauseTransitService, org.apache.oozie.service.GroupsService, org.apache.oozie.service.ProxyUserService, org.apache.oozie.service.XLogStreamingService, org.apache.oozie.service.JvmPauseMonitorService, org.apache.oozie.service.SparkConfigurationService</value> - </condition> + <definition xsi:type="configure" id="biginsights_4_2_oozie_server_update_configurations" summary="Updating oozie-site configurations"> + <type>oozie-site</type> + <replace key="oozie.services" find="org.apache.oozie.service.JvmPauseMonitorService" replace-with="org.apache.oozie.service.JvmPauseMonitorService, org.apache.oozie.service.SparkConfigurationService"/> </definition> <definition xsi:type="configure" id="biginsights_4_2_oozie_server_update_environment_configurations" summary="Update oozie env"> <type>oozie-env</type> http://git-wip-us.apache.org/repos/asf/ambari/blob/a5ce6b42/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java index 88fc22d..f0469eb 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java @@ -116,7 +116,7 @@ public class TestActionDBAccessorImpl { clusters.addHost(serverHostName); clusters.addHost(hostName); - StackId stackId = new StackId("HDP-0.1"); + StackId stackId = new StackId("HDP-0.2"); clusters.addCluster(clusterName, stackId); db = injector.getInstance(ActionDBAccessorImpl.class); @@ -138,7 +138,7 @@ public class TestActionDBAccessorImpl { Assert.assertEquals(stageId, stage.getStageId()); stage.setHostRoleStatus(hostname, "HBASE_MASTER", HostRoleStatus.QUEUED); db.hostRoleScheduled(stage, hostname, "HBASE_MASTER"); - List<CommandReport> reports = new ArrayList<CommandReport>(); + List<CommandReport> reports = new ArrayList<>(); CommandReport cr = new CommandReport(); cr.setTaskId(1); cr.setActionId(StageUtils.getActionId(requestId, stageId)); @@ -166,7 +166,7 @@ public class TestActionDBAccessorImpl { Assert.assertEquals(stageId, stage.getStageId()); stage.setHostRoleStatus(hostname, "HBASE_MASTER", HostRoleStatus.ABORTED); db.hostRoleScheduled(stage, hostname, "HBASE_MASTER"); - List<CommandReport> reports = new ArrayList<CommandReport>(); + List<CommandReport> reports = new ArrayList<>(); CommandReport cr = new CommandReport(); cr.setTaskId(1); cr.setActionId(StageUtils.getActionId(requestId, stageId)); @@ -191,7 +191,7 @@ public class TestActionDBAccessorImpl { @Test public void testGetStagesInProgress() throws AmbariException { - List<Stage> stages = new ArrayList<Stage>(); + List<Stage> stages = new ArrayList<>(); stages.add(createStubStage(hostName, requestId, stageId)); stages.add(createStubStage(hostName, requestId, stageId + 1)); Request request = new Request(stages, "", clusters); @@ -454,7 +454,7 @@ public class TestActionDBAccessorImpl { @Test public void testGetRequestsByStatus() throws AmbariException { - List<Long> requestIds = new ArrayList<Long>(); + List<Long> requestIds = new ArrayList<>(); requestIds.add(requestId + 1); requestIds.add(requestId); populateActionDB(db, hostName, requestId, stageId); @@ -475,7 +475,7 @@ public class TestActionDBAccessorImpl { */ @Test public void testGetCompletedRequests() throws AmbariException { - List<Long> requestIds = new ArrayList<Long>(); + List<Long> requestIds = new ArrayList<>(); requestIds.add(requestId); requestIds.add(requestId + 1); @@ -502,7 +502,7 @@ public class TestActionDBAccessorImpl { @Test public void testGetRequestsByStatusWithParams() throws AmbariException { - List<Long> ids = new ArrayList<Long>(); + List<Long> ids = new ArrayList<>(); for (long l = 1; l <= 10; l++) { ids.add(l); @@ -517,20 +517,20 @@ public class TestActionDBAccessorImpl { // Select all requests actual = db.getRequestsByStatus(null, BaseRequest.DEFAULT_PAGE_SIZE, false); - expected = reverse(new ArrayList<Long>(ids)); + expected = reverse(new ArrayList<>(ids)); assertEquals("Request IDs not matches", expected, actual); actual = db.getRequestsByStatus(null, 4, false); - expected = reverse(new ArrayList<Long>(ids.subList(ids.size() - 4, ids.size()))); + expected = reverse(new ArrayList<>(ids.subList(ids.size() - 4, ids.size()))); assertEquals("Request IDs not matches", expected, actual); actual = db.getRequestsByStatus(null, 7, true); - expected = new ArrayList<Long>(ids.subList(0, 7)); + expected = new ArrayList<>(ids.subList(0, 7)); assertEquals("Request IDs not matches", expected, actual); } private <T> List<T> reverse(List<T> list) { - List<T> result = new ArrayList<T>(list); + List<T> result = new ArrayList<>(list); Collections.reverse(result); @@ -567,7 +567,7 @@ public class TestActionDBAccessorImpl { RoleCommand.START, new ServiceComponentHostStartEvent(Role.HBASE_REGIONSERVER .toString(), "host4", System.currentTimeMillis()), "cluster1", "HBASE", false, false); - List<Stage> stages = new ArrayList<Stage>(); + List<Stage> stages = new ArrayList<>(); stages.add(s); s.getOrderedHostRoleCommands().get(0).setStatus(HostRoleStatus.PENDING); s.getOrderedHostRoleCommands().get(1).setStatus(HostRoleStatus.IN_PROGRESS); @@ -582,7 +582,7 @@ public class TestActionDBAccessorImpl { db.persistActions(request); db.abortOperation(requestId); - List<Long> aborted = new ArrayList<Long>(); + List<Long> aborted = new ArrayList<>(); List<HostRoleCommand> commands = db.getRequestTasks(requestId); for(HostRoleCommand command : commands) { @@ -617,7 +617,7 @@ public class TestActionDBAccessorImpl { */ @Test public void testEntitiesCreatedWithIDs() throws Exception { - List<Stage> stages = new ArrayList<Stage>(); + List<Stage> stages = new ArrayList<>(); Stage stage = createStubStage(hostName, requestId, stageId); stages.add(stage); @@ -681,7 +681,7 @@ public class TestActionDBAccessorImpl { RoleCommand.START, null, "cluster1", "HBASE", false, false); } - List<Stage> stages = new ArrayList<Stage>(); + List<Stage> stages = new ArrayList<>(); stages.add(s); Request request = new Request(stages, "", clusters); request.setClusterHostInfo("clusterHostInfo"); @@ -691,7 +691,7 @@ public class TestActionDBAccessorImpl { hostRoleCommandDAO.findByRequest(request.getRequestId()); assertEquals(1002, entities.size()); - List<Long> taskIds = new ArrayList<Long>(); + List<Long> taskIds = new ArrayList<>(); for (HostRoleCommandEntity entity : entities) { taskIds.add(entity.getTaskId()); } @@ -710,7 +710,7 @@ public class TestActionDBAccessorImpl { private void populateActionDB(ActionDBAccessor db, String hostname, long requestId, long stageId) throws AmbariException { Stage s = createStubStage(hostname, requestId, stageId); - List<Stage> stages = new ArrayList<Stage>(); + List<Stage> stages = new ArrayList<>(); stages.add(s); Request request = new Request(stages, "", clusters); db.persistActions(request); @@ -720,7 +720,7 @@ public class TestActionDBAccessorImpl { ActionDBAccessor db, String hostname, long requestId, long stageId) throws AmbariException { - List<Stage> stages = new ArrayList<Stage>(); + List<Stage> stages = new ArrayList<>(); for (int i = 0; i < numberOfStages; i++) { Stage stage = createStubStage(hostname, requestId, stageId + i); stages.add(stage); @@ -734,7 +734,7 @@ public class TestActionDBAccessorImpl { long requestId, long stageId) throws AmbariException { Stage s = createStubStage(hostname, requestId, stageId); - List<Stage> stages = new ArrayList<Stage>(); + List<Stage> stages = new ArrayList<>(); stages.add(s); Request request = new Request(stages, "", clusters); @@ -747,7 +747,7 @@ public class TestActionDBAccessorImpl { long requestId, long stageId) throws AmbariException { Stage s = createStubStage(hostname, requestId, stageId); - List<Stage> stages = new ArrayList<Stage>(); + List<Stage> stages = new ArrayList<>(); stages.add(s); Request request = new Request(stages, "", clusters); @@ -783,7 +783,7 @@ public class TestActionDBAccessorImpl { RoleCommand.ACTIONEXECUTE, new ServiceComponentHostStartEvent(Role.HBASE_MASTER.toString(), hostname, System.currentTimeMillis()), "cluster1", "HBASE", false, false); - List<Stage> stages = new ArrayList<Stage>(); + List<Stage> stages = new ArrayList<>(); stages.add(s); final RequestResourceFilter resourceFilter = new RequestResourceFilter("HBASE", "HBASE_MASTER", null); List<RequestResourceFilter> resourceFilters = new @@ -800,7 +800,7 @@ public class TestActionDBAccessorImpl { s.setStageId(stageId); s.addServerActionCommand(serverActionName, null, Role.AMBARI_SERVER_ACTION, RoleCommand.ACTIONEXECUTE, clusterName, null, null, "command details", null, 300, false, false); - List<Stage> stages = new ArrayList<Stage>(); + List<Stage> stages = new ArrayList<>(); stages.add(s); Request request = new Request(stages, "", clusters); request.setClusterHostInfo(""); http://git-wip-us.apache.org/repos/asf/ambari/blob/a5ce6b42/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderHDP22Test.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderHDP22Test.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderHDP22Test.java index d13d5ca..221cc20 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderHDP22Test.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderHDP22Test.java @@ -137,6 +137,11 @@ public class UpgradeResourceProviderHDP22Test { StackEntity stackEntity = stackDAO.find("HDP", "2.2.0"); + clusters = injector.getInstance(Clusters.class); + StackId stackId = new StackId("HDP-2.2.0"); + clusters.addCluster("c1", stackId); + Cluster cluster = clusters.getCluster("c1"); + RepositoryVersionEntity repoVersionEntity = new RepositoryVersionEntity(); repoVersionEntity.setDisplayName("For Stack Version 2.2.0"); repoVersionEntity.setOperatingSystems(""); @@ -151,11 +156,9 @@ public class UpgradeResourceProviderHDP22Test { repoVersionEntity.setVersion("2.2.4.2"); repoVersionDao.create(repoVersionEntity); - clusters = injector.getInstance(Clusters.class); - - StackId stackId = new StackId("HDP-2.2.0"); - clusters.addCluster("c1", stackId); - Cluster cluster = clusters.getCluster("c1"); + // create the cluster version for + cluster.createClusterVersion(repoVersionEntity.getStackId(), repoVersionEntity.getVersion(), + "admin", RepositoryVersionState.INSTALLED); helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion()); cluster.createClusterVersion(stackId, stackId.getStackVersion(), "admin", RepositoryVersionState.INSTALLING); http://git-wip-us.apache.org/repos/asf/ambari/blob/a5ce6b42/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java index a303167..c9c0dd0 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java @@ -149,6 +149,7 @@ public class UpgradeActionTest { private RepositoryVersionEntity repositoryVersion2110; private RepositoryVersionEntity repositoryVersion2111; private RepositoryVersionEntity repositoryVersion2201; + private RepositoryVersionEntity repositoryVersion2202; @Before public void setup() throws Exception { @@ -168,6 +169,7 @@ public class UpgradeActionTest { repositoryVersion2110 = m_helper.getOrCreateRepositoryVersion(HDP_21_STACK, HDP_2_1_1_0); repositoryVersion2111 = m_helper.getOrCreateRepositoryVersion(HDP_21_STACK, HDP_2_1_1_1); repositoryVersion2201 = m_helper.getOrCreateRepositoryVersion(HDP_22_STACK, HDP_2_2_0_1); + repositoryVersion2202 = m_helper.getOrCreateRepositoryVersion(HDP_22_STACK, HDP_2_2_0_2); } @After @@ -211,7 +213,13 @@ public class UpgradeActionTest { hostVersionDAO.create(entity); } - private void makeTwoUpgradesWhereLastDidNotComplete(StackId sourceStack, String sourceRepo, StackId midStack, String midRepo, StackId targetStack, String targetRepo) throws Exception { + private void makeTwoUpgradesWhereLastDidNotComplete( + RepositoryVersionEntity sourceRepositoryVersion, RepositoryVersionEntity midRepositoryVersion, + RepositoryVersionEntity targetRepositoryVersion) throws Exception { + StackId sourceStack = sourceRepositoryVersion.getStackId(); + StackId midStack = midRepositoryVersion.getStackId(); + StackId targetStack = targetRepositoryVersion.getStackId(); + String hostName = "h1"; clusters.addCluster(clusterName, sourceStack); @@ -229,28 +237,28 @@ public class UpgradeActionTest { host.setHostAttributes(hostAttributes); // Create the starting repo version - c.createClusterVersion(sourceStack, sourceRepo, "admin", RepositoryVersionState.INSTALLING); - c.transitionClusterVersion(sourceStack, sourceRepo, RepositoryVersionState.CURRENT); + c.createClusterVersion(sourceStack, sourceRepositoryVersion.getVersion(), "admin", RepositoryVersionState.INSTALLING); + c.transitionClusterVersion(sourceStack, sourceRepositoryVersion.getVersion(), RepositoryVersionState.CURRENT); // Start upgrading the mid repo c.setDesiredStackVersion(midStack); - c.createClusterVersion(midStack, midRepo, "admin", RepositoryVersionState.INSTALLING); - c.transitionClusterVersion(midStack, midRepo, RepositoryVersionState.INSTALLED); - c.transitionClusterVersion(midStack, midRepo, RepositoryVersionState.CURRENT); + c.createClusterVersion(midStack, midRepositoryVersion.getVersion(), "admin", RepositoryVersionState.INSTALLING); + c.transitionClusterVersion(midStack, midRepositoryVersion.getVersion(), RepositoryVersionState.INSTALLED); + c.transitionClusterVersion(midStack, midRepositoryVersion.getVersion(), RepositoryVersionState.CURRENT); // Set original version as INSTALLED - c.transitionClusterVersion(sourceStack, sourceRepo, RepositoryVersionState.INSTALLED); + c.transitionClusterVersion(sourceStack, sourceRepositoryVersion.getVersion(), RepositoryVersionState.INSTALLED); // Notice that we have not yet changed the cluster current stack to the mid stack to simulate // the user skipping this step. c.setDesiredStackVersion(targetStack); - c.createClusterVersion(targetStack, targetRepo, "admin", RepositoryVersionState.INSTALLING); - c.transitionClusterVersion(targetStack, targetRepo, RepositoryVersionState.INSTALLED); + c.createClusterVersion(targetStack, targetRepositoryVersion.getVersion(), "admin", RepositoryVersionState.INSTALLING); + c.transitionClusterVersion(targetStack, targetRepositoryVersion.getVersion(), RepositoryVersionState.INSTALLED); // Create a host version for the starting repo in INSTALLED HostVersionEntity entitySource = new HostVersionEntity(); entitySource.setHostEntity(hostDAO.findByName(hostName)); - entitySource.setRepositoryVersion(repoVersionDAO.findByStackAndVersion(sourceStack, sourceRepo)); + entitySource.setRepositoryVersion(repoVersionDAO.findByStackAndVersion(sourceStack, sourceRepositoryVersion.getVersion())); entitySource.setState(RepositoryVersionState.INSTALL_FAILED); hostVersionDAO.create(entitySource); @@ -261,9 +269,11 @@ public class UpgradeActionTest { // Create a host version for the target repo in UPGRADED HostVersionEntity entityTarget = new HostVersionEntity(); entityTarget.setHostEntity(hostDAO.findByName(hostName)); - entityTarget.setRepositoryVersion(repoVersionDAO.findByStackAndVersion(targetStack, targetRepo)); + entityTarget.setRepositoryVersion(repoVersionDAO.findByStackAndVersion(targetStack, targetRepositoryVersion.getVersion())); entityTarget.setState(RepositoryVersionState.INSTALLED); hostVersionDAO.create(entityTarget); + + createUpgrade(c, "", Direction.DOWNGRADE, midRepositoryVersion, targetRepositoryVersion); } private void createUpgradeClusterAndSourceRepo(StackId sourceStack, String sourceRepo, @@ -520,22 +530,13 @@ public class UpgradeActionTest { */ @Test public void testFinalizeDowngradeWhenDidNotFinalizePreviousUpgrade() throws Exception { - StackId sourceStack = HDP_21_STACK; - StackId midStack = HDP_22_STACK; - StackId targetStack = HDP_22_STACK; - - String sourceRepo = HDP_2_1_1_0; - String midRepo = HDP_2_2_0_1; - String targetRepo = HDP_2_2_0_2; + RepositoryVersionEntity sourceRepositoryVersion = repositoryVersion2110; + RepositoryVersionEntity midRepositoryVersion = repositoryVersion2201; + RepositoryVersionEntity targetRepositoryVersion = repositoryVersion2202; - makeTwoUpgradesWhereLastDidNotComplete(sourceStack, sourceRepo, midStack, midRepo, targetStack, targetRepo); + makeTwoUpgradesWhereLastDidNotComplete(sourceRepositoryVersion, midRepositoryVersion, targetRepositoryVersion); Map<String, String> commandParams = new HashMap<>(); - commandParams.put(FinalizeUpgradeAction.UPGRADE_DIRECTION_KEY, "downgrade"); - commandParams.put(FinalizeUpgradeAction.VERSION_KEY, midRepo); - commandParams.put(FinalizeUpgradeAction.ORIGINAL_STACK_KEY, sourceStack.getStackId()); - commandParams.put(FinalizeUpgradeAction.TARGET_STACK_KEY, targetStack.getStackId()); - ExecutionCommand executionCommand = new ExecutionCommand(); executionCommand.setCommandParams(commandParams); executionCommand.setClusterName(clusterName);