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");
}
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));
}
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()));
}
}
Aggregations