Source:
private Function<Void, CompletionStage<Void>> checkServers( List<CompletableFuture<?>> toCancelFutures, KubernetesMachineImpl machine) { final Span activeSpan = tracer.activeSpan(); return ignored -> { final Span tracingSpan = tracer.buildSpan("CheckServers").asChildOf(activeSpan).start(); TracingTags.WORKSPACE_ID.set(tracingSpan, getContext().getIdentity().getWorkspaceId()); TracingTags.MACHINE_NAME.set(tracingSpan, machine.getName()); final CompletableFuture<Void> serversAndProbesFuture = new CompletableFuture<>(); final String machineName = machine.getName(); final RuntimeIdentity runtimeId = getContext().getIdentity(); final ServersChecker serverCheck = serverCheckerFactory.create(runtimeId, machineName, machine.getServers()); final CompletableFuture<?> serversReadyFuture; LOG.debug( "Performing servers check for machine '{}' in workspace '{}'", machineName, runtimeId.getWorkspaceId()); try { serversReadyFuture = serverCheck.startAsync(new ServerReadinessHandler(machineName)); toCancelFutures.add(serversReadyFuture); serversAndProbesFuture.whenComplete( (ok, ex) -> { LOG.debug( "Servers checks done for machine '{}' in workspace '{}'", machineName, runtimeId.getWorkspaceId()); serversReadyFuture.cancel(true); }); } catch (InfrastructureException ex) { serversAndProbesFuture.completeExceptionally(ex); TracingTags.setErrorStatus(tracingSpan, ex); tracingSpan.finish(); return serversAndProbesFuture; } serversReadyFuture.whenComplete( (BiConsumer<Object, Throwable>) (ok, ex) -> { if (ex != null) { serversAndProbesFuture.completeExceptionally(ex); TracingTags.setErrorStatus(tracingSpan, ex); tracingSpan.finish(); return; } try { probeScheduler.schedule( probesFactory.getProbes(runtimeId, machineName, machine.getServers()), new ServerLivenessHandler()); } catch (InfrastructureException iex) { serversAndProbesFuture.completeExceptionally(iex); } serversAndProbesFuture.complete(null); tracingSpan.finish(); }); return serversAndProbesFuture; }; }

Target:
private Function<Void, CompletionStage<Void>> checkServers( List<CompletableFuture<?>> toCancelFutures, KubernetesMachineImpl machine) { final Span activeSpan = tracer.activeSpan(); return ignored -> { final Span tracingSpan = tracer.buildSpan(CHECK_SERVERS).asChildOf(activeSpan).start(); TracingTags.WORKSPACE_ID.set(tracingSpan, getContext().getIdentity().getWorkspaceId()); TracingTags.MACHINE_NAME.set(tracingSpan, machine.getName()); final CompletableFuture<Void> serversAndProbesFuture = new CompletableFuture<>(); final String machineName = machine.getName(); final RuntimeIdentity runtimeId = getContext().getIdentity(); final ServersChecker serverCheck = serverCheckerFactory.create(runtimeId, machineName, machine.getServers()); final CompletableFuture<?> serversReadyFuture; LOG.debug( "Performing servers check for machine '{}' in workspace '{}'", machineName, runtimeId.getWorkspaceId()); try { serversReadyFuture = serverCheck.startAsync(new ServerReadinessHandler(machineName)); toCancelFutures.add(serversReadyFuture); serversAndProbesFuture.whenComplete( (ok, ex) -> { LOG.debug( "Servers checks done for machine '{}' in workspace '{}'", machineName, runtimeId.getWorkspaceId()); serversReadyFuture.cancel(true); }); } catch (InfrastructureException ex) { serversAndProbesFuture.completeExceptionally(ex); TracingTags.setErrorStatus(tracingSpan, ex); tracingSpan.finish(); return serversAndProbesFuture; } serversReadyFuture.whenComplete( (BiConsumer<Object, Throwable>) (ok, ex) -> { if (ex != null) { serversAndProbesFuture.completeExceptionally(ex); TracingTags.setErrorStatus(tracingSpan, ex); tracingSpan.finish(); return; } try { probeScheduler.schedule( probesFactory.getProbes(runtimeId, machineName, machine.getServers()), new ServerLivenessHandler()); } catch (InfrastructureException iex) { serversAndProbesFuture.completeExceptionally(iex); } serversAndProbesFuture.complete(null); tracingSpan.finish(); }); return serversAndProbesFuture; }; }