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());
}
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);
});
}
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");
}
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());
}
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;
}
Aggregations