Search in sources :

Example 1 with RetryableFreeIpaClientException

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);
    }
}
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)

Example 2 with RetryableFreeIpaClientException

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);
    }
}
Also used : RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) 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 3 with RetryableFreeIpaClientException

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;
}
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) DnsZone(com.sequenceiq.freeipa.client.model.DnsZone) Stack(com.sequenceiq.freeipa.entity.Stack) Retryable(org.springframework.retry.annotation.Retryable)

Example 4 with RetryableFreeIpaClientException

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);
    }
}
Also used : Status(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.Status) HttpStatus(org.springframework.http.HttpStatus) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) FreeIpaDomainUtils(com.sequenceiq.freeipa.service.config.FreeIpaDomainUtils) FreeIpaClientBuilder(com.sequenceiq.freeipa.client.FreeIpaClientBuilder) LoggerFactory(org.slf4j.LoggerFactory) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) ClusterProxyConfiguration(com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyConfiguration) Inject(javax.inject.Inject) RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) Service(org.springframework.stereotype.Service) Map(java.util.Map) FreeIpaHostNotAvailableException(com.sequenceiq.freeipa.client.FreeIpaHostNotAvailableException) StackService(com.sequenceiq.freeipa.service.stack.StackService) ServiceFamilies(com.sequenceiq.cloudbreak.ccm.endpoint.ServiceFamilies) Status(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.Status) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Tracer(io.opentracing.Tracer) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) ClusterProxyService(com.sequenceiq.freeipa.service.stack.ClusterProxyService) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) ClusterProxyServiceAvailabilityChecker(com.sequenceiq.freeipa.util.ClusterProxyServiceAvailabilityChecker) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) Collectors(java.util.stream.Collectors) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) ClusterProxyErrorRpcListener(com.sequenceiq.freeipa.client.ClusterProxyErrorRpcListener) Optional(java.util.Optional) TlsSecurityService(com.sequenceiq.freeipa.service.TlsSecurityService) InvalidFreeIpaStateException(com.sequenceiq.freeipa.client.InvalidFreeIpaStateException) RequestListener(com.googlecode.jsonrpc4j.JsonRpcClient.RequestListener) RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) FreeIpaHostNotAvailableException(com.sequenceiq.freeipa.client.FreeIpaHostNotAvailableException) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) FreeIpaHostNotAvailableException(com.sequenceiq.freeipa.client.FreeIpaHostNotAvailableException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) InvalidFreeIpaStateException(com.sequenceiq.freeipa.client.InvalidFreeIpaStateException)

Example 5 with RetryableFreeIpaClientException

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);
}
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)

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