Search in sources :

Example 16 with SafeIllegalArgumentException

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

the class PinUntilErrorNodeSelectionStrategyChannel method of.

static PinUntilErrorNodeSelectionStrategyChannel of(Optional<LimitedChannel> initialChannel, DialogueNodeSelectionStrategy strategy, List<LimitedChannel> channels, DialoguePinuntilerrorMetrics metrics, Random random, Ticker ticker, String channelName) {
    // We preserve the 'stableIndex' so that calls can be attributed to one host even across reshuffles
    List<PinChannel> pinChannels = IntStream.range(0, channels.size()).mapToObj(index -> ImmutablePinChannel.builder().delegate(channels.get(index)).stableIndex(index).build()).collect(ImmutableList.toImmutableList());
    /**
     * The *initial* list is shuffled to ensure that clients across the fleet don't all traverse the in the
     * same order.  If they did, then restarting one upstream node n would shift all its traffic (from all
     * servers) to upstream n+1. When n+1 restarts, it would all shift to n+2. This results in the disastrous
     * situation where there might be many nodes but all clients have decided to hammer one of them.
     */
    ImmutableList<PinChannel> initialShuffle = shuffleImmutableList(pinChannels, random);
    int initialPin = initialChannel.map(limitedChannel -> Math.max(0, initialShuffle.indexOf(limitedChannel))).orElse(0);
    if (strategy == DialogueNodeSelectionStrategy.PIN_UNTIL_ERROR) {
        NodeList shuffling = ReshufflingNodeList.of(initialShuffle, random, ticker, metrics, channelName);
        return new PinUntilErrorNodeSelectionStrategyChannel(shuffling, initialPin, metrics, channelName);
    } else if (strategy == DialogueNodeSelectionStrategy.PIN_UNTIL_ERROR_WITHOUT_RESHUFFLE) {
        NodeList constant = new ConstantNodeList(initialShuffle);
        return new PinUntilErrorNodeSelectionStrategyChannel(constant, initialPin, metrics, channelName);
    }
    throw new SafeIllegalArgumentException("Unsupported NodeSelectionStrategy", SafeArg.of("strategy", strategy));
}
Also used : IntStream(java.util.stream.IntStream) Ticker(com.github.benmanes.caffeine.cache.Ticker) SafeLoggerFactory(com.palantir.logsafe.logger.SafeLoggerFactory) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Random(java.util.Random) OptionalInt(java.util.OptionalInt) SafeLogger(com.palantir.logsafe.logger.SafeLogger) ArrayList(java.util.ArrayList) Meter(com.codahale.metrics.Meter) DialogueFutures(com.palantir.dialogue.futures.DialogueFutures) SafeArg(com.palantir.logsafe.SafeArg) ImmutableList(com.google.common.collect.ImmutableList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Value(org.immutables.value.Value) Duration(java.time.Duration) Endpoint(com.palantir.dialogue.Endpoint) Request(com.palantir.dialogue.Request) Nullable(javax.annotation.Nullable) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) FutureCallback(com.google.common.util.concurrent.FutureCallback) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) UnsafeArg(com.palantir.logsafe.UnsafeArg) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Response(com.palantir.dialogue.Response) Collections(java.util.Collections) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) Endpoint(com.palantir.dialogue.Endpoint)

Example 17 with SafeIllegalArgumentException

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

the class HostMetricsChannel method create.

static Channel create(Config cf, Channel channel, String uri) {
    Optional<HostEventsSink> hostEventsSink = cf.clientConf().hostEventsSink();
    if (!hostEventsSink.isPresent()) {
        return channel;
    }
    if (hostEventsSink.get().getClass().getSimpleName().equals("NoOpHostEventsSink")) {
        // special-casing for the implementation in conjure-java-runtime
        return channel;
    }
    try {
        URL parsed = new URL(uri);
        String host = parsed.getHost();
        int port = parsed.getPort() != -1 ? parsed.getPort() : parsed.getDefaultPort();
        return new HostMetricsChannel(channel, hostEventsSink.get(), cf.ticker(), cf.channelName(), host, port);
    } catch (MalformedURLException e) {
        throw new SafeIllegalArgumentException("Failed to parse URI", UnsafeArg.of("uri", uri));
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) HostEventsSink(com.palantir.conjure.java.client.config.HostEventsSink) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) URL(java.net.URL) Endpoint(com.palantir.dialogue.Endpoint)

Example 18 with SafeIllegalArgumentException

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

the class DefaultLockAndTimestampServiceFactory method createRawRemoteServices.

private static LockAndTimestampServices createRawRemoteServices(MetricsManager metricsManager, AtlasDbConfig config, Supplier<AtlasDbRuntimeConfig> runtimeConfigSupplier, UserAgent userAgent) {
    ServiceCreator creator = ServiceCreator.noPayloadLimiter(metricsManager, Refreshable.only(config.lock().orElseThrow(() -> new SafeIllegalArgumentException("lock server list config absent"))), userAgent, () -> runtimeConfigSupplier.get().remotingClient());
    LockService lockService = new RemoteLockServiceAdapter(creator.createService(NamespaceAgnosticLockRpcClient.class));
    TimestampService timeService = creator.createService(TimestampService.class);
    TimestampManagementService timestampManagementService = creator.createService(TimestampManagementService.class);
    return ImmutableLockAndTimestampServices.builder().lock(lockService).timestamp(timeService).timestampManagement(timestampManagementService).timelock(new LegacyTimelockService(timeService, lockService, TransactionManagers.LOCK_CLIENT)).build();
}
Also used : LegacyTimelockService(com.palantir.lock.impl.LegacyTimelockService) TimestampManagementService(com.palantir.timestamp.TimestampManagementService) RemoteLockServiceAdapter(com.palantir.lock.client.RemoteLockServiceAdapter) LockRefreshingLockService(com.palantir.lock.client.LockRefreshingLockService) LockService(com.palantir.lock.LockService) NamespaceAgnosticLockRpcClient(com.palantir.lock.NamespaceAgnosticLockRpcClient) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) TimestampService(com.palantir.timestamp.TimestampService) ManagedTimestampService(com.palantir.timestamp.ManagedTimestampService)

Example 19 with SafeIllegalArgumentException

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

the class CassandraCliParser method parseSystemAuthReplicationFromCqlsh.

public int parseSystemAuthReplicationFromCqlsh(String output) throws IllegalArgumentException {
    try {
        for (String line : NEWLINE_SPLITTER.split(output)) {
            if (line.contains("system_auth")) {
                Pattern replicationRegex = cassandraVersion.replicationFactorRegex();
                Matcher matcher = replicationRegex.matcher(line);
                matcher.find();
                return Integer.parseInt(matcher.group(1));
            }
        }
    } catch (Exception e) {
        log.error("Failed parsing system_auth keyspace RF", e);
        throw new SafeIllegalArgumentException("Cannot determine replication factor of system_auth keyspace");
    }
    throw new SafeIllegalArgumentException("Cannot determine replication factor of system_auth keyspace");
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException)

Example 20 with SafeIllegalArgumentException

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

the class ForkedJsonFormat method escapeText.

/**
 * Implements JSON string escaping as specified <a href="http://www.ietf.org/rfc/rfc4627.txt">here</a>.
 * <ul>
 * <li>The following characters are escaped by prefixing them with a '\' : \b,\f,\n,\r,\t,\,"</li>
 * <li>Other control characters in the range 0x0000-0x001F are escaped using the \\uXXXX notation</li>
 * <li>UTF-16 surrogate pairs are encoded using the \\uXXXX\\uXXXX notation</li>
 * <li>any other character is printed as-is</li>
 * </ul>
 */
private static String escapeText(String input) {
    StringBuilder builder = new StringBuilder(input.length());
    CharacterIterator iter = new StringCharacterIterator(input);
    for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
        switch(c) {
            case '\b':
                builder.append("\\b");
                break;
            case '\f':
                builder.append("\\f");
                break;
            case '\n':
                builder.append("\\n");
                break;
            case '\r':
                builder.append("\\r");
                break;
            case '\t':
                builder.append("\\t");
                break;
            case '\\':
                builder.append("\\\\");
                break;
            case '"':
                builder.append("\\\"");
                break;
            default:
                // Check for other control characters
                if (c >= 0x0000 && c <= 0x001F) {
                    appendEscapedUnicode(builder, c);
                } else if (Character.isHighSurrogate(c)) {
                    // Encode the surrogate pair using 2 six-character sequence (\\uXXXX\\uXXXX)
                    appendEscapedUnicode(builder, c);
                    char next = iter.next();
                    if (next == CharacterIterator.DONE) {
                        throw new SafeIllegalArgumentException("invalid unicode string: unexpected high surrogate " + "pair value without corresponding low value.");
                    }
                    appendEscapedUnicode(builder, next);
                } else {
                    // Anything else can be printed as-is
                    builder.append(c);
                }
                break;
        }
    }
    return builder.toString();
}
Also used : StringCharacterIterator(java.text.StringCharacterIterator) CharacterIterator(java.text.CharacterIterator) StringCharacterIterator(java.text.StringCharacterIterator) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException)

Aggregations

SafeIllegalArgumentException (com.palantir.logsafe.exceptions.SafeIllegalArgumentException)30 Test (org.junit.jupiter.api.Test)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 Range (com.google.common.collect.Range)3 SafeArg (com.palantir.logsafe.SafeArg)3 SafeIllegalStateException (com.palantir.logsafe.exceptions.SafeIllegalStateException)3 InetSocketAddress (java.net.InetSocketAddress)3 List (java.util.List)3 Optional (java.util.Optional)3 Meter (com.codahale.metrics.Meter)2 KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)2 TableMetadata (com.datastax.driver.core.TableMetadata)2 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)2 ImmutableRangeSet.toImmutableRangeSet (com.google.common.collect.ImmutableRangeSet.toImmutableRangeSet)2 MoreCollectors (com.google.common.collect.MoreCollectors)2 Multimap (com.google.common.collect.Multimap)2 RangeSet (com.google.common.collect.RangeSet)2 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)2