Search in sources :

Example 26 with Acceptable

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

the class UpgradeServiceTest method testUpgradeTriggeredWithBackup.

@Test
public void testUpgradeTriggeredWithBackup() {
    FreeIpaUpgradeRequest request = new FreeIpaUpgradeRequest();
    request.setImage(new ImageSettingsRequest());
    request.setEnvironmentCrn(ENVIRONMENT_CRN);
    Stack stack = mock(Stack.class);
    when(stack.getBackup()).thenReturn(new Backup());
    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()));
    assertTrue(upgradeEvent.isBackupSet());
    verify(validationService).validateEntitlement(ACCOUNT_ID);
    verify(validationService).validateStackForUpgrade(allInstances, stack);
    verify(validationService).validateSelectedImageDifferentFromCurrent(currentImage, selectedImage);
}
Also used : ImageInfoResponse(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.ImageInfoResponse) FreeIpaUpgradeResponse(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeResponse) ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) FreeIpaUpgradeRequest(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeRequest) Backup(com.sequenceiq.freeipa.api.model.Backup) Operation(com.sequenceiq.freeipa.entity.Operation) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) UpgradeEvent(com.sequenceiq.freeipa.flow.freeipa.upgrade.UpgradeEvent) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) Test(org.junit.jupiter.api.Test)

Example 27 with Acceptable

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

the class FlowPayloadConstructorTest method constructorAccessible.

@Test
void constructorAccessible() {
    Reflections reflections = new Reflections("com.sequenceiq", new SubTypesScanner(true));
    Set<Class<? extends Acceptable>> eventClasses = reflections.getSubTypesOf(Acceptable.class);
    eventClasses.stream().filter(c -> !c.isInterface() && !isAbstract(c) && !c.isAnonymousClass() && !c.isLocalClass() && !c.isMemberClass()).filter(c -> !c.getName().endsWith("Test")).forEach(this::checkForConstructor);
}
Also used : Test(org.junit.jupiter.api.Test) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Modifier(java.lang.reflect.Modifier) Set(java.util.Set) ReflectionUtils(org.reflections.ReflectionUtils) Reflections(org.reflections.Reflections) Constructor(java.lang.reflect.Constructor) SubTypesScanner(org.reflections.scanners.SubTypesScanner) SubTypesScanner(org.reflections.scanners.SubTypesScanner) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) Reflections(org.reflections.Reflections) Test(org.junit.jupiter.api.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