Search in sources :

Example 16 with ClusterApi

use of com.sequenceiq.cloudbreak.cluster.api.ClusterApi in project cloudbreak by hortonworks.

the class ClusterServiceTest method testIsRangerRazEnabledOnClusterReturnsFalseIfCmIsRunning.

@Test
void testIsRangerRazEnabledOnClusterReturnsFalseIfCmIsRunning() {
    Stack stack = setupStack(STACK_ID);
    ClusterApi clusterApi = mock(ClusterApi.class);
    ClusterStatusService clusterStatusService = mock(ClusterStatusService.class);
    ClusterModificationService clusterModificationService = mock(ClusterModificationService.class);
    when(clusterApiConnectors.getConnector(stack)).thenReturn(clusterApi);
    when(clusterApi.clusterStatusService()).thenReturn(clusterStatusService);
    when(clusterApi.clusterModificationService()).thenReturn(clusterModificationService);
    when(clusterStatusService.isClusterManagerRunning()).thenReturn(true);
    when(clusterModificationService.isServicePresent(anyString(), eq(RANGER_RAZ))).thenReturn(false);
    assertFalse(underTest.isRangerRazEnabledOnCluster(stack));
}
Also used : ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) ClusterModificationService(com.sequenceiq.cloudbreak.cluster.api.ClusterModificationService) ClusterStatusService(com.sequenceiq.cloudbreak.cluster.api.ClusterStatusService) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with ClusterApi

use of com.sequenceiq.cloudbreak.cluster.api.ClusterApi in project cloudbreak by hortonworks.

the class StackStatusIntegrationTest method setUpClusterApi.

private void setUpClusterApi() {
    ClusterApi clusterApi = Mockito.mock(ClusterApi.class);
    when(clusterApi.clusterStatusService()).thenReturn(clusterStatusService);
    when(clusterApiConnectors.getConnector(stack)).thenReturn(clusterApi);
    hostStatuses = new HashMap<>();
    when(clusterStatusService.getExtendedHostStatuses(any())).thenReturn(new ExtendedHostStatuses(hostStatuses));
}
Also used : ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi)

Example 18 with ClusterApi

use of com.sequenceiq.cloudbreak.cluster.api.ClusterApi in project cloudbreak by hortonworks.

the class HealthCheckService method getUnhealthyHosts.

@Retryable(value = RuntimeException.class, maxAttempts = 5, backoff = @Backoff(delay = 5000L))
public Set<String> getUnhealthyHosts(Long stackId) {
    Stack stack = stackService.getById(stackId);
    ClusterApi connector = clusterApiConnectors.getConnector(stack);
    LOGGER.debug("Fetching extended host statuses for stack {} with retries", stack.getName());
    ExtendedHostStatuses extendedHostStatuses = connector.clusterStatusService().getExtendedHostStatuses(runtimeVersionService.getRuntimeVersion(stack.getCluster().getId()));
    LOGGER.debug("Returned statuses: {}", extendedHostStatuses);
    return extendedHostStatuses.getHostsHealth().entrySet().stream().filter(e -> e.getValue().stream().anyMatch(hc -> hc.getType() == HealthCheckType.HOST && hc.getResult() == HealthCheckResult.UNHEALTHY)).map(e -> e.getKey().value()).collect(Collectors.toSet());
}
Also used : ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) HealthCheckResult(com.sequenceiq.cloudbreak.common.type.HealthCheckResult) HealthCheckType(com.sequenceiq.cloudbreak.common.type.HealthCheckType) Logger(org.slf4j.Logger) RuntimeVersionService(com.sequenceiq.cloudbreak.service.stack.RuntimeVersionService) ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Collectors(java.util.stream.Collectors) Backoff(org.springframework.retry.annotation.Backoff) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) Inject(javax.inject.Inject) Service(org.springframework.stereotype.Service) ClusterApiConnectors(com.sequenceiq.cloudbreak.service.cluster.ClusterApiConnectors) Retryable(org.springframework.retry.annotation.Retryable) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Retryable(org.springframework.retry.annotation.Retryable)

Example 19 with ClusterApi

use of com.sequenceiq.cloudbreak.cluster.api.ClusterApi in project cloudbreak by hortonworks.

the class ClusterHostCertificatesRotationHandler method doAccept.

protected Selectable doAccept(HandlerEvent<ClusterHostCertificatesRotationRequest> event) {
    LOGGER.debug("Accepting Cluster Manager host certificates rotation request...");
    ClusterHostCertificatesRotationRequest request = event.getData();
    Selectable result;
    try {
        Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId());
        ClusterApi clusterApi = apiConnectors.getConnector(stack);
        String subAltName = loadBalancerSANProvider.getLoadBalancerSAN(stack).orElse(null);
        if (isRootSshAccessNeededForHostCertRotation(stack)) {
            rotateCertsWithSsh(stack, clusterApi, subAltName);
        } else {
            clusterApi.rotateHostCertificates(null, null, subAltName);
        }
        result = new ClusterHostCertificatesRotationSuccess(request.getResourceId());
    } catch (Exception e) {
        LOGGER.info("Cluster Manager host certificates rotation failed", e);
        result = new ClusterCertificatesRotationFailed(request.getResourceId(), e);
    }
    return result;
}
Also used : ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ClusterCertificatesRotationFailed(com.sequenceiq.cloudbreak.reactor.api.event.cluster.certrotate.ClusterCertificatesRotationFailed) ClusterHostCertificatesRotationSuccess(com.sequenceiq.cloudbreak.reactor.api.event.cluster.certrotate.ClusterHostCertificatesRotationSuccess) ClusterHostCertificatesRotationRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.certrotate.ClusterHostCertificatesRotationRequest) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 20 with ClusterApi

use of com.sequenceiq.cloudbreak.cluster.api.ClusterApi in project cloudbreak by hortonworks.

the class ClusterService method isRangerRazEnabledOnCluster.

public boolean isRangerRazEnabledOnCluster(Stack stack) {
    Cluster cluster = stack.getCluster();
    ClusterApi clusterApi = clusterApiConnectors.getConnector(stack);
    if (!clusterApi.clusterStatusService().isClusterManagerRunning()) {
        throw new BadRequestException(String.format("Cloudera Manager is not running for cluster: %s", cluster.getName()));
    }
    return clusterApi.clusterModificationService().isServicePresent(cluster.getName(), RANGER_RAZ);
}
Also used : ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException)

Aggregations

ClusterApi (com.sequenceiq.cloudbreak.cluster.api.ClusterApi)27 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)20 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)9 Set (java.util.Set)7 ExtendedHostStatuses (com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses)6 ParcelOperationStatus (com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus)5 ClusterApiConnectors (com.sequenceiq.cloudbreak.service.cluster.ClusterApiConnectors)5 ClusterStatusService (com.sequenceiq.cloudbreak.cluster.api.ClusterStatusService)4 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)4 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)4 InstanceMetaDataService (com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService)4 StackService (com.sequenceiq.cloudbreak.service.stack.StackService)4 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 Test (org.junit.jupiter.api.Test)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Service (org.springframework.stereotype.Service)4 InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)3 HostName (com.sequenceiq.cloudbreak.cloud.model.HostName)3