Java Code Examples for reactor.core.publisher.Flux#concatWith()

The following examples show how to use reactor.core.publisher.Flux#concatWith() . 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: AbstractServerHttpResponse.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Apply {@link #beforeCommit(Supplier) beforeCommit} actions, apply the
 * response status and headers/cookies, and write the response body.
 * @param writeAction the action to write the response body (may be {@code null})
 * @return a completion publisher
 */
protected Mono<Void> doCommit(@Nullable Supplier<? extends Mono<Void>> writeAction) {
	if (!this.state.compareAndSet(State.NEW, State.COMMITTING)) {
		return Mono.empty();
	}
	this.commitActions.add(() ->
			Mono.fromRunnable(() -> {
				applyStatusCode();
				applyHeaders();
				applyCookies();
				this.state.set(State.COMMITTED);
			}));
	if (writeAction != null) {
		this.commitActions.add(writeAction);
	}
	Flux<Void> commit = Flux.empty();
	for (Supplier<? extends Mono<Void>> action : this.commitActions) {
		commit = commit.concatWith(action.get());
	}
	return commit.then();
}
 
Example 2
Source File: CtrlSnapshotCrtApiCallHandler.java    From linstor-server with GNU General Public License v3.0 6 votes vote down vote up
private Flux<ApiCallRc> resumeResourceInTransaction(ResourceName rscName, SnapshotName snapshotName)
{
    SnapshotDefinition snapshotDfn = ctrlApiDataLoader.loadSnapshotDfn(rscName, snapshotName, true);

    for (Snapshot snapshot : getAllSnapshotsPrivileged(snapshotDfn))
    {
        unsetSuspendResourcePrivileged(snapshot);
    }

    ResourceDefinition rscDfn = ctrlApiDataLoader.loadRscDfn(rscName, true);
    resumeIoPrivileged(rscDfn);

    ctrlTransactionHelper.commit();

    Flux<ApiCallRc> satelliteUpdateResponses =
        ctrlSatelliteUpdateCaller.updateSatellites(snapshotDfn, notConnectedError())
            .concatWith(ctrlSatelliteUpdateCaller.updateSatellites(rscDfn, notConnectedError(), Flux.empty()))
            .transform(responses -> CtrlResponseUtils.combineResponses(
                responses,
                rscName,
                "Resumed IO of {1} on {0} after snapshot"
            ));

    return satelliteUpdateResponses
        .concatWith(removeInProgressSnapshots(rscName, snapshotName));
}
 
Example 3
Source File: R2dbcServiceInstanceMetricsRepository.java    From cf-butler with Apache License 2.0 5 votes vote down vote up
public Flux<Tuple2<String, Long>> byService() {
	String sqlup = "select type, count(type) as cnt from service_instance_detail where type = 'user_provided_service_instance' group by type";
	Flux<Tuple2<String, Long>> ups = client.execute(sqlup)
				.map((row, metadata)
						-> Tuples.of("user-provided", Defaults.getColumnValueOrDefault(row, "cnt", Long.class, 0L)))
				.all()
				.defaultIfEmpty(Tuples.of("user-provided", 0L));
	String sqlms = "select service, count(service) as cnt from service_instance_detail where type = 'managed_service_instance' group by service";
	Flux<Tuple2<String, Long>> ms = client.execute(sqlms)
				.map((row, metadata)
						-> Tuples.of(Defaults.getColumnValueOrDefault(row, "service", String.class, "managed"), Defaults.getColumnValueOrDefault(row, "cnt", Long.class, 0L)))
				.all()
				.defaultIfEmpty(Tuples.of("managed", 0L));
	return ups.concatWith(ms);
}
 
Example 4
Source File: PhysicalStorage.java    From linstor-server with GNU General Public License v3.0 4 votes vote down vote up
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("{nodeName}")
public void createDevicePool(
    @Context Request request,
    @Suspended AsyncResponse asyncResponse,
    @PathParam("nodeName") String nodeName,
    String jsonData
)
{
    try
    {
        JsonGenTypes.PhysicalStorageCreate createData = objectMapper
            .readValue(jsonData, JsonGenTypes.PhysicalStorageCreate.class);

        // check if with_storage_pool is given and if storage pool name is valid, before we do unneeded create/del
        if (createData.with_storage_pool != null)
        {
            LinstorParsingUtils.asStorPoolName(createData.with_storage_pool.name);
        }

        final String poolName = CtrlPhysicalStorageApiCallHandler.getDevicePoolName(
            createData.pool_name,
            createData.device_paths
        );

        final DeviceProviderKind deviceProviderKind = LinstorParsingUtils.asProviderKind(createData.provider_kind);
        Flux<ApiCallRc> responses = physicalStorageApiCallHandler.createDevicePool(
            nodeName,
            createData.device_paths,
            deviceProviderKind,
            LinstorParsingUtils.asRaidLevel(createData.raid_level),
            poolName,
            createData.vdo_enable,
            createData.vdo_logical_size_kib,
            createData.vdo_slab_size_kib
        ).subscriberContext(requestHelper.createContext(ApiConsts.API_CREATE_DEVICE_POOL, request));

        if (createData.with_storage_pool != null)
        {
            Map<String, String> storPoolProps = deviceProviderToStorPoolProperty(deviceProviderKind, poolName);
            storPoolProps.putAll(createData.with_storage_pool.props);
            responses = responses.concatWith(
                storPoolCrtApiCallHandler.createStorPool(
                    nodeName,
                    createData.with_storage_pool.name,
                    deviceProviderKind,
                    null,
                    storPoolProps,
                    physicalStorageApiCallHandler.deleteDevicePool(
                        nodeName,
                        createData.device_paths,
                        deviceProviderKind,
                        poolName
                    )
                ).subscriberContext(requestHelper.createContext(ApiConsts.API_CRT_STOR_POOL, request))
            );
        }

        requestHelper.doFlux(
            asyncResponse,
            ApiCallRcRestUtils.mapToMonoResponse(responses, Response.Status.CREATED)
        );
    }
    catch (IOException ioExc)
    {
        ApiCallRcRestUtils.handleJsonParseException(ioExc, asyncResponse);
    }
}
 
