Search in sources :

Example 1 with RepairEvent

use of com.sequenceiq.freeipa.flow.freeipa.repair.event.RepairEvent in project cloudbreak by hortonworks.

the class RepairInstancesServiceTest method testRepairInstancesWithForce.

@Test
void testRepairInstancesWithForce() {
    Stack stack = createStack(Status.AVAILABLE, List.of(InstanceStatus.CREATED, InstanceStatus.CREATED));
    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 2 with RepairEvent

use of com.sequenceiq.freeipa.flow.freeipa.repair.event.RepairEvent in project cloudbreak by hortonworks.

the class RepairInstancesServiceTest method testRepairInstancesWithBadHealthInstance.

@Test
void testRepairInstancesWithBadHealthInstance() {
    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.setForceRepair(false);
    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 3 with RepairEvent

use of com.sequenceiq.freeipa.flow.freeipa.repair.event.RepairEvent 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 4 with RepairEvent

use of com.sequenceiq.freeipa.flow.freeipa.repair.event.RepairEvent 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 5 with RepairEvent

use of com.sequenceiq.freeipa.flow.freeipa.repair.event.RepairEvent in project cloudbreak by hortonworks.

the class RepairFlowEventChainFactoryTest method testRepair.

@Test
public void testRepair() {
    RepairEvent event = new RepairEvent(FlowChainTriggers.REPAIR_TRIGGER_EVENT, STACK_ID, OPERATION_ID, INSTANCE_COUNT_BY_GROUP, INSTANCE_IDS_TO_REPAIR, TERMINATED_INSTANCE_IDS);
    Queue<Selectable> eventQueues = underTest.createFlowTriggerEventQueue(event).getQueue();
    List<String> triggeredOperations = eventQueues.stream().map(Selectable::selector).collect(Collectors.toList());
    assertEquals(List.of("CHANGE_PRIMARY_GATEWAY_EVENT", "DOWNSCALE_EVENT", "UPSCALE_EVENT", "CHANGE_PRIMARY_GATEWAY_EVENT"), triggeredOperations);
}
Also used : Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) RepairEvent(com.sequenceiq.freeipa.flow.freeipa.repair.event.RepairEvent) Test(org.junit.Test)

Aggregations

RepairEvent (com.sequenceiq.freeipa.flow.freeipa.repair.event.RepairEvent)6 Stack (com.sequenceiq.freeipa.entity.Stack)5 RepairInstancesRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.repair.RepairInstancesRequest)4 OperationStatus (com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus)4 Test (org.junit.jupiter.api.Test)4 ArgumentCaptor (org.mockito.ArgumentCaptor)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)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 Test (org.junit.Test)1