|
@@ -110,11 +110,26 @@ public class EnrichPolicyResolver {
|
|
/**
|
|
/**
|
|
* Resolves a set of enrich policies
|
|
* Resolves a set of enrich policies
|
|
*
|
|
*
|
|
- * @param unresolvedPolicies the unresolved policies
|
|
|
|
|
|
+ * @param enriches the unresolved policies
|
|
* @param executionInfo the execution info
|
|
* @param executionInfo the execution info
|
|
* @param listener notified with the enrich resolution
|
|
* @param listener notified with the enrich resolution
|
|
*/
|
|
*/
|
|
- public void resolvePolicies(
|
|
|
|
|
|
+ public void resolvePolicies(List<Enrich> enriches, EsqlExecutionInfo executionInfo, ActionListener<EnrichResolution> listener) {
|
|
|
|
+ if (enriches.isEmpty()) {
|
|
|
|
+ listener.onResponse(new EnrichResolution());
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ doResolvePolicies(
|
|
|
|
+ new HashSet<>(executionInfo.getClusters().keySet()),
|
|
|
|
+ enriches.stream().map(EnrichPolicyResolver.UnresolvedPolicy::from).toList(),
|
|
|
|
+ executionInfo,
|
|
|
|
+ listener
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected void doResolvePolicies(
|
|
|
|
+ Set<String> remoteClusters,
|
|
Collection<UnresolvedPolicy> unresolvedPolicies,
|
|
Collection<UnresolvedPolicy> unresolvedPolicies,
|
|
EsqlExecutionInfo executionInfo,
|
|
EsqlExecutionInfo executionInfo,
|
|
ActionListener<EnrichResolution> listener
|
|
ActionListener<EnrichResolution> listener
|
|
@@ -124,13 +139,10 @@ public class EnrichPolicyResolver {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- final Set<String> remoteClusters = new HashSet<>(executionInfo.getClusters().keySet());
|
|
|
|
final boolean includeLocal = remoteClusters.isEmpty() || remoteClusters.remove(RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY);
|
|
final boolean includeLocal = remoteClusters.isEmpty() || remoteClusters.remove(RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY);
|
|
lookupPolicies(remoteClusters, includeLocal, unresolvedPolicies, listener.map(lookupResponses -> {
|
|
lookupPolicies(remoteClusters, includeLocal, unresolvedPolicies, listener.map(lookupResponses -> {
|
|
final EnrichResolution enrichResolution = new EnrichResolution();
|
|
final EnrichResolution enrichResolution = new EnrichResolution();
|
|
-
|
|
|
|
- Map<String, LookupResponse> lookupResponsesToProcess = new HashMap<>();
|
|
|
|
-
|
|
|
|
|
|
+ final Map<String, LookupResponse> lookupResponsesToProcess = new HashMap<>();
|
|
for (Map.Entry<String, LookupResponse> entry : lookupResponses.entrySet()) {
|
|
for (Map.Entry<String, LookupResponse> entry : lookupResponses.entrySet()) {
|
|
String clusterAlias = entry.getKey();
|
|
String clusterAlias = entry.getKey();
|
|
if (entry.getValue().connectionError != null) {
|
|
if (entry.getValue().connectionError != null) {
|
|
@@ -424,9 +436,7 @@ public class EnrichPolicyResolver {
|
|
new ChannelActionListener<>(channel),
|
|
new ChannelActionListener<>(channel),
|
|
threadContext
|
|
threadContext
|
|
);
|
|
);
|
|
- try (
|
|
|
|
- RefCountingListener refs = new RefCountingListener(listener.map(unused -> new LookupResponse(resolvedPolices, failures)))
|
|
|
|
- ) {
|
|
|
|
|
|
+ try (var refs = new RefCountingListener(listener.map(unused -> new LookupResponse(resolvedPolices, failures)))) {
|
|
for (String policyName : request.policyNames) {
|
|
for (String policyName : request.policyNames) {
|
|
EnrichPolicy p = availablePolicies.get(policyName);
|
|
EnrichPolicy p = availablePolicies.get(policyName);
|
|
if (p == null) {
|
|
if (p == null) {
|
|
@@ -434,7 +444,7 @@ public class EnrichPolicyResolver {
|
|
}
|
|
}
|
|
try (ThreadContext.StoredContext ignored = threadContext.stashWithOrigin(ClientHelper.ENRICH_ORIGIN)) {
|
|
try (ThreadContext.StoredContext ignored = threadContext.stashWithOrigin(ClientHelper.ENRICH_ORIGIN)) {
|
|
String indexName = EnrichPolicy.getBaseName(policyName);
|
|
String indexName = EnrichPolicy.getBaseName(policyName);
|
|
- indexResolver.resolveAsMergedMapping(indexName, IndexResolver.ALL_FIELDS, null, refs.acquire(indexResult -> {
|
|
|
|
|
|
+ indexResolver.resolveAsMergedMapping(indexName, IndexResolver.ALL_FIELDS, null, false, refs.acquire(indexResult -> {
|
|
if (indexResult.isValid() && indexResult.get().concreteIndices().size() == 1) {
|
|
if (indexResult.isValid() && indexResult.get().concreteIndices().size() == 1) {
|
|
EsIndex esIndex = indexResult.get();
|
|
EsIndex esIndex = indexResult.get();
|
|
var concreteIndices = Map.of(request.clusterAlias, Iterables.get(esIndex.concreteIndices(), 0));
|
|
var concreteIndices = Map.of(request.clusterAlias, Iterables.get(esIndex.concreteIndices(), 0));
|
|
@@ -449,7 +459,7 @@ public class EnrichPolicyResolver {
|
|
} else {
|
|
} else {
|
|
failures.put(policyName, indexResult.toString());
|
|
failures.put(policyName, indexResult.toString());
|
|
}
|
|
}
|
|
- }), false);
|
|
|
|
|
|
+ }));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -457,9 +467,7 @@ public class EnrichPolicyResolver {
|
|
}
|
|
}
|
|
|
|
|
|
protected Map<String, EnrichPolicy> availablePolicies() {
|
|
protected Map<String, EnrichPolicy> availablePolicies() {
|
|
- final EnrichMetadata metadata = projectResolver.getProjectMetadata(clusterService.state())
|
|
|
|
- .custom(EnrichMetadata.TYPE, EnrichMetadata.EMPTY);
|
|
|
|
- return metadata.getPolicies();
|
|
|
|
|
|
+ return projectResolver.getProjectMetadata(clusterService.state()).custom(EnrichMetadata.TYPE, EnrichMetadata.EMPTY).getPolicies();
|
|
}
|
|
}
|
|
|
|
|
|
protected void getRemoteConnection(String cluster, ActionListener<Transport.Connection> listener) {
|
|
protected void getRemoteConnection(String cluster, ActionListener<Transport.Connection> listener) {
|