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);
}
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());
}
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);
}
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());
}
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));
}
}
Aggregations