|
7 | 7 |
|
8 | 8 | import lombok.Getter;
|
9 | 9 | import org.opensearch.core.action.ActionResponse;
|
| 10 | +import org.opensearch.core.common.io.stream.InputStreamStreamInput; |
| 11 | +import org.opensearch.core.common.io.stream.OutputStreamStreamOutput; |
10 | 12 | import org.opensearch.core.common.io.stream.StreamInput;
|
11 | 13 | import org.opensearch.core.common.io.stream.StreamOutput;
|
12 | 14 | import org.opensearch.core.xcontent.ToXContent;
|
13 | 15 | import org.opensearch.core.xcontent.ToXContentObject;
|
14 | 16 | import org.opensearch.core.xcontent.XContentBuilder;
|
| 17 | +import org.opensearch.ml.common.transport.MLTaskResponse; |
15 | 18 |
|
| 19 | +import java.io.ByteArrayInputStream; |
| 20 | +import java.io.ByteArrayOutputStream; |
16 | 21 | import java.io.IOException;
|
| 22 | +import java.io.UncheckedIOException; |
17 | 23 |
|
18 | 24 | @Getter
|
19 | 25 | public class MLRegisterModelResponse extends ActionResponse implements ToXContentObject {
|
@@ -61,4 +67,20 @@ public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params par
|
61 | 67 | builder.endObject();
|
62 | 68 | return builder;
|
63 | 69 | }
|
| 70 | + |
| 71 | + public static MLRegisterModelResponse fromActionResponse(ActionResponse actionResponse) { |
| 72 | + if (actionResponse instanceof MLRegisterModelResponse) { |
| 73 | + return (MLRegisterModelResponse) actionResponse; |
| 74 | + } |
| 75 | + |
| 76 | + try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 77 | + OutputStreamStreamOutput osso = new OutputStreamStreamOutput(baos)) { |
| 78 | + actionResponse.writeTo(osso); |
| 79 | + try (StreamInput input = new InputStreamStreamInput(new ByteArrayInputStream(baos.toByteArray()))) { |
| 80 | + return new MLRegisterModelResponse(input); |
| 81 | + } |
| 82 | + } catch (IOException e) { |
| 83 | + throw new UncheckedIOException("failed to parse ActionResponse into MLRegisterModelResponse", e); |
| 84 | + } |
| 85 | + } |
64 | 86 | }
|
0 commit comments