Search in sources :

Example 1 with EnvironmentStartDto

use of com.sequenceiq.environment.environment.dto.EnvironmentStartDto in project cloudbreak by hortonworks.

the class StartFreeIpaHandlerTest method shouldStopFreeipaButStatusIsNull.

@Test
public void shouldStopFreeipaButStatusIsNull() {
    String envCrn = "someCrnValue";
    EnvironmentDto environmentDto = createEnvironmentDto();
    environmentDto.setResourceCrn(envCrn);
    Event<EnvironmentStartDto> environmentDtoEvent = Event.wrap(mockEnvironmentDto);
    when(mockFreeIpaService.describe(envCrn)).thenReturn(Optional.of(mockDescribeFreeIpaResponse));
    underTest.accept(environmentDtoEvent);
    verifyEnvStartFailedEvent(environmentDtoEvent, "FreeIPA status is unpredictable, env start will be interrupted.");
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvironmentStartDto(com.sequenceiq.environment.environment.dto.EnvironmentStartDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with EnvironmentStartDto

use of com.sequenceiq.environment.environment.dto.EnvironmentStartDto in project cloudbreak by hortonworks.

the class StartFreeIpaHandlerTest method shouldThrowErrorWhenUnstartable.

@ParameterizedTest
@EnumSource(value = DetailedStackStatus.class, names = { "STOPPED", "STOP_FAILED", "START_FAILED", "START_IN_PROGRESS" }, mode = EnumSource.Mode.EXCLUDE)
public void shouldThrowErrorWhenUnstartable(DetailedStackStatus detailedStackStatus) {
    if (!detailedStackStatus.getAvailabilityStatus().isAvailable()) {
        String envCrn = "someCrnValue";
        EnvironmentDto environmentDto = createEnvironmentDto();
        environmentDto.setResourceCrn(envCrn);
        Event<EnvironmentStartDto> environmentDtoEvent = Event.wrap(mockEnvironmentDto);
        when(mockDescribeFreeIpaResponse.getAvailabilityStatus()).thenReturn(detailedStackStatus.getAvailabilityStatus());
        when(mockDescribeFreeIpaResponse.getStatus()).thenReturn(detailedStackStatus.getStatus());
        when(mockFreeIpaService.describe(envCrn)).thenReturn(Optional.of(mockDescribeFreeIpaResponse));
        underTest.accept(environmentDtoEvent);
        verifyEnvStartFailedEvent(environmentDtoEvent, "FreeIPA is not in a valid state to start! Current state is: " + detailedStackStatus.getStatus());
    }
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvironmentStartDto(com.sequenceiq.environment.environment.dto.EnvironmentStartDto) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with EnvironmentStartDto

use of com.sequenceiq.environment.environment.dto.EnvironmentStartDto in project cloudbreak by hortonworks.

the class EnvStartActions method startFreeipa.

@Bean(name = "START_FREEIPA_STATE")
public Action<?, ?> startFreeipa() {
    return new AbstractEnvStartAction<>(EnvStartEvent.class) {

        @Override
        protected void doExecute(CommonContext context, EnvStartEvent payload, Map<Object, Object> variables) {
            EnvironmentStatus environmentStatus = EnvironmentStatus.START_FREEIPA_STARTED;
            ResourceEvent resourceEvent = ResourceEvent.ENVIRONMENT_START_FREEIPA_STARTED;
            EnvStartState envStartState = EnvStartState.START_FREEIPA_STATE;
            EnvironmentDto envDto = environmentStatusUpdateService.updateEnvironmentStatusAndNotify(context, payload, environmentStatus, resourceEvent, envStartState);
            EnvironmentStartDto environmentStartDto = EnvironmentStartDto.builder().withDataHubStart(payload.getDataHubStartAction()).withEnvironmentDto(envDto).withId(envDto.getId()).build();
            sendEvent(context, EnvStartHandlerSelectors.START_FREEIPA_HANDLER_EVENT.selector(), environmentStartDto);
        }
    };
}
Also used : EnvironmentStatus(com.sequenceiq.environment.environment.EnvironmentStatus) EnvStartEvent(com.sequenceiq.environment.environment.flow.start.event.EnvStartEvent) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Map(java.util.Map) EnvironmentStartDto(com.sequenceiq.environment.environment.dto.EnvironmentStartDto) Bean(org.springframework.context.annotation.Bean)

Example 4 with EnvironmentStartDto

use of com.sequenceiq.environment.environment.dto.EnvironmentStartDto in project cloudbreak by hortonworks.

the class StartFreeIpaHandlerTest method shouldSkipStartFreeipaInstanceWhenStatusAvaialbleOrStartInProgress.

@ParameterizedTest
@EnumSource(value = DetailedStackStatus.class, names = { "PROVISIONED", "START_IN_PROGRESS" })
public void shouldSkipStartFreeipaInstanceWhenStatusAvaialbleOrStartInProgress(DetailedStackStatus detailedStackStatus) {
    String envCrn = "someCrnValue";
    EnvironmentDto environmentDto = createEnvironmentDto();
    environmentDto.setResourceCrn(envCrn);
    Event<EnvironmentStartDto> environmentDtoEvent = Event.wrap(mockEnvironmentDto);
    when(mockDescribeFreeIpaResponse.getAvailabilityStatus()).thenReturn(detailedStackStatus.getAvailabilityStatus());
    when(mockDescribeFreeIpaResponse.getStatus()).thenReturn(detailedStackStatus.getStatus());
    when(mockFreeIpaService.describe(envCrn)).thenReturn(Optional.of(mockDescribeFreeIpaResponse));
    underTest.accept(environmentDtoEvent);
    verify(mockFreeIpaPollerService, never()).stopAttachedFreeipaInstances(environmentDto.getId(), envCrn);
    verifyEnvStartEvent(environmentDtoEvent);
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvironmentStartDto(com.sequenceiq.environment.environment.dto.EnvironmentStartDto) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with EnvironmentStartDto

use of com.sequenceiq.environment.environment.dto.EnvironmentStartDto in project cloudbreak by hortonworks.

the class EnvStartActions method synchronizeUsers.

@Bean(name = "SYNCHRONIZE_USERS_STATE")
public Action<?, ?> synchronizeUsers() {
    return new AbstractEnvStartAction<>(EnvStartEvent.class) {

        @Override
        protected void doExecute(CommonContext context, EnvStartEvent payload, Map<Object, Object> variables) {
            EnvironmentStatus environmentStatus = EnvironmentStatus.START_SYNCHRONIZE_USERS_STARTED;
            ResourceEvent resourceEvent = ResourceEvent.ENVIRONMENT_START_SYNCHRONIZE_USERS_STARTED;
            EnvStartState envStartState = EnvStartState.SYNCHRONIZE_USERS_STATE;
            EnvironmentDto envDto = environmentStatusUpdateService.updateEnvironmentStatusAndNotify(context, payload, environmentStatus, resourceEvent, envStartState);
            EnvironmentStartDto environmentStartDto = EnvironmentStartDto.builder().withDataHubStart(payload.getDataHubStartAction()).withEnvironmentDto(envDto).withId(envDto.getId()).build();
            sendEvent(context, EnvStartHandlerSelectors.SYNCHRONIZE_USERS_HANDLER_EVENT.selector(), environmentStartDto);
        }
    };
}
Also used : EnvironmentStatus(com.sequenceiq.environment.environment.EnvironmentStatus) EnvStartEvent(com.sequenceiq.environment.environment.flow.start.event.EnvStartEvent) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Map(java.util.Map) EnvironmentStartDto(com.sequenceiq.environment.environment.dto.EnvironmentStartDto) Bean(org.springframework.context.annotation.Bean)

Aggregations

EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)7 EnvironmentStartDto (com.sequenceiq.environment.environment.dto.EnvironmentStartDto)7 ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)4 EnvironmentStatus (com.sequenceiq.environment.environment.EnvironmentStatus)4 EnvStartEvent (com.sequenceiq.environment.environment.flow.start.event.EnvStartEvent)4 CommonContext (com.sequenceiq.flow.core.CommonContext)4 Map (java.util.Map)4 Bean (org.springframework.context.annotation.Bean)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 EnumSource (org.junit.jupiter.params.provider.EnumSource)2 Test (org.junit.jupiter.api.Test)1