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);
}
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);
}
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);
}
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());
}
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());
}
Aggregations