You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jo...@apache.org on 2017/04/26 18:01:13 UTC

[07/34] ambari git commit: AMBARI-20835. Unable to proceed from manual prompt in EU wizard due to IllegalArgumentException (ncole)

AMBARI-20835. Unable to proceed from manual prompt in EU wizard due to IllegalArgumentException (ncole)


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

Branch: refs/heads/branch-feature-AMBARI-12556
Commit: 4b672348dacb96466275b8bfa2c41b62885f993c
Parents: 0197813
Author: Nate Cole <nc...@hortonworks.com>
Authored: Mon Apr 24 16:00:23 2017 -0400
Committer: Nate Cole <nc...@hortonworks.com>
Committed: Mon Apr 24 17:09:13 2017 -0400

----------------------------------------------------------------------
 .../actionmanager/ActionDBAccessorImpl.java     |  5 ++-
 .../server/orm/dao/HostRoleCommandDAO.java      |  2 +-
 .../FixCapacitySchedulerOrderingPolicy.java     |  5 +++
 .../server/state/cluster/ClustersImpl.java      |  4 ---
 .../server/actionmanager/TestActionManager.java | 36 ++++++++++++++++++++
 .../AmbariManagementControllerTest.java         |  9 +++--
 6 files changed, 53 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/4b672348/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java
