use of org.opensearch.ad.transport.ForwardADTaskRequest in project anomaly-detection by opensearch-project.
the class ADTaskManagerTests method testForwardRequestToLeadNodeWithNotExistingNode.
@SuppressWarnings("unchecked")
public void testForwardRequestToLeadNodeWithNotExistingNode() throws IOException {
ADTask adTask = randomAdTask(ADTaskType.HISTORICAL_HC_ENTITY);
ForwardADTaskRequest forwardADTaskRequest = new ForwardADTaskRequest(adTask, ADTaskAction.APPLY_FOR_TASK_SLOTS);
ActionListener<AnomalyDetectorJobResponse> listener = mock(ActionListener.class);
doAnswer(invocation -> {
Consumer<Optional<DiscoveryNode>> function = invocation.getArgument(1);
function.accept(Optional.empty());
return null;
}).when(hashRing).buildAndGetOwningNodeWithSameLocalAdVersion(any(), any(), any());
adTaskManager.forwardRequestToLeadNode(forwardADTaskRequest, transportService, listener);
verify(listener, times(1)).onFailure(any());
}
use of org.opensearch.ad.transport.ForwardADTaskRequest in project anomaly-detection by opensearch-project.
the class ADTaskManager method forwardADTaskToCoordinatingNode.
/**
* Forward AD task to coordinating node
*
* @param adTask AD task
* @param adTaskAction AD task action
* @param transportService transport service
* @param listener action listener
*/
protected void forwardADTaskToCoordinatingNode(ADTask adTask, ADTaskAction adTaskAction, TransportService transportService, ActionListener<AnomalyDetectorJobResponse> listener) {
logger.debug("Forward AD task to coordinating node, task id: {}, action: {}", adTask.getTaskId(), adTaskAction.name());
transportService.sendRequest(getCoordinatingNode(adTask), ForwardADTaskAction.NAME, new ForwardADTaskRequest(adTask, adTaskAction), transportRequestOptions, new ActionListenerResponseHandler<>(listener, AnomalyDetectorJobResponse::new));
}
use of org.opensearch.ad.transport.ForwardADTaskRequest in project anomaly-detection by opensearch-project.
the class ADTaskManager method forwardApplyForTaskSlotsRequestToLeadNode.
/**
* When AD receives start historical analysis request for a detector, will
* 1. Forward to lead node to check available task slots first.
* 2. If available task slots exit, will forward request to coordinating node
* to gather information like top entities.
* 3. Then coordinating node will choose one data node with least load as work
* node and dispatch historical analysis to it.
*
* @param detector detector
* @param detectionDateRange detection date range
* @param user user
* @param transportService transport service
* @param listener action listener
*/
protected void forwardApplyForTaskSlotsRequestToLeadNode(AnomalyDetector detector, DetectionDateRange detectionDateRange, User user, TransportService transportService, ActionListener<AnomalyDetectorJobResponse> listener) {
ForwardADTaskRequest forwardADTaskRequest = new ForwardADTaskRequest(detector, detectionDateRange, user, ADTaskAction.APPLY_FOR_TASK_SLOTS);
forwardRequestToLeadNode(forwardADTaskRequest, transportService, listener);
}
use of org.opensearch.ad.transport.ForwardADTaskRequest in project anomaly-detection by opensearch-project.
the class ADTaskManager method scaleTaskLaneOnCoordinatingNode.
protected void scaleTaskLaneOnCoordinatingNode(ADTask adTask, int approvedTaskSlot, TransportService transportService, ActionListener<AnomalyDetectorJobResponse> listener) {
DiscoveryNode coordinatingNode = getCoordinatingNode(adTask);
transportService.sendRequest(coordinatingNode, ForwardADTaskAction.NAME, new ForwardADTaskRequest(adTask, approvedTaskSlot, ADTaskAction.SCALE_ENTITY_TASK_SLOTS), transportRequestOptions, new ActionListenerResponseHandler<>(listener, AnomalyDetectorJobResponse::new));
}
use of org.opensearch.ad.transport.ForwardADTaskRequest in project anomaly-detection by opensearch-project.
the class ADTaskManager method forwardDetectRequestToCoordinatingNode.
/**
* We have three types of nodes in AD task process.
*
* 1.Forwarding node which receives external request. The request will \
* be sent to coordinating node first.
* 2.Coordinating node which maintains running historical detector set.\
* We use hash ring to find coordinating node with detector id. \
* Coordinating node will find a worker node with least load and \
* dispatch AD task to that worker node.
* 3.Worker node which will run AD task.
*
* This function is to forward the request to coordinating node.
*
* @param detector anomaly detector
* @param detectionDateRange historical analysis date range
* @param user user
* @param availableTaskSlots available task slots
* @param adTaskAction AD task action
* @param transportService transport service
* @param node ES node
* @param listener action listener
*/
protected void forwardDetectRequestToCoordinatingNode(AnomalyDetector detector, DetectionDateRange detectionDateRange, User user, Integer availableTaskSlots, ADTaskAction adTaskAction, TransportService transportService, DiscoveryNode node, ActionListener<AnomalyDetectorJobResponse> listener) {
Version adVersion = hashRing.getAdVersion(node.getId());
transportService.sendRequest(node, ForwardADTaskAction.NAME, // node, check ADTaskManager#cleanDetectorCache.
new ForwardADTaskRequest(detector, detectionDateRange, user, adTaskAction, availableTaskSlots, adVersion), transportRequestOptions, new ActionListenerResponseHandler<>(listener, AnomalyDetectorJobResponse::new));
}
Aggregations