-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mohit Godwani <[email protected]>
- Loading branch information
Showing
9 changed files
with
314 additions
and
33 deletions.
There are no files selected for viewing
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
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
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
110 changes: 110 additions & 0 deletions
110
server/src/main/java/org/opensearch/cluster/metadata/Context.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,110 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.cluster.metadata; | ||
|
||
import org.opensearch.cluster.AbstractDiffable; | ||
import org.opensearch.common.annotation.ExperimentalApi; | ||
import org.opensearch.core.ParseField; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.xcontent.ConstructingObjectParser; | ||
import org.opensearch.core.xcontent.ToXContentObject; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
import org.opensearch.core.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
/** | ||
* Class encapsulating the context metadata associated with an index template/index. | ||
*/ | ||
@ExperimentalApi | ||
public class Context extends AbstractDiffable<ComposableIndexTemplate> implements ToXContentObject { | ||
|
||
private static final ParseField NAME = new ParseField("name"); | ||
private static final ParseField VERSION = new ParseField("version"); | ||
private static final ParseField PARAMS = new ParseField("params"); | ||
|
||
public static final String LATEST_VERSION = "_latest"; | ||
|
||
private String name; | ||
private String version = LATEST_VERSION; | ||
private Map<String, Object> params; | ||
|
||
public static final ConstructingObjectParser<Context, Void> PARSER = new ConstructingObjectParser<>( | ||
"index_template", | ||
false, | ||
a -> new Context((String) a[0], (String) a[1], (Map<String, Object>) a[2]) | ||
); | ||
|
||
static { | ||
PARSER.declareString(ConstructingObjectParser.constructorArg(), NAME); | ||
PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), VERSION); | ||
PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), (p, c) -> p.map(), PARAMS); | ||
} | ||
|
||
public Context(String name, String version, Map<String, Object> params) { | ||
this.name = name; | ||
this.version = version; | ||
this.params = params; | ||
} | ||
|
||
public Context(StreamInput in) throws IOException { | ||
this.name = in.readString(); | ||
this.version = in.readOptionalString(); | ||
this.params = in.readMap(); | ||
} | ||
|
||
public String name() { | ||
return name; | ||
} | ||
|
||
public void name(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String version() { | ||
return version; | ||
} | ||
|
||
public void version(String version) { | ||
this.version = version; | ||
} | ||
|
||
public Map<String, Object> params() { | ||
return params; | ||
} | ||
|
||
public void params(Map<String, Object> params) { | ||
this.params = params; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeString(name); | ||
out.writeOptionalString(version); | ||
out.writeMap(params); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field(NAME.getPreferredName(), this.name); | ||
builder.field("version", this.version); | ||
if (params != null) { | ||
builder.field("params", this.params); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
public static Context fromXContent(XContentParser parser) { | ||
return PARSER.apply(parser, null); | ||
} | ||
} |
Oops, something went wrong.