ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject ambari git commit: AMBARI-9984. RU: Inconsistent upgrade item statuses (ncole)
Date Mon, 09 Mar 2015 18:21:56 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.0.0 6b96bc4aa -> ba69c1d4d


AMBARI-9984. RU: Inconsistent upgrade item statuses (ncole)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/ba69c1d4
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/ba69c1d4
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/ba69c1d4

Branch: refs/heads/branch-2.0.0
Commit: ba69c1d4d6b1790c69127775defba2b1ccdfaa14
Parents: 6b96bc4
Author: Nate Cole <ncole@hortonworks.com>
Authored: Mon Mar 9 13:51:45 2015 -0400
Committer: Nate Cole <ncole@hortonworks.com>
Committed: Mon Mar 9 13:51:45 2015 -0400

----------------------------------------------------------------------
 .../controller/internal/CalculatedStatus.java   |   8 +-
 .../server/orm/dao/HostRoleCommandDAO.java      |   2 +-
 .../orm/entities/HostRoleCommandEntity.java     |   2 +-
 .../ambari/server/orm/dao/RequestDAOTest.java   | 151 ++++++++++++++++++-
 4 files changed, 151 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/ba69c1d4/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/CalculatedStatus.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/CalculatedStatus.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/CalculatedStatus.java
index 99c0a76..9a9bc8a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/CalculatedStatus.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/CalculatedStatus.java
@@ -281,8 +281,12 @@ public class CalculatedStatus {
       }
 
       HostRoleCommandStatusSummaryDTO summary = stageDto.get(stageId);
-      HostRoleStatus stageStatus = calculateSummaryStatus(summary.getCounts(),
-          summary.getTaskTotal(), summary.isStageSkippable());
+
+      int total = summary.getTaskTotal();
+      boolean skip = summary.isStageSkippable();
+      Map<HostRoleStatus, Integer> counts = calculateStatusCounts(summary.getTaskStatuses());
+
+      HostRoleStatus stageStatus = calculateSummaryStatus(counts, total, skip);
 
       stageStatuses.add(stageStatus);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/ba69c1d4/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java
