Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ public final class RoleMappingMetadata extends AbstractNamedDiffable<Metadata.Pr

private static final RoleMappingMetadata EMPTY = new RoleMappingMetadata(Set.of());

public static RoleMappingMetadata getFromClusterState(ClusterState clusterState) {
final ProjectMetadata project = clusterState.metadata().getProject();
return getFromProject(project);
}

public static RoleMappingMetadata getFromProject(ProjectMetadata project) {
return project.custom(RoleMappingMetadata.TYPE, RoleMappingMetadata.EMPTY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.apache.lucene.tests.util.LuceneTestCase;
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.ProjectId;
import org.elasticsearch.core.Tuple;
import org.elasticsearch.integration.RoleMappingFileSettingsIT;
import org.elasticsearch.reservedstate.service.FileSettingsService;
Expand Down Expand Up @@ -272,9 +273,10 @@ private void assertRoleMappingsInClusterStateWithAwait(
}

private void assertRoleMappingsInClusterState(ClusterState clusterState, ExpressionRoleMapping... expectedRoleMappings) {
final var project = clusterState.metadata().getProject(ProjectId.DEFAULT);
String[] expectedRoleMappingNames = Arrays.stream(expectedRoleMappings).map(ExpressionRoleMapping::getName).toArray(String[]::new);
assertRoleMappingReservedMetadata(clusterState, expectedRoleMappingNames);
var actualRoleMappings = new ArrayList<>(RoleMappingMetadata.getFromClusterState(clusterState).getRoleMappings());
var actualRoleMappings = new ArrayList<>(RoleMappingMetadata.getFromProject(project).getRoleMappings());
assertThat(actualRoleMappings, containsInAnyOrder(expectedRoleMappings));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.ClusterStateListener;
import org.elasticsearch.cluster.ClusterStateUpdateTask;
import org.elasticsearch.cluster.metadata.ProjectId;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.settings.Settings;
Expand Down Expand Up @@ -444,6 +445,7 @@ private SignedJWT getSignedJWT(JWTClaimsSet claimsSet) throws Exception {
}

private void publishRoleMappings(Set<ExpressionRoleMapping> roleMappings) throws InterruptedException {
final ProjectId projectId = ProjectId.DEFAULT;
RoleMappingMetadata roleMappingMetadata = new RoleMappingMetadata(roleMappings);
List<ClusterService> clusterServices = new ArrayList<>();
internalCluster().getInstances(ClusterService.class).forEach(clusterServices::add);
Expand All @@ -452,7 +454,8 @@ private void publishRoleMappings(Set<ExpressionRoleMapping> roleMappings) throws
clusterService.addListener(new ClusterStateListener() {
@Override
public void clusterChanged(ClusterChangedEvent event) {
RoleMappingMetadata publishedRoleMappingMetadata = RoleMappingMetadata.getFromClusterState(event.state());
final var project = event.state().metadata().getProject(projectId);
RoleMappingMetadata publishedRoleMappingMetadata = RoleMappingMetadata.getFromProject(project);
if (roleMappingMetadata.equals(publishedRoleMappingMetadata)) {
clusterService.removeListener(this);
publishedClusterState.countDown();
Expand All @@ -464,7 +467,9 @@ public void clusterChanged(ClusterChangedEvent event) {
masterClusterService.submitUnbatchedStateUpdateTask("test-add-role-mapping", new ClusterStateUpdateTask() {
@Override
public ClusterState execute(ClusterState currentState) {
return roleMappingMetadata.updateClusterState(currentState);
return ClusterState.builder(currentState)
.putProjectMetadata(roleMappingMetadata.updateProject(currentState.getMetadata().getProject(projectId)))
.build();
}

@Override
Expand Down