Search in sources :

Example 1 with DatalakeDto

use of com.sequenceiq.cloudbreak.dto.datalake.DatalakeDto in project cloudbreak by hortonworks.

the class DeregisterServicesHandler method accept.

@Override
public void accept(Event<DeregisterServicesRequest> event) {
    DeregisterServicesResult result;
    try {
        LOGGER.info("Received DeregisterServicesRequest event: {}", event.getData());
        Stack stack = stackService.getByIdWithListsInTransaction(event.getData().getResourceId());
        ClusterApi clusterApi = clusterApiConnectors.getConnector(stack);
        Optional<DatalakeDto> datalakeDto = Optional.empty();
        Optional<Stack> dataLakeOptional = datalakeService.getDatalakeStackByDatahubStack(stack);
        if (dataLakeOptional.isPresent()) {
            Stack dataLake = dataLakeOptional.get();
            HttpClientConfig httpClientConfig = tlsSecurityService.buildTLSClientConfigForPrimaryGateway(dataLake.getId(), dataLake.getClusterManagerIp(), dataLake.cloudPlatform());
            datalakeDto = Optional.ofNullable(DatalakeDto.DatalakeDtoBuilder.aDatalakeDto().withGatewayPort(dataLake.getGatewayPort()).withHttpClientConfig(httpClientConfig).withPassword(dataLake.getCluster().getCloudbreakAmbariPassword()).withUser(dataLake.getCluster().getCloudbreakAmbariUser()).withName(dataLake.getName()).build());
        }
        clusterApi.clusterSecurityService().deregisterServices(stack.getName(), datalakeDto);
        LOGGER.info("Finished disabling Security");
        result = new DeregisterServicesResult(event.getData());
    } catch (Exception e) {
        LOGGER.warn("An error has occured during disabling security", e);
        result = new DeregisterServicesResult(e.getMessage(), e, event.getData());
    }
    LOGGER.info("Sending out DeregisterServicesResult: {}", result);
    eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
    LOGGER.info("DeregisterServicesResult has been sent");
}
Also used : ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) DatalakeDto(com.sequenceiq.cloudbreak.dto.datalake.DatalakeDto) DeregisterServicesResult(com.sequenceiq.cloudbreak.reactor.api.event.cluster.DeregisterServicesResult) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 2 with DatalakeDto

use of com.sequenceiq.cloudbreak.dto.datalake.DatalakeDto in project cloudbreak by hortonworks.

the class DeregisterServicesHandlerTest method testAcceptEvent.

@Test
void testAcceptEvent() {
    when(clusterApi.clusterSecurityService()).thenReturn(clusterSecurityService);
    underTest.accept(event);
    verify(clusterSecurityService).deregisterServices(anyString(), argumentCaptor.capture());
    DatalakeDto result = argumentCaptor.getValue().get();
    assertThat(result.getName()).isEqualTo(TEST_DATALAKE_NAME);
    assertThat(result.getUser()).isEqualTo(TEST_CM_USER);
    assertThat(result.getPassword()).isEqualTo(TEST_CM_PASSWORD);
    assertThat(result.getGatewayPort()).isEqualTo(TEST_GATEWAY_PORT);
    verify(eventBus, times(1)).notify((Object) any(), any(Event.class));
}
Also used : DatalakeDto(com.sequenceiq.cloudbreak.dto.datalake.DatalakeDto) Event(reactor.bus.Event) Test(org.junit.jupiter.api.Test)

Example 3 with DatalakeDto

use of com.sequenceiq.cloudbreak.dto.datalake.DatalakeDto in project cloudbreak by hortonworks.

the class ClouderaManagerDeregisterService method deregisterServices.

public void deregisterServices(HttpClientConfig clientConfig, Stack stack, Optional<DatalakeDto> datalakeDto) {
    Cluster cluster = stack.getCluster();
    String user = cluster.getCloudbreakAmbariUser();
    String password = cluster.getCloudbreakAmbariPassword();
    ClouderaManagerRepo clouderaManagerRepoDetails = clusterComponentConfigProvider.getClouderaManagerRepoDetails(cluster.getId());
    try {
        CmTemplateProcessor cmTemplateProcessor = cmTemplateProcessorFactory.get(stack.getCluster().getBlueprint().getBlueprintText());
        if (CMRepositoryVersionUtil.isRangerTearDownSupported(clouderaManagerRepoDetails)) {
            if (datalakeDto.isPresent()) {
                LOGGER.info("The current cluster {} is a Data Hub cluster so teardown REQUIRED.", stack.getName());
                DatalakeDto datalake = datalakeDto.get();
                ClustersResourceApi clustersResourceApi = clouderaManagerApiFactory.getClustersResourceApi(datalakeClient(datalake));
                clustersResourceApi.tearDownWorkloadCluster(datalake.getName(), stack.getName());
            } else {
                LOGGER.info("The current cluster {} is a Data Lake cluster so teardown NOT_REQUIRED.", stack.getName());
            }
        } else {
            ApiClient client = clouderaManagerApiClientProvider.getV31Client(stack.getGatewayPort(), user, password, clientConfig);
            if (cmTemplateProcessor.isCMComponentExistsInBlueprint(COMPONENT_NIFI_REGISTRY_SERVER)) {
                LOGGER.info("The current cluster {} contains NIFI_REGISTRY_SERVER and ranger teardown not supported. " + "CDP will call RemoveRangerRepo command.", stack.getName());
                clouderaManagerApiFactory.getServicesResourceApi(client).serviceCommandByName(stack.getName(), "RemoveRangerRepo", SERVICE_NIFIREGISTRY);
            }
            if (cmTemplateProcessor.isCMComponentExistsInBlueprint(COMPONENT_NIFI_NODE)) {
                LOGGER.info("The current cluster {} contains NIFI_NODE and ranger teardown not supported. " + "CDP will call RemoveRangerRepo command.", stack.getName());
                clouderaManagerApiFactory.getServicesResourceApi(client).serviceCommandByName(stack.getName(), "RemoveRangerRepo", SERVICE_NIFI);
            }
        }
    } catch (Exception e) {
        LOGGER.warn("Couldn't remove services. This has to be done manually." + " It's possible that CM or the instance is not running. Notification is sent to the UI.", e);
        cloudbreakEventService.fireCloudbreakEvent(stack.getId(), stack.getStatus().name(), ResourceEvent.CLUSTER_CM_SECURITY_GROUP_TOO_STRICT, List.of(e.getMessage()));
    }
}
Also used : ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) DatalakeDto(com.sequenceiq.cloudbreak.dto.datalake.DatalakeDto) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) CmTemplateProcessor(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor) ApiClient(com.cloudera.api.swagger.client.ApiClient) ClustersResourceApi(com.cloudera.api.swagger.ClustersResourceApi) ClouderaManagerClientInitException(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException)

Aggregations

DatalakeDto (com.sequenceiq.cloudbreak.dto.datalake.DatalakeDto)3 ClustersResourceApi (com.cloudera.api.swagger.ClustersResourceApi)1 ApiClient (com.cloudera.api.swagger.client.ApiClient)1 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)1 ClouderaManagerRepo (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo)1 ClusterApi (com.sequenceiq.cloudbreak.cluster.api.ClusterApi)1 ClouderaManagerClientInitException (com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException)1 CmTemplateProcessor (com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)1 DeregisterServicesResult (com.sequenceiq.cloudbreak.reactor.api.event.cluster.DeregisterServicesResult)1 Test (org.junit.jupiter.api.Test)1 Event (reactor.bus.Event)1