index c5d447a..f9d21ad 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java
@@ -48,9 +48,9 @@ public class HostRoleCommandDAO {
 
   private static final String SUMMARY_DTO = String.format(
     "SELECT NEW %s(" +
+      "MAX(hrc.stage.skippable), " +
       "MIN(hrc.startTime), " +
       "MAX(hrc.endTime), " +
-      "MIN(hrc.stage.skippable), " +
       "hrc.stageId, " +
       "SUM(CASE WHEN hrc.status = :aborted THEN 1 ELSE 0 END), " +
       "SUM(CASE WHEN hrc.status = :completed THEN 1 ELSE 0 END), " +

http://git-wip-us.apache.org/repos/asf/ambari/blob/ba69c1d4/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
index 6ab5aac..c9877fb 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
@@ -160,7 +160,7 @@ public class HostRoleCommandEntity {
   @JoinColumns({@JoinColumn(name = "request_id", referencedColumnName = "request_id", nullable
= false), @JoinColumn(name = "stage_id", referencedColumnName = "stage_id", nullable = false)})
   private StageEntity stage;
 
-  @ManyToOne(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
+  @ManyToOne(cascade = {CascadeType.MERGE, CascadeType.REFRESH})
   @JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false)
   private HostEntity host;
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/ba69c1d4/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RequestDAOTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RequestDAOTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RequestDAOTest.java
index ffdcd6e..bae6fd5 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RequestDAOTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RequestDAOTest.java
@@ -17,14 +17,28 @@
  */
 package org.apache.ambari.server.orm.dao;
 
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.Role;
+import org.apache.ambari.server.RoleCommand;
+import org.apache.ambari.server.actionmanager.HostRoleStatus;
+import org.apache.ambari.server.controller.internal.CalculatedStatus;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.OrmTestHelper;
+import org.apache.ambari.server.orm.entities.ClusterEntity;
+import org.apache.ambari.server.orm.entities.HostEntity;
+import org.apache.ambari.server.orm.entities.HostRoleCommandEntity;
 import org.apache.ambari.server.orm.entities.RequestEntity;
+import org.apache.ambari.server.orm.entities.ResourceEntity;
+import org.apache.ambari.server.orm.entities.ResourceTypeEntity;
+import org.apache.ambari.server.orm.entities.StageEntity;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -40,14 +54,22 @@ import com.google.inject.persist.PersistService;
 public class RequestDAOTest {
   private Injector injector;
   private ClusterDAO clusterDAO;
-  
-  
+  StageDAO stageDAO;
+  HostRoleCommandDAO hostRoleCommandDAO;
+  HostDAO hostDAO;
+  RequestDAO requestDAO;
+
   @Before
   public void setup() throws Exception {
     injector = Guice.createInjector(new InMemoryDefaultTestModule());
     injector.getInstance(GuiceJpaInitializer.class);
 
     clusterDAO = injector.getInstance(ClusterDAO.class);
+    stageDAO = injector.getInstance(StageDAO.class);
+    hostRoleCommandDAO = injector.getInstance(HostRoleCommandDAO.class);
+    hostDAO = injector.getInstance(HostDAO.class);
+    requestDAO = injector.getInstance(RequestDAO.class);
+
   }
 
   @After
@@ -55,17 +77,130 @@ public class RequestDAOTest {
     injector.getInstance(PersistService.class).stop();
   }
 
-  
+
   @Test
   public void testFindAll() throws Exception {
     RequestDAO dao = injector.getInstance(RequestDAO.class);
-    
+
     Set<Long> set = Collections.emptySet();
-    
+
     List<RequestEntity> list = dao.findByPks(set);
-    
+
     Assert.assertEquals(0, list.size());
-    
   }
-  
+
+
+  @Test
+  public void testCalculatedStatus() throws Exception {
+    createGraph();
+
+    RequestEntity requestEntity = requestDAO.findByPK(100L);
+
+    // !!! accepted value
+    CalculatedStatus calc1 = CalculatedStatus.statusFromStageEntities(
+        requestEntity.getStages());
+
+    // !!! aggregated value
+    Map<Long, HostRoleCommandStatusSummaryDTO> map = hostRoleCommandDAO.findAggregateCounts(100L);
+    CalculatedStatus calc2 = CalculatedStatus.statusFromStageSummary(map,
+        map.keySet());
+
+    Assert.assertEquals(HostRoleStatus.IN_PROGRESS, calc1.getStatus());
+    Assert.assertEquals(calc1.getStatus(), calc2.getStatus());
+    Assert.assertEquals(calc1.getPercent(), calc2.getPercent(), 0.01d);
+
+    // !!! simulate an upgrade group
+    Set<Long> group = new HashSet<Long>();
+    group.add(2L);
+    group.add(3L);
+    group.add(4L);
+
+    // !!! accepted
+    List<StageEntity> stages = stageDAO.findByStageIds(requestEntity.getRequestId(),
group);
+    CalculatedStatus calc3 = CalculatedStatus.statusFromStageEntities(stages);
+
+    // !!! aggregated
+    CalculatedStatus calc4 = CalculatedStatus.statusFromStageSummary(map, group);
+
+    Assert.assertEquals(100d, calc3.getPercent(), 0.01d);
+    Assert.assertEquals(HostRoleStatus.COMPLETED, calc3.getStatus());
+    Assert.assertEquals(calc3.getPercent(), calc4.getPercent(), 0.01d);
+    Assert.assertEquals(calc3.getStatus(), calc4.getStatus());
+  }
+
+  private void createGraph() {
+    OrmTestHelper helper = injector.getInstance(OrmTestHelper.class);
+    helper.createDefaultData();
+
+
+    Long requestId = Long.valueOf(100L);
+    String hostName = "test_host1";
+
+    ResourceTypeEntity resourceTypeEntity =  new ResourceTypeEntity();
+    resourceTypeEntity.setId(ResourceTypeEntity.CLUSTER_RESOURCE_TYPE);
+    resourceTypeEntity.setName(ResourceTypeEntity.CLUSTER_RESOURCE_TYPE_NAME);
+
+    ResourceEntity resourceEntity = new ResourceEntity();
+    resourceEntity.setResourceType(resourceTypeEntity);
+
+    ClusterEntity clusterEntity = clusterDAO.findByName("test_cluster1");
+
+    RequestEntity requestEntity = new RequestEntity();
+    requestEntity.setRequestId(requestId);
+    requestEntity.setClusterId(clusterEntity.getClusterId());
+    requestEntity.setStages(new ArrayList<StageEntity>());
+    requestDAO.create(requestEntity);
+
+    HostEntity host = hostDAO.findByName(hostName);
+    host.setHostRoleCommandEntities(new ArrayList<HostRoleCommandEntity>());
+
+    long stageId = 1L;
+
+    stageId = createStages(stageId, 3, host, requestEntity, HostRoleStatus.COMPLETED, false);
+    stageId = createStages(stageId, 1, host, requestEntity, HostRoleStatus.FAILED, true);
+    stageId = createStages(stageId, 1, host, requestEntity, HostRoleStatus.IN_PROGRESS, false);
+    stageId = createStages(stageId, 3, host, requestEntity, HostRoleStatus.PENDING, false);
+
+    requestDAO.merge(requestEntity);
+  }
+
+  private long createStages(long startStageId, int count,
+      HostEntity he, RequestEntity re, HostRoleStatus status, boolean skipStage) {
+    long stageId = startStageId;
+
+    ClusterEntity clusterEntity = clusterDAO.findByName("test_cluster1");
+
+    for (int i = 0; i < count; i++) {
+      StageEntity stageEntity = new StageEntity();
+      stageEntity.setClusterId(clusterEntity.getClusterId());
+      stageEntity.setRequest(re);
+      stageEntity.setStageId(stageId);
+      stageEntity.setHostRoleCommands(new ArrayList<HostRoleCommandEntity>());
+      stageEntity.setSkippable(skipStage);
+      stageDAO.create(stageEntity);
+
+      re.getStages().add(stageEntity);
+
+      HostRoleCommandEntity commandEntity = new HostRoleCommandEntity();
+      commandEntity.setRequestId(re.getRequestId());
+      commandEntity.setStageId(stageId);
+      commandEntity.setRoleCommand(RoleCommand.INSTALL);
+      commandEntity.setStatus(status);
+      commandEntity.setRole(Role.DATANODE);
+      commandEntity.setHost(he);
+      commandEntity.setStage(stageEntity);
+      hostRoleCommandDAO.create(commandEntity);
+
+      he.getHostRoleCommandEntities().add(commandEntity);
+      he = hostDAO.merge(he);
+
+      stageEntity.getHostRoleCommands().add(commandEntity);
+      stageDAO.merge(stageEntity);
+
+      stageId++;
+    }
+
+    return stageId;
+  }
+
 }


Mime
View raw message