Search in sources :

Example 1 with DaemonDiagnostics

use of org.gradle.launcher.daemon.diagnostics.DaemonDiagnostics in project gradle by gradle.

the class DaemonServices method createDaemonCommandActions.

protected ImmutableList<DaemonCommandAction> createDaemonCommandActions(DaemonContext daemonContext, ProcessEnvironment processEnvironment, DaemonHealthStats healthStats, DaemonHealthCheck healthCheck, BuildExecuter buildActionExecuter, DaemonRunningStats runningStats) {
    File daemonLog = getDaemonLogFile();
    DaemonDiagnostics daemonDiagnostics = new DaemonDiagnostics(daemonLog, daemonContext.getPid());
    return ImmutableList.of(new HandleStop(get(ListenerManager.class)), new HandleCancel(), new HandleReportStatus(), new ReturnResult(), // from this point down, the daemon is 'busy'
    new StartBuildOrRespondWithBusy(daemonDiagnostics), new EstablishBuildEnvironment(processEnvironment), // from this point down, logging is sent back to the client
    new LogToClient(loggingManager, daemonDiagnostics), new LogAndCheckHealth(healthStats, healthCheck), new ForwardClientInput(), new RequestStopIfSingleUsedDaemon(), new ResetDeprecationLogger(), new WatchForDisconnection(), new ExecuteBuild(buildActionExecuter, runningStats, this));
}
Also used : LogAndCheckHealth(org.gradle.launcher.daemon.server.exec.LogAndCheckHealth) ForwardClientInput(org.gradle.launcher.daemon.server.exec.ForwardClientInput) ResetDeprecationLogger(org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger) HandleStop(org.gradle.launcher.daemon.server.api.HandleStop) RequestStopIfSingleUsedDaemon(org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon) HandleReportStatus(org.gradle.launcher.daemon.server.api.HandleReportStatus) ExecuteBuild(org.gradle.launcher.daemon.server.exec.ExecuteBuild) StartBuildOrRespondWithBusy(org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy) EstablishBuildEnvironment(org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment) WatchForDisconnection(org.gradle.launcher.daemon.server.exec.WatchForDisconnection) DaemonDiagnostics(org.gradle.launcher.daemon.diagnostics.DaemonDiagnostics) ReturnResult(org.gradle.launcher.daemon.server.exec.ReturnResult) HandleCancel(org.gradle.launcher.daemon.server.exec.HandleCancel) File(java.io.File) LogToClient(org.gradle.launcher.daemon.server.exec.LogToClient)

Example 2 with DaemonDiagnostics

use of org.gradle.launcher.daemon.diagnostics.DaemonDiagnostics in project gradle by gradle.

the class DaemonStartupCommunication method readDiagnostics.

public DaemonStartupInfo readDiagnostics(String message) {
    //Assuming the message has correct format. Not bullet proof, but seems to work ok for now.
    if (!message.startsWith(daemonGreeting())) {
        throw new IllegalArgumentException(String.format("Unexpected daemon startup message: %s", message));
    }
    try {
        String encoded = message.substring(daemonGreeting().length()).trim();
        InputStream inputStream = new EncodedStream.EncodedInput(new ByteArrayInputStream(encoded.getBytes()));
        Decoder decoder = new InputStreamBackedDecoder(inputStream);
        String pidString = decoder.readNullableString();
        String uid = decoder.readString();
        Long pid = pidString == null ? null : Long.valueOf(pidString);
        Address address = new MultiChoiceAddressSerializer().read(decoder);
        File daemonLog = new File(decoder.readString());
        return new DaemonStartupInfo(uid, address, new DaemonDiagnostics(daemonLog, pid));
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : InputStreamBackedDecoder(org.gradle.internal.serialize.InputStreamBackedDecoder) Address(org.gradle.internal.remote.Address) MultiChoiceAddress(org.gradle.internal.remote.internal.inet.MultiChoiceAddress) UncheckedIOException(org.gradle.api.UncheckedIOException) UncheckedIOException(org.gradle.api.UncheckedIOException) Decoder(org.gradle.internal.serialize.Decoder) InputStreamBackedDecoder(org.gradle.internal.serialize.InputStreamBackedDecoder) DaemonStartupInfo(org.gradle.launcher.daemon.diagnostics.DaemonStartupInfo) DaemonDiagnostics(org.gradle.launcher.daemon.diagnostics.DaemonDiagnostics) MultiChoiceAddressSerializer(org.gradle.internal.remote.internal.inet.MultiChoiceAddressSerializer)

Example 3 with DaemonDiagnostics

use of org.gradle.launcher.daemon.diagnostics.DaemonDiagnostics in project gradle by gradle.

the class DaemonClient method executeBuild.

protected Object executeBuild(Build build, DaemonClientConnection connection, BuildCancellationToken cancellationToken, BuildEventConsumer buildEventConsumer) throws DaemonInitialConnectException {
    Object result;
    try {
        LOGGER.info("Connected to daemon {}. Dispatching request {}.", connection.getDaemon(), build);
        connection.dispatch(build);
        result = connection.receive();
    } catch (StaleDaemonAddressException e) {
        LOGGER.debug("Connected to a stale daemon address.", e);
        //However, since we haven't yet started running the build, we can recover by just trying again...
        throw new DaemonInitialConnectException("Connected to a stale daemon address.", e);
    }
    if (result == null) {
        throw new DaemonInitialConnectException("The first result from the daemon was empty. Most likely the process died immediately after connection.");
    }
    LOGGER.info("Received result {} from daemon {} (build should be starting).", result, connection.getDaemon());
    DaemonDiagnostics diagnostics = null;
    if (result instanceof BuildStarted) {
        diagnostics = ((BuildStarted) result).getDiagnostics();
        result = monitorBuild(build, diagnostics, connection, cancellationToken, buildEventConsumer);
    }
    LOGGER.info("Received result {} from daemon {} (build should be done).", result, connection.getDaemon());
    connection.dispatch(new Finished());
    if (result instanceof Failure) {
        Throwable failure = ((Failure) result).getValue();
        if (failure instanceof DaemonStoppedException && cancellationToken.isCancellationRequested()) {
            LOGGER.error("Daemon was stopped to handle build cancel request.");
            throw new BuildCancelledException();
        }
        throw UncheckedException.throwAsUncheckedException(failure);
    } else if (result instanceof DaemonUnavailable) {
        throw new DaemonInitialConnectException("The daemon we connected to was unavailable: " + ((DaemonUnavailable) result).getReason());
    } else if (result instanceof Result) {
        return ((Result) result).getValue();
    } else {
        throw invalidResponse(result, build, diagnostics);
    }
}
Also used : DaemonStoppedException(org.gradle.launcher.daemon.server.api.DaemonStoppedException) DaemonDiagnostics(org.gradle.launcher.daemon.diagnostics.DaemonDiagnostics) BuildCancelledException(org.gradle.api.BuildCancelledException)

Aggregations

DaemonDiagnostics (org.gradle.launcher.daemon.diagnostics.DaemonDiagnostics)3 File (java.io.File)1 BuildCancelledException (org.gradle.api.BuildCancelledException)1 UncheckedIOException (org.gradle.api.UncheckedIOException)1 Address (org.gradle.internal.remote.Address)1 MultiChoiceAddress (org.gradle.internal.remote.internal.inet.MultiChoiceAddress)1 MultiChoiceAddressSerializer (org.gradle.internal.remote.internal.inet.MultiChoiceAddressSerializer)1 Decoder (org.gradle.internal.serialize.Decoder)1 InputStreamBackedDecoder (org.gradle.internal.serialize.InputStreamBackedDecoder)1 DaemonStartupInfo (org.gradle.launcher.daemon.diagnostics.DaemonStartupInfo)1 DaemonStoppedException (org.gradle.launcher.daemon.server.api.DaemonStoppedException)1 HandleReportStatus (org.gradle.launcher.daemon.server.api.HandleReportStatus)1 HandleStop (org.gradle.launcher.daemon.server.api.HandleStop)1 EstablishBuildEnvironment (org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment)1 ExecuteBuild (org.gradle.launcher.daemon.server.exec.ExecuteBuild)1 ForwardClientInput (org.gradle.launcher.daemon.server.exec.ForwardClientInput)1 HandleCancel (org.gradle.launcher.daemon.server.exec.HandleCancel)1 LogAndCheckHealth (org.gradle.launcher.daemon.server.exec.LogAndCheckHealth)1 LogToClient (org.gradle.launcher.daemon.server.exec.LogToClient)1 RequestStopIfSingleUsedDaemon (org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon)1