AMBARI-21749. Remove DB consistency check for topology tables (magyari_sandor)

(cherry picked from commit 5c09d0760eb62ff18f120b0688ff4eb7e9b63227)

Change-Id: If7814db6100e121aaa88b3ffb69a9a4152a59ebe


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

Branch: refs/heads/2.5-maint
Commit: 5a80b5274a7aad0312ac174fa3e6f247687c35b1
Parents: 2030db8
Author: Sandor Magyari <[email protected]>
Authored: Fri Aug 18 13:13:29 2017 +0200
Committer: Sumit Mohanty <[email protected]>
Committed: Sat Aug 19 09:28:13 2017 -0700

----------------------------------------------------------------------
 .../checks/DatabaseConsistencyCheckHelper.java  | 62 -------------------
 .../server/topology/PersistedStateImpl.java     | 23 +++----
 .../DatabaseConsistencyCheckHelperTest.java     | 63 --------------------
 3 files changed, 13 insertions(+), 135 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/5a80b527/ambari-server/src/main/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelper.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelper.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelper.java
index 533fad7..d59e676 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelper.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelper.java
@@ -187,7 +187,6 @@ public class DatabaseConsistencyCheckHelper {
       checkForHostsWithoutState();
       checkHostComponentStatesCountEqualsHostComponentsDesiredStates();
       checkServiceConfigs();
-      checkTopologyTables();
       checkForLargeTables();
       checkConfigGroupHostMapping(true);
       LOG.info("******************************* Check database completed 
*******************************");
@@ -493,67 +492,6 @@ public class DatabaseConsistencyCheckHelper {
     }
   }
 
-
-  /**
-   * This method checks that for each row in topology_request there is at 
least one row in topology_logical_request,
-   * topology_host_request, topology_host_task, topology_logical_task.
-   * */
-  static void checkTopologyTables() {
-    LOG.info("Checking Topology tables");
-
-    String SELECT_REQUEST_COUNT_QUERY = "select count(tpr.id) from 
topology_request tpr";
-
-    String SELECT_JOINED_COUNT_QUERY = "select count(DISTINCT tpr.id) from 
topology_request tpr join " +
-      "topology_logical_request tlr on tpr.id = tlr.request_id";
-
-    String SELECT_HOST_REQUEST_COUNT_QUERY = "select count(thr.id) from 
topology_host_request thr";
-
-    String SELECT_HOST_JOINED_COUNT_QUERY = "select count(DISTINCT thr.id) 
from topology_host_request thr join " +
-            "topology_host_task tht on thr.id = tht.host_request_id join 
topology_logical_task " +
-            "tlt on tht.id = tlt.host_task_id";
-
-    Statement statement = null;
-
-    if (connection == null) {
-      if (dbAccessor == null) {
-        dbAccessor = injector.getInstance(DBAccessor.class);
-      }
-      connection = dbAccessor.getConnection();
-    }
-
-    try {
-      statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, 
ResultSet.CONCUR_UPDATABLE);
-
-      int topologyRequestCount = runQuery(statement, 
SELECT_REQUEST_COUNT_QUERY);
-      int topologyRequestTablesJoinedCount = runQuery(statement, 
SELECT_JOINED_COUNT_QUERY);
-
-      if (topologyRequestCount != topologyRequestTablesJoinedCount) {
-        error("Your topology request hierarchy is not complete for each row in 
topology_request should exist " +
-          "at least one row in topology_logical_request");
-      }
-
-      int topologyHostRequestCount = runQuery(statement, 
SELECT_HOST_REQUEST_COUNT_QUERY);
-      int topologyHostRequestTablesJoinedCount = runQuery(statement, 
SELECT_HOST_JOINED_COUNT_QUERY);
-
-      if (topologyHostRequestCount != topologyHostRequestTablesJoinedCount) {
-        error("Your topology request hierarchy is not complete for each row in 
topology_host_request should exist " +
-                "at least one row in topology_host_task, 
topology_logical_task.");
-      }
-
-    } catch (SQLException e) {
-      LOG.error("Exception occurred during topology request tables check: ", 
e);
-    } finally {
-      if (statement != null) {
-        try {
-          statement.close();
-        } catch (SQLException e) {
-          LOG.error("Exception occurred during statement closing procedure: ", 
e);
-        }
-      }
-    }
-
-  }
-
   private static int runQuery(Statement statement, String query) {
     ResultSet rs = null;
     int result = 0;

http://git-wip-us.apache.org/repos/asf/ambari/blob/5a80b527/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java
index 1def4df..ebc5fbc 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java
@@ -223,18 +223,21 @@ public class PersistedStateImpl implements PersistedState 
{
       }
 
       TopologyLogicalRequestEntity logicalRequestEntity = 
entity.getTopologyLogicalRequestEntity();
-      Long logicalId = logicalRequestEntity.getId();
+      if (logicalRequestEntity != null) {
+        try {
+          Long logicalId = logicalRequestEntity.getId();
 
-      try {
-        //todo: fix initialization of ActionManager.requestCounter to account 
for logical requests
-        //todo: until this is fixed, increment the counter for every recovered 
logical request
-        //todo: this will cause gaps in the request id's after recovery
-        ambariContext.getNextRequestId();
-        
allRequests.get(clusterTopology).add(logicalRequestFactory.createRequest(
-            logicalId, replayedRequest, clusterTopology, 
logicalRequestEntity));
-      } catch (AmbariException e) {
-        throw new RuntimeException("Failed to construct logical request during 
replay: " + e, e);
+          //todo: fix initialization of ActionManager.requestCounter to 
account for logical requests
+          //todo: until this is fixed, increment the counter for every 
recovered logical request
+          //todo: this will cause gaps in the request id's after recovery
+          ambariContext.getNextRequestId();
+          
allRequests.get(clusterTopology).add(logicalRequestFactory.createRequest(
+                  logicalId, replayedRequest, clusterTopology, 
logicalRequestEntity));
+        } catch (AmbariException e) {
+          throw new RuntimeException("Failed to construct logical request 
during replay: " + e, e);
+        }
       }
+
     }
 
     return allRequests;

http://git-wip-us.apache.org/repos/asf/ambari/blob/5a80b527/ambari-server/src/test/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelperTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelperTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelperTest.java
index 9e85fa2..1e4cf58 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelperTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelperTest.java
@@ -189,69 +189,6 @@ public class DatabaseConsistencyCheckHelperTest {
   }
 
   @Test
-  public void testCheckTopologyTablesAreConsistent() throws Exception {
-    testCheckTopologyTablesConsistent(2);
-    
Assert.assertFalse(DatabaseConsistencyCheckHelper.getLastCheckResult().isError());
-  }
-
-  @Test
-  public void testCheckTopologyTablesAreNotConsistent() throws Exception {
-    testCheckTopologyTablesConsistent(1);
-    
Assert.assertTrue(DatabaseConsistencyCheckHelper.getLastCheckResult().isError());
-  }
-
-  private void testCheckTopologyTablesConsistent(int resultCount) throws 
Exception {
-    EasyMockSupport easyMockSupport = new EasyMockSupport();
-
-    final DBAccessor mockDBDbAccessor = 
easyMockSupport.createNiceMock(DBAccessor.class);
-    final Connection mockConnection = 
easyMockSupport.createNiceMock(Connection.class);
-    final ResultSet mockCountResultSet = 
easyMockSupport.createNiceMock(ResultSet.class);
-    final ResultSet mockJoinResultSet = 
easyMockSupport.createNiceMock(ResultSet.class);
-    final Statement mockStatement = 
easyMockSupport.createNiceMock(Statement.class);
-
-    final StackManagerFactory mockStackManagerFactory = 
easyMockSupport.createNiceMock(StackManagerFactory.class);
-    final EntityManager mockEntityManager = 
easyMockSupport.createNiceMock(EntityManager.class);
-    final Clusters mockClusters = 
easyMockSupport.createNiceMock(Clusters.class);
-    final OsFamily mockOSFamily = 
easyMockSupport.createNiceMock(OsFamily.class);
-    final Injector mockInjector = Guice.createInjector(new AbstractModule() {
-      @Override
-      protected void configure() {
-
-        bind(StackManagerFactory.class).toInstance(mockStackManagerFactory);
-        bind(EntityManager.class).toInstance(mockEntityManager);
-        bind(DBAccessor.class).toInstance(mockDBDbAccessor);
-        bind(Clusters.class).toInstance(mockClusters);
-        bind(OsFamily.class).toInstance(mockOSFamily);
-      }
-    });
-
-    expect(mockConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, 
ResultSet.CONCUR_UPDATABLE)).andReturn(mockStatement);
-    expect(mockCountResultSet.next()).andReturn(true).once();
-    expect(mockCountResultSet.getInt(1)).andReturn(2);
-    expect(mockJoinResultSet.next()).andReturn(true).once();
-    expect(mockJoinResultSet.getInt(1)).andReturn(resultCount);
-    expect(mockStatement.executeQuery("select count(tpr.id) from 
topology_request tpr")).andReturn(mockCountResultSet);
-    expect(mockStatement.executeQuery("select count(DISTINCT tpr.id) from 
topology_request tpr join " +
-            "topology_logical_request tlr on tpr.id = 
tlr.request_id")).andReturn(mockJoinResultSet);
-
-    expect(mockStatement.executeQuery("select count(thr.id) from 
topology_host_request thr")).andReturn(mockCountResultSet);
-    expect(mockStatement.executeQuery("select count(DISTINCT thr.id) from 
topology_host_request thr join " +
-            "topology_host_task tht on thr.id = tht.host_request_id join 
topology_logical_task " +
-            "tlt on tht.id = tlt.host_task_id")).andReturn(mockJoinResultSet);
-
-    DatabaseConsistencyCheckHelper.setInjector(mockInjector);
-    DatabaseConsistencyCheckHelper.setConnection(mockConnection);
-
-    easyMockSupport.replayAll();
-
-
-    DatabaseConsistencyCheckHelper.checkTopologyTables();
-
-    easyMockSupport.verifyAll();
-
-  }
-
-  @Test
   public void 
testCheckHostComponentStatesCountEqualsHostComponentsDesiredStates() throws 
Exception {
     EasyMockSupport easyMockSupport = new EasyMockSupport();
 

Reply via email to