Search in sources :

Example 61 with Stack

use of com.sequenceiq.freeipa.entity.Stack 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 62 with Stack

use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.

the class RepairInstancesServiceTest method testRepairThrowsWhenOnlyBadInstancesRemain.

@Test
void testRepairThrowsWhenOnlyBadInstancesRemain() {
    Stack stack = createStack(Status.UNHEALTHY, List.of(InstanceStatus.UNREACHABLE, InstanceStatus.UNREACHABLE, InstanceStatus.CREATED));
    when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENVIRONMENT_ID1, ACCOUNT_ID)).thenReturn(stack);
    RepairInstancesRequest request = new RepairInstancesRequest();
    request.setForceRepair(true);
    request.setEnvironmentCrn(ENVIRONMENT_ID1);
    request.setInstanceIds(List.of("i-1"));
    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 63 with Stack

use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.

the class RepairInstancesServiceTest method init.

@BeforeAll
public static void init() {
    stack1 = new Stack();
    stack1.setResourceCrn(ENVIRONMENT_ID1);
    stack1.setEnvironmentCrn(ENVIRONMENT_ID1);
    InstanceGroup instanceGroup = new InstanceGroup();
    stack1.getInstanceGroups().add(instanceGroup);
    instanceGroup.setInstanceGroupType(InstanceGroupType.MASTER);
    InstanceMetaData instanceMetaData = new InstanceMetaData();
    instanceGroup.setInstanceMetaData(Sets.newHashSet(instanceMetaData));
    instanceMetaData.setDiscoveryFQDN("host.domain");
    instanceMetaData.setInstanceId("instance_1");
    stack2 = new Stack();
    stack2.setResourceCrn(ENVIRONMENT_ID2);
    stack2.setEnvironmentCrn(ENVIRONMENT_ID2);
    instanceGroup = new InstanceGroup();
    stack2.getInstanceGroups().add(instanceGroup);
    instanceGroup.setInstanceGroupType(InstanceGroupType.MASTER);
    instanceMetaData = new InstanceMetaData();
    instanceGroup.setInstanceMetaData(Sets.newHashSet(instanceMetaData));
    instanceMetaData.setDiscoveryFQDN("host1.domain");
    instanceMetaData.setInstanceId("instance_1");
    instanceMetaData = new InstanceMetaData();
    instanceGroup.getInstanceMetaData().add(instanceMetaData);
    instanceMetaData.setDiscoveryFQDN("host2.domain");
    instanceMetaData.setInstanceId("instance_2");
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 64 with Stack

use of com.sequenceiq.freeipa.entity.Stack 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 65 with Stack

use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.

the class RepairInstancesServiceTest method createStack.

private Stack createStack(Status stackStatus, List<InstanceStatus> instanceStatuses, int requestedInstancesWithoutInstanceIds) {
    Stack stack = new Stack();
    stack.setId(STACK_ID);
    stack.setEnvironmentCrn(ENVIRONMENT_ID1);
    StackStatus s = new StackStatus();
    s.setStatus(stackStatus);
    stack.setStackStatus(s);
    int i = 1;
    Set<InstanceMetaData> instanceMetaDataSet = new HashSet<>();
    for (InstanceStatus instanceStatus : instanceStatuses) {
        InstanceMetaData instanceMetaData = new InstanceMetaData();
        instanceMetaData.setInstanceId("i-" + i);
        instanceMetaData.setInstanceStatus(instanceStatus);
        instanceMetaDataSet.add(instanceMetaData);
        i++;
    }
    for (i = 0; i < requestedInstancesWithoutInstanceIds; i++) {
        InstanceMetaData instanceMetaData = new InstanceMetaData();
        instanceMetaData.setInstanceStatus(InstanceStatus.REQUESTED);
        instanceMetaDataSet.add(instanceMetaData);
    }
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setInstanceMetaData(instanceMetaDataSet);
    instanceGroup.setNodeCount(instanceMetaDataSet.size());
    stack.setInstanceGroups(Set.of(instanceGroup));
    return stack;
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) InstanceStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus) DetailedStackStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus) StackStatus(com.sequenceiq.freeipa.entity.StackStatus) Stack(com.sequenceiq.freeipa.entity.Stack) HashSet(java.util.HashSet) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup)

Aggregations

Stack (com.sequenceiq.freeipa.entity.Stack)468 Test (org.junit.jupiter.api.Test)237 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)107 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)63 Map (java.util.Map)63 Bean (org.springframework.context.annotation.Bean)50 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)45 StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)41 List (java.util.List)37 InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)34 Inject (javax.inject.Inject)30 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)29 Collectors (java.util.stream.Collectors)29 Logger (org.slf4j.Logger)29 LoggerFactory (org.slf4j.LoggerFactory)29 Set (java.util.Set)28 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)25 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)25 ImageSettingsRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)24 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)23