Skip to content

Commit 53b09ab

Browse files
authored
Enable spotless for enrich gradle project. (#48908)
The enrich project doesn't have much history as all the other gradle projects, so it makes sense to enable spotless for this gradle project first. Other changes: * Increased `alignment_for_selector_in_method_invocation` setting from 48 to 80. * Restructured some xcontent mapping code to be more readable with new code style.
1 parent 7053aec commit 53b09ab

File tree

47 files changed

+1922
-1198
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1922
-1198
lines changed

.eclipseformat.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@
205205
<setting id="org.eclipse.jdt.core.formatter.alignment_for_resources_in_try" value="48"/>
206206
<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>
207207
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause" value="separate_lines_if_wrapped"/>
208-
<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="48"/>
208+
<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="80"/>
209209
<setting id="org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column" value="false"/>
210210
<setting id="org.eclipse.jdt.core.formatter.keep_code_block_on_one_line" value="one_line_if_empty"/>
211211
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/>

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ subprojects {
106106
// is greater than the number of unformatted projects, this can be
107107
// switched to an exclude list, and eventualy removed completely.
108108
def projectPathsToFormat = [
109-
// ':build-tools'
109+
':x-pack:plugin:enrich'
110110
]
111111

112112
if (projectPathsToFormat.contains(project.path)) {

x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/AbstractEnrichProcessor.java

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,31 @@ public abstract class AbstractEnrichProcessor extends AbstractProcessor {
3535
protected final String matchField;
3636
protected final int maxMatches;
3737

38-
protected AbstractEnrichProcessor(String tag, Client client, String policyName, String field, String targetField,
39-
boolean ignoreMissing, boolean overrideEnabled, String matchField, int maxMatches) {
38+
protected AbstractEnrichProcessor(
39+
String tag,
40+
Client client,
41+
String policyName,
42+
String field,
43+
String targetField,
44+
boolean ignoreMissing,
45+
boolean overrideEnabled,
46+
String matchField,
47+
int maxMatches
48+
) {
4049
this(tag, createSearchRunner(client), policyName, field, targetField, ignoreMissing, overrideEnabled, matchField, maxMatches);
4150
}
4251

43-
protected AbstractEnrichProcessor(String tag,
44-
BiConsumer<SearchRequest, BiConsumer<SearchResponse, Exception>> searchRunner,
45-
String policyName, String field, String targetField, boolean ignoreMissing, boolean overrideEnabled,
46-
String matchField, int maxMatches) {
52+
protected AbstractEnrichProcessor(
53+
String tag,
54+
BiConsumer<SearchRequest, BiConsumer<SearchResponse, Exception>> searchRunner,
55+
String policyName,
56+
String field,
57+
String targetField,
58+
boolean ignoreMissing,
59+
boolean overrideEnabled,
60+
String matchField,
61+
int maxMatches
62+
) {
4763
super(tag);
4864
this.policyName = policyName;
4965
this.searchRunner = searchRunner;
@@ -155,13 +171,11 @@ int getMaxMatches() {
155171

156172
private static BiConsumer<SearchRequest, BiConsumer<SearchResponse, Exception>> createSearchRunner(Client client) {
157173
return (req, handler) -> {
158-
client.execute(EnrichCoordinatorProxyAction.INSTANCE, req, ActionListener.wrap(
159-
resp -> {
160-
handler.accept(resp, null);
161-
},
162-
e -> {
163-
handler.accept(null, e);
164-
}));
174+
client.execute(
175+
EnrichCoordinatorProxyAction.INSTANCE,
176+
req,
177+
ActionListener.wrap(resp -> { handler.accept(resp, null); }, e -> { handler.accept(null, e); })
178+
);
165179
};
166180
}
167181
}

x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichMetadata.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
108108

109109
@Override
110110
public boolean equals(Object o) {
111-
if (this == o) return true;
112-
if (o == null || getClass() != o.getClass()) return false;
111+
if (this == o)
112+
return true;
113+
if (o == null || getClass() != o.getClass())
114+
return false;
113115
EnrichMetadata that = (EnrichMetadata) o;
114116
return policies.equals(that.policies);
115117
}

x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPlugin.java

Lines changed: 86 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -66,33 +66,57 @@
6666

6767
public class EnrichPlugin extends Plugin implements ActionPlugin, IngestPlugin {
6868

69-
static final Setting<Integer> ENRICH_FETCH_SIZE_SETTING =
70-
Setting.intSetting("enrich.fetch_size", 10000, 1, 1000000, Setting.Property.NodeScope);
71-
72-
static final Setting<Integer> ENRICH_MAX_CONCURRENT_POLICY_EXECUTIONS =
73-
Setting.intSetting("enrich.max_concurrent_policy_executions", 50, 1, Setting.Property.NodeScope);
74-
75-
static final Setting<TimeValue> ENRICH_CLEANUP_PERIOD =
76-
Setting.timeSetting("enrich.cleanup_period", new TimeValue(15, TimeUnit.MINUTES), Setting.Property.NodeScope);
77-
78-
public static final Setting<Integer> COORDINATOR_PROXY_MAX_CONCURRENT_REQUESTS =
79-
Setting.intSetting("enrich.coordinator_proxy.max_concurrent_requests", 8, 1, 10000, Setting.Property.NodeScope);
80-
81-
public static final Setting<Integer> COORDINATOR_PROXY_MAX_LOOKUPS_PER_REQUEST =
82-
Setting.intSetting("enrich.coordinator_proxy.max_lookups_per_request", 128, 1, 10000, Setting.Property.NodeScope);
83-
84-
static final Setting<Integer> ENRICH_MAX_FORCE_MERGE_ATTEMPTS =
85-
Setting.intSetting("enrich.max_force_merge_attempts", 3, 1, 10, Setting.Property.NodeScope);
69+
static final Setting<Integer> ENRICH_FETCH_SIZE_SETTING = Setting.intSetting(
70+
"enrich.fetch_size",
71+
10000,
72+
1,
73+
1000000,
74+
Setting.Property.NodeScope
75+
);
76+
77+
static final Setting<Integer> ENRICH_MAX_CONCURRENT_POLICY_EXECUTIONS = Setting.intSetting(
78+
"enrich.max_concurrent_policy_executions",
79+
50,
80+
1,
81+
Setting.Property.NodeScope
82+
);
83+
84+
static final Setting<TimeValue> ENRICH_CLEANUP_PERIOD = Setting.timeSetting(
85+
"enrich.cleanup_period",
86+
new TimeValue(15, TimeUnit.MINUTES),
87+
Setting.Property.NodeScope
88+
);
89+
90+
public static final Setting<Integer> COORDINATOR_PROXY_MAX_CONCURRENT_REQUESTS = Setting.intSetting(
91+
"enrich.coordinator_proxy.max_concurrent_requests",
92+
8,
93+
1,
94+
10000,
95+
Setting.Property.NodeScope
96+
);
97+
98+
public static final Setting<Integer> COORDINATOR_PROXY_MAX_LOOKUPS_PER_REQUEST = Setting.intSetting(
99+
"enrich.coordinator_proxy.max_lookups_per_request",
100+
128,
101+
1,
102+
10000,
103+
Setting.Property.NodeScope
104+
);
105+
106+
static final Setting<Integer> ENRICH_MAX_FORCE_MERGE_ATTEMPTS = Setting.intSetting(
107+
"enrich.max_force_merge_attempts",
108+
3,
109+
1,
110+
10,
111+
Setting.Property.NodeScope
112+
);
86113

87114
private static final String QUEUE_CAPACITY_SETTING_NAME = "enrich.coordinator_proxy.queue_capacity";
88-
public static final Setting<Integer> COORDINATOR_PROXY_QUEUE_CAPACITY = new Setting<>(QUEUE_CAPACITY_SETTING_NAME,
89-
settings -> {
90-
int maxConcurrentRequests = COORDINATOR_PROXY_MAX_CONCURRENT_REQUESTS.get(settings);
91-
int maxLookupsPerRequest = COORDINATOR_PROXY_MAX_LOOKUPS_PER_REQUEST.get(settings);
92-
return String.valueOf(maxConcurrentRequests * maxLookupsPerRequest);
93-
},
94-
val -> Setting.parseInt(val, 1, Integer.MAX_VALUE, QUEUE_CAPACITY_SETTING_NAME),
95-
Setting.Property.NodeScope);
115+
public static final Setting<Integer> COORDINATOR_PROXY_QUEUE_CAPACITY = new Setting<>(QUEUE_CAPACITY_SETTING_NAME, settings -> {
116+
int maxConcurrentRequests = COORDINATOR_PROXY_MAX_CONCURRENT_REQUESTS.get(settings);
117+
int maxLookupsPerRequest = COORDINATOR_PROXY_MAX_LOOKUPS_PER_REQUEST.get(settings);
118+
return String.valueOf(maxConcurrentRequests * maxLookupsPerRequest);
119+
}, val -> Setting.parseInt(val, 1, Integer.MAX_VALUE, QUEUE_CAPACITY_SETTING_NAME), Setting.Property.NodeScope);
96120

97121
private final Settings settings;
98122
private final Boolean enabled;
@@ -113,13 +137,13 @@ public Map<String, Processor.Factory> getProcessors(Processor.Parameters paramet
113137
return Map.of(EnrichProcessorFactory.TYPE, factory);
114138
}
115139

116-
protected XPackLicenseState getLicenseState() { return XPackPlugin.getSharedLicenseState(); }
140+
protected XPackLicenseState getLicenseState() {
141+
return XPackPlugin.getSharedLicenseState();
142+
}
117143

118144
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
119145
if (enabled == false) {
120-
return List.of(
121-
new ActionHandler<>(XPackInfoFeatureAction.ENRICH, EnrichInfoTransportAction.class)
122-
);
146+
return List.of(new ActionHandler<>(XPackInfoFeatureAction.ENRICH, EnrichInfoTransportAction.class));
123147
}
124148

125149
return List.of(
@@ -135,10 +159,15 @@ public Map<String, Processor.Factory> getProcessors(Processor.Parameters paramet
135159
);
136160
}
137161

138-
public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings,
139-
IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter,
140-
IndexNameExpressionResolver indexNameExpressionResolver,
141-
Supplier<DiscoveryNodes> nodesInCluster) {
162+
public List<RestHandler> getRestHandlers(
163+
Settings settings,
164+
RestController restController,
165+
ClusterSettings clusterSettings,
166+
IndexScopedSettings indexScopedSettings,
167+
SettingsFilter settingsFilter,
168+
IndexNameExpressionResolver indexNameExpressionResolver,
169+
Supplier<DiscoveryNodes> nodesInCluster
170+
) {
142171
if (enabled == false) {
143172
return List.of();
144173
}
@@ -153,31 +182,42 @@ public List<RestHandler> getRestHandlers(Settings settings, RestController restC
153182
}
154183

155184
@Override
156-
public Collection<Object> createComponents(Client client, ClusterService clusterService, ThreadPool threadPool,
157-
ResourceWatcherService resourceWatcherService, ScriptService scriptService,
158-
NamedXContentRegistry xContentRegistry, Environment environment,
159-
NodeEnvironment nodeEnvironment, NamedWriteableRegistry namedWriteableRegistry) {
185+
public Collection<Object> createComponents(
186+
Client client,
187+
ClusterService clusterService,
188+
ThreadPool threadPool,
189+
ResourceWatcherService resourceWatcherService,
190+
ScriptService scriptService,
191+
NamedXContentRegistry xContentRegistry,
192+
Environment environment,
193+
NodeEnvironment nodeEnvironment,
194+
NamedWriteableRegistry namedWriteableRegistry
195+
) {
160196
if (enabled == false) {
161197
return List.of();
162198
}
163199

164200
EnrichPolicyLocks enrichPolicyLocks = new EnrichPolicyLocks();
165-
EnrichPolicyMaintenanceService enrichPolicyMaintenanceService = new EnrichPolicyMaintenanceService(settings, client,
166-
clusterService, threadPool, enrichPolicyLocks);
167-
enrichPolicyMaintenanceService.initialize();
168-
return List.of(
169-
enrichPolicyLocks,
170-
new EnrichCoordinatorProxyAction.Coordinator(client, settings),
171-
enrichPolicyMaintenanceService
201+
EnrichPolicyMaintenanceService enrichPolicyMaintenanceService = new EnrichPolicyMaintenanceService(
202+
settings,
203+
client,
204+
clusterService,
205+
threadPool,
206+
enrichPolicyLocks
172207
);
208+
enrichPolicyMaintenanceService.initialize();
209+
return List.of(enrichPolicyLocks, new EnrichCoordinatorProxyAction.Coordinator(client, settings), enrichPolicyMaintenanceService);
173210
}
174211

175212
@Override
176213
public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
177214
return List.of(
178215
new NamedWriteableRegistry.Entry(MetaData.Custom.class, EnrichMetadata.TYPE, EnrichMetadata::new),
179-
new NamedWriteableRegistry.Entry(NamedDiff.class, EnrichMetadata.TYPE,
180-
in -> EnrichMetadata.readDiffFrom(MetaData.Custom.class, EnrichMetadata.TYPE, in))
216+
new NamedWriteableRegistry.Entry(
217+
NamedDiff.class,
218+
EnrichMetadata.TYPE,
219+
in -> EnrichMetadata.readDiffFrom(MetaData.Custom.class, EnrichMetadata.TYPE, in)
220+
)
181221
);
182222
}
183223

0 commit comments

Comments
 (0)