Search in sources :

Example 1 with HostRequest

use of com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostRequest in project cloudbreak by hortonworks.

the class KeytabCleanupServiceTest method testDeleteHost.

@Test
public void testDeleteHost() throws Exception {
    Set<Service> services = new HashSet<>();
    services.add(service);
    FreeIpaClient mockIpaClient = Mockito.mock(FreeIpaClient.class);
    HostRequest request = new HostRequest();
    request.setEnvironmentCrn(ENVIRONMENT_ID);
    request.setServerHostName(HOST);
    request.setClusterCrn(CLUSTER_ID);
    request.setRoleName(ROLE);
    when(freeIpaClientFactory.getFreeIpaClientByAccountAndEnvironment(anyString(), anyString())).thenReturn(mockIpaClient);
    when(mockIpaClient.findAllService()).thenReturn(services);
    underTest.deleteHost(request, ACCOUNT_ID);
    verify(mockIpaClient).deleteService(SERVICE_PRINCIPAL);
    verify(hostDeletionService).deleteHostsWithDeleteException(mockIpaClient, Set.of(HOST));
    verify(vaultComponent).recursivelyCleanupVault("accountId/ServiceKeytab/serviceprincipal/12345-6789/54321-9876/host1/");
    verify(vaultComponent).recursivelyCleanupVault("accountId/ServiceKeytab/keytab/12345-6789/54321-9876/host1/");
    verify(vaultComponent).recursivelyCleanupVault("accountId/HostKeytab/serviceprincipal/12345-6789/54321-9876/host1");
    verify(vaultComponent).recursivelyCleanupVault("accountId/HostKeytab/keytab/12345-6789/54321-9876/host1");
    verify(roleComponent).deleteRoleIfItIsNoLongerUsed(ROLE, mockIpaClient);
    verify(keytabCacheService).deleteByEnvironmentCrnAndPrincipal(ENVIRONMENT_ID, SERVICE_PRINCIPAL);
}
Also used : FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) KeytabCacheService(com.sequenceiq.freeipa.kerberosmgmt.v1.KeytabCacheService) Service(com.sequenceiq.freeipa.client.model.Service) KeytabCleanupService(com.sequenceiq.freeipa.kerberosmgmt.v1.KeytabCleanupService) KeytabCommonService(com.sequenceiq.freeipa.kerberosmgmt.v1.KeytabCommonService) HostDeletionService(com.sequenceiq.freeipa.service.freeipa.host.HostDeletionService) HashSet(java.util.HashSet) HostRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostRequest) Test(org.junit.jupiter.api.Test)

Example 2 with HostRequest

use of com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostRequest 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)

Aggregations

HostRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostRequest)2 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)2 HashSet (java.util.HashSet)2 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)1 RetryableFreeIpaClientException (com.sequenceiq.freeipa.client.RetryableFreeIpaClientException)1 Service (com.sequenceiq.freeipa.client.model.Service)1 Stack (com.sequenceiq.freeipa.entity.Stack)1 DeleteException (com.sequenceiq.freeipa.kerberosmgmt.exception.DeleteException)1 KeytabCacheService (com.sequenceiq.freeipa.kerberosmgmt.v1.KeytabCacheService)1 KeytabCleanupService (com.sequenceiq.freeipa.kerberosmgmt.v1.KeytabCleanupService)1 KeytabCommonService (com.sequenceiq.freeipa.kerberosmgmt.v1.KeytabCommonService)1 HostDeletionService (com.sequenceiq.freeipa.service.freeipa.host.HostDeletionService)1 HashMap (java.util.HashMap)1 Test (org.junit.jupiter.api.Test)1 Retryable (org.springframework.retry.annotation.Retryable)1