use of com.sequenceiq.freeipa.flow.freeipa.backup.full.event.CreateFullBackupEvent in project cloudbreak by hortonworks.
the class CreateFullBackupHandlerTest method testBackupSuccessful.
@Test
public void testBackupSuccessful() throws CloudbreakOrchestratorFailedException {
Stack stack = mock(Stack.class);
when(stackService.getByIdWithListsInTransaction(2L)).thenReturn(stack);
Set<InstanceMetaData> metaDataSet = Set.of();
when(stack.getNotDeletedInstanceMetaDataSet()).thenReturn(metaDataSet);
Node node1 = createNode("node1");
Node node2 = createNode("node2");
Set<Node> nodes = Set.of(node1, node2);
when(nodeService.mapInstancesToNodes(metaDataSet)).thenReturn(nodes);
GatewayConfig gatewayConfig = mock(GatewayConfig.class);
when(gatewayConfigService.getPrimaryGatewayConfig(stack)).thenReturn(gatewayConfig);
StackEvent result = (StackEvent) underTest.doAccept(new HandlerEvent<>(new Event<>(new CreateFullBackupEvent(2L))));
ArgumentCaptor<OrchestratorStateParams> captor = ArgumentCaptor.forClass(OrchestratorStateParams.class);
verify(orchestrator, times(2)).runOrchestratorState(captor.capture());
List<OrchestratorStateParams> stateParams = captor.getAllValues();
assertThat(stateParams, everyItem(allOf(hasProperty("primaryGatewayConfig", is(gatewayConfig)), hasProperty("state", is("freeipa.backup-full")), hasProperty("allNodes", is(nodes)))));
assertThat(stateParams, hasItem(hasProperty("targetHostNames", allOf(hasItem("node1"), iterableWithSize(1)))));
assertThat(stateParams, hasItem(hasProperty("targetHostNames", allOf(hasItem("node2"), iterableWithSize(1)))));
assertEquals(2L, result.getResourceId());
assertEquals(FullBackupEvent.FULL_BACKUP_SUCCESSFUL_EVENT.event(), result.selector());
}
use of com.sequenceiq.freeipa.flow.freeipa.backup.full.event.CreateFullBackupEvent in project cloudbreak by hortonworks.
the class FullBackupActions method backupAction.
@Bean(name = "BACKUP_STATE")
public Action<?, ?> backupAction() {
return new AbstractBackupAction<>(TriggerFullBackupEvent.class) {
@Override
protected void doExecute(BackupContext context, TriggerFullBackupEvent payload, Map<Object, Object> variables) {
LOGGER.info("Full backup flow started with: {}", payload);
setChainedAction(variables, payload.isChained());
setFinalChain(variables, payload.isFinalChain());
setOperationId(variables, payload.getOperationId());
sendEvent(context, new CreateFullBackupEvent(payload.getResourceId()));
}
};
}
use of com.sequenceiq.freeipa.flow.freeipa.backup.full.event.CreateFullBackupEvent in project cloudbreak by hortonworks.
the class CreateFullBackupHandlerTest method testOrchestratorThrowException.
@Test
public void testOrchestratorThrowException() throws CloudbreakOrchestratorFailedException {
Stack stack = mock(Stack.class);
when(stackService.getByIdWithListsInTransaction(2L)).thenReturn(stack);
Set<InstanceMetaData> metaDataSet = Set.of();
when(stack.getNotDeletedInstanceMetaDataSet()).thenReturn(metaDataSet);
Node node1 = createNode("node1");
Set<Node> nodes = Set.of(node1);
when(nodeService.mapInstancesToNodes(metaDataSet)).thenReturn(nodes);
GatewayConfig gatewayConfig = mock(GatewayConfig.class);
when(gatewayConfigService.getPrimaryGatewayConfig(stack)).thenReturn(gatewayConfig);
doThrow(new CloudbreakOrchestratorFailedException("tada")).when(orchestrator).runOrchestratorState(any(OrchestratorStateParams.class));
StackFailureEvent result = (StackFailureEvent) underTest.doAccept(new HandlerEvent<>(new Event<>(new CreateFullBackupEvent(2L))));
assertEquals(2L, result.getResourceId());
assertEquals(FullBackupEvent.FULL_BACKUP_FAILED_EVENT.event(), result.selector());
assertEquals("tada", result.getException().getMessage());
}
use of com.sequenceiq.freeipa.flow.freeipa.backup.full.event.CreateFullBackupEvent in project cloudbreak by hortonworks.
the class CreateFullBackupHandlerTest method testDefaultFailureEvent.
@Test
public void testDefaultFailureEvent() {
Exception e = new Exception();
StackFailureEvent result = (StackFailureEvent) underTest.defaultFailureEvent(2L, e, new Event<>(new CreateFullBackupEvent(3L)));
assertEquals(2L, result.getResourceId());
assertEquals(e, result.getException());
assertEquals(FullBackupEvent.FULL_BACKUP_FAILED_EVENT.event(), result.selector());
}
Aggregations