use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class ClouderaManagerDecomissioner method getReplicationFactor.
private int getReplicationFactor(ApiClient client, String clusterName) {
try {
ServicesResourceApi servicesResourceApi = clouderaManagerApiFactory.getServicesResourceApi(client);
ApiServiceConfig apiServiceConfig = servicesResourceApi.readServiceConfig(clusterName, "hdfs", "full");
Optional<ApiConfig> dfsReplicationConfig = apiServiceConfig.getItems().stream().filter(apiConfig -> "dfs_replication".equals(apiConfig.getName())).findFirst();
return dfsReplicationConfig.map(rc -> Integer.parseInt(StringUtils.isEmpty(rc.getValue()) ? rc.getDefault() : rc.getValue())).orElse(0);
} catch (ApiException ex) {
throw new CloudbreakServiceException(ex.getMessage(), ex);
}
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class ClouderaManagerDecomissioner method enterMaintenanceMode.
public void enterMaintenanceMode(Set<String> hostList, ApiClient client) {
HostsResourceApi hostsResourceApi = clouderaManagerApiFactory.getHostsResourceApi(client);
String currentHostId = null;
int successCount = 0;
List<String> availableHostsIdsFromCm = null;
LOGGER.debug("Attempting to put {} instances into CM maintenance mode", hostList == null ? 0 : hostList.size());
try {
ApiHostList hostRefList = hostsResourceApi.readHosts(null, null, SUMMARY_REQUEST_VIEW);
availableHostsIdsFromCm = hostRefList.getItems().stream().filter(apiHostRef -> hostList.contains(apiHostRef.getHostname())).parallel().map(ApiHost::getHostId).collect(Collectors.toList());
for (String hostId : availableHostsIdsFromCm) {
currentHostId = hostId;
hostsResourceApi.enterMaintenanceMode(hostId);
successCount++;
}
LOGGER.debug("Finished putting {} instances into CM maintenance mode. Initial request size: {}, CM availableCount: {}", successCount, hostList == null ? 0 : hostList.size(), availableHostsIdsFromCm == null ? "null" : availableHostsIdsFromCm);
} catch (ApiException e) {
LOGGER.error("Failed while putting a node into maintenance mode. nodeId=" + currentHostId + ", successCount=" + successCount, e);
throw new CloudbreakServiceException(e.getMessage(), e);
}
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class ResourceAttributeUtil method getTypedAttributes.
public <T> Optional<T> getTypedAttributes(Resource resource) {
Json attributes = resource.getAttributes();
Optional<T> ret = Optional.empty();
try {
if (Objects.nonNull(attributes.getValue())) {
Map<String, Object> map = attributes.get(Map.class);
String clss = map.getOrDefault(CloudResource.ATTRIBUTE_TYPE, VolumeSetAttributes.class.getCanonicalName()).toString();
Class<T> attributeType = (Class<T>) Class.forName(clss);
ret = Optional.ofNullable(attributes.get(attributeType));
}
} catch (IOException e) {
throw new CloudbreakServiceException("Failed to parse attributes to type: " + attributes, e);
} catch (ClassNotFoundException e) {
LOGGER.debug("Cannot parse class: {}", e.getMessage());
}
return ret;
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class SaltCheckerConclusionStep method check.
@Override
public Conclusion check(Long resourceId) {
RPCResponse<SaltHealthReport> saltPingResponse;
try {
saltPingResponse = nodeStatusService.saltPing(resourceId);
} catch (CloudbreakServiceException e) {
LOGGER.debug("Salt health report failed, fallback and check unreachable nodes, error: {}", e.getMessage());
return checkUnreachableNodes(resourceId);
}
SaltHealthReport report = saltPingResponse.getResult();
if (report == null) {
LOGGER.debug("Salt health report was null, fallback and check unreachable nodes.");
return checkUnreachableNodes(resourceId);
}
List<String> failedServicesOnMaster = collectFailedServicesOnMaster(report);
if (!failedServicesOnMaster.isEmpty()) {
return createFailedConclusionForMaster(failedServicesOnMaster);
} else {
Map<String, String> unreachableMinions = collectUnreachableMinions(report);
if (unreachableMinions.isEmpty()) {
return succeeded();
} else {
return createFailedConclusionForMinions(unreachableMinions);
}
}
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class NetworkCheckerConclusionStepTest method checkShouldBeSuccessfulIfNetworkReportFailedForOlderImageVersions.
@Test
public void checkShouldBeSuccessfulIfNetworkReportFailedForOlderImageVersions() {
when(nodeStatusService.getNetworkReport(eq(1L))).thenThrow(new CloudbreakServiceException("error"));
Conclusion stepResult = underTest.check(1L);
assertFalse(stepResult.isFailureFound());
assertNull(stepResult.getConclusion());
assertNull(stepResult.getDetails());
assertEquals(NetworkCheckerConclusionStep.class, stepResult.getConclusionStepClass());
verify(nodeStatusService, times(1)).getNetworkReport(eq(1L));
}
Aggregations