Source:
<code>private Function<Void, CompletionStage<Void>> checkServers( List<CompletableFuture<?>> toCancelFutures, KubernetesMachineImpl machine) { final Span activeSpan = tracer == null ? null : tracer.activeSpan(); return ignored -> { final Span tracingSpan = tracer == null <START> ? null <END> : tracer .buildSpan("CheckServers") .withTag( TracingTags.WORKSPACE_ID.getKey(), getContext().getIdentity().getWorkspaceId()) .withTag(TracingTags.MACHINE_NAME.getKey(), machine.getName()) .asChildOf(activeSpan) .start(); 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); finishSpanAsFailure(tracingSpan, ex.getMessage()); return serversAndProbesFuture; } serversReadyFuture.whenComplete( (BiConsumer<Object, Throwable>) (ok, ex) -> { if (ex != null) { serversAndProbesFuture.completeExceptionally(ex); return; } try { probeScheduler.schedule( probesFactory.getProbes(runtimeId, machineName, machine.getServers()), new ServerLivenessHandler()); } catch (InfrastructureException iex) { serversAndProbesFuture.completeExceptionally(iex); } serversAndProbesFuture.complete(null); if (tracingSpan != null) { tracingSpan.finish(); } }); return serversAndProbesFuture; }; }</code><technical_language>This complicates code significantly. move a separate method</technical_language>

Target:
private Function<Void, CompletionStage<Void>> checkServers( List<CompletableFuture<?>> toCancelFutures, KubernetesMachineImpl machine) { final Span activeSpan = tracerUtil.getActiveSpan(); return ignored -> { final Span tracingSpan = tracerUtil.buildSpan( "CheckServers", activeSpan, getContext().getIdentity().getWorkspaceId(), 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); tracerUtil.finishSpanAsFailure(tracingSpan, ex.getMessage()); return serversAndProbesFuture; } serversReadyFuture.whenComplete( (BiConsumer<Object, Throwable>) (ok, ex) -> { if (ex != null) { serversAndProbesFuture.completeExceptionally(ex); return; } try { probeScheduler.schedule( probesFactory.getProbes(runtimeId, machineName, machine.getServers()), new ServerLivenessHandler()); } catch (InfrastructureException iex) { serversAndProbesFuture.completeExceptionally(iex); } serversAndProbesFuture.complete(null); if (ex == null) { tracerUtil.finishSpan(tracingSpan); } else { tracerUtil.finishSpanAsFailure(tracingSpan, ex.getMessage()); } }); return serversAndProbesFuture; }; }