Search in sources :

Example 26 with SafeRuntimeException

use of com.palantir.logsafe.exceptions.SafeRuntimeException in project dialogue by palantir.

the class CustomStringDeserializer method deserialize.

@Override
public String deserialize(Response response) {
    try (InputStream is = response.body()) {
        String csv = new String(ByteStreams.toByteArray(is), StandardCharsets.UTF_8);
        List<String> fields = SPLITTER.splitToList(csv);
        Preconditions.checkState(fields.size() == 2);
        Preconditions.checkState("mystring".equals(fields.get(0)));
        Preconditions.checkState(!Strings.isNullOrEmpty(fields.get(1)));
        return fields.get(1);
    } catch (IOException e) {
        throw new SafeRuntimeException("Failed to serialize payload", e);
    }
}
Also used : SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 27 with SafeRuntimeException

use of com.palantir.logsafe.exceptions.SafeRuntimeException in project dialogue by palantir.

the class SimulationServer method execute.

@Override
public ListenableFuture<Response> execute(Endpoint endpoint, Request request) {
    Meter perEndpointRequests = MetricNames.requestMeter(simulation.taggedMetrics(), serverName, endpoint);
    activeRequests.inc();
    perEndpointRequests.mark();
    simulation.metricsReporter().report();
    for (ServerHandler handler : handlers) {
        long beforeNanos = simulation.clock().read();
        Optional<ListenableFuture<Response>> maybeResp = handler.maybeExecute(this, endpoint, request);
        if (!maybeResp.isPresent()) {
            continue;
        }
        ListenableFuture<Response> resp = maybeResp.get();
        DialogueFutures.addDirectCallback(resp, DialogueFutures.onSuccess(_ignored -> globalResponses.inc()));
        resp.addListener(() -> {
            activeRequests.dec();
            globalServerTimeNanos.inc(simulation.clock().read() - beforeNanos);
        }, DialogueFutures.safeDirectExecutor());
        if (log.isDebugEnabled()) {
            DialogueFutures.addDirectCallback(resp, DialogueFutures.onSuccess(result -> {
                log.debug("time={} server={} status={} id={}", Duration.ofNanos(simulation.clock().read()), serverName, result.code(), request != null ? request.headerParams().get(Benchmark.REQUEST_ID_HEADER) : null);
            }));
        }
        return resp;
    }
    log.error("No handler available for request {}", request);
    activeRequests.dec();
    return Futures.immediateFailedFuture(new SafeRuntimeException("No handler"));
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) Response(com.palantir.dialogue.Response) Logger(org.slf4j.Logger) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ListMultimap(com.google.common.collect.ListMultimap) SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) Predicate(java.util.function.Predicate) LoggerFactory(org.slf4j.LoggerFactory) Channel(com.palantir.dialogue.Channel) Function(java.util.function.Function) TimeUnit(java.util.concurrent.TimeUnit) Meter(com.codahale.metrics.Meter) TestResponse(com.palantir.dialogue.TestResponse) Futures(com.google.common.util.concurrent.Futures) DialogueFutures(com.palantir.dialogue.futures.DialogueFutures) ImmutableList(com.google.common.collect.ImmutableList) Duration(java.time.Duration) Counter(com.codahale.metrics.Counter) Endpoint(com.palantir.dialogue.Endpoint) Optional(java.util.Optional) ResponseAttachments(com.palantir.dialogue.ResponseAttachments) Request(com.palantir.dialogue.Request) Response(com.palantir.dialogue.Response) Preconditions(com.palantir.logsafe.Preconditions) InputStream(java.io.InputStream) SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) Meter(com.codahale.metrics.Meter) ListenableFuture(com.google.common.util.concurrent.ListenableFuture)

Example 28 with SafeRuntimeException

use of com.palantir.logsafe.exceptions.SafeRuntimeException in project atlasdb by palantir.

the class HikariCPConnectionManager method close.

@Override
public synchronized void close() {
    try {
        switch(state.type) {
            case ZERO:
                break;
            case NORMAL:
                if (log.isDebugEnabled()) {
                    log.debug("Closing connection pool", UnsafeArg.of("connConfig", connConfig), new SafeRuntimeException("Closing connection pool"));
                }
                state.dataSourcePool.close();
                break;
            case CLOSED:
                break;
        }
    } finally {
        state = new State(StateType.CLOSED, null, null, new Throwable("Hikari pool closed here"));
        exec.shutdownNow();
    }
}
Also used : SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException)

Example 29 with SafeRuntimeException

use of com.palantir.logsafe.exceptions.SafeRuntimeException in project atlasdb by palantir.

the class KvTableMappingService method readTableMap.

protected BiMap<TableReference, TableReference> readTableMap() {
    // TODO (jkong) Remove after PDS-117310 is resolved.
    if (log.isTraceEnabled()) {
        log.trace("Attempting to read the table mapping from the namespace table.", new SafeRuntimeException("I exist to show you the stack trace"));
    }
    BiMap<TableReference, TableReference> ret = HashBiMap.create();
    try (ClosableIterator<RowResult<Value>> range = rangeScanNamespaceTable()) {
        while (range.hasNext()) {
            RowResult<Value> row = range.next();
            String shortName = PtBytes.toString(row.getColumns().get(AtlasDbConstants.NAMESPACE_SHORT_COLUMN_BYTES).getContents());
            TableReference ref = getTableRefFromBytes(row.getRowName());
            ret.put(ref, TableReference.createWithEmptyNamespace(shortName));
        }
    }
    // TODO (jkong) Remove after PDS-117310 is resolved.
    if (log.isTraceEnabled()) {
        log.trace("Successfully read {} entries from the namespace table, to refresh the table map.", SafeArg.of("entriesRead", ret.size()), new SafeRuntimeException("I exist to show you the stack trace"));
    }
    return ret;
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) Value(com.palantir.atlasdb.keyvalue.api.Value)

Example 30 with SafeRuntimeException

use of com.palantir.logsafe.exceptions.SafeRuntimeException in project atlasdb by palantir.

the class ForkedJsonFormat method printToString.

/**
 * Like {@code print()}, but writes directly to a {@code String} and returns it.
 */
public static String printToString(Message message) {
    try {
        StringBuilder text = new StringBuilder();
        print(message, text);
        return text.toString();
    } catch (IOException e) {
        throw new SafeRuntimeException("Writing to a StringBuilder threw an IOException (should never happen).", e);
    }
}
Also used : SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) IOException(java.io.IOException)

Aggregations

SafeRuntimeException (com.palantir.logsafe.exceptions.SafeRuntimeException)43 IOException (java.io.IOException)13 Test (org.junit.jupiter.api.Test)7 Path (java.nio.file.Path)6 Response (com.palantir.dialogue.Response)5 ImmutableMap (com.google.common.collect.ImmutableMap)3 TestResponse (com.palantir.dialogue.TestResponse)3 DefaultInvocationContext (com.palantir.tritium.event.DefaultInvocationContext)3 InvocationContext (com.palantir.tritium.event.InvocationContext)3 File (java.io.File)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 ImmutableList (com.google.common.collect.ImmutableList)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 Value (com.palantir.atlasdb.keyvalue.api.Value)2 DisableNamespacesResponse (com.palantir.atlasdb.timelock.api.DisableNamespacesResponse)2 SuccessfulDisableNamespacesResponse (com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse)2 UnsuccessfulDisableNamespacesResponse (com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse)2 Channel (com.palantir.dialogue.Channel)2