Skip to content

Commit d36b6a8

Browse files
committed
Rename to EntitledNodePaths
1 parent 5e318eb commit d36b6a8

File tree

9 files changed

+59
-48
lines changed

9 files changed

+59
-48
lines changed

server/src/internalClusterTest/java/org/elasticsearch/discovery/single/SingleNodeDiscoveryIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public Path nodeConfigPath(int nodeOrdinal) {
8888
"other",
8989
Arrays.asList(getTestTransportPlugin(), MockHttpTransport.TestPlugin.class),
9090
Function.identity(),
91-
TEST_ENTITLEMENTS::newNodeGrant
91+
TEST_ENTITLEMENTS::addEntitledNodePaths
9292
);
9393
try {
9494
other.beforeTest(random());
@@ -139,7 +139,7 @@ public Path nodeConfigPath(int nodeOrdinal) {
139139
"other",
140140
Arrays.asList(getTestTransportPlugin(), MockHttpTransport.TestPlugin.class),
141141
Function.identity(),
142-
TEST_ENTITLEMENTS::newNodeGrant
142+
TEST_ENTITLEMENTS::addEntitledNodePaths
143143
);
144144
try (var mockLog = MockLog.capture(JoinHelper.class)) {
145145
mockLog.addExpectation(

server/src/internalClusterTest/java/org/elasticsearch/snapshots/MultiClusterRepoAccessIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public Path nodeConfigPath(int nodeOrdinal) {
7878
getTestTransportPlugin()
7979
),
8080
Function.identity(),
81-
TEST_ENTITLEMENTS::newNodeGrant
81+
TEST_ENTITLEMENTS::addEntitledNodePaths
8282
);
8383
secondCluster.beforeTest(random());
8484
}

test/framework/src/main/java/org/elasticsearch/entitlement/bootstrap/TestEntitlementsRule.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,10 @@ public void evaluate() throws Throwable {
142142
}
143143

144144
/**
145-
* Creates a entitlement grant for node specific paths.
145+
* Temporarily adds node paths based entitlements based on a node's {@code settings} and {@code configPath}
146+
* until the returned handle is closed.
146147
*/
147-
public Closeable newNodeGrant(Settings settings, Path configPath) {
148+
public Closeable addEntitledNodePaths(Settings settings, Path configPath) {
148149
if (POLICY_MANAGER == null) {
149150
return () -> {}; // noop if not running with entitlements
150151
}
@@ -153,20 +154,20 @@ public Closeable newNodeGrant(Settings settings, Path configPath) {
153154
while (unwrappedConfigPath instanceof FilterPath fPath) {
154155
unwrappedConfigPath = fPath.getDelegate();
155156
}
156-
NodeGrant nodeGrant = new NodeGrant(settings, unwrappedConfigPath, this::revokeGrant);
157-
addGrant(nodeGrant);
158-
return nodeGrant;
157+
EntitledNodePaths entitledNodePaths = new EntitledNodePaths(settings, unwrappedConfigPath, this::removeEntitledNodePaths);
158+
addEntitledNodePaths(entitledNodePaths);
159+
return entitledNodePaths;
159160
}
160161

161162
/**
162-
* Revoke all open node grants.
163+
* Revoke all entitled node paths.
163164
*/
164-
public void revokeNodeGrants() {
165+
public void revokeAllEntitledNodePaths() {
165166
BASE_DIR_PATHS.keySet().retainAll(List.of(TEMP));
166167
POLICY_MANAGER.clearModuleEntitlementsCache();
167168
}
168169

169-
private record NodeGrant(Settings settings, Path configPath, Consumer<NodeGrant> onClose) implements Closeable {
170+
private record EntitledNodePaths(Settings settings, Path configPath, Consumer<EntitledNodePaths> onClose) implements Closeable {
170171
private Path homeDir() {
171172
return absolutePath(PATH_HOME_SETTING.get(settings));
172173
}
@@ -179,7 +180,7 @@ private Path[] dataDirs() {
179180
List<String> dataDirs = PATH_DATA_SETTING.get(settings);
180181
return dataDirs.isEmpty()
181182
? new Path[] { homeDir().resolve("data") }
182-
: dataDirs.stream().map(NodeGrant::absolutePath).toArray(Path[]::new);
183+
: dataDirs.stream().map(EntitledNodePaths::absolutePath).toArray(Path[]::new);
183184
}
184185

185186
private Path[] sharedDataDir() {
@@ -188,7 +189,7 @@ private Path[] sharedDataDir() {
188189
}
189190

190191
private Path[] repoDirs() {
191-
return PATH_REPO_SETTING.get(settings).stream().map(NodeGrant::absolutePath).toArray(Path[]::new);
192+
return PATH_REPO_SETTING.get(settings).stream().map(EntitledNodePaths::absolutePath).toArray(Path[]::new);
192193
}
193194

194195
@SuppressForbidden(reason = "must be resolved using the default file system, rather then the mocked test file system")
@@ -207,7 +208,7 @@ public void close() {
207208
@Override
208209
public String toString() {
209210
return Strings.format(
210-
"NodeGrant[configDir=%s, dataDirs=%s, sharedDataDir=%s, repoDirs=%s]",
211+
"EntitledNodePaths[configDir=%s, dataDirs=%s, sharedDataDir=%s, repoDirs=%s]",
211212
configDir(),
212213
dataDirs(),
213214
sharedDataDir(),
@@ -216,21 +217,21 @@ public String toString() {
216217
}
217218
}
218219

219-
private void addGrant(NodeGrant nodeGrant) {
220-
logger.debug("Adding node grant: {}", nodeGrant);
221-
BASE_DIR_PATHS.compute(BaseDir.CONFIG, baseDirModifier(Collection::add, nodeGrant.configDir()));
222-
BASE_DIR_PATHS.compute(BaseDir.DATA, baseDirModifier(Collection::add, nodeGrant.dataDirs()));
223-
BASE_DIR_PATHS.compute(BaseDir.SHARED_DATA, baseDirModifier(Collection::add, nodeGrant.sharedDataDir()));
224-
BASE_DIR_PATHS.compute(BaseDir.SHARED_REPO, baseDirModifier(Collection::add, nodeGrant.repoDirs()));
220+
private void addEntitledNodePaths(EntitledNodePaths entitledNodePaths) {
221+
logger.debug("Adding {}", entitledNodePaths);
222+
BASE_DIR_PATHS.compute(BaseDir.CONFIG, baseDirModifier(Collection::add, entitledNodePaths.configDir()));
223+
BASE_DIR_PATHS.compute(BaseDir.DATA, baseDirModifier(Collection::add, entitledNodePaths.dataDirs()));
224+
BASE_DIR_PATHS.compute(BaseDir.SHARED_DATA, baseDirModifier(Collection::add, entitledNodePaths.sharedDataDir()));
225+
BASE_DIR_PATHS.compute(BaseDir.SHARED_REPO, baseDirModifier(Collection::add, entitledNodePaths.repoDirs()));
225226
POLICY_MANAGER.clearModuleEntitlementsCache();
226227
}
227228

228-
private void revokeGrant(NodeGrant nodeGrant) {
229-
logger.debug("Revoking node grant: {}", nodeGrant);
230-
BASE_DIR_PATHS.compute(BaseDir.CONFIG, baseDirModifier(Collection::remove, nodeGrant.configDir()));
231-
BASE_DIR_PATHS.compute(BaseDir.DATA, baseDirModifier(Collection::remove, nodeGrant.dataDirs()));
232-
BASE_DIR_PATHS.compute(BaseDir.SHARED_DATA, baseDirModifier(Collection::remove, nodeGrant.sharedDataDir()));
233-
BASE_DIR_PATHS.compute(BaseDir.SHARED_REPO, baseDirModifier(Collection::remove, nodeGrant.repoDirs()));
229+
private void removeEntitledNodePaths(EntitledNodePaths entitledNodePaths) {
230+
logger.debug("Removing {}", entitledNodePaths);
231+
BASE_DIR_PATHS.compute(BaseDir.CONFIG, baseDirModifier(Collection::remove, entitledNodePaths.configDir()));
232+
BASE_DIR_PATHS.compute(BaseDir.DATA, baseDirModifier(Collection::remove, entitledNodePaths.dataDirs()));
233+
BASE_DIR_PATHS.compute(BaseDir.SHARED_DATA, baseDirModifier(Collection::remove, entitledNodePaths.sharedDataDir()));
234+
BASE_DIR_PATHS.compute(BaseDir.SHARED_REPO, baseDirModifier(Collection::remove, entitledNodePaths.repoDirs()));
234235
POLICY_MANAGER.clearModuleEntitlementsCache();
235236
}
236237

test/framework/src/main/java/org/elasticsearch/test/AbstractMultiClustersTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public final void startClusters() throws Exception {
128128
clusterName + "-",
129129
mockPlugins,
130130
Function.identity(),
131-
TEST_ENTITLEMENTS::newNodeGrant
131+
TEST_ENTITLEMENTS::addEntitledNodePaths
132132
);
133133
try {
134134
cluster.beforeTest(random());

test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ private TestCluster buildAndPutCluster(Scope currentClusterScope, long seed) thr
549549
// close the previous one and create a new one
550550
if (testCluster != null) {
551551
IOUtils.closeWhileHandlingException(testCluster::close);
552-
TEST_ENTITLEMENTS.revokeNodeGrants();
552+
TEST_ENTITLEMENTS.revokeAllEntitledNodePaths();
553553
}
554554
testCluster = buildTestCluster(currentClusterScope, seed);
555555
}
@@ -2338,7 +2338,7 @@ protected TestCluster buildTestCluster(Scope scope, long seed) throws IOExceptio
23382338
forbidPrivateIndexSettings(),
23392339
forceSingleDataPath(),
23402340
autoManageVotingExclusions(),
2341-
TEST_ENTITLEMENTS::newNodeGrant
2341+
TEST_ENTITLEMENTS::addEntitledNodePaths
23422342
);
23432343
}
23442344

test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ private Node newNode() {
288288
plugins.add(ConcurrentSearchTestPlugin.class);
289289
}
290290
plugins.add(MockScriptService.TestPlugin.class);
291-
Node node = new MockNode(settings, plugins, forbidPrivateIndexSettings(), TEST_ENTITLEMENTS.newNodeGrant(settings, null));
291+
Node node = new MockNode(settings, plugins, forbidPrivateIndexSettings(), TEST_ENTITLEMENTS.addEntitledNodePaths(settings, null));
292292
try {
293293
node.start();
294294
} catch (NodeValidationException e) {

test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,13 @@
178178
* </p>
179179
*/
180180
public final class InternalTestCluster extends TestCluster {
181-
public interface NodeGrantProvider {
182-
Closeable create(Settings settings, Path configPath);
181+
182+
/**
183+
* Temporarily adds node paths based entitlements based on a node's {@code settings} and {@code configPath}
184+
* until the returned handle is closed.
185+
*/
186+
public interface EntitledNodePathsProvider {
187+
Closeable addEntitledNodePaths(Settings settings, Path configPath);
183188
}
184189

185190
private static final Logger logger = LogManager.getLogger(InternalTestCluster.class);
@@ -281,7 +286,7 @@ public String toString() {
281286
// index of node to bootstrap as master, or BOOTSTRAP_MASTER_NODE_INDEX_AUTO or BOOTSTRAP_MASTER_NODE_INDEX_DONE
282287
private int bootstrapMasterNodeIndex = BOOTSTRAP_MASTER_NODE_INDEX_AUTO;
283288

284-
private final NodeGrantProvider nodeGrantProvider;
289+
private final EntitledNodePathsProvider entitledNodePathsProvider;
285290

286291
public InternalTestCluster(
287292
final long clusterSeed,
@@ -296,7 +301,7 @@ public InternalTestCluster(
296301
final String nodePrefix,
297302
final Collection<Class<? extends Plugin>> mockPlugins,
298303
final Function<Client, Client> clientWrapper,
299-
NodeGrantProvider nodeGrantProvider
304+
EntitledNodePathsProvider entitledNodePathsProvider
300305
) {
301306
this(
302307
clusterSeed,
@@ -314,7 +319,7 @@ public InternalTestCluster(
314319
true,
315320
false,
316321
true,
317-
nodeGrantProvider
322+
entitledNodePathsProvider
318323
);
319324
}
320325

@@ -334,7 +339,7 @@ public InternalTestCluster(
334339
final boolean forbidPrivateIndexSettings,
335340
final boolean forceSingleDataPath,
336341
final boolean autoManageVotingExclusions,
337-
final NodeGrantProvider nodeGrantProvider
342+
final EntitledNodePathsProvider entitledNodePathsProvider
338343
) {
339344
super(clusterSeed);
340345
this.autoManageMasterNodes = autoManageMasterNodes;
@@ -343,7 +348,7 @@ public InternalTestCluster(
343348
this.baseDir = baseDir;
344349
this.clusterName = clusterName;
345350
this.autoManageVotingExclusions = autoManageVotingExclusions;
346-
this.nodeGrantProvider = nodeGrantProvider;
351+
this.entitledNodePathsProvider = entitledNodePathsProvider;
347352
if (minNumDataNodes < 0 || maxNumDataNodes < 0) {
348353
throw new IllegalArgumentException("minimum and maximum number of data nodes must be >= 0");
349354
}
@@ -798,7 +803,7 @@ private synchronized NodeAndClient buildNode(int nodeId, Settings settings, bool
798803
plugins,
799804
configPath,
800805
forbidPrivateIndexSettings,
801-
nodeGrantProvider.create(settings, configPath)
806+
entitledNodePathsProvider.addEntitledNodePaths(settings, configPath)
802807
);
803808
node.injector().getInstance(TransportService.class).addLifecycleListener(new LifecycleListener() {
804809
@Override
@@ -1074,7 +1079,12 @@ private void recreateNode(final Settings newSettings, final Runnable onTransport
10741079
.put(NodeEnvironment.NODE_ID_SEED_SETTING.getKey(), newIdSeed)
10751080
.build();
10761081
Collection<Class<? extends Plugin>> plugins = node.getClasspathPlugins();
1077-
node = new MockNode(finalSettings, plugins, forbidPrivateIndexSettings, nodeGrantProvider.create(finalSettings, null));
1082+
node = new MockNode(
1083+
finalSettings,
1084+
plugins,
1085+
forbidPrivateIndexSettings,
1086+
entitledNodePathsProvider.addEntitledNodePaths(finalSettings, null)
1087+
);
10781088
node.injector().getInstance(TransportService.class).addLifecycleListener(new LifecycleListener() {
10791089
@Override
10801090
public void afterStart() {

test/framework/src/test/java/org/elasticsearch/test/test/InternalTestClusterTests.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void testInitializiationIsConsistent() {
8686
nodePrefix,
8787
Collections.emptyList(),
8888
Function.identity(),
89-
TEST_ENTITLEMENTS::newNodeGrant
89+
TEST_ENTITLEMENTS::addEntitledNodePaths
9090
);
9191
InternalTestCluster cluster1 = new InternalTestCluster(
9292
clusterSeed,
@@ -101,7 +101,7 @@ public void testInitializiationIsConsistent() {
101101
nodePrefix,
102102
Collections.emptyList(),
103103
Function.identity(),
104-
TEST_ENTITLEMENTS::newNodeGrant
104+
TEST_ENTITLEMENTS::addEntitledNodePaths
105105
);
106106
assertClusters(cluster0, cluster1, true);
107107
}
@@ -201,7 +201,7 @@ public Path nodeConfigPath(int nodeOrdinal) {
201201
nodePrefix,
202202
mockPlugins(),
203203
Function.identity(),
204-
TEST_ENTITLEMENTS::newNodeGrant
204+
TEST_ENTITLEMENTS::addEntitledNodePaths
205205
);
206206
cluster0.setBootstrapMasterNodeIndex(bootstrapMasterNodeIndex);
207207

@@ -218,7 +218,7 @@ public Path nodeConfigPath(int nodeOrdinal) {
218218
nodePrefix,
219219
mockPlugins(),
220220
Function.identity(),
221-
TEST_ENTITLEMENTS::newNodeGrant
221+
TEST_ENTITLEMENTS::addEntitledNodePaths
222222
);
223223
cluster1.setBootstrapMasterNodeIndex(bootstrapMasterNodeIndex);
224224

@@ -285,7 +285,7 @@ public Path nodeConfigPath(int nodeOrdinal) {
285285
nodePrefix,
286286
mockPlugins(),
287287
Function.identity(),
288-
TEST_ENTITLEMENTS::newNodeGrant
288+
TEST_ENTITLEMENTS::addEntitledNodePaths
289289
);
290290
try {
291291
cluster.beforeTest(random());
@@ -381,7 +381,7 @@ public Path nodeConfigPath(int nodeOrdinal) {
381381
"",
382382
mockPlugins(),
383383
Function.identity(),
384-
TEST_ENTITLEMENTS::newNodeGrant
384+
TEST_ENTITLEMENTS::addEntitledNodePaths
385385
);
386386
cluster.beforeTest(random());
387387
List<DiscoveryNodeRole> roles = new ArrayList<>();
@@ -474,7 +474,7 @@ public Path nodeConfigPath(int nodeOrdinal) {
474474
nodePrefix,
475475
plugins,
476476
Function.identity(),
477-
TEST_ENTITLEMENTS::newNodeGrant
477+
TEST_ENTITLEMENTS::addEntitledNodePaths
478478
);
479479
try {
480480
cluster.beforeTest(random());

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public final void startClusters() throws Exception {
184184
"leader",
185185
mockPlugins,
186186
Function.identity(),
187-
TEST_ENTITLEMENTS::newNodeGrant
187+
TEST_ENTITLEMENTS::addEntitledNodePaths
188188
);
189189
leaderCluster.beforeTest(random());
190190
leaderCluster.ensureAtLeastNumDataNodes(numberOfNodesPerCluster());
@@ -207,7 +207,7 @@ public final void startClusters() throws Exception {
207207
"follower",
208208
mockPlugins,
209209
Function.identity(),
210-
TEST_ENTITLEMENTS::newNodeGrant
210+
TEST_ENTITLEMENTS::addEntitledNodePaths
211211
);
212212
clusterGroup = new ClusterGroup(leaderCluster, followerCluster);
213213

0 commit comments

Comments
 (0)