final Map<String, Tuple<Long, Settings>> retVal = new HashMap<String, Tuple<Long, Settings>>(); try(StoredContext ctx = threadContext.stashContext()) { threadContext.putHeader(ConfigConstants.SG_CONF_REQUEST_HEADER, "true");
final Object remoteAdress0 = getThreadContext().getTransient(ConfigConstants.SG_REMOTE_ADDRESS); try (ThreadContext.StoredContext stashedContext = getThreadContext().stashContext()) { final RestoringTransportResponseHandler<T> restoringHandler = new RestoringTransportResponseHandler<T>(handler, stashedContext); getThreadContext().putHeader("_sg_remotecn", cs.getClusterName().value());
try(StoredContext ctx = threadContext.stashContext()) { threadContext.putHeader(ConfigConstants.SG_CONF_REQUEST_HEADER, "true");
private SearchGuardLicense createOrGetTrial(String msg) { long created = System.currentTimeMillis(); ThreadContext threadContext = threadPool.getThreadContext(); try(StoredContext ctx = threadContext.stashContext()) { threadContext.putHeader(ConfigConstants.SG_CONF_REQUEST_HEADER, "true"); GetResponse get = client.prepareGet(searchguardIndex, "sg", "tattr").get(); if(get.isExists()) { created = (long) get.getSource().get("val"); } else { try { client.index(new IndexRequest(searchguardIndex) .type("sg") .id("tattr") .setRefreshPolicy(RefreshPolicy.IMMEDIATE) .create(true) .source("{\"val\": "+System.currentTimeMillis()+"}", XContentType.JSON)).actionGet(); } catch (VersionConflictEngineException e) { //ignore } catch (Exception e) { LOGGER.error("Unable to index tattr", e); } } } return SearchGuardLicense.createTrialLicense(formatDate(created), clusterService, msg); } }
/** * Removes the current context and resets a default context marked with as * originating from the supplied string. The removed context can be * restored by closing the returned {@link StoredContext}. Callers should * be careful to save the current context before calling this method and * restore it any listeners, likely with * {@link ContextPreservingActionListener}. Use {@link OriginSettingClient} * which can be used to do this automatically. * <p> * Without security the origin is ignored, but security uses it to authorize * actions that are made up of many sub-actions. These actions call * {@link #stashWithOrigin} before performing on behalf of a user that * should be allowed even if the user doesn't have permission to perform * those actions on their own. * <p> * For example, a user might not have permission to GET from the tasks index * but the tasks API will perform a get on their behalf using this method * if it can't find the task in memory. */ public StoredContext stashWithOrigin(String origin) { final ThreadContext.StoredContext storedContext = stashContext(); putTransient(ACTION_ORIGIN_TRANSIENT_NAME, origin); return storedContext; }
@Override protected void doRun() throws Exception { boolean whileRunning = false; threadsOriginalContext = stashContext(); try { creatorsContext.restore(); whileRunning = true; in.doRun(); whileRunning = false; } catch (IllegalStateException ex) { if (whileRunning || threadLocal.closed.get() == false) { throw ex; } // if we hit an ISE here we have been shutting down // this comes from the threadcontext and barfs if // our threadpool has been shutting down } }
StoredContext ctx = tc.threadPool().getThreadContext().stashContext(); try { tc.threadPool().getThreadContext().putHeader("sg_impersonate_as", "worf"); StoredContext ctx = tc.threadPool().getThreadContext().stashContext(); try { Header header = encodeBasicHeader("worf", "worf"); ctx = tc.threadPool().getThreadContext().stashContext(); try { Header header = encodeBasicHeader("worf", "worf111"); ctx = tc.threadPool().getThreadContext().stashContext(); try { tc.threadPool().getThreadContext().putHeader("sg_impersonate_as", "gkar"); ctx = tc.threadPool().getThreadContext().stashContext(); try { tc.threadPool().getThreadContext().putHeader("sg_impersonate_as", "nagilum"); ctx = tc.threadPool().getThreadContext().stashContext(); try { tc.threadPool().getThreadContext().putHeader("sg_impersonate_as", "nagilum"); ctx = tc.threadPool().getThreadContext().stashContext(); try { tc.threadPool().getThreadContext().putHeader("sg_impersonate_as", "nagilum"); ctx = tc.threadPool().getThreadContext().stashContext();
StoredContext ctx = tc.threadPool().getThreadContext().stashContext(); try { tc.threadPool().getThreadContext().putHeader("sg_impersonate_as", "worf"); StoredContext ctx = tc.threadPool().getThreadContext().stashContext(); try { Header header = encodeBasicHeader("worf", "worf"); ctx = tc.threadPool().getThreadContext().stashContext(); try { Header header = encodeBasicHeader("worf", "worf111"); ctx = tc.threadPool().getThreadContext().stashContext(); try { tc.threadPool().getThreadContext().putHeader("sg_impersonate_as", "gkar"); ctx = tc.threadPool().getThreadContext().stashContext(); try { tc.threadPool().getThreadContext().putHeader("sg_impersonate_as", "nagilum"); ctx = tc.threadPool().getThreadContext().stashContext(); try { tc.threadPool().getThreadContext().putHeader("sg_impersonate_as", "nagilum"); ctx = tc.threadPool().getThreadContext().stashContext(); try { tc.threadPool().getThreadContext().putHeader("sg_impersonate_as", "nagilum"); ctx = tc.threadPool().getThreadContext().stashContext();
@Override public void run() { boolean whileRunning = false; try (ThreadContext.StoredContext ignore = stashContext()){ ctx.restore(); whileRunning = true;
ThreadContext.StoredContext storedContext = threadContext.newStoredContext(true); Consumer<Boolean> contextPreservingListener = forced -> { try (ThreadContext.StoredContext ignore = threadContext.stashContext()) { storedContext.restore(); listener.accept(forced);
try (ThreadContext.StoredContext ignore = threadContext.stashContext()) { threadContext.markAsSystemContext();
try (ThreadContext.StoredContext ignore = threadContext.stashContext()) { threadContext.markAsSystemContext(); threadPool.generic().execute(() -> upgradeTemplates(changes.get().v1(), changes.get().v2()));
public void updateGlobalCheckpointForShard(final ShardId shardId) { final ThreadContext threadContext = threadPool.getThreadContext(); try (ThreadContext.StoredContext ignore = threadContext.stashContext()) { threadContext.markAsSystemContext(); execute( new Request(shardId), ActionListener.wrap(r -> { }, e -> { if (ExceptionsHelper.unwrap(e, AlreadyClosedException.class, IndexShardClosedException.class) == null) { logger.info(new ParameterizedMessage("{} global checkpoint sync failed", shardId), e); } })); } }
StreamInput streamIn = reference.streamInput(); boolean success = false; try (ThreadContext.StoredContext tCtx = threadPool.getThreadContext().stashContext()) { long requestId = streamIn.readLong(); byte status = streamIn.readByte();
new SniffClusterStateResponseHandler(connection, listener, seedNodes, cancellableThreads)); try (ThreadContext.StoredContext ignore = threadContext.stashContext()) {
void dispatchRequest(final RestRequest request, final RestChannel channel) { final ThreadContext threadContext = threadPool.getThreadContext(); try (ThreadContext.StoredContext ignore = threadContext.stashContext()) { dispatcher.dispatchRequest(request, channel, threadContext); } }
void dispatchBadRequest(final RestRequest request, final RestChannel channel, final Throwable cause) { final ThreadContext threadContext = threadPool.getThreadContext(); try (ThreadContext.StoredContext ignore = threadContext.stashContext()) { dispatcher.dispatchBadRequest(request, channel, threadContext, cause); } }
void dispatchBadRequest(final RestRequest request, final RestChannel channel, final Throwable cause) { final ThreadContext threadContext = threadPool.getThreadContext(); try (ThreadContext.StoredContext ignore = threadContext.stashContext()) { dispatcher.dispatchBadRequest(request, channel, threadContext, cause); } }
void dispatchBadRequest(final RestRequest request, final RestChannel channel, final Throwable cause) { final ThreadContext threadContext = threadPool.getThreadContext(); try (ThreadContext.StoredContext ignore = threadContext.stashContext()) { dispatcher.dispatchBadRequest(request, channel, threadContext, cause); } }
protected void dispatchRequest(RestRequest request, RestChannel channel) { final ThreadContext threadContext = threadPool.getThreadContext(); try (ThreadContext.StoredContext ignore = threadContext.stashContext()) { dispatcher.dispatchRequest(request, channel, threadContext); } }