use of com.sequenceiq.freeipa.client.RetryableFreeIpaClientException in project cloudbreak by hortonworks.
the class KeytabCommonService method addHost.
public Host addHost(String hostname, RoleRequest roleRequest, FreeIpaClient ipaClient) throws FreeIpaClientException, KeytabCreationException {
try {
Host host = fetchOrCreateHost(hostname, ipaClient);
allowHostKeytabRetrieval(hostname, ipaClient);
roleComponent.addRoleAndPrivileges(Optional.empty(), Optional.of(host), roleRequest, ipaClient);
return host;
} catch (RetryableFreeIpaClientException e) {
LOGGER.error(HOST_CREATION_FAILED + " " + e.getLocalizedMessage(), e);
throw new RetryableFreeIpaClientException(HOST_CREATION_FAILED, e, new KeytabCreationException(HOST_CREATION_FAILED));
} catch (FreeIpaClientException e) {
LOGGER.error(HOST_CREATION_FAILED + " " + e.getLocalizedMessage(), e);
throw new KeytabCreationException(HOST_CREATION_FAILED);
}
}
use of com.sequenceiq.freeipa.client.RetryableFreeIpaClientException in project cloudbreak by hortonworks.
the class KeytabCommonService method getKeytab.
public KeytabCache getKeytab(String environmentCrn, String canonicalPrincipal, String hostName, FreeIpaClient ipaClient) throws FreeIpaClientException, KeytabCreationException {
try {
LOGGER.debug("Fetching keytab from FreeIPA");
Keytab keytab = ipaClient.getKeytab(canonicalPrincipal);
return keytabCacheService.saveOrUpdate(environmentCrn, canonicalPrincipal, hostName, keytab.getKeytab());
} catch (RetryableFreeIpaClientException e) {
LOGGER.error(KEYTAB_GENERATION_FAILED + " " + e.getLocalizedMessage(), e);
throw new RetryableFreeIpaClientException(KEYTAB_GENERATION_FAILED, e, new KeytabCreationException(KEYTAB_GENERATION_FAILED));
} catch (FreeIpaClientException e) {
LOGGER.error(KEYTAB_GENERATION_FAILED + " " + e.getLocalizedMessage(), e);
throw new KeytabCreationException(KEYTAB_GENERATION_FAILED);
}
}
use of com.sequenceiq.freeipa.client.RetryableFreeIpaClientException in project cloudbreak by hortonworks.
the class DnsZoneService method addDnsZonesForSubnetIds.
@Retryable(value = RetryableFreeIpaClientException.class, maxAttemptsExpression = RetryableFreeIpaClientException.MAX_RETRIES_EXPRESSION, backoff = @Backoff(delayExpression = RetryableFreeIpaClientException.DELAY_EXPRESSION, multiplierExpression = RetryableFreeIpaClientException.MULTIPLIER_EXPRESSION))
public AddDnsZoneForSubnetsResponse addDnsZonesForSubnetIds(AddDnsZoneForSubnetIdsRequest request, String accountId) throws FreeIpaClientException {
Stack stack = stackService.getByEnvironmentCrnAndAccountId(request.getEnvironmentCrn(), accountId);
MDCBuilder.buildMdcContext(stack);
Multimap<String, String> subnetWithCidr = networkService.getFilteredSubnetWithCidr(request.getEnvironmentCrn(), stack, request.getAddDnsZoneNetwork().getNetworkId(), request.getAddDnsZoneNetwork().getSubnetIds());
FreeIpaClient client = freeIpaClientFactory.getFreeIpaClientForStack(stack);
AddDnsZoneForSubnetsResponse response = new AddDnsZoneForSubnetsResponse();
for (Entry<String, String> subnet : subnetWithCidr.entries()) {
try {
LOGGER.info("Add subnet's [{}] reverse DNS zone", subnet);
String subnetCidr = subnet.getValue();
Set<DnsZone> dnsZones = client.findDnsZone(subnetCidr);
if (dnsZones.isEmpty()) {
LOGGER.debug("Subnet reverse DNS zone does not exists [{}], add it now", subnet);
client.addReverseDnsZone(subnetCidr);
response.getSuccess().add(subnet.getKey());
LOGGER.debug("Subnet [{}] added", subnet);
}
} catch (RetryableFreeIpaClientException e) {
throw e;
} catch (FreeIpaClientException e) {
LOGGER.warn("Can't add subnet's [{}] reverse DNS zone with cidr [{}]", subnet, subnet.getValue(), e);
response.getFailed().putIfAbsent(subnet.getKey(), e.getMessage());
}
}
return response;
}
use of com.sequenceiq.freeipa.client.RetryableFreeIpaClientException in project cloudbreak by hortonworks.
the class FreeIpaClientFactory method getFreeIpaClient.
private FreeIpaClient getFreeIpaClient(Stack stack, boolean withPing, boolean forceCheckUnreachable, Optional<String> freeIpaFqdn) throws FreeIpaClientException {
stack = stackService.getByIdWithListsInTransaction(stack.getId());
Status stackStatus = stack.getStackStatus().getStatus();
if (forceCheckUnreachable || !stackStatus.isFreeIpaUnreachableStatus()) {
try {
Optional<FreeIpaClient> client = Optional.empty();
if (clusterProxyService.isCreateConfigForClusterProxy(stack)) {
return getFreeIpaClientBuilderForClusterProxy(stack, freeIpaFqdn).build(withPing);
} else {
List<InstanceMetaData> instanceMetaDatas = getPriorityOrderedFreeIpaInstances(stack, forceCheckUnreachable).stream().filter(instanceMetaData -> freeIpaFqdn.isEmpty() || freeIpaFqdn.get().equals(instanceMetaData.getDiscoveryFQDN())).collect(Collectors.toList());
for (Iterator<InstanceMetaData> instanceIterator = instanceMetaDatas.iterator(); instanceIterator.hasNext() && client.isEmpty(); ) {
InstanceMetaData instanceMetaData = instanceIterator.next();
client = getFreeIpaClientForDirectConnect(stack, instanceMetaData, withPing, !instanceIterator.hasNext());
}
}
return client.orElseThrow(() -> new FreeIpaHostNotAvailableException("No FreeIPA client was available"));
} catch (RetryableFreeIpaClientException e) {
throw createFreeIpaUnableToBuildClient(e);
} catch (Exception e) {
throw createFreeIpaUnableToBuildClient(e);
}
} else {
throw createFreeIpaStateIsInvalidException(stackStatus);
}
}
use of com.sequenceiq.freeipa.client.RetryableFreeIpaClientException in project cloudbreak by hortonworks.
the class KeytabCommonServiceTest method testGetKeytabRetryable.
@Test
public void testGetKeytabRetryable() throws FreeIpaClientException {
FreeIpaClient ipaClient = mock(FreeIpaClient.class);
when(ipaClient.getKeytab(PRINCIPAL)).thenThrow(new RetryableFreeIpaClientException("expected", new FreeIpaClientException("inner")));
assertThrows(RetryableFreeIpaClientException.class, () -> underTest.getKeytab(ENVIRONMENT_CRN, PRINCIPAL, HOST, ipaClient));
verifyNoInteractions(keytabCacheService);
}
Aggregations