Search in sources :

Example 6 with RepairInstancesRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.repair.RepairInstancesRequest in project cloudbreak by hortonworks.

the class RepairInstancesServiceTest method testRepairForceWhenOnlyBadInstarncesRemain.

@Test
void testRepairForceWhenOnlyBadInstarncesRemain() {
    Stack stack = createStack(Status.UNREACHABLE, List.of(InstanceStatus.UNREACHABLE, InstanceStatus.UNREACHABLE));
    List<String> instanceIds = List.of("i-2");
    OperationStatus operationStatus = new OperationStatus();
    when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENVIRONMENT_ID1, ACCOUNT_ID)).thenReturn(stack);
    when(operationService.startOperation(any(), any(), any(), any())).thenReturn(createOperation());
    when(operationToOperationStatusConverter.convert(any())).thenReturn(operationStatus);
    when(entitlementService.freeIpaHaRepairEnabled(any())).thenReturn(Boolean.TRUE);
    when(stackUpdater.updateStackStatus(anyLong(), any(), any())).thenReturn(stack);
    RepairInstancesRequest request = new RepairInstancesRequest();
    request.setForceRepair(true);
    request.setInstanceIds(instanceIds);
    request.setEnvironmentCrn(ENVIRONMENT_ID1);
    assertEquals(operationStatus, underTest.repairInstances(ACCOUNT_ID, request));
    ArgumentCaptor acAcceptable = ArgumentCaptor.forClass(Acceptable.class);
    verify(flowManager).notify(eq("REPAIR_TRIGGER_EVENT"), (Acceptable) acAcceptable.capture());
    assertTrue(acAcceptable.getValue() instanceof RepairEvent);
    RepairEvent repairEvent = (RepairEvent) acAcceptable.getValue();
    assertEquals(instanceIds, repairEvent.getRepairInstanceIds());
    verify(stackUpdater).updateStackStatus(eq(STACK_ID), eq(DetailedStackStatus.REPAIR_REQUESTED), any());
}
Also used : ArgumentCaptor(org.mockito.ArgumentCaptor) OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus) RepairEvent(com.sequenceiq.freeipa.flow.freeipa.repair.event.RepairEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RepairInstancesRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.repair.RepairInstancesRequest) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 7 with RepairInstancesRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.repair.RepairInstancesRequest in project cloudbreak by hortonworks.

the class RepairInstancesServiceTest method testRepairInstancesWithNoneSpecified.

@Test
void testRepairInstancesWithNoneSpecified() {
    Stack stack = createStack(Status.UNHEALTHY, List.of(InstanceStatus.CREATED, InstanceStatus.UNREACHABLE));
    List<String> instanceIds = List.of("i-2");
    OperationStatus operationStatus = new OperationStatus();
    when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENVIRONMENT_ID1, ACCOUNT_ID)).thenReturn(stack);
    when(healthDetailsService.getHealthDetails(ENVIRONMENT_ID1, ACCOUNT_ID)).thenReturn(createHealthDetails(InstanceStatus.CREATED, InstanceStatus.UNREACHABLE));
    when(operationService.startOperation(any(), any(), any(), any())).thenReturn(createOperation());
    when(operationToOperationStatusConverter.convert(any())).thenReturn(operationStatus);
    when(entitlementService.freeIpaHaRepairEnabled(any())).thenReturn(Boolean.TRUE);
    when(stackUpdater.updateStackStatus(anyLong(), any(), any())).thenReturn(stack);
    RepairInstancesRequest request = new RepairInstancesRequest();
    request.setEnvironmentCrn(ENVIRONMENT_ID1);
    assertEquals(operationStatus, underTest.repairInstances(ACCOUNT_ID, request));
    ArgumentCaptor acAcceptable = ArgumentCaptor.forClass(Acceptable.class);
    verify(flowManager).notify(eq("REPAIR_TRIGGER_EVENT"), (Acceptable) acAcceptable.capture());
    assertTrue(acAcceptable.getValue() instanceof RepairEvent);
    RepairEvent repairEvent = (RepairEvent) acAcceptable.getValue();
    assertEquals(instanceIds, repairEvent.getRepairInstanceIds());
    verify(stackUpdater).updateStackStatus(eq(STACK_ID), eq(DetailedStackStatus.REPAIR_REQUESTED), any());
}
Also used : ArgumentCaptor(org.mockito.ArgumentCaptor) OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus) RepairEvent(com.sequenceiq.freeipa.flow.freeipa.repair.event.RepairEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RepairInstancesRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.repair.RepairInstancesRequest) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 8 with RepairInstancesRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.repair.RepairInstancesRequest in project cloudbreak by hortonworks.

the class FreeIpaV1ControllerTest method repair.

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

Example 9 with RepairInstancesRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.repair.RepairInstancesRequest in project cloudbreak by hortonworks.

the class RepairInstancesServiceTest method testRepairThrowsWhenOnlyDeletedInstancesAndForceIsCalledRemain.

@Test
void testRepairThrowsWhenOnlyDeletedInstancesAndForceIsCalledRemain() {
    Stack stack = createStack(Status.DELETED_ON_PROVIDER_SIDE, List.of(InstanceStatus.DELETED_BY_PROVIDER, InstanceStatus.DELETED_BY_PROVIDER));
    when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENVIRONMENT_ID1, ACCOUNT_ID)).thenReturn(stack);
    when(healthDetailsService.getHealthDetails(ENVIRONMENT_ID1, ACCOUNT_ID)).thenReturn(createHealthDetails(InstanceStatus.UNREACHABLE, InstanceStatus.UNREACHABLE));
    RepairInstancesRequest request = new RepairInstancesRequest();
    request.setEnvironmentCrn(ENVIRONMENT_ID1);
    assertThrows(BadRequestException.class, () -> {
        underTest.repairInstances(ACCOUNT_ID, request);
    });
}
Also used : RepairInstancesRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.repair.RepairInstancesRequest) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 10 with RepairInstancesRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.repair.RepairInstancesRequest in project cloudbreak by hortonworks.

the class RepairInstancesServiceTest method testRepairThrowsWhenOneBadInstancesRemain.

@Test
void testRepairThrowsWhenOneBadInstancesRemain() {
    Stack stack = createStack(Status.UNHEALTHY, List.of(InstanceStatus.UNREACHABLE, InstanceStatus.UNREACHABLE));
    when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENVIRONMENT_ID1, ACCOUNT_ID)).thenReturn(stack);
    when(healthDetailsService.getHealthDetails(ENVIRONMENT_ID1, ACCOUNT_ID)).thenReturn(createHealthDetails(InstanceStatus.UNREACHABLE, InstanceStatus.UNREACHABLE));
    RepairInstancesRequest request = new RepairInstancesRequest();
    request.setEnvironmentCrn(ENVIRONMENT_ID1);
    assertThrows(BadRequestException.class, () -> {
        underTest.repairInstances(ACCOUNT_ID, request);
    });
}
Also used : RepairInstancesRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.repair.RepairInstancesRequest) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

RepairInstancesRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.repair.RepairInstancesRequest)13 Stack (com.sequenceiq.freeipa.entity.Stack)12 Test (org.junit.jupiter.api.Test)12 OperationStatus (com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus)6 RepairEvent (com.sequenceiq.freeipa.flow.freeipa.repair.event.RepairEvent)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 ArgumentCaptor (org.mockito.ArgumentCaptor)4 InstanceGroupResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupResponse)1 InstanceStatus (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus)1 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)1 Operation (com.sequenceiq.freeipa.entity.Operation)1 ArrayList (java.util.ArrayList)1