-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] tags on model group #1370
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
644 changes: 344 additions & 300 deletions
644
common/src/main/java/org/opensearch/ml/common/CommonValue.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
common/src/main/java/org/opensearch/ml/common/model/ModelGroupTag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.ml.common.model; | ||
|
||
import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken; | ||
|
||
import java.io.IOException; | ||
import java.util.*; | ||
import org.opensearch.common.Nullable; | ||
import org.opensearch.common.inject.internal.ToStringBuilder; | ||
import org.opensearch.common.xcontent.XContentHelper; | ||
import org.opensearch.common.xcontent.json.JsonXContent; | ||
import org.opensearch.core.common.Strings; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.common.io.stream.Writeable; | ||
import org.opensearch.core.xcontent.ToXContent; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
import org.opensearch.core.xcontent.XContentParser; | ||
|
||
public final class ModelGroupTag implements Writeable, ToXContent { | ||
public static final String TAG_KEY_FIELD = "key"; | ||
public static final String TAG_TYPE_FIELD = "type"; | ||
|
||
@Nullable private final String key; | ||
@Nullable private final String type; | ||
|
||
public ModelGroupTag() { | ||
key = ""; | ||
type = ""; | ||
} | ||
|
||
public ModelGroupTag(@Nullable final String key, @Nullable final String type) { | ||
this.key = key; | ||
this.type = type; | ||
} | ||
|
||
public ModelGroupTag(String json) { | ||
if (Strings.isNullOrEmpty(json)) { | ||
throw new IllegalArgumentException("Response json cannot be null"); | ||
} | ||
|
||
Map<String, Object> mapValue = | ||
XContentHelper.convertToMap(JsonXContent.jsonXContent, json, false); | ||
key = (String) mapValue.get(TAG_KEY_FIELD); | ||
type = (String) mapValue.get(TAG_TYPE_FIELD); | ||
} | ||
|
||
public ModelGroupTag(StreamInput in) throws IOException { | ||
this.key = in.readString(); | ||
this.type = in.readString(); | ||
} | ||
|
||
public static ModelGroupTag parse(XContentParser parser) throws IOException { | ||
String key = ""; | ||
String type = ""; | ||
|
||
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser); | ||
while (parser.nextToken() != XContentParser.Token.END_OBJECT) { | ||
String fieldName = parser.currentName(); | ||
parser.nextToken(); | ||
switch (fieldName) { | ||
case TAG_KEY_FIELD: | ||
key = parser.text(); | ||
break; | ||
case TAG_TYPE_FIELD: | ||
type = parser.text(); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
return new ModelGroupTag(key, type); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject().field(TAG_KEY_FIELD, key).field(TAG_TYPE_FIELD, type); | ||
return builder.endObject(); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeString(key); | ||
out.writeString(type); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
ToStringBuilder builder = new ToStringBuilder(this.getClass()); | ||
builder.add(TAG_KEY_FIELD, key); | ||
builder.add(TAG_TYPE_FIELD, type); | ||
return builder.toString(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (!(obj instanceof ModelGroupTag)) { | ||
return false; | ||
} | ||
ModelGroupTag that = (ModelGroupTag) obj; | ||
return this.key.equals(that.key) && this.type.equals(that.type); | ||
} | ||
|
||
@Nullable | ||
public String getKey() { | ||
return key; | ||
} | ||
|
||
@Nullable | ||
public String getType() { | ||
return type; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not change the format of this file, the format change caused a lot of differences.