ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stoa...@apache.org
Subject ambari git commit: AMBARI-18254. DB consistency check should tolerate services with no configuration. (Balazs Bence Sari via stoader)
Date Thu, 25 Aug 2016 11:36:00 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 5878c1af7 -> 8242c7f06


AMBARI-18254. DB consistency check should tolerate services with no configuration. (Balazs
Bence Sari via stoader)


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

Branch: refs/heads/trunk
Commit: 8242c7f06f2fdaf1efd623e2b6a545fec5582c6c
Parents: 5878c1a
Author: Balazs Bence Sari <bsari@hortonworks.com>
Authored: Thu Aug 25 13:35:37 2016 +0200
Committer: Toader, Sebastian <stoader@hortonworks.com>
Committed: Thu Aug 25 13:35:37 2016 +0200

----------------------------------------------------------------------
 .../checks/DatabaseConsistencyCheckHelper.java  | 10 ++-
 .../DatabaseConsistencyCheckHelperTest.java     | 91 ++++++++++++++++++++
 2 files changed, 99 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/8242c7f0/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 36a2d99..9f7419c 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
@@ -86,6 +86,12 @@ public class DatabaseConsistencyCheckHelper {
 
   protected static void setInjector(Injector injector) {
     DatabaseConsistencyCheckHelper.injector = injector;
+    // Clean up: new injector means static fields should be reinitalized, though in real
life it only occurs during testing
+    closeConnection();
+    connection = null;
+    metainfoDAO = null;
+    ambariMetaInfo = null;
+    dbAccessor = null;
   }
 
   public static void setConnection(Connection connection) {
@@ -448,8 +454,8 @@ public class DatabaseConsistencyCheckHelper {
         }
 
         for (String clusterName : clusterServiceMap.keySet()) {
-          LOG.error("Service(s): {}, from cluster {} has no config(s) in serviceconfig table!",
StringUtils.join(clusterServiceMap.get(clusterName), ","), clusterName);
-          errorAvailable = true;
+          LOG.warn("Service(s): {}, from cluster {} has no config(s) in serviceconfig table!",
StringUtils.join(clusterServiceMap.get(clusterName), ","), clusterName);
+          warningAvailable = true;
         }
 
       }

http://git-wip-us.apache.org/repos/asf/ambari/blob/8242c7f0/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 a7c77e1..d8f538e 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
@@ -27,6 +27,7 @@ import java.sql.Statement;
 import java.util.HashMap;
 import java.util.Map;
 
+import junit.framework.Assert;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.orm.DBAccessor;
 import org.apache.ambari.server.stack.StackManagerFactory;
@@ -34,6 +35,7 @@ import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.ServiceInfo;
 import org.apache.ambari.server.state.stack.OsFamily;
 import org.easymock.EasyMockSupport;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import com.google.inject.AbstractModule;
@@ -293,6 +295,95 @@ public class DatabaseConsistencyCheckHelperTest {
     easyMockSupport.verifyAll();
   }
 
+  @Test
+  public void testCheckServiceConfigs_missingServiceConfigGeneratesWarning() throws Exception
{
+    EasyMockSupport easyMockSupport = new EasyMockSupport();
+    final AmbariMetaInfo mockAmbariMetainfo = easyMockSupport.createNiceMock(AmbariMetaInfo.class);
+    final DBAccessor mockDBDbAccessor = easyMockSupport.createNiceMock(DBAccessor.class);
+    final Connection mockConnection = easyMockSupport.createNiceMock(Connection.class);
+    final ResultSet mockResultSet = easyMockSupport.createNiceMock(ResultSet.class);
+    final ResultSet clusterServicesResultSet = easyMockSupport.createNiceMock(ResultSet.class);
+    final ResultSet stackResultSet = easyMockSupport.createNiceMock(ResultSet.class);
+    final ResultSet serviceConfigResultSet = easyMockSupport.createNiceMock(ResultSet.class);
+    final Statement mockStatement = easyMockSupport.createNiceMock(Statement.class);
+    final ServiceInfo mockHDFSServiceInfo = easyMockSupport.createNiceMock(ServiceInfo.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(AmbariMetaInfo.class).toInstance(mockAmbariMetainfo);
+        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);
+      }
+    });
+
+    Map<String, ServiceInfo> services = new HashMap<>();
+    services.put("HDFS", mockHDFSServiceInfo);
+
+    Map<String, Map<String, Map<String, String>>> configAttributes = new
HashMap<>();
+    configAttributes.put("core-site", new HashMap<String, Map<String, String>>());
+
+    expect(mockHDFSServiceInfo.getConfigTypeAttributes()).andReturn(configAttributes);
+    expect(mockAmbariMetainfo.getServices("HDP", "2.2")).andReturn(services);
+    expect(clusterServicesResultSet.next()).andReturn(true);
+    expect(clusterServicesResultSet.getString("service_name")).andReturn("OPENSOFT R");
+    expect(clusterServicesResultSet.getString("cluster_name")).andReturn("My Cluster");
+    expect(serviceConfigResultSet.next()).andReturn(true);
+    expect(serviceConfigResultSet.getString("service_name")).andReturn("HDFS");
+    expect(serviceConfigResultSet.getString("type_name")).andReturn("core-site");
+    expect(stackResultSet.next()).andReturn(true);
+    expect(stackResultSet.getString("stack_name")).andReturn("HDP");
+    expect(stackResultSet.getString("stack_version")).andReturn("2.2");
+    expect(mockConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)).andReturn(mockStatement);
+    expect(mockStatement.executeQuery("select c.cluster_name, service_name from clusterservices
cs " +
+        "join clusters c on cs.cluster_id=c.cluster_id " +
+        "where service_name not in (select service_name from serviceconfig sc where sc.cluster_id=cs.cluster_id
and sc.service_name=cs.service_name and sc.group_id is null)")).andReturn(clusterServicesResultSet);
+    expect(mockStatement.executeQuery("select c.cluster_name, sc.service_name, sc.version
from serviceconfig sc " +
+        "join clusters c on sc.cluster_id=c.cluster_id " +
+        "where service_config_id not in (select service_config_id from serviceconfigmapping)
and group_id is null")).andReturn(mockResultSet);
+    expect(mockStatement.executeQuery("select c.cluster_name, s.stack_name, s.stack_version
from clusters c " +
+        "join stack s on c.desired_stack_id = s.stack_id")).andReturn(stackResultSet);
+    expect(mockStatement.executeQuery("select c.cluster_name, cs.service_name, cc.type_name,
sc.version from clusterservices cs " +
+        "join serviceconfig sc on cs.service_name=sc.service_name and cs.cluster_id=sc.cluster_id
" +
+        "join serviceconfigmapping scm on sc.service_config_id=scm.service_config_id " +
+        "join clusterconfig cc on scm.config_id=cc.config_id and sc.cluster_id=cc.cluster_id
" +
+        "join clusters c on cc.cluster_id=c.cluster_id and sc.stack_id=c.desired_stack_id
" +
+        "where sc.group_id is null and sc.service_config_id=(select max(service_config_id)
from serviceconfig sc2 where sc2.service_name=sc.service_name and sc2.cluster_id=sc.cluster_id)
" +
+        "group by c.cluster_name, cs.service_name, cc.type_name, sc.version")).andReturn(serviceConfigResultSet);
+    expect(mockStatement.executeQuery("select c.cluster_name, cs.service_name, cc.type_name
from clusterservices cs " +
+        "join serviceconfig sc on cs.service_name=sc.service_name and cs.cluster_id=sc.cluster_id
" +
+        "join serviceconfigmapping scm on sc.service_config_id=scm.service_config_id " +
+        "join clusterconfig cc on scm.config_id=cc.config_id and cc.cluster_id=sc.cluster_id
" +
+        "join clusterconfigmapping ccm on cc.type_name=ccm.type_name and cc.version_tag=ccm.version_tag
and cc.cluster_id=ccm.cluster_id " +
+        "join clusters c on ccm.cluster_id=c.cluster_id " +
+        "where sc.group_id is null and sc.service_config_id = (select max(service_config_id)
from serviceconfig sc2 where sc2.service_name=sc.service_name and sc2.cluster_id=sc.cluster_id)
" +
+        "group by c.cluster_name, cs.service_name, cc.type_name " +
+        "having sum(ccm.selected) < 1")).andReturn(mockResultSet);
+
+    DatabaseConsistencyCheckHelper.setInjector(mockInjector);
+    DatabaseConsistencyCheckHelper.setConnection(mockConnection);
+
+    easyMockSupport.replayAll();
+
+    mockAmbariMetainfo.init();
+
+    DatabaseConsistencyCheckHelper.resetErrorWarningFlags();
+    DatabaseConsistencyCheckHelper.checkServiceConfigs();
+
+    easyMockSupport.verifyAll();
+
+    Assert.assertTrue("Missing service config for OPENSOFT R should have triggered a warning.",
+        DatabaseConsistencyCheckHelper.isWarningAvailable());
+    Assert.assertFalse("No errors should have been triggered.", DatabaseConsistencyCheckHelper.isErrorAvailable());
+  }
+
 
 }
 


Mime
View raw message