Search in sources :

Example 36 with NonNull

use of lombok.NonNull in project testcontainers-java by testcontainers.

the class SimpleMySQLTest method performQuery.

@NonNull
protected ResultSet performQuery(MySQLContainer containerRule, String sql) throws SQLException {
    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setJdbcUrl(containerRule.getJdbcUrl());
    hikariConfig.setUsername(containerRule.getUsername());
    hikariConfig.setPassword(containerRule.getPassword());
    HikariDataSource ds = new HikariDataSource(hikariConfig);
    Statement statement = ds.getConnection().createStatement();
    statement.execute(sql);
    ResultSet resultSet = statement.getResultSet();
    resultSet.next();
    return resultSet;
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) HikariConfig(com.zaxxer.hikari.HikariConfig) NonNull(lombok.NonNull)

Example 37 with NonNull

use of lombok.NonNull in project testcontainers-java by testcontainers.

the class SimpleMariaDBTest method performQuery.

@NonNull
protected ResultSet performQuery(MariaDBContainer containerRule, String sql) throws SQLException {
    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setJdbcUrl(containerRule.getJdbcUrl());
    hikariConfig.setUsername(containerRule.getUsername());
    hikariConfig.setPassword(containerRule.getPassword());
    HikariDataSource ds = new HikariDataSource(hikariConfig);
    Statement statement = ds.getConnection().createStatement();
    statement.execute(sql);
    ResultSet resultSet = statement.getResultSet();
    resultSet.next();
    return resultSet;
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) HikariConfig(com.zaxxer.hikari.HikariConfig) NonNull(lombok.NonNull)

Example 38 with NonNull

use of lombok.NonNull in project pravega by pravega.

the class TokenVerifierImpl method verifyToken.

@Override
public JsonWebToken verifyToken(@NonNull String resource, String token, @NonNull AuthHandler.Permissions expectedLevel) throws TokenExpiredException, InvalidTokenException, InvalidClaimException, TokenException {
    if (Strings.isNullOrEmpty(token)) {
        throw new InvalidTokenException("Token is null or empty");
    }
    // All key value pairs inside the payload are returned, including standard fields such as sub (for subject),
    // aud (for audience), iat, exp, as well as custom fields of the form "<resource> -> <permission>" set by
    // Pravega.
    JsonWebToken jwt = JwtParser.parse(token, tokenSigningKey);
    Map<String, Object> permissionsByResource = jwt.getPermissionsByResource();
    Optional<Map.Entry<String, Object>> matchingClaim = permissionsByResource.entrySet().stream().filter(entry -> resourceMatchesClaimKey(entry.getKey(), resource) && expectedLevel.compareTo(AuthHandler.Permissions.valueOf(entry.getValue().toString())) <= 0).findFirst();
    if (!matchingClaim.isPresent()) {
        log.debug(String.format("No matching claim found for resource [%s] and permission [%s] in token.", resource, expectedLevel));
        throw new InvalidClaimException(String.format("No matching claim found for resource: [%s] and permission: [%s] in the delegation token.", resource, expectedLevel));
    }
    return jwt;
}
Also used : InvalidClaimException(io.pravega.auth.InvalidClaimException) TokenExpiredException(io.pravega.auth.TokenExpiredException) NonNull(lombok.NonNull) AuthHandler(io.pravega.auth.AuthHandler) Exceptions(io.pravega.common.Exceptions) JsonWebToken(io.pravega.shared.security.token.JsonWebToken) Strings(com.google.common.base.Strings) Slf4j(lombok.extern.slf4j.Slf4j) JwtParser(io.pravega.shared.security.token.JwtParser) InvalidTokenException(io.pravega.auth.InvalidTokenException) Map(java.util.Map) TokenException(io.pravega.auth.TokenException) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Pattern(java.util.regex.Pattern) InvalidTokenException(io.pravega.auth.InvalidTokenException) InvalidClaimException(io.pravega.auth.InvalidClaimException) JsonWebToken(io.pravega.shared.security.token.JsonWebToken)

Example 39 with NonNull

use of lombok.NonNull in project pravega by pravega.

the class FixedKeyLengthTableSegmentLayout method get.

@Override
CompletableFuture<List<TableEntry>> get(@NonNull DirectSegmentAccess segment, @NonNull List<BufferView> keys, TimeoutTimer timer) {
    val segmentInfo = segment.getInfo();
    ensureSegmentType(segmentInfo.getName(), segmentInfo.getType());
    val attributes = keys.stream().map(key -> {
        ensureValidKeyLength(segmentInfo.getName(), key.getLength());
        return AttributeId.from(key.getCopy());
    }).collect(Collectors.toList());
    logRequest("get", segmentInfo.getName(), keys.size());
    return getByAttributes(segment, attributes, timer);
}
Also used : lombok.val(lombok.val) DynamicAttributeValue(io.pravega.segmentstore.contracts.DynamicAttributeValue) TableSegmentConfig(io.pravega.segmentstore.contracts.tables.TableSegmentConfig) SneakyThrows(lombok.SneakyThrows) RequiredArgsConstructor(lombok.RequiredArgsConstructor) RevisionDataInput(io.pravega.common.io.serialization.RevisionDataInput) IteratorArgs(io.pravega.segmentstore.contracts.tables.IteratorArgs) UpdateableSegmentMetadata(io.pravega.segmentstore.server.UpdateableSegmentMetadata) SegmentProperties(io.pravega.segmentstore.contracts.SegmentProperties) ArrayView(io.pravega.common.util.ArrayView) AttributeUpdate(io.pravega.segmentstore.contracts.AttributeUpdate) BufferView(io.pravega.common.util.BufferView) Duration(java.time.Duration) Map(java.util.Map) RevisionDataOutput(io.pravega.common.io.serialization.RevisionDataOutput) AsyncReadResultProcessor(io.pravega.segmentstore.server.reading.AsyncReadResultProcessor) VersionedSerializer(io.pravega.common.io.serialization.VersionedSerializer) Attributes(io.pravega.segmentstore.contracts.Attributes) TableKey(io.pravega.segmentstore.contracts.tables.TableKey) NonNull(lombok.NonNull) Collection(java.util.Collection) CompletionException(java.util.concurrent.CompletionException) DynamicAttributeUpdate(io.pravega.segmentstore.contracts.DynamicAttributeUpdate) Collectors(java.util.stream.Collectors) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) TableSegmentInfo(io.pravega.segmentstore.contracts.tables.TableSegmentInfo) ByteArraySegment(io.pravega.common.util.ByteArraySegment) Builder(lombok.Builder) DelayedProcessor(io.pravega.common.concurrent.DelayedProcessor) WriterSegmentProcessor(io.pravega.segmentstore.server.WriterSegmentProcessor) Futures(io.pravega.common.concurrent.Futures) TableAttributes(io.pravega.segmentstore.contracts.tables.TableAttributes) Getter(lombok.Getter) Exceptions(io.pravega.common.Exceptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) BadAttributeUpdateException(io.pravega.segmentstore.contracts.BadAttributeUpdateException) AtomicReference(java.util.concurrent.atomic.AtomicReference) BadKeyVersionException(io.pravega.segmentstore.contracts.tables.BadKeyVersionException) ArrayList(java.util.ArrayList) SegmentType(io.pravega.segmentstore.contracts.SegmentType) IteratorItem(io.pravega.segmentstore.contracts.tables.IteratorItem) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) AttributeIterator(io.pravega.segmentstore.server.AttributeIterator) StreamSegmentTruncatedException(io.pravega.segmentstore.contracts.StreamSegmentTruncatedException) IteratorState(io.pravega.segmentstore.contracts.tables.IteratorState) TimeoutTimer(io.pravega.common.TimeoutTimer) KeyNotExistsException(io.pravega.segmentstore.contracts.tables.KeyNotExistsException) AttributeId(io.pravega.segmentstore.contracts.AttributeId) lombok.val(lombok.val) AsyncIterator(io.pravega.common.util.AsyncIterator) IOException(java.io.IOException) Beta(com.google.common.annotations.Beta) ObjectBuilder(io.pravega.common.ObjectBuilder) DirectSegmentAccess(io.pravega.segmentstore.server.DirectSegmentAccess) AttributeUpdateCollection(io.pravega.segmentstore.contracts.AttributeUpdateCollection) Data(lombok.Data) Preconditions(com.google.common.base.Preconditions) AttributeUpdateType(io.pravega.segmentstore.contracts.AttributeUpdateType) AllArgsConstructor(lombok.AllArgsConstructor) TableEntry(io.pravega.segmentstore.contracts.tables.TableEntry) Collections(java.util.Collections)

Example 40 with NonNull

use of lombok.NonNull in project pravega by pravega.

the class HashTableSegmentLayout method entryDeltaIterator.

@Override
AsyncIterator<IteratorItem<TableEntry>> entryDeltaIterator(@NonNull DirectSegmentAccess segment, long fromPosition, Duration fetchTimeout) {
    val segmentInfo = segment.getInfo();
    ensureSegmentType(segmentInfo.getName(), segmentInfo.getType());
    Preconditions.checkArgument(fromPosition <= segmentInfo.getLength(), "fromPosition (%s) can not exceed the length (%s) of the TableSegment.", fromPosition, segmentInfo.getLength());
    logRequest("entryDeltaIterator", segment.getSegmentId(), fromPosition);
    long compactionOffset = segmentInfo.getAttributes().getOrDefault(TableAttributes.COMPACTION_OFFSET, 0L);
    // All of the most recent keys will exist beyond the compactionOffset.
    long startOffset = Math.max(fromPosition, compactionOffset);
    // We should clear if the starting position may have been truncated out due to compaction.
    boolean shouldClear = fromPosition < compactionOffset;
    // Maximum length of the TableSegment we want to read until.
    int maxBytesToRead = (int) (segmentInfo.getLength() - startOffset);
    TableEntryDeltaIterator.ConvertResult<IteratorItem<TableEntry>> converter = item -> CompletableFuture.completedFuture(new IteratorItemImpl<TableEntry>(item.getKey().serialize(), Collections.singletonList(item.getValue())));
    return TableEntryDeltaIterator.<IteratorItem<TableEntry>>builder().segment(segment).entrySerializer(serializer).executor(executor).maxBytesToRead(maxBytesToRead).startOffset(startOffset).currentBatchOffset(fromPosition).fetchTimeout(fetchTimeout).resultConverter(converter).shouldClear(shouldClear).build();
}
Also used : lombok.val(lombok.val) TableAttributes(io.pravega.segmentstore.contracts.tables.TableAttributes) TableSegmentConfig(io.pravega.segmentstore.contracts.tables.TableSegmentConfig) Getter(lombok.Getter) OperationPriority(io.pravega.segmentstore.server.logs.operations.OperationPriority) SneakyThrows(lombok.SneakyThrows) RequiredArgsConstructor(lombok.RequiredArgsConstructor) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) RevisionDataInput(io.pravega.common.io.serialization.RevisionDataInput) Function(java.util.function.Function) IteratorArgs(io.pravega.segmentstore.contracts.tables.IteratorArgs) UpdateableSegmentMetadata(io.pravega.segmentstore.server.UpdateableSegmentMetadata) ArrayList(java.util.ArrayList) ArrayView(io.pravega.common.util.ArrayView) SegmentMetadata(io.pravega.segmentstore.server.SegmentMetadata) SegmentType(io.pravega.segmentstore.contracts.SegmentType) IteratorItem(io.pravega.segmentstore.contracts.tables.IteratorItem) Runnables(com.google.common.util.concurrent.Runnables) BufferView(io.pravega.common.util.BufferView) Duration(java.time.Duration) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) RevisionDataOutput(io.pravega.common.io.serialization.RevisionDataOutput) VersionedSerializer(io.pravega.common.io.serialization.VersionedSerializer) IteratorState(io.pravega.segmentstore.contracts.tables.IteratorState) Attributes(io.pravega.segmentstore.contracts.Attributes) TableKey(io.pravega.segmentstore.contracts.tables.TableKey) TimeoutTimer(io.pravega.common.TimeoutTimer) NonNull(lombok.NonNull) Collection(java.util.Collection) AttributeId(io.pravega.segmentstore.contracts.AttributeId) lombok.val(lombok.val) AsyncIterator(io.pravega.common.util.AsyncIterator) IOException(java.io.IOException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ObjectBuilder(io.pravega.common.ObjectBuilder) DirectSegmentAccess(io.pravega.segmentstore.server.DirectSegmentAccess) List(java.util.List) TableSegmentInfo(io.pravega.segmentstore.contracts.tables.TableSegmentInfo) Preconditions(com.google.common.base.Preconditions) IllegalDataFormatException(io.pravega.common.util.IllegalDataFormatException) WriterSegmentProcessor(io.pravega.segmentstore.server.WriterSegmentProcessor) TableEntry(io.pravega.segmentstore.contracts.tables.TableEntry) Collections(java.util.Collections) Futures(io.pravega.common.concurrent.Futures) CacheManager(io.pravega.segmentstore.server.CacheManager) TableEntry(io.pravega.segmentstore.contracts.tables.TableEntry) IteratorItem(io.pravega.segmentstore.contracts.tables.IteratorItem)

Aggregations

NonNull (lombok.NonNull)52 List (java.util.List)31 Collectors (java.util.stream.Collectors)22 Map (java.util.Map)20 Slf4j (lombok.extern.slf4j.Slf4j)18 ArrayList (java.util.ArrayList)17 Collection (java.util.Collection)17 HashMap (java.util.HashMap)16 lombok.val (lombok.val)14 Collections (java.util.Collections)13 Duration (java.time.Duration)11 Nullable (javax.annotation.Nullable)11 TimeoutTimer (io.pravega.common.TimeoutTimer)10 Set (java.util.Set)10 CompletableFuture (java.util.concurrent.CompletableFuture)10 Function (java.util.function.Function)10 Futures (io.pravega.common.concurrent.Futures)9 Getter (lombok.Getter)9 Preconditions (com.google.common.base.Preconditions)8 Strings (com.google.common.base.Strings)8