|
3 | 3 | * SPDX-License-Identifier: Apache-2.0
|
4 | 4 | */
|
5 | 5 |
|
6 |
| -package org.opensearch.ml.engine.indices; |
| 6 | +package org.opensearch.ml.common; |
7 | 7 |
|
8 | 8 | import static org.opensearch.ml.common.CommonValue.ML_AGENT_INDEX;
|
9 |
| -import static org.opensearch.ml.common.CommonValue.ML_AGENT_INDEX_MAPPING; |
10 |
| -import static org.opensearch.ml.common.CommonValue.ML_AGENT_INDEX_SCHEMA_VERSION; |
| 9 | +import static org.opensearch.ml.common.CommonValue.ML_AGENT_INDEX_MAPPING_PATH; |
11 | 10 | import static org.opensearch.ml.common.CommonValue.ML_CONFIG_INDEX;
|
12 |
| -import static org.opensearch.ml.common.CommonValue.ML_CONFIG_INDEX_MAPPING; |
13 |
| -import static org.opensearch.ml.common.CommonValue.ML_CONFIG_INDEX_SCHEMA_VERSION; |
| 11 | +import static org.opensearch.ml.common.CommonValue.ML_CONFIG_INDEX_MAPPING_PATH; |
14 | 12 | import static org.opensearch.ml.common.CommonValue.ML_CONNECTOR_INDEX;
|
15 |
| -import static org.opensearch.ml.common.CommonValue.ML_CONNECTOR_INDEX_MAPPING; |
16 |
| -import static org.opensearch.ml.common.CommonValue.ML_CONNECTOR_SCHEMA_VERSION; |
| 13 | +import static org.opensearch.ml.common.CommonValue.ML_CONNECTOR_INDEX_MAPPING_PATH; |
17 | 14 | import static org.opensearch.ml.common.CommonValue.ML_CONTROLLER_INDEX;
|
18 |
| -import static org.opensearch.ml.common.CommonValue.ML_CONTROLLER_INDEX_MAPPING; |
19 |
| -import static org.opensearch.ml.common.CommonValue.ML_CONTROLLER_INDEX_SCHEMA_VERSION; |
| 15 | +import static org.opensearch.ml.common.CommonValue.ML_CONTROLLER_INDEX_MAPPING_PATH; |
20 | 16 | import static org.opensearch.ml.common.CommonValue.ML_MEMORY_MESSAGE_INDEX;
|
21 |
| -import static org.opensearch.ml.common.CommonValue.ML_MEMORY_MESSAGE_INDEX_MAPPING; |
22 |
| -import static org.opensearch.ml.common.CommonValue.ML_MEMORY_MESSAGE_INDEX_SCHEMA_VERSION; |
| 17 | +import static org.opensearch.ml.common.CommonValue.ML_MEMORY_MESSAGE_INDEX_MAPPING_PATH; |
23 | 18 | import static org.opensearch.ml.common.CommonValue.ML_MEMORY_META_INDEX;
|
24 |
| -import static org.opensearch.ml.common.CommonValue.ML_MEMORY_META_INDEX_MAPPING; |
25 |
| -import static org.opensearch.ml.common.CommonValue.ML_MEMORY_META_INDEX_SCHEMA_VERSION; |
| 19 | +import static org.opensearch.ml.common.CommonValue.ML_MEMORY_META_INDEX_MAPPING_PATH; |
26 | 20 | import static org.opensearch.ml.common.CommonValue.ML_MODEL_GROUP_INDEX;
|
27 |
| -import static org.opensearch.ml.common.CommonValue.ML_MODEL_GROUP_INDEX_MAPPING; |
28 |
| -import static org.opensearch.ml.common.CommonValue.ML_MODEL_GROUP_INDEX_SCHEMA_VERSION; |
| 21 | +import static org.opensearch.ml.common.CommonValue.ML_MODEL_GROUP_INDEX_MAPPING_PATH; |
29 | 22 | import static org.opensearch.ml.common.CommonValue.ML_MODEL_INDEX;
|
30 |
| -import static org.opensearch.ml.common.CommonValue.ML_MODEL_INDEX_MAPPING; |
31 |
| -import static org.opensearch.ml.common.CommonValue.ML_MODEL_INDEX_SCHEMA_VERSION; |
| 23 | +import static org.opensearch.ml.common.CommonValue.ML_MODEL_INDEX_MAPPING_PATH; |
32 | 24 | import static org.opensearch.ml.common.CommonValue.ML_TASK_INDEX;
|
33 |
| -import static org.opensearch.ml.common.CommonValue.ML_TASK_INDEX_MAPPING; |
34 |
| -import static org.opensearch.ml.common.CommonValue.ML_TASK_INDEX_SCHEMA_VERSION; |
| 25 | +import static org.opensearch.ml.common.CommonValue.ML_TASK_INDEX_MAPPING_PATH; |
| 26 | + |
| 27 | +import java.io.IOException; |
| 28 | +import java.io.UncheckedIOException; |
| 29 | + |
| 30 | +import org.opensearch.ml.common.utils.IndexUtils; |
35 | 31 |
|
36 | 32 | public enum MLIndex {
|
37 |
| - MODEL_GROUP(ML_MODEL_GROUP_INDEX, false, ML_MODEL_GROUP_INDEX_MAPPING, ML_MODEL_GROUP_INDEX_SCHEMA_VERSION), |
38 |
| - MODEL(ML_MODEL_INDEX, false, ML_MODEL_INDEX_MAPPING, ML_MODEL_INDEX_SCHEMA_VERSION), |
39 |
| - TASK(ML_TASK_INDEX, false, ML_TASK_INDEX_MAPPING, ML_TASK_INDEX_SCHEMA_VERSION), |
40 |
| - CONNECTOR(ML_CONNECTOR_INDEX, false, ML_CONNECTOR_INDEX_MAPPING, ML_CONNECTOR_SCHEMA_VERSION), |
41 |
| - CONFIG(ML_CONFIG_INDEX, false, ML_CONFIG_INDEX_MAPPING, ML_CONFIG_INDEX_SCHEMA_VERSION), |
42 |
| - CONTROLLER(ML_CONTROLLER_INDEX, false, ML_CONTROLLER_INDEX_MAPPING, ML_CONTROLLER_INDEX_SCHEMA_VERSION), |
43 |
| - AGENT(ML_AGENT_INDEX, false, ML_AGENT_INDEX_MAPPING, ML_AGENT_INDEX_SCHEMA_VERSION), |
44 |
| - MEMORY_META(ML_MEMORY_META_INDEX, false, ML_MEMORY_META_INDEX_MAPPING, ML_MEMORY_META_INDEX_SCHEMA_VERSION), |
45 |
| - MEMORY_MESSAGE(ML_MEMORY_MESSAGE_INDEX, false, ML_MEMORY_MESSAGE_INDEX_MAPPING, ML_MEMORY_MESSAGE_INDEX_SCHEMA_VERSION); |
| 33 | + MODEL_GROUP(ML_MODEL_GROUP_INDEX, false, ML_MODEL_GROUP_INDEX_MAPPING_PATH), |
| 34 | + MODEL(ML_MODEL_INDEX, false, ML_MODEL_INDEX_MAPPING_PATH), |
| 35 | + TASK(ML_TASK_INDEX, false, ML_TASK_INDEX_MAPPING_PATH), |
| 36 | + CONNECTOR(ML_CONNECTOR_INDEX, false, ML_CONNECTOR_INDEX_MAPPING_PATH), |
| 37 | + CONFIG(ML_CONFIG_INDEX, false, ML_CONFIG_INDEX_MAPPING_PATH), |
| 38 | + CONTROLLER(ML_CONTROLLER_INDEX, false, ML_CONTROLLER_INDEX_MAPPING_PATH), |
| 39 | + AGENT(ML_AGENT_INDEX, false, ML_AGENT_INDEX_MAPPING_PATH), |
| 40 | + MEMORY_META(ML_MEMORY_META_INDEX, false, ML_MEMORY_META_INDEX_MAPPING_PATH), |
| 41 | + MEMORY_MESSAGE(ML_MEMORY_MESSAGE_INDEX, false, ML_MEMORY_MESSAGE_INDEX_MAPPING_PATH); |
46 | 42 |
|
47 | 43 | private final String indexName;
|
48 | 44 | // whether we use an alias for the index
|
49 | 45 | private final boolean alias;
|
50 | 46 | private final String mapping;
|
51 | 47 | private final Integer version;
|
52 | 48 |
|
53 |
| - MLIndex(String name, boolean alias, String mapping, Integer version) { |
| 49 | + MLIndex(String name, boolean alias, String mappingPath) { |
54 | 50 | this.indexName = name;
|
55 | 51 | this.alias = alias;
|
56 |
| - this.mapping = mapping; |
57 |
| - this.version = version; |
| 52 | + this.mapping = getMapping(mappingPath); |
| 53 | + this.version = IndexUtils.getVersionFromMapping(this.mapping); |
| 54 | + } |
| 55 | + |
| 56 | + private String getMapping(String mappingPath) { |
| 57 | + if (mappingPath == null) { |
| 58 | + throw new IllegalArgumentException("Mapping path cannot be null"); |
| 59 | + } |
| 60 | + |
| 61 | + try { |
| 62 | + return IndexUtils.getMappingFromFile(mappingPath); |
| 63 | + } catch (IOException e) { |
| 64 | + // Unchecked exception is thrown since the method is being called within a constructor |
| 65 | + throw new UncheckedIOException("Failed to fetch index mapping from file: " + mappingPath, e); |
| 66 | + } |
58 | 67 | }
|
59 | 68 |
|
60 | 69 | public String getIndexName() {
|
|
0 commit comments