@@ -54,6 +54,10 @@ public class ProjectStateRegistry extends AbstractNamedDiffable<Custom> implemen
54
54
// A counter that is incremented each time one or more projects are marked for deletion.
55
55
private final long projectsMarkedForDeletionGeneration ;
56
56
57
+ public static ProjectStateRegistry get (ClusterState clusterState ) {
58
+ return clusterState .custom (TYPE , EMPTY );
59
+ }
60
+
57
61
public ProjectStateRegistry (StreamInput in ) throws IOException {
58
62
if (in .getTransportVersion ().onOrAfter (TransportVersions .PROJECT_STATE_REGISTRY_ENTRY )) {
59
63
projectsEntries = in .readMap (ProjectId ::readFrom , Entry ::readFrom );
@@ -80,6 +84,10 @@ private ProjectStateRegistry(
80
84
this .projectsMarkedForDeletionGeneration = projectsMarkedForDeletionGeneration ;
81
85
}
82
86
87
+ public boolean hasProject (ProjectId projectId ) {
88
+ return projectsEntries .containsKey (projectId );
89
+ }
90
+
83
91
/**
84
92
* Retrieves the settings for a specific project based on its project ID from the specified cluster state without creating a new object.
85
93
* 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) {
97
105
return projectsEntries .getOrDefault (projectId , EMPTY_ENTRY ).settings ;
98
106
}
99
107
108
+ public Set <ProjectId > getProjectsMarkedForDeletion () {
109
+ return projectsMarkedForDeletion ;
110
+ }
111
+
100
112
public boolean isProjectMarkedForDeletion (ProjectId projectId ) {
101
113
return projectsMarkedForDeletion .contains (projectId );
102
114
}
@@ -310,6 +322,12 @@ public Builder markProjectForDeletion(ProjectId projectId) {
310
322
return this ;
311
323
}
312
324
325
+ public Builder removeProject (ProjectId projectId ) {
326
+ projectsEntries .remove (projectId );
327
+ projectsMarkedForDeletion .remove (projectId );
328
+ return this ;
329
+ }
330
+
313
331
public ProjectStateRegistry build () {
314
332
final var unknownButUnderDeletion = Sets .difference (projectsMarkedForDeletion , projectsEntries .keys ());
315
333
if (unknownButUnderDeletion .isEmpty () == false ) {
@@ -319,7 +337,7 @@ public ProjectStateRegistry build() {
319
337
}
320
338
return new ProjectStateRegistry (
321
339
projectsEntries .build (),
322
- projectsMarkedForDeletion ,
340
+ Collections . unmodifiableSet ( projectsMarkedForDeletion ) ,
323
341
newProjectMarkedForDeletion ? projectsMarkedForDeletionGeneration + 1 : projectsMarkedForDeletionGeneration
324
342
);
325
343
}
0 commit comments