use of com.sequenceiq.freeipa.client.RetryableFreeIpaClientException in project cloudbreak by hortonworks.
the class KeytabCommonServiceTest method testGetExistingKeytabRetryableException.
@Test
public void testGetExistingKeytabRetryableException() throws FreeIpaClientException {
FreeIpaClient ipaClient = mock(FreeIpaClient.class);
when(keytabCacheService.findByEnvironmentCrnAndPrincipal(ENVIRONMENT_CRN, PRINCIPAL)).thenReturn(Optional.empty());
when(ipaClient.getExistingKeytab(PRINCIPAL)).thenThrow(new RetryableFreeIpaClientException("expected", new FreeIpaClientException("inner")));
assertThrows(RetryableFreeIpaClientException.class, () -> underTest.getExistingKeytab(ENVIRONMENT_CRN, PRINCIPAL, HOST, ipaClient));
}
use of com.sequenceiq.freeipa.client.RetryableFreeIpaClientException in project cloudbreak by hortonworks.
the class KeytabCommonServiceTest method testAddHostRetryableException.
@Test
public void testAddHostRetryableException() throws FreeIpaClientException {
FreeIpaClient ipaClient = mock(FreeIpaClient.class);
RoleRequest roleRequest = new RoleRequest();
when(ipaClient.showHost(HOST)).thenThrow(new RetryableFreeIpaClientException("expected", new FreeIpaClientException("inner")));
assertThrows(RetryableFreeIpaClientException.class, () -> underTest.addHost(HOST, roleRequest, ipaClient));
}
use of com.sequenceiq.freeipa.client.RetryableFreeIpaClientException 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;
}
use of com.sequenceiq.freeipa.client.RetryableFreeIpaClientException in project cloudbreak by hortonworks.
the class KeytabCommonService method getExistingKeytab.
public KeytabCache getExistingKeytab(String environmentCrn, String canonicalPrincipal, String hostName, FreeIpaClient ipaClient) throws FreeIpaClientException, KeytabCreationException {
try {
Optional<KeytabCache> keytabCache = keytabCacheService.findByEnvironmentCrnAndPrincipal(environmentCrn, canonicalPrincipal);
if (keytabCache.isPresent()) {
LOGGER.debug("Returning keytab from cache");
return keytabCache.get();
} else {
LOGGER.debug("Keytab is not found in cache, fetching existing from FreeIPA");
Keytab keytab = ipaClient.getExistingKeytab(canonicalPrincipal);
return keytabCacheService.saveOrUpdate(environmentCrn, canonicalPrincipal, hostName, keytab.getKeytab());
}
} catch (RetryableFreeIpaClientException e) {
LOGGER.error(KEYTAB_FETCH_FAILED + " " + e.getLocalizedMessage(), e);
throw new RetryableFreeIpaClientException(KEYTAB_FETCH_FAILED, e, new KeytabCreationException(KEYTAB_FETCH_FAILED));
} catch (FreeIpaClientException e) {
LOGGER.error(KEYTAB_FETCH_FAILED + " " + e.getLocalizedMessage(), e);
throw new KeytabCreationException(KEYTAB_FETCH_FAILED);
}
}
use of com.sequenceiq.freeipa.client.RetryableFreeIpaClientException in project cloudbreak by hortonworks.
the class KeytabCommonService method fetchOrCreateHost.
private Host fetchOrCreateHost(String hostname, FreeIpaClient ipaClient) throws FreeIpaClientException {
try {
Optional<Host> optionalHost = fetchHostIfExists(hostname, ipaClient);
LOGGER.debug("Fetch host: {}", optionalHost);
return optionalHost.isEmpty() ? ipaClient.addHost(hostname) : optionalHost.get();
} catch (RetryableFreeIpaClientException e) {
throw e;
} catch (FreeIpaClientException e) {
if (FreeIpaClientExceptionUtil.isDuplicateEntryException(e)) {
LOGGER.debug("Host [{}] was already created while trying to create it", hostname);
return ipaClient.showHost(hostname);
} else {
LOGGER.error(HOST_CREATION_FAILED + " " + e.getLocalizedMessage(), e);
throw new KeytabCreationException(HOST_CREATION_FAILED);
}
}
}
Aggregations