Skip to content

Commit 64b7145

Browse files
author
elasticsearchmachine
committed
[CI] Auto commit changes from spotless
1 parent 2ddbdea commit 64b7145

File tree

6 files changed

+65
-39
lines changed

6 files changed

+65
-39
lines changed

modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/ConfigDatabases.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ final class ConfigDatabases implements Closeable {
3939
private final GeoIpCache cache;
4040
private final Path geoipConfigDir;
4141

42-
// private final ConcurrentMap<ProjectId, ConcurrentMap<String, DatabaseReaderLazyLoader>> configDatabasesByProject;
42+
// private final ConcurrentMap<ProjectId, ConcurrentMap<String, DatabaseReaderLazyLoader>> configDatabasesByProject;
4343
private final ConcurrentMap<String, DatabaseReaderLazyLoader> configDatabases;
4444

4545
ConfigDatabases(Environment environment, GeoIpCache cache) {

modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/DatabaseNodeService.java

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,12 @@ public final class DatabaseNodeService implements IpDatabaseProvider {
146146
this.clusterService = clusterService;
147147
}
148148

149-
public void initialize(String nodeId, ResourceWatcherService resourceWatcher, IngestService ingestServiceArg,
150-
ProjectResolver projectResolver) throws IOException {
149+
public void initialize(
150+
String nodeId,
151+
ResourceWatcherService resourceWatcher,
152+
IngestService ingestServiceArg,
153+
ProjectResolver projectResolver
154+
) throws IOException {
151155
configDatabases.initialize(resourceWatcher);
152156
geoipTmpDirectory = geoipTmpBaseDirectory.resolve(nodeId);
153157
// delete all stale files in the geoip tmp directory
@@ -191,7 +195,7 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
191195
}
192196

193197
@Override
194-
public Boolean isValid(ProjectId projectId,String databaseFile) {
198+
public Boolean isValid(ProjectId projectId, String databaseFile) {
195199
ProjectState projectState = clusterService.state().projectState(projectId);
196200
assert projectState != null;
197201

@@ -253,9 +257,11 @@ DatabaseReaderLazyLoader get(ProjectId projectId, String key) {
253257
public void shutdown() throws IOException {
254258
// this is a little 'fun' looking, but it's just adapting IOUtils.close() into something
255259
// that can call a bunch of shutdown methods (rather than close methods)
256-
final var loadersToShutdown = databases.values().stream()
260+
final var loadersToShutdown = databases.values()
261+
.stream()
257262
.flatMap(map -> map.values().stream())
258-
.map(ShutdownCloseable::new).toList();
263+
.map(ShutdownCloseable::new)
264+
.toList();
259265
databases.clear();
260266
IOUtils.close(loadersToShutdown);
261267
}
@@ -285,7 +291,8 @@ void checkDatabases(ClusterState state) {
285291
for (ProjectMetadata projectMetadata : state.getMetadata().projects().values()) {
286292
ProjectId projectId = projectMetadata.id();
287293

288-
PersistentTasksCustomMetadata persistentTasks = state.metadata().getProject(projectId)
294+
PersistentTasksCustomMetadata persistentTasks = state.metadata()
295+
.getProject(projectId)
289296
.custom(PersistentTasksCustomMetadata.TYPE);
290297
if (persistentTasks == null) {
291298
logger.trace("Not checking databases for project [{}] because persistent tasks are null", projectId);
@@ -301,8 +308,11 @@ void checkDatabases(ClusterState state) {
301308
Index databasesIndex = databasesAbstraction.getWriteIndex();
302309
IndexRoutingTable databasesIndexRT = state.routingTable(projectId).index(databasesIndex);
303310
if (databasesIndexRT == null || databasesIndexRT.allPrimaryShardsActive() == false) {
304-
logger.trace("Not checking databases because geoip databases index does not have all active primary shards for" +
305-
" project [{}]", projectId);
311+
logger.trace(
312+
"Not checking databases because geoip databases index does not have all active primary shards for"
313+
+ " project [{}]",
314+
projectId
315+
);
306316
return;
307317
}
308318
}
@@ -312,8 +322,10 @@ void checkDatabases(ClusterState state) {
312322

313323
// process the geoip task state for the (ordinary) geoip downloader
314324
{
315-
GeoIpTaskState taskState = getGeoIpTaskState(projectMetadata, getTaskId(projectId,
316-
projectResolver.supportsMultipleProjects()));
325+
GeoIpTaskState taskState = getGeoIpTaskState(
326+
projectMetadata,
327+
getTaskId(projectId, projectResolver.supportsMultipleProjects())
328+
);
317329
if (taskState == null) {
318330
// Note: an empty state will purge stale entries in databases map
319331
taskState = GeoIpTaskState.EMPTY;
@@ -439,8 +451,11 @@ void retrieveAndUpdateDatabase(ProjectId projectId, String databaseName, GeoIpTa
439451
if (name.startsWith(databaseName)) {
440452
Files.copy(is, databaseTmpFile, StandardCopyOption.REPLACE_EXISTING);
441453
} else {
442-
Files.copy(is, databaseTmpDirectory.resolve(databaseName + "_" + name),
443-
StandardCopyOption.REPLACE_EXISTING);
454+
Files.copy(
455+
is,
456+
databaseTmpDirectory.resolve(databaseName + "_" + name),
457+
StandardCopyOption.REPLACE_EXISTING
458+
);
444459
}
445460
}
446461
}
@@ -466,7 +481,8 @@ void retrieveAndUpdateDatabase(ProjectId projectId, String databaseName, GeoIpTa
466481
ioe.addSuppressed(failure);
467482
logger.error("unable to delete tmp database file after failure", ioe);
468483
}
469-
});
484+
}
485+
);
470486
}
471487

472488
void updateDatabase(ProjectId projectId, String databaseFileName, String recordedMd5, Path file) {
@@ -522,7 +538,7 @@ void removeStaleEntries(ProjectId projectId, Collection<String> staleEntries) {
522538
assert existing != null;
523539
existing.shutdown(true);
524540
} catch (Exception e) {
525-
logger.error(() -> "failed to clean database [" + staleEntry + "] for project [" + projectId + "]" , e);
541+
logger.error(() -> "failed to clean database [" + staleEntry + "] for project [" + projectId + "]", e);
526542
}
527543
}
528544
}
@@ -558,7 +574,7 @@ void retrieveDatabase(
558574
// so it is ok if this happens in a blocking manner on a thread from generic thread pool.
559575
// This makes the code easier to understand and maintain.
560576
// TODO: we should revisit if blocking the generic thread pool for search is still acceptable,
561-
// since in multi-project mode each project will have its own geoip databases index search
577+
// since in multi-project mode each project will have its own geoip databases index search
562578
SearchResponse searchResponse = client.search(searchRequest).actionGet();
563579
try {
564580
SearchHit[] hits = searchResponse.getHits().getHits();

modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpProcessor.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,12 @@ public static final class DatabaseVerifyingSupplier implements CheckedSupplier<I
182182
private final String databaseType;
183183
private final ProjectId projectId;
184184

185-
public DatabaseVerifyingSupplier(IpDatabaseProvider ipDatabaseProvider, String databaseFile, String databaseType,
186-
ProjectId projectId) {
185+
public DatabaseVerifyingSupplier(
186+
IpDatabaseProvider ipDatabaseProvider,
187+
String databaseFile,
188+
String databaseType,
189+
ProjectId projectId
190+
) {
187191
this.ipDatabaseProvider = ipDatabaseProvider;
188192
this.databaseFile = databaseFile;
189193
this.databaseType = databaseType;

modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpTaskState.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import org.elasticsearch.TransportVersion;
1313
import org.elasticsearch.TransportVersions;
14-
import org.elasticsearch.cluster.ClusterState;
1514
import org.elasticsearch.cluster.metadata.ProjectMetadata;
1615
import org.elasticsearch.common.io.stream.StreamInput;
1716
import org.elasticsearch.common.io.stream.StreamOutput;
@@ -253,19 +252,19 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
253252
}
254253
}
255254

256-
// /**
257-
// * Retrieves the geoip downloader's task state from the cluster state. This may return null in some circumstances,
258-
// * for example if the geoip downloader task hasn't been created yet (which it wouldn't be if it's disabled).
259-
// *
260-
// * @param state the cluster state to read the task state from
261-
// * @return the geoip downloader's task state or null if there is not a state to read
262-
// */
263-
// @Nullable
264-
// @Deprecated(forRemoval = true)
265-
// static GeoIpTaskState getGeoIpTaskState(ClusterState state) {
266-
// PersistentTasksCustomMetadata.PersistentTask<?> task = getTaskWithId(state, GeoIpDownloader.GEOIP_DOWNLOADER);
267-
// return (task == null) ? null : (GeoIpTaskState) task.getState();
268-
// }
255+
// /**
256+
// * Retrieves the geoip downloader's task state from the cluster state. This may return null in some circumstances,
257+
// * for example if the geoip downloader task hasn't been created yet (which it wouldn't be if it's disabled).
258+
// *
259+
// * @param state the cluster state to read the task state from
260+
// * @return the geoip downloader's task state or null if there is not a state to read
261+
// */
262+
// @Nullable
263+
// @Deprecated(forRemoval = true)
264+
// static GeoIpTaskState getGeoIpTaskState(ClusterState state) {
265+
// PersistentTasksCustomMetadata.PersistentTask<?> task = getTaskWithId(state, GeoIpDownloader.GEOIP_DOWNLOADER);
266+
// return (task == null) ? null : (GeoIpTaskState) task.getState();
267+
// }
269268

270269
/**
271270
* Retrieves the geoip downloader's task state from the project metadata. This may return null in some circumstances,

modules/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/DatabaseNodeServiceTests.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,12 @@ public void setup() throws IOException {
136136
clusterService = mock(ClusterService.class);
137137
geoIpTmpDir = createTempDir();
138138
databaseNodeService = new DatabaseNodeService(geoIpTmpDir, client, cache, configDatabases, Runnable::run, clusterService);
139-
databaseNodeService.initialize("nodeId", resourceWatcherService, ingestService,
140-
TestProjectResolvers.singleProject(randomProjectIdOrDefault()));
139+
databaseNodeService.initialize(
140+
"nodeId",
141+
resourceWatcherService,
142+
ingestService,
143+
TestProjectResolvers.singleProject(randomProjectIdOrDefault())
144+
);
141145
}
142146

143147
@After
@@ -203,7 +207,6 @@ public void testCheckDatabases_dontCheckDatabaseOnNonIngestNode() throws Excepti
203207
task = new PersistentTask<>(task, new GeoIpTaskState(Map.of("GeoIP2-City.mmdb", new GeoIpTaskState.Metadata(0L, 0, 9, md5, 10))));
204208
PersistentTasksCustomMetadata tasksCustomMetadata = new PersistentTasksCustomMetadata(1L, Map.of(taskId, task));
205209

206-
207210
ClusterState state = ClusterState.builder(createClusterState(projectId, tasksCustomMetadata))
208211
.nodes(
209212
new DiscoveryNodes.Builder().add(
@@ -306,7 +309,7 @@ public void testUpdateDatabase() throws Exception {
306309
List<String> pipelineIds = IntStream.range(0, numPipelinesToBeReloaded).mapToObj(String::valueOf).toList();
307310
when(ingestService.getPipelineWithProcessorType(any(), any(), any())).thenReturn(pipelineIds);
308311

309-
databaseNodeService.updateDatabase(projectId,"_name", "_md5", geoIpTmpDir.resolve("some-file"));
312+
databaseNodeService.updateDatabase(projectId, "_name", "_md5", geoIpTmpDir.resolve("some-file"));
310313

311314
// Updating the first time may trigger a reload.
312315
verify(clusterService, times(1)).addListener(any());

modules/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/GeoIpProcessorFactoryTests.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,12 @@ public void loadDatabaseReaders() throws IOException {
8181
clusterService = mock(ClusterService.class);
8282
when(clusterService.state()).thenReturn(ClusterState.EMPTY_STATE);
8383
databaseNodeService = new DatabaseNodeService(geoipTmpDir, client, cache, configDatabases, Runnable::run, clusterService);
84-
databaseNodeService.initialize("nodeId", mock(ResourceWatcherService.class), mock(IngestService.class),
85-
TestProjectResolvers.singleProject(randomProjectIdOrDefault()));
84+
databaseNodeService.initialize(
85+
"nodeId",
86+
mock(ResourceWatcherService.class),
87+
mock(IngestService.class),
88+
TestProjectResolvers.singleProject(randomProjectIdOrDefault())
89+
);
8690
}
8791

8892
@After
@@ -224,7 +228,7 @@ public void testBuildWithAsnDbAndCityFields() {
224228
public void testBuildNonExistingDbFile() throws Exception {
225229
ProjectId projectId = randomProjectIdOrDefault();
226230
copyDatabase("GeoLite2-City-Test.mmdb", geoipTmpDir.resolve("GeoLite2-City.mmdb"));
227-
databaseNodeService.updateDatabase(projectId,"GeoLite2-City.mmdb", "md5", geoipTmpDir.resolve("GeoLite2-City.mmdb"));
231+
databaseNodeService.updateDatabase(projectId, "GeoLite2-City.mmdb", "md5", geoipTmpDir.resolve("GeoLite2-City.mmdb"));
228232
GeoIpProcessor.Factory factory = new GeoIpProcessor.Factory(GEOIP_TYPE, databaseNodeService);
229233

230234
Map<String, Object> config = new HashMap<>();

0 commit comments

Comments
 (0)