Skip to content

Commit 9afbe3a

Browse files
cwperksstephen-crawford
authored andcommitted
Remove references to LegacyESVersion.V_7x constants (opensearch-project#2151)
* Remove references to LegacyESVersion.V_7x constants Signed-off-by: Craig Perkins <[email protected]> Signed-off-by: Stephen Crawford <[email protected]>
1 parent ef212a8 commit 9afbe3a

File tree

4 files changed

+2
-78
lines changed

4 files changed

+2
-78
lines changed

src/main/java/org/opensearch/security/action/configupdate/TransportConfigUpdateAction.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
import org.opensearch.action.FailedNodeException;
3636
import org.opensearch.action.support.ActionFilters;
37-
import org.opensearch.action.support.nodes.BaseNodeRequest;
3837
import org.opensearch.action.support.nodes.TransportNodesAction;
3938
import org.opensearch.cluster.service.ClusterService;
4039
import org.opensearch.common.inject.Inject;
@@ -47,6 +46,7 @@
4746
import org.opensearch.security.securityconf.DynamicConfigFactory;
4847
import org.opensearch.security.securityconf.impl.CType;
4948
import org.opensearch.threadpool.ThreadPool;
49+
import org.opensearch.transport.TransportRequest;
5050
import org.opensearch.transport.TransportService;
5151

5252
public class TransportConfigUpdateAction
@@ -72,7 +72,7 @@ public TransportConfigUpdateAction(final Settings settings,
7272
this.dynamicConfigFactory = dynamicConfigFactory;
7373
}
7474

75-
public static class NodeConfigUpdateRequest extends BaseNodeRequest {
75+
public static class NodeConfigUpdateRequest extends TransportRequest {
7676

7777
ConfigUpdateRequest request;
7878

src/main/java/org/opensearch/security/configuration/ClusterInfoHolder.java

-49
Original file line numberDiff line numberDiff line change
@@ -26,49 +26,23 @@
2626

2727
package org.opensearch.security.configuration;
2828

29-
import java.util.Iterator;
30-
import java.util.List;
31-
3229
import org.apache.logging.log4j.LogManager;
3330
import org.apache.logging.log4j.Logger;
3431

35-
import org.opensearch.LegacyESVersion;
3632
import org.opensearch.cluster.ClusterChangedEvent;
37-
import org.opensearch.cluster.ClusterState;
3833
import org.opensearch.cluster.ClusterStateListener;
39-
import org.opensearch.cluster.metadata.IndexMetadata;
4034
import org.opensearch.cluster.node.DiscoveryNode;
4135
import org.opensearch.cluster.node.DiscoveryNodes;
42-
import org.opensearch.index.Index;
4336

4437
public class ClusterInfoHolder implements ClusterStateListener {
4538

4639
protected final Logger log = LogManager.getLogger(this.getClass());
47-
private volatile Boolean has6xNodes = null;
48-
private volatile Boolean has6xIndices = null;
4940
private volatile DiscoveryNodes nodes = null;
5041
private volatile Boolean isLocalNodeElectedClusterManager = null;
5142
private volatile boolean initialized;
5243

5344
@Override
5445
public void clusterChanged(ClusterChangedEvent event) {
55-
final boolean isTraceEnabled = log.isTraceEnabled();
56-
if(has6xNodes == null || event.nodesChanged()) {
57-
has6xNodes = Boolean.valueOf(clusterHas6xNodes(event.state()));
58-
if (isTraceEnabled) {
59-
log.trace("has6xNodes: {}", has6xNodes);
60-
}
61-
}
62-
63-
final List<String> indicesCreated = event.indicesCreated();
64-
final List<Index> indicesDeleted = event.indicesDeleted();
65-
if(has6xIndices == null || !indicesCreated.isEmpty() || !indicesDeleted.isEmpty()) {
66-
has6xIndices = Boolean.valueOf(clusterHas6xIndices(event.state()));
67-
if (isTraceEnabled) {
68-
log.trace("has6xIndices: {}", has6xIndices);
69-
}
70-
}
71-
7246
if(nodes == null || event.nodesChanged()) {
7347
nodes = event.state().nodes();
7448
if (log.isDebugEnabled()) {
@@ -80,14 +54,6 @@ public void clusterChanged(ClusterChangedEvent event) {
8054
isLocalNodeElectedClusterManager = event.localNodeClusterManager()?Boolean.TRUE:Boolean.FALSE;
8155
}
8256

83-
public Boolean getHas6xNodes() {
84-
return has6xNodes;
85-
}
86-
87-
public Boolean getHas6xIndices() {
88-
return has6xIndices;
89-
}
90-
9157
public Boolean isLocalNodeElectedClusterManager() {
9258
return isLocalNodeElectedClusterManager;
9359
}
@@ -106,19 +72,4 @@ public Boolean hasNode(DiscoveryNode node) {
10672

10773
return nodes.nodeExists(node)?Boolean.TRUE:Boolean.FALSE;
10874
}
109-
110-
private static boolean clusterHas6xNodes(ClusterState state) {
111-
return state.nodes().getMinNodeVersion().before(LegacyESVersion.V_7_0_0);
112-
}
113-
114-
private static boolean clusterHas6xIndices(ClusterState state) {
115-
final Iterator<IndexMetadata> indices = state.metadata().indices().valuesIt();
116-
while (indices.hasNext()) {
117-
final IndexMetadata indexMetadata = indices.next();
118-
if (indexMetadata.getCreationVersion().before(LegacyESVersion.V_7_0_0)) {
119-
return true;
120-
}
121-
}
122-
return false;
123-
}
12475
}

src/main/java/org/opensearch/security/configuration/ConfigurationLoaderSecurity7.java

-18
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.apache.logging.log4j.LogManager;
4040
import org.apache.logging.log4j.Logger;
4141

42-
import org.opensearch.LegacyESVersion;
4342
import org.opensearch.action.ActionListener;
4443
import org.opensearch.action.get.GetResponse;
4544
import org.opensearch.action.get.MultiGetItemResponse;
@@ -125,23 +124,6 @@ public void singleFailure(Failure failure) {
125124
public void noData(String id) {
126125
CType cType = CType.fromString(id);
127126

128-
//when index was created with ES 6 there are no separate tenants. So we load just empty ones.
129-
//when index was created with ES 7 and type not "security" (ES 6 type) there are no rolemappings anymore.
130-
if(cs.state().metadata().index(securityIndex).getCreationVersion().before(LegacyESVersion.V_7_0_0)) {
131-
//created with SG 6
132-
//skip tenants
133-
134-
if (isDebugEnabled) {
135-
log.debug("Skip tenants because we not yet migrated to ES 7 (index was created with ES 6)");
136-
}
137-
138-
if(cType == CType.TENANTS) {
139-
rs.put(cType, SecurityDynamicConfiguration.empty());
140-
latch.countDown();
141-
return;
142-
}
143-
}
144-
145127
// Since NODESDN is newly introduced data-type applying for existing clusters as well, we make it backward compatible by returning valid empty
146128
// SecurityDynamicConfiguration.
147129
// Same idea for new setting WHITELIST/ALLOWLIST

src/main/java/org/opensearch/security/dlic/rest/api/MigrateApiAction.java

-9
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import com.fasterxml.jackson.databind.JsonNode;
2121
import com.google.common.collect.ImmutableList;
2222

23-
import org.opensearch.LegacyESVersion;
24-
import org.opensearch.Version;
2523
import org.opensearch.action.ActionListener;
2624
import org.opensearch.action.admin.indices.create.CreateIndexResponse;
2725
import org.opensearch.action.bulk.BulkRequestBuilder;
@@ -98,13 +96,6 @@ protected Endpoint getEndpoint() {
9896
@Override
9997
protected void handlePost(RestChannel channel, RestRequest request, Client client, final JsonNode content) throws IOException {
10098

101-
final Version oldestNodeVersion = cs.state().getNodes().getMinNodeVersion();
102-
103-
if(oldestNodeVersion.before(LegacyESVersion.V_7_0_0)) {
104-
badRequestResponse(channel, "Can not migrate configuration because cluster is not fully migrated.");
105-
return;
106-
}
107-
10899
final SecurityDynamicConfiguration<?> loadedConfig = load(CType.CONFIG, true);
109100

110101
if (loadedConfig.getVersion() != 1) {

0 commit comments

Comments
 (0)