Search in sources :

Example 6 with PollingConfig

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"));
}
Also used : StackViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response) UserBreakException(com.dyngr.exception.UserBreakException) Environment(com.sequenceiq.environment.environment.domain.Environment) DistroXMultiDeleteV1Request(com.sequenceiq.distrox.api.v1.distrox.model.cluster.DistroXMultiDeleteV1Request) StackViewV4Responses(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Responses) PollingConfig(com.sequenceiq.environment.util.PollingConfig) Test(org.junit.jupiter.api.Test)

Example 7 with PollingConfig

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"));
}
Also used : StackViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response) Environment(com.sequenceiq.environment.environment.domain.Environment) DistroXMultiDeleteV1Request(com.sequenceiq.distrox.api.v1.distrox.model.cluster.DistroXMultiDeleteV1Request) StackViewV4Responses(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Responses) PollingConfig(com.sequenceiq.environment.util.PollingConfig) Test(org.junit.jupiter.api.Test)

Example 8 with PollingConfig

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());
    }
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvDeleteEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent) EnvClusterDeleteFailedEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent) PollingConfig(com.sequenceiq.environment.util.PollingConfig) EnvironmentDeletionDto(com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)

Example 9 with PollingConfig

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());
    }
}
Also used : ExceptionResponse(com.sequenceiq.cloudbreak.common.exception.ExceptionResponse) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvDeleteEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent) EnvironmentView(com.sequenceiq.environment.environment.domain.EnvironmentView) ClientErrorException(javax.ws.rs.ClientErrorException) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) EnvClusterDeleteFailedEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent) PollingConfig(com.sequenceiq.environment.util.PollingConfig) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ClientErrorException(javax.ws.rs.ClientErrorException) EnvironmentDeletionDto(com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)

Aggregations

PollingConfig (com.sequenceiq.environment.util.PollingConfig)9 Test (org.junit.jupiter.api.Test)7 EnvironmentView (com.sequenceiq.environment.environment.domain.EnvironmentView)5 StackViewV4Responses (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Responses)4 Environment (com.sequenceiq.environment.environment.domain.Environment)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 UserBreakException (com.dyngr.exception.UserBreakException)2 StackViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response)2 DistroXMultiDeleteV1Request (com.sequenceiq.distrox.api.v1.distrox.model.cluster.DistroXMultiDeleteV1Request)2 EnvironmentDeletionDto (com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)2 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)2 EnvClusterDeleteFailedEvent (com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent)2 EnvDeleteEvent (com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent)2 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 ExceptionResponse (com.sequenceiq.cloudbreak.common.exception.ExceptionResponse)1 ClientErrorException (javax.ws.rs.ClientErrorException)1