Search in sources :

Example 41 with DescribeFreeIpaResponse

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse in project cloudbreak by hortonworks.

the class FreeIpaDeletionHandlerTest method shouldDeleteFreeIpaIfParentDoesNotExist.

@Test
public void shouldDeleteFreeIpaIfParentDoesNotExist() {
    EnvironmentDto environmentDto = new EnvironmentDto();
    environmentDto.setId(CHILD_ENVIRONMENT_ID);
    EnvironmentDeletionDto environmentDeletionDto = EnvironmentDeletionDto.builder().withEnvironmentDto(environmentDto).withForceDelete(true).withId(CHILD_ENVIRONMENT_ID).build();
    ExtendedPollingResult extendedPollingResult = new ExtendedPollingResult.ExtendedPollingResultBuilder().success().build();
    when(environmentService.findEnvironmentById(CHILD_ENVIRONMENT_ID)).thenReturn(of(anEnvironmentWithoutParent(Boolean.TRUE)));
    when(freeIpaService.describe(ENVIRONMENT_CRN)).thenReturn(of(new DescribeFreeIpaResponse()));
    when(freeIpaPollingService.pollWithTimeout(any(), any(), Mockito.eq(FreeIpaDeletionRetrievalTask.FREEIPA_RETRYING_INTERVAL), Mockito.eq(FreeIpaDeletionRetrievalTask.FREEIPA_RETRYING_COUNT), Mockito.eq(1))).thenReturn(extendedPollingResult);
    victim.accept(new Event<>(environmentDeletionDto));
    verify(freeIpaService).delete(ENVIRONMENT_CRN, true);
    verify(eventSender).sendEvent(any(BaseNamedFlowEvent.class), any(Event.Headers.class));
    verifyNoMoreInteractions(freeIpaService);
}
Also used : BaseNamedFlowEvent(com.sequenceiq.flow.reactor.api.event.BaseNamedFlowEvent) DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) EnvironmentDeletionDto(com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto) Test(org.junit.jupiter.api.Test)

Example 42 with DescribeFreeIpaResponse

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse in project cloudbreak by hortonworks.

the class FreeIpaDeletionHandlerTest method shouldNotDeleteDnsZoneWhenSiblingsExist.

@Test
public void shouldNotDeleteDnsZoneWhenSiblingsExist() throws Exception {
    EnvironmentDto environmentDto = new EnvironmentDto();
    environmentDto.setId(CHILD_ENVIRONMENT_ID);
    EnvironmentDeletionDto environmentDeletionDto = EnvironmentDeletionDto.builder().withEnvironmentDto(environmentDto).withForceDelete(true).withId(CHILD_ENVIRONMENT_ID).build();
    Environment environment = anEnvironmentWithParent(CHILD_ENVIRONMENT_ID);
    when(environmentService.findEnvironmentById(CHILD_ENVIRONMENT_ID)).thenReturn(of(environment));
    when(environmentService.findAllByAccountIdAndParentEnvIdAndArchivedIsFalse(anyString(), eq(PARENT_ENVIRONMENT_ID))).thenReturn(List.of(environment, anEnvironmentWithParent(ANOTHER_CHILD_ENVIRONMENT_ID)));
    when(freeIpaService.describe(ENVIRONMENT_CRN)).thenReturn(of(new DescribeFreeIpaResponse()));
    victim.accept(new Event<>(environmentDeletionDto));
    verify(dnsV1Endpoint, never()).deleteDnsZoneBySubnet(eq(PARENT_ENVIRONMENT_CRN), any());
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvironmentDeletionDto(com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto) Test(org.junit.jupiter.api.Test)

Example 43 with DescribeFreeIpaResponse

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse in project cloudbreak by hortonworks.

the class UpgradeCcmOnFreeIpaHandlerTest method testFreeIpaWrongStatuses.

@ParameterizedTest
@EnumSource(value = Status.class, names = { "AVAILABLE", "UPGRADE_CCM_FAILED" }, mode = EnumSource.Mode.EXCLUDE)
void testFreeIpaWrongStatuses(Status status) {
    DescribeFreeIpaResponse freeipa = new DescribeFreeIpaResponse();
    freeipa.setStatus(status);
    freeipa.setAvailabilityStatus(AvailabilityStatus.AVAILABLE);
    Optional<DescribeFreeIpaResponse> freeipaOpt = Optional.of(freeipa);
    when(freeIpaService.describe(any())).thenReturn(freeipaOpt);
    underTest.accept(mockEnvironmentDtoEvent);
    verify(freeIpaPollerService, never()).waitForCcmUpgrade(any(), any());
    UpgradeCcmFailedEvent capturedUpgradeCcmEvent = (UpgradeCcmFailedEvent) baseNamedFlowEvent.getValue();
    assertThat(capturedUpgradeCcmEvent.getResourceName()).isEqualTo(TEST_ENV_NAME);
    assertThat(capturedUpgradeCcmEvent.getResourceId()).isEqualTo(TEST_ENV_ID);
    assertThat(capturedUpgradeCcmEvent.getResourceCrn()).isEqualTo(TEST_ENV_CRN);
    assertThat(capturedUpgradeCcmEvent.selector()).isEqualTo("FAILED_UPGRADE_CCM_EVENT");
    assertThat(capturedUpgradeCcmEvent.getEnvironmentStatus()).isEqualTo(UPGRADE_CCM_ON_FREEIPA_FAILED);
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) UpgradeCcmFailedEvent(com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmFailedEvent) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 44 with DescribeFreeIpaResponse

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse in project cloudbreak by hortonworks.

the class FreeIpaPollerProviderTest method testStartPoller.

@ParameterizedTest
@MethodSource("freeIpaStartStatuses")
void testStartPoller(Status s1Status, AttemptState attemptState, String message) throws Exception {
    DescribeFreeIpaResponse stack1 = getDescribeFreeIpaResponse(s1Status, CRN);
    when(freeIpaService.describe(CRN)).thenReturn(Optional.ofNullable(stack1));
    AttemptResult<Void> result = underTest.startPoller(ENV_ID, CRN).process();
    Assertions.assertEquals(attemptState, result.getState());
    Assertions.assertEquals(message, result.getMessage());
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 45 with DescribeFreeIpaResponse

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse in project cloudbreak by hortonworks.

the class DistroXServiceTest method testWithValidEnvironmentNameValueButTheActualEnvIsNotAvailableBadRequestExceptionShouldCome.

@ParameterizedTest
@EnumSource(value = com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus.class)
@DisplayName("When request contains a valid environment name but that environment is not in the AVAILABLE state then BadRequestException should come")
void testWithValidEnvironmentNameValueButTheActualEnvIsNotAvailableBadRequestExceptionShouldCome(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus detailedStackStatus) {
    if (!detailedStackStatus.getAvailabilityStatus().isAvailable()) {
        String envName = "someAwesomeExistingButNotAvailableEnvironment";
        DistroXV1Request r = new DistroXV1Request();
        r.setEnvironmentName(envName);
        DetailedEnvironmentResponse envResponse = new DetailedEnvironmentResponse();
        envResponse.setCrn("crn");
        envResponse.setName(envName);
        DescribeFreeIpaResponse freeipa = new DescribeFreeIpaResponse();
        freeipa.setAvailabilityStatus(detailedStackStatus.getAvailabilityStatus());
        freeipa.setStatus(detailedStackStatus.getStatus());
        when(freeipaClientService.getByEnvironmentCrn("crn")).thenReturn(freeipa);
        when(environmentClientService.getByName(envName)).thenReturn(envResponse);
        BadRequestException err = assertThrows(BadRequestException.class, () -> underTest.post(r));
        assertEquals(String.format("If you want to provision a Data Hub then the FreeIPA instance must be running in the '%s' Environment.", envName), err.getMessage());
        verify(environmentClientService, calledOnce()).getByName(any());
        verify(environmentClientService, calledOnce()).getByName(eq(envName));
        verify(stackOperations, never()).post(any(), any(), any(), anyBoolean());
        verify(workspaceService, never()).getForCurrentUser();
        verify(stackRequestConverter, never()).convert(any(DistroXV1Request.class));
    }
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) DistroXV1Request(com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

DescribeFreeIpaResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse)60 Test (org.junit.jupiter.api.Test)32 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)17 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)8 EnumSource (org.junit.jupiter.params.provider.EnumSource)8 DistroXV1Request (com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request)7 InstanceGroupResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupResponse)7 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)6 AttemptResults (com.dyngr.core.AttemptResults)5 Stack (com.sequenceiq.freeipa.entity.Stack)5 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)4 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)3 EnvironmentDeletionDto (com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)3 FreeIpaOperationFailedException (com.sequenceiq.environment.exception.FreeIpaOperationFailedException)3 BaseNamedFlowEvent (com.sequenceiq.flow.reactor.api.event.BaseNamedFlowEvent)3 InstanceMetaDataResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceMetaDataResponse)3 CreateFreeIpaRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest)3 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)3 ImageEntity (com.sequenceiq.freeipa.entity.ImageEntity)3 Environment (com.sequenceiq.environment.environment.domain.Environment)2