Search in sources :

Example 1 with EnvCreationFailureEvent

use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent in project cloudbreak by hortonworks.

the class NetworkCreationHandlerTest method testHandleValidationFailure.

@Test
public void testHandleValidationFailure() {
    EnvironmentDto environmentDto = createEnvironmentDto();
    Event<EnvironmentDto> environmentDtoEvent = Event.wrap(environmentDto);
    AwsNetwork network = createNetwork();
    Environment environment = createEnvironment(network);
    Optional<Environment> environmentOptional = Optional.of(environment);
    Map<String, CloudSubnet> subnets = createDefaultPrivateSubnets();
    when(environmentService.findEnvironmentById(any())).thenReturn(environmentOptional);
    when(cloudNetworkService.retrieveSubnetMetadata(any(EnvironmentDto.class), any())).thenReturn(subnets);
    when(networkMetadataValidationService.getEndpointGatewaySubnetMetadata(any(), any())).thenThrow(new BadRequestException("failure"));
    when(environmentResourceService.createAndSetNetwork(any(), any(), any(), any(), any())).thenReturn(network);
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.accept(environmentDtoEvent));
    ArgumentCaptor<Event<EnvCreationFailureEvent>> eventCaptor = ArgumentCaptor.forClass(Event.class);
    verify(eventBus, times(1)).notify(any(Object.class), eventCaptor.capture());
    Event<EnvCreationFailureEvent> value = eventCaptor.getValue();
    assertTrue(value.getData().getException() instanceof BadRequestException);
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) EnvCreationFailureEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Environment(com.sequenceiq.environment.environment.domain.Environment) BadRequestException(javax.ws.rs.BadRequestException) Event(reactor.bus.Event) EnvCreationFailureEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent) NetworkTest(com.sequenceiq.environment.environment.service.network.NetworkTest) Test(org.junit.jupiter.api.Test)

Example 2 with EnvCreationFailureEvent

use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent in project cloudbreak by hortonworks.

the class PublicKeyCreationHandlerTest method verifyEnvCreationFailedEvent.

private void verifyEnvCreationFailedEvent(Exception exceptionExpected) {
    // BaseNamedFlowEvent event = baseNamedFlowEvent.getValue();
    Event<EnvCreationFailureEvent> value = envCreationFailureEventEventCaptor.getValue();
    EnvCreationFailureEvent event = value.getData();
    assertThat(event).isInstanceOf(EnvCreationFailureEvent.class);
    EnvCreationFailureEvent envCreateFailedEvent = (EnvCreationFailureEvent) event;
    assertThat(envCreateFailedEvent.getResourceName()).isEqualTo(ENVIRONMENT_NAME);
    assertThat(envCreateFailedEvent.getResourceCrn()).isEqualTo(ENVIRONMENT_CRN);
    assertThat(envCreateFailedEvent.getResourceId()).isEqualTo(ENVIRONMENT_ID);
    assertThat(envCreateFailedEvent.selector()).isEqualTo(FAILED_ENV_CREATION_EVENT.selector());
    assertThat(envCreateFailedEvent.getException()).isSameAs(exceptionExpected);
}
Also used : EnvCreationFailureEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent)

Example 3 with EnvCreationFailureEvent

use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent in project cloudbreak by hortonworks.

the class ResourceEncryptionInitializationHandlerTest method verifyEnvCreationFailedEvent.

private void verifyEnvCreationFailedEvent(Exception exceptionExpected, boolean wrappedInCloudbreakServiceException, String messageCloudbreakServiceExceptionExpected) {
    Event<EnvCreationFailureEvent> event = envCreationFailureEventEventCaptor.getValue();
    EnvCreationFailureEvent envCreationFailureEvent = event.getData();
    assertThat(envCreationFailureEvent.getResourceName()).isEqualTo(ENVIRONMENT_NAME);
    assertThat(envCreationFailureEvent.getResourceCrn()).isEqualTo(ENVIRONMENT_CRN);
    assertThat(envCreationFailureEvent.getResourceId()).isEqualTo(ENVIRONMENT_ID);
    assertThat(envCreationFailureEvent.selector()).isEqualTo(FAILED_ENV_CREATION_EVENT.selector());
    Exception exception = envCreationFailureEvent.getException();
    if (wrappedInCloudbreakServiceException) {
        assertThat(exception).isInstanceOf(CloudbreakServiceException.class);
        assertThat(exception).hasMessage(messageCloudbreakServiceExceptionExpected);
        assertThat(exception.getCause()).isSameAs(exceptionExpected);
    } else {
        assertThat(exception).isSameAs(exceptionExpected);
    }
}
Also used : EnvCreationFailureEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)

Example 4 with EnvCreationFailureEvent

use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent in project cloudbreak by hortonworks.

the class EnvCreationActionsTest method verifyCreationActionFailureEvent.

private void verifyCreationActionFailureEvent(String selector) {
    assertThat(selectorArgumentCaptor.getValue()).isEqualTo(selector);
    verifyEventFactoryAndHeaders();
    Object payload = payloadArgumentCaptor.getValue();
    assertThat(payload).isInstanceOf(EnvCreationFailureEvent.class);
    EnvCreationFailureEvent failureEvent = (EnvCreationFailureEvent) payload;
    assertThat(failureEvent.getResourceCrn()).isEqualTo(ENVIRONMENT_CRN);
    assertThat(failureEvent.getResourceName()).isEqualTo(ENVIRONMENT_NAME);
    assertThat(failureEvent.getResourceId()).isEqualTo(ENVIRONMENT_ID);
}
Also used : EnvCreationFailureEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent)

Example 5 with EnvCreationFailureEvent

use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent in project cloudbreak by hortonworks.

the class EnvironmentInitHandler method goToFailedState.

private void goToFailedState(Event<EnvironmentDto> environmentDtoEvent, String message) {
    EnvironmentDto environmentDto = environmentDtoEvent.getData();
    EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(environmentDto.getId(), environmentDto.getName(), new BadRequestException(message), environmentDto.getResourceCrn());
    eventBus.notify(failureEvent.selector(), new Event<>(environmentDtoEvent.getHeaders(), failureEvent));
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) EnvCreationFailureEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent)

Aggregations

EnvCreationFailureEvent (com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent)19 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)14 EnvCreationEvent (com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent)12 CommonContext (com.sequenceiq.flow.core.CommonContext)7 Map (java.util.Map)7 Bean (org.springframework.context.annotation.Bean)7 Event (reactor.bus.Event)7 Environment (com.sequenceiq.environment.environment.domain.Environment)3 EnvironmentValidationDto (com.sequenceiq.environment.environment.dto.EnvironmentValidationDto)3 Test (org.junit.jupiter.api.Test)3 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)2 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)2 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)2 ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)1 NetworkTest (com.sequenceiq.environment.environment.service.network.NetworkTest)1 FreeIpaOperationFailedException (com.sequenceiq.environment.exception.FreeIpaOperationFailedException)1 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)1 AzureParametersDto (com.sequenceiq.environment.parameter.dto.AzureParametersDto)1 BadRequestException (javax.ws.rs.BadRequestException)1