Search in sources :

Example 1 with CreateFullBackupEvent

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());
}
Also used : CreateFullBackupEvent(com.sequenceiq.freeipa.flow.freeipa.backup.full.event.CreateFullBackupEvent) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) OrchestratorStateParams(com.sequenceiq.cloudbreak.orchestrator.host.OrchestratorStateParams) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Test(org.junit.jupiter.api.Test)

Example 2 with CreateFullBackupEvent

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()));
        }
    };
}
Also used : CreateFullBackupEvent(com.sequenceiq.freeipa.flow.freeipa.backup.full.event.CreateFullBackupEvent) TriggerFullBackupEvent(com.sequenceiq.freeipa.flow.freeipa.backup.full.event.TriggerFullBackupEvent) BackupContext(com.sequenceiq.freeipa.flow.freeipa.backup.full.BackupContext) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 3 with CreateFullBackupEvent

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());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) CreateFullBackupEvent(com.sequenceiq.freeipa.flow.freeipa.backup.full.event.CreateFullBackupEvent) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) StackFailureEvent(com.sequenceiq.freeipa.flow.stack.StackFailureEvent) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) OrchestratorStateParams(com.sequenceiq.cloudbreak.orchestrator.host.OrchestratorStateParams) Stack(com.sequenceiq.freeipa.entity.Stack) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Test(org.junit.jupiter.api.Test)

Example 4 with CreateFullBackupEvent

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());
}
Also used : CreateFullBackupEvent(com.sequenceiq.freeipa.flow.freeipa.backup.full.event.CreateFullBackupEvent) StackFailureEvent(com.sequenceiq.freeipa.flow.stack.StackFailureEvent) Event(reactor.bus.Event) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) StackFailureEvent(com.sequenceiq.freeipa.flow.stack.StackFailureEvent) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) CreateFullBackupEvent(com.sequenceiq.freeipa.flow.freeipa.backup.full.event.CreateFullBackupEvent) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) Test(org.junit.jupiter.api.Test)

Aggregations

CreateFullBackupEvent (com.sequenceiq.freeipa.flow.freeipa.backup.full.event.CreateFullBackupEvent)4 HandlerEvent (com.sequenceiq.flow.reactor.api.handler.HandlerEvent)3 Test (org.junit.jupiter.api.Test)3 Node (com.sequenceiq.cloudbreak.common.orchestration.Node)2 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)2 OrchestratorStateParams (com.sequenceiq.cloudbreak.orchestrator.host.OrchestratorStateParams)2 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)2 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)2 Stack (com.sequenceiq.freeipa.entity.Stack)2 StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)2 StackFailureEvent (com.sequenceiq.freeipa.flow.stack.StackFailureEvent)2 BackupContext (com.sequenceiq.freeipa.flow.freeipa.backup.full.BackupContext)1 TriggerFullBackupEvent (com.sequenceiq.freeipa.flow.freeipa.backup.full.event.TriggerFullBackupEvent)1 Map (java.util.Map)1 Bean (org.springframework.context.annotation.Bean)1 Event (reactor.bus.Event)1