|
10 | 10 | import org.apache.logging.log4j.LogManager;
|
11 | 11 | import org.apache.logging.log4j.Logger;
|
12 | 12 | import org.apache.logging.log4j.message.ParameterizedMessage;
|
| 13 | +import org.elasticsearch.ElasticsearchException; |
13 | 14 | import org.elasticsearch.Version;
|
14 | 15 | import org.elasticsearch.action.ActionListener;
|
15 | 16 | import org.elasticsearch.action.ActionListenerResponseHandler;
|
|
50 | 51 | import java.util.List;
|
51 | 52 | import java.util.Map;
|
52 | 53 |
|
| 54 | +import static org.elasticsearch.core.Strings.format; |
53 | 55 | import static org.elasticsearch.xpack.transform.utils.SecondaryAuthorizationUtils.useSecondaryAuthIfAvailable;
|
54 | 56 |
|
55 | 57 | public class TransportUpdateTransformAction extends TransportTasksAction<TransformTask, Request, Response, Response> {
|
@@ -169,9 +171,35 @@ protected void doExecute(Task task, Request request, ActionListener<Response> li
|
169 | 171 | && ((TransformState) transformTask.getState()).getTaskState() != TransformTaskState.FAILED
|
170 | 172 | && clusterState.nodes().get(transformTask.getExecutorNode()).getVersion().onOrAfter(Version.V_7_8_0)) {
|
171 | 173 |
|
| 174 | + ActionListener<Response> taskUpdateListener = ActionListener.wrap(listener::onResponse, e -> { |
| 175 | + // benign: A transform might be stopped meanwhile, this is not a problem |
| 176 | + if (e instanceof TransformTaskDisappearedDuringUpdateException) { |
| 177 | + logger.debug("[{}] transform task disappeared during update, ignoring", request.getId()); |
| 178 | + listener.onResponse(new Response(updatedConfig)); |
| 179 | + return; |
| 180 | + } |
| 181 | + |
| 182 | + if (e instanceof TransformTaskUpdateException) { |
| 183 | + // BWC: only log a warning as response object can not be changed |
| 184 | + logger.warn( |
| 185 | + () -> format( |
| 186 | + "[%s] failed to notify running transform task about update. " |
| 187 | + + "New settings will be applied after next checkpoint.", |
| 188 | + request.getId() |
| 189 | + ), |
| 190 | + e |
| 191 | + ); |
| 192 | + |
| 193 | + listener.onResponse(new Response(updatedConfig)); |
| 194 | + return; |
| 195 | + } |
| 196 | + |
| 197 | + listener.onFailure(e); |
| 198 | + }); |
| 199 | + |
172 | 200 | request.setNodes(transformTask.getExecutorNode());
|
173 | 201 | request.setConfig(updatedConfig);
|
174 |
| - super.doExecute(task, request, listener); |
| 202 | + super.doExecute(task, request, taskUpdateListener); |
175 | 203 | return;
|
176 | 204 | }
|
177 | 205 | }
|
@@ -208,8 +236,29 @@ protected Response newResponse(
|
208 | 236 | List<TaskOperationFailure> taskOperationFailures,
|
209 | 237 | List<FailedNodeException> failedNodeExceptions
|
210 | 238 | ) {
|
211 |
| - // there should be only 1 response, todo: check |
| 239 | + if (tasks.isEmpty()) { |
| 240 | + if (taskOperationFailures.isEmpty() == false) { |
| 241 | + throw new TransformTaskUpdateException("Failed to update running transform task.", taskOperationFailures.get(0).getCause()); |
| 242 | + } else if (failedNodeExceptions.isEmpty() == false) { |
| 243 | + throw new TransformTaskUpdateException("Failed to update running transform task.", failedNodeExceptions.get(0)); |
| 244 | + } else { |
| 245 | + throw new TransformTaskDisappearedDuringUpdateException("Could not update running transform as it has been stopped."); |
| 246 | + } |
| 247 | + } |
| 248 | + |
212 | 249 | return tasks.get(0);
|
213 | 250 | }
|
214 | 251 |
|
| 252 | + private static class TransformTaskUpdateException extends ElasticsearchException { |
| 253 | + TransformTaskUpdateException(String msg, Throwable cause, Object... args) { |
| 254 | + super(msg, cause, args); |
| 255 | + } |
| 256 | + } |
| 257 | + |
| 258 | + private static class TransformTaskDisappearedDuringUpdateException extends ElasticsearchException { |
| 259 | + TransformTaskDisappearedDuringUpdateException(String msg) { |
| 260 | + super(msg); |
| 261 | + } |
| 262 | + } |
| 263 | + |
215 | 264 | }
|
0 commit comments