use of com.sequenceiq.freeipa.flow.instance.InstanceEvent in project cloudbreak by hortonworks.
the class RepairInstancesServiceTest method testForceInstancesSuccessReboot.
@Test
public void testForceInstancesSuccessReboot() throws Exception {
OperationStatus operationStatus = new OperationStatus();
Mockito.when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(anyString(), anyString())).thenReturn(stack1);
Mockito.when(operationService.startOperation(any(), any(), any(), any())).thenReturn(createOperation());
Mockito.when(operationToOperationStatusConverter.convert(any())).thenReturn(operationStatus);
RebootInstancesRequest rebootInstancesRequest = new RebootInstancesRequest();
rebootInstancesRequest.setEnvironmentCrn(ENVIRONMENT_ID1);
rebootInstancesRequest.setInstanceIds(Arrays.asList("instance_1"));
rebootInstancesRequest.setForceReboot(true);
assertEquals(operationStatus, underTest.rebootInstances(ACCOUNT_ID, rebootInstancesRequest));
ArgumentCaptor<InstanceEvent> terminationEventArgumentCaptor = ArgumentCaptor.forClass(InstanceEvent.class);
verify(flowManager, times(1)).notify(eq(REBOOT_EVENT.event()), terminationEventArgumentCaptor.capture());
}
use of com.sequenceiq.freeipa.flow.instance.InstanceEvent in project cloudbreak by hortonworks.
the class RepairInstancesServiceTest method testNonForceAvailableInstanceReboot.
@Test
public void testNonForceAvailableInstanceReboot() throws Exception {
Mockito.when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(anyString(), anyString())).thenReturn(stack2);
Mockito.when(healthDetailsService.getHealthDetails(any(), any())).thenReturn(getMockDetails2());
RebootInstancesRequest rebootInstancesRequest = new RebootInstancesRequest();
rebootInstancesRequest.setEnvironmentCrn(ENVIRONMENT_ID2);
rebootInstancesRequest.setInstanceIds(Arrays.asList("instance_1"));
Exception expected = assertThrows(NotFoundException.class, () -> {
underTest.rebootInstances(ACCOUNT_ID, rebootInstancesRequest);
});
Assert.assertTrue(expected.getLocalizedMessage().equals("No unhealthy instances to reboot. Maybe use the force option."));
ArgumentCaptor<InstanceEvent> terminationEventArgumentCaptor = ArgumentCaptor.forClass(InstanceEvent.class);
verify(flowManager, times(0)).notify(eq(REBOOT_EVENT.event()), terminationEventArgumentCaptor.capture());
}
use of com.sequenceiq.freeipa.flow.instance.InstanceEvent in project cloudbreak by hortonworks.
the class RebootActions method rebootFailureAction.
@Bean(name = "REBOOT_FAILED_STATE")
public Action<?, ?> rebootFailureAction() {
return new AbstractRebootAction<>(InstanceFailureEvent.class) {
@Inject
private OperationService operationService;
@Override
protected void doExecute(RebootContext context, InstanceFailureEvent payload, Map<Object, Object> variables) {
addMdcOperationId(variables);
rebootService.handleInstanceRebootError(context);
String message = String.format("Rebooting failed for %s.", context.getInstanceIds());
LOGGER.error(message);
Stack stack = context.getStack();
SuccessDetails successDetails = new SuccessDetails(stack.getEnvironmentCrn());
FailureDetails failureDetails = new FailureDetails(stack.getEnvironmentCrn(), message);
operationService.failOperation(stack.getAccountId(), getOperationId(variables), message, List.of(successDetails), List.of(failureDetails));
sendEvent(context, new InstanceEvent(RebootEvent.REBOOT_FAIL_HANDLED_EVENT.event(), context.getStack().getId(), context.getInstanceIdList()));
}
@Override
protected RebootContext createFlowContext(FlowParameters flowParameters, StateContext<RebootState, RebootEvent> stateContext, InstanceFailureEvent payload) {
Long stackId = payload.getResourceId();
Stack stack = stackService.getStackById(stackId);
MDCBuilder.buildMdcContext(stack);
return new RebootContext(flowParameters, stack, payload.getInstanceIds().stream().map(instanceId -> {
InstanceMetaData md = new InstanceMetaData();
md.setInstanceId(instanceId);
return md;
}).collect(Collectors.toList()), null, null);
}
@Override
protected Object getFailurePayload(InstanceFailureEvent payload, Optional<RebootContext> flowContext, Exception ex) {
return new InstanceFailureEvent(payload.getResourceId(), ex, payload.getInstanceIds());
}
@Override
protected void initPayloadConverterMap(List<PayloadConverter<InstanceFailureEvent>> payloadConverters) {
payloadConverters.add(new RebootInstancesResultToCleanupFailureEventConverter());
payloadConverters.add(new WaitUntilAvailableFailedToInstanceFailureEventConverter());
}
};
}
use of com.sequenceiq.freeipa.flow.instance.InstanceEvent in project cloudbreak by hortonworks.
the class RebootActions method rebootFinishedAction.
@Bean(name = "REBOOT_FINISHED_STATE")
public Action<?, ?> rebootFinishedAction() {
return new AbstractRebootAction<>(HealthCheckSuccess.class) {
@Inject
private OperationService operationService;
@Override
protected void doExecute(RebootContext context, HealthCheckSuccess payload, Map<Object, Object> variables) {
addMdcOperationId(variables);
rebootService.finishInstanceReboot(context);
LOGGER.info("Finished rebooting {}.", context.getInstanceIds());
Stack stack = context.getStack();
SuccessDetails successDetails = new SuccessDetails(stack.getEnvironmentCrn());
successDetails.getAdditionalDetails().put("InstanceIds", context.getInstanceIdList());
operationService.completeOperation(stack.getAccountId(), getOperationId(variables), List.of(successDetails), Collections.emptyList());
sendEvent(context);
}
@Override
protected Object getFailurePayload(HealthCheckSuccess payload, Optional<RebootContext> flowContext, Exception ex) {
return new InstanceFailureEvent(payload.getResourceId(), ex, payload.getInstanceIds());
}
@Override
protected Selectable createRequest(RebootContext context) {
return new InstanceEvent(RebootEvent.REBOOT_FINALIZED_EVENT.event(), context.getStack().getId(), context.getInstanceIdList());
}
@Override
protected RebootContext createFlowContext(FlowParameters flowParameters, StateContext<RebootState, RebootEvent> stateContext, HealthCheckSuccess payload) {
Long stackId = payload.getResourceId();
Stack stack = stackService.getByIdWithListsInTransaction(stackId);
MDCBuilder.buildMdcContext(stack);
List<InstanceMetaData> instances = instanceMetaDataService.findNotTerminatedForStack(stackId).stream().filter(instanceMetaData -> payload.getInstanceIds().contains(instanceMetaData.getInstanceId())).collect(Collectors.toList());
return new RebootContext(flowParameters, stack, instances, null, null);
}
};
}
use of com.sequenceiq.freeipa.flow.instance.InstanceEvent in project cloudbreak by hortonworks.
the class RepairInstancesServiceTest method testForceMultiInstanceReboot.
@Test
public void testForceMultiInstanceReboot() throws Exception {
OperationStatus operationStatus = new OperationStatus();
Mockito.when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(anyString(), anyString())).thenReturn(stack2);
Mockito.when(operationService.startOperation(any(), any(), any(), any())).thenReturn(createOperation());
Mockito.when(operationToOperationStatusConverter.convert(any())).thenReturn(operationStatus);
RebootInstancesRequest rebootInstancesRequest = new RebootInstancesRequest();
rebootInstancesRequest.setEnvironmentCrn(ENVIRONMENT_ID2);
rebootInstancesRequest.setForceReboot(true);
assertEquals(operationStatus, underTest.rebootInstances(ACCOUNT_ID, rebootInstancesRequest));
ArgumentCaptor<InstanceEvent> terminationEventArgumentCaptor = ArgumentCaptor.forClass(InstanceEvent.class);
verify(flowManager, times(1)).notify(eq(REBOOT_EVENT.event()), terminationEventArgumentCaptor.capture());
}
Aggregations