Search in sources :

Example 1 with CleanupRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.cleanup.CleanupRequest in project cloudbreak by hortonworks.

the class FreeIpaCleanupService method sendCleanupRequest.

private OperationStatus sendCleanupRequest(Stack stack, Set<CleanupStep> stepsToSkip, Set<String> hostNames, Set<String> ips) {
    try {
        CleanupRequest cleanupRequest = createCleanupRequest(stack, stepsToSkip, hostNames, ips);
        LOGGER.info("Sending cleanup request to FreeIPA: [{}]", cleanupRequest);
        OperationStatus cleanup = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> freeIpaV1Endpoint.internalCleanup(cleanupRequest, Crn.fromString(stack.getResourceCrn()).getAccountId()));
        LOGGER.info("Cleanup operation started: {}", cleanup);
        return cleanup;
    } catch (WebApplicationException e) {
        String errorMessage = exceptionMessageExtractor.getErrorMessage(e);
        String message = String.format("Couldn't start cleanup due to: '%s' ", errorMessage);
        LOGGER.error(message, e);
        throw new FreeIpaOperationFailedException(message, e);
    } catch (Exception e) {
        LOGGER.error("Couldn't start cleanup", e);
        throw new FreeIpaOperationFailedException("Couldn't start cleanup", e);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus) CleanupRequest(com.sequenceiq.freeipa.api.v1.freeipa.cleanup.CleanupRequest) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 2 with CleanupRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.cleanup.CleanupRequest in project cloudbreak by hortonworks.

the class FreeIpaUpgradeTests method cleanUp.

private void cleanUp(TestContext testContext, com.sequenceiq.freeipa.api.client.FreeIpaClient ipaClient, String environmentCrn) {
    try {
        CleanupRequest cleanupRequest = new CleanupRequest();
        cleanupRequest.setEnvironmentCrn(environmentCrn);
        cleanupRequest.setClusterName("testuser");
        cleanupRequest.setUsers(Set.of("kerberosbind-testuser", "ldapbind-testuser"));
        OperationStatus operationStatus = ipaClient.getFreeIpaV1Endpoint().cleanup(cleanupRequest);
        waitToCompleted(testContext, operationStatus.getOperationId(), "cleanupOperation");
    } catch (Exception e) {
        logger.error("CLEANUP test failed during upgrade", e);
    // throw new TestFailException("CLEANUP test failed during upgrade with: " + e.getMessage(), e);
    }
}
Also used : OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus) SyncOperationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus) CleanupRequest(com.sequenceiq.freeipa.api.v1.freeipa.cleanup.CleanupRequest) WebApplicationException(javax.ws.rs.WebApplicationException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 3 with CleanupRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.cleanup.CleanupRequest in project cloudbreak by hortonworks.

the class FreeIpaCleanupServiceTest method testCleanup.

@Test
public void testCleanup() {
    Stack stack = spy(aStack());
    Optional<KerberosConfig> kerberosConfig = Optional.of(mock(KerberosConfig.class));
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    when(kerberosConfigService.get(ENVIRONMENT_CRN, STACK_NAME)).thenReturn(kerberosConfig);
    when(environmentConfigProvider.isChildEnvironment(ENVIRONMENT_CRN)).thenReturn(false);
    when(kerberosDetailService.keytabsShouldBeUpdated(CLOUD_PLATFORM, false, kerberosConfig)).thenReturn(true);
    when(stack.getInstanceMetaDataAsList()).thenReturn(List.of(createInstanceMetadata("asdf", "1.1.1.1"), createInstanceMetadata("qwer", "1.1.1.2")));
    OperationStatus operationStatus = new OperationStatus("opId", OperationType.CLEANUP, null, null, null, null, 0L, null);
    ArgumentCaptor<CleanupRequest> captor = ArgumentCaptor.forClass(CleanupRequest.class);
    when(freeIpaV1Endpoint.internalCleanup(captor.capture(), anyString())).thenReturn(operationStatus);
    when(freeIpaOperationChecker.pollWithAbsoluteTimeout(any(), any(), anyLong(), anyLong(), anyInt())).thenReturn(pollingResult);
    victim.cleanupButIp(stack);
    CleanupRequest cleanupRequest = captor.getValue();
    assertEquals(STACK_NAME, cleanupRequest.getClusterName());
    assertEquals(ENVIRONMENT_CRN, cleanupRequest.getEnvironmentCrn());
    assertTrue(cleanupRequest.getCleanupStepsToSkip().isEmpty());
    assertEquals(Set.of(KERBEROS_USER_PREFIX + stack.getName(), KEYTAB_USER_PREFIX + stack.getName(), LDAP_USER_PREFIX + stack.getName()), cleanupRequest.getUsers());
    assertEquals(Set.of(ROLE_NAME_PREFIX + stack.getName()), cleanupRequest.getRoles());
    assertTrue(cleanupRequest.getIps().isEmpty());
    assertEquals(Set.of("asdf", "qwer"), cleanupRequest.getHosts());
}
Also used : KerberosConfig(com.sequenceiq.cloudbreak.dto.KerberosConfig) OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus) CleanupRequest(com.sequenceiq.freeipa.api.v1.freeipa.cleanup.CleanupRequest) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 4 with CleanupRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.cleanup.CleanupRequest in project cloudbreak by hortonworks.

the class FreeIpaCleanupServiceTest method testCleanupOnScale.

@Test
public void testCleanupOnScale() {
    Stack stack = spy(aStack());
    Optional<KerberosConfig> kerberosConfig = Optional.of(mock(KerberosConfig.class));
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    when(kerberosConfigService.get(ENVIRONMENT_CRN, STACK_NAME)).thenReturn(kerberosConfig);
    when(environmentConfigProvider.isChildEnvironment(ENVIRONMENT_CRN)).thenReturn(false);
    when(kerberosDetailService.keytabsShouldBeUpdated(CLOUD_PLATFORM, false, kerberosConfig)).thenReturn(true);
    OperationStatus operationStatus = new OperationStatus("opId", OperationType.CLEANUP, null, null, null, null, 0L, null);
    ArgumentCaptor<CleanupRequest> captor = ArgumentCaptor.forClass(CleanupRequest.class);
    when(freeIpaV1Endpoint.internalCleanup(captor.capture(), anyString())).thenReturn(operationStatus);
    when(freeIpaOperationChecker.pollWithAbsoluteTimeout(any(), any(), anyLong(), anyLong(), anyInt())).thenReturn(pollingResult);
    victim.cleanupOnScale(stack, Set.of("asdf", "qwer"), Set.of("1.1.1.1", "1.1.1.2"));
    CleanupRequest cleanupRequest = captor.getValue();
    assertEquals(STACK_NAME, cleanupRequest.getClusterName());
    assertEquals(ENVIRONMENT_CRN, cleanupRequest.getEnvironmentCrn());
    assertEquals(Set.of(REMOVE_USERS, REMOVE_ROLES), cleanupRequest.getCleanupStepsToSkip());
    assertEquals(Set.of(KERBEROS_USER_PREFIX + stack.getName(), KEYTAB_USER_PREFIX + stack.getName(), LDAP_USER_PREFIX + stack.getName()), cleanupRequest.getUsers());
    assertEquals(Set.of(ROLE_NAME_PREFIX + stack.getName()), cleanupRequest.getRoles());
    assertEquals(Set.of("1.1.1.1", "1.1.1.2"), cleanupRequest.getIps());
    assertEquals(Set.of("asdf", "qwer"), cleanupRequest.getHosts());
}
Also used : KerberosConfig(com.sequenceiq.cloudbreak.dto.KerberosConfig) OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus) CleanupRequest(com.sequenceiq.freeipa.api.v1.freeipa.cleanup.CleanupRequest) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 5 with CleanupRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.cleanup.CleanupRequest in project cloudbreak by hortonworks.

the class FreeIpaCleanupServiceTest method testCleanupOnRecover.

@Test
public void testCleanupOnRecover() {
    Stack stack = spy(aStack());
    Optional<KerberosConfig> kerberosConfig = Optional.of(mock(KerberosConfig.class));
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    when(kerberosConfigService.get(ENVIRONMENT_CRN, STACK_NAME)).thenReturn(kerberosConfig);
    when(environmentConfigProvider.isChildEnvironment(ENVIRONMENT_CRN)).thenReturn(false);
    when(kerberosDetailService.keytabsShouldBeUpdated(CLOUD_PLATFORM, false, kerberosConfig)).thenReturn(true);
    OperationStatus operationStatus = new OperationStatus("opId", OperationType.CLEANUP, null, null, null, null, 0L, null);
    ArgumentCaptor<CleanupRequest> captor = ArgumentCaptor.forClass(CleanupRequest.class);
    when(freeIpaV1Endpoint.internalCleanup(captor.capture(), anyString())).thenReturn(operationStatus);
    when(freeIpaOperationChecker.pollWithAbsoluteTimeout(any(), any(), anyLong(), anyLong(), anyInt())).thenReturn(pollingResult);
    victim.cleanupOnRecover(stack, Set.of("asdf", "qwer"), Set.of("1.1.1.1", "1.1.1.2"));
    CleanupRequest cleanupRequest = captor.getValue();
    assertEquals(STACK_NAME, cleanupRequest.getClusterName());
    assertEquals(ENVIRONMENT_CRN, cleanupRequest.getEnvironmentCrn());
    assertEquals(Set.of(REMOVE_HOSTS, REMOVE_VAULT_ENTRIES, REMOVE_USERS, REMOVE_ROLES), cleanupRequest.getCleanupStepsToSkip());
    assertEquals(Set.of(KERBEROS_USER_PREFIX + stack.getName(), KEYTAB_USER_PREFIX + stack.getName(), LDAP_USER_PREFIX + stack.getName()), cleanupRequest.getUsers());
    assertEquals(Set.of(ROLE_NAME_PREFIX + stack.getName()), cleanupRequest.getRoles());
    assertEquals(Set.of("1.1.1.1", "1.1.1.2"), cleanupRequest.getIps());
    assertEquals(Set.of("asdf", "qwer"), cleanupRequest.getHosts());
}
Also used : KerberosConfig(com.sequenceiq.cloudbreak.dto.KerberosConfig) OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus) CleanupRequest(com.sequenceiq.freeipa.api.v1.freeipa.cleanup.CleanupRequest) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

CleanupRequest (com.sequenceiq.freeipa.api.v1.freeipa.cleanup.CleanupRequest)8 OperationStatus (com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus)7 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)5 KerberosConfig (com.sequenceiq.cloudbreak.dto.KerberosConfig)5 Test (org.junit.jupiter.api.Test)5 WebApplicationException (javax.ws.rs.WebApplicationException)2 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)1 SyncOperationStatus (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus)1 TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)1