-
Notifications
You must be signed in to change notification settings - Fork 285
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
Upgrade to OpenSearch 2.0.0 #1698
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Sets the version of the Security plugin | ||
security-plugin.version=2.0.0.0 | ||
# Sets the version of OpenSearch this plugin should be built with | ||
opensearch-core.version=1.4.0 | ||
opensearch-core.version=2.0.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,11 +58,10 @@ | |
import org.opensearch.action.admin.cluster.health.ClusterHealthRequest; | ||
import org.opensearch.action.admin.cluster.health.ClusterHealthResponse; | ||
import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; | ||
import org.opensearch.action.admin.indices.create.CreateIndexRequest; | ||
import org.opensearch.client.indices.CreateIndexRequest; | ||
import org.opensearch.action.admin.indices.delete.DeleteIndexRequest; | ||
import org.opensearch.action.admin.indices.get.GetIndexRequest; | ||
import org.opensearch.action.admin.indices.get.GetIndexRequest.Feature; | ||
import org.opensearch.action.admin.indices.get.GetIndexResponse; | ||
import org.opensearch.client.indices.GetIndexRequest; | ||
import org.opensearch.client.indices.GetIndexRequest.Feature; | ||
import org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest; | ||
import org.opensearch.action.get.GetRequest; | ||
import org.opensearch.action.get.GetResponse; | ||
|
@@ -75,6 +74,7 @@ | |
import org.opensearch.client.RestClient; | ||
import org.opensearch.client.RestClientBuilder; | ||
import org.opensearch.client.RestHighLevelClient; | ||
import org.opensearch.client.indices.GetIndexResponse; | ||
import org.opensearch.client.transport.NoNodeAvailableException; | ||
import org.opensearch.cluster.health.ClusterHealthStatus; | ||
import org.opensearch.common.Strings; | ||
|
@@ -655,7 +655,7 @@ public static int execute(final String[] args) throws Exception { | |
|
||
GetIndexResponse securityIndex = null; | ||
try { | ||
securityIndex = restHighLevelClient.indices().get(new GetIndexRequest().indices(index).addFeatures(Feature.MAPPINGS), RequestOptions.DEFAULT); | ||
securityIndex = restHighLevelClient.indices().get(new GetIndexRequest(index).addFeatures(Feature.MAPPINGS), RequestOptions.DEFAULT); | ||
} catch (OpenSearchStatusException e1) { | ||
if(e1.status() == RestStatus.NOT_FOUND) { | ||
//ignore | ||
|
@@ -715,8 +715,7 @@ public static int execute(final String[] args) throws Exception { | |
|
||
final boolean legacy = createLegacyMode || (indexExists | ||
&& securityIndex.getMappings() != null | ||
&& securityIndex.getMappings().get(index) != null | ||
&& securityIndex.getMappings().get(index).containsKey("security")); | ||
&& securityIndex.getMappings().get(index) != null); | ||
|
||
if(legacy) { | ||
System.out.println("Legacy index '"+index+"' (ES 6) detected (or forced). You should migrate the configuration!"); | ||
|
@@ -832,15 +831,13 @@ private static boolean uploadFile(final RestHighLevelClient restHighLevelClient, | |
private static boolean uploadFile(final RestHighLevelClient restHighLevelClient, final String filepath, final String index, final String _id, final boolean legacy, boolean resolveEnvVars, | ||
final boolean populateEmptyIfMissing) { | ||
|
||
String type = "_doc"; | ||
String id = _id; | ||
|
||
if(legacy) { | ||
type = "security"; | ||
id = _id; | ||
|
||
try { | ||
ConfigHelper.fromYamlFile(filepath, CType.fromString(_id), 1, 0, 0); | ||
ConfigHelper.fromYamlFile(filepath, CType.fromString(_id), 2, 0, 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does it mean for this value to switch from 1 -> 2? Additional documentation would be useful in this code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was for migration Config 6 -> Config 7. But OpenSearch doesn't need to support this migration. Removing the 2 test classes for the same reason. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we include documentation in the code as to how this value is determine or aligned to. This could also be done with a local variable eg. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good idea! Can we do that in a separate PR? Let's unblock 2.0.0 build first. |
||
} catch (Exception e) { | ||
System.out.println("ERR: Seems "+filepath+" is not in legacy format: "+e); | ||
return false; | ||
|
@@ -855,12 +852,12 @@ private static boolean uploadFile(final RestHighLevelClient restHighLevelClient, | |
} | ||
} | ||
|
||
System.out.println("Will update '" + type + "/" + id + "' with " + filepath + " " + (legacy ? "(legacy mode)" : "")); | ||
System.out.println("Will update '" + "/" + id + "' with " + filepath + " " + (legacy ? "(legacy mode)" : "")); | ||
cliu123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
try (Reader reader = ConfigHelper.createFileOrStringReader(CType.fromString(_id), legacy ? 1 : 2, filepath, populateEmptyIfMissing)) { | ||
final String content = CharStreams.toString(reader); | ||
final String res = restHighLevelClient | ||
.index(new IndexRequest(index).type(type).id(id).setRefreshPolicy(RefreshPolicy.IMMEDIATE) | ||
.index(new IndexRequest(index).id(id).setRefreshPolicy(RefreshPolicy.IMMEDIATE) | ||
.source(_id, readXContent(resolveEnvVars ? replaceEnvVars(content, Settings.EMPTY) : content, XContentType.YAML)), RequestOptions.DEFAULT).getId(); | ||
|
||
|
||
|
@@ -883,19 +880,17 @@ private static boolean retrieveFile(final RestHighLevelClient restHighLevelClien | |
} | ||
|
||
private static boolean retrieveFile(final RestHighLevelClient restHighLevelClient, final String filepath, final String index, final String _id, final boolean legacy, final boolean populateFileIfEmpty) { | ||
String type = "_doc"; | ||
String id = _id; | ||
|
||
if(legacy) { | ||
type = "security"; | ||
id = _id; | ||
|
||
} | ||
|
||
System.out.println("Will retrieve '"+type+"/" +id+"' into "+filepath+" "+(legacy?"(legacy mode)":"")); | ||
System.out.println("Will retrieve '"+"/" +id+"' into "+filepath+" "+(legacy?"(legacy mode)":"")); | ||
try (Writer writer = new FileWriter(filepath)) { | ||
|
||
final GetResponse response = restHighLevelClient.get(new GetRequest(index).type(type).id(id).refresh(true).realtime(false), RequestOptions.DEFAULT); | ||
final GetResponse response = restHighLevelClient.get(new GetRequest(index).id(id).refresh(true).realtime(false), RequestOptions.DEFAULT); | ||
|
||
boolean isEmpty = !response.isExists() || response.isSourceEmpty(); | ||
String yaml; | ||
|
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.
out of curiosity, why is this change reqd?