use of io.crate.common.collections.Tuple in project crate by crate.
the class HttpAuthUpstreamHandler method credentialsFromRequest.
@VisibleForTesting
static Tuple<String, SecureString> credentialsFromRequest(HttpRequest request, @Nullable SSLSession session, Settings settings) {
String username = null;
if (request.headers().contains(HttpHeaderNames.AUTHORIZATION.toString())) {
// Prefer Http Basic Auth
return Headers.extractCredentialsFromHttpBasicAuthHeader(request.headers().get(HttpHeaderNames.AUTHORIZATION.toString()));
} else {
// prefer commonName as userName over AUTH_TRUST_HTTP_DEFAULT_HEADER user
if (session != null) {
try {
Certificate certificate = session.getPeerCertificates()[0];
username = SSL.extractCN(certificate);
} catch (ArrayIndexOutOfBoundsException | SSLPeerUnverifiedException ignored) {
// client cert is optional
}
}
if (username == null) {
username = AuthSettings.AUTH_TRUST_HTTP_DEFAULT_HEADER.get(settings);
}
}
return new Tuple<>(username, null);
}
use of io.crate.common.collections.Tuple in project crate by crate.
the class JobLauncher method createHandlerPhaseAndReceivers.
private List<Tuple<ExecutionPhase, RowConsumer>> createHandlerPhaseAndReceivers(List<ExecutionPhase> handlerPhases, List<RowConsumer> handlerReceivers, InitializationTracker initializationTracker) {
List<Tuple<ExecutionPhase, RowConsumer>> handlerPhaseAndReceiver = new ArrayList<>();
ListIterator<RowConsumer> consumerIt = handlerReceivers.listIterator();
for (ExecutionPhase handlerPhase : handlerPhases) {
InterceptingRowConsumer interceptingBatchConsumer = new InterceptingRowConsumer(jobId, consumerIt.next(), initializationTracker, executor, transportKillJobsNodeAction);
handlerPhaseAndReceiver.add(new Tuple<>(handlerPhase, interceptingBatchConsumer));
}
return handlerPhaseAndReceiver;
}
use of io.crate.common.collections.Tuple in project crate by crate.
the class InsertSourceFromCells method addDefaults.
private static Tuple<List<Reference>, List<Input<?>>> addDefaults(List<Reference> targets, DocTableInfo table, TransactionContext txnCtx, NodeContext nodeCtx) {
if (table.defaultExpressionColumns().isEmpty()) {
return new Tuple<>(targets, List.of());
}
InputFactory inputFactory = new InputFactory(nodeCtx);
Context<CollectExpression<Row, ?>> ctx = inputFactory.ctxForInputColumns(txnCtx);
ArrayList<Reference> defaultColumns = new ArrayList<>(table.defaultExpressionColumns().size());
ArrayList<Input<?>> defaultValues = new ArrayList<>();
for (Reference ref : table.defaultExpressionColumns()) {
if (targets.contains(ref) == false) {
defaultColumns.add(ref);
defaultValues.add(ctx.add(ref.defaultExpression()));
}
}
List<Reference> allColumns;
if (defaultColumns.isEmpty()) {
allColumns = targets;
} else {
allColumns = Lists2.concat(targets, defaultColumns);
}
return new Tuple<>(allColumns, defaultValues);
}
use of io.crate.common.collections.Tuple in project crate by crate.
the class IndexShard method syncRetentionLeases.
/**
* Syncs the current retention leases to all replicas.
*/
public void syncRetentionLeases() {
assert assertPrimaryMode();
verifyNotClosed();
replicationTracker.renewPeerRecoveryRetentionLeases();
final Tuple<Boolean, RetentionLeases> retentionLeases = getRetentionLeases(true);
if (retentionLeases.v1()) {
logger.trace("syncing retention leases [{}] after expiration check", retentionLeases.v2());
retentionLeaseSyncer.sync(shardId, shardRouting.allocationId().getId(), getPendingPrimaryTerm(), retentionLeases.v2(), ActionListener.wrap(r -> {
}, e -> logger.warn(new ParameterizedMessage("failed to sync retention leases [{}] after expiration check", retentionLeases), e)));
} else {
logger.trace("background syncing retention leases [{}] after expiration check", retentionLeases.v2());
retentionLeaseSyncer.backgroundSync(shardId, shardRouting.allocationId().getId(), getPendingPrimaryTerm(), retentionLeases.v2());
}
}
use of io.crate.common.collections.Tuple in project crate by crate.
the class LinearizabilityChecker method isLinearizable.
private boolean isLinearizable(SequentialSpec spec, List<Event> history, BooleanSupplier terminateEarly) {
LOGGER.debug("Checking history of size: {}: {}", history.size(), history);
// the current state of the datatype
Object state = spec.initialState();
// the linearized prefix of the history
final FixedBitSet linearized = new FixedBitSet(history.size() / 2);
// cache of explored <state, linearized prefix> pairs
final Cache cache = new Cache();
// path we're currently exploring
final Deque<Tuple<Entry, Object>> calls = new LinkedList<>();
final Entry headEntry = createLinkedEntries(history);
// current entry
Entry entry = headEntry.next;
while (headEntry.next != null) {
if (terminateEarly.getAsBoolean()) {
return false;
}
if (entry.match != null) {
final Optional<Object> maybeNextState = spec.nextState(state, entry.event.value, entry.match.event.value);
boolean shouldExploreNextState = false;
if (maybeNextState.isPresent()) {
// check if we have already explored this linearization
final FixedBitSet updatedLinearized = linearized.clone();
updatedLinearized.set(entry.id);
shouldExploreNextState = cache.add(maybeNextState.get(), updatedLinearized);
}
if (shouldExploreNextState) {
calls.push(new Tuple<>(entry, state));
state = maybeNextState.get();
linearized.set(entry.id);
entry.lift();
entry = headEntry.next;
} else {
entry = entry.next;
}
} else {
if (calls.isEmpty()) {
return false;
}
final Tuple<Entry, Object> top = calls.pop();
entry = top.v1();
state = top.v2();
linearized.clear(entry.id);
entry.unlift();
entry = entry.next;
}
}
return true;
}
Aggregations