index 8c4eae8..4b7e71d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java
@@ -377,6 +377,7 @@ public class ActionDBAccessorImpl implements ActionDBAccessor {
       stageDAO.create(stageEntity);
 
       List<HostRoleCommand> orderedHostRoleCommands = stage.getOrderedHostRoleCommands();
+      List<HostRoleCommandEntity> hostRoleCommandEntities = new ArrayList<>();
 
       for (HostRoleCommand hostRoleCommand : orderedHostRoleCommands) {
         hostRoleCommand.setRequestId(requestId);
@@ -384,8 +385,8 @@ public class ActionDBAccessorImpl implements ActionDBAccessor {
         HostRoleCommandEntity hostRoleCommandEntity = hostRoleCommand.constructNewPersistenceEntity();
         hostRoleCommandEntity.setStage(stageEntity);
         hostRoleCommandDAO.create(hostRoleCommandEntity);
+        hostRoleCommandEntities.add(hostRoleCommandEntity);
 
-        assert hostRoleCommandEntity.getTaskId() != null;
         hostRoleCommand.setTaskId(hostRoleCommandEntity.getTaskId());
 
         String prefix = "";
@@ -442,6 +443,7 @@ public class ActionDBAccessorImpl implements ActionDBAccessor {
         roleSuccessCriteriaDAO.create(roleSuccessCriteriaEntity);
       }
 
+      stageEntity.setHostRoleCommands(hostRoleCommandEntities);
       stageEntity = stageDAO.merge(stageEntity);
     }
 
@@ -516,6 +518,7 @@ public class ActionDBAccessorImpl implements ActionDBAccessor {
     long now = System.currentTimeMillis();
 
     List<Long> requestsToCheck = new ArrayList<>();
+    List<Long> abortedCommandUpdates = new ArrayList<>();
 
     List<HostRoleCommandEntity> commandEntities = hostRoleCommandDAO.findByPKs(taskReports.keySet());
     List<HostRoleCommandEntity> commandEntitiesToMerge = new ArrayList<>();

http://git-wip-us.apache.org/repos/asf/ambari/blob/4b672348/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 6b34575..58a4180 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
@@ -737,7 +737,7 @@ public class HostRoleCommandDAO {
   @TransactionalLock(lockArea = LockArea.HRC_STATUS_CACHE, lockType = LockType.WRITE)
   public void remove(HostRoleCommandEntity entity) {
     EntityManager entityManager = entityManagerProvider.get();
-    entityManager.remove(merge(entity));
+    entityManager.remove(entity);
     invalidateHostRoleCommandStatusSummaryCache(entity);
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/4b672348/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FixCapacitySchedulerOrderingPolicy.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FixCapacitySchedulerOrderingPolicy.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FixCapacitySchedulerOrderingPolicy.java
index fbb88d8..92f6e50 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FixCapacitySchedulerOrderingPolicy.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FixCapacitySchedulerOrderingPolicy.java
@@ -66,6 +66,11 @@ public class FixCapacitySchedulerOrderingPolicy extends AbstractServerAction {
     Cluster cluster = clusters.getCluster(clusterName);
     Config config = cluster.getDesiredConfigByType(SOURCE_CONFIG_TYPE);
 
+    if (null == config) {
+      return createCommandReport(0, HostRoleStatus.COMPLETED, "{}",
+          String.format("The cluster does not have %s defined.", SOURCE_CONFIG_TYPE), "");
+    }
+
     Map<String, String> properties = config.getProperties();
 
     Set<String> parentQueueNames = new HashSet<>();

http://git-wip-us.apache.org/repos/asf/ambari/blob/4b672348/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
index 2bc1e68..99bc781 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
@@ -811,10 +811,6 @@ public class ClustersImpl implements Clusters {
       }
     }
 
-
-    entity.setHostRoleCommandEntities(null);
-    hostRoleCommandDAO.removeByHostId(entity.getHostId());
-
     entity.setHostStateEntity(null);
     hostStateDAO.removeByHostId(entity.getHostId());
     hostConfigMappingDAO.removeByHostId(entity.getHostId());

http://git-wip-us.apache.org/repos/asf/ambari/blob/4b672348/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java
index e12461d..fbd7c4e 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java
@@ -26,10 +26,12 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
 
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.List;
 
 import org.apache.ambari.server.AmbariException;
@@ -42,11 +44,16 @@ import org.apache.ambari.server.audit.AuditLogger;
 import org.apache.ambari.server.events.publishers.JPAEventPublisher;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.dao.StageDAO;
+import org.apache.ambari.server.orm.entities.HostRoleCommandEntity;
+import org.apache.ambari.server.orm.entities.StageEntity;
+import org.apache.ambari.server.orm.entities.StageEntityPK;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostStartEvent;
 import org.apache.ambari.server.utils.CommandUtils;
 import org.apache.ambari.server.utils.StageUtils;
+import org.apache.commons.collections.CollectionUtils;
 import org.easymock.EasyMock;
 import org.junit.After;
 import org.junit.Before;
@@ -286,4 +293,33 @@ public class TestActionManager {
 
     verify(queue, db, clusters);
   }
+
+  /**
+   * Tests whether {@link ActionDBAccessor#persistActions(Request)} associates tasks with their
+   * stages.  Improvements to {@code Stage} processing exposed the fact that the association wasn't
+   * being made, and JPA didn't know of the Stage-to-Tasks child relationship.
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testPersistCommandsWithStages() throws Exception {
+    ActionDBAccessor db = injector.getInstance(ActionDBAccessorImpl.class);
+
+    populateActionDBWithTwoCommands(db, hostname);
+
+    List<Stage> stages = db.getAllStages(requestId);
+    assertEquals(1, stages.size());
+    Stage stage = stages.get(0);
+
+    StageEntityPK pk = new StageEntityPK();
+    pk.setRequestId(stage.getRequestId());
+    pk.setStageId(stage.getStageId());
+
+    StageDAO dao = injector.getInstance(StageDAO.class);
+    StageEntity stageEntity = dao.findByPK(pk);
+    assertNotNull(stageEntity);
+
+    Collection<HostRoleCommandEntity> commandEntities = stageEntity.getHostRoleCommands();
+    assertTrue(CollectionUtils.isNotEmpty(commandEntities));
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/4b672348/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
index 554e089..628a56f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
@@ -158,6 +158,7 @@ import org.easymock.Capture;
 import org.easymock.EasyMock;
 import org.junit.After;
 import org.junit.AfterClass;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
@@ -174,8 +175,6 @@ import com.google.gson.reflect.TypeToken;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
 
-import junit.framework.Assert;
-
 public class AmbariManagementControllerTest {
 
   private static final Logger LOG =
@@ -9018,6 +9017,8 @@ public class AmbariManagementControllerTest {
 
     Assert.assertNull(topologyHostInfoDAO.findByHostname(host1));
 
+    Long firstHostId = clusters.getHost(host1).getHostId();
+
     // Deletion without specifying cluster should be successful
     requests.clear();
     requests.add(new HostRequest(host1, null, null));
@@ -9031,6 +9032,10 @@ public class AmbariManagementControllerTest {
     Assert.assertFalse(clusters.getClustersForHost(host1).contains(cluster));
     Assert.assertNull(topologyHostInfoDAO.findByHostname(host1));
 
+    // verify there are no host role commands for the host
+    List<HostRoleCommandEntity> tasks = hostRoleCommandDAO.findByHostId(firstHostId);
+    assertEquals(0, tasks.size());
+
     // Case 3: Delete host that is still part of the cluster, and specify the cluster_name in the request
     requests.clear();
     requests.add(new HostRequest(host2, cluster1, null));