File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
main/java/org/elasticsearch/cluster/project
test/java/org/elasticsearch/cluster/project Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -84,6 +84,10 @@ private ProjectStateRegistry(
8484 this .projectsMarkedForDeletionGeneration = projectsMarkedForDeletionGeneration ;
8585 }
8686
87+ public boolean hasProject (ProjectId projectId ) {
88+ return projectsEntries .containsKey (projectId );
89+ }
90+
8791 /**
8892 * Retrieves the settings for a specific project based on its project ID from the specified cluster state without creating a new object.
8993 * If you need a full state of the project rather than just its setting, please use {@link ClusterState#projectState(ProjectId)}
@@ -318,6 +322,12 @@ public Builder markProjectForDeletion(ProjectId projectId) {
318322 return this ;
319323 }
320324
325+ public Builder removeProject (ProjectId projectId ) {
326+ projectsEntries .remove (projectId );
327+ projectsMarkedForDeletion .remove (projectId );
328+ return this ;
329+ }
330+
321331 public ProjectStateRegistry build () {
322332 final var unknownButUnderDeletion = Sets .difference (projectsMarkedForDeletion , projectsEntries .keys ());
323333 if (unknownButUnderDeletion .isEmpty () == false ) {
@@ -327,7 +337,7 @@ public ProjectStateRegistry build() {
327337 }
328338 return new ProjectStateRegistry (
329339 projectsEntries .build (),
330- projectsMarkedForDeletion ,
340+ Collections . unmodifiableSet ( projectsMarkedForDeletion ) ,
331341 newProjectMarkedForDeletion ? projectsMarkedForDeletionGeneration + 1 : projectsMarkedForDeletionGeneration
332342 );
333343 }
Original file line number Diff line number Diff line change @@ -46,6 +46,11 @@ public void testBuilder() {
4646 var unknownProjectId = randomUniqueProjectId ();
4747 var throwingBuilder = ProjectStateRegistry .builder (projectStateRegistry ).markProjectForDeletion (unknownProjectId );
4848 assertThrows (IllegalArgumentException .class , throwingBuilder ::build );
49+
50+ var projectToRemove = randomFrom (projectStateRegistry .knownProjects ());
51+ projectStateRegistry = ProjectStateRegistry .builder (projectStateRegistry ).removeProject (projectToRemove ).build ();
52+ assertFalse (projectStateRegistry .hasProject (projectToRemove ));
53+ assertFalse (projectStateRegistry .isProjectMarkedForDeletion (projectToRemove ));
4954 }
5055
5156 public void testDiff () {
You can’t perform that action at this time.
0 commit comments