Search in sources :

Example 1 with DeleteException

use of com.sequenceiq.freeipa.kerberosmgmt.exception.DeleteException in project cloudbreak by hortonworks.

the class KeytabCleanupService method cleanupByEnvironment.

public void cleanupByEnvironment(String environmentCrn, String accountId) throws DeleteException {
    LOGGER.debug("Request to cleanup vault for an environment for account {}: {}", accountId, environmentCrn);
    try {
        MDCBuilder.addEnvCrn(environmentCrn);
        MDCBuilder.addAccountId(accountId);
        vaultComponent.cleanupSecrets(environmentCrn, null, accountId);
        keytabCacheService.deleteByEnvironmentCrn(environmentCrn);
    } catch (Exception e) {
        LOGGER.error("Cleanup cluster failed " + e.getLocalizedMessage(), e);
        throw new DeleteException("Failed to cleanup " + e.getLocalizedMessage());
    }
}
Also used : DeleteException(com.sequenceiq.freeipa.kerberosmgmt.exception.DeleteException) DeleteException(com.sequenceiq.freeipa.kerberosmgmt.exception.DeleteException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException)

Example 2 with DeleteException

use of com.sequenceiq.freeipa.kerberosmgmt.exception.DeleteException in project cloudbreak by hortonworks.

the class CleanupService method removeVaultEntries.

@Retryable(value = RetryableFreeIpaClientException.class, maxAttemptsExpression = RetryableFreeIpaClientException.MAX_RETRIES_EXPRESSION, backoff = @Backoff(delayExpression = RetryableFreeIpaClientException.DELAY_EXPRESSION, multiplierExpression = RetryableFreeIpaClientException.MULTIPLIER_EXPRESSION))
public Pair<Set<String>, Map<String, String>> removeVaultEntries(Long stackId, Set<String> hosts) throws FreeIpaClientException {
    Set<String> vaultCleanupSuccess = new HashSet<>();
    Map<String, String> vaultCleanupFailed = new HashMap<>();
    Stack stack = stackService.getStackById(stackId);
    FreeIpaClient freeIpaClient = getFreeIpaClient(stackId);
    for (String host : hosts) {
        try {
            HostRequest hostRequest = new HostRequest();
            hostRequest.setEnvironmentCrn(stack.getEnvironmentCrn());
            hostRequest.setServerHostName(host);
            keytabCleanupService.removeHostRelatedKerberosConfiguration(hostRequest, stack.getAccountId(), freeIpaClient);
            vaultCleanupSuccess.add(host);
        } catch (DeleteException | FreeIpaClientException e) {
            LOGGER.info("Vault secret cleanup failed for host: {}", host, e);
            vaultCleanupFailed.put(host, e.getMessage());
        }
    }
    return Pair.of(vaultCleanupSuccess, vaultCleanupFailed);
}
Also used : HashMap(java.util.HashMap) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) DeleteException(com.sequenceiq.freeipa.kerberosmgmt.exception.DeleteException) RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) HashSet(java.util.HashSet) Stack(com.sequenceiq.freeipa.entity.Stack) HostRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostRequest) Retryable(org.springframework.retry.annotation.Retryable)

Example 3 with DeleteException

use of com.sequenceiq.freeipa.kerberosmgmt.exception.DeleteException in project cloudbreak by hortonworks.

the class KeytabCleanupService method cleanupByCluster.

public void cleanupByCluster(VaultCleanupRequest request, String accountId) throws DeleteException {
    LOGGER.debug("Request to cleanup vault for a cluster for account {}: {}", accountId, request);
    try {
        MDCBuilder.addEnvCrn(request.getEnvironmentCrn());
        MDCBuilder.addAccountId(accountId);
        if (Strings.isNullOrEmpty(request.getClusterCrn())) {
            LOGGER.error("Cluster CRN not provided. Vault is not cleaned-up");
            throw new DeleteException("Cluster CRN is required");
        } else {
            MDCBuilder.addResourceCrn(request.getClusterCrn());
            vaultComponent.cleanupSecrets(request.getEnvironmentCrn(), request.getClusterCrn(), accountId);
        }
    } catch (DeleteException e) {
        throw e;
    } catch (Exception e) {
        LOGGER.error("Cleanup cluster failed " + e.getLocalizedMessage(), e);
        throw new DeleteException("Failed to cleanup " + e.getLocalizedMessage());
    }
}
Also used : DeleteException(com.sequenceiq.freeipa.kerberosmgmt.exception.DeleteException) DeleteException(com.sequenceiq.freeipa.kerberosmgmt.exception.DeleteException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException)

Aggregations

FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)3 RetryableFreeIpaClientException (com.sequenceiq.freeipa.client.RetryableFreeIpaClientException)3 DeleteException (com.sequenceiq.freeipa.kerberosmgmt.exception.DeleteException)3 HostRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostRequest)1 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)1 Stack (com.sequenceiq.freeipa.entity.Stack)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Retryable (org.springframework.retry.annotation.Retryable)1