Return-Path: X-Original-To: apmail-incubator-ambari-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-ambari-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1478D100FC for ; Thu, 11 Apr 2013 22:55:13 +0000 (UTC) Received: (qmail 15852 invoked by uid 500); 11 Apr 2013 22:55:13 -0000 Delivered-To: apmail-incubator-ambari-commits-archive@incubator.apache.org Received: (qmail 15825 invoked by uid 500); 11 Apr 2013 22:55:13 -0000 Mailing-List: contact ambari-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@incubator.apache.org Delivered-To: mailing list ambari-commits@incubator.apache.org Received: (qmail 15816 invoked by uid 99); 11 Apr 2013 22:55:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Apr 2013 22:55:12 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Apr 2013 22:55:10 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id E90A023889D5; Thu, 11 Apr 2013 22:54:50 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1467125 - in /incubator/ambari/trunk: CHANGES.txt ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java Date: Thu, 11 Apr 2013 22:54:50 -0000 To: ambari-commits@incubator.apache.org From: smohanty@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130411225450.E90A023889D5@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: smohanty Date: Thu Apr 11 22:54:50 2013 New Revision: 1467125 URL: http://svn.apache.org/r1467125 Log: AMBARI-1901. Add additional tests for verifying request behavior based on host role command results. (smohanty) Modified: incubator/ambari/trunk/CHANGES.txt incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java Modified: incubator/ambari/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1467125&r1=1467124&r2=1467125&view=diff ============================================================================== --- incubator/ambari/trunk/CHANGES.txt (original) +++ incubator/ambari/trunk/CHANGES.txt Thu Apr 11 22:54:50 2013 @@ -692,6 +692,9 @@ Trunk (unreleased changes): BUG FIXES + AMBARI-1901. Add additional tests for verifying request behavior based on + host role command results. (smohanty) + AMBARI-1899. ambari-reset does not respect -s. (swagle) AMBARI-1898. Update stack definitions for 1.3.0. (smohanty) Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java?rev=1467125&r1=1467124&r2=1467125&view=diff ============================================================================== --- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java (original) +++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java Thu Apr 11 22:54:50 2013 @@ -181,6 +181,7 @@ public class HeartBeatHandler { throws AmbariException { List reports = heartbeat.getReports(); for (CommandReport report : reports) { + LOG.debug("Received command report: " + report); Cluster cl = clusterFsm.getCluster(report.getClusterName()); String service = report.getServiceName(); if (service == null || "".equals(service)) { Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java?rev=1467125&r1=1467124&r2=1467125&view=diff ============================================================================== --- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java (original) +++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java Thu Apr 11 22:54:50 2013 @@ -46,12 +46,17 @@ import org.apache.ambari.server.state.Cl import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.ServiceComponent; import org.apache.ambari.server.state.ServiceComponentHost; +import org.apache.ambari.server.state.svccomphost.ServiceComponentHostInstallEvent; import org.apache.ambari.server.state.svccomphost.ServiceComponentHostUpgradeEvent; import org.apache.ambari.server.utils.StageUtils; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class TestActionScheduler { + private static final Logger log = LoggerFactory.getLogger(TestActionScheduler.class); + /** * This test sends a new action to the action scheduler and verifies that the action * shows up in the action queue. @@ -274,6 +279,139 @@ public class TestActionScheduler { Assert.assertEquals(HostRoleStatus.ABORTED, stages.get(1).getHostRoleStatus(hostname, "DATANODE")); } + /** + * Tests that the whole request is aborted when there are no QUEUED tasks for a role and + * success factor is not met. As long as there is one QUEUED task the request is not + * aborted. + * @throws Exception + */ + @Test + public void testRequestAbortsOnlyWhenNoQueuedTaskAndSuccessFactorUnmet() throws Exception { + ActionQueue aq = new ActionQueue(); + Clusters fsm = mock(Clusters.class); + Cluster oneClusterMock = mock(Cluster.class); + Service serviceObj = mock(Service.class); + ServiceComponent scomp = mock(ServiceComponent.class); + ServiceComponentHost sch = mock(ServiceComponentHost.class); + when(fsm.getCluster(anyString())).thenReturn(oneClusterMock); + when(oneClusterMock.getService(anyString())).thenReturn(serviceObj); + when(serviceObj.getServiceComponent(anyString())).thenReturn(scomp); + when(scomp.getServiceComponentHost(anyString())).thenReturn(sch); + when(serviceObj.getCluster()).thenReturn(oneClusterMock); + + ActionDBAccessor db = new ActionDBInMemoryImpl(); + List stages = new ArrayList(); + + long now = System.currentTimeMillis(); + Stage stage = new Stage(1, "/tmp", "cluster1", "testRequestFailureBasedOnSuccessFactor"); + stage.setStageId(1); + + addHostRoleExecutionCommand(now, stage, Role.SQOOP, Service.Type.SQOOP, + RoleCommand.INSTALL, "host1", "cluster1"); + + addHostRoleExecutionCommand(now, stage, Role.OOZIE_CLIENT, Service.Type.OOZIE, + RoleCommand.INSTALL, "host1", "cluster1"); + + addHostRoleExecutionCommand(now, stage, Role.MAPREDUCE_CLIENT, Service.Type.MAPREDUCE, + RoleCommand.INSTALL, "host1", "cluster1"); + + addHostRoleExecutionCommand(now, stage, Role.HBASE_CLIENT, Service.Type.HBASE, + RoleCommand.INSTALL, "host1", "cluster1"); + + addHostRoleExecutionCommand(now, stage, Role.GANGLIA_MONITOR, Service.Type.GANGLIA, + RoleCommand.INSTALL, "host1", "cluster1"); + + addHostRoleExecutionCommand(now, stage, Role.HBASE_CLIENT, Service.Type.HBASE, + RoleCommand.INSTALL, "host2", "cluster1"); + + addHostRoleExecutionCommand(now, stage, Role.GANGLIA_MONITOR, Service.Type.GANGLIA, + RoleCommand.INSTALL, "host2", "cluster1"); + + stages.add(stage); + + HostRoleStatus[] statusesAtIterOne = {HostRoleStatus.QUEUED, HostRoleStatus.QUEUED, + HostRoleStatus.QUEUED, HostRoleStatus.QUEUED, HostRoleStatus.FAILED, + HostRoleStatus.FAILED, HostRoleStatus.QUEUED, HostRoleStatus.QUEUED}; + for (int index = 0; index < stage.getOrderedHostRoleCommands().size(); index++) { + stage.getOrderedHostRoleCommands().get(index).setTaskId(index + 1); + stage.getOrderedHostRoleCommands().get(index).setStatus(statusesAtIterOne[index]); + } + + stage.setLastAttemptTime("host1", Role.SQOOP.toString(), now); + stage.setLastAttemptTime("host1", Role.MAPREDUCE_CLIENT.toString(), now); + stage.setLastAttemptTime("host1", Role.OOZIE_CLIENT.toString(), now); + stage.setLastAttemptTime("host1", Role.GANGLIA_MONITOR.toString(), now); + stage.setLastAttemptTime("host1", Role.HBASE_CLIENT.toString(), now); + stage.setLastAttemptTime("host2", Role.GANGLIA_MONITOR.toString(), now); + stage.setLastAttemptTime("host2", Role.HBASE_CLIENT.toString(), now); + + db.persistActions(stages); + + ActionScheduler scheduler = new ActionScheduler(100, 10000, db, aq, fsm, 3, + new HostsMap((String) null), new ServerActionManagerImpl(fsm)); + ActionManager am = new ActionManager( + 2, 10000, aq, fsm, db, new HostsMap((String) null), new ServerActionManagerImpl(fsm)); + + scheduler.doWork(); + + // Request is not aborted because all roles are in progress + HostRoleStatus[] expectedStatusesAtIterOne = {HostRoleStatus.QUEUED, HostRoleStatus.QUEUED, + HostRoleStatus.QUEUED, HostRoleStatus.QUEUED, HostRoleStatus.FAILED, + HostRoleStatus.FAILED, HostRoleStatus.QUEUED, HostRoleStatus.QUEUED}; + for (int index = 0; index < stage.getOrderedHostRoleCommands().size(); index++) { + log.info(stage.getOrderedHostRoleCommands().get(index).toString()); + Assert.assertEquals(expectedStatusesAtIterOne[index], + stage.getOrderedHostRoleCommands().get(index).getStatus()); + } + + HostRoleStatus[] statusesAtIterTwo = {HostRoleStatus.QUEUED, HostRoleStatus.QUEUED, + HostRoleStatus.QUEUED, HostRoleStatus.QUEUED, HostRoleStatus.FAILED, + HostRoleStatus.FAILED, HostRoleStatus.QUEUED, HostRoleStatus.COMPLETED}; + for (int index = 0; index < stage.getOrderedHostRoleCommands().size(); index++) { + stage.getOrderedHostRoleCommands().get(index).setStatus(statusesAtIterTwo[index]); + } + + scheduler.doWork(); + + // Request is not aborted because GANGLIA_MONITOR's success factor (0.5) is met + HostRoleStatus[] expectedStatusesAtIterTwo = {HostRoleStatus.QUEUED, HostRoleStatus.QUEUED, + HostRoleStatus.QUEUED, HostRoleStatus.QUEUED, HostRoleStatus.FAILED, + HostRoleStatus.FAILED, HostRoleStatus.QUEUED, HostRoleStatus.COMPLETED}; + for (int index = 0; index < stage.getOrderedHostRoleCommands().size(); index++) { + log.info(stage.getOrderedHostRoleCommands().get(index).toString()); + Assert.assertEquals(expectedStatusesAtIterTwo[index], + stage.getOrderedHostRoleCommands().get(index).getStatus()); + } + + HostRoleStatus[] statusesAtIterThree = {HostRoleStatus.QUEUED, HostRoleStatus.QUEUED, + HostRoleStatus.QUEUED, HostRoleStatus.QUEUED, HostRoleStatus.FAILED, + HostRoleStatus.FAILED, HostRoleStatus.FAILED, HostRoleStatus.COMPLETED}; + for (int index = 0; index < stage.getOrderedHostRoleCommands().size(); index++) { + stage.getOrderedHostRoleCommands().get(index).setStatus(statusesAtIterThree[index]); + } + + scheduler.doWork(); + + // Request is aborted because HBASE_CLIENT's success factor (1) is not met + HostRoleStatus[] expectedStatusesAtIterThree = {HostRoleStatus.ABORTED, HostRoleStatus.ABORTED, + HostRoleStatus.ABORTED, HostRoleStatus.ABORTED, HostRoleStatus.FAILED, + HostRoleStatus.FAILED, HostRoleStatus.FAILED, HostRoleStatus.COMPLETED}; + for (int index = 0; index < stage.getOrderedHostRoleCommands().size(); index++) { + log.info(stage.getOrderedHostRoleCommands().get(index).toString()); + Assert.assertEquals(expectedStatusesAtIterThree[index], + stage.getOrderedHostRoleCommands().get(index).getStatus()); + } + } + + private void addHostRoleExecutionCommand(long now, Stage stage, Role role, Service.Type service, + RoleCommand command, String host, String cluster) { + stage.addHostRoleExecutionCommand(host, role, command, + new ServiceComponentHostInstallEvent(role.toString(), host, now, "HDP-0.2"), + cluster, service.toString()); + stage.getExecutionCommandWrapper(host, + role.toString()).getExecutionCommand(); + } + @Test public void testRequestFailureBasedOnSuccessFactor() throws Exception { ActionQueue aq = new ActionQueue();