6
6
package org .opensearch .ml .common ;
7
7
8
8
import static org .opensearch .core .xcontent .XContentParserUtils .ensureExpectedToken ;
9
+ import static org .opensearch .ml .common .CommonValue .TENANT_ID_FIELD ;
10
+ import static org .opensearch .ml .common .CommonValue .VERSION_2_19_0 ;
9
11
10
12
import java .io .IOException ;
11
13
import java .time .Instant ;
@@ -57,6 +59,7 @@ public class MLConfig implements ToXContentObject, Writeable {
57
59
private final Instant createTime ;
58
60
private Instant lastUpdateTime ;
59
61
private Instant lastUpdatedTime ;
62
+ private final String tenantId ;
60
63
61
64
@ Builder (toBuilder = true )
62
65
public MLConfig (
@@ -66,7 +69,8 @@ public MLConfig(
66
69
Configuration mlConfiguration ,
67
70
Instant createTime ,
68
71
Instant lastUpdateTime ,
69
- Instant lastUpdatedTime
72
+ Instant lastUpdatedTime ,
73
+ String tenantId
70
74
) {
71
75
this .type = type ;
72
76
this .configType = configType ;
@@ -75,6 +79,7 @@ public MLConfig(
75
79
this .createTime = createTime ;
76
80
this .lastUpdateTime = lastUpdateTime ;
77
81
this .lastUpdatedTime = lastUpdatedTime ;
82
+ this .tenantId = tenantId ;
78
83
}
79
84
80
85
public MLConfig (StreamInput input ) throws IOException {
@@ -92,6 +97,7 @@ public MLConfig(StreamInput input) throws IOException {
92
97
}
93
98
lastUpdatedTime = input .readOptionalInstant ();
94
99
}
100
+ this .tenantId = streamInputVersion .onOrAfter (VERSION_2_19_0 ) ? input .readOptionalString () : null ;
95
101
}
96
102
97
103
@ Override
@@ -116,6 +122,9 @@ public void writeTo(StreamOutput out) throws IOException {
116
122
}
117
123
out .writeOptionalInstant (lastUpdatedTime );
118
124
}
125
+ if (streamOutputVersion .onOrAfter (VERSION_2_19_0 )) {
126
+ out .writeOptionalString (tenantId );
127
+ }
119
128
}
120
129
121
130
@ Override
@@ -133,12 +142,14 @@ public XContentBuilder toXContent(XContentBuilder xContentBuilder, Params params
133
142
if (lastUpdateTime != null || lastUpdatedTime != null ) {
134
143
builder .field (LAST_UPDATE_TIME_FIELD , lastUpdatedTime == null ? lastUpdateTime .toEpochMilli () : lastUpdatedTime .toEpochMilli ());
135
144
}
145
+ if (tenantId != null ) {
146
+ builder .field (TENANT_ID_FIELD , tenantId );
147
+ }
136
148
return builder .endObject ();
137
149
}
138
150
139
151
public static MLConfig fromStream (StreamInput in ) throws IOException {
140
- MLConfig mlConfig = new MLConfig (in );
141
- return mlConfig ;
152
+ return new MLConfig (in );
142
153
}
143
154
144
155
public static MLConfig parse (XContentParser parser ) throws IOException {
@@ -149,6 +160,7 @@ public static MLConfig parse(XContentParser parser) throws IOException {
149
160
Instant createTime = null ;
150
161
Instant lastUpdateTime = null ;
151
162
Instant lastUpdatedTime = null ;
163
+ String tenantId = null ;
152
164
153
165
ensureExpectedToken (XContentParser .Token .START_OBJECT , parser .currentToken (), parser );
154
166
while (parser .nextToken () != XContentParser .Token .END_OBJECT ) {
@@ -177,6 +189,8 @@ public static MLConfig parse(XContentParser parser) throws IOException {
177
189
case LAST_UPDATED_TIME_FIELD :
178
190
lastUpdatedTime = Instant .ofEpochMilli (parser .longValue ());
179
191
break ;
192
+ case TENANT_ID_FIELD :
193
+ tenantId = parser .textOrNull ();
180
194
default :
181
195
parser .skipChildren ();
182
196
break ;
@@ -191,6 +205,7 @@ public static MLConfig parse(XContentParser parser) throws IOException {
191
205
.createTime (createTime )
192
206
.lastUpdateTime (lastUpdateTime )
193
207
.lastUpdatedTime (lastUpdatedTime )
208
+ .tenantId (tenantId )
194
209
.build ();
195
210
}
196
211
}
0 commit comments