use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.
the class AmbariClusterSecurityServiceTest method testDisableSecurityWhenExceptionOccursWhichNotCancellationThenShouldThrowAmbariOperationFailedException.
@Test
public void testDisableSecurityWhenExceptionOccursWhichNotCancellationThenShouldThrowAmbariOperationFailedException() throws CloudbreakException {
Stack stack = TestUtil.stack();
Cluster cluster = TestUtil.cluster();
stack.setCluster(cluster);
AmbariClient ambariClient = Mockito.mock(AmbariClient.class);
when(clientFactory.getAmbariClient(stack, stack.getCluster())).thenReturn(ambariClient);
when(ambariClient.disableKerberos()).thenReturn(1);
Map<String, Integer> operationRequests = singletonMap("DISABLE_KERBEROS_REQUEST", 1);
ImmutablePair<PollingResult, Exception> pair = new ImmutablePair<>(PollingResult.EXIT, null);
String failed = "failed";
when(ambariOperationService.waitForOperations(stack, ambariClient, operationRequests, DISABLE_KERBEROS_STATE)).thenThrow(new AmbariConnectionException("failed"));
when(cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_DISABLE_KERBEROS_FAILED.code())).thenReturn("failed");
doThrow(new AmbariOperationFailedException("cancel")).when(ambariClusterConnectorPollingResultChecker).checkPollingResult(pair.getLeft(), failed);
thrown.expect(AmbariOperationFailedException.class);
thrown.expectMessage("failed");
underTest.disableSecurity(stack);
verify(ambariOperationService, times(1)).waitForOperations(stack, ambariClient, operationRequests, DISABLE_KERBEROS_STATE);
verify(cloudbreakMessagesService, times(1)).getMessage(AMBARI_CLUSTER_DISABLE_KERBEROS_FAILED.code());
verify(ambariClusterConnectorPollingResultChecker, times(1)).checkPollingResult(pair.getLeft(), failed);
}
use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.
the class AmbariClusterService method getAmbariClient.
private AmbariClient getAmbariClient(Stack stack) {
if (stack.getAmbariIp() == null) {
throw new NotFoundException(String.format("Ambari server is not available for the stack.[id: %s]", stack.getId()));
}
HttpClientConfig httpClientConfig = tlsSecurityService.buildTLSClientConfigForPrimaryGateway(stack.getId(), stack.getAmbariIp());
AmbariClient ambariClient = ambariClientProvider.getAmbariClient(httpClientConfig, stack.getGatewayPort(), stack.getCluster());
return ambariClient;
}
use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.
the class AmbariClusterService method validateComponentsCategory.
private void validateComponentsCategory(Stack stack, String hostGroup) {
Blueprint blueprint = stack.getCluster().getBlueprint();
try {
JsonNode root = JsonUtil.readTree(blueprint.getBlueprintText());
String blueprintName = root.path("Blueprints").path("blueprint_name").asText();
AmbariClient ambariClient = getAmbariClient(stack);
Map<String, String> categories = ambariClient.getComponentsCategory(blueprintName, hostGroup);
for (Entry<String, String> entry : categories.entrySet()) {
if (entry.getValue().equalsIgnoreCase(MASTER_CATEGORY)) {
throw new BadRequestException(String.format("Cannot downscale the '%s' hostGroupAdjustment group, because it contains a '%s' component", hostGroup, entry.getKey()));
}
}
} catch (IOException e) {
LOGGER.warn("Cannot check the host components category", e);
}
}
use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.
the class AmbariClusterService method updateClusterMetadata.
@Override
@Transactional(TxType.NEVER)
public Cluster updateClusterMetadata(Long stackId) {
Stack stack = stackService.getById(stackId);
AmbariClient ambariClient = getAmbariClient(stack);
Map<String, Integer> hostGroupCounter = new HashMap<>();
Set<HostMetadata> hosts = hostMetadataRepository.findHostsInCluster(stack.getCluster().getId());
Map<String, String> hostStatuses = ambariClient.getHostStatuses();
for (HostMetadata host : hosts) {
if (hostStatuses.containsKey(host.getHostName())) {
String hgName = host.getHostGroup().getName();
Integer hgCounter = hostGroupCounter.getOrDefault(hgName, 0) + 1;
hostGroupCounter.put(hgName, hgCounter);
HostMetadataState newState = HostMetadataState.HEALTHY.name().equals(hostStatuses.get(host.getHostName())) ? HostMetadataState.HEALTHY : HostMetadataState.UNHEALTHY;
boolean stateChanged = updateHostMetadataByHostState(stack, host.getHostName(), newState);
if (stateChanged && HostMetadataState.HEALTHY == newState) {
updateInstanceMetadataStateToRegistered(stackId, host);
}
}
}
hostGroupCounter(stack.getCluster().getId(), hostGroupCounter);
return stack.getCluster();
}
use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.
the class AmbariDecommissioner method verifyNodeCount.
public void verifyNodeCount(@Nonnull Stack stack, @Nonnull Cluster cluster, @Nonnull String hostName) {
requireNonNull(stack);
requireNonNull(cluster);
requireNonNull(hostName);
HttpClientConfig clientConfig = tlsSecurityService.buildTLSClientConfigForPrimaryGateway(stack.getId(), cluster.getAmbariIp());
AmbariClient ambariClient = ambariClientProvider.getAmbariClient(clientConfig, stack.getGatewayPort(), cluster);
String ambariName = cluster.getBlueprint().getAmbariName();
HostGroup hostGroup = hostGroupService.getByClusterAndHostName(cluster, hostName);
int replication = getReplicationFactor(ambariClient.getBlueprintMap(ambariName), hostGroup, ambariClient);
int hostSize = 1;
int reservedInstances = hostGroup.getHostMetadata().size() - hostSize;
verifyNodeCount(replication, hostSize, hostSize, reservedInstances);
}
Aggregations