reactor.rx.Promise Java Examples

The following examples show how to use reactor.rx.Promise. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Reactor2TcpClient.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public Publisher<Void> apply(ChannelStream<Message<P>, Message<P>> channelStream) {
	Promise<Void> closePromise = Promises.prepare();
	this.connectionHandler.afterConnected(new Reactor2TcpConnection<P>(channelStream, closePromise));
	channelStream
			.finallyDo(new Consumer<Signal<Message<P>>>() {
				@Override
				public void accept(Signal<Message<P>> signal) {
					if (signal.isOnError()) {
						connectionHandler.handleFailure(signal.getThrowable());
					}
					else if (signal.isOnComplete()) {
						connectionHandler.afterConnectionClosed();
					}
				}
			})
			.consume(new Consumer<Message<P>>() {
				@Override
				public void accept(Message<P> message) {
					connectionHandler.handleMessage(message);
				}
			});

	return closePromise;
}
 
Example #2
Source File: ReactorNotifierTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test(expected = FlowsAlreadyRunningException.class)
public void testAcceptedReturnFalse() throws InterruptedException {
    Stack stack = TestUtil.stack();
    stack.setCluster(TestUtil.cluster());
    stack.getCluster().setStatus(Status.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);
    when(accepted.await(10L, TimeUnit.SECONDS)).thenReturn(FlowAcceptResult.alreadyExistingFlow());

    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);
}
 
Example #3
Source File: ReactorNotifierTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test(expected = FlowNotAcceptedException.class)
public void testAcceptedReturnNull() throws InterruptedException {
    Stack stack = TestUtil.stack();
    stack.setCluster(TestUtil.cluster());
    stack.getCluster().setStatus(Status.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);
    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);
}
 
Example #4
Source File: ReactorNotifierTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
public void testAccepted() throws InterruptedException {
    Stack stack = TestUtil.stack();
    stack.setCluster(TestUtil.cluster());
    stack.getCluster().setStatus(Status.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);
}
 
Example #5
Source File: StackScaleTriggerEvent.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public StackScaleTriggerEvent(String selector, Long stackId, String instanceGroup, Integer adjustment, Set<String> hostNames,
        Promise<AcceptResult> accepted) {
    super(selector, stackId, accepted);
    this.instanceGroup = instanceGroup;
    this.adjustment = adjustment;
    this.hostNames = hostNames;
}
 
Example #6
Source File: StackAndClusterUpscaleTriggerEvent.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public StackAndClusterUpscaleTriggerEvent(String selector, Long stackId, String instanceGroup, Integer adjustment, ScalingType scalingType,
        Set<String> hostNames, boolean singlePrimaryGateway, boolean kerberosSecured, Promise<AcceptResult> accepted, boolean singleNodeCluster,
        ClusterManagerType clusterManagerType) {
    super(selector, stackId, instanceGroup, adjustment, hostNames, accepted);
    this.scalingType = scalingType;
    singleMasterGateway = singlePrimaryGateway;
    this.kerberosSecured = kerberosSecured;
    this.singleNodeCluster = singleNodeCluster;
    this.clusterManagerType = clusterManagerType;
}
 
Example #7
Source File: ReactorTcpServerTests.java    From reactive-ipc-jvm with Apache License 2.0 5 votes vote down vote up
@Test
public void writeMultipleValues() throws IOException {
    Promise<ByteBuf> chunk1 = Promises.success(Unpooled.buffer().writeBytes("This is".getBytes()));
    Promise<ByteBuf> chunk2 = Promises.success(Unpooled.buffer().writeBytes(" a test!".getBytes()));
    reactorServer.start(connection -> connection.writeWith(Streams.concat(chunk1, chunk2)));
    assertEquals("This is a test!", SocketTestUtils.read("localhost", reactorServer.getPort()));
}
 
Example #8
Source File: ClusterScaleTriggerEvent.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public ClusterScaleTriggerEvent(String selector, Long stackId, String hostGroup, Integer adjustment, Promise<AcceptResult> accepted) {
    super(selector, stackId, accepted);
    this.hostGroup = hostGroup;
    this.adjustment = adjustment;
    hostNames = Collections.emptySet();
    singlePrimaryGateway = false;
    kerberosSecured = false;
    singleNodeCluster = false;
    clusterManagerType = ClusterManagerType.CLOUDERA_MANAGER;
}
 
Example #9
Source File: MultiHostgroupDownscaleFlowEventChainFactoryTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateFlowWithTwoHostgroup() {
    Map<String, Set<Long>> instanceIdsByHostgroupMap = new HashMap<>();
    instanceIdsByHostgroupMap.put("firstGroup", Sets.newHashSet(1L, 2L));
    instanceIdsByHostgroupMap.put("secondGroup", Sets.newHashSet(3L, 4L));
    ClusterDownscaleDetails details = new ClusterDownscaleDetails();
    MultiHostgroupClusterAndStackDownscaleTriggerEvent event = new MultiHostgroupClusterAndStackDownscaleTriggerEvent("selector", 1L,
            instanceIdsByHostgroupMap, details, ScalingType.DOWNSCALE_TOGETHER, new Promise<>());
    Queue<Selectable> queue = underTest.createFlowTriggerEventQueue(event);
    assertEquals(4L, queue.size());
    assertEquals(DECOMMISSION_EVENT.event(), queue.poll().selector());
    assertEquals(STACK_DOWNSCALE_EVENT.event(), queue.poll().selector());
    assertEquals(DECOMMISSION_EVENT.event(), queue.poll().selector());
    assertEquals(STACK_DOWNSCALE_EVENT.event(), queue.poll().selector());
}
 
Example #10
Source File: MultiHostgroupClusterAndStackDownscaleTriggerEvent.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public MultiHostgroupClusterAndStackDownscaleTriggerEvent(String selector, Long stackId, Map<String, Set<Long>> instanceIdsByHostgroupMap,
        ClusterDownscaleDetails details, ScalingType scalingType, Promise<AcceptResult> accepted) {
    super(selector, stackId, accepted);
    this.instanceIdsByHostgroupMap = instanceIdsByHostgroupMap;
    this.details = details;
    this.scalingType = scalingType;
}
 
Example #11
Source File: DownscaleEvent.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public DownscaleEvent(String selector, Long stackId, List<String> instanceIds, int instanceCountByGroup, boolean repair, String operationId,
        Promise<AcceptResult> accepted) {
    super(selector, stackId, accepted);
    this.instanceIds = instanceIds;
    this.instanceCountByGroup = instanceCountByGroup;
    this.repair = repair;
    this.operationId = operationId;
}
 
Example #12
Source File: ChangePrimaryGatewayEvent.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public ChangePrimaryGatewayEvent(String selector, Long stackId, List<String> repairInstanceIds, Boolean finalChain, String operationId,
        Promise<AcceptResult> accepted) {
    super(selector, stackId, accepted);
    this.repairInstanceIds = repairInstanceIds;
    this.finalChain = finalChain;
    this.operationId = operationId;
}
 
Example #13
Source File: ReactorFlowManager.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public FlowIdentifier triggerStackRemoveInstance(Long stackId, String hostGroup, Long privateId, boolean forced) {
    String selector = FlowChainTriggers.FULL_DOWNSCALE_TRIGGER_EVENT;
    ClusterDownscaleDetails details = new ClusterDownscaleDetails(forced, false);
    ClusterAndStackDownscaleTriggerEvent event = new ClusterAndStackDownscaleTriggerEvent(selector, stackId, hostGroup, Collections.singleton(privateId),
            ScalingType.DOWNSCALE_TOGETHER, new Promise<>(), details);
    return reactorNotifier.notify(stackId, selector, event);
}
 
Example #14
Source File: EnvironmentReactorFlowManager.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public void triggerCreationFlow(long envId, String envName, String userCrn, String envCrn) {
    LOGGER.info("Environment creation flow triggered.");
    EnvCreationEvent envCreationEvent = EnvCreationEvent.builder()
            .withAccepted(new Promise<>())
            .withSelector(START_ENVIRONMENT_INITIALIZATION_EVENT.selector())
            .withResourceId(envId)
            .withResourceName(envName)
            .withResourceCrn(envCrn)
            .build();

    eventSender.sendEvent(envCreationEvent, new Event.Headers(getFlowTriggerUsercrn(userCrn)));
}
 
Example #15
Source File: EnvironmentReactorFlowManager.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public void triggerDeleteFlow(Environment environment, String userCrn, boolean forced) {
    LOGGER.info("Environment deletion flow triggered for '{}'.", environment.getName());
    flowCancelService.cancelRunningFlows(environment.getId());
    EnvDeleteEvent envDeleteEvent = EnvDeleteEvent.builder()
            .withAccepted(new Promise<>())
            .withSelector(START_FREEIPA_DELETE_EVENT.selector())
            .withResourceId(environment.getId())
            .withResourceName(environment.getName())
            .withForceDelete(forced)
            .build();

    eventSender.sendEvent(envDeleteEvent, new Event.Headers(getFlowTriggerUsercrn(userCrn)));
}
 
Example #16
Source File: EnvironmentReactorFlowManager.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public void triggerCascadingDeleteFlow(Environment environment, String userCrn, boolean forced) {
    LOGGER.info("Environment forced deletion flow triggered for '{}'.", environment.getName());
    flowCancelService.cancelRunningFlows(environment.getId());
    EnvDeleteEvent envDeleteEvent = EnvDeleteEvent.builder()
            .withAccepted(new Promise<>())
            .withSelector(ENV_DELETE_CLUSTERS_TRIGGER_EVENT)
            .withResourceId(environment.getId())
            .withResourceName(environment.getName())
            .withForceDelete(forced)
            .build();

    eventSender.sendEvent(envDeleteEvent, new Event.Headers(getFlowTriggerUsercrn(userCrn)));
}
 
Example #17
Source File: EnvironmentReactorFlowManager.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public void triggerStopFlow(long envId, String envName, String userCrn) {
    LOGGER.info("Environment stop flow triggered.");
    EnvStopEvent envStopEvent = EnvStopEvent.EnvStopEventBuilder.anEnvStopEvent()
            .withAccepted(new Promise<>())
            .withSelector(EnvStopStateSelectors.ENV_STOP_DATAHUB_EVENT.selector())
            .withResourceId(envId)
            .withResourceName(envName)
            .build();

    eventSender.sendEvent(envStopEvent, new Event.Headers(getFlowTriggerUsercrn(userCrn)));
}
 
Example #18
Source File: EnvironmentReactorFlowManager.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public void triggerStartFlow(long envId, String envName, String userCrn) {
    LOGGER.info("Environment start flow triggered.");
    EnvStartEvent envSrartEvent = EnvStartEvent.EnvStartEventBuilder.anEnvStartEvent()
            .withAccepted(new Promise<>())
            .withSelector(EnvStartStateSelectors.ENV_START_FREEIPA_EVENT.selector())
            .withResourceId(envId)
            .withResourceName(envName)
            .build();

    eventSender.sendEvent(envSrartEvent, new Event.Headers(getFlowTriggerUsercrn(userCrn)));
}
 
Example #19
Source File: ReactorFlowManager.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public FlowIdentifier triggerStackRemoveInstances(Long stackId, Map<String, Set<Long>> instanceIdsByHostgroupMap, boolean forced) {
    String selector = FlowChainTriggers.FULL_DOWNSCALE_MULTIHOSTGROUP_TRIGGER_EVENT;
    ClusterDownscaleDetails details = new ClusterDownscaleDetails(forced, false);
    MultiHostgroupClusterAndStackDownscaleTriggerEvent event = new MultiHostgroupClusterAndStackDownscaleTriggerEvent(selector, stackId,
            instanceIdsByHostgroupMap, details, ScalingType.DOWNSCALE_TOGETHER, new Promise<>());
    return reactorNotifier.notify(stackId, selector, event);
}
 
Example #20
Source File: MaintenanceModeValidationTriggerEvent.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
public MaintenanceModeValidationTriggerEvent(String selector, Long stackId, Promise<AcceptResult> accepted) {
    super(selector, stackId, accepted);
}
 
Example #21
Source File: ChangePrimaryGatewayTriggerEvent.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
public ChangePrimaryGatewayTriggerEvent(String selector, Long stackId, Promise<AcceptResult> accepted) {
    super(selector, stackId, accepted);
}
 
Example #22
Source File: RescheduleStatusCheckTriggerEvent.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
public RescheduleStatusCheckTriggerEvent(String selector, Long stackId, Promise<AcceptResult> accepted) {
    super(selector, stackId, accepted);
}
 
Example #23
Source File: EnvDeleteEvent.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
public EnvDeleteEvent(String selector, Long resourceId, Promise<AcceptResult> accepted, String resourceName, String resourceCrn, boolean forceDelete) {
    super(selector, resourceId, accepted, resourceName, resourceCrn);
    this.forceDelete = forceDelete;
}
 
Example #24
Source File: EphemeralClustersUpgradeTriggerEvent.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
public EphemeralClustersUpgradeTriggerEvent(String selector, Long stackId, Promise<AcceptResult> accepted) {
    super(selector, stackId, accepted);
}
 
Example #25
Source File: StackEvent.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
public StackEvent(String selector, Long stackId, Promise<AcceptResult> accepted) {
    this.selector = selector;
    this.stackId = stackId;
    this.accepted = accepted;
}
 
Example #26
Source File: StackEvent.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
@Override
public Promise<AcceptResult> accepted() {
    return accepted;
}
 
Example #27
Source File: RepairSingleMasterInstanceEvent.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
public RepairSingleMasterInstanceEvent(String selector, Long stackId, Promise<AcceptResult> accepted) {
    super(selector, stackId, accepted);
}
 
Example #28
Source File: ImageUpdateEvent.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
public ImageUpdateEvent(String selector, Long stackId, Promise<AcceptResult> accepted, StatedImage image) {
    super(selector, stackId, accepted);
    this.image = image;
}
 
Example #29
Source File: CleanupFreeIpaEvent.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
public CleanupFreeIpaEvent(String selector, Long stackId, Promise<AcceptResult> accepted, Set<String> hostNames, Set<String> ips, boolean recover) {
    super(selector, stackId, accepted);
    this.hostNames = hostNames;
    this.ips = ips;
    this.recover = recover;
}
 
Example #30
Source File: StackEvent.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
public StackEvent(String selector, Long stackId) {
    this.selector = selector;
    this.stackId = stackId;
    accepted = new Promise<>();
}