Search in sources :

Example 21 with Acceptable

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

the class ReactorNotifierTest method testAccepted.

@Test
public void testAccepted() throws InterruptedException {
    Stack stack = TestUtil.stack();
    stack.setCluster(TestUtil.cluster());
    stack.setStackStatus(new StackStatus(stack, AVAILABLE));
    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);
    FlowAcceptResult acceptResult = FlowAcceptResult.runningInFlow("flowid");
    when(accepted.await(10L, TimeUnit.SECONDS)).thenReturn(acceptResult);
    underTest.notify(1L, "RANDOM", data, stackService::getByIdWithTransaction);
    verify(reactorReporter, times(1)).logInfoReport();
    verify(reactor, times(1)).notify(eq("RANDOM"), eq(event));
    verify(accepted, times(1)).await(10L, TimeUnit.SECONDS);
}
Also used : Promise(reactor.rx.Promise) FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) 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 22 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)

Example 23 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)

Example 24 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)

Example 25 with Acceptable

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

the class UpgradeServiceTest method testImageSettingsCreatedIfMissingAndUpgradeTriggered.

@Test
public void testImageSettingsCreatedIfMissingAndUpgradeTriggered() {
    FreeIpaUpgradeRequest request = new FreeIpaUpgradeRequest();
    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 = new ImageInfoResponse();
    when(imageService.selectImage(eq(stack), any(ImageSettingsRequest.class))).thenReturn(selectedImage);
    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();
    assertNotNull(upgradeEvent.getImageSettingsRequest());
    assertEquals(operation.getOperationId(), upgradeEvent.getOperationId());
    assertEquals("pgw", upgradeEvent.getPrimareGwInstanceId());
    assertEquals(2, upgradeEvent.getInstanceIds().size());
    assertTrue(Set.of("im2", "im3").containsAll(upgradeEvent.getInstanceIds()));
    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)

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