Search in sources :

Example 6 with RetryableFreeIpaClientException

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));
}
Also used : RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Test(org.junit.jupiter.api.Test)

Example 7 with RetryableFreeIpaClientException

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));
}
Also used : RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) RoleRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest) Test(org.junit.jupiter.api.Test)

Example 8 with RetryableFreeIpaClientException

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;
}
Also used : RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) AddDnsZoneForSubnetsResponse(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneForSubnetsResponse) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) Retryable(org.springframework.retry.annotation.Retryable)

Example 9 with RetryableFreeIpaClientException

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);
    }
}
Also used : RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) KeytabCache(com.sequenceiq.freeipa.entity.KeytabCache) Keytab(com.sequenceiq.freeipa.client.model.Keytab) KeytabCreationException(com.sequenceiq.freeipa.kerberosmgmt.exception.KeytabCreationException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException)

Example 10 with RetryableFreeIpaClientException

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);
        }
    }
}
Also used : RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) KeytabCreationException(com.sequenceiq.freeipa.kerberosmgmt.exception.KeytabCreationException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) Host(com.sequenceiq.freeipa.client.model.Host)

Aggregations

FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)11 RetryableFreeIpaClientException (com.sequenceiq.freeipa.client.RetryableFreeIpaClientException)11 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)6 KeytabCreationException (com.sequenceiq.freeipa.kerberosmgmt.exception.KeytabCreationException)5 Test (org.junit.jupiter.api.Test)3 AddDnsZoneForSubnetsResponse (com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneForSubnetsResponse)2 Host (com.sequenceiq.freeipa.client.model.Host)2 Keytab (com.sequenceiq.freeipa.client.model.Keytab)2 Stack (com.sequenceiq.freeipa.entity.Stack)2 RequestListener (com.googlecode.jsonrpc4j.JsonRpcClient.RequestListener)1 ServiceFamilies (com.sequenceiq.cloudbreak.ccm.endpoint.ServiceFamilies)1 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)1 ClusterProxyConfiguration (com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyConfiguration)1 MDCBuilder (com.sequenceiq.cloudbreak.logger.MDCBuilder)1 Status (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.Status)1 RoleRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest)1 ClusterProxyErrorRpcListener (com.sequenceiq.freeipa.client.ClusterProxyErrorRpcListener)1 FreeIpaClientBuilder (com.sequenceiq.freeipa.client.FreeIpaClientBuilder)1 FreeIpaHostNotAvailableException (com.sequenceiq.freeipa.client.FreeIpaHostNotAvailableException)1 InvalidFreeIpaStateException (com.sequenceiq.freeipa.client.InvalidFreeIpaStateException)1