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