use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class ClouderaManagerDecomissioner method deleteUnusedCredentialsFromCluster.
public void deleteUnusedCredentialsFromCluster(Stack stack, ApiClient client) {
LOGGER.debug("Deleting unused credentials");
ClouderaManagerResourceApi clouderaManagerResourceApi = clouderaManagerApiFactory.getClouderaManagerResourceApi(client);
try {
ApiCommand command = clouderaManagerResourceApi.deleteCredentialsCommand("unused");
clouderaManagerPollingServiceProvider.startPollingCmKerberosJob(stack, client, command.getId());
} catch (ApiException e) {
LOGGER.error("Failed to delete unused credentials", e);
throw new CloudbreakServiceException(e.getMessage(), e);
}
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class ClouderaManagerDecomissioner method stopAndRemoveMgmtService.
public void stopAndRemoveMgmtService(Stack stack, ApiClient client) {
MgmtServiceResourceApi mgmtServiceResourceApi = clouderaManagerApiFactory.getMgmtServiceResourceApi(client);
try {
clouderaManagerPollingServiceProvider.startPollingCmManagementServiceShutdown(stack, client, mgmtServiceResourceApi.stopCommand().getId());
mgmtServiceResourceApi.deleteCMS();
} catch (ApiException e) {
LOGGER.error("Failed to stop management services.", e);
throw new CloudbreakServiceException(e.getMessage(), e);
}
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class ClouderaManagerDecomissioner method deleteHostFromClouderaManager.
private void deleteHostFromClouderaManager(Stack stack, InstanceMetaData data, ApiClient client) {
HostsResourceApi hostsResourceApi = clouderaManagerApiFactory.getHostsResourceApi(client);
try {
ApiHostList hostRefList = hostsResourceApi.readHosts(null, null, SUMMARY_REQUEST_VIEW);
Optional<ApiHost> hostRefOptional = hostRefList.getItems().stream().filter(host -> data.getDiscoveryFQDN() != null && data.getDiscoveryFQDN().equals(host.getHostname())).findFirst();
if (hostRefOptional.isPresent()) {
ApiHost hostRef = hostRefOptional.get();
ClustersResourceApi clustersResourceApi = clouderaManagerApiFactory.getClustersResourceApi(client);
clustersResourceApi.removeHost(stack.getName(), hostRef.getHostId());
hostsResourceApi.deleteHost(hostRef.getHostId());
LOGGER.debug("Host remove request sent. Host id: [{}]", hostRef.getHostId());
} else {
LOGGER.debug("Host already deleted.");
}
} catch (ApiException e) {
LOGGER.error("Failed to delete host: {}", data.getDiscoveryFQDN(), e);
throw new CloudbreakServiceException(e.getMessage(), e);
}
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class ClouderaManagerDecomissioner method deleteRolesFromHost.
private void deleteRolesFromHost(Stack stack, InstanceMetaData data, ApiClient client) {
LOGGER.debug("Deleting roles from host: [{}]", data.getDiscoveryFQDN());
ServicesResourceApi servicesResourceApi = clouderaManagerApiFactory.getServicesResourceApi(client);
RolesResourceApi rolesResourceApi = clouderaManagerApiFactory.getRolesResourceApi(client);
String filter = "hostname==" + data.getDiscoveryFQDN();
try {
ApiServiceList serviceList = servicesResourceApi.readServices(stack.getName(), SUMMARY_REQUEST_VIEW);
serviceList.getItems().stream().map(ApiService::getName).flatMap(toRoleStream(stack, rolesResourceApi, filter)).forEach(deleteServiceRole(stack, rolesResourceApi));
} catch (ApiException e) {
LOGGER.error("Failed to read services", e);
throw new CloudbreakServiceException(e.getMessage(), e);
}
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class ClouderaManagerDecomissioner method collectHostsToRemove.
public Map<String, InstanceMetaData> collectHostsToRemove(Stack stack, HostGroup hostGroup, Set<String> hostNames, ApiClient client) {
Set<InstanceMetaData> hostsInHostGroup = hostGroup.getInstanceGroup().getNotTerminatedInstanceMetaDataSet();
Map<String, InstanceMetaData> hostsToRemove = hostsInHostGroup.stream().filter(hostMetadata -> hostNames.contains(hostMetadata.getDiscoveryFQDN())).collect(Collectors.toMap(InstanceMetaData::getDiscoveryFQDN, hostMetadata -> hostMetadata));
if (hostsToRemove.size() != hostNames.size()) {
List<String> missingHosts = hostNames.stream().filter(h -> !hostsToRemove.containsKey(h)).collect(Collectors.toList());
LOGGER.debug("Not all requested hosts found in CB for host group: {}. MissingCount={}, missingHosts=[{}]. Requested hosts: [{}]", hostGroup.getName(), missingHosts.size(), missingHosts, hostNames);
}
HostsResourceApi hostsResourceApi = clouderaManagerApiFactory.getHostsResourceApi(client);
try {
ApiHostList hostRefList = hostsResourceApi.readHosts(null, null, SUMMARY_REQUEST_VIEW);
List<String> runningHosts = hostRefList.getItems().stream().map(ApiHost::getHostname).collect(Collectors.toList());
// TODO: what if i remove a node from CM manually?
List<String> matchingCmHosts = hostsToRemove.keySet().stream().filter(hostName -> runningHosts.contains(hostName)).collect(Collectors.toList());
Set<String> matchingCmHostSet = new HashSet<>(matchingCmHosts);
if (matchingCmHosts.size() != hostsToRemove.size()) {
List<String> missingHostsInCm = hostsToRemove.keySet().stream().filter(h -> !matchingCmHostSet.contains(h)).collect(Collectors.toList());
LOGGER.debug("Not all requested hosts found in CM. MissingCount={}, missingHosts=[{}]. Requested hosts: [{}]", missingHostsInCm.size(), missingHostsInCm, hostsToRemove.keySet());
}
Sets.newHashSet(hostsToRemove.keySet()).stream().filter(hostName -> !matchingCmHostSet.contains(hostName)).forEach(hostsToRemove::remove);
LOGGER.debug("Collected hosts to remove: [{}]", hostsToRemove);
return hostsToRemove;
} catch (ApiException e) {
LOGGER.error("Failed to get host list for cluster: {}", stack.getName(), e);
throw new CloudbreakServiceException(e.getMessage(), e);
}
}
Aggregations