use of com.palantir.logsafe.exceptions.SafeIllegalArgumentException in project atlasdb by palantir.
the class ClusterMetadataUtils method findLatestEndingRange.
// VisibleForTesting
public static Range<LightweightOppToken> findLatestEndingRange(Range<LightweightOppToken> range1, Range<LightweightOppToken> range2) {
Preconditions.checkArgument(LightweightOppToken.getLowerExclusive(range1).equals(LightweightOppToken.getLowerExclusive(range2)), "Expects token ranges to have the same start token", SafeArg.of("range1", range1), SafeArg.of("range2", range2));
Set<Range<LightweightOppToken>> wrapAroundTokenRanges = Stream.of(range1, range2).filter(Predicate.not(Range::hasUpperBound)).collect(Collectors.toSet());
// If any token ranges are wraparound ranges, the non-wraparound ranges cannot possibly be the longest range
if (wrapAroundTokenRanges.size() == 1) {
return wrapAroundTokenRanges.iterator().next();
}
if (range1.contains(range2.upperEndpoint())) {
return range1;
} else if (range2.contains(range1.upperEndpoint())) {
return range2;
} else {
throw new SafeIllegalArgumentException("Cannot find max token range", SafeArg.of("tokenRange1", range1), SafeArg.of("tokenRange2", range2));
}
}
use of com.palantir.logsafe.exceptions.SafeIllegalArgumentException in project atlasdb by palantir.
the class ClusterMetadataUtils method getTableMetadata.
public static TableMetadata getTableMetadata(CqlMetadata metadata, Namespace namespace, String table) {
KeyspaceMetadata keyspaceMetadata = metadata.getKeyspaceMetadata(namespace);
Optional<TableMetadata> maybeTable = keyspaceMetadata.getTables().stream().filter(tableMetadata -> tableMetadata.getName().equals(table)).collect(MoreCollectors.toOptional());
return maybeTable.orElseThrow(() -> new SafeIllegalArgumentException("Can't find table", SafeArg.of("keyspace", namespace), LoggingArgs.tableRef("table", TableReference.fromString(table))));
}
use of com.palantir.logsafe.exceptions.SafeIllegalArgumentException in project atlasdb by palantir.
the class ReadPunchTableCommand method execute.
@Override
public int execute(AtlasDbServices services) {
if (epochTime == null) {
throw new SafeIllegalArgumentException("Required option '-e' is missing");
}
if (epochTime < 0) {
throw new SafeIllegalArgumentException("Option '-e' should be a positive long, as epoch time" + " is never negative.");
}
Instant epochTimeInstant = Instant.ofEpochSecond(epochTime);
ZonedDateTime date = ZonedDateTime.ofInstant(epochTimeInstant, ZoneOffset.UTC);
printer.info("Input {} in epoch millis is {}", SafeArg.of("epochMillis", epochTime), SafeArg.of("date", date.toString()));
KeyValueService keyValueService = services.getKeyValueService();
PuncherStore puncherStore = KeyValueServicePuncherStore.create(keyValueService, false);
Long value = puncherStore.get(epochTime);
printer.info("The first timestamp before {} is {}", SafeArg.of("date", date.toString()), SafeArg.of("timestamp", value));
return 0;
}
use of com.palantir.logsafe.exceptions.SafeIllegalArgumentException in project atlasdb by palantir.
the class LockServiceImpl method getTokens.
@Override
public Set<HeldLocksToken> getTokens(LockClient client) {
com.palantir.logsafe.Preconditions.checkNotNull(client);
if (client.isAnonymous()) {
throw new SafeIllegalArgumentException("client must not be anonymous");
} else if (client.equals(INTERNAL_LOCK_GRANT_CLIENT)) {
throw new SafeIllegalArgumentException("Illegal client!");
}
ImmutableSet.Builder<HeldLocksToken> tokens = ImmutableSet.builder();
synchronized (lockClientMultimap) {
for (HeldLocksToken token : lockClientMultimap.get(client)) {
@Nullable HeldLocks<HeldLocksToken> heldLocks = heldLocksTokenMap.get(token);
if ((heldLocks != null) && !isFrozen(heldLocks.locks.getKeys())) {
tokens.add(token);
}
}
}
ImmutableSet<HeldLocksToken> tokenSet = tokens.build();
if (log.isTraceEnabled()) {
log.trace(".getTokens({}) returns {}", UnsafeArg.of("client", client), UnsafeArg.of("tokens", Collections2.transform(tokenSet, LockServiceImpl::tokenToId)));
}
return tokenSet;
}
use of com.palantir.logsafe.exceptions.SafeIllegalArgumentException in project conjure by palantir.
the class ConjureParserTest method testConjureEnumValueDeprecation.
@Test
public void testConjureEnumValueDeprecation() {
ConjureSourceFile conjure = ConjureParser.parse(new File("src/test/resources/example-deprecation.yml"));
EnumTypeDefinition enumType = conjure.types().definitions().objects().get(TypeName.of("EnumWithDeprecatedValues")).visit(new TypeDefinitionVisitor<EnumTypeDefinition>() {
@Override
public EnumTypeDefinition visit(AliasTypeDefinition _def) {
throw new SafeIllegalArgumentException("Expected EnumTypeDefinition");
}
@Override
public EnumTypeDefinition visit(EnumTypeDefinition def) {
return def;
}
@Override
public EnumTypeDefinition visit(ObjectTypeDefinition _def) {
throw new SafeIllegalArgumentException("Expected EnumTypeDefinition");
}
@Override
public EnumTypeDefinition visit(UnionTypeDefinition _def) {
throw new SafeIllegalArgumentException("Expected EnumTypeDefinition");
}
});
EnumValueDefinition one = enumType.values().get(0);
EnumValueDefinition two = enumType.values().get(1);
assertThat(one.value()).isEqualTo("ONE");
assertThat(one.deprecated()).isNotPresent();
assertThat(two.value()).isEqualTo("TWO");
assertThat(two.deprecated()).hasValue("Prefer ONE.");
}
Aggregations