@@ -54,6 +54,10 @@ public class ProjectStateRegistry extends AbstractNamedDiffable<Custom> implemen
5454 // A counter that is incremented each time one or more projects are marked for deletion.
5555 private final long projectsMarkedForDeletionGeneration ;
5656
57+ public static ProjectStateRegistry get (ClusterState clusterState ) {
58+ return clusterState .custom (TYPE , EMPTY );
59+ }
60+
5761 public ProjectStateRegistry (StreamInput in ) throws IOException {
5862 if (in .getTransportVersion ().onOrAfter (TransportVersions .PROJECT_STATE_REGISTRY_ENTRY )) {
5963 projectsEntries = in .readMap (ProjectId ::readFrom , Entry ::readFrom );
@@ -80,6 +84,10 @@ private ProjectStateRegistry(
8084 this .projectsMarkedForDeletionGeneration = projectsMarkedForDeletionGeneration ;
8185 }
8286
87+ public boolean hasProject (ProjectId projectId ) {
88+ return projectsEntries .containsKey (projectId );
89+ }
90+
8391 /**
8492 * Retrieves the settings for a specific project based on its project ID from the specified cluster state without creating a new object.
8593 * If you need a full state of the project rather than just its setting, please use {@link ClusterState#projectState(ProjectId)}
@@ -97,6 +105,10 @@ public Settings getProjectSettings(ProjectId projectId) {
97105 return projectsEntries .getOrDefault (projectId , EMPTY_ENTRY ).settings ;
98106 }
99107
108+ public Set <ProjectId > getProjectsMarkedForDeletion () {
109+ return projectsMarkedForDeletion ;
110+ }
111+
100112 public boolean isProjectMarkedForDeletion (ProjectId projectId ) {
101113 return projectsMarkedForDeletion .contains (projectId );
102114 }
@@ -310,6 +322,12 @@ public Builder markProjectForDeletion(ProjectId projectId) {
310322 return this ;
311323 }
312324
325+ public Builder removeProject (ProjectId projectId ) {
326+ projectsEntries .remove (projectId );
327+ projectsMarkedForDeletion .remove (projectId );
328+ return this ;
329+ }
330+
313331 public ProjectStateRegistry build () {
314332 final var unknownButUnderDeletion = Sets .difference (projectsMarkedForDeletion , projectsEntries .keys ());
315333 if (unknownButUnderDeletion .isEmpty () == false ) {
@@ -319,7 +337,7 @@ public ProjectStateRegistry build() {
319337 }
320338 return new ProjectStateRegistry (
321339 projectsEntries .build (),
322- projectsMarkedForDeletion ,
340+ Collections . unmodifiableSet ( projectsMarkedForDeletion ) ,
323341 newProjectMarkedForDeletion ? projectsMarkedForDeletionGeneration + 1 : projectsMarkedForDeletionGeneration
324342 );
325343 }
0 commit comments