Skip to content

Commit 84c38fc

Browse files
committed
fixup!
1 parent 6661c6f commit 84c38fc

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/support/SecurityIndexManager.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public void clusterChanged(ClusterChangedEvent event) {
290290
final Set<String> reservedStateRoleMappingNames = ReservedRoleMappingAction.getFileSettingsMetadataHandlerRoleMappingKeys(
291291
event.state()
292292
);
293-
final boolean clusterStateRoleMappingsSynced = reservedStateRoleMappingNames.size() == RoleMappingMetadata.getFromClusterState(
293+
final boolean reservedRoleMappingsSynced = reservedStateRoleMappingNames.size() == RoleMappingMetadata.getFromClusterState(
294294
event.state()
295295
).getRoleMappings().size();
296296
final boolean mappingIsUpToDate = indexMetadata == null || checkIndexMappingUpToDate(event.state());
@@ -323,7 +323,7 @@ public void clusterChanged(ClusterChangedEvent event) {
323323
indexAvailableForWrite,
324324
mappingIsUpToDate,
325325
createdOnLatestVersion,
326-
clusterStateRoleMappingsSynced,
326+
reservedRoleMappingsSynced,
327327
migrationsVersion,
328328
minClusterMappingVersion,
329329
indexMappingVersion,
@@ -704,7 +704,7 @@ public static class State {
704704
public final boolean indexAvailableForWrite;
705705
public final boolean mappingUpToDate;
706706
public final boolean createdOnLatestVersion;
707-
public final boolean clusterStateRoleMappingsSynced;
707+
public final boolean reservedRoleMappingsSynced;
708708
public final Integer migrationsVersion;
709709
// Min mapping version supported by the descriptors in the cluster
710710
public final SystemIndexDescriptor.MappingsVersion minClusterMappingVersion;
@@ -724,7 +724,7 @@ public State(
724724
boolean indexAvailableForWrite,
725725
boolean mappingUpToDate,
726726
boolean createdOnLatestVersion,
727-
boolean clusterStateRoleMappingsSynced,
727+
boolean reservedRoleMappingsSynced,
728728
Integer migrationsVersion,
729729
SystemIndexDescriptor.MappingsVersion minClusterMappingVersion,
730730
Integer indexMappingVersion,
@@ -742,7 +742,7 @@ public State(
742742
this.mappingUpToDate = mappingUpToDate;
743743
this.migrationsVersion = migrationsVersion;
744744
this.createdOnLatestVersion = createdOnLatestVersion;
745-
this.clusterStateRoleMappingsSynced = clusterStateRoleMappingsSynced;
745+
this.reservedRoleMappingsSynced = reservedRoleMappingsSynced;
746746
this.minClusterMappingVersion = minClusterMappingVersion;
747747
this.indexMappingVersion = indexMappingVersion;
748748
this.concreteIndexName = concreteIndexName;
@@ -764,7 +764,7 @@ public boolean equals(Object o) {
764764
&& indexAvailableForWrite == state.indexAvailableForWrite
765765
&& mappingUpToDate == state.mappingUpToDate
766766
&& createdOnLatestVersion == state.createdOnLatestVersion
767-
&& clusterStateRoleMappingsSynced == state.clusterStateRoleMappingsSynced
767+
&& reservedRoleMappingsSynced == state.reservedRoleMappingsSynced
768768
&& Objects.equals(indexMappingVersion, state.indexMappingVersion)
769769
&& Objects.equals(migrationsVersion, state.migrationsVersion)
770770
&& Objects.equals(minClusterMappingVersion, state.minClusterMappingVersion)
@@ -788,7 +788,7 @@ public int hashCode() {
788788
indexAvailableForWrite,
789789
mappingUpToDate,
790790
createdOnLatestVersion,
791-
clusterStateRoleMappingsSynced,
791+
reservedRoleMappingsSynced,
792792
migrationsVersion,
793793
minClusterMappingVersion,
794794
indexMappingVersion,
@@ -814,8 +814,8 @@ public String toString() {
814814
+ mappingUpToDate
815815
+ ", createdOnLatestVersion="
816816
+ createdOnLatestVersion
817-
+ ", clusterStateRoleMappingsSynced="
818-
+ clusterStateRoleMappingsSynced
817+
+ ", reservedRoleMappingsSynced="
818+
+ reservedRoleMappingsSynced
819819
+ ", migrationsVersion="
820820
+ migrationsVersion
821821
+ ", minClusterMappingVersion="

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/support/SecurityMigrations.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ public interface SecurityMigration {
6464
*/
6565
Set<NodeFeature> nodeFeaturesRequired();
6666

67+
/**
68+
* Check that any pre-conditions are met before launching migration
69+
*
70+
* @param securityIndexManagerState current state of the security index
71+
* @return true if pre-conditions met, otherwise false
72+
*/
6773
default boolean checkPreConditions(SecurityIndexManager.State securityIndexManagerState) {
6874
return true;
6975
}
@@ -145,7 +151,7 @@ public void migrate(SecurityIndexManager securityIndexManager, Client client, Ac
145151
}
146152

147153
getNativeRoleMappings(client, ActionListener.wrap(roleMappings -> {
148-
logger.info("Found [" + roleMappings.size() + "] to cleanup in .security index.");
154+
logger.info("Found [" + roleMappings.size() + "] role mappings to cleanup in .security index.");
149155
deleteNativeRoleMappings(client, roleMappings.iterator(), listener);
150156
}, listener::onFailure), clusterStateRoleMappingNames.toArray(String[]::new));
151157
}
@@ -173,6 +179,8 @@ private void deleteNativeRoleMappings(Client client, Iterator<String> namesItera
173179
ActionListener.wrap(response -> {
174180
if (response.isFound() == false) {
175181
logger.warn("Expected role mapping [" + name + "] not found during role mapping clean up.");
182+
} else {
183+
logger.info("Deleted duplicated role mapping [" + name + "] from .security index");
176184
}
177185
if (namesIterator.hasNext()) {
178186
deleteNativeRoleMappings(client, namesIterator, listener);
@@ -186,7 +194,7 @@ private void deleteNativeRoleMappings(Client client, Iterator<String> namesItera
186194
@Override
187195
public boolean checkPreConditions(SecurityIndexManager.State securityIndexManagerState) {
188196
// If there are operator defined role mappings, make sure they've been loaded in to cluster state before launching migration
189-
return securityIndexManagerState.clusterStateRoleMappingsSynced;
197+
return securityIndexManagerState.reservedRoleMappingsSynced;
190198
}
191199

192200
@Override

0 commit comments

Comments
 (0)