Search in sources :

Example 6 with Acceptable

use of com.sequenceiq.cloudbreak.common.event.Acceptable in project cloudbreak by hortonworks.

the class UpgradeServiceTest method testUpgradeTriggered.

@Test
public void testUpgradeTriggered() {
    FreeIpaUpgradeRequest request = new FreeIpaUpgradeRequest();
    request.setImage(new ImageSettingsRequest());
    request.setEnvironmentCrn(ENVIRONMENT_CRN);
    Stack stack = mock(Stack.class);
    when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(stack);
    Set<InstanceMetaData> allInstances = createValidImSet();
    when(stack.getNotDeletedInstanceMetaDataSet()).thenReturn(allInstances);
    ImageInfoResponse selectedImage = mockSelectedImage(request, stack);
    ImageInfoResponse currentImage = mockCurrentImage(stack);
    Operation operation = mockOperation(OperationState.RUNNING);
    ArgumentCaptor<Acceptable> eventCaptor = ArgumentCaptor.forClass(Acceptable.class);
    FlowIdentifier flowIdentifier = new FlowIdentifier(FlowType.FLOW_CHAIN, "flowId");
    when(flowManager.notify(eq(FlowChainTriggers.UPGRADE_TRIGGER_EVENT), eventCaptor.capture())).thenReturn(flowIdentifier);
    when(instanceMetaDataService.getPrimaryGwInstance(allInstances)).thenReturn(createPgwIm());
    when(instanceMetaDataService.getNonPrimaryGwInstances(allInstances)).thenReturn(createGwImSet());
    FreeIpaUpgradeResponse response = underTest.upgradeFreeIpa(ACCOUNT_ID, request);
    assertEquals(flowIdentifier, response.getFlowIdentifier());
    assertEquals(operation.getOperationId(), response.getOperationId());
    assertEquals(currentImage, response.getOriginalImage());
    assertEquals(selectedImage, response.getTargetImage());
    UpgradeEvent upgradeEvent = (UpgradeEvent) eventCaptor.getValue();
    assertEquals(request.getImage(), upgradeEvent.getImageSettingsRequest());
    assertEquals(operation.getOperationId(), upgradeEvent.getOperationId());
    assertEquals("pgw", upgradeEvent.getPrimareGwInstanceId());
    assertEquals(2, upgradeEvent.getInstanceIds().size());
    assertTrue(Set.of("im2", "im3").containsAll(upgradeEvent.getInstanceIds()));
    assertFalse(upgradeEvent.isBackupSet());
    verify(validationService).validateEntitlement(ACCOUNT_ID);
    verify(validationService).validateStackForUpgrade(allInstances, stack);
    verify(validationService).validateSelectedImageDifferentFromCurrent(currentImage, selectedImage);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) ImageInfoResponse(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.ImageInfoResponse) FreeIpaUpgradeResponse(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeResponse) UpgradeEvent(com.sequenceiq.freeipa.flow.freeipa.upgrade.UpgradeEvent) ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) FreeIpaUpgradeRequest(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeRequest) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) Operation(com.sequenceiq.freeipa.entity.Operation) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 7 with Acceptable

use of com.sequenceiq.cloudbreak.common.event.Acceptable in project cloudbreak by hortonworks.

the class ReactorNotifierTest method testAcceptedReturnNull.

@Test(expected = FlowNotAcceptedException.class)
public void testAcceptedReturnNull() throws InterruptedException {
    Stack stack = TestUtil.stack();
    stack.setCluster(TestUtil.cluster());
    when(stackService.getByIdWithTransaction(1L)).thenReturn(stack);
    Acceptable data = mock(Acceptable.class);
    Promise<AcceptResult> accepted = (Promise<AcceptResult>) mock(Promise.class);
    when(data.accepted()).thenReturn(accepted);
    when(data.getResourceId()).thenReturn(1L);
    Event<Acceptable> event = new Event<>(data);
    when(eventFactory.createEventWithErrHandler(anyMap(), any(Acceptable.class))).thenReturn(event);
    when(accepted.await(10L, TimeUnit.SECONDS)).thenReturn(null);
    underTest.notify(1L, "RANDOM", data, stackService::getByIdWithTransaction);
    verify(reactorReporter, times(1)).logInfoReport();
    verify(reactorReporter, times(1)).logErrorReport();
    verify(reactor, times(1)).notify(eq("RANDOM"), eq(event));
    verify(accepted, times(1)).await(10L, TimeUnit.SECONDS);
}
Also used : Promise(reactor.rx.Promise) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) Event(reactor.bus.Event) BaseFlowEvent(com.sequenceiq.flow.reactor.api.event.BaseFlowEvent) AcceptResult(com.sequenceiq.cloudbreak.common.event.AcceptResult) FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.Test)

Example 8 with Acceptable

use of com.sequenceiq.cloudbreak.common.event.Acceptable in project cloudbreak by hortonworks.

the class ReactorNotifierTest method testAcceptedReturnFalse.

@Test(expected = FlowsAlreadyRunningException.class)
public void testAcceptedReturnFalse() throws InterruptedException {
    Stack stack = TestUtil.stack();
    stack.setCluster(TestUtil.cluster());
    when(stackService.getByIdWithTransaction(1L)).thenReturn(stack);
    Acceptable data = mock(Acceptable.class);
    Promise<AcceptResult> accepted = (Promise<AcceptResult>) mock(Promise.class);
    when(data.accepted()).thenReturn(accepted);
    when(data.getResourceId()).thenReturn(1L);
    Event<Acceptable> event = new Event<>(data);
    when(eventFactory.createEventWithErrHandler(anyMap(), any(Acceptable.class))).thenReturn(event);
    when(accepted.await(10L, TimeUnit.SECONDS)).thenReturn(FlowAcceptResult.alreadyExistingFlow(Collections.EMPTY_SET));
    underTest.notify(1L, "RANDOM", data, stackService::getByIdWithTransaction);
    verify(reactorReporter, times(1)).logInfoReport();
    verify(reactorReporter, times(1)).logErrorReport();
    verify(reactor, times(1)).notify(eq("RANDOM"), eq(event));
    verify(accepted, times(1)).await(10L, TimeUnit.SECONDS);
}
Also used : Promise(reactor.rx.Promise) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) Event(reactor.bus.Event) BaseFlowEvent(com.sequenceiq.flow.reactor.api.event.BaseFlowEvent) AcceptResult(com.sequenceiq.cloudbreak.common.event.AcceptResult) FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.Test)

Example 9 with Acceptable

use of com.sequenceiq.cloudbreak.common.event.Acceptable in project cloudbreak by hortonworks.

the class ReactorFlowManagerTest method testTriggerUpscaleWithoutClusterEvent.

@Test
public void testTriggerUpscaleWithoutClusterEvent() {
    InstanceGroupAdjustmentV4Request instanceGroupAdjustment = new InstanceGroupAdjustmentV4Request();
    instanceGroupAdjustment.setInstanceGroup("ig");
    instanceGroupAdjustment.setScalingAdjustment(3);
    when(stackService.getPlatformVariantByStackId(STACK_ID)).thenReturn(cloudPlatformVariant);
    when(cloudPlatformVariant.getVariant()).thenReturn(Variant.variant("AWS"));
    underTest.triggerStackUpscale(stack.getId(), instanceGroupAdjustment, false);
    ArgumentCaptor<Acceptable> captor = ArgumentCaptor.forClass(Acceptable.class);
    verify(reactorNotifier, times(1)).notify(eq(stack.getId()), eq(FlowChainTriggers.FULL_UPSCALE_TRIGGER_EVENT), captor.capture());
    StackAndClusterUpscaleTriggerEvent event = (StackAndClusterUpscaleTriggerEvent) captor.getValue();
    assertEquals(FlowChainTriggers.FULL_UPSCALE_TRIGGER_EVENT, event.selector());
    assertEquals(stack.getId(), event.getResourceId());
    assertEquals(instanceGroupAdjustment.getInstanceGroup(), event.getHostGroupsWithAdjustment().keySet().stream().findFirst().get());
    assertEquals(instanceGroupAdjustment.getScalingAdjustment(), event.getHostGroupsWithAdjustment().values().stream().findFirst().get());
    assertEquals(ScalingType.UPSCALE_ONLY_STACK, event.getScalingType());
}
Also used : StackAndClusterUpscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackAndClusterUpscaleTriggerEvent) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) InstanceGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request) Test(org.junit.Test)

Example 10 with Acceptable

use of com.sequenceiq.cloudbreak.common.event.Acceptable in project cloudbreak by hortonworks.

the class ReactorFlowManagerTest method testTriggerDatabaseBackupFlowchain.

@Test
public void testTriggerDatabaseBackupFlowchain() {
    long stackId = 1L;
    String backupId = UUID.randomUUID().toString();
    underTest.triggerDatalakeDatabaseBackup(stackId, BACKUP_LOCATION, backupId, true);
    ArgumentCaptor<Acceptable> captor = ArgumentCaptor.forClass(Acceptable.class);
    verify(reactorNotifier).notify(eq(stackId), eq(FlowChainTriggers.DATALAKE_DATABASE_BACKUP_CHAIN_TRIGGER_EVENT), captor.capture());
    DatabaseBackupTriggerEvent event = (DatabaseBackupTriggerEvent) captor.getValue();
    assertEquals(stack.getId(), event.getResourceId());
    assertEquals(backupId, event.getBackupId());
    assertEquals(BACKUP_LOCATION, event.getBackupLocation());
    assertEquals(FlowChainTriggers.DATALAKE_DATABASE_BACKUP_CHAIN_TRIGGER_EVENT, event.selector());
}
Also used : Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) DatabaseBackupTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.DatabaseBackupTriggerEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

Acceptable (com.sequenceiq.cloudbreak.common.event.Acceptable)27 Test (org.junit.Test)9 Test (org.junit.jupiter.api.Test)9 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)5 FlowAcceptResult (com.sequenceiq.flow.core.model.FlowAcceptResult)5 Constructor (java.lang.reflect.Constructor)5 Modifier (java.lang.reflect.Modifier)5 Set (java.util.Set)5 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)5 AcceptResult (com.sequenceiq.cloudbreak.common.event.AcceptResult)4 StackAndClusterUpscaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StackAndClusterUpscaleTriggerEvent)4 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)4 BaseFlowEvent (com.sequenceiq.flow.reactor.api.event.BaseFlowEvent)4 Operation (com.sequenceiq.freeipa.entity.Operation)4 ReflectionUtils (org.reflections.ReflectionUtils)4 Reflections (org.reflections.Reflections)4 SubTypesScanner (org.reflections.scanners.SubTypesScanner)4 Event (reactor.bus.Event)4 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)3 ImageSettingsRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)3