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));
}
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));
}
}
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();
}
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");
}
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();
}
Aggregations