Search in sources :

Example 21 with AmbariClient

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);
}
Also used : ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Matchers.anyString(org.mockito.Matchers.anyString) AmbariConnectionException(com.sequenceiq.ambari.client.AmbariConnectionException) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) AmbariConnectionException(com.sequenceiq.ambari.client.AmbariConnectionException) ExpectedException(org.junit.rules.ExpectedException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) Stack(com.sequenceiq.cloudbreak.domain.Stack) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Example 22 with AmbariClient

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;
}
Also used : HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Example 23 with 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);
    }
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Example 24 with AmbariClient

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();
}
Also used : HashMap(java.util.HashMap) HostMetadataState(com.sequenceiq.cloudbreak.common.type.HostMetadataState) Stack(com.sequenceiq.cloudbreak.domain.Stack) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata) Transactional(javax.transaction.Transactional)

Example 25 with AmbariClient

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);
}
Also used : HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Aggregations

AmbariClient (com.sequenceiq.ambari.client.AmbariClient)78 Test (org.junit.Test)39 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)37 Stack (com.sequenceiq.cloudbreak.domain.Stack)32 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)23 HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)16 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)16 HashMap (java.util.HashMap)16 PollingResult (com.sequenceiq.cloudbreak.service.PollingResult)15 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)14 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)14 Matchers.anyString (org.mockito.Matchers.anyString)14 Map (java.util.Map)13 AmbariConnectionException (com.sequenceiq.ambari.client.AmbariConnectionException)10 Collections.singletonMap (java.util.Collections.singletonMap)9 HashSet (java.util.HashSet)9 HostGroupAdjustmentJson (com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson)6 Status (com.sequenceiq.cloudbreak.api.model.Status)6 List (java.util.List)6 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)6