use of com.sequenceiq.environment.util.PollingConfig in project cloudbreak by hortonworks.
the class DatahubDeletionServiceTest method deleteDatahubClustersForEnvironmentFail.
@Test
void deleteDatahubClustersForEnvironmentFail() {
PollingConfig pollingConfig = PollingConfig.builder().withSleepTime(0).withSleepTimeUnit(TimeUnit.SECONDS).withTimeout(10).withTimeoutTimeUnit(TimeUnit.SECONDS).build();
Environment environment = new Environment();
environment.setResourceCrn(ENV_CRN);
StackViewV4Response datahub1 = new StackViewV4Response();
datahub1.setCrn("crn1");
StackViewV4Response datahub2 = new StackViewV4Response();
datahub2.setCrn("crn2");
datahub2.setStatus(Status.DELETE_FAILED);
when(datahubService.list(anyString())).thenReturn(new StackViewV4Responses(Set.of(datahub1, datahub2)), new StackViewV4Responses(Set.of(datahub2)), new StackViewV4Responses(Set.of(datahub2)));
assertThatThrownBy(() -> underTest.deleteDatahubClustersForEnvironment(pollingConfig, environment, true)).isInstanceOf(UserBreakException.class).hasCauseInstanceOf(IllegalStateException.class);
ArgumentCaptor<DistroXMultiDeleteV1Request> captor = ArgumentCaptor.forClass(DistroXMultiDeleteV1Request.class);
verify(datahubService).deleteMultiple(anyString(), captor.capture(), eq(true));
DistroXMultiDeleteV1Request multiDeleteRequest = captor.getValue();
assertThat(multiDeleteRequest.getCrns()).hasSameElementsAs(Set.of("crn1", "crn2"));
}
use of com.sequenceiq.environment.util.PollingConfig in project cloudbreak by hortonworks.
the class DatahubDeletionServiceTest method deleteDatahubClustersForEnvironment.
@Test
void deleteDatahubClustersForEnvironment() {
PollingConfig pollingConfig = PollingConfig.builder().withSleepTime(0).withSleepTimeUnit(TimeUnit.SECONDS).withTimeout(10).withTimeoutTimeUnit(TimeUnit.SECONDS).build();
Environment environment = new Environment();
environment.setResourceCrn(ENV_CRN);
StackViewV4Response distrox1 = new StackViewV4Response();
distrox1.setCrn("crn1");
StackViewV4Response distrox2 = new StackViewV4Response();
distrox2.setCrn("crn2");
when(datahubService.list(anyString())).thenReturn(new StackViewV4Responses(Set.of(distrox1, distrox2)), new StackViewV4Responses(Set.of(distrox2)), new StackViewV4Responses(Set.of()));
underTest.deleteDatahubClustersForEnvironment(pollingConfig, environment, true);
ArgumentCaptor<DistroXMultiDeleteV1Request> captor = ArgumentCaptor.forClass(DistroXMultiDeleteV1Request.class);
verify(datahubService).deleteMultiple(anyString(), captor.capture(), eq(true));
DistroXMultiDeleteV1Request multiDeleteRequest = captor.getValue();
assertThat(multiDeleteRequest.getCrns()).hasSameElementsAs(Set.of("crn1", "crn2"));
}
use of com.sequenceiq.environment.util.PollingConfig in project cloudbreak by hortonworks.
the class DataHubClusterDeletionHandler method accept.
@Override
public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) {
LOGGER.debug("Accepting DataHubClustersDelete event");
EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData();
EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto();
EnvDeleteEvent envDeleteEvent = getEnvDeleteEvent(environmentDeletionDto);
try {
PollingConfig pollingConfig = getPollingConfig();
environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> datahubDeletionService.deleteDatahubClustersForEnvironment(pollingConfig, environment, environmentDeletionDto.isForceDelete()));
eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders());
} catch (Exception e) {
EnvClusterDeleteFailedEvent failedEvent = EnvClusterDeleteFailedEvent.builder().withEnvironmentID(environmentDto.getId()).withException(e).withResourceCrn(environmentDto.getResourceCrn()).withResourceName(environmentDto.getName()).build();
eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders());
}
}
use of com.sequenceiq.environment.util.PollingConfig in project cloudbreak by hortonworks.
the class DataLakeClustersDeleteHandler method accept.
@Override
public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) {
LOGGER.debug("Accepting DataLakeClustersDelete event");
EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData();
EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto();
EnvDeleteEvent envDeleteEvent = getEnvDeleteEvent(environmentDeletionDto);
try {
PollingConfig pollingConfig = getPollingConfig();
EnvironmentView environment = environmentViewService.getById(environmentDto.getId());
sdxDeleteService.deleteSdxClustersForEnvironment(pollingConfig, environment, environmentDeletionDto.isForceDelete());
eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders());
} catch (ClientErrorException e) {
String message;
try {
message = e.getResponse().readEntity(ExceptionResponse.class).getMessage();
} catch (Exception exception) {
message = null;
}
EnvClusterDeleteFailedEvent failedEvent = EnvClusterDeleteFailedEvent.builder().withEnvironmentID(environmentDto.getId()).withException(new BadRequestException(message)).withResourceCrn(environmentDto.getResourceCrn()).withResourceName(environmentDto.getName()).withMessage(message).build();
eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders());
} catch (Exception e) {
EnvClusterDeleteFailedEvent failedEvent = EnvClusterDeleteFailedEvent.builder().withEnvironmentID(environmentDto.getId()).withException(e).withResourceCrn(environmentDto.getResourceCrn()).withResourceName(environmentDto.getName()).build();
eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders());
}
}
Aggregations