Skip to content

Commit

Permalink
do index refresh of the internal transform index with the system user
Browse files Browse the repository at this point in the history
instead of using the calling user which does not have the sufficient rights
if security is enabled

fixes elastic#51728
  • Loading branch information
Hendrik Muhs committed Jan 31, 2020
1 parent 2854f5c commit 06a31a1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.elasticsearch.xpack.core.transform.transforms.TransformState;
import org.elasticsearch.xpack.core.transform.transforms.TransformTaskParams;
import org.elasticsearch.xpack.core.transform.transforms.TransformTaskState;
import org.elasticsearch.xpack.core.transform.transforms.persistence.TransformInternalIndexConstants;
import org.elasticsearch.xpack.transform.TransformServices;
import org.elasticsearch.xpack.transform.persistence.TransformConfigManager;
import org.elasticsearch.xpack.transform.transforms.TransformTask;
Expand Down Expand Up @@ -274,13 +273,10 @@ protected StopTransformAction.Response newResponse(
private ActionListener<Response> waitForStopListener(Request request, ActionListener<Response> listener) {

ActionListener<Response> onStopListener = ActionListener.wrap(
waitResponse -> client.admin()
.indices()
.prepareRefresh(TransformInternalIndexConstants.LATEST_INDEX_NAME)
.execute(ActionListener.wrap(r -> listener.onResponse(waitResponse), e -> {
logger.info("Failed to refresh internal index after delete", e);
listener.onResponse(waitResponse);
})),
waitResponse -> transformConfigManager.refresh(ActionListener.wrap(r -> listener.onResponse(waitResponse), e -> {
logger.debug("Failed to refresh internal index after stop", e);
listener.onResponse(waitResponse);
})),
listener::onFailure
);
return ActionListener.wrap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.elasticsearch.ResourceNotFoundException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.DocWriteRequest;
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
import org.elasticsearch.action.bulk.BulkItemResponse;
import org.elasticsearch.action.index.IndexAction;
import org.elasticsearch.action.index.IndexRequest;
Expand Down Expand Up @@ -634,6 +636,17 @@ public void getTransformStoredDocs(Collection<String> transformIds, ActionListen
);
}

@Override
public void refresh(ActionListener<Boolean> listener) {
executeAsyncWithOrigin(
client.threadPool().getThreadContext(),
TRANSFORM_ORIGIN,
new RefreshRequest(TransformInternalIndexConstants.LATEST_INDEX_NAME),
ActionListener.<RefreshResponse>wrap(r -> listener.onResponse(true), listener::onFailure),
client.admin().indices()::refresh
);
}

private void parseTransformLenientlyFromSource(
BytesReference source,
String transformId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,5 @@ void putOrUpdateTransformStoredDoc(

void getTransformStoredDocs(Collection<String> transformIds, ActionListener<List<TransformStoredDoc>> listener);

void refresh(ActionListener<Boolean> listener);
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,9 @@ public void getTransformStoredDocs(Collection<String> transformIds, ActionListen
listener.onResponse(docs);
}

@Override
public void refresh(ActionListener<Boolean> listener) {
listener.onResponse(true);
}

}

0 comments on commit 06a31a1

Please sign in to comment.