use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.repair.RepairInstancesRequest in project cloudbreak by hortonworks.
the class FreeIpaRepairAction method action.
public FreeIpaTestDto action(TestContext testContext, FreeIpaTestDto testDto, FreeIpaClient client) throws Exception {
Log.when(LOGGER, format(" FreeIPA CRN: %s", testDto.getRequest().getEnvironmentCrn()));
RepairInstancesRequest request = new RepairInstancesRequest();
request.setForceRepair(true);
request.setEnvironmentCrn(testDto.getRequest().getEnvironmentCrn());
List<String> instanceIds = testDto.getResponse().getInstanceGroups().stream().map(InstanceGroupResponse::getMetaData).flatMap(Collection::stream).filter(im -> instanceMetadataType.equals(im.getInstanceType())).map(InstanceMetaDataResponse::getInstanceId).collect(Collectors.toList());
request.setInstanceIds(instanceIds);
Log.whenJson(LOGGER, format(" FreeIPA repair request: %n"), request);
client.getDefaultClient().getFreeIpaV1Endpoint().repairInstances(request);
return testDto;
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.repair.RepairInstancesRequest 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());
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.repair.RepairInstancesRequest in project cloudbreak by hortonworks.
the class RepairInstancesServiceTest method testRepairAndAutodetectBadInstances.
@Test
public void testRepairAndAutodetectBadInstances() throws Exception {
Stack stack = createStack(Status.UNHEALTHY, List.of(InstanceStatus.DELETED_ON_PROVIDER_SIDE, InstanceStatus.CREATED));
OperationStatus operationStatus = new OperationStatus();
RepairInstancesRequest repairInstancesRequest = new RepairInstancesRequest();
repairInstancesRequest.setEnvironmentCrn(ENVIRONMENT_ID1);
repairInstancesRequest.setForceRepair(false);
when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENVIRONMENT_ID1, ACCOUNT_ID)).thenReturn(stack);
when(healthDetailsService.getHealthDetails(ENVIRONMENT_ID1, ACCOUNT_ID)).thenReturn(createHealthDetails(InstanceStatus.DELETED_ON_PROVIDER_SIDE, InstanceStatus.CREATED));
when(entitlementService.freeIpaHaRepairEnabled(any())).thenReturn(Boolean.TRUE);
when(operationService.startOperation(any(), any(), any(), any())).thenReturn(createOperation());
when(operationToOperationStatusConverter.convert(any())).thenReturn(operationStatus);
assertEquals(operationStatus, underTest.repairInstances(ACCOUNT_ID, repairInstancesRequest));
verify(flowManager, times(1)).notify(eq(REPAIR_TRIGGER_EVENT), any());
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.repair.RepairInstancesRequest 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.api.v1.freeipa.stack.model.repair.RepairInstancesRequest 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);
});
}
Aggregations