use of com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneForSubnetsRequest in project cloudbreak by hortonworks.
the class FreeIpaUpgradeTests method addListDeleteDnsZonesBySubnet.
private void addListDeleteDnsZonesBySubnet(com.sequenceiq.freeipa.api.client.FreeIpaClient ipaClient, String environmentCrn) {
try {
AddDnsZoneForSubnetsRequest request = new AddDnsZoneForSubnetsRequest();
request.setSubnets(List.of("10.0.1.0/24", "192.168.1.0/24"));
request.setEnvironmentCrn(environmentCrn);
ipaClient.getDnsV1Endpoint().addDnsZoneForSubnets(request);
/* Until CB-15454 is fixed
Set<String> dnsZones = ipaClient.getDnsV1Endpoint().listDnsZones(environmentCrn);
Assertions.assertTrue(dnsZones.stream().anyMatch(dnsZone -> dnsZone.startsWith("1.0.10")));
Assertions.assertTrue(dnsZones.stream().anyMatch(dnsZone -> dnsZone.startsWith("1.168.192")));*/
ipaClient.getDnsV1Endpoint().deleteDnsZoneBySubnet(environmentCrn, "192.168.1.0/24");
ipaClient.getDnsV1Endpoint().deleteDnsZoneBySubnet(environmentCrn, "10.0.1.0/24");
/* dnsZones = ipaClient.getDnsV1Endpoint().listDnsZones(environmentCrn);
Assertions.assertFalse(dnsZones.stream().anyMatch(dnsZone -> dnsZone.startsWith("1.0.10")));
Assertions.assertFalse(dnsZones.stream().anyMatch(dnsZone -> dnsZone.startsWith("1.168.192")));*/
} catch (Exception e) {
logger.error("DNS ZONE test failed during upgrade", e);
throw new TestFailException("DNS ZONE test failed during upgrade with: " + e.getMessage(), e);
}
}
use of com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneForSubnetsRequest in project cloudbreak by hortonworks.
the class FreeIpaCreationHandlerTest method shouldAttachFreeIpaInCaseOfChildEnvironment.
@Test
public void shouldAttachFreeIpaInCaseOfChildEnvironment() throws Exception {
DescribeFreeIpaResponse describeFreeIpaResponse = mock(DescribeFreeIpaResponse.class);
EnvironmentDto environmentDto = aYarnEnvironmentDtoWithParentEnvironment();
Environment environment = anEnvironmentWithParent();
ArgumentCaptor<AddDnsZoneForSubnetsRequest> addDnsZoneForSubnetsRequestArgumentCaptor = ArgumentCaptor.forClass(AddDnsZoneForSubnetsRequest.class);
when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(environment));
when(freeIpaService.describe(PARENT_ENVIRONMENT_CRN)).thenReturn(Optional.of(describeFreeIpaResponse));
victim.accept(new Event<>(environmentDto));
ArgumentCaptor<AttachChildEnvironmentRequest> attachChildEnvironmentRequestArgumentCaptor = ArgumentCaptor.forClass(AttachChildEnvironmentRequest.class);
verify(dnsV1Endpoint).addDnsZoneForSubnets(addDnsZoneForSubnetsRequestArgumentCaptor.capture());
verify(freeIpaService).attachChildEnvironment(attachChildEnvironmentRequestArgumentCaptor.capture());
verify(eventSender).sendEvent(any(BaseNamedFlowEvent.class), any(Headers.class));
assertEquals(PARENT_ENVIRONMENT_CRN, addDnsZoneForSubnetsRequestArgumentCaptor.getValue().getEnvironmentCrn());
assertEquals(Collections.singletonList(YARN_NETWORK_CIDR), addDnsZoneForSubnetsRequestArgumentCaptor.getValue().getSubnets());
assertEquals(ENVIRONMENT_CRN, attachChildEnvironmentRequestArgumentCaptor.getValue().getChildEnvironmentCrn());
assertEquals(PARENT_ENVIRONMENT_CRN, attachChildEnvironmentRequestArgumentCaptor.getValue().getParentEnvironmentCrn());
}
use of com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneForSubnetsRequest in project cloudbreak by hortonworks.
the class FreeIpaCreationHandler method attachParentFreeIpa.
private void attachParentFreeIpa(EnvironmentDto environmentDto) throws Exception {
if (enabledChildPlatforms.stream().anyMatch(p -> p.equalsIgnoreCase(environmentDto.getCloudPlatform()))) {
String parentEnvironmentCrn = environmentDto.getParentEnvironmentCrn();
Optional<DescribeFreeIpaResponse> freeIpa = freeIpaService.describe(parentEnvironmentCrn);
if (freeIpa.isPresent()) {
LOGGER.info("Using FreeIpa of parent environment '{}' .", parentEnvironmentCrn);
AttachChildEnvironmentRequest attachChildEnvironmentRequest = new AttachChildEnvironmentRequest();
attachChildEnvironmentRequest.setChildEnvironmentCrn(environmentDto.getResourceCrn());
attachChildEnvironmentRequest.setParentEnvironmentCrn(parentEnvironmentCrn);
freeIpaService.attachChildEnvironment(attachChildEnvironmentRequest);
AddDnsZoneForSubnetsRequest addDnsZoneForSubnetsRequest = new AddDnsZoneForSubnetsRequest();
addDnsZoneForSubnetsRequest.setEnvironmentCrn(parentEnvironmentCrn);
addDnsZoneForSubnetsRequest.setSubnets(getSubnetCidrs(environmentDto));
dnsV1Endpoint.addDnsZoneForSubnets(addDnsZoneForSubnetsRequest);
}
}
}
use of com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneForSubnetsRequest in project cloudbreak by hortonworks.
the class DnsZoneService method addDnsZonesForSubnets.
@Retryable(value = RetryableFreeIpaClientException.class, maxAttemptsExpression = RetryableFreeIpaClientException.MAX_RETRIES_EXPRESSION, backoff = @Backoff(delayExpression = RetryableFreeIpaClientException.DELAY_EXPRESSION, multiplierExpression = RetryableFreeIpaClientException.MULTIPLIER_EXPRESSION))
public AddDnsZoneForSubnetsResponse addDnsZonesForSubnets(AddDnsZoneForSubnetsRequest request, String accountId) throws FreeIpaClientException {
FreeIpaClient client = getFreeIpaClient(request.getEnvironmentCrn(), accountId);
AddDnsZoneForSubnetsResponse response = new AddDnsZoneForSubnetsResponse();
for (String subnet : request.getSubnets()) {
try {
LOGGER.info("Add subnet's [{}] reverse DNS zone", subnet);
client.addReverseDnsZone(subnet);
response.getSuccess().add(subnet);
LOGGER.debug("Subnet [{}] added", subnet);
} catch (RetryableFreeIpaClientException e) {
throw e;
} catch (FreeIpaClientException e) {
LOGGER.warn("Can't add subnet's [{}] reverse DNS zone", subnet, e);
response.getFailed().put(subnet, e.getMessage());
}
}
return response;
}
Aggregations