|
23 | 23 | import org.opensearch.common.util.concurrent.ConcurrentCollections;
|
24 | 24 | import org.opensearch.common.util.concurrent.ConcurrentMapLong;
|
25 | 25 | import org.opensearch.common.util.concurrent.ThreadContext;
|
26 |
| -import org.opensearch.common.xcontent.XContentHelper; |
27 |
| -import org.opensearch.core.common.bytes.BytesArray; |
| 26 | +import org.opensearch.core.common.io.stream.StreamInput; |
28 | 27 | import org.opensearch.core.tasks.resourcetracker.ResourceStats;
|
29 | 28 | import org.opensearch.core.tasks.resourcetracker.ResourceStatsType;
|
30 | 29 | import org.opensearch.core.tasks.resourcetracker.ResourceUsageInfo;
|
31 | 30 | import org.opensearch.core.tasks.resourcetracker.ResourceUsageMetric;
|
32 | 31 | import org.opensearch.core.tasks.resourcetracker.TaskResourceInfo;
|
33 | 32 | import org.opensearch.core.tasks.resourcetracker.TaskResourceUsage;
|
34 | 33 | import org.opensearch.core.tasks.resourcetracker.ThreadResourceInfo;
|
35 |
| -import org.opensearch.core.xcontent.DeprecationHandler; |
36 |
| -import org.opensearch.core.xcontent.MediaTypeRegistry; |
37 |
| -import org.opensearch.core.xcontent.NamedXContentRegistry; |
38 |
| -import org.opensearch.core.xcontent.XContentParser; |
39 | 34 | import org.opensearch.threadpool.RunnableTaskExecutionListener;
|
40 | 35 | import org.opensearch.threadpool.ThreadPool;
|
41 | 36 |
|
42 | 37 | import java.io.IOException;
|
43 | 38 | import java.lang.management.ManagementFactory;
|
44 | 39 | import java.util.ArrayList;
|
| 40 | +import java.util.Base64; |
45 | 41 | import java.util.Collections;
|
46 | 42 | import java.util.List;
|
47 | 43 | import java.util.Map;
|
@@ -346,13 +342,12 @@ public TaskResourceInfo getTaskResourceUsageFromThreadContext() {
|
346 | 342 | String usage = taskResourceUsages.get(0);
|
347 | 343 | try {
|
348 | 344 | if (usage != null && !usage.isEmpty()) {
|
349 |
| - XContentParser parser = XContentHelper.createParser( |
350 |
| - NamedXContentRegistry.EMPTY, |
351 |
| - DeprecationHandler.THROW_UNSUPPORTED_OPERATION, |
352 |
| - new BytesArray(usage), |
353 |
| - MediaTypeRegistry.JSON |
354 |
| - ); |
355 |
| - return TaskResourceInfo.PARSER.apply(parser, null); |
| 345 | + // Get the serialized data as a byte array |
| 346 | + byte[] serializedData = Base64.getDecoder().decode(usage); |
| 347 | + // Deserialize from byte array |
| 348 | + try (StreamInput streamInput = StreamInput.wrap(serializedData)) { |
| 349 | + return TaskResourceInfo.readFromStream(streamInput); |
| 350 | + } |
356 | 351 | }
|
357 | 352 | } catch (IOException e) {
|
358 | 353 | logger.debug("fail to parse phase resource usages: ", e);
|
|
0 commit comments