|
@@ -37,11 +37,9 @@ import java.sql.Connection;
|
|
import java.sql.ResultSet;
|
|
import java.sql.ResultSet;
|
|
import java.sql.SQLException;
|
|
import java.sql.SQLException;
|
|
import java.sql.Statement;
|
|
import java.sql.Statement;
|
|
-import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
import java.util.Collection;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.HashSet;
|
|
import java.util.HashSet;
|
|
-import java.util.List;
|
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
|
|
|
|
@@ -60,6 +58,7 @@ public class CheckDatabaseHelper {
|
|
private Connection connection;
|
|
private Connection connection;
|
|
private AmbariMetaInfo ambariMetaInfo;
|
|
private AmbariMetaInfo ambariMetaInfo;
|
|
private Injector injector;
|
|
private Injector injector;
|
|
|
|
+ private boolean errorAvailable = false;
|
|
|
|
|
|
@Inject
|
|
@Inject
|
|
public CheckDatabaseHelper(DBAccessor dbAccessor,
|
|
public CheckDatabaseHelper(DBAccessor dbAccessor,
|
|
@@ -112,6 +111,14 @@ public class CheckDatabaseHelper {
|
|
persistService.stop();
|
|
persistService.stop();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ protected boolean isErrorAvailable() {
|
|
|
|
+ return errorAvailable;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected void setErrorAvailable(boolean errorAvailable) {
|
|
|
|
+ this.errorAvailable = errorAvailable;
|
|
|
|
+ }
|
|
|
|
+
|
|
/*
|
|
/*
|
|
* This method checks if all configurations that we have in clusterconfig table
|
|
* This method checks if all configurations that we have in clusterconfig table
|
|
* have at least one mapping in clusterconfigmapping table. If we found not mapped config
|
|
* have at least one mapping in clusterconfigmapping table. If we found not mapped config
|
|
@@ -169,6 +176,7 @@ public class CheckDatabaseHelper {
|
|
for (String clusterName : configsSelectedMoreThanOnce.keySet()) {
|
|
for (String clusterName : configsSelectedMoreThanOnce.keySet()) {
|
|
LOG.error(String.format("You have config(s), in cluster %s, that is(are) selected more than once in clusterconfigmapping: %s",
|
|
LOG.error(String.format("You have config(s), in cluster %s, that is(are) selected more than once in clusterconfigmapping: %s",
|
|
clusterName ,StringUtils.join(configsSelectedMoreThanOnce.get(clusterName), ",")));
|
|
clusterName ,StringUtils.join(configsSelectedMoreThanOnce.get(clusterName), ",")));
|
|
|
|
+ errorAvailable = true;
|
|
}
|
|
}
|
|
} catch (SQLException e) {
|
|
} catch (SQLException e) {
|
|
LOG.error("Exception occurred during check for config selected more than ones procedure: ", e);
|
|
LOG.error("Exception occurred during check for config selected more than ones procedure: ", e);
|
|
@@ -203,6 +211,7 @@ public class CheckDatabaseHelper {
|
|
|
|
|
|
if (!hostsWithoutStatus.isEmpty()) {
|
|
if (!hostsWithoutStatus.isEmpty()) {
|
|
LOG.error("You have host(s) without status: " + StringUtils.join(hostsWithoutStatus, ","));
|
|
LOG.error("You have host(s) without status: " + StringUtils.join(hostsWithoutStatus, ","));
|
|
|
|
+ errorAvailable = true;
|
|
}
|
|
}
|
|
} catch (SQLException e) {
|
|
} catch (SQLException e) {
|
|
LOG.error("Exception occurred during check for host without state procedure: ", e);
|
|
LOG.error("Exception occurred during check for host without state procedure: ", e);
|
|
@@ -257,7 +266,8 @@ public class CheckDatabaseHelper {
|
|
}
|
|
}
|
|
|
|
|
|
if (hostComponentStateCount != hostComponentDesiredStateCount || hostComponentStateCount != mergedCount) {
|
|
if (hostComponentStateCount != hostComponentDesiredStateCount || hostComponentStateCount != mergedCount) {
|
|
- LOG.error("Your host component state count not equals host component desired state count!");
|
|
|
|
|
|
+ LOG.error("Your host component states(hostcomponentstate table) count not equals host component desired states(hostcomponentdesiredstate table) count!");
|
|
|
|
+ errorAvailable = true;
|
|
}
|
|
}
|
|
|
|
|
|
} catch (SQLException e) {
|
|
} catch (SQLException e) {
|
|
@@ -284,27 +294,32 @@ public class CheckDatabaseHelper {
|
|
* If any issue was discovered, we are showing error message for user.
|
|
* If any issue was discovered, we are showing error message for user.
|
|
* */
|
|
* */
|
|
protected void checkServiceConfigs() {
|
|
protected void checkServiceConfigs() {
|
|
- String GET_SERVICES_WITHOUT_CONFIGS_QUERY = "select service_name from clusterservices where service_name not in (select service_name from serviceconfig where group_id is null)";
|
|
|
|
|
|
+ String GET_SERVICES_WITHOUT_CONFIGS_QUERY = "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)";
|
|
String GET_SERVICE_CONFIG_WITHOUT_MAPPING_QUERY = "select service_name from serviceconfig where service_config_id not in (select service_config_id from serviceconfigmapping) and group_id is null";
|
|
String GET_SERVICE_CONFIG_WITHOUT_MAPPING_QUERY = "select service_name from serviceconfig where service_config_id not in (select service_config_id from serviceconfigmapping) and group_id is null";
|
|
- String GET_STACK_NAME_VERSION_QUERY = "select s.stack_name, s.stack_version from clusters c join stack s on c.desired_stack_id = s.stack_id";
|
|
|
|
- String GET_SERVICES_WITH_CONFIGS_QUERY = "select cs.service_name, type_name, sc.version from clusterservices cs " +
|
|
|
|
- "join serviceconfig sc on cs.service_name=sc.service_name " +
|
|
|
|
|
|
+ String GET_STACK_NAME_VERSION_QUERY = "select c.cluster_name, s.stack_name, s.stack_version from clusters c " +
|
|
|
|
+ "join stack s on c.desired_stack_id = s.stack_id";
|
|
|
|
+ String GET_SERVICES_WITH_CONFIGS_QUERY = "select c.cluster_name, cs.service_name, 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 serviceconfigmapping scm on sc.service_config_id=scm.service_config_id " +
|
|
- "join clusterconfig cc on scm.config_id=cc.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 " +
|
|
"where sc.group_id is null " +
|
|
"where sc.group_id is null " +
|
|
- "group by cs.service_name, type_name, sc.version";
|
|
|
|
- String GET_NOT_SELECTED_SERVICE_CONFIGS_QUERY = "select cs.service_name,cc.type_name from clusterservices cs " +
|
|
|
|
- "join serviceconfig sc on cs.service_name=sc.service_name " +
|
|
|
|
|
|
+ "group by c.cluster_name, cs.service_name, type_name, sc.version";
|
|
|
|
+ String GET_NOT_SELECTED_SERVICE_CONFIGS_QUERY = "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 serviceconfigmapping scm on sc.service_config_id=scm.service_config_id " +
|
|
- "join clusterconfig cc on scm.config_id=cc.config_id " +
|
|
|
|
- "join clusterconfigmapping ccm on cc.type_name=ccm.type_name and cc.version_tag=ccm.version_tag " +
|
|
|
|
- "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) " +
|
|
|
|
- "group by cs.service_name,cc.type_name " +
|
|
|
|
|
|
+ "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";
|
|
"having sum(ccm.selected) < 1";
|
|
- String stackName = null, stackVersion = null;
|
|
|
|
- Set<String> servicesWithoutConfigs = new HashSet<>();
|
|
|
|
|
|
+ Multimap<String, String> servicesWithoutConfigs = HashMultimap.create();
|
|
|
|
+ Map<String, Map<String, String>> clusterStackInfo = new HashMap<>();
|
|
Set<String> servicesWithoutMappedConfigs = new HashSet<>();
|
|
Set<String> servicesWithoutMappedConfigs = new HashSet<>();
|
|
- Map<String, List<String>> notSelectedServiceConfigs = new HashMap<>();
|
|
|
|
|
|
+ Map<String, Multimap<String, String>> notSelectedServiceConfigs = new HashMap<>();
|
|
ResultSet rs = null;
|
|
ResultSet rs = null;
|
|
|
|
|
|
try {
|
|
try {
|
|
@@ -313,12 +328,13 @@ public class CheckDatabaseHelper {
|
|
rs = statement.executeQuery(GET_SERVICES_WITHOUT_CONFIGS_QUERY);
|
|
rs = statement.executeQuery(GET_SERVICES_WITHOUT_CONFIGS_QUERY);
|
|
if (rs != null) {
|
|
if (rs != null) {
|
|
while (rs.next()) {
|
|
while (rs.next()) {
|
|
- servicesWithoutConfigs.add(rs.getString("service_name"));
|
|
|
|
|
|
+ servicesWithoutConfigs.put(rs.getString("cluster_name"), rs.getString("service_name"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (!servicesWithoutConfigs.isEmpty()) {
|
|
|
|
- LOG.error("You have services without configs at all: " + StringUtils.join(servicesWithoutConfigs, ","));
|
|
|
|
|
|
+ for (String clusterName : servicesWithoutConfigs.keySet()) {
|
|
|
|
+ LOG.error(String.format("Service(s): %s, from cluster %s has no config(s) in serviceconfig table!", StringUtils.join(servicesWithoutConfigs.get(clusterName), ","), clusterName));
|
|
|
|
+ errorAvailable = true;
|
|
}
|
|
}
|
|
|
|
|
|
rs = statement.executeQuery(GET_SERVICE_CONFIG_WITHOUT_MAPPING_QUERY);
|
|
rs = statement.executeQuery(GET_SERVICE_CONFIG_WITHOUT_MAPPING_QUERY);
|
|
@@ -329,44 +345,63 @@ public class CheckDatabaseHelper {
|
|
}
|
|
}
|
|
|
|
|
|
if (!servicesWithoutMappedConfigs.isEmpty()) {
|
|
if (!servicesWithoutMappedConfigs.isEmpty()) {
|
|
- LOG.error("You have services without mapped configs: " + StringUtils.join(servicesWithoutMappedConfigs, ","));
|
|
|
|
|
|
+ LOG.error("You have service(s) without mapped configs in serviceconfigmapping: " + StringUtils.join(servicesWithoutMappedConfigs, ","));
|
|
|
|
+ errorAvailable = true;
|
|
}
|
|
}
|
|
|
|
|
|
rs = statement.executeQuery(GET_STACK_NAME_VERSION_QUERY);
|
|
rs = statement.executeQuery(GET_STACK_NAME_VERSION_QUERY);
|
|
if (rs != null) {
|
|
if (rs != null) {
|
|
while (rs.next()) {
|
|
while (rs.next()) {
|
|
- stackName = rs.getString("stack_name");
|
|
|
|
- stackVersion = rs.getString("stack_version");
|
|
|
|
|
|
+ Map<String, String> stackInfoMap = new HashMap<>();
|
|
|
|
+ stackInfoMap.put(rs.getString("stack_name"), rs.getString("stack_version"));
|
|
|
|
+ clusterStackInfo.put(rs.getString("cluster_name"), stackInfoMap);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (stackName != null && stackVersion != null) {
|
|
|
|
- Set<String> serviceNames = new HashSet<>();
|
|
|
|
- Map<Integer, Multimap<String, String>> dbServiceVersionConfigs = new HashMap<>();
|
|
|
|
- Multimap<String, String> stackServiceConfigs = HashMultimap.create();
|
|
|
|
|
|
|
|
- rs = statement.executeQuery(GET_SERVICES_WITH_CONFIGS_QUERY);
|
|
|
|
- if (rs != null) {
|
|
|
|
- String serviceName = null, configType = null;
|
|
|
|
- Integer serviceVersion = null;
|
|
|
|
- while (rs.next()) {
|
|
|
|
- serviceName = rs.getString("service_name");
|
|
|
|
- configType = rs.getString("type_name");
|
|
|
|
- serviceVersion = rs.getInt("version");
|
|
|
|
|
|
+ Set<String> serviceNames = new HashSet<>();
|
|
|
|
+ Map<String, Map<Integer, Multimap<String, String>>> dbClusterServiceVersionConfigs = new HashMap<>();
|
|
|
|
+ Multimap<String, String> stackServiceConfigs = HashMultimap.create();
|
|
|
|
+
|
|
|
|
+ rs = statement.executeQuery(GET_SERVICES_WITH_CONFIGS_QUERY);
|
|
|
|
+ if (rs != null) {
|
|
|
|
+ String serviceName = null, configType = null, clusterName = null;
|
|
|
|
+ Integer serviceVersion = null;
|
|
|
|
+ while (rs.next()) {
|
|
|
|
+ clusterName = rs.getString("cluster_name");
|
|
|
|
+ serviceName = rs.getString("service_name");
|
|
|
|
+ configType = rs.getString("type_name");
|
|
|
|
+ serviceVersion = rs.getInt("version");
|
|
|
|
+
|
|
|
|
+ serviceNames.add(serviceName);
|
|
|
|
|
|
- serviceNames.add(serviceName);
|
|
|
|
|
|
+ if (dbClusterServiceVersionConfigs.get(clusterName) != null) {
|
|
|
|
+ Map<Integer, Multimap<String, String>> dbServiceVersionConfigs = dbClusterServiceVersionConfigs.get(clusterName);
|
|
|
|
|
|
- if (dbServiceVersionConfigs.get(serviceVersion) == null) {
|
|
|
|
|
|
+ if (dbServiceVersionConfigs.get(serviceVersion) != null) {
|
|
|
|
+ dbServiceVersionConfigs.get(serviceVersion).put(serviceName, configType);
|
|
|
|
+ } else {
|
|
Multimap<String, String> dbServiceConfigs = HashMultimap.create();
|
|
Multimap<String, String> dbServiceConfigs = HashMultimap.create();
|
|
dbServiceConfigs.put(serviceName, configType);
|
|
dbServiceConfigs.put(serviceName, configType);
|
|
dbServiceVersionConfigs.put(serviceVersion, dbServiceConfigs);
|
|
dbServiceVersionConfigs.put(serviceVersion, dbServiceConfigs);
|
|
- } else {
|
|
|
|
- dbServiceVersionConfigs.get(serviceVersion).put(serviceName, configType);
|
|
|
|
}
|
|
}
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ Map<Integer, Multimap<String, String>> dbServiceVersionConfigs = new HashMap<>();
|
|
|
|
+ Multimap<String, String> dbServiceConfigs = HashMultimap.create();
|
|
|
|
+ dbServiceConfigs.put(serviceName, configType);
|
|
|
|
+ dbServiceVersionConfigs.put(serviceVersion, dbServiceConfigs);
|
|
|
|
+ dbClusterServiceVersionConfigs.put(clusterName, dbServiceVersionConfigs);
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
|
|
|
+ for (Map.Entry<String, Map<String, String>> clusterStackInfoEntry : clusterStackInfo.entrySet()) {
|
|
|
|
+ String clusterName = clusterStackInfoEntry.getKey();
|
|
|
|
+ Map<String, String> stackInfo = clusterStackInfoEntry.getValue();
|
|
|
|
+ String stackName = stackInfo.keySet().iterator().next();
|
|
|
|
+ String stackVersion = stackInfo.get(stackName);
|
|
Map<String, ServiceInfo> serviceInfoMap = ambariMetaInfo.getServices(stackName, stackVersion);
|
|
Map<String, ServiceInfo> serviceInfoMap = ambariMetaInfo.getServices(stackName, stackVersion);
|
|
for (String serviceName : serviceNames) {
|
|
for (String serviceName : serviceNames) {
|
|
ServiceInfo serviceInfo = serviceInfoMap.get(serviceName);
|
|
ServiceInfo serviceInfo = serviceInfoMap.get(serviceName);
|
|
@@ -376,6 +411,7 @@ public class CheckDatabaseHelper {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ Map<Integer, Multimap<String, String>> dbServiceVersionConfigs = dbClusterServiceVersionConfigs.get(clusterName);
|
|
for (Integer serviceVersion : dbServiceVersionConfigs.keySet()) {
|
|
for (Integer serviceVersion : dbServiceVersionConfigs.keySet()) {
|
|
Multimap<String, String> dbServiceConfigs = dbServiceVersionConfigs.get(serviceVersion);
|
|
Multimap<String, String> dbServiceConfigs = dbServiceVersionConfigs.get(serviceVersion);
|
|
for (String serviceName : dbServiceConfigs.keySet()) {
|
|
for (String serviceName : dbServiceConfigs.keySet()) {
|
|
@@ -384,33 +420,45 @@ public class CheckDatabaseHelper {
|
|
if (serviceConfigsFromDB != null && serviceConfigsFromStack != null) {
|
|
if (serviceConfigsFromDB != null && serviceConfigsFromStack != null) {
|
|
serviceConfigsFromStack.removeAll(serviceConfigsFromDB);
|
|
serviceConfigsFromStack.removeAll(serviceConfigsFromDB);
|
|
if (!serviceConfigsFromStack.isEmpty()) {
|
|
if (!serviceConfigsFromStack.isEmpty()) {
|
|
- LOG.error(String.format("Required config(s): %s is(are) not available for service %s with service config version %s",
|
|
|
|
- StringUtils.join(serviceConfigsFromStack, ","), serviceName, Integer.toString(serviceVersion)));
|
|
|
|
|
|
+ LOG.error(String.format("Required config(s): %s is(are) not available for service %s with service config version %s for cluster %s",
|
|
|
|
+ StringUtils.join(serviceConfigsFromStack, ","), serviceName, Integer.toString(serviceVersion), clusterName));
|
|
|
|
+ errorAvailable = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
rs = statement.executeQuery(GET_NOT_SELECTED_SERVICE_CONFIGS_QUERY);
|
|
rs = statement.executeQuery(GET_NOT_SELECTED_SERVICE_CONFIGS_QUERY);
|
|
if (rs != null) {
|
|
if (rs != null) {
|
|
- String serviceName = null, configType = null;
|
|
|
|
|
|
+ String serviceName = null, configType = null, clusterName = null;
|
|
while (rs.next()) {
|
|
while (rs.next()) {
|
|
|
|
+ clusterName = rs.getString("cluster_name");
|
|
serviceName = rs.getString("service_name");
|
|
serviceName = rs.getString("service_name");
|
|
configType = rs.getString("type_name");
|
|
configType = rs.getString("type_name");
|
|
|
|
|
|
- if (notSelectedServiceConfigs.get(serviceName) != null) {
|
|
|
|
- notSelectedServiceConfigs.get(serviceName).add(configType);
|
|
|
|
|
|
+
|
|
|
|
+ if (notSelectedServiceConfigs.get(clusterName) != null) {
|
|
|
|
+ Multimap<String, String> serviceConfigs = notSelectedServiceConfigs.get(clusterName);
|
|
|
|
+ serviceConfigs.put(serviceName, configType);
|
|
} else {
|
|
} else {
|
|
- List<String> configTypes = new ArrayList<>();
|
|
|
|
- configTypes.add(configType);
|
|
|
|
- notSelectedServiceConfigs.put(serviceName, configTypes);
|
|
|
|
|
|
+
|
|
|
|
+ Multimap<String, String> serviceConfigs = HashMultimap.create();
|
|
|
|
+ serviceConfigs.put(serviceName, configType);
|
|
|
|
+ notSelectedServiceConfigs.put(clusterName, serviceConfigs);
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- for (String serviceName : notSelectedServiceConfigs.keySet()) {
|
|
|
|
- LOG.error(String.format("You have non selected configs: %s for service %s.", StringUtils.join(notSelectedServiceConfigs.get(serviceName), ","), serviceName));
|
|
|
|
|
|
+ for (String clusterName : notSelectedServiceConfigs.keySet()) {
|
|
|
|
+ Multimap<String, String> serviceConfig = notSelectedServiceConfigs.get(clusterName);
|
|
|
|
+ for (String serviceName : serviceConfig.keySet()) {
|
|
|
|
+ LOG.error(String.format("You have non selected configs: %s for service %s from cluster %s!", StringUtils.join(serviceConfig.get(serviceName), ","), serviceName, clusterName));
|
|
|
|
+ errorAvailable = true;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
} catch (SQLException e) {
|
|
} catch (SQLException e) {
|
|
LOG.error("Exception occurred during complex service check procedure: ", e);
|
|
LOG.error("Exception occurred during complex service check procedure: ", e);
|
|
@@ -467,6 +515,11 @@ public class CheckDatabaseHelper {
|
|
} finally {
|
|
} finally {
|
|
if (checkDatabaseHelper != null) {
|
|
if (checkDatabaseHelper != null) {
|
|
checkDatabaseHelper.closeConnection();
|
|
checkDatabaseHelper.closeConnection();
|
|
|
|
+ if (checkDatabaseHelper.isErrorAvailable()) {
|
|
|
|
+ System.out.print("Some error(s) was(were) found. Please check ambari-server-check-database.log for problem(s).");
|
|
|
|
+ } else {
|
|
|
|
+ System.out.print("No erros were found.");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|