Example 5
Source File: CtrlSnapshotCrtApiCallHandler.java    From linstor-server with GNU General Public License v3.0 4 votes vote down vote up
private Flux<ApiCallRc> abortSnapshotInTransaction(
    ResourceName rscName,
    SnapshotName snapshotName,
    Throwable exception
)
{
    SnapshotDefinition snapshotDfn = ctrlApiDataLoader.loadSnapshotDfn(rscName, snapshotName, true);

    SnapshotDefinition.Flags flag = exception instanceof CtrlResponseUtils.DelayedApiRcException &&
        isFailNotConnected((CtrlResponseUtils.DelayedApiRcException) exception) ?
            SnapshotDefinition.Flags.FAILED_DISCONNECT : SnapshotDefinition.Flags.FAILED_DEPLOYMENT;

    enableFlagPrivileged(snapshotDfn, flag);
    unsetInCreationPrivileged(snapshotDfn);
    ResourceDefinition rscDfn = snapshotDfn.getResourceDefinition();
    resumeIoPrivileged(rscDfn);

    ctrlTransactionHelper.commit();

    Flux<ApiCallRc> satelliteUpdateResponses =
        ctrlSatelliteUpdateCaller.updateSatellites(snapshotDfn, notConnectedCannotAbort())
            .transform(responses -> CtrlResponseUtils.combineResponses(
                responses,
                rscName,
                "Aborted snapshot of {1} on {0}"
            ))
            .concatWith(
                ctrlSatelliteUpdateCaller.updateSatellites(rscDfn, Flux.empty())
                    .transform(
                        responses -> CtrlResponseUtils.combineResponses(
                            responses,
                            rscName,
                            "Resumed IO of {1} on {0} after failed snapshot"
                        )
                    )
            )
            .onErrorResume(CtrlResponseUtils.DelayedApiRcException.class, ignored -> Flux.empty());

    return satelliteUpdateResponses
        .concatWith(Flux.error(exception));
}
 
Example 6
Source File: CtrlRscDeleteApiCallHandler.java    From linstor-server with GNU General Public License v3.0 4 votes vote down vote up
private Flux<ApiCallRc> deleteResourceInTransaction(String nodeNameStr, String rscNameStr, ResponseContext context)
{
    Resource rsc = ctrlApiDataLoader.loadRsc(nodeNameStr, rscNameStr, false);

    if (rsc == null)
    {
        throw new ApiRcException(ApiCallRcImpl.simpleEntry(
            ApiConsts.WARN_NOT_FOUND,
            getRscDescription(nodeNameStr, rscNameStr) + " not found."
        ));
    }

    Set<NodeName> nodeNamesToDelete = new TreeSet<>();
    NodeName nodeName = rsc.getNode().getName();
    ResourceName rscName = rsc.getDefinition().getName();

    ctrlRscDeleteApiHelper.ensureNotInUse(rsc);

    ensureNotLastDisk(rscName, rsc);

    failIfDependentSnapshot(rsc);

    ctrlRscDeleteApiHelper.markDeletedWithVolumes(rsc);
    nodeNamesToDelete.add(nodeName);

    ApiCallRcImpl responses = new ApiCallRcImpl();
    AutoHelperResult autoResult = autoHelper.manage(
        responses,
        context,
        rsc.getDefinition()
    );

    ctrlTransactionHelper.commit();


    Flux<ApiCallRc> flux;
    if (!autoResult.isPreventUpdateSatellitesForResourceDelete())
    {
        String descriptionFirstLetterCaps = firstLetterCaps(getRscDescription(rsc));
        responses.addEntries(
            ApiCallRcImpl.singletonApiCallRc(
                ApiCallRcImpl
                    .entryBuilder(
                        ApiConsts.DELETED,
                        descriptionFirstLetterCaps + " marked for deletion."
                    )
                    .setDetails(descriptionFirstLetterCaps + " UUID is: " + rsc.getUuid())
                    .build()
            )
        );
        flux = Flux.just(responses);

        flux = flux.concatWith(
            ctrlRscDeleteApiHelper.updateSatellitesForResourceDelete(nodeNamesToDelete, rscName)
        );
    }
    else
    {
        flux = Flux.just(responses);
    }
    flux = flux.concatWith(autoResult.getFlux());

    return flux;
}
 
Example 7
Source File: MonoResultTest.java    From crnk-framework with Apache License 2.0 4 votes vote down vote up
public <T> Flux<T> appendBoomError(Flux<T> source) {
	return source.concatWith(Mono.error(new IllegalArgumentException("boom")));
}