use of com.sequenceiq.freeipa.api.v1.dns.model.AddDnsCnameRecordRequest in project cloudbreak by hortonworks.
the class FreeIPAEndpointManagementService method sendAddDnsCnameRecordRequest.
private void sendAddDnsCnameRecordRequest(Stack stack, LoadBalancer loadBalancer) {
String targetFQDN = StringUtils.appendIfMissing(loadBalancer.getDns(), DOMAIN_PART_DELIMITER);
String endpoint = loadBalancer.getEndpoint();
AddDnsCnameRecordRequest request = new AddDnsCnameRecordRequest();
request.setCname(endpoint);
request.setTargetFqdn(targetFQDN);
request.setEnvironmentCrn(stack.getEnvironmentCrn());
LOGGER.debug("Registering load balancer with target FQDN {} in FreeIPA with CNAME {}", targetFQDN, endpoint);
String accountId = ThreadBasedUserCrnProvider.getAccountId();
ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> dnsV1Endpoint.addDnsCnameRecordInternal(accountId, request));
}
use of com.sequenceiq.freeipa.api.v1.dns.model.AddDnsCnameRecordRequest in project cloudbreak by hortonworks.
the class DnsRecordServiceTest method testCnameRecordAddDifferentDomainMissing.
@Test
public void testCnameRecordAddDifferentDomainMissing() throws FreeIpaClientException {
AddDnsCnameRecordRequest request = new AddDnsCnameRecordRequest();
request.setEnvironmentCrn(ENV_CRN);
request.setCname("Asdf");
request.setTargetFqdn(TARGET_FQDN);
request.setDnsZone(DOMAIN2);
Stack stack = createStack();
when(stackService.getByEnvironmentCrnAndAccountId(ENV_CRN, ACCOUNT_ID)).thenReturn(stack);
FreeIpa freeIpa = createFreeIpa();
when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
when(freeIpaClientFactory.getFreeIpaClientForStack(stack)).thenReturn(freeIpaClient);
when(freeIpaClient.findAllDnsZone()).thenReturn(createDnsZones(DOMAIN));
Assertions.assertThrows(BadRequestException.class, () -> underTest.addDnsCnameRecord(ACCOUNT_ID, request), String.format("Zone [%s] doesn't exists", DOMAIN2));
}
use of com.sequenceiq.freeipa.api.v1.dns.model.AddDnsCnameRecordRequest in project cloudbreak by hortonworks.
the class DnsRecordServiceTest method testCnameRecordAdd.
@Test
public void testCnameRecordAdd() throws FreeIpaClientException {
AddDnsCnameRecordRequest request = new AddDnsCnameRecordRequest();
request.setEnvironmentCrn(ENV_CRN);
request.setCname("Asdf");
request.setTargetFqdn(TARGET_FQDN);
Stack stack = createStack();
when(stackService.getByEnvironmentCrnAndAccountId(ENV_CRN, ACCOUNT_ID)).thenReturn(stack);
FreeIpa freeIpa = createFreeIpa();
when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
when(freeIpaClientFactory.getFreeIpaClientForStack(stack)).thenReturn(freeIpaClient);
underTest.addDnsCnameRecord(ACCOUNT_ID, request);
verify(freeIpaClient).addDnsCnameRecord(DOMAIN, request.getCname(), request.getTargetFqdn());
}
use of com.sequenceiq.freeipa.api.v1.dns.model.AddDnsCnameRecordRequest in project cloudbreak by hortonworks.
the class DnsRecordServiceTest method testCnameRecordAddNotFound.
@Test
public void testCnameRecordAddNotFound() throws FreeIpaClientException {
AddDnsCnameRecordRequest request = new AddDnsCnameRecordRequest();
request.setEnvironmentCrn(ENV_CRN);
request.setCname("Asdf");
request.setTargetFqdn(TARGET_FQDN);
Stack stack = createStack();
when(stackService.getByEnvironmentCrnAndAccountId(ENV_CRN, ACCOUNT_ID)).thenReturn(stack);
FreeIpa freeIpa = createFreeIpa();
when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
when(freeIpaClientFactory.getFreeIpaClientForStack(stack)).thenReturn(freeIpaClient);
when(freeIpaClient.showDnsRecord(DOMAIN, request.getCname())).thenThrow(new FreeIpaClientException("Not found", new JsonRpcClientException(FreeIpaErrorCodes.NOT_FOUND.getValue(), "Not found", null)));
underTest.addDnsCnameRecord(ACCOUNT_ID, request);
verify(freeIpaClient).addDnsCnameRecord(DOMAIN, request.getCname(), request.getTargetFqdn());
}
use of com.sequenceiq.freeipa.api.v1.dns.model.AddDnsCnameRecordRequest in project cloudbreak by hortonworks.
the class DnsRecordServiceTest method testCnameRecordAddEmptyModListIgnored.
@Test
public void testCnameRecordAddEmptyModListIgnored() throws FreeIpaClientException {
AddDnsCnameRecordRequest request = new AddDnsCnameRecordRequest();
request.setEnvironmentCrn(ENV_CRN);
request.setCname("Asdf");
request.setTargetFqdn(TARGET_FQDN);
Stack stack = createStack();
when(stackService.getByEnvironmentCrnAndAccountId(ENV_CRN, ACCOUNT_ID)).thenReturn(stack);
FreeIpa freeIpa = createFreeIpa();
when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
when(freeIpaClientFactory.getFreeIpaClientForStack(stack)).thenReturn(freeIpaClient);
JsonRpcClientException noModEx = new JsonRpcClientException(FreeIpaErrorCodes.EMPTY_MODLIST.getValue(), "no modifications to be performed", null);
when(freeIpaClient.addDnsCnameRecord(DOMAIN, request.getCname(), request.getTargetFqdn())).thenThrow(new FreeIpaClientException("can't create", noModEx));
underTest.addDnsCnameRecord(ACCOUNT_ID, request);
verify(freeIpaClient).addDnsCnameRecord(DOMAIN, request.getCname(), request.getTargetFqdn());
}
Aggregations