Search in sources :

Example 1 with RebuildRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.rebuild.RebuildRequest in project cloudbreak by hortonworks.

the class FreeIpaRebuildAction method action.

public FreeIpaTestDto action(TestContext testContext, FreeIpaTestDto testDto, FreeIpaClient client) throws Exception {
    Log.when(LOGGER, format(" FreeIPA CRN: %s", testDto.getRequest().getEnvironmentCrn()));
    RebuildRequest request = new RebuildRequest();
    request.setEnvironmentCrn(testDto.getRequest().getEnvironmentCrn());
    request.setSourceCrn(testDto.getCrn());
    Log.whenJson(LOGGER, format(" FreeIPA rebuild request: %n"), request);
    testDto.setResponse(client.getDefaultClient().getFreeIpaV1Endpoint().rebuild(request));
    Log.whenJson(LOGGER, format(" FreeIPA rebuilt successfully:%n"), testDto.getResponse());
    Log.when(LOGGER, format(" FreeIPA CRN: %s", testDto.getResponse().getCrn()));
    return testDto;
}
Also used : RebuildRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.rebuild.RebuildRequest)

Example 2 with RebuildRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.rebuild.RebuildRequest in project cloudbreak by hortonworks.

the class RepairInstancesServiceTest method testRebuild.

@Test
public void testRebuild() throws Exception {
    Stack stack = createStack(Status.DELETE_COMPLETED, List.of(InstanceStatus.TERMINATED, InstanceStatus.TERMINATED), 2);
    CreateFreeIpaRequest createFreeIpaRequest = new CreateFreeIpaRequest();
    DescribeFreeIpaResponse response = new DescribeFreeIpaResponse();
    when(stackService.getByCrnAndAccountIdEvenIfTerminated(ENVIRONMENT_ID1, ACCOUNT_ID, FREEIPA_CRN)).thenReturn(stack);
    when(stackService.findByEnvironmentCrnAndAccountId(ENVIRONMENT_ID1, ACCOUNT_ID)).thenReturn(Optional.empty());
    when(stackToCreateFreeIpaRequestConverter.convert(eq(stack))).thenReturn(createFreeIpaRequest);
    when(freeIpaCreationService.launchFreeIpa(eq(createFreeIpaRequest), eq(ACCOUNT_ID))).thenReturn(response);
    when(entitlementService.isFreeIpaRebuildEnabled(eq(ACCOUNT_ID))).thenReturn(true);
    RebuildRequest rebuildRequest = new RebuildRequest();
    rebuildRequest.setEnvironmentCrn(ENVIRONMENT_ID1);
    rebuildRequest.setSourceCrn(FREEIPA_CRN);
    assertEquals(response, underTest.rebuild(ACCOUNT_ID, rebuildRequest));
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) CreateFreeIpaRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest) RebuildRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.rebuild.RebuildRequest) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 3 with RebuildRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.rebuild.RebuildRequest in project cloudbreak by hortonworks.

the class FreeIpaV1ControllerTest method rebuild.

@Test
void rebuild() {
    when(crnService.getCurrentAccountId()).thenReturn(ACCOUNT_ID);
    RebuildRequest request = new RebuildRequest();
    underTest.rebuild(request);
    verify(repairInstancesService, times(1)).rebuild(crnService.getCurrentAccountId(), request);
}
Also used : RebuildRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.rebuild.RebuildRequest) Test(org.junit.jupiter.api.Test)

Example 4 with RebuildRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.rebuild.RebuildRequest in project cloudbreak by hortonworks.

the class RepairInstancesServiceTest method testRebuildThrowsWhenSourceStackIsRunning.

@Test
public void testRebuildThrowsWhenSourceStackIsRunning() throws Exception {
    Stack stack = createStack(Status.AVAILABLE, List.of(InstanceStatus.CREATED, InstanceStatus.CREATED), 2);
    when(stackService.getByCrnAndAccountIdEvenIfTerminated(ENVIRONMENT_ID1, ACCOUNT_ID, FREEIPA_CRN)).thenReturn(stack);
    when(stackService.findByEnvironmentCrnAndAccountId(ENVIRONMENT_ID1, ACCOUNT_ID)).thenReturn(Optional.of(stack));
    when(entitlementService.isFreeIpaRebuildEnabled(eq(ACCOUNT_ID))).thenReturn(true);
    RebuildRequest rebuildRequest = new RebuildRequest();
    rebuildRequest.setEnvironmentCrn(ENVIRONMENT_ID1);
    rebuildRequest.setSourceCrn(FREEIPA_CRN);
    assertThrows(BadRequestException.class, () -> underTest.rebuild(ACCOUNT_ID, rebuildRequest));
}
Also used : RebuildRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.rebuild.RebuildRequest) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 5 with RebuildRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.rebuild.RebuildRequest in project cloudbreak by hortonworks.

the class RepairInstancesServiceTest method testRebuildThrowsWhenEntitlementIsDisabled.

@Test
public void testRebuildThrowsWhenEntitlementIsDisabled() throws Exception {
    when(entitlementService.isFreeIpaRebuildEnabled(eq(ACCOUNT_ID))).thenReturn(false);
    RebuildRequest rebuildRequest = new RebuildRequest();
    rebuildRequest.setEnvironmentCrn(ENVIRONMENT_ID1);
    rebuildRequest.setSourceCrn(FREEIPA_CRN);
    assertThrows(BadRequestException.class, () -> underTest.rebuild(ACCOUNT_ID, rebuildRequest));
}
Also used : RebuildRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.rebuild.RebuildRequest) Test(org.junit.jupiter.api.Test)

Aggregations

RebuildRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.rebuild.RebuildRequest)5 Test (org.junit.jupiter.api.Test)4 Stack (com.sequenceiq.freeipa.entity.Stack)3 CreateFreeIpaRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest)2 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 DescribeFreeIpaResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse)1