id
stringlengths 7
14
| text
stringlengths 1
106k
|
---|---|
223551095_1934 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
String isRangerHTTPEnabled = getProperty(request, "ranger-admin-site", "ranger.service.http.enabled");
String isRangerSSLEnabled = getProperty(request, "ranger-admin-site", "ranger.service.https.attrib.ssl.enabled");
String rangerSSLKeystoreFile = getProperty(request, "ranger-admin-site", "ranger.https.attrib.keystore.file");
if (("false").equalsIgnoreCase(isRangerHTTPEnabled) && ("true").equalsIgnoreCase(isRangerSSLEnabled) && rangerSSLKeystoreFile.contains("/etc/ranger/admin/conf") ) {
LOG.info("Ranger is SSL enabled, need to show Configuration changes warning before upragade proceeds.");
prerequisiteCheck.getFailedOn().add(serviceName);
prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING);
prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
} else {
LOG.info("Ranger is not SSL enabled, no need to show Configuration changes warning before upragade proceeds.");
}
} |
223551095_1935 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request)
throws AmbariException {
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
Collection<Host> hosts = cluster.getHosts();
// see if any hosts in the cluster are in MM
for (Host host : hosts) {
MaintenanceState maintenanceState = host.getMaintenanceState(cluster.getClusterId());
if (maintenanceState != MaintenanceState.OFF) {
prerequisiteCheck.getFailedOn().add(host.getHostName());
prerequisiteCheck.getFailedDetail().add(
new HostDetail(host.getHostId(), host.getHostName()));
}
}
// for any host in MM, produce a warning
if (!prerequisiteCheck.getFailedOn().isEmpty()) {
PrereqCheckStatus status = request.getUpgradeType() == UpgradeType.HOST_ORDERED ?
PrereqCheckStatus.FAIL : PrereqCheckStatus.WARNING;
prerequisiteCheck.setStatus(status);
String failReason = request.getUpgradeType() == UpgradeType.HOST_ORDERED ?
getFailReason(KEY_CANNOT_START_HOST_ORDERED, prerequisiteCheck, request) :
getFailReason(prerequisiteCheck, request);
prerequisiteCheck.setFailReason(failReason);
}
} |
223551095_1936 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request)
throws AmbariException {
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
Collection<Host> hosts = cluster.getHosts();
// see if any hosts in the cluster are in MM
for (Host host : hosts) {
MaintenanceState maintenanceState = host.getMaintenanceState(cluster.getClusterId());
if (maintenanceState != MaintenanceState.OFF) {
prerequisiteCheck.getFailedOn().add(host.getHostName());
prerequisiteCheck.getFailedDetail().add(
new HostDetail(host.getHostId(), host.getHostName()));
}
}
// for any host in MM, produce a warning
if (!prerequisiteCheck.getFailedOn().isEmpty()) {
PrereqCheckStatus status = request.getUpgradeType() == UpgradeType.HOST_ORDERED ?
PrereqCheckStatus.FAIL : PrereqCheckStatus.WARNING;
prerequisiteCheck.setStatus(status);
String failReason = request.getUpgradeType() == UpgradeType.HOST_ORDERED ?
getFailReason(KEY_CANNOT_START_HOST_ORDERED, prerequisiteCheck, request) :
getFailReason(prerequisiteCheck, request);
prerequisiteCheck.setFailReason(failReason);
}
} |
223551095_1937 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request)
throws AmbariException {
RepositoryVersionEntity rve = request.getTargetRepositoryVersion();
Map<String, Map<String, ThreeWayValue>> changes =
m_mergeHelper.getConflicts(request.getClusterName(), rve.getStackId());
Set<String> failedTypes = new HashSet<>();
for (Entry<String, Map<String, ThreeWayValue>> entry : changes.entrySet()) {
for (Entry<String, ThreeWayValue> configEntry : entry.getValue().entrySet()) {
ThreeWayValue twv = configEntry.getValue();
if (null == twv.oldStackValue) { // !!! did not exist and in the map means changed
failedTypes.add(entry.getKey());
prerequisiteCheck.getFailedOn().add(entry.getKey() + "/" + configEntry.getKey());
MergeDetail md = new MergeDetail();
md.type = entry.getKey();
md.property = configEntry.getKey();
md.current = twv.savedValue;
md.new_stack_value = twv.newStackValue;
md.result_value = md.current;
prerequisiteCheck.getFailedDetail().add(md);
} else if (!twv.oldStackValue.equals(twv.savedValue)) { // !!! value customized
if (null == twv.newStackValue || // !!! not in new stack
!twv.oldStackValue.equals(twv.newStackValue)) { // !!! or the default value changed
failedTypes.add(entry.getKey());
prerequisiteCheck.getFailedOn().add(entry.getKey() + "/" + configEntry.getKey());
MergeDetail md = new MergeDetail();
md.type = entry.getKey();
md.property = configEntry.getKey();
md.current = twv.savedValue;
md.new_stack_value = twv.newStackValue;
md.result_value = md.current;
prerequisiteCheck.getFailedDetail().add(md);
}
}
}
}
if (prerequisiteCheck.getFailedOn().size() > 0) {
prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING);
String failReason = getFailReason(prerequisiteCheck, request);
prerequisiteCheck.setFailReason(String.format(failReason, StringUtils.join(
failedTypes, ", ")));
} else {
prerequisiteCheck.setStatus(PrereqCheckStatus.PASS);
}
} |
223551095_1938 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
if (cluster.getSecurityType() == SecurityType.KERBEROS){
prerequisiteCheck.getFailedOn().add(KAFKA_SERVICE);
prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING);
prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
}
} |
223551095_1939 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
Set<String> hosts = new HashSet<>();
final String SECONDARY_NAMENODE = "SECONDARY_NAMENODE";
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
try {
ServiceComponent serviceComponent = cluster.getService(HDFS_SERVICE_NAME).getServiceComponent(SECONDARY_NAMENODE);
if (serviceComponent != null) {
hosts = serviceComponent.getServiceComponentHosts().keySet();
}
} catch (ServiceComponentNotFoundException err) {
// This exception can be ignored if the component doesn't exist because it is a best-attempt at finding it.
;
}
// Try another method to find references to SECONDARY_NAMENODE
if (hosts.isEmpty()) {
List<HostComponentStateEntity> allHostComponents = hostComponentStateDao.findAll();
for(HostComponentStateEntity hc : allHostComponents) {
if (hc.getServiceName().equalsIgnoreCase(HDFS_SERVICE_NAME) && hc.getComponentName().equalsIgnoreCase(SECONDARY_NAMENODE)) {
hosts.add(hc.getHostName());
}
}
}
if (!hosts.isEmpty()) {
String foundHost = hosts.toArray(new String[hosts.size()])[0];
prerequisiteCheck.getFailedOn().add(HDFS_SERVICE_NAME);
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
String failReason = getFailReason(prerequisiteCheck, request);
prerequisiteCheck.setFailReason(String.format(failReason, foundHost));
}
} |
223551095_1940 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
String propertyValue = getProperty(request, "yarn-site",
"yarn.resourcemanager.work-preserving-recovery.enabled");
if (null == propertyValue || !BooleanUtils.toBoolean(propertyValue)) {
prerequisiteCheck.getFailedOn().add("YARN");
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
}
} |
223551095_1941 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
Map<String, Service> services = cluster.getServices();
List<String> errorMessages = new ArrayList<>();
for (Service service : services.values()) {
validateService(service, prerequisiteCheck, errorMessages);
}
if (!prerequisiteCheck.getFailedOn().isEmpty()) {
prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING);
String failReason = getFailReason(prerequisiteCheck, request);
prerequisiteCheck.setFailReason(String.format(failReason, StringUtils.join(errorMessages, "\n")));
prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, "\n"));
}
} |
223551095_1942 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
Map<String, Service> services = cluster.getServices();
List<String> errorMessages = new ArrayList<>();
for (Service service : services.values()) {
validateService(service, prerequisiteCheck, errorMessages);
}
if (!prerequisiteCheck.getFailedOn().isEmpty()) {
prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING);
String failReason = getFailReason(prerequisiteCheck, request);
prerequisiteCheck.setFailReason(String.format(failReason, StringUtils.join(errorMessages, "\n")));
prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, "\n"));
}
} |
223551095_1943 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
try {
Service hive = cluster.getService("HIVE");
ServiceComponent metastore = hive.getServiceComponent("HIVE_METASTORE");
Map<String, ServiceComponentHost> metastores = metastore.getServiceComponentHosts();
if (metastores.size() < 2) {
prerequisiteCheck.getFailedOn().add("HIVE");
prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING);
prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
}
} catch (ServiceComponentNotFoundException scnfe) {
prerequisiteCheck.getFailedOn().add("HIVE");
prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING);
prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
}
} |
223551095_1944 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
try {
Service hive = cluster.getService("HIVE");
ServiceComponent metastore = hive.getServiceComponent("HIVE_METASTORE");
Map<String, ServiceComponentHost> metastores = metastore.getServiceComponentHosts();
if (metastores.size() < 2) {
prerequisiteCheck.getFailedOn().add("HIVE");
prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING);
prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
}
} catch (ServiceComponentNotFoundException scnfe) {
prerequisiteCheck.getFailedOn().add("HIVE");
prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING);
prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
}
} |
223551095_1945 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
final Cluster cluster = clustersProvider.get().getCluster(request.getClusterName());
Set<String> servicesInUpgrade = getServicesInUpgrade(request);
for (String serviceName : servicesInUpgrade) {
final Service service = cluster.getService(serviceName);
if (!service.isClientOnlyService() && service.getMaintenanceState() == MaintenanceState.ON) {
prerequisiteCheck.getFailedOn().add(service.getName());
}
}
if (!prerequisiteCheck.getFailedOn().isEmpty()) {
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
}
} |
223551095_1948 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
String propertyValue = getProperty(request, "yarn-site",
YARN_TIMELINE_STATE_RECOVERY_ENABLED_KEY);
if (null == propertyValue || !BooleanUtils.toBoolean(propertyValue)) {
prerequisiteCheck.getFailedOn().add("YARN");
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
}
} |
223551095_1949 | @Override
public void perform(PrerequisiteCheck check, PrereqCheckRequest request) throws AmbariException {
// !!! ComponentSSLConfiguration is an old-school singleton which doesn't
// get initialized until after Guice is done - because this check is bound
// as a singleton via Guice, we can't initialize the stream provider in the
// constructor since the SSL configuration instance hasn't been initialized
URLStreamProvider streamProvider = new URLStreamProvider(2000, 2000,
ComponentSSLConfiguration.instance());
String rangerUrl = checkEmpty("admin-properties", "policymgr_external_url", check, request);
if (null == rangerUrl) {
// !!! check results already filled
return;
}
String adminUsername = checkEmpty("ranger-env", "admin_username", check, request);
if (null == adminUsername) {
return;
}
String adminPassword = checkEmpty("ranger-env", "admin_password", check, request);
if (null == adminPassword) {
return;
}
String rangerAdminUsername = checkEmpty("ranger-env", "ranger_admin_username", check, request);
if (null == rangerAdminUsername) {
return;
}
String rangerAdminPassword = checkEmpty("ranger-env", "ranger_admin_password", check, request);
if (null == rangerAdminPassword) {
return;
}
if (rangerUrl.endsWith("/")) {
rangerUrl = rangerUrl.substring(0, rangerUrl.length()-1);
}
String rangerAuthUrl = String.format("%s/%s", rangerUrl,
"service/public/api/repository/count");
String rangerUserUrl = String.format("%s/%s", rangerUrl,
"service/xusers/users");
List<String> failReasons = new ArrayList<>();
List<String> warnReasons = new ArrayList<>();
// !!! first, just try the service with the admin credentials
try {
int response = checkLogin(streamProvider, rangerAuthUrl, adminUsername, adminPassword);
switch (response) {
case 401: {
String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request);
failReasons.add(String.format(reason, adminUsername));
break;
}
case 200: {
break;
}
default: {
String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request);
warnReasons.add(String.format(reason, adminUsername, response, rangerAuthUrl));
break;
}
}
} catch (IOException e) {
LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e);
LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage());
String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request);
warnReasons.add(String.format(reason, adminUsername, rangerAuthUrl, e.getMessage()));
}
// !!! shortcut when something happened with the admin user
if (!failReasons.isEmpty()) {
check.setFailReason(StringUtils.join(failReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.FAIL);
return;
} else if (!warnReasons.isEmpty()) {
check.setFailReason(StringUtils.join(warnReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.WARNING);
return;
}
// !!! Check for the user, capture exceptions as a warning.
boolean hasUser = checkRangerUser(streamProvider, rangerUserUrl, adminUsername, adminPassword,
rangerAdminUsername, check, request, warnReasons);
if (hasUser) {
// !!! try credentials for specific user
try {
int response = checkLogin(streamProvider, rangerAuthUrl, rangerAdminUsername,
rangerAdminPassword);
switch (response) {
case 401: {
String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request);
failReasons.add(String.format(reason, rangerAdminUsername));
break;
}
case 200: {
break;
}
default: {
String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request);
warnReasons.add(String.format(reason, rangerAdminUsername, response, rangerAuthUrl));
break;
}
}
} catch (IOException e) {
LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage());
LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e);
String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request);
warnReasons.add(String.format(reason, rangerAdminUsername, rangerAuthUrl, e.getMessage()));
}
}
if (!failReasons.isEmpty()) {
check.setFailReason(StringUtils.join(failReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.FAIL);
} else if (!warnReasons.isEmpty()) {
check.setFailReason(StringUtils.join(warnReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.WARNING);
} else {
check.setStatus(PrereqCheckStatus.PASS);
}
} |
223551095_1950 | @Override
public void perform(PrerequisiteCheck check, PrereqCheckRequest request) throws AmbariException {
// !!! ComponentSSLConfiguration is an old-school singleton which doesn't
// get initialized until after Guice is done - because this check is bound
// as a singleton via Guice, we can't initialize the stream provider in the
// constructor since the SSL configuration instance hasn't been initialized
URLStreamProvider streamProvider = new URLStreamProvider(2000, 2000,
ComponentSSLConfiguration.instance());
String rangerUrl = checkEmpty("admin-properties", "policymgr_external_url", check, request);
if (null == rangerUrl) {
// !!! check results already filled
return;
}
String adminUsername = checkEmpty("ranger-env", "admin_username", check, request);
if (null == adminUsername) {
return;
}
String adminPassword = checkEmpty("ranger-env", "admin_password", check, request);
if (null == adminPassword) {
return;
}
String rangerAdminUsername = checkEmpty("ranger-env", "ranger_admin_username", check, request);
if (null == rangerAdminUsername) {
return;
}
String rangerAdminPassword = checkEmpty("ranger-env", "ranger_admin_password", check, request);
if (null == rangerAdminPassword) {
return;
}
if (rangerUrl.endsWith("/")) {
rangerUrl = rangerUrl.substring(0, rangerUrl.length()-1);
}
String rangerAuthUrl = String.format("%s/%s", rangerUrl,
"service/public/api/repository/count");
String rangerUserUrl = String.format("%s/%s", rangerUrl,
"service/xusers/users");
List<String> failReasons = new ArrayList<>();
List<String> warnReasons = new ArrayList<>();
// !!! first, just try the service with the admin credentials
try {
int response = checkLogin(streamProvider, rangerAuthUrl, adminUsername, adminPassword);
switch (response) {
case 401: {
String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request);
failReasons.add(String.format(reason, adminUsername));
break;
}
case 200: {
break;
}
default: {
String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request);
warnReasons.add(String.format(reason, adminUsername, response, rangerAuthUrl));
break;
}
}
} catch (IOException e) {
LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e);
LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage());
String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request);
warnReasons.add(String.format(reason, adminUsername, rangerAuthUrl, e.getMessage()));
}
// !!! shortcut when something happened with the admin user
if (!failReasons.isEmpty()) {
check.setFailReason(StringUtils.join(failReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.FAIL);
return;
} else if (!warnReasons.isEmpty()) {
check.setFailReason(StringUtils.join(warnReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.WARNING);
return;
}
// !!! Check for the user, capture exceptions as a warning.
boolean hasUser = checkRangerUser(streamProvider, rangerUserUrl, adminUsername, adminPassword,
rangerAdminUsername, check, request, warnReasons);
if (hasUser) {
// !!! try credentials for specific user
try {
int response = checkLogin(streamProvider, rangerAuthUrl, rangerAdminUsername,
rangerAdminPassword);
switch (response) {
case 401: {
String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request);
failReasons.add(String.format(reason, rangerAdminUsername));
break;
}
case 200: {
break;
}
default: {
String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request);
warnReasons.add(String.format(reason, rangerAdminUsername, response, rangerAuthUrl));
break;
}
}
} catch (IOException e) {
LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage());
LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e);
String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request);
warnReasons.add(String.format(reason, rangerAdminUsername, rangerAuthUrl, e.getMessage()));
}
}
if (!failReasons.isEmpty()) {
check.setFailReason(StringUtils.join(failReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.FAIL);
} else if (!warnReasons.isEmpty()) {
check.setFailReason(StringUtils.join(warnReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.WARNING);
} else {
check.setStatus(PrereqCheckStatus.PASS);
}
} |
223551095_1951 | @Override
public void perform(PrerequisiteCheck check, PrereqCheckRequest request) throws AmbariException {
// !!! ComponentSSLConfiguration is an old-school singleton which doesn't
// get initialized until after Guice is done - because this check is bound
// as a singleton via Guice, we can't initialize the stream provider in the
// constructor since the SSL configuration instance hasn't been initialized
URLStreamProvider streamProvider = new URLStreamProvider(2000, 2000,
ComponentSSLConfiguration.instance());
String rangerUrl = checkEmpty("admin-properties", "policymgr_external_url", check, request);
if (null == rangerUrl) {
// !!! check results already filled
return;
}
String adminUsername = checkEmpty("ranger-env", "admin_username", check, request);
if (null == adminUsername) {
return;
}
String adminPassword = checkEmpty("ranger-env", "admin_password", check, request);
if (null == adminPassword) {
return;
}
String rangerAdminUsername = checkEmpty("ranger-env", "ranger_admin_username", check, request);
if (null == rangerAdminUsername) {
return;
}
String rangerAdminPassword = checkEmpty("ranger-env", "ranger_admin_password", check, request);
if (null == rangerAdminPassword) {
return;
}
if (rangerUrl.endsWith("/")) {
rangerUrl = rangerUrl.substring(0, rangerUrl.length()-1);
}
String rangerAuthUrl = String.format("%s/%s", rangerUrl,
"service/public/api/repository/count");
String rangerUserUrl = String.format("%s/%s", rangerUrl,
"service/xusers/users");
List<String> failReasons = new ArrayList<>();
List<String> warnReasons = new ArrayList<>();
// !!! first, just try the service with the admin credentials
try {
int response = checkLogin(streamProvider, rangerAuthUrl, adminUsername, adminPassword);
switch (response) {
case 401: {
String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request);
failReasons.add(String.format(reason, adminUsername));
break;
}
case 200: {
break;
}
default: {
String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request);
warnReasons.add(String.format(reason, adminUsername, response, rangerAuthUrl));
break;
}
}
} catch (IOException e) {
LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e);
LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage());
String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request);
warnReasons.add(String.format(reason, adminUsername, rangerAuthUrl, e.getMessage()));
}
// !!! shortcut when something happened with the admin user
if (!failReasons.isEmpty()) {
check.setFailReason(StringUtils.join(failReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.FAIL);
return;
} else if (!warnReasons.isEmpty()) {
check.setFailReason(StringUtils.join(warnReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.WARNING);
return;
}
// !!! Check for the user, capture exceptions as a warning.
boolean hasUser = checkRangerUser(streamProvider, rangerUserUrl, adminUsername, adminPassword,
rangerAdminUsername, check, request, warnReasons);
if (hasUser) {
// !!! try credentials for specific user
try {
int response = checkLogin(streamProvider, rangerAuthUrl, rangerAdminUsername,
rangerAdminPassword);
switch (response) {
case 401: {
String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request);
failReasons.add(String.format(reason, rangerAdminUsername));
break;
}
case 200: {
break;
}
default: {
String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request);
warnReasons.add(String.format(reason, rangerAdminUsername, response, rangerAuthUrl));
break;
}
}
} catch (IOException e) {
LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage());
LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e);
String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request);
warnReasons.add(String.format(reason, rangerAdminUsername, rangerAuthUrl, e.getMessage()));
}
}
if (!failReasons.isEmpty()) {
check.setFailReason(StringUtils.join(failReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.FAIL);
} else if (!warnReasons.isEmpty()) {
check.setFailReason(StringUtils.join(warnReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.WARNING);
} else {
check.setStatus(PrereqCheckStatus.PASS);
}
} |
223551095_1952 | @Override
public void perform(PrerequisiteCheck check, PrereqCheckRequest request) throws AmbariException {
// !!! ComponentSSLConfiguration is an old-school singleton which doesn't
// get initialized until after Guice is done - because this check is bound
// as a singleton via Guice, we can't initialize the stream provider in the
// constructor since the SSL configuration instance hasn't been initialized
URLStreamProvider streamProvider = new URLStreamProvider(2000, 2000,
ComponentSSLConfiguration.instance());
String rangerUrl = checkEmpty("admin-properties", "policymgr_external_url", check, request);
if (null == rangerUrl) {
// !!! check results already filled
return;
}
String adminUsername = checkEmpty("ranger-env", "admin_username", check, request);
if (null == adminUsername) {
return;
}
String adminPassword = checkEmpty("ranger-env", "admin_password", check, request);
if (null == adminPassword) {
return;
}
String rangerAdminUsername = checkEmpty("ranger-env", "ranger_admin_username", check, request);
if (null == rangerAdminUsername) {
return;
}
String rangerAdminPassword = checkEmpty("ranger-env", "ranger_admin_password", check, request);
if (null == rangerAdminPassword) {
return;
}
if (rangerUrl.endsWith("/")) {
rangerUrl = rangerUrl.substring(0, rangerUrl.length()-1);
}
String rangerAuthUrl = String.format("%s/%s", rangerUrl,
"service/public/api/repository/count");
String rangerUserUrl = String.format("%s/%s", rangerUrl,
"service/xusers/users");
List<String> failReasons = new ArrayList<>();
List<String> warnReasons = new ArrayList<>();
// !!! first, just try the service with the admin credentials
try {
int response = checkLogin(streamProvider, rangerAuthUrl, adminUsername, adminPassword);
switch (response) {
case 401: {
String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request);
failReasons.add(String.format(reason, adminUsername));
break;
}
case 200: {
break;
}
default: {
String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request);
warnReasons.add(String.format(reason, adminUsername, response, rangerAuthUrl));
break;
}
}
} catch (IOException e) {
LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e);
LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage());
String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request);
warnReasons.add(String.format(reason, adminUsername, rangerAuthUrl, e.getMessage()));
}
// !!! shortcut when something happened with the admin user
if (!failReasons.isEmpty()) {
check.setFailReason(StringUtils.join(failReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.FAIL);
return;
} else if (!warnReasons.isEmpty()) {
check.setFailReason(StringUtils.join(warnReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.WARNING);
return;
}
// !!! Check for the user, capture exceptions as a warning.
boolean hasUser = checkRangerUser(streamProvider, rangerUserUrl, adminUsername, adminPassword,
rangerAdminUsername, check, request, warnReasons);
if (hasUser) {
// !!! try credentials for specific user
try {
int response = checkLogin(streamProvider, rangerAuthUrl, rangerAdminUsername,
rangerAdminPassword);
switch (response) {
case 401: {
String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request);
failReasons.add(String.format(reason, rangerAdminUsername));
break;
}
case 200: {
break;
}
default: {
String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request);
warnReasons.add(String.format(reason, rangerAdminUsername, response, rangerAuthUrl));
break;
}
}
} catch (IOException e) {
LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage());
LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e);
String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request);
warnReasons.add(String.format(reason, rangerAdminUsername, rangerAuthUrl, e.getMessage()));
}
}
if (!failReasons.isEmpty()) {
check.setFailReason(StringUtils.join(failReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.FAIL);
} else if (!warnReasons.isEmpty()) {
check.setFailReason(StringUtils.join(warnReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.WARNING);
} else {
check.setStatus(PrereqCheckStatus.PASS);
}
} |
223551095_1953 | @Override
public void perform(PrerequisiteCheck check, PrereqCheckRequest request) throws AmbariException {
// !!! ComponentSSLConfiguration is an old-school singleton which doesn't
// get initialized until after Guice is done - because this check is bound
// as a singleton via Guice, we can't initialize the stream provider in the
// constructor since the SSL configuration instance hasn't been initialized
URLStreamProvider streamProvider = new URLStreamProvider(2000, 2000,
ComponentSSLConfiguration.instance());
String rangerUrl = checkEmpty("admin-properties", "policymgr_external_url", check, request);
if (null == rangerUrl) {
// !!! check results already filled
return;
}
String adminUsername = checkEmpty("ranger-env", "admin_username", check, request);
if (null == adminUsername) {
return;
}
String adminPassword = checkEmpty("ranger-env", "admin_password", check, request);
if (null == adminPassword) {
return;
}
String rangerAdminUsername = checkEmpty("ranger-env", "ranger_admin_username", check, request);
if (null == rangerAdminUsername) {
return;
}
String rangerAdminPassword = checkEmpty("ranger-env", "ranger_admin_password", check, request);
if (null == rangerAdminPassword) {
return;
}
if (rangerUrl.endsWith("/")) {
rangerUrl = rangerUrl.substring(0, rangerUrl.length()-1);
}
String rangerAuthUrl = String.format("%s/%s", rangerUrl,
"service/public/api/repository/count");
String rangerUserUrl = String.format("%s/%s", rangerUrl,
"service/xusers/users");
List<String> failReasons = new ArrayList<>();
List<String> warnReasons = new ArrayList<>();
// !!! first, just try the service with the admin credentials
try {
int response = checkLogin(streamProvider, rangerAuthUrl, adminUsername, adminPassword);
switch (response) {
case 401: {
String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request);
failReasons.add(String.format(reason, adminUsername));
break;
}
case 200: {
break;
}
default: {
String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request);
warnReasons.add(String.format(reason, adminUsername, response, rangerAuthUrl));
break;
}
}
} catch (IOException e) {
LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e);
LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage());
String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request);
warnReasons.add(String.format(reason, adminUsername, rangerAuthUrl, e.getMessage()));
}
// !!! shortcut when something happened with the admin user
if (!failReasons.isEmpty()) {
check.setFailReason(StringUtils.join(failReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.FAIL);
return;
} else if (!warnReasons.isEmpty()) {
check.setFailReason(StringUtils.join(warnReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.WARNING);
return;
}
// !!! Check for the user, capture exceptions as a warning.
boolean hasUser = checkRangerUser(streamProvider, rangerUserUrl, adminUsername, adminPassword,
rangerAdminUsername, check, request, warnReasons);
if (hasUser) {
// !!! try credentials for specific user
try {
int response = checkLogin(streamProvider, rangerAuthUrl, rangerAdminUsername,
rangerAdminPassword);
switch (response) {
case 401: {
String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request);
failReasons.add(String.format(reason, rangerAdminUsername));
break;
}
case 200: {
break;
}
default: {
String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request);
warnReasons.add(String.format(reason, rangerAdminUsername, response, rangerAuthUrl));
break;
}
}
} catch (IOException e) {
LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage());
LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e);
String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request);
warnReasons.add(String.format(reason, rangerAdminUsername, rangerAuthUrl, e.getMessage()));
}
}
if (!failReasons.isEmpty()) {
check.setFailReason(StringUtils.join(failReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.FAIL);
} else if (!warnReasons.isEmpty()) {
check.setFailReason(StringUtils.join(warnReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.WARNING);
} else {
check.setStatus(PrereqCheckStatus.PASS);
}
} |
223551095_1954 | @Override
public void perform(PrerequisiteCheck check, PrereqCheckRequest request) throws AmbariException {
// !!! ComponentSSLConfiguration is an old-school singleton which doesn't
// get initialized until after Guice is done - because this check is bound
// as a singleton via Guice, we can't initialize the stream provider in the
// constructor since the SSL configuration instance hasn't been initialized
URLStreamProvider streamProvider = new URLStreamProvider(2000, 2000,
ComponentSSLConfiguration.instance());
String rangerUrl = checkEmpty("admin-properties", "policymgr_external_url", check, request);
if (null == rangerUrl) {
// !!! check results already filled
return;
}
String adminUsername = checkEmpty("ranger-env", "admin_username", check, request);
if (null == adminUsername) {
return;
}
String adminPassword = checkEmpty("ranger-env", "admin_password", check, request);
if (null == adminPassword) {
return;
}
String rangerAdminUsername = checkEmpty("ranger-env", "ranger_admin_username", check, request);
if (null == rangerAdminUsername) {
return;
}
String rangerAdminPassword = checkEmpty("ranger-env", "ranger_admin_password", check, request);
if (null == rangerAdminPassword) {
return;
}
if (rangerUrl.endsWith("/")) {
rangerUrl = rangerUrl.substring(0, rangerUrl.length()-1);
}
String rangerAuthUrl = String.format("%s/%s", rangerUrl,
"service/public/api/repository/count");
String rangerUserUrl = String.format("%s/%s", rangerUrl,
"service/xusers/users");
List<String> failReasons = new ArrayList<>();
List<String> warnReasons = new ArrayList<>();
// !!! first, just try the service with the admin credentials
try {
int response = checkLogin(streamProvider, rangerAuthUrl, adminUsername, adminPassword);
switch (response) {
case 401: {
String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request);
failReasons.add(String.format(reason, adminUsername));
break;
}
case 200: {
break;
}
default: {
String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request);
warnReasons.add(String.format(reason, adminUsername, response, rangerAuthUrl));
break;
}
}
} catch (IOException e) {
LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e);
LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage());
String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request);
warnReasons.add(String.format(reason, adminUsername, rangerAuthUrl, e.getMessage()));
}
// !!! shortcut when something happened with the admin user
if (!failReasons.isEmpty()) {
check.setFailReason(StringUtils.join(failReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.FAIL);
return;
} else if (!warnReasons.isEmpty()) {
check.setFailReason(StringUtils.join(warnReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.WARNING);
return;
}
// !!! Check for the user, capture exceptions as a warning.
boolean hasUser = checkRangerUser(streamProvider, rangerUserUrl, adminUsername, adminPassword,
rangerAdminUsername, check, request, warnReasons);
if (hasUser) {
// !!! try credentials for specific user
try {
int response = checkLogin(streamProvider, rangerAuthUrl, rangerAdminUsername,
rangerAdminPassword);
switch (response) {
case 401: {
String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request);
failReasons.add(String.format(reason, rangerAdminUsername));
break;
}
case 200: {
break;
}
default: {
String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request);
warnReasons.add(String.format(reason, rangerAdminUsername, response, rangerAuthUrl));
break;
}
}
} catch (IOException e) {
LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage());
LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e);
String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request);
warnReasons.add(String.format(reason, rangerAdminUsername, rangerAuthUrl, e.getMessage()));
}
}
if (!failReasons.isEmpty()) {
check.setFailReason(StringUtils.join(failReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.FAIL);
} else if (!warnReasons.isEmpty()) {
check.setFailReason(StringUtils.join(warnReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.WARNING);
} else {
check.setStatus(PrereqCheckStatus.PASS);
}
} |
223551095_1955 | @Override
public void perform(PrerequisiteCheck check, PrereqCheckRequest request) throws AmbariException {
// !!! ComponentSSLConfiguration is an old-school singleton which doesn't
// get initialized until after Guice is done - because this check is bound
// as a singleton via Guice, we can't initialize the stream provider in the
// constructor since the SSL configuration instance hasn't been initialized
URLStreamProvider streamProvider = new URLStreamProvider(2000, 2000,
ComponentSSLConfiguration.instance());
String rangerUrl = checkEmpty("admin-properties", "policymgr_external_url", check, request);
if (null == rangerUrl) {
// !!! check results already filled
return;
}
String adminUsername = checkEmpty("ranger-env", "admin_username", check, request);
if (null == adminUsername) {
return;
}
String adminPassword = checkEmpty("ranger-env", "admin_password", check, request);
if (null == adminPassword) {
return;
}
String rangerAdminUsername = checkEmpty("ranger-env", "ranger_admin_username", check, request);
if (null == rangerAdminUsername) {
return;
}
String rangerAdminPassword = checkEmpty("ranger-env", "ranger_admin_password", check, request);
if (null == rangerAdminPassword) {
return;
}
if (rangerUrl.endsWith("/")) {
rangerUrl = rangerUrl.substring(0, rangerUrl.length()-1);
}
String rangerAuthUrl = String.format("%s/%s", rangerUrl,
"service/public/api/repository/count");
String rangerUserUrl = String.format("%s/%s", rangerUrl,
"service/xusers/users");
List<String> failReasons = new ArrayList<>();
List<String> warnReasons = new ArrayList<>();
// !!! first, just try the service with the admin credentials
try {
int response = checkLogin(streamProvider, rangerAuthUrl, adminUsername, adminPassword);
switch (response) {
case 401: {
String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request);
failReasons.add(String.format(reason, adminUsername));
break;
}
case 200: {
break;
}
default: {
String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request);
warnReasons.add(String.format(reason, adminUsername, response, rangerAuthUrl));
break;
}
}
} catch (IOException e) {
LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e);
LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage());
String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request);
warnReasons.add(String.format(reason, adminUsername, rangerAuthUrl, e.getMessage()));
}
// !!! shortcut when something happened with the admin user
if (!failReasons.isEmpty()) {
check.setFailReason(StringUtils.join(failReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.FAIL);
return;
} else if (!warnReasons.isEmpty()) {
check.setFailReason(StringUtils.join(warnReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.WARNING);
return;
}
// !!! Check for the user, capture exceptions as a warning.
boolean hasUser = checkRangerUser(streamProvider, rangerUserUrl, adminUsername, adminPassword,
rangerAdminUsername, check, request, warnReasons);
if (hasUser) {
// !!! try credentials for specific user
try {
int response = checkLogin(streamProvider, rangerAuthUrl, rangerAdminUsername,
rangerAdminPassword);
switch (response) {
case 401: {
String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request);
failReasons.add(String.format(reason, rangerAdminUsername));
break;
}
case 200: {
break;
}
default: {
String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request);
warnReasons.add(String.format(reason, rangerAdminUsername, response, rangerAuthUrl));
break;
}
}
} catch (IOException e) {
LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage());
LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e);
String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request);
warnReasons.add(String.format(reason, rangerAdminUsername, rangerAuthUrl, e.getMessage()));
}
}
if (!failReasons.isEmpty()) {
check.setFailReason(StringUtils.join(failReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.FAIL);
} else if (!warnReasons.isEmpty()) {
check.setFailReason(StringUtils.join(warnReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.WARNING);
} else {
check.setStatus(PrereqCheckStatus.PASS);
}
} |
223551095_1956 | @Override
public void perform(PrerequisiteCheck check, PrereqCheckRequest request) throws AmbariException {
// !!! ComponentSSLConfiguration is an old-school singleton which doesn't
// get initialized until after Guice is done - because this check is bound
// as a singleton via Guice, we can't initialize the stream provider in the
// constructor since the SSL configuration instance hasn't been initialized
URLStreamProvider streamProvider = new URLStreamProvider(2000, 2000,
ComponentSSLConfiguration.instance());
String rangerUrl = checkEmpty("admin-properties", "policymgr_external_url", check, request);
if (null == rangerUrl) {
// !!! check results already filled
return;
}
String adminUsername = checkEmpty("ranger-env", "admin_username", check, request);
if (null == adminUsername) {
return;
}
String adminPassword = checkEmpty("ranger-env", "admin_password", check, request);
if (null == adminPassword) {
return;
}
String rangerAdminUsername = checkEmpty("ranger-env", "ranger_admin_username", check, request);
if (null == rangerAdminUsername) {
return;
}
String rangerAdminPassword = checkEmpty("ranger-env", "ranger_admin_password", check, request);
if (null == rangerAdminPassword) {
return;
}
if (rangerUrl.endsWith("/")) {
rangerUrl = rangerUrl.substring(0, rangerUrl.length()-1);
}
String rangerAuthUrl = String.format("%s/%s", rangerUrl,
"service/public/api/repository/count");
String rangerUserUrl = String.format("%s/%s", rangerUrl,
"service/xusers/users");
List<String> failReasons = new ArrayList<>();
List<String> warnReasons = new ArrayList<>();
// !!! first, just try the service with the admin credentials
try {
int response = checkLogin(streamProvider, rangerAuthUrl, adminUsername, adminPassword);
switch (response) {
case 401: {
String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request);
failReasons.add(String.format(reason, adminUsername));
break;
}
case 200: {
break;
}
default: {
String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request);
warnReasons.add(String.format(reason, adminUsername, response, rangerAuthUrl));
break;
}
}
} catch (IOException e) {
LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e);
LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage());
String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request);
warnReasons.add(String.format(reason, adminUsername, rangerAuthUrl, e.getMessage()));
}
// !!! shortcut when something happened with the admin user
if (!failReasons.isEmpty()) {
check.setFailReason(StringUtils.join(failReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.FAIL);
return;
} else if (!warnReasons.isEmpty()) {
check.setFailReason(StringUtils.join(warnReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.WARNING);
return;
}
// !!! Check for the user, capture exceptions as a warning.
boolean hasUser = checkRangerUser(streamProvider, rangerUserUrl, adminUsername, adminPassword,
rangerAdminUsername, check, request, warnReasons);
if (hasUser) {
// !!! try credentials for specific user
try {
int response = checkLogin(streamProvider, rangerAuthUrl, rangerAdminUsername,
rangerAdminPassword);
switch (response) {
case 401: {
String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request);
failReasons.add(String.format(reason, rangerAdminUsername));
break;
}
case 200: {
break;
}
default: {
String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request);
warnReasons.add(String.format(reason, rangerAdminUsername, response, rangerAuthUrl));
break;
}
}
} catch (IOException e) {
LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage());
LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e);
String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request);
warnReasons.add(String.format(reason, rangerAdminUsername, rangerAuthUrl, e.getMessage()));
}
}
if (!failReasons.isEmpty()) {
check.setFailReason(StringUtils.join(failReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.FAIL);
} else if (!warnReasons.isEmpty()) {
check.setFailReason(StringUtils.join(warnReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.WARNING);
} else {
check.setStatus(PrereqCheckStatus.PASS);
}
} |
223551095_1957 | @Override
public void perform(PrerequisiteCheck check, PrereqCheckRequest request) throws AmbariException {
// !!! ComponentSSLConfiguration is an old-school singleton which doesn't
// get initialized until after Guice is done - because this check is bound
// as a singleton via Guice, we can't initialize the stream provider in the
// constructor since the SSL configuration instance hasn't been initialized
URLStreamProvider streamProvider = new URLStreamProvider(2000, 2000,
ComponentSSLConfiguration.instance());
String rangerUrl = checkEmpty("admin-properties", "policymgr_external_url", check, request);
if (null == rangerUrl) {
// !!! check results already filled
return;
}
String adminUsername = checkEmpty("ranger-env", "admin_username", check, request);
if (null == adminUsername) {
return;
}
String adminPassword = checkEmpty("ranger-env", "admin_password", check, request);
if (null == adminPassword) {
return;
}
String rangerAdminUsername = checkEmpty("ranger-env", "ranger_admin_username", check, request);
if (null == rangerAdminUsername) {
return;
}
String rangerAdminPassword = checkEmpty("ranger-env", "ranger_admin_password", check, request);
if (null == rangerAdminPassword) {
return;
}
if (rangerUrl.endsWith("/")) {
rangerUrl = rangerUrl.substring(0, rangerUrl.length()-1);
}
String rangerAuthUrl = String.format("%s/%s", rangerUrl,
"service/public/api/repository/count");
String rangerUserUrl = String.format("%s/%s", rangerUrl,
"service/xusers/users");
List<String> failReasons = new ArrayList<>();
List<String> warnReasons = new ArrayList<>();
// !!! first, just try the service with the admin credentials
try {
int response = checkLogin(streamProvider, rangerAuthUrl, adminUsername, adminPassword);
switch (response) {
case 401: {
String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request);
failReasons.add(String.format(reason, adminUsername));
break;
}
case 200: {
break;
}
default: {
String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request);
warnReasons.add(String.format(reason, adminUsername, response, rangerAuthUrl));
break;
}
}
} catch (IOException e) {
LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e);
LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage());
String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request);
warnReasons.add(String.format(reason, adminUsername, rangerAuthUrl, e.getMessage()));
}
// !!! shortcut when something happened with the admin user
if (!failReasons.isEmpty()) {
check.setFailReason(StringUtils.join(failReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.FAIL);
return;
} else if (!warnReasons.isEmpty()) {
check.setFailReason(StringUtils.join(warnReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.WARNING);
return;
}
// !!! Check for the user, capture exceptions as a warning.
boolean hasUser = checkRangerUser(streamProvider, rangerUserUrl, adminUsername, adminPassword,
rangerAdminUsername, check, request, warnReasons);
if (hasUser) {
// !!! try credentials for specific user
try {
int response = checkLogin(streamProvider, rangerAuthUrl, rangerAdminUsername,
rangerAdminPassword);
switch (response) {
case 401: {
String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request);
failReasons.add(String.format(reason, rangerAdminUsername));
break;
}
case 200: {
break;
}
default: {
String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request);
warnReasons.add(String.format(reason, rangerAdminUsername, response, rangerAuthUrl));
break;
}
}
} catch (IOException e) {
LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage());
LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e);
String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request);
warnReasons.add(String.format(reason, rangerAdminUsername, rangerAuthUrl, e.getMessage()));
}
}
if (!failReasons.isEmpty()) {
check.setFailReason(StringUtils.join(failReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.FAIL);
} else if (!warnReasons.isEmpty()) {
check.setFailReason(StringUtils.join(warnReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.WARNING);
} else {
check.setStatus(PrereqCheckStatus.PASS);
}
} |
223551095_1958 | @Override
public void perform(PrerequisiteCheck check, PrereqCheckRequest request) throws AmbariException {
// !!! ComponentSSLConfiguration is an old-school singleton which doesn't
// get initialized until after Guice is done - because this check is bound
// as a singleton via Guice, we can't initialize the stream provider in the
// constructor since the SSL configuration instance hasn't been initialized
URLStreamProvider streamProvider = new URLStreamProvider(2000, 2000,
ComponentSSLConfiguration.instance());
String rangerUrl = checkEmpty("admin-properties", "policymgr_external_url", check, request);
if (null == rangerUrl) {
// !!! check results already filled
return;
}
String adminUsername = checkEmpty("ranger-env", "admin_username", check, request);
if (null == adminUsername) {
return;
}
String adminPassword = checkEmpty("ranger-env", "admin_password", check, request);
if (null == adminPassword) {
return;
}
String rangerAdminUsername = checkEmpty("ranger-env", "ranger_admin_username", check, request);
if (null == rangerAdminUsername) {
return;
}
String rangerAdminPassword = checkEmpty("ranger-env", "ranger_admin_password", check, request);
if (null == rangerAdminPassword) {
return;
}
if (rangerUrl.endsWith("/")) {
rangerUrl = rangerUrl.substring(0, rangerUrl.length()-1);
}
String rangerAuthUrl = String.format("%s/%s", rangerUrl,
"service/public/api/repository/count");
String rangerUserUrl = String.format("%s/%s", rangerUrl,
"service/xusers/users");
List<String> failReasons = new ArrayList<>();
List<String> warnReasons = new ArrayList<>();
// !!! first, just try the service with the admin credentials
try {
int response = checkLogin(streamProvider, rangerAuthUrl, adminUsername, adminPassword);
switch (response) {
case 401: {
String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request);
failReasons.add(String.format(reason, adminUsername));
break;
}
case 200: {
break;
}
default: {
String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request);
warnReasons.add(String.format(reason, adminUsername, response, rangerAuthUrl));
break;
}
}
} catch (IOException e) {
LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e);
LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage());
String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request);
warnReasons.add(String.format(reason, adminUsername, rangerAuthUrl, e.getMessage()));
}
// !!! shortcut when something happened with the admin user
if (!failReasons.isEmpty()) {
check.setFailReason(StringUtils.join(failReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.FAIL);
return;
} else if (!warnReasons.isEmpty()) {
check.setFailReason(StringUtils.join(warnReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.WARNING);
return;
}
// !!! Check for the user, capture exceptions as a warning.
boolean hasUser = checkRangerUser(streamProvider, rangerUserUrl, adminUsername, adminPassword,
rangerAdminUsername, check, request, warnReasons);
if (hasUser) {
// !!! try credentials for specific user
try {
int response = checkLogin(streamProvider, rangerAuthUrl, rangerAdminUsername,
rangerAdminPassword);
switch (response) {
case 401: {
String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request);
failReasons.add(String.format(reason, rangerAdminUsername));
break;
}
case 200: {
break;
}
default: {
String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request);
warnReasons.add(String.format(reason, rangerAdminUsername, response, rangerAuthUrl));
break;
}
}
} catch (IOException e) {
LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage());
LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e);
String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request);
warnReasons.add(String.format(reason, rangerAdminUsername, rangerAuthUrl, e.getMessage()));
}
}
if (!failReasons.isEmpty()) {
check.setFailReason(StringUtils.join(failReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.FAIL);
} else if (!warnReasons.isEmpty()) {
check.setFailReason(StringUtils.join(warnReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.WARNING);
} else {
check.setStatus(PrereqCheckStatus.PASS);
}
} |
223551095_1959 | @Override
public void perform(PrerequisiteCheck check, PrereqCheckRequest request) throws AmbariException {
// !!! ComponentSSLConfiguration is an old-school singleton which doesn't
// get initialized until after Guice is done - because this check is bound
// as a singleton via Guice, we can't initialize the stream provider in the
// constructor since the SSL configuration instance hasn't been initialized
URLStreamProvider streamProvider = new URLStreamProvider(2000, 2000,
ComponentSSLConfiguration.instance());
String rangerUrl = checkEmpty("admin-properties", "policymgr_external_url", check, request);
if (null == rangerUrl) {
// !!! check results already filled
return;
}
String adminUsername = checkEmpty("ranger-env", "admin_username", check, request);
if (null == adminUsername) {
return;
}
String adminPassword = checkEmpty("ranger-env", "admin_password", check, request);
if (null == adminPassword) {
return;
}
String rangerAdminUsername = checkEmpty("ranger-env", "ranger_admin_username", check, request);
if (null == rangerAdminUsername) {
return;
}
String rangerAdminPassword = checkEmpty("ranger-env", "ranger_admin_password", check, request);
if (null == rangerAdminPassword) {
return;
}
if (rangerUrl.endsWith("/")) {
rangerUrl = rangerUrl.substring(0, rangerUrl.length()-1);
}
String rangerAuthUrl = String.format("%s/%s", rangerUrl,
"service/public/api/repository/count");
String rangerUserUrl = String.format("%s/%s", rangerUrl,
"service/xusers/users");
List<String> failReasons = new ArrayList<>();
List<String> warnReasons = new ArrayList<>();
// !!! first, just try the service with the admin credentials
try {
int response = checkLogin(streamProvider, rangerAuthUrl, adminUsername, adminPassword);
switch (response) {
case 401: {
String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request);
failReasons.add(String.format(reason, adminUsername));
break;
}
case 200: {
break;
}
default: {
String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request);
warnReasons.add(String.format(reason, adminUsername, response, rangerAuthUrl));
break;
}
}
} catch (IOException e) {
LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e);
LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage());
String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request);
warnReasons.add(String.format(reason, adminUsername, rangerAuthUrl, e.getMessage()));
}
// !!! shortcut when something happened with the admin user
if (!failReasons.isEmpty()) {
check.setFailReason(StringUtils.join(failReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.FAIL);
return;
} else if (!warnReasons.isEmpty()) {
check.setFailReason(StringUtils.join(warnReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.WARNING);
return;
}
// !!! Check for the user, capture exceptions as a warning.
boolean hasUser = checkRangerUser(streamProvider, rangerUserUrl, adminUsername, adminPassword,
rangerAdminUsername, check, request, warnReasons);
if (hasUser) {
// !!! try credentials for specific user
try {
int response = checkLogin(streamProvider, rangerAuthUrl, rangerAdminUsername,
rangerAdminPassword);
switch (response) {
case 401: {
String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request);
failReasons.add(String.format(reason, rangerAdminUsername));
break;
}
case 200: {
break;
}
default: {
String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request);
warnReasons.add(String.format(reason, rangerAdminUsername, response, rangerAuthUrl));
break;
}
}
} catch (IOException e) {
LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage());
LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e);
String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request);
warnReasons.add(String.format(reason, rangerAdminUsername, rangerAuthUrl, e.getMessage()));
}
}
if (!failReasons.isEmpty()) {
check.setFailReason(StringUtils.join(failReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.FAIL);
} else if (!warnReasons.isEmpty()) {
check.setFailReason(StringUtils.join(warnReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.WARNING);
} else {
check.setStatus(PrereqCheckStatus.PASS);
}
} |
223551095_1960 | @Override
public void perform(PrerequisiteCheck check, PrereqCheckRequest request) throws AmbariException {
// !!! ComponentSSLConfiguration is an old-school singleton which doesn't
// get initialized until after Guice is done - because this check is bound
// as a singleton via Guice, we can't initialize the stream provider in the
// constructor since the SSL configuration instance hasn't been initialized
URLStreamProvider streamProvider = new URLStreamProvider(2000, 2000,
ComponentSSLConfiguration.instance());
String rangerUrl = checkEmpty("admin-properties", "policymgr_external_url", check, request);
if (null == rangerUrl) {
// !!! check results already filled
return;
}
String adminUsername = checkEmpty("ranger-env", "admin_username", check, request);
if (null == adminUsername) {
return;
}
String adminPassword = checkEmpty("ranger-env", "admin_password", check, request);
if (null == adminPassword) {
return;
}
String rangerAdminUsername = checkEmpty("ranger-env", "ranger_admin_username", check, request);
if (null == rangerAdminUsername) {
return;
}
String rangerAdminPassword = checkEmpty("ranger-env", "ranger_admin_password", check, request);
if (null == rangerAdminPassword) {
return;
}
if (rangerUrl.endsWith("/")) {
rangerUrl = rangerUrl.substring(0, rangerUrl.length()-1);
}
String rangerAuthUrl = String.format("%s/%s", rangerUrl,
"service/public/api/repository/count");
String rangerUserUrl = String.format("%s/%s", rangerUrl,
"service/xusers/users");
List<String> failReasons = new ArrayList<>();
List<String> warnReasons = new ArrayList<>();
// !!! first, just try the service with the admin credentials
try {
int response = checkLogin(streamProvider, rangerAuthUrl, adminUsername, adminPassword);
switch (response) {
case 401: {
String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request);
failReasons.add(String.format(reason, adminUsername));
break;
}
case 200: {
break;
}
default: {
String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request);
warnReasons.add(String.format(reason, adminUsername, response, rangerAuthUrl));
break;
}
}
} catch (IOException e) {
LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e);
LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage());
String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request);
warnReasons.add(String.format(reason, adminUsername, rangerAuthUrl, e.getMessage()));
}
// !!! shortcut when something happened with the admin user
if (!failReasons.isEmpty()) {
check.setFailReason(StringUtils.join(failReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.FAIL);
return;
} else if (!warnReasons.isEmpty()) {
check.setFailReason(StringUtils.join(warnReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.WARNING);
return;
}
// !!! Check for the user, capture exceptions as a warning.
boolean hasUser = checkRangerUser(streamProvider, rangerUserUrl, adminUsername, adminPassword,
rangerAdminUsername, check, request, warnReasons);
if (hasUser) {
// !!! try credentials for specific user
try {
int response = checkLogin(streamProvider, rangerAuthUrl, rangerAdminUsername,
rangerAdminPassword);
switch (response) {
case 401: {
String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request);
failReasons.add(String.format(reason, rangerAdminUsername));
break;
}
case 200: {
break;
}
default: {
String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request);
warnReasons.add(String.format(reason, rangerAdminUsername, response, rangerAuthUrl));
break;
}
}
} catch (IOException e) {
LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage());
LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e);
String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request);
warnReasons.add(String.format(reason, rangerAdminUsername, rangerAuthUrl, e.getMessage()));
}
}
if (!failReasons.isEmpty()) {
check.setFailReason(StringUtils.join(failReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.FAIL);
} else if (!warnReasons.isEmpty()) {
check.setFailReason(StringUtils.join(warnReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.WARNING);
} else {
check.setStatus(PrereqCheckStatus.PASS);
}
} |
223551095_1961 | @Override
public void perform(PrerequisiteCheck check, PrereqCheckRequest request) throws AmbariException {
// !!! ComponentSSLConfiguration is an old-school singleton which doesn't
// get initialized until after Guice is done - because this check is bound
// as a singleton via Guice, we can't initialize the stream provider in the
// constructor since the SSL configuration instance hasn't been initialized
URLStreamProvider streamProvider = new URLStreamProvider(2000, 2000,
ComponentSSLConfiguration.instance());
String rangerUrl = checkEmpty("admin-properties", "policymgr_external_url", check, request);
if (null == rangerUrl) {
// !!! check results already filled
return;
}
String adminUsername = checkEmpty("ranger-env", "admin_username", check, request);
if (null == adminUsername) {
return;
}
String adminPassword = checkEmpty("ranger-env", "admin_password", check, request);
if (null == adminPassword) {
return;
}
String rangerAdminUsername = checkEmpty("ranger-env", "ranger_admin_username", check, request);
if (null == rangerAdminUsername) {
return;
}
String rangerAdminPassword = checkEmpty("ranger-env", "ranger_admin_password", check, request);
if (null == rangerAdminPassword) {
return;
}
if (rangerUrl.endsWith("/")) {
rangerUrl = rangerUrl.substring(0, rangerUrl.length()-1);
}
String rangerAuthUrl = String.format("%s/%s", rangerUrl,
"service/public/api/repository/count");
String rangerUserUrl = String.format("%s/%s", rangerUrl,
"service/xusers/users");
List<String> failReasons = new ArrayList<>();
List<String> warnReasons = new ArrayList<>();
// !!! first, just try the service with the admin credentials
try {
int response = checkLogin(streamProvider, rangerAuthUrl, adminUsername, adminPassword);
switch (response) {
case 401: {
String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request);
failReasons.add(String.format(reason, adminUsername));
break;
}
case 200: {
break;
}
default: {
String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request);
warnReasons.add(String.format(reason, adminUsername, response, rangerAuthUrl));
break;
}
}
} catch (IOException e) {
LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e);
LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage());
String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request);
warnReasons.add(String.format(reason, adminUsername, rangerAuthUrl, e.getMessage()));
}
// !!! shortcut when something happened with the admin user
if (!failReasons.isEmpty()) {
check.setFailReason(StringUtils.join(failReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.FAIL);
return;
} else if (!warnReasons.isEmpty()) {
check.setFailReason(StringUtils.join(warnReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.WARNING);
return;
}
// !!! Check for the user, capture exceptions as a warning.
boolean hasUser = checkRangerUser(streamProvider, rangerUserUrl, adminUsername, adminPassword,
rangerAdminUsername, check, request, warnReasons);
if (hasUser) {
// !!! try credentials for specific user
try {
int response = checkLogin(streamProvider, rangerAuthUrl, rangerAdminUsername,
rangerAdminPassword);
switch (response) {
case 401: {
String reason = getFailReason(KEY_RANGER_PASSWORD_MISMATCH, check, request);
failReasons.add(String.format(reason, rangerAdminUsername));
break;
}
case 200: {
break;
}
default: {
String reason = getFailReason(KEY_RANGER_UNKNOWN_RESPONSE, check, request);
warnReasons.add(String.format(reason, rangerAdminUsername, response, rangerAuthUrl));
break;
}
}
} catch (IOException e) {
LOG.warn("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage());
LOG.debug("Could not access the url {}. Message: {}", rangerAuthUrl, e.getMessage(), e);
String reason = getFailReason(KEY_RANGER_COULD_NOT_ACCESS, check, request);
warnReasons.add(String.format(reason, rangerAdminUsername, rangerAuthUrl, e.getMessage()));
}
}
if (!failReasons.isEmpty()) {
check.setFailReason(StringUtils.join(failReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.FAIL);
} else if (!warnReasons.isEmpty()) {
check.setFailReason(StringUtils.join(warnReasons, '\n'));
check.getFailedOn().add("RANGER");
check.setStatus(PrereqCheckStatus.WARNING);
} else {
check.setStatus(PrereqCheckStatus.PASS);
}
} |
223551095_1962 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
if (config.getGplLicenseAccepted()){
return;
}
List<String> errorMessages = new ArrayList<>();
PrereqCheckStatus checkStatus = PrereqCheckStatus.WARNING;
String codecs = getProperty(request, "core-site", IO_COMPRESSION_CODECS);
if (codecs!= null && codecs.contains(LZO_ENABLE_VALUE)) {
errorMessages.add(getFailReason(IO_COMPRESSION_CODECS, prerequisiteCheck, request));
}
String classValue = getProperty(request, "core-site", LZO_ENABLE_KEY);
if (LZO_ENABLE_VALUE.equals(classValue)) {
errorMessages.add(getFailReason(LZO_ENABLE_KEY, prerequisiteCheck, request));
}
if (!errorMessages.isEmpty()) {
prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, "You have LZO codec enabled in the core-site config of your cluster. " +
"You have to accept GPL license during ambari-server setup to have LZO installed automatically. " +
"If any hosts require LZO, it should be installed before starting the upgrade. " +
"Consult Ambari documentation for instructions on how to do this."));
prerequisiteCheck.getFailedOn().add("LZO");
prerequisiteCheck.setStatus(checkStatus);
}
} |
223551095_1963 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
String errorMessage = null;
UpgradeEntity upgradeInProgress = cluster.getUpgradeInProgress();
if (null != upgradeInProgress) {
Direction direction = upgradeInProgress.getDirection();
String directionText = direction.getText(false);
String prepositionText = direction.getPreposition();
errorMessage = MessageFormat.format(ERROR_MESSAGE, directionText, prepositionText,
upgradeInProgress.getRepositoryVersion().getVersion(), directionText);
}
if (null != errorMessage) {
LinkedHashSet<String> failedOn = new LinkedHashSet<>();
failedOn.add(cluster.getClusterName());
prerequisiteCheck.setFailedOn(failedOn);
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(errorMessage);
}
} |
223551095_1964 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
String atlasMigrationProperty = getProperty(request,"application-properties","atlas.migration.data.filename");
if(StringUtils.isBlank(atlasMigrationProperty)) {
LOG.info("The property atlas.migration.data.filename is not found in application-properties, need to add the property before upgrade.");
prerequisiteCheck.getFailedOn().add(serviceName);
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
} else if (atlasMigrationProperty.contains("/etc/atlas/conf")) {
LOG.info("The property atlas.migration.data.filename is found in application-properties, but it contains atlas conf path ie /etc/atlas/conf. Avoid using conf path for this property.");
prerequisiteCheck.getFailedOn().add(serviceName);
prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING);
prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
}
} |
223551095_1965 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request)
throws AmbariException {
AlertsDAO alertsDAO = alertsDAOProvider.get();
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
List<AlertCurrentEntity> alerts = alertsDAO.findCurrentByCluster(cluster.getClusterId());
List<String> errorMessages = new ArrayList<>();
for (AlertCurrentEntity alert : alerts) {
AlertHistoryEntity alertHistory = alert.getAlertHistory();
AlertState alertState = alertHistory.getAlertState();
if (ALERT_STATES.contains(alertState) && !alert.getMaintenanceState().equals(MaintenanceState.ON)) {
String state = alertState.name();
String label = alertHistory.getAlertDefinition().getLabel();
String hostName = alertHistory.getHostName();
if (hostName == null) {
errorMessages.add(state + ": " + label);
} else {
errorMessages.add(state + ": " + label + ": " + hostName);
}
prerequisiteCheck.getFailedDetail().add(new AlertDetail(state, label, hostName));
}
}
if (!errorMessages.isEmpty()) {
prerequisiteCheck.getFailedOn().add(clusterName);
prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING);
String failReason = getFailReason(prerequisiteCheck, request);
prerequisiteCheck.setFailReason(
String.format(failReason, StringUtils.join(errorMessages, System.lineSeparator())));
}
} |
223551095_1966 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request)
throws AmbariException {
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
List<String> errorMessages = new ArrayList<>();
LinkedHashSet<ServiceDetail> failedServices = new LinkedHashSet<>();
Set<String> servicesInUpgrade = getServicesInUpgrade(request);
for (String serviceName : servicesInUpgrade) {
final Service service = cluster.getService(serviceName);
// Ignore services like Tez that are clientOnly.
if (service.isClientOnlyService()) {
continue;
}
Map<String, ServiceComponent> serviceComponents = service.getServiceComponents();
for (Map.Entry<String, ServiceComponent> component : serviceComponents.entrySet()) {
ServiceComponent serviceComponent = component.getValue();
// In Services like HDFS, ignore components like HDFS Client
if (serviceComponent.isClientComponent()) {
continue;
}
// skip if the component is not part of the finalization version check
if (!serviceComponent.isVersionAdvertised()) {
continue;
}
// TODO, add more logic that checks the Upgrade Pack.
// These components are not in the upgrade pack and do not advertise a
// version:
// ZKFC, Ambari Metrics, Kerberos, Atlas (right now).
// Generally, if it advertises a version => in the upgrade pack.
// So it can be in the Upgrade Pack but not advertise a version.
List<HostComponentSummary> hostComponentSummaries = HostComponentSummary.getHostComponentSummaries(
service.getName(), serviceComponent.getName());
// not installed, nothing to do
if (hostComponentSummaries.isEmpty()) {
continue;
}
// non-master, "true" slaves with cardinality 1+
boolean checkThreshold = false;
if (!serviceComponent.isMasterComponent()) {
StackId stackId = service.getDesiredStackId();
ComponentInfo componentInfo = ambariMetaInfo.get().getComponent(stackId.getStackName(),
stackId.getStackVersion(), serviceComponent.getServiceName(),
serviceComponent.getName());
String cardinality = componentInfo.getCardinality();
// !!! check if there can be more than one. This will match, say,
// datanodes but not ZKFC
if (null != cardinality
&& (cardinality.equals("ALL") || cardinality.matches("[1-9].*"))) {
checkThreshold = true;
}
}
// check threshold for slaves which have a non-0 cardinality
if (checkThreshold) {
int total = hostComponentSummaries.size();
int up = 0;
int down = 0;
for (HostComponentSummary summary : hostComponentSummaries) {
if (isConsideredDown(cluster, serviceComponent, summary)) {
down++;
} else {
up++;
}
}
if ((float) down / total > SLAVE_THRESHOLD) { // arbitrary
failedServices.add(new ServiceDetail(serviceName));
String message = MessageFormat.format(
"{0}: {1} out of {2} {3} are started; there should be {4,number,percent} started before upgrading.",
service.getName(), up, total, serviceComponent.getName(), SLAVE_THRESHOLD);
errorMessages.add(message);
}
} else {
for (HostComponentSummary summary : hostComponentSummaries) {
if (isConsideredDown(cluster, serviceComponent, summary)) {
failedServices.add(new ServiceDetail(serviceName));
String message = MessageFormat.format("{0}: {1} (in {2} on host {3})",
service.getName(), serviceComponent.getName(), summary.getCurrentState(),
summary.getHostName());
errorMessages.add(message);
break;
}
}
}
}
}
if (!errorMessages.isEmpty()) {
prerequisiteCheck.setFailedOn(
failedServices.stream().map(failedService -> failedService.serviceName).collect(
Collectors.toCollection(LinkedHashSet::new)));
prerequisiteCheck.getFailedDetail().addAll(failedServices);
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(
"The following Service Components should be in a started state. Please invoke a service Stop and full Start and try again. "
+ StringUtils.join(errorMessages, ", "));
}
} |
223551095_1967 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException
{
List<String> haNotEnabledComponents = Lists.newArrayList();
for (String component : DRUID_COMPONENT_NAMES) {
Set<String> hosts = getHostsForComponent(request, component);
if (hosts.size() == 1) {
// This component is installed on only 1 host, HA is not enabled for it.
haNotEnabledComponents.add(component);
}
}
if (!haNotEnabledComponents.isEmpty()) {
prerequisiteCheck.getFailedOn().add(DRUID_SERVICE_NAME);
prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING);
String failReason = getFailReason(prerequisiteCheck, request);
prerequisiteCheck.setFailReason(String.format(failReason, StringUtils.join(haNotEnabledComponents.toArray(), ", ")));
}
} |
223551095_1968 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
prerequisiteCheck.getFailedOn().add("HIVE");
prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING);
prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
} |
223551095_1969 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
final Cluster cluster = clustersProvider.get().getCluster(request.getClusterName());
Map<String, Service> services = cluster.getServices();
List<String> errorMessages = new ArrayList<>();
// HDFS needs to actually prevent client retry since that causes them to try too long and not failover quickly.
if (services.containsKey("HDFS")) {
String clientRetryPolicyEnabled = getProperty(request, "hdfs-site", HDFS_CLIENT_RETRY_PROPERTY);
if (null != clientRetryPolicyEnabled && Boolean.parseBoolean(clientRetryPolicyEnabled)) {
MissingClientRetryProperty missingProperty = new MissingClientRetryProperty("HDFS",
"hdfs-site", HDFS_CLIENT_RETRY_PROPERTY);
prerequisiteCheck.getFailedDetail().add(missingProperty);
errorMessages.add(getFailReason(HDFS_CLIENT_RETRY_DISABLED_KEY, prerequisiteCheck, request));
prerequisiteCheck.getFailedOn().add("HDFS");
}
}
// check hive client properties
if (services.containsKey("HIVE")) {
String hiveClientRetryCount = getProperty(request, "hive-site", HIVE_CLIENT_RETRY_PROPERTY);
if (null != hiveClientRetryCount && Integer.parseInt(hiveClientRetryCount) <= 0) {
MissingClientRetryProperty missingProperty = new MissingClientRetryProperty("HIVE",
"hive-site", HIVE_CLIENT_RETRY_PROPERTY);
prerequisiteCheck.getFailedDetail().add(missingProperty);
errorMessages.add(getFailReason(HIVE_CLIENT_RETRY_MISSING_KEY, prerequisiteCheck, request));
prerequisiteCheck.getFailedOn().add("HIVE");
}
}
if (services.containsKey("OOZIE")) {
String oozieClientRetry = getProperty(request, "oozie-env", "content");
if (null == oozieClientRetry || !oozieClientRetry.contains(OOZIE_CLIENT_RETRY_PROPERTY)) {
MissingClientRetryProperty missingProperty = new MissingClientRetryProperty("OOZIE",
"oozie-env", OOZIE_CLIENT_RETRY_PROPERTY);
prerequisiteCheck.getFailedDetail().add(missingProperty);
errorMessages.add(getFailReason(OOZIE_CLIENT_RETRY_MISSING_KEY, prerequisiteCheck, request));
prerequisiteCheck.getFailedOn().add("OOZIE");
}
}
if (!errorMessages.isEmpty()) {
prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, " "));
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
}
} |
223551095_1970 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
Set<String> failedServiceNames = new HashSet<>();
// Preq-req check should fail if any service component is in INSTALL_FAILED state
Set<String> installFailedHostComponents = new HashSet<>();
Set<String> servicesInUpgrade = getServicesInUpgrade(request);
for (String serviceName : servicesInUpgrade) {
final Service service = cluster.getService(serviceName);
// Skip service if it is in maintenance mode
if (service.getMaintenanceState() == MaintenanceState.ON) {
continue;
}
Map<String, ServiceComponent> serviceComponents = service.getServiceComponents();
for (Map.Entry<String, ServiceComponent> component : serviceComponents.entrySet()) {
ServiceComponent serviceComponent = component.getValue();
if (serviceComponent.isVersionAdvertised()) {
List<HostComponentSummary> hostComponentSummaries = HostComponentSummary.getHostComponentSummaries(
service.getName(), serviceComponent.getName());
for (HostComponentSummary hcs : hostComponentSummaries) {
// Skip host if it is in maintenance mode
Host host = clustersProvider.get().getHost(hcs.getHostName());
if (host.getMaintenanceState(cluster.getClusterId()) != MaintenanceState.ON) {
if (hcs.getCurrentState() == State.INSTALL_FAILED) {
prerequisiteCheck.getFailedDetail().add(hcs);
failedServiceNames.add(service.getName());
installFailedHostComponents.add(MessageFormat.format("[{0}:{1} on {2}]",
service.getName(), serviceComponent.getName(), hcs.getHostName()));
}
}
}
}
}
}
if(!installFailedHostComponents.isEmpty()) {
String message = MessageFormat.format("Service components in INSTALL_FAILED state: {0}.",
StringUtils.join(installFailedHostComponents, ", "));
prerequisiteCheck.setFailedOn(new LinkedHashSet<>(failedServiceNames));
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(
"Found service components in INSTALL_FAILED state. Please re-install these components. " + message);
}
} |
223551095_1971 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
String propertyValue = getProperty(request, "ranger-admin-site", "ranger.audit.source.type");
if (null != propertyValue && propertyValue.equalsIgnoreCase("db")) {
prerequisiteCheck.getFailedOn().add(serviceName);
prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING);
prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
}
} |
223551095_1972 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
Config config = cluster.getDesiredConfigByType("hdfs-site");
String truncateEnabled = config.getProperties().get("dfs.allow.truncate");
if (Boolean.valueOf(truncateEnabled)) {
prerequisiteCheck.getFailedOn().add("HDFS");
PrereqCheckStatus checkStatus = PrereqCheckStatus.FAIL;
prerequisiteCheck.setStatus(checkStatus);
prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
}
} |
223551095_1973 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
String clusterName = request.getClusterName();
Cluster cluster = clustersProvider.get().getCluster(clusterName);
VersionDefinitionXml xml = getVersionDefinitionXml(request);
Set<String> missingDependencies = xml.getMissingDependencies(cluster);
if (!missingDependencies.isEmpty()) {
String failReasonTemplate = getFailReason(prerequisiteCheck, request);
String message = String.format(
"The following services are also required to be included in this upgrade: %s",
StringUtils.join(missingDependencies, ", "));
prerequisiteCheck.setFailedOn(new LinkedHashSet<>(missingDependencies));
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(String.format(failReasonTemplate, message));
Set<ServiceDetail> missingServiceDetails = missingDependencies.stream().map(
missingService -> new ServiceDetail(missingService)).collect(
Collectors.toCollection(TreeSet::new));
prerequisiteCheck.getFailedDetail().addAll(missingServiceDetails);
return;
}
prerequisiteCheck.setStatus(PrereqCheckStatus.PASS);
} |
223551095_1974 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
String clusterName = request.getClusterName();
Cluster cluster = clustersProvider.get().getCluster(clusterName);
VersionDefinitionXml xml = getVersionDefinitionXml(request);
Set<String> missingDependencies = xml.getMissingDependencies(cluster);
if (!missingDependencies.isEmpty()) {
String failReasonTemplate = getFailReason(prerequisiteCheck, request);
String message = String.format(
"The following services are also required to be included in this upgrade: %s",
StringUtils.join(missingDependencies, ", "));
prerequisiteCheck.setFailedOn(new LinkedHashSet<>(missingDependencies));
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(String.format(failReasonTemplate, message));
Set<ServiceDetail> missingServiceDetails = missingDependencies.stream().map(
missingService -> new ServiceDetail(missingService)).collect(
Collectors.toCollection(TreeSet::new));
prerequisiteCheck.getFailedDetail().addAll(missingServiceDetails);
return;
}
prerequisiteCheck.setStatus(PrereqCheckStatus.PASS);
} |
223551095_1975 | static void checkForConfigsSelectedMoreThanOnce() {
LOG.info("Checking for more than 1 configuration of the same type being enabled.");
String GET_CONFIGS_SELECTED_MORE_THAN_ONCE_QUERY = "select c.cluster_name, cc.type_name from clusterconfig cc "
+ "join clusters c on cc.cluster_id=c.cluster_id "
+ "group by c.cluster_name, cc.type_name " +
"having sum(selected) > 1";
Multimap<String, String> clusterConfigTypeMap = HashMultimap.create();
ResultSet rs = null;
Statement statement = null;
ensureConnection();
try {
statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs = statement.executeQuery(GET_CONFIGS_SELECTED_MORE_THAN_ONCE_QUERY);
if (rs != null) {
while (rs.next()) {
clusterConfigTypeMap.put(rs.getString("cluster_name"), rs.getString("type_name"));
}
for (String clusterName : clusterConfigTypeMap.keySet()) {
error("You have config(s), in cluster {}, that is(are) selected more than once in clusterconfig table: {}",
clusterName ,StringUtils.join(clusterConfigTypeMap.get(clusterName), ","));
}
}
} catch (SQLException e) {
warning("Exception occurred during check for config selected more than once procedure: ", e);
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
LOG.error("Exception occurred during result set closing procedure: ", e);
}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
LOG.error("Exception occurred during statement closing procedure: ", e);
}
}
}
} |
223551095_1976 | static void checkForHostsWithoutState() {
LOG.info("Checking for hosts without state");
String GET_HOSTS_WITHOUT_STATUS_QUERY = "select host_name from hosts where host_id not in (select host_id from hoststate)";
Set<String> hostsWithoutStatus = new HashSet<>();
ResultSet rs = null;
Statement statement = null;
ensureConnection();
try {
statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs = statement.executeQuery(GET_HOSTS_WITHOUT_STATUS_QUERY);
if (rs != null) {
while (rs.next()) {
hostsWithoutStatus.add(rs.getString("host_name"));
}
if (!hostsWithoutStatus.isEmpty()) {
warning("You have host(s) without state (in hoststate table): " + StringUtils.join(hostsWithoutStatus, ","));
}
}
} catch (SQLException e) {
warning("Exception occurred during check for host without state procedure: ", e);
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
LOG.error("Exception occurred during result set closing procedure: ", e);
}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
LOG.error("Exception occurred during statement closing procedure: ", e);
}
}
}
} |
223551095_1977 | static void checkServiceConfigs() {
LOG.info("Checking services and their configs");
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 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";
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, 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";
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 clusterconfig cc on scm.config_id=cc.config_id and cc.cluster_id=sc.cluster_id " +
"join clusters c on cc.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(cc.selected) < 1";
Multimap<String, String> clusterServiceMap = HashMultimap.create();
Map<String, Map<String, String>> clusterStackInfo = new HashMap<>();
Map<String, Multimap<String, String>> clusterServiceVersionMap = new HashMap<>();
Map<String, Multimap<String, String>> clusterServiceConfigType = new HashMap<>();
ResultSet rs = null;
Statement statement = null;
ensureConnection();
LOG.info("Getting ambari metainfo instance");
if (ambariMetaInfo == null) {
ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class);
}
try {
LOG.info("Executing query 'GET_SERVICES_WITHOUT_CONFIGS'");
statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs = statement.executeQuery(GET_SERVICES_WITHOUT_CONFIGS_QUERY);
if (rs != null) {
while (rs.next()) {
clusterServiceMap.put(rs.getString("cluster_name"), rs.getString("service_name"));
}
for (String clusterName : clusterServiceMap.keySet()) {
warning("Service(s): {}, from cluster {} has no config(s) in serviceconfig table!", StringUtils.join(clusterServiceMap.get(clusterName), ","), clusterName);
}
}
LOG.info("Executing query 'GET_SERVICE_CONFIG_WITHOUT_MAPPING'");
rs = statement.executeQuery(GET_SERVICE_CONFIG_WITHOUT_MAPPING_QUERY);
if (rs != null) {
String serviceName = null, version = null, clusterName = null;
while (rs.next()) {
serviceName = rs.getString("service_name");
clusterName = rs.getString("cluster_name");
version = rs.getString("version");
if (clusterServiceVersionMap.get(clusterName) != null) {
Multimap<String, String> serviceVersion = clusterServiceVersionMap.get(clusterName);
serviceVersion.put(serviceName, version);
} else {
Multimap<String, String> serviceVersion = HashMultimap.create();;
serviceVersion.put(serviceName, version);
clusterServiceVersionMap.put(clusterName, serviceVersion);
}
}
for (String clName : clusterServiceVersionMap.keySet()) {
Multimap<String, String> serviceVersion = clusterServiceVersionMap.get(clName);
for (String servName : serviceVersion.keySet()) {
warning("In cluster {}, service config mapping is unavailable (in table serviceconfigmapping) for service {} with version(s) {}! ", clName, servName, StringUtils.join(serviceVersion.get(servName), ","));
}
}
}
//get stack info from db
LOG.info("Getting stack info from database");
rs = statement.executeQuery(GET_STACK_NAME_VERSION_QUERY);
if (rs != null) {
while (rs.next()) {
Map<String, String> stackInfoMap = new HashMap<>();
stackInfoMap.put(rs.getString("stack_name"), rs.getString("stack_version"));
clusterStackInfo.put(rs.getString("cluster_name"), stackInfoMap);
}
}
Set<String> serviceNames = new HashSet<>();
Map<String, Map<Integer, Multimap<String, String>>> dbClusterServiceVersionConfigs = new HashMap<>();
Multimap<String, String> stackServiceConfigs = HashMultimap.create();
LOG.info("Executing query 'GET_SERVICES_WITH_CONFIGS'");
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);
//collect data about mapped configs to services from db
if (dbClusterServiceVersionConfigs.get(clusterName) != null) {
Map<Integer, Multimap<String, String>> dbServiceVersionConfigs = dbClusterServiceVersionConfigs.get(clusterName);
if (dbServiceVersionConfigs.get(serviceVersion) != null) {
dbServiceVersionConfigs.get(serviceVersion).put(serviceName, configType);
} else {
Multimap<String, String> dbServiceConfigs = HashMultimap.create();
dbServiceConfigs.put(serviceName, configType);
dbServiceVersionConfigs.put(serviceVersion, dbServiceConfigs);
}
} 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);
}
}
}
//compare service configs from stack with configs that we got from db
LOG.info("Comparing service configs from stack with configs that we got from db");
for (Map.Entry<String, Map<String, String>> clusterStackInfoEntry : clusterStackInfo.entrySet()) {
//collect required configs for all services from stack
String clusterName = clusterStackInfoEntry.getKey();
Map<String, String> stackInfo = clusterStackInfoEntry.getValue();
String stackName = stackInfo.keySet().iterator().next();
String stackVersion = stackInfo.get(stackName);
LOG.info("Getting services from metainfo");
Map<String, ServiceInfo> serviceInfoMap = ambariMetaInfo.getServices(stackName, stackVersion);
for (String serviceName : serviceNames) {
LOG.info("Processing {}-{} / {}", stackName, stackVersion, serviceName);
ServiceInfo serviceInfo = serviceInfoMap.get(serviceName);
if (serviceInfo != null) {
Set<String> configTypes = serviceInfo.getConfigTypeAttributes().keySet();
for (String configType : configTypes) {
stackServiceConfigs.put(serviceName, configType);
}
} else {
warning("Service {} is not available for stack {} in cluster {}",
serviceName, stackName + "-" + stackVersion, clusterName);
}
}
//compare required service configs from stack with mapped service configs from db
LOG.info("Comparing required service configs from stack with mapped service configs from db");
Map<Integer, Multimap<String, String>> dbServiceVersionConfigs = dbClusterServiceVersionConfigs.get(clusterName);
if (dbServiceVersionConfigs != null) {
for (Integer serviceVersion : dbServiceVersionConfigs.keySet()) {
Multimap<String, String> dbServiceConfigs = dbServiceVersionConfigs.get(serviceVersion);
if (dbServiceConfigs != null) {
for (String serviceName : dbServiceConfigs.keySet()) {
ServiceInfo serviceInfo = serviceInfoMap.get(serviceName);
Collection<String> serviceConfigsFromStack = stackServiceConfigs.get(serviceName);
Collection<String> serviceConfigsFromDB = dbServiceConfigs.get(serviceName);
if (serviceConfigsFromDB != null && serviceConfigsFromStack != null) {
serviceConfigsFromStack.removeAll(serviceConfigsFromDB);
if (serviceInfo != null && serviceInfo.getComponents() != null) {
for (ComponentInfo componentInfo : serviceInfo.getComponents()) {
if (componentInfo.getClientConfigFiles() != null) {
for (ClientConfigFileDefinition clientConfigFileDefinition : componentInfo.getClientConfigFiles()) {
if (clientConfigFileDefinition.isOptional()) {
serviceConfigsFromStack.remove(clientConfigFileDefinition.getDictionaryName());
}
}
}
}
}
// skip ranger-{service_name}-* from being checked, unless ranger is installed
if(!dbServiceConfigs.containsKey("RANGER")) {
removeStringsByRegexp(serviceConfigsFromStack, "^ranger-"+ serviceName.toLowerCase() + "-" + "*");
}
if (!serviceConfigsFromStack.isEmpty()) {
warning("Required config(s): {} is(are) not available for service {} with service config version {} in cluster {}",
StringUtils.join(serviceConfigsFromStack, ","), serviceName, Integer.toString(serviceVersion), clusterName);
}
}
}
}
}
}
}
// getting services which has mapped configs which are not selected in clusterconfig
LOG.info("Getting services which has mapped configs which are not selected in clusterconfig");
rs = statement.executeQuery(GET_NOT_SELECTED_SERVICE_CONFIGS_QUERY);
if (rs != null) {
String serviceName = null, configType = null, clusterName = null;
while (rs.next()) {
clusterName = rs.getString("cluster_name");
serviceName = rs.getString("service_name");
configType = rs.getString("type_name");
if (clusterServiceConfigType.get(clusterName) != null) {
Multimap<String, String> serviceConfigs = clusterServiceConfigType.get(clusterName);
serviceConfigs.put(serviceName, configType);
} else {
Multimap<String, String> serviceConfigs = HashMultimap.create();
serviceConfigs.put(serviceName, configType);
clusterServiceConfigType.put(clusterName, serviceConfigs);
}
}
}
for (String clusterName : clusterServiceConfigType.keySet()) {
Multimap<String, String> serviceConfig = clusterServiceConfigType.get(clusterName);
for (String serviceName : serviceConfig.keySet()) {
warning("You have non selected configs: {} for service {} from cluster {}!", StringUtils.join(serviceConfig.get(serviceName), ","), serviceName, clusterName);
}
}
} catch (SQLException | AmbariException e) {
warning("Exception occurred during complex service check procedure: ", e);
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
LOG.error("Exception occurred during result set closing procedure: ", e);
}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
LOG.error("Exception occurred during statement closing procedure: ", e);
}
}
}
} |
223551095_1978 | static void checkForLargeTables() {
LOG.info("Checking for tables with large physical size");
ensureConnection();
DBAccessor.DbType dbType = dbAccessor.getDbType();
String schemaName = dbAccessor.getDbSchema();
String GET_TABLE_SIZE_IN_BYTES_POSTGRESQL = "SELECT pg_total_relation_size('%s') \"Table Size\"";
String GET_TABLE_SIZE_IN_BYTES_MYSQL = "SELECT (data_length + index_length) \"Table Size\" FROM information_schema.TABLES WHERE table_schema = \"" + schemaName + "\" AND table_name =\"%s\"";
String GET_TABLE_SIZE_IN_BYTES_ORACLE = "SELECT bytes \"Table Size\" FROM user_segments WHERE segment_type='TABLE' AND segment_name='%s'";
String GET_ROW_COUNT_QUERY = "SELECT COUNT(*) FROM %s";
Map<DBAccessor.DbType, String> tableSizeQueryMap = new HashMap<>();
tableSizeQueryMap.put(DBAccessor.DbType.POSTGRES, GET_TABLE_SIZE_IN_BYTES_POSTGRESQL);
tableSizeQueryMap.put(DBAccessor.DbType.MYSQL, GET_TABLE_SIZE_IN_BYTES_MYSQL);
tableSizeQueryMap.put(DBAccessor.DbType.ORACLE, GET_TABLE_SIZE_IN_BYTES_ORACLE);
List<String> tablesToCheck = Arrays.asList("host_role_command", "execution_command", "stage", "request", "alert_history");
final double TABLE_SIZE_LIMIT_MB = 3000.0;
final int TABLE_ROW_COUNT_LIMIT = 3000000;
String findTableSizeQuery = tableSizeQueryMap.get(dbType);
if (dbType == DBAccessor.DbType.ORACLE) {
for (int i = 0;i < tablesToCheck.size(); i++) {
tablesToCheck.set(i, tablesToCheck.get(i).toUpperCase());
}
}
for (String tableName : tablesToCheck) {
ResultSet rs = null;
Statement statement = null;
Double tableSizeInMB = null;
Long tableSizeInBytes = null;
int tableRowCount = -1;
try {
statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs = statement.executeQuery(String.format(findTableSizeQuery, tableName));
if (rs != null) {
while (rs.next()) {
tableSizeInBytes = rs.getLong(1);
if (tableSizeInBytes != null) {
tableSizeInMB = tableSizeInBytes / 1024.0 / 1024.0;
}
}
}
if (tableSizeInMB != null && tableSizeInMB > TABLE_SIZE_LIMIT_MB) {
warning("The database table {} is currently {} MB (limit is {}) and may impact performance. It is recommended " +
"that you reduce its size by executing \"ambari-server db-purge-history\".",
tableName, tableSizeInMB, TABLE_SIZE_LIMIT_MB);
} else if (tableSizeInMB != null && tableSizeInMB < TABLE_SIZE_LIMIT_MB) {
LOG.info(String.format("The database table %s is currently %.3f MB and is within normal limits (%.3f)",
tableName, tableSizeInMB, TABLE_SIZE_LIMIT_MB));
} else {
throw new Exception();
}
} catch (Exception e) {
LOG.error(String.format("Failed to get %s table size from database, will check row count: ", tableName), e);
try {
rs = statement.executeQuery(String.format(GET_ROW_COUNT_QUERY, tableName));
if (rs != null) {
while (rs.next()) {
tableRowCount = rs.getInt(1);
}
}
if (tableRowCount > TABLE_ROW_COUNT_LIMIT) {
warning("The database table {} currently has {} rows (limit is {}) and may impact performance. It is " +
"recommended that you reduce its size by executing \"ambari-server db-purge-history\".",
tableName, tableRowCount, TABLE_ROW_COUNT_LIMIT);
} else if (tableRowCount != -1 && tableRowCount < TABLE_ROW_COUNT_LIMIT) {
LOG.info(String.format("The database table %s currently has %d rows and is within normal limits (%d)", tableName, tableRowCount, TABLE_ROW_COUNT_LIMIT));
} else {
warning("Unable to get size for table {}!", tableName);
}
} catch (SQLException ex) {
warning(String.format("Failed to get %s row count: ", tableName), e);
}
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
LOG.error("Exception occurred during result set closing procedure: ", e);
}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
LOG.error("Exception occurred during statement closing procedure: ", e);
}
}
}
}
} |
223551095_1979 | static Map<String, String> checkForStalealertdefs () {
Configuration conf = injector.getInstance(Configuration.class);
Map<String, String> alertInfo = new HashMap<>();
LOG.info("Checking to ensure there is no stale alert definitions");
ensureConnection();
String STALE_ALERT_DEFINITIONS = "select definition_name, service_name from alert_definition where service_name not in " +
"(select service_name from clusterservices) and service_name not in ('AMBARI')";
ResultSet rs = null;
Statement statement;
try {
statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs = statement.executeQuery(STALE_ALERT_DEFINITIONS);
if (rs != null) {
while (rs.next()) {
alertInfo.put(rs.getString("definition_name"),rs.getString("service_name"));
}
if (!alertInfo.isEmpty()){
String alertInfoStr = "";
for (Map.Entry<String, String> entry : alertInfo.entrySet()) {
alertInfoStr = entry.getKey() + "(" + entry.getValue() + ")" ;
}
warning("You have Alerts that are not mapped with any services : {}.Run --auto-fix-database to fix " +
"this automatically. Please backup Ambari Server database before running --auto-fix-database.", alertInfoStr);
}
}
} catch (SQLException e) {
warning("Exception occurred during checking for stale alert definitions: ", e);
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
LOG.error("Exception occurred during checking for stale alert definitions: ", e);
}
}
}
return alertInfo;
} |
223551095_1980 | static Map<Long, ConfigGroup> collectConfigGroupsWithoutServiceName() {
Map<Long, ConfigGroup> configGroupMap = new HashMap<>();
Clusters clusters = injector.getInstance(Clusters.class);
Map<String, Cluster> clusterMap = clusters.getClusters();
if (MapUtils.isEmpty(clusterMap))
return configGroupMap;
for (Cluster cluster : clusterMap.values()) {
Map<Long, ConfigGroup> configGroups = cluster.getConfigGroups();
if (MapUtils.isEmpty(configGroups)) {
continue;
}
for (ConfigGroup configGroup : configGroups.values()) {
if (StringUtils.isEmpty(configGroup.getServiceName())) {
configGroupMap.put(configGroup.getId(), configGroup);
}
}
}
return configGroupMap;
} |
223551095_1981 | @Transactional
static void fixConfigsSelectedMoreThanOnce() {
LOG.info("Fix configs selected more than once");
ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
Clusters clusters = injector.getInstance(Clusters.class);
Map<String, Cluster> clusterMap = clusters.getClusters();
Multimap<String, String> clusterConfigTypeMap = HashMultimap.create();
ResultSet rs = null;
Statement statement = null;
ensureConnection();
try {
statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs = statement.executeQuery(GET_CONFIGS_SELECTED_MORE_THAN_ONCE_QUERY);
if (rs != null) {
while (rs.next()) {
clusterConfigTypeMap.put(rs.getString("cluster_name"), rs.getString("type_name"));
}
}
} catch (SQLException e) {
warning("Exception occurred during check for config selected more than once procedure: ", e);
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
LOG.error("Exception occurred during result set closing procedure: ", e);
}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
LOG.error("Exception occurred during statement closing procedure: ", e);
}
}
}
for (String clusterName : clusterConfigTypeMap.keySet()) {
Cluster cluster = null;
try {
cluster = clusters.getCluster(clusterName);
Collection<String> typesWithMultipleSelectedConfigs = clusterConfigTypeMap.get(clusterName);
for (String type: typesWithMultipleSelectedConfigs) {
List<ClusterConfigEntity> enabledConfigsByType = getEnabledConfigsByType(cluster.getClusterId(), type);
ClusterConfigEntity latestConfig = enabledConfigsByType.get(0);
for (ClusterConfigEntity entity : enabledConfigsByType){
entity.setSelected(false);
if (latestConfig.getSelectedTimestamp() < entity.getSelectedTimestamp()){
latestConfig = entity;
}
clusterDAO.merge(entity, true);
}
latestConfig.setSelected(true);
clusterDAO.merge(latestConfig, true);
}
} catch (AmbariException e) {
warning("Exception occurred during fix for config selected more than once procedure: ", e);
}
}
} |
223551095_1982 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
final String configType = "hdfs-site";
final Map<String, DesiredConfig> desiredConfigs = cluster.getDesiredConfigs();
final DesiredConfig desiredConfig = desiredConfigs.get(configType);
final Config config = cluster.getConfig(configType, desiredConfig.getTag());
if (!config.getProperties().containsKey("dfs.internal.nameservices")) {
prerequisiteCheck.getFailedOn().add("HDFS");
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
}
} |
223551095_1983 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request)
throws AmbariException {
ServiceConfigDAO serviceConfigDAO = serviceConfigDAOProvider.get();
HostRoleCommandDAO hostRoleCommandDAO = hostRoleCommandDAOProvider.get();
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
long clusterId = cluster.getClusterId();
// build a mapping of the last config changes by service
Map<String, Long> lastServiceConfigUpdates = new HashMap<>();
for (Service service : cluster.getServices().values()) {
if (service.getMaintenanceState() != MaintenanceState.OFF || !hasAtLeastOneComponentVersionAdvertised(service)) {
continue;
}
StackId stackId = service.getDesiredStackId();
boolean isServiceWitNoConfigs = ambariMetaInfo.get().isServiceWithNoConfigs(stackId.getStackName(), stackId.getStackVersion(), service.getName());
if (isServiceWitNoConfigs){
LOG.info(String.format("%s in %s version %s does not have customizable configurations. Skip checking service configuration history.", service.getName(), stackId.getStackName(), stackId.getStackVersion()));
} else {
LOG.info(String.format("%s in %s version %s has customizable configurations. Check service configuration history.", service.getName(), stackId.getStackName(), stackId.getStackVersion()));
ServiceConfigEntity lastServiceConfig = serviceConfigDAO.getLastServiceConfig(clusterId, service.getName());
lastServiceConfigUpdates.put(service.getName(), lastServiceConfig.getCreateTimestamp());
}
}
// get the latest service checks, grouped by role
List<LastServiceCheckDTO> lastServiceChecks = hostRoleCommandDAO.getLatestServiceChecksByRole(clusterId);
Map<String, Long> lastServiceChecksByRole = new HashMap<>();
for( LastServiceCheckDTO lastServiceCheck : lastServiceChecks ) {
lastServiceChecksByRole.put(lastServiceCheck.role, lastServiceCheck.endTime);
}
LinkedHashSet<ServiceCheckConfigDetail> failures = new LinkedHashSet<>();
// for every service, see if there was a service check executed and then
for( Entry<String, Long> entry : lastServiceConfigUpdates.entrySet() ) {
String serviceName = entry.getKey();
long configCreationTime = entry.getValue();
String role = actionMetadataProvider.get().getServiceCheckAction(serviceName);
if(!lastServiceChecksByRole.containsKey(role) ) {
LOG.info("There was no service check found for service {} matching role {}", serviceName, role);
failures.add(new ServiceCheckConfigDetail(serviceName, null, null));
continue;
}
long lastServiceCheckTime = lastServiceChecksByRole.get(role);
if (lastServiceCheckTime < configCreationTime) {
failures.add(
new ServiceCheckConfigDetail(serviceName, lastServiceCheckTime, configCreationTime));
LOG.info(
"The {} service (role {}) had its configurations updated on {}, but the last service check was {}",
serviceName, role, DATE_FORMAT.format(new Date(configCreationTime)),
DATE_FORMAT.format(new Date(lastServiceCheckTime)));
}
}
if (!failures.isEmpty()) {
prerequisiteCheck.getFailedDetail().addAll(failures);
LinkedHashSet<String> failedServiceNames = failures.stream().map(
failure -> failure.serviceName).collect(Collectors.toCollection(LinkedHashSet::new));
prerequisiteCheck.setFailedOn(failedServiceNames);
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
String failReason = getFailReason(prerequisiteCheck, request);
prerequisiteCheck.setFailReason(String.format(failReason, StringUtils.join(failedServiceNames, ", ")));
}
} |
223551095_1984 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request)
throws AmbariException {
ServiceConfigDAO serviceConfigDAO = serviceConfigDAOProvider.get();
HostRoleCommandDAO hostRoleCommandDAO = hostRoleCommandDAOProvider.get();
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
long clusterId = cluster.getClusterId();
// build a mapping of the last config changes by service
Map<String, Long> lastServiceConfigUpdates = new HashMap<>();
for (Service service : cluster.getServices().values()) {
if (service.getMaintenanceState() != MaintenanceState.OFF || !hasAtLeastOneComponentVersionAdvertised(service)) {
continue;
}
StackId stackId = service.getDesiredStackId();
boolean isServiceWitNoConfigs = ambariMetaInfo.get().isServiceWithNoConfigs(stackId.getStackName(), stackId.getStackVersion(), service.getName());
if (isServiceWitNoConfigs){
LOG.info(String.format("%s in %s version %s does not have customizable configurations. Skip checking service configuration history.", service.getName(), stackId.getStackName(), stackId.getStackVersion()));
} else {
LOG.info(String.format("%s in %s version %s has customizable configurations. Check service configuration history.", service.getName(), stackId.getStackName(), stackId.getStackVersion()));
ServiceConfigEntity lastServiceConfig = serviceConfigDAO.getLastServiceConfig(clusterId, service.getName());
lastServiceConfigUpdates.put(service.getName(), lastServiceConfig.getCreateTimestamp());
}
}
// get the latest service checks, grouped by role
List<LastServiceCheckDTO> lastServiceChecks = hostRoleCommandDAO.getLatestServiceChecksByRole(clusterId);
Map<String, Long> lastServiceChecksByRole = new HashMap<>();
for( LastServiceCheckDTO lastServiceCheck : lastServiceChecks ) {
lastServiceChecksByRole.put(lastServiceCheck.role, lastServiceCheck.endTime);
}
LinkedHashSet<ServiceCheckConfigDetail> failures = new LinkedHashSet<>();
// for every service, see if there was a service check executed and then
for( Entry<String, Long> entry : lastServiceConfigUpdates.entrySet() ) {
String serviceName = entry.getKey();
long configCreationTime = entry.getValue();
String role = actionMetadataProvider.get().getServiceCheckAction(serviceName);
if(!lastServiceChecksByRole.containsKey(role) ) {
LOG.info("There was no service check found for service {} matching role {}", serviceName, role);
failures.add(new ServiceCheckConfigDetail(serviceName, null, null));
continue;
}
long lastServiceCheckTime = lastServiceChecksByRole.get(role);
if (lastServiceCheckTime < configCreationTime) {
failures.add(
new ServiceCheckConfigDetail(serviceName, lastServiceCheckTime, configCreationTime));
LOG.info(
"The {} service (role {}) had its configurations updated on {}, but the last service check was {}",
serviceName, role, DATE_FORMAT.format(new Date(configCreationTime)),
DATE_FORMAT.format(new Date(lastServiceCheckTime)));
}
}
if (!failures.isEmpty()) {
prerequisiteCheck.getFailedDetail().addAll(failures);
LinkedHashSet<String> failedServiceNames = failures.stream().map(
failure -> failure.serviceName).collect(Collectors.toCollection(LinkedHashSet::new));
prerequisiteCheck.setFailedOn(failedServiceNames);
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
String failReason = getFailReason(prerequisiteCheck, request);
prerequisiteCheck.setFailReason(String.format(failReason, StringUtils.join(failedServiceNames, ", ")));
}
} |
223551095_1985 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request)
throws AmbariException {
ServiceConfigDAO serviceConfigDAO = serviceConfigDAOProvider.get();
HostRoleCommandDAO hostRoleCommandDAO = hostRoleCommandDAOProvider.get();
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
long clusterId = cluster.getClusterId();
// build a mapping of the last config changes by service
Map<String, Long> lastServiceConfigUpdates = new HashMap<>();
for (Service service : cluster.getServices().values()) {
if (service.getMaintenanceState() != MaintenanceState.OFF || !hasAtLeastOneComponentVersionAdvertised(service)) {
continue;
}
StackId stackId = service.getDesiredStackId();
boolean isServiceWitNoConfigs = ambariMetaInfo.get().isServiceWithNoConfigs(stackId.getStackName(), stackId.getStackVersion(), service.getName());
if (isServiceWitNoConfigs){
LOG.info(String.format("%s in %s version %s does not have customizable configurations. Skip checking service configuration history.", service.getName(), stackId.getStackName(), stackId.getStackVersion()));
} else {
LOG.info(String.format("%s in %s version %s has customizable configurations. Check service configuration history.", service.getName(), stackId.getStackName(), stackId.getStackVersion()));
ServiceConfigEntity lastServiceConfig = serviceConfigDAO.getLastServiceConfig(clusterId, service.getName());
lastServiceConfigUpdates.put(service.getName(), lastServiceConfig.getCreateTimestamp());
}
}
// get the latest service checks, grouped by role
List<LastServiceCheckDTO> lastServiceChecks = hostRoleCommandDAO.getLatestServiceChecksByRole(clusterId);
Map<String, Long> lastServiceChecksByRole = new HashMap<>();
for( LastServiceCheckDTO lastServiceCheck : lastServiceChecks ) {
lastServiceChecksByRole.put(lastServiceCheck.role, lastServiceCheck.endTime);
}
LinkedHashSet<ServiceCheckConfigDetail> failures = new LinkedHashSet<>();
// for every service, see if there was a service check executed and then
for( Entry<String, Long> entry : lastServiceConfigUpdates.entrySet() ) {
String serviceName = entry.getKey();
long configCreationTime = entry.getValue();
String role = actionMetadataProvider.get().getServiceCheckAction(serviceName);
if(!lastServiceChecksByRole.containsKey(role) ) {
LOG.info("There was no service check found for service {} matching role {}", serviceName, role);
failures.add(new ServiceCheckConfigDetail(serviceName, null, null));
continue;
}
long lastServiceCheckTime = lastServiceChecksByRole.get(role);
if (lastServiceCheckTime < configCreationTime) {
failures.add(
new ServiceCheckConfigDetail(serviceName, lastServiceCheckTime, configCreationTime));
LOG.info(
"The {} service (role {}) had its configurations updated on {}, but the last service check was {}",
serviceName, role, DATE_FORMAT.format(new Date(configCreationTime)),
DATE_FORMAT.format(new Date(lastServiceCheckTime)));
}
}
if (!failures.isEmpty()) {
prerequisiteCheck.getFailedDetail().addAll(failures);
LinkedHashSet<String> failedServiceNames = failures.stream().map(
failure -> failure.serviceName).collect(Collectors.toCollection(LinkedHashSet::new));
prerequisiteCheck.setFailedOn(failedServiceNames);
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
String failReason = getFailReason(prerequisiteCheck, request);
prerequisiteCheck.setFailReason(String.format(failReason, StringUtils.join(failedServiceNames, ", ")));
}
} |
223551095_1986 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request)
throws AmbariException {
ServiceConfigDAO serviceConfigDAO = serviceConfigDAOProvider.get();
HostRoleCommandDAO hostRoleCommandDAO = hostRoleCommandDAOProvider.get();
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
long clusterId = cluster.getClusterId();
// build a mapping of the last config changes by service
Map<String, Long> lastServiceConfigUpdates = new HashMap<>();
for (Service service : cluster.getServices().values()) {
if (service.getMaintenanceState() != MaintenanceState.OFF || !hasAtLeastOneComponentVersionAdvertised(service)) {
continue;
}
StackId stackId = service.getDesiredStackId();
boolean isServiceWitNoConfigs = ambariMetaInfo.get().isServiceWithNoConfigs(stackId.getStackName(), stackId.getStackVersion(), service.getName());
if (isServiceWitNoConfigs){
LOG.info(String.format("%s in %s version %s does not have customizable configurations. Skip checking service configuration history.", service.getName(), stackId.getStackName(), stackId.getStackVersion()));
} else {
LOG.info(String.format("%s in %s version %s has customizable configurations. Check service configuration history.", service.getName(), stackId.getStackName(), stackId.getStackVersion()));
ServiceConfigEntity lastServiceConfig = serviceConfigDAO.getLastServiceConfig(clusterId, service.getName());
lastServiceConfigUpdates.put(service.getName(), lastServiceConfig.getCreateTimestamp());
}
}
// get the latest service checks, grouped by role
List<LastServiceCheckDTO> lastServiceChecks = hostRoleCommandDAO.getLatestServiceChecksByRole(clusterId);
Map<String, Long> lastServiceChecksByRole = new HashMap<>();
for( LastServiceCheckDTO lastServiceCheck : lastServiceChecks ) {
lastServiceChecksByRole.put(lastServiceCheck.role, lastServiceCheck.endTime);
}
LinkedHashSet<ServiceCheckConfigDetail> failures = new LinkedHashSet<>();
// for every service, see if there was a service check executed and then
for( Entry<String, Long> entry : lastServiceConfigUpdates.entrySet() ) {
String serviceName = entry.getKey();
long configCreationTime = entry.getValue();
String role = actionMetadataProvider.get().getServiceCheckAction(serviceName);
if(!lastServiceChecksByRole.containsKey(role) ) {
LOG.info("There was no service check found for service {} matching role {}", serviceName, role);
failures.add(new ServiceCheckConfigDetail(serviceName, null, null));
continue;
}
long lastServiceCheckTime = lastServiceChecksByRole.get(role);
if (lastServiceCheckTime < configCreationTime) {
failures.add(
new ServiceCheckConfigDetail(serviceName, lastServiceCheckTime, configCreationTime));
LOG.info(
"The {} service (role {}) had its configurations updated on {}, but the last service check was {}",
serviceName, role, DATE_FORMAT.format(new Date(configCreationTime)),
DATE_FORMAT.format(new Date(lastServiceCheckTime)));
}
}
if (!failures.isEmpty()) {
prerequisiteCheck.getFailedDetail().addAll(failures);
LinkedHashSet<String> failedServiceNames = failures.stream().map(
failure -> failure.serviceName).collect(Collectors.toCollection(LinkedHashSet::new));
prerequisiteCheck.setFailedOn(failedServiceNames);
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
String failReason = getFailReason(prerequisiteCheck, request);
prerequisiteCheck.setFailReason(String.format(failReason, StringUtils.join(failedServiceNames, ", ")));
}
} |
223551095_1987 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request)
throws AmbariException {
ServiceConfigDAO serviceConfigDAO = serviceConfigDAOProvider.get();
HostRoleCommandDAO hostRoleCommandDAO = hostRoleCommandDAOProvider.get();
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
long clusterId = cluster.getClusterId();
// build a mapping of the last config changes by service
Map<String, Long> lastServiceConfigUpdates = new HashMap<>();
for (Service service : cluster.getServices().values()) {
if (service.getMaintenanceState() != MaintenanceState.OFF || !hasAtLeastOneComponentVersionAdvertised(service)) {
continue;
}
StackId stackId = service.getDesiredStackId();
boolean isServiceWitNoConfigs = ambariMetaInfo.get().isServiceWithNoConfigs(stackId.getStackName(), stackId.getStackVersion(), service.getName());
if (isServiceWitNoConfigs){
LOG.info(String.format("%s in %s version %s does not have customizable configurations. Skip checking service configuration history.", service.getName(), stackId.getStackName(), stackId.getStackVersion()));
} else {
LOG.info(String.format("%s in %s version %s has customizable configurations. Check service configuration history.", service.getName(), stackId.getStackName(), stackId.getStackVersion()));
ServiceConfigEntity lastServiceConfig = serviceConfigDAO.getLastServiceConfig(clusterId, service.getName());
lastServiceConfigUpdates.put(service.getName(), lastServiceConfig.getCreateTimestamp());
}
}
// get the latest service checks, grouped by role
List<LastServiceCheckDTO> lastServiceChecks = hostRoleCommandDAO.getLatestServiceChecksByRole(clusterId);
Map<String, Long> lastServiceChecksByRole = new HashMap<>();
for( LastServiceCheckDTO lastServiceCheck : lastServiceChecks ) {
lastServiceChecksByRole.put(lastServiceCheck.role, lastServiceCheck.endTime);
}
LinkedHashSet<ServiceCheckConfigDetail> failures = new LinkedHashSet<>();
// for every service, see if there was a service check executed and then
for( Entry<String, Long> entry : lastServiceConfigUpdates.entrySet() ) {
String serviceName = entry.getKey();
long configCreationTime = entry.getValue();
String role = actionMetadataProvider.get().getServiceCheckAction(serviceName);
if(!lastServiceChecksByRole.containsKey(role) ) {
LOG.info("There was no service check found for service {} matching role {}", serviceName, role);
failures.add(new ServiceCheckConfigDetail(serviceName, null, null));
continue;
}
long lastServiceCheckTime = lastServiceChecksByRole.get(role);
if (lastServiceCheckTime < configCreationTime) {
failures.add(
new ServiceCheckConfigDetail(serviceName, lastServiceCheckTime, configCreationTime));
LOG.info(
"The {} service (role {}) had its configurations updated on {}, but the last service check was {}",
serviceName, role, DATE_FORMAT.format(new Date(configCreationTime)),
DATE_FORMAT.format(new Date(lastServiceCheckTime)));
}
}
if (!failures.isEmpty()) {
prerequisiteCheck.getFailedDetail().addAll(failures);
LinkedHashSet<String> failedServiceNames = failures.stream().map(
failure -> failure.serviceName).collect(Collectors.toCollection(LinkedHashSet::new));
prerequisiteCheck.setFailedOn(failedServiceNames);
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
String failReason = getFailReason(prerequisiteCheck, request);
prerequisiteCheck.setFailReason(String.format(failReason, StringUtils.join(failedServiceNames, ", ")));
}
} |
223551095_1988 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
String dfsProtocolsRegex = DFS_PROTOCOLS_REGEX_DEFAULT;
PrerequisiteCheckConfig prerequisiteCheckConfig = request.getPrerequisiteCheckConfig();
Map<String, String> checkProperties = null;
if(prerequisiteCheckConfig != null) {
checkProperties = prerequisiteCheckConfig.getCheckProperties(this.getClass().getName());
}
if(checkProperties != null && checkProperties.containsKey(DFS_PROTOCOLS_REGEX_PROPERTY_NAME)) {
dfsProtocolsRegex = checkProperties.get(DFS_PROTOCOLS_REGEX_PROPERTY_NAME);
}
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
final String tezConfigType = "tez-site";
final String coreSiteConfigType = "core-site";
final Map<String, DesiredConfig> desiredConfigs = cluster.getDesiredConfigs();
final DesiredConfig tezDesiredConfig = desiredConfigs.get(tezConfigType);
final Config tezConfig = cluster.getConfig(tezConfigType, tezDesiredConfig.getTag());
final DesiredConfig coreSiteDesiredConfig = desiredConfigs.get(coreSiteConfigType);
final Config coreSiteConfig = cluster.getConfig(coreSiteConfigType, coreSiteDesiredConfig.getTag());
final String libUris = tezConfig.getProperties().get("tez.lib.uris");
final String useHadoopLibs = tezConfig.getProperties().get("tez.use.cluster.hadoop-libs");
final String defaultFS = coreSiteConfig.getProperties().get("fs.defaultFS");
List<String> errorMessages = new ArrayList<>();
if (libUris == null || libUris.isEmpty()) {
errorMessages.add(getFailReason(KEY_LIB_URI_MISSING, prerequisiteCheck, request));
}
if (useHadoopLibs == null || useHadoopLibs.isEmpty()) {
errorMessages.add(getFailReason(KEY_USE_HADOOP_LIBS, prerequisiteCheck, request));
}
if (!errorMessages.isEmpty()) {
prerequisiteCheck.getFailedOn().add("TEZ");
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, " "));
return;
}
if (!libUris.matches(dfsProtocolsRegex) && (defaultFS == null || !defaultFS.matches(dfsProtocolsRegex))) {
errorMessages.add(getFailReason(KEY_LIB_NOT_DFS, prerequisiteCheck, request));
}
if (!libUris.contains("tar.gz")) {
errorMessages.add(getFailReason(KEY_LIB_NOT_TARGZ, prerequisiteCheck, request));
}
if (Boolean.parseBoolean(useHadoopLibs)) {
errorMessages.add(getFailReason(KEY_USE_HADOOP_LIBS_FALSE, prerequisiteCheck, request));
}
if (!errorMessages.isEmpty()) {
prerequisiteCheck.getFailedOn().add("TEZ");
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, " "));
}
} |
223551095_1989 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
String dfsProtocolsRegex = DFS_PROTOCOLS_REGEX_DEFAULT;
PrerequisiteCheckConfig prerequisiteCheckConfig = request.getPrerequisiteCheckConfig();
Map<String, String> checkProperties = null;
if(prerequisiteCheckConfig != null) {
checkProperties = prerequisiteCheckConfig.getCheckProperties(this.getClass().getName());
}
if(checkProperties != null && checkProperties.containsKey(DFS_PROTOCOLS_REGEX_PROPERTY_NAME)) {
dfsProtocolsRegex = checkProperties.get(DFS_PROTOCOLS_REGEX_PROPERTY_NAME);
}
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
final String tezConfigType = "tez-site";
final String coreSiteConfigType = "core-site";
final Map<String, DesiredConfig> desiredConfigs = cluster.getDesiredConfigs();
final DesiredConfig tezDesiredConfig = desiredConfigs.get(tezConfigType);
final Config tezConfig = cluster.getConfig(tezConfigType, tezDesiredConfig.getTag());
final DesiredConfig coreSiteDesiredConfig = desiredConfigs.get(coreSiteConfigType);
final Config coreSiteConfig = cluster.getConfig(coreSiteConfigType, coreSiteDesiredConfig.getTag());
final String libUris = tezConfig.getProperties().get("tez.lib.uris");
final String useHadoopLibs = tezConfig.getProperties().get("tez.use.cluster.hadoop-libs");
final String defaultFS = coreSiteConfig.getProperties().get("fs.defaultFS");
List<String> errorMessages = new ArrayList<>();
if (libUris == null || libUris.isEmpty()) {
errorMessages.add(getFailReason(KEY_LIB_URI_MISSING, prerequisiteCheck, request));
}
if (useHadoopLibs == null || useHadoopLibs.isEmpty()) {
errorMessages.add(getFailReason(KEY_USE_HADOOP_LIBS, prerequisiteCheck, request));
}
if (!errorMessages.isEmpty()) {
prerequisiteCheck.getFailedOn().add("TEZ");
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, " "));
return;
}
if (!libUris.matches(dfsProtocolsRegex) && (defaultFS == null || !defaultFS.matches(dfsProtocolsRegex))) {
errorMessages.add(getFailReason(KEY_LIB_NOT_DFS, prerequisiteCheck, request));
}
if (!libUris.contains("tar.gz")) {
errorMessages.add(getFailReason(KEY_LIB_NOT_TARGZ, prerequisiteCheck, request));
}
if (Boolean.parseBoolean(useHadoopLibs)) {
errorMessages.add(getFailReason(KEY_USE_HADOOP_LIBS_FALSE, prerequisiteCheck, request));
}
if (!errorMessages.isEmpty()) {
prerequisiteCheck.getFailedOn().add("TEZ");
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, " "));
}
} |
223551095_1990 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
List<String> errorMessages = new ArrayList<>();
String dynamicServiceDiscoveryEnabled = getProperty(request, "hive-site", "hive.server2.support.dynamic.service.discovery");
String zookeeperQuorum = getProperty(request, "hive-site", "hive.zookeeper.quorum");
String zookeeperNamespace = getProperty(request, "hive-site", "hive.server2.zookeeper.namespace");
if (null == dynamicServiceDiscoveryEnabled || !Boolean.parseBoolean(dynamicServiceDiscoveryEnabled)) {
errorMessages.add(getFailReason(HIVE_DYNAMIC_SERVICE_DISCOVERY_ENABLED_KEY, prerequisiteCheck, request));
}
if (StringUtils.isBlank(zookeeperQuorum)) {
errorMessages.add(getFailReason(HIVE_DYNAMIC_SERVICE_ZK_QUORUM_KEY, prerequisiteCheck,
request));
}
if (StringUtils.isBlank(zookeeperNamespace)) {
errorMessages.add(getFailReason(HIVE_DYNAMIC_SERVICE_ZK_NAMESPACE_KEY, prerequisiteCheck,
request));
}
String minFailureStackVersion = null;
PrerequisiteCheckConfig prerequisiteCheckConfig = request.getPrerequisiteCheckConfig();
Map<String, String> checkProperties = null;
if(prerequisiteCheckConfig != null) {
checkProperties = prerequisiteCheckConfig.getCheckProperties(this.getClass().getName());
}
if(checkProperties != null && checkProperties.containsKey(MIN_FAILURE_STACK_VERSION_PROPERTY_NAME)) {
minFailureStackVersion = checkProperties.get(MIN_FAILURE_STACK_VERSION_PROPERTY_NAME);
}
if (!errorMessages.isEmpty()) {
prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, " "));
prerequisiteCheck.getFailedOn().add("HIVE");
PrereqCheckStatus checkStatus = PrereqCheckStatus.FAIL;
if(minFailureStackVersion != null && !minFailureStackVersion.isEmpty()) {
String[] minStack = minFailureStackVersion.split("-");
if (minStack.length == 2) {
String minStackName = minStack[0];
String minStackVersion = minStack[1];
if (minStackName.equals(request.getSourceStackId().getStackName())) {
RepositoryVersionEntity repositoryVersion = request.getTargetRepositoryVersion();
StackId targetStackId = repositoryVersion.getStackId();
if (VersionUtils.compareVersions(request.getSourceStackId().getStackVersion(), minStackVersion) < 0
&& VersionUtils.compareVersions(targetStackId.getStackVersion(), minStackVersion) < 0
&& VersionUtils.compareVersions(request.getSourceStackId().getStackVersion(), targetStackId.getStackVersion()) < 0) {
checkStatus = PrereqCheckStatus.WARNING;
}
}
}
}
prerequisiteCheck.setStatus(checkStatus);
}
} |
223551095_1991 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
prerequisiteCheck.getFailedOn().add("STORM");
prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING);
prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
} |
223551095_1992 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
RepositoryVersionEntity repositoryVersion = request.getTargetRepositoryVersion();
final StackId targetStackId = repositoryVersion.getStackId();
if (!repositoryVersion.getVersion().matches("^\\d+(\\.\\d+)*\\-\\d+$")) {
String message = MessageFormat.format("The Repository Version {0} for Stack {1} must contain a \"-\" followed by a build number. " +
"Make sure that another registered repository does not have the same repo URL or " +
"shares the same build number. Next, try reinstalling the Repository Version.", repositoryVersion.getVersion(), repositoryVersion.getStackVersion());
prerequisiteCheck.getFailedOn().add("Repository Version " + repositoryVersion.getVersion());
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(message);
return;
}
final Set<HostDetail> failedHosts = new TreeSet<>();
for (Host host : cluster.getHosts()) {
if (host.getMaintenanceState(cluster.getClusterId()) != MaintenanceState.ON) {
for (HostVersionEntity hve : hostVersionDaoProvider.get().findByHost(host.getHostName())) {
if (StringUtils.equals(hve.getRepositoryVersion().getVersion(), repositoryVersion.getVersion())
&& hve.getState() == RepositoryVersionState.INSTALL_FAILED) {
failedHosts.add(new HostDetail(host.getHostId(), host.getHostName()));
}
}
}
}
if (!failedHosts.isEmpty()) {
String message = MessageFormat.format("Hosts in cluster [{0},{1},{2},{3}] are in INSTALL_FAILED state because " +
"Install Packages had failed. Please re-run Install Packages, if necessary place following hosts " +
"in Maintenance mode: {4}", cluster.getClusterName(), targetStackId.getStackName(),
targetStackId.getStackVersion(), repositoryVersion.getVersion(),
StringUtils.join(failedHosts, ", "));
LinkedHashSet<String> failedHostNames = failedHosts.stream().map(
failedHost -> failedHost.hostName).collect(
Collectors.toCollection(LinkedHashSet::new));
prerequisiteCheck.setFailedOn(failedHostNames);
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(message);
prerequisiteCheck.getFailedDetail().addAll(failedHosts);
return;
}
prerequisiteCheck.setStatus(PrereqCheckStatus.PASS);
} |
223551095_1993 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request)
throws AmbariException {
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
final Map<String, Host> clusterHosts = clustersProvider.get().getHostsForCluster(clusterName);
for (Host host : clusterHosts.values()) {
// hosts in MM will produce a warning if they do not have the repo version
MaintenanceState maintenanceState = host.getMaintenanceState(cluster.getClusterId());
if (maintenanceState != MaintenanceState.OFF) {
continue;
}
RepositoryVersionEntity repositoryVersion = request.getTargetRepositoryVersion();
StackId repositoryStackId = repositoryVersion.getStackId();
// get the host version entity for this host and repository
final HostVersionEntity hostVersion = hostVersionDaoProvider.get().findByClusterStackVersionAndHost(
clusterName, repositoryStackId, repositoryVersion.getVersion(), host.getHostName());
// the repo needs to either be installed or not required
Set<RepositoryVersionState> okStates = EnumSet.of(RepositoryVersionState.INSTALLED,
RepositoryVersionState.NOT_REQUIRED);
if (hostVersion == null || !okStates.contains(hostVersion.getState())) {
prerequisiteCheck.getFailedOn().add(host.getHostName());
prerequisiteCheck.getFailedDetail().add(
new HostDetail(host.getHostId(), host.getHostName()));
}
}
if (!prerequisiteCheck.getFailedOn().isEmpty()) {
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
}
} |
223551095_1994 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request)
throws AmbariException {
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
final Map<String, Host> clusterHosts = clustersProvider.get().getHostsForCluster(clusterName);
for (Host host : clusterHosts.values()) {
// hosts in MM will produce a warning if they do not have the repo version
MaintenanceState maintenanceState = host.getMaintenanceState(cluster.getClusterId());
if (maintenanceState != MaintenanceState.OFF) {
continue;
}
RepositoryVersionEntity repositoryVersion = request.getTargetRepositoryVersion();
StackId repositoryStackId = repositoryVersion.getStackId();
// get the host version entity for this host and repository
final HostVersionEntity hostVersion = hostVersionDaoProvider.get().findByClusterStackVersionAndHost(
clusterName, repositoryStackId, repositoryVersion.getVersion(), host.getHostName());
// the repo needs to either be installed or not required
Set<RepositoryVersionState> okStates = EnumSet.of(RepositoryVersionState.INSTALLED,
RepositoryVersionState.NOT_REQUIRED);
if (hostVersion == null || !okStates.contains(hostVersion.getState())) {
prerequisiteCheck.getFailedOn().add(host.getHostName());
prerequisiteCheck.getFailedDetail().add(
new HostDetail(host.getHostId(), host.getHostName()));
}
}
if (!prerequisiteCheck.getFailedOn().isEmpty()) {
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
}
} |
223551095_1995 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request)
throws AmbariException {
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
final Map<String, Host> clusterHosts = clustersProvider.get().getHostsForCluster(clusterName);
for (Host host : clusterHosts.values()) {
// hosts in MM will produce a warning if they do not have the repo version
MaintenanceState maintenanceState = host.getMaintenanceState(cluster.getClusterId());
if (maintenanceState != MaintenanceState.OFF) {
continue;
}
RepositoryVersionEntity repositoryVersion = request.getTargetRepositoryVersion();
StackId repositoryStackId = repositoryVersion.getStackId();
// get the host version entity for this host and repository
final HostVersionEntity hostVersion = hostVersionDaoProvider.get().findByClusterStackVersionAndHost(
clusterName, repositoryStackId, repositoryVersion.getVersion(), host.getHostName());
// the repo needs to either be installed or not required
Set<RepositoryVersionState> okStates = EnumSet.of(RepositoryVersionState.INSTALLED,
RepositoryVersionState.NOT_REQUIRED);
if (hostVersion == null || !okStates.contains(hostVersion.getState())) {
prerequisiteCheck.getFailedOn().add(host.getHostName());
prerequisiteCheck.getFailedDetail().add(
new HostDetail(host.getHostId(), host.getHostName()));
}
}
if (!prerequisiteCheck.getFailedOn().isEmpty()) {
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
}
} |
223551095_1996 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
String autoStartEnabled = getProperty(request, CLUSTER_ENV_TYPE, RECOVERY_ENABLED_KEY);
// !!! auto-start is already disabled
if (!Boolean.valueOf(autoStartEnabled)) {
return;
}
// !!! double check the value is AUTO_START. it's the only supported value (and there's no enum for it)
String recoveryType = getProperty(request, CLUSTER_ENV_TYPE, RECOVERY_TYPE_KEY);
if (StringUtils.equals(recoveryType, RECOVERY_AUTO_START)) {
prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.getFailedOn().add(request.getClusterName());
}
} |
223551095_1997 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
String autoStartEnabled = getProperty(request, CLUSTER_ENV_TYPE, RECOVERY_ENABLED_KEY);
// !!! auto-start is already disabled
if (!Boolean.valueOf(autoStartEnabled)) {
return;
}
// !!! double check the value is AUTO_START. it's the only supported value (and there's no enum for it)
String recoveryType = getProperty(request, CLUSTER_ENV_TYPE, RECOVERY_TYPE_KEY);
if (StringUtils.equals(recoveryType, RECOVERY_AUTO_START)) {
prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.getFailedOn().add(request.getClusterName());
}
} |
223551095_1998 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
String autoStartEnabled = getProperty(request, CLUSTER_ENV_TYPE, RECOVERY_ENABLED_KEY);
// !!! auto-start is already disabled
if (!Boolean.valueOf(autoStartEnabled)) {
return;
}
// !!! double check the value is AUTO_START. it's the only supported value (and there's no enum for it)
String recoveryType = getProperty(request, CLUSTER_ENV_TYPE, RECOVERY_TYPE_KEY);
if (StringUtils.equals(recoveryType, RECOVERY_AUTO_START)) {
prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.getFailedOn().add(request.getClusterName());
}
} |
223551095_1999 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
List<String> errorMessages = new ArrayList<>();
PrereqCheckStatus checkStatus = PrereqCheckStatus.FAIL;
String enabled =
getProperty(request, "mapred-site", MAPREDUCE2_JOBHISTORY_RECOVERY_ENABLE_KEY);
String storeClass =
getProperty(request, "mapred-site", MAPREDUCE2_JOBHISTORY_RECOVERY_STORE_KEY);
String storeLevelDbPath =
getProperty(request, "mapred-site", MAPREDUCE2_JOBHISTORY_RECOVERY_STORE_LEVELDB_PATH_KEY);
if (null == enabled || !Boolean.parseBoolean(enabled)) {
errorMessages.add(getFailReason(MAPREDUCE2_JOBHISTORY_RECOVERY_ENABLE_KEY, prerequisiteCheck, request));
}
if (StringUtils.isBlank(storeClass)) {
errorMessages.add(getFailReason(MAPREDUCE2_JOBHISTORY_RECOVERY_STORE_KEY, prerequisiteCheck,
request));
}
if (StringUtils.isBlank(storeLevelDbPath)) {
errorMessages.add(getFailReason(MAPREDUCE2_JOBHISTORY_RECOVERY_STORE_LEVELDB_PATH_KEY, prerequisiteCheck,
request));
}
if (!errorMessages.isEmpty()) {
prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, "\n"));
prerequisiteCheck.getFailedOn().add("MAPREDUCE2");
prerequisiteCheck.setStatus(checkStatus);
}
} |
223551095_2000 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request)
throws AmbariException {
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
Collection<Host> hosts = cluster.getHosts();
for (Host host : hosts) {
HealthStatus hostHealth = host.getHealthStatus().getHealthStatus();
MaintenanceState maintenanceState = host.getMaintenanceState(cluster.getClusterId());
switch (hostHealth) {
case UNHEALTHY:
case UNKNOWN:
if (maintenanceState == MaintenanceState.OFF) {
prerequisiteCheck.getFailedOn().add(host.getHostName());
prerequisiteCheck.getFailedDetail().add(
new HostDetail(host.getHostId(), host.getHostName()));
}
break;
default:
break;
}
}
// for any hosts unhealthy and NOT in MM mode, fail this check
if (!prerequisiteCheck.getFailedOn().isEmpty()) {
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
return;
}
} |
223551095_2001 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
final StackId stackId = request.getSourceStackId();
final Set<String> hostsWithMasterComponent = new HashSet<>();
// TODO AMBARI-12698, need to pass the upgrade pack to use in the request, or at least the type.
RepositoryVersionEntity repositoryVersion = request.getTargetRepositoryVersion();
final String upgradePackName = repositoryVersionHelper.get().getUpgradePackageName(
stackId.getStackName(), stackId.getStackVersion(), repositoryVersion.getVersion(), null);
if (upgradePackName == null) {
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
String fail = getFailReason(KEY_NO_UPGRADE_NAME, prerequisiteCheck, request);
prerequisiteCheck.setFailReason(String.format(fail, stackId.getStackName(), stackId.getStackVersion()));
return;
}
final UpgradePack upgradePack = ambariMetaInfo.get().getUpgradePacks(stackId.getStackName(), stackId.getStackVersion()).get(upgradePackName);
if (upgradePack == null) {
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
String fail = getFailReason(KEY_NO_UPGRADE_PACK, prerequisiteCheck, request);
prerequisiteCheck.setFailReason(String.format(fail, upgradePackName));
return;
}
final Set<String> componentsFromUpgradePack = new HashSet<>();
for (Map<String, ProcessingComponent> task: upgradePack.getTasks().values()) {
componentsFromUpgradePack.addAll(task.keySet());
}
for (Service service: cluster.getServices().values()) {
for (ServiceComponent serviceComponent: service.getServiceComponents().values()) {
if (serviceComponent.isMasterComponent() && componentsFromUpgradePack.contains(serviceComponent.getName())) {
hostsWithMasterComponent.addAll(serviceComponent.getServiceComponentHosts().keySet());
}
}
}
final Map<String, Host> clusterHosts = clustersProvider.get().getHostsForCluster(clusterName);
for (Map.Entry<String, Host> hostEntry : clusterHosts.entrySet()) {
final Host host = hostEntry.getValue();
if (host.getMaintenanceState(cluster.getClusterId()) == MaintenanceState.ON && hostsWithMasterComponent.contains(host.getHostName())) {
prerequisiteCheck.getFailedOn().add(host.getHostName());
prerequisiteCheck.getFailedDetail().add(
new HostDetail(host.getHostId(), host.getHostName()));
}
}
if (!prerequisiteCheck.getFailedOn().isEmpty()) {
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
}
} |
223551095_2002 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
String dfsProtocolsRegex = DFS_PROTOCOLS_REGEX_DEFAULT;
PrerequisiteCheckConfig prerequisiteCheckConfig = request.getPrerequisiteCheckConfig();
Map<String, String> checkProperties = null;
if(prerequisiteCheckConfig != null) {
checkProperties = prerequisiteCheckConfig.getCheckProperties(this.getClass().getName());
}
if(checkProperties != null && checkProperties.containsKey(DFS_PROTOCOLS_REGEX_PROPERTY_NAME)) {
dfsProtocolsRegex = checkProperties.get(DFS_PROTOCOLS_REGEX_PROPERTY_NAME);
}
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
final String mrConfigType = "mapred-site";
final String coreSiteConfigType = "core-site";
final Map<String, DesiredConfig> desiredConfigs = cluster.getDesiredConfigs();
final DesiredConfig mrDesiredConfig = desiredConfigs.get(mrConfigType);
final DesiredConfig coreSiteDesiredConfig = desiredConfigs.get(coreSiteConfigType);
final Config mrConfig = cluster.getConfig(mrConfigType, mrDesiredConfig.getTag());
final Config coreSiteConfig = cluster.getConfig(coreSiteConfigType, coreSiteDesiredConfig.getTag());
final String applicationClasspath = mrConfig.getProperties().get("mapreduce.application.classpath");
final String frameworkPath = mrConfig.getProperties().get("mapreduce.application.framework.path");
final String defaultFS = coreSiteConfig.getProperties().get("fs.defaultFS");
List<String> errorMessages = new ArrayList<>();
if (applicationClasspath == null || applicationClasspath.isEmpty()) {
errorMessages.add(getFailReason(KEY_APP_CLASSPATH, prerequisiteCheck, request));
}
if (frameworkPath == null || frameworkPath.isEmpty()) {
errorMessages.add(getFailReason(KEY_FRAMEWORK_PATH, prerequisiteCheck, request));
}
if (!errorMessages.isEmpty()) {
prerequisiteCheck.getFailedOn().add("MAPREDUCE2");
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, " "));
return;
}
if (!frameworkPath.matches(dfsProtocolsRegex) && (defaultFS == null || !defaultFS.matches(dfsProtocolsRegex))) {
prerequisiteCheck.getFailedOn().add("MAPREDUCE2");
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(getFailReason(KEY_NOT_DFS, prerequisiteCheck, request));
}
} |
223551095_2003 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
String dfsProtocolsRegex = DFS_PROTOCOLS_REGEX_DEFAULT;
PrerequisiteCheckConfig prerequisiteCheckConfig = request.getPrerequisiteCheckConfig();
Map<String, String> checkProperties = null;
if(prerequisiteCheckConfig != null) {
checkProperties = prerequisiteCheckConfig.getCheckProperties(this.getClass().getName());
}
if(checkProperties != null && checkProperties.containsKey(DFS_PROTOCOLS_REGEX_PROPERTY_NAME)) {
dfsProtocolsRegex = checkProperties.get(DFS_PROTOCOLS_REGEX_PROPERTY_NAME);
}
final String clusterName = request.getClusterName();
final Cluster cluster = clustersProvider.get().getCluster(clusterName);
final String mrConfigType = "mapred-site";
final String coreSiteConfigType = "core-site";
final Map<String, DesiredConfig> desiredConfigs = cluster.getDesiredConfigs();
final DesiredConfig mrDesiredConfig = desiredConfigs.get(mrConfigType);
final DesiredConfig coreSiteDesiredConfig = desiredConfigs.get(coreSiteConfigType);
final Config mrConfig = cluster.getConfig(mrConfigType, mrDesiredConfig.getTag());
final Config coreSiteConfig = cluster.getConfig(coreSiteConfigType, coreSiteDesiredConfig.getTag());
final String applicationClasspath = mrConfig.getProperties().get("mapreduce.application.classpath");
final String frameworkPath = mrConfig.getProperties().get("mapreduce.application.framework.path");
final String defaultFS = coreSiteConfig.getProperties().get("fs.defaultFS");
List<String> errorMessages = new ArrayList<>();
if (applicationClasspath == null || applicationClasspath.isEmpty()) {
errorMessages.add(getFailReason(KEY_APP_CLASSPATH, prerequisiteCheck, request));
}
if (frameworkPath == null || frameworkPath.isEmpty()) {
errorMessages.add(getFailReason(KEY_FRAMEWORK_PATH, prerequisiteCheck, request));
}
if (!errorMessages.isEmpty()) {
prerequisiteCheck.getFailedOn().add("MAPREDUCE2");
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, " "));
return;
}
if (!frameworkPath.matches(dfsProtocolsRegex) && (defaultFS == null || !defaultFS.matches(dfsProtocolsRegex))) {
prerequisiteCheck.getFailedOn().add("MAPREDUCE2");
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(getFailReason(KEY_NOT_DFS, prerequisiteCheck, request));
}
} |
223551095_2004 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
final Cluster cluster = clustersProvider.get().getCluster(request.getClusterName());
Set<String> installedServices = cluster.getServices().keySet();
List<String> noUpgradeSupportServices = getNoUpgradeSupportServices(request);
Map<String, String> replacedServices = getReplacedServices(request);
List<String> removedServices = getRemovedServices(request);
List<String> failReasons = new ArrayList<>();
String reason = getFailReason(prerequisiteCheck, request);
for(String service: noUpgradeSupportServices){
if (installedServices.contains(service.toUpperCase())){
prerequisiteCheck.getFailedOn().add(service);
String msg = String.format(reason, service, service);
failReasons.add(msg);
}
}
reason = getFailReason(KEY_SERVICE_REPLACED, prerequisiteCheck, request);
for (Map.Entry<String, String> entry : replacedServices.entrySet()) {
String removedService = entry.getKey();
if(installedServices.contains(removedService.toUpperCase())){
prerequisiteCheck.getFailedOn().add(removedService);
String newService = entry.getValue();
String msg = String.format(reason, removedService, newService);
failReasons.add(msg);
}
}
reason = getFailReason(KEY_SERVICE_REMOVED, prerequisiteCheck, request);
for(String service: removedServices){
if (installedServices.contains(service.toUpperCase())){
prerequisiteCheck.getFailedOn().add(service);
String msg = String.format(reason, service, service);
failReasons.add(msg);
}
}
if(!failReasons.isEmpty()){
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(StringUtils.join(failReasons, '\n'));
}
} |
223551095_2005 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
final Cluster cluster = clustersProvider.get().getCluster(request.getClusterName());
Set<String> installedServices = cluster.getServices().keySet();
List<String> noUpgradeSupportServices = getNoUpgradeSupportServices(request);
Map<String, String> replacedServices = getReplacedServices(request);
List<String> removedServices = getRemovedServices(request);
List<String> failReasons = new ArrayList<>();
String reason = getFailReason(prerequisiteCheck, request);
for(String service: noUpgradeSupportServices){
if (installedServices.contains(service.toUpperCase())){
prerequisiteCheck.getFailedOn().add(service);
String msg = String.format(reason, service, service);
failReasons.add(msg);
}
}
reason = getFailReason(KEY_SERVICE_REPLACED, prerequisiteCheck, request);
for (Map.Entry<String, String> entry : replacedServices.entrySet()) {
String removedService = entry.getKey();
if(installedServices.contains(removedService.toUpperCase())){
prerequisiteCheck.getFailedOn().add(removedService);
String newService = entry.getValue();
String msg = String.format(reason, removedService, newService);
failReasons.add(msg);
}
}
reason = getFailReason(KEY_SERVICE_REMOVED, prerequisiteCheck, request);
for(String service: removedServices){
if (installedServices.contains(service.toUpperCase())){
prerequisiteCheck.getFailedOn().add(service);
String msg = String.format(reason, service, service);
failReasons.add(msg);
}
}
if(!failReasons.isEmpty()){
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(StringUtils.join(failReasons, '\n'));
}
} |
223551095_2006 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
final Cluster cluster = clustersProvider.get().getCluster(request.getClusterName());
Set<String> installedServices = cluster.getServices().keySet();
List<String> noUpgradeSupportServices = getNoUpgradeSupportServices(request);
Map<String, String> replacedServices = getReplacedServices(request);
List<String> removedServices = getRemovedServices(request);
List<String> failReasons = new ArrayList<>();
String reason = getFailReason(prerequisiteCheck, request);
for(String service: noUpgradeSupportServices){
if (installedServices.contains(service.toUpperCase())){
prerequisiteCheck.getFailedOn().add(service);
String msg = String.format(reason, service, service);
failReasons.add(msg);
}
}
reason = getFailReason(KEY_SERVICE_REPLACED, prerequisiteCheck, request);
for (Map.Entry<String, String> entry : replacedServices.entrySet()) {
String removedService = entry.getKey();
if(installedServices.contains(removedService.toUpperCase())){
prerequisiteCheck.getFailedOn().add(removedService);
String newService = entry.getValue();
String msg = String.format(reason, removedService, newService);
failReasons.add(msg);
}
}
reason = getFailReason(KEY_SERVICE_REMOVED, prerequisiteCheck, request);
for(String service: removedServices){
if (installedServices.contains(service.toUpperCase())){
prerequisiteCheck.getFailedOn().add(service);
String msg = String.format(reason, service, service);
failReasons.add(msg);
}
}
if(!failReasons.isEmpty()){
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(StringUtils.join(failReasons, '\n'));
}
} |
223551095_2007 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
final Cluster cluster = clustersProvider.get().getCluster(request.getClusterName());
Set<String> installedServices = cluster.getServices().keySet();
List<String> noUpgradeSupportServices = getNoUpgradeSupportServices(request);
Map<String, String> replacedServices = getReplacedServices(request);
List<String> removedServices = getRemovedServices(request);
List<String> failReasons = new ArrayList<>();
String reason = getFailReason(prerequisiteCheck, request);
for(String service: noUpgradeSupportServices){
if (installedServices.contains(service.toUpperCase())){
prerequisiteCheck.getFailedOn().add(service);
String msg = String.format(reason, service, service);
failReasons.add(msg);
}
}
reason = getFailReason(KEY_SERVICE_REPLACED, prerequisiteCheck, request);
for (Map.Entry<String, String> entry : replacedServices.entrySet()) {
String removedService = entry.getKey();
if(installedServices.contains(removedService.toUpperCase())){
prerequisiteCheck.getFailedOn().add(removedService);
String newService = entry.getValue();
String msg = String.format(reason, removedService, newService);
failReasons.add(msg);
}
}
reason = getFailReason(KEY_SERVICE_REMOVED, prerequisiteCheck, request);
for(String service: removedServices){
if (installedServices.contains(service.toUpperCase())){
prerequisiteCheck.getFailedOn().add(service);
String msg = String.format(reason, service, service);
failReasons.add(msg);
}
}
if(!failReasons.isEmpty()){
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(StringUtils.join(failReasons, '\n'));
}
} |
223551095_2008 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
final Cluster cluster = clustersProvider.get().getCluster(request.getClusterName());
Set<String> installedServices = cluster.getServices().keySet();
List<String> noUpgradeSupportServices = getNoUpgradeSupportServices(request);
Map<String, String> replacedServices = getReplacedServices(request);
List<String> removedServices = getRemovedServices(request);
List<String> failReasons = new ArrayList<>();
String reason = getFailReason(prerequisiteCheck, request);
for(String service: noUpgradeSupportServices){
if (installedServices.contains(service.toUpperCase())){
prerequisiteCheck.getFailedOn().add(service);
String msg = String.format(reason, service, service);
failReasons.add(msg);
}
}
reason = getFailReason(KEY_SERVICE_REPLACED, prerequisiteCheck, request);
for (Map.Entry<String, String> entry : replacedServices.entrySet()) {
String removedService = entry.getKey();
if(installedServices.contains(removedService.toUpperCase())){
prerequisiteCheck.getFailedOn().add(removedService);
String newService = entry.getValue();
String msg = String.format(reason, removedService, newService);
failReasons.add(msg);
}
}
reason = getFailReason(KEY_SERVICE_REMOVED, prerequisiteCheck, request);
for(String service: removedServices){
if (installedServices.contains(service.toUpperCase())){
prerequisiteCheck.getFailedOn().add(service);
String msg = String.format(reason, service, service);
failReasons.add(msg);
}
}
if(!failReasons.isEmpty()){
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(StringUtils.join(failReasons, '\n'));
}
} |
223551095_2009 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
final Cluster cluster = clustersProvider.get().getCluster(request.getClusterName());
Set<String> installedServices = cluster.getServices().keySet();
List<String> noUpgradeSupportServices = getNoUpgradeSupportServices(request);
Map<String, String> replacedServices = getReplacedServices(request);
List<String> removedServices = getRemovedServices(request);
List<String> failReasons = new ArrayList<>();
String reason = getFailReason(prerequisiteCheck, request);
for(String service: noUpgradeSupportServices){
if (installedServices.contains(service.toUpperCase())){
prerequisiteCheck.getFailedOn().add(service);
String msg = String.format(reason, service, service);
failReasons.add(msg);
}
}
reason = getFailReason(KEY_SERVICE_REPLACED, prerequisiteCheck, request);
for (Map.Entry<String, String> entry : replacedServices.entrySet()) {
String removedService = entry.getKey();
if(installedServices.contains(removedService.toUpperCase())){
prerequisiteCheck.getFailedOn().add(removedService);
String newService = entry.getValue();
String msg = String.format(reason, removedService, newService);
failReasons.add(msg);
}
}
reason = getFailReason(KEY_SERVICE_REMOVED, prerequisiteCheck, request);
for(String service: removedServices){
if (installedServices.contains(service.toUpperCase())){
prerequisiteCheck.getFailedOn().add(service);
String msg = String.format(reason, service, service);
failReasons.add(msg);
}
}
if(!failReasons.isEmpty()){
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(StringUtils.join(failReasons, '\n'));
}
} |
223551095_2010 | @Override
public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException {
final Cluster cluster = clustersProvider.get().getCluster(request.getClusterName());
Set<String> installedServices = cluster.getServices().keySet();
List<String> noUpgradeSupportServices = getNoUpgradeSupportServices(request);
Map<String, String> replacedServices = getReplacedServices(request);
List<String> removedServices = getRemovedServices(request);
List<String> failReasons = new ArrayList<>();
String reason = getFailReason(prerequisiteCheck, request);
for(String service: noUpgradeSupportServices){
if (installedServices.contains(service.toUpperCase())){
prerequisiteCheck.getFailedOn().add(service);
String msg = String.format(reason, service, service);
failReasons.add(msg);
}
}
reason = getFailReason(KEY_SERVICE_REPLACED, prerequisiteCheck, request);
for (Map.Entry<String, String> entry : replacedServices.entrySet()) {
String removedService = entry.getKey();
if(installedServices.contains(removedService.toUpperCase())){
prerequisiteCheck.getFailedOn().add(removedService);
String newService = entry.getValue();
String msg = String.format(reason, removedService, newService);
failReasons.add(msg);
}
}
reason = getFailReason(KEY_SERVICE_REMOVED, prerequisiteCheck, request);
for(String service: removedServices){
if (installedServices.contains(service.toUpperCase())){
prerequisiteCheck.getFailedOn().add(service);
String msg = String.format(reason, service, service);
failReasons.add(msg);
}
}
if(!failReasons.isEmpty()){
prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
prerequisiteCheck.setFailReason(StringUtils.join(failReasons, '\n'));
}
} |
223551095_2011 | protected String formatEntityList(LinkedHashSet<String> entities) {
if (entities == null || entities.isEmpty()) {
return "";
}
final StringBuilder formatted = new StringBuilder(StringUtils.join(entities, ", "));
if (entities.size() > 1) {
formatted.replace(formatted.lastIndexOf(","), formatted.lastIndexOf(",") + 1, " and");
}
return formatted.toString();
} |
223551095_2012 | public final boolean isApplicable(PrereqCheckRequest request) throws AmbariException {
List<CheckQualification> qualifications = Lists.newArrayList(
new ServiceQualification(), new OrchestrationQualification(getClass()));
// add any others from the concrete check
qualifications.addAll(getQualifications());
for (CheckQualification qualification : qualifications) {
if (!qualification.isApplicable(request)) {
return false;
}
}
return true;
} |
223551095_2013 | public boolean isRequired(UpgradeType upgradeType) {
UpgradeType[] upgradeTypes = getClass().getAnnotation(UpgradeCheck.class).required();
for (UpgradeType requiredType : upgradeTypes) {
if (upgradeType == requiredType) {
return true;
}
}
return false;
} |
223551095_2019 | public Map<String, ValidationResult> getPropertyResults() {
return propertyResults;
} |
223551095_2046 | public List<ParameterConfig> getParameters() {
return parameters == null ? Collections.emptyList() : parameters;
} |
223551095_2047 | public List<ResourceConfig> getResources() {
return resources == null ? Collections.emptyList() : resources;
} |
223551095_2049 | public List<InstanceConfig> getInstances() {
return instances == null ? Collections.emptyList() : instances;
} |
223551095_2061 | public List<PropertyConfig> getProperties() {
return properties == null ? Collections.emptyList() : properties;
} |
223551095_2062 | public List<EntityConfig> getEntities() {
return entities == null ? Collections.emptyList() : entities;
} |
223551095_2071 | public List<String> getSubResourceNames() {
return subResourceNames == null ? Collections.emptyList() : subResourceNames;
} |
223551095_2078 | @Override
public Set<Resource> getResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
Set<String> requestedIds = getRequestPropertyIds(request, predicate);
Set<ViewInstanceEntity> instanceDefinitions = new HashSet<>();
try {
Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate);
int size = propertyMaps.size();
Collection<ViewInstanceEntity> viewInstanceDefinitions = viewDefinition.getInstances();
if (size == 0) {
instanceDefinitions.addAll(viewInstanceDefinitions);
} else {
for (Map<String, Object> propertyMap : propertyMaps) {
String instanceName = (String) propertyMap.get(INSTANCE_NAME_PROPERTY_ID);
if (size == 1 && instanceName != null) {
String resourceId = (String) propertyMap.get(pkField);
if (resourceId != null) {
Object bean = getResourceProvider(instanceName).getResource(resourceId, requestedIds);
return Collections.singleton(getResource(bean, viewDefinition.getCommonName(),
viewDefinition.getVersion(), instanceName, requestedIds));
}
}
if (instanceName == null) {
instanceDefinitions.addAll(viewInstanceDefinitions);
break;
} else {
ViewInstanceEntity instanceDefinition = viewDefinition.getInstanceDefinition(instanceName);
if (instanceDefinition != null) {
instanceDefinitions.add(instanceDefinition);
}
}
}
}
Set<Resource> results = new HashSet<>();
ReadRequest readRequest = new ViewReadRequest(request, requestedIds, predicate == null ? "" : predicate.toString());
for (ViewInstanceEntity instanceDefinition : instanceDefinitions) {
Set<?> beans = instanceDefinition.getResourceProvider(type).getResources(readRequest);
for (Object bean : beans) {
Resource resource = getResource(bean, viewDefinition.getCommonName(),
viewDefinition.getVersion(), instanceDefinition.getName(), requestedIds);
if (predicate.evaluate(resource)) {
results.add(resource);
}
}
}
return results;
} catch (org.apache.ambari.view.NoSuchResourceException e) {
throw new NoSuchParentResourceException(e.getMessage(), e);
} catch (org.apache.ambari.view.UnsupportedPropertyException e) {
throw new UnsupportedPropertyException(getResourceType(e), e.getPropertyIds());
} catch (Exception e) {
LOG.error("Caught exception getting view sub resources.", e);
throw new SystemException(e.getMessage(), e);
}
} |
223551095_2079 | @Override
public Set<Resource> getResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
Set<String> requestedIds = getRequestPropertyIds(request, predicate);
Set<ViewInstanceEntity> instanceDefinitions = new HashSet<>();
try {
Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate);
int size = propertyMaps.size();
Collection<ViewInstanceEntity> viewInstanceDefinitions = viewDefinition.getInstances();
if (size == 0) {
instanceDefinitions.addAll(viewInstanceDefinitions);
} else {
for (Map<String, Object> propertyMap : propertyMaps) {
String instanceName = (String) propertyMap.get(INSTANCE_NAME_PROPERTY_ID);
if (size == 1 && instanceName != null) {
String resourceId = (String) propertyMap.get(pkField);
if (resourceId != null) {
Object bean = getResourceProvider(instanceName).getResource(resourceId, requestedIds);
return Collections.singleton(getResource(bean, viewDefinition.getCommonName(),
viewDefinition.getVersion(), instanceName, requestedIds));
}
}
if (instanceName == null) {
instanceDefinitions.addAll(viewInstanceDefinitions);
break;
} else {
ViewInstanceEntity instanceDefinition = viewDefinition.getInstanceDefinition(instanceName);
if (instanceDefinition != null) {
instanceDefinitions.add(instanceDefinition);
}
}
}
}
Set<Resource> results = new HashSet<>();
ReadRequest readRequest = new ViewReadRequest(request, requestedIds, predicate == null ? "" : predicate.toString());
for (ViewInstanceEntity instanceDefinition : instanceDefinitions) {
Set<?> beans = instanceDefinition.getResourceProvider(type).getResources(readRequest);
for (Object bean : beans) {
Resource resource = getResource(bean, viewDefinition.getCommonName(),
viewDefinition.getVersion(), instanceDefinition.getName(), requestedIds);
if (predicate.evaluate(resource)) {
results.add(resource);
}
}
}
return results;
} catch (org.apache.ambari.view.NoSuchResourceException e) {
throw new NoSuchParentResourceException(e.getMessage(), e);
} catch (org.apache.ambari.view.UnsupportedPropertyException e) {
throw new UnsupportedPropertyException(getResourceType(e), e.getPropertyIds());
} catch (Exception e) {
LOG.error("Caught exception getting view sub resources.", e);
throw new SystemException(e.getMessage(), e);
}
} |
223551095_2093 | private static Map<String, Map<String, String>> getInstanceDataByUser(ViewInstanceEntity instanceDefinition) {
Map<String, Map<String, String>> instanceDataByUser = new HashMap<>();
for (ViewInstanceDataEntity entity : instanceDefinition.getData()) {
if (!instanceDataByUser.containsKey(entity.getUser())) {
instanceDataByUser.put(entity.getUser(), new HashMap<>());
}
instanceDataByUser.get(entity.getUser()).put(entity.getName(), entity.getValue());
}
return instanceDataByUser;
} |
223551095_2095 | @Override
public InputStream readFrom(String path, String requestMethod, String body, Map<String, String> headers
) throws IOException, AmbariHttpException {
return getInputStream(path, requestMethod, headers, body == null ? null : body.getBytes());
} |
223551095_2098 | @Override
public <T> Collection<T> findAll(Class<T> clazz, String whereClause) throws PersistenceException {
checkInitialize();
EntityManager em = getEntityManager();
try {
Collection<T> resources = new HashSet<>();
DynamicType type = getDynamicEntityType(clazz);
if (type != null) {
try {
Query query = em.createQuery(getSelectStatement(clazz, whereClause));
List dynamicEntities = query.getResultList();
for (Object dynamicEntity : dynamicEntities) {
resources.add(toEntity(clazz, type, (DynamicEntity) dynamicEntity));
}
} catch (Exception e) {
throwPersistenceException("Caught exception trying to find " +
clazz.getName() + " where " + whereClause, e);
}
}
return resources;
} finally {
em.close();
}
} |
223551095_2101 | @Override
public synchronized Set<SubResourceDefinition> getSubResourceDefinitions() {
if (definitions == null) {
definitions = new HashSet<>();
List<String> subResourceNames = resourceConfiguration.getSubResourceNames();
if (subResourceNames != null) {
for (String subType : subResourceNames) {
Resource.Type type = Resource.Type.valueOf(
viewDefinition.getQualifiedResourceTypeName(subType));
definitions.add(new SubResourceDefinition(type));
}
}
}
return definitions;
} |
223551095_2103 | @Override
public String getConfigurationValue(String type, String key) {
Config config = cluster.getDesiredConfigByType(type);
return config == null ? null : config.getProperties().get(key);
} |
223551095_2104 | @Override
public List<String> getHostsForServiceComponent(String serviceName, String componentName){
List<ServiceComponentHost> serviceComponentHosts = cluster.getServiceComponentHosts(serviceName, componentName);
List<String> hosts = new ArrayList<>();
for (ServiceComponentHost serviceComponentHost : serviceComponentHosts) {
hosts.add(serviceComponentHost.getHostName());
}
return hosts;
} |
223551095_2105 | public String getId() {
return id;
} |
223551095_2106 | public Map<String, String> getProperties() {
return properties;
} |
223551095_2107 | public ViewDefinition getViewSubject() {
return viewSubject;
} |
223551095_2108 | public ViewInstanceDefinition getViewInstanceSubject() {
return viewInstanceSubject;
} |
223551095_2109 | @Override
public String getConfigurationValue(String type, String key) {
JsonElement config = null;
try {
String desiredTag = getDesiredConfig(type);
if (desiredTag != null) {
config = configurationCache.get(String.format("%s/configurations?(type=%s&tag=%s)",this.clusterPath, type, desiredTag));
}
} catch (ExecutionException e) {
throw new RemoteAmbariConfigurationReadException("Can't retrieve configuration from Remote Ambari", e);
}
if (config == null || !config.isJsonObject()) return null;
JsonElement items = config.getAsJsonObject().get("items");
if (items == null || !items.isJsonArray()) return null;
JsonElement item = items.getAsJsonArray().get(0);
if (item == null || !item.isJsonObject()) return null;
JsonElement properties = item.getAsJsonObject().get("properties");
if (properties == null || !properties.isJsonObject()) return null;
JsonElement property = properties.getAsJsonObject().get(key);
if (property == null || !property.isJsonPrimitive()) return null;
return property.getAsJsonPrimitive().getAsString();
} |
223551095_2110 | @Override
public List<String> getHostsForServiceComponent(String serviceName, String componentName) {
String url = String.format("%s/services/%s/components/%s?" +
"fields=host_components/HostRoles/host_name", this.clusterPath, serviceName, componentName);
List<String> hosts = new ArrayList<>();
try {
JsonElement response = configurationCache.get(url);
if (response == null || !response.isJsonObject()) return hosts;
JsonElement hostComponents = response.getAsJsonObject().get("host_components");
if (hostComponents == null || !hostComponents.isJsonArray()) return hosts;
for (JsonElement element : hostComponents.getAsJsonArray()) {
JsonElement hostRoles = element.getAsJsonObject().get("HostRoles");
String hostName = hostRoles.getAsJsonObject().get("host_name").getAsString();
hosts.add(hostName);
}
} catch (ExecutionException e) {
throw new RemoteAmbariConfigurationReadException("Can't retrieve host information from Remote Ambari", e);
}
return hosts;
} |
223551095_2111 | public void uninstallViewInstance(ViewInstanceEntity instanceEntity) {
LOG.info("uninstalling ViewInstance : {} ", instanceEntity);
ViewEntity viewEntity = viewDAO.findByName(instanceEntity.getViewName());
LOG.info("viewEntity received corresponding to the view entity : {} ", viewEntity);
if (viewEntity != null) {
String instanceName = instanceEntity.getName();
String viewName = viewEntity.getCommonName();
String version = viewEntity.getVersion();
ViewInstanceEntity instanceDefinition = instanceDAO.findByName(instanceEntity.getViewName(), instanceEntity.getName()); //getInstanceDefinition(viewName, version, instanceName);
LOG.debug("view instance entity received from database : {}", instanceDefinition);
if (instanceDefinition != null) {
if (instanceDefinition.isXmlDriven()) {
throw new IllegalStateException("View instances defined via xml can't be deleted through api requests");
}
List<PrivilegeEntity> instancePrivileges = privilegeDAO.findByResourceId(instanceEntity.getResource().getId());
LOG.info("Removing privilege entities : {}", instancePrivileges);
for (PrivilegeEntity privilegeEntity : instancePrivileges) {
removePrivilegeEntity(privilegeEntity);
}
LOG.info("Deleting view instance : view name : {}, version : {}, instanceName : {}", viewName, version, instanceName);
instanceDAO.remove(instanceDefinition);
}else{
throw new IllegalStateException("View instance '" + instanceEntity.getName() + "' not found.");
}
}else{
throw new IllegalStateException("View '" + instanceEntity.getViewName() + "' not found corresponding to view instance '" + instanceEntity.getName() + "'");
}
} |