Search in sources :

Example 6 with SafeIllegalArgumentException

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));
    }
}
Also used : Range(com.google.common.collect.Range) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException)

Example 7 with SafeIllegalArgumentException

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))));
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) RangeSet(com.google.common.collect.RangeSet) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) HashMap(java.util.HashMap) ImmutableRangeSet.toImmutableRangeSet(com.google.common.collect.ImmutableRangeSet.toImmutableRangeSet) Multimap(com.google.common.collect.Multimap) LightweightOppToken(com.palantir.atlasdb.keyvalue.cassandra.LightweightOppToken) SafeArg(com.palantir.logsafe.SafeArg) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) LoggingArgs(com.palantir.atlasdb.logging.LoggingArgs) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) TableMetadata(com.datastax.driver.core.TableMetadata) ImmutableSet(com.google.common.collect.ImmutableSet) KeyedStream(com.palantir.common.streams.KeyedStream) Predicate(java.util.function.Predicate) MoreCollectors(com.google.common.collect.MoreCollectors) Collection(java.util.Collection) Range(com.google.common.collect.Range) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) Set(java.util.Set) Namespace(com.palantir.atlasdb.timelock.api.Namespace) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata) TreeMap(java.util.TreeMap) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Preconditions(com.palantir.logsafe.Preconditions) SortedMap(java.util.SortedMap) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException)

Example 8 with SafeIllegalArgumentException

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;
}
Also used : KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) ZonedDateTime(java.time.ZonedDateTime) Instant(java.time.Instant) KeyValueServicePuncherStore(com.palantir.atlasdb.cleaner.KeyValueServicePuncherStore) PuncherStore(com.palantir.atlasdb.cleaner.PuncherStore) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException)

Example 9 with SafeIllegalArgumentException

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;
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) HeldLocksToken(com.palantir.lock.HeldLocksToken) SimpleHeldLocksToken(com.palantir.lock.SimpleHeldLocksToken) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) Nullable(javax.annotation.Nullable)

Example 10 with SafeIllegalArgumentException

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.");
}
Also used : ObjectTypeDefinition(com.palantir.conjure.parser.types.complex.ObjectTypeDefinition) EnumTypeDefinition(com.palantir.conjure.parser.types.complex.EnumTypeDefinition) EnumValueDefinition(com.palantir.conjure.parser.types.complex.EnumValueDefinition) UnionTypeDefinition(com.palantir.conjure.parser.types.complex.UnionTypeDefinition) File(java.io.File) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) AliasTypeDefinition(com.palantir.conjure.parser.types.reference.AliasTypeDefinition) Test(org.junit.jupiter.api.Test)

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