use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.detachchildenv.DetachChildEnvironmentRequest in project cloudbreak by hortonworks.
the class FreeIpaDeletionHandlerTest method shouldDetachChildEnvironmentIfParentExists.
@Test
public void shouldDetachChildEnvironmentIfParentExists() throws Exception {
EnvironmentDto environmentDto = new EnvironmentDto();
environmentDto.setId(CHILD_ENVIRONMENT_ID);
EnvironmentDeletionDto environmentDeletionDto = EnvironmentDeletionDto.builder().withEnvironmentDto(environmentDto).withForceDelete(true).withId(CHILD_ENVIRONMENT_ID).build();
when(environmentService.findEnvironmentById(CHILD_ENVIRONMENT_ID)).thenReturn(of(anEnvironmentWithParent(CHILD_ENVIRONMENT_ID)));
when(freeIpaService.describe(ENVIRONMENT_CRN)).thenReturn(of(new DescribeFreeIpaResponse()));
victim.accept(new Event<>(environmentDeletionDto));
ArgumentCaptor<DetachChildEnvironmentRequest> detachChildEnvironmentRequestArgumentCaptor = ArgumentCaptor.forClass(DetachChildEnvironmentRequest.class);
verify(freeIpaService).detachChildEnvironment(detachChildEnvironmentRequestArgumentCaptor.capture());
verifyNoMoreInteractions(freeIpaService);
verify(eventSender).sendEvent(any(BaseNamedFlowEvent.class), any(Event.Headers.class));
verify(dnsV1Endpoint).deleteDnsZoneBySubnet(eq(PARENT_ENVIRONMENT_CRN), any());
assertEquals(PARENT_ENVIRONMENT_CRN, detachChildEnvironmentRequestArgumentCaptor.getValue().getParentEnvironmentCrn());
assertEquals(ENVIRONMENT_CRN, detachChildEnvironmentRequestArgumentCaptor.getValue().getChildEnvironmentCrn());
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.detachchildenv.DetachChildEnvironmentRequest in project cloudbreak by hortonworks.
the class FreeIpaDetachChildEnvironmentAction method convertRequest.
private DetachChildEnvironmentRequest convertRequest(AttachChildEnvironmentRequest attachChildEnvironmentRequest) {
DetachChildEnvironmentRequest detachChildEnvironmentRequest = new DetachChildEnvironmentRequest();
detachChildEnvironmentRequest.setParentEnvironmentCrn(attachChildEnvironmentRequest.getParentEnvironmentCrn());
detachChildEnvironmentRequest.setChildEnvironmentCrn(attachChildEnvironmentRequest.getChildEnvironmentCrn());
return detachChildEnvironmentRequest;
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.detachchildenv.DetachChildEnvironmentRequest in project cloudbreak by hortonworks.
the class ChildEnvironmentServiceTest method detachChildEnvironmentFailure.
@Test
void detachChildEnvironmentFailure() {
when(repository.findByParentAndChildEnvironmentCrns(ENVIRONMENT_CRN, CHILD_ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(Optional.empty());
DetachChildEnvironmentRequest request = new DetachChildEnvironmentRequest();
request.setParentEnvironmentCrn(ENVIRONMENT_CRN);
request.setChildEnvironmentCrn(CHILD_ENVIRONMENT_CRN);
Assertions.assertThatThrownBy(() -> underTest.detachChildEnvironment(request, ACCOUNT_ID)).isInstanceOf(NotFoundException.class);
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.detachchildenv.DetachChildEnvironmentRequest in project cloudbreak by hortonworks.
the class ChildEnvironmentServiceTest method detachChildEnvironmentOptimisticLockingFailure.
@Test
void detachChildEnvironmentOptimisticLockingFailure() {
ChildEnvironment childEnvironment = new ChildEnvironment();
childEnvironment.setEnvironmentCrn(CHILD_ENVIRONMENT_CRN);
when(repository.findByParentAndChildEnvironmentCrns(ENVIRONMENT_CRN, CHILD_ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(Optional.of(childEnvironment));
doThrow(ObjectOptimisticLockingFailureException.class).when(repository).delete(childEnvironment);
DetachChildEnvironmentRequest request = new DetachChildEnvironmentRequest();
request.setParentEnvironmentCrn(ENVIRONMENT_CRN);
request.setChildEnvironmentCrn(CHILD_ENVIRONMENT_CRN);
Assertions.assertThatThrownBy(() -> underTest.detachChildEnvironment(request, ACCOUNT_ID)).isInstanceOf(NotFoundException.class).hasMessage("Child env %s is already detached", CHILD_ENVIRONMENT_CRN);
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.detachchildenv.DetachChildEnvironmentRequest in project cloudbreak by hortonworks.
the class FreeIpaDeletionHandler method detachChildEnvironmentFromFreeIpa.
private void detachChildEnvironmentFromFreeIpa(Environment environment) {
try {
DetachChildEnvironmentRequest detachChildEnvironmentRequest = new DetachChildEnvironmentRequest();
detachChildEnvironmentRequest.setParentEnvironmentCrn(environment.getParentEnvironment().getResourceCrn());
detachChildEnvironmentRequest.setChildEnvironmentCrn(environment.getResourceCrn());
freeIpaService.detachChildEnvironment(detachChildEnvironmentRequest);
if (lastChildEnvironmentInNetworkIsGettingDeleted(environment)) {
try {
dnsV1Endpoint.deleteDnsZoneBySubnet(environment.getParentEnvironment().getResourceCrn(), environment.getNetwork().getNetworkCidr());
} catch (Exception e) {
LOGGER.warn("Failed to delete dns zone of child environment.", e);
}
}
} catch (FreeIpaOperationFailedException e) {
if (e.getCause() instanceof NotFoundException) {
LOGGER.warn("Child FreeIpa is already detached.", e);
} else {
throw e;
}
}
}
Aggregations