Search in sources :

Example 1 with RCFPollingResponse

use of org.opensearch.ad.transport.RCFPollingResponse in project anomaly-detection by opensearch-project.

the class AnomalyDetectorProfileRunnerTests method setUpClientExecuteRCFPollingAction.

@SuppressWarnings("unchecked")
private void setUpClientExecuteRCFPollingAction(RCFPollingStatus inittedEverResultStatus) {
    doAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        ActionListener<RCFPollingResponse> listener = (ActionListener<RCFPollingResponse>) args[2];
        Exception cause = null;
        String detectorId = "123";
        if (inittedEverResultStatus == RCFPollingStatus.INIT_NOT_EXIT || inittedEverResultStatus == RCFPollingStatus.REMOTE_INIT_NOT_EXIT || inittedEverResultStatus == RCFPollingStatus.INDEX_NOT_FOUND || inittedEverResultStatus == RCFPollingStatus.REMOTE_INDEX_NOT_FOUND) {
            switch(inittedEverResultStatus) {
                case INIT_NOT_EXIT:
                case REMOTE_INIT_NOT_EXIT:
                    cause = new ResourceNotFoundException(detectorId, messaingExceptionError);
                    break;
                case INDEX_NOT_FOUND:
                case REMOTE_INDEX_NOT_FOUND:
                    cause = new IndexNotFoundException(detectorId, CommonName.CHECKPOINT_INDEX_NAME);
                    break;
                default:
                    assertTrue("should not reach here", false);
                    break;
            }
            cause = new AnomalyDetectionException(detectorId, cause);
            if (inittedEverResultStatus == RCFPollingStatus.REMOTE_INIT_NOT_EXIT || inittedEverResultStatus == RCFPollingStatus.REMOTE_INDEX_NOT_FOUND) {
                cause = new RemoteTransportException(RCFPollingAction.NAME, new NotSerializableExceptionWrapper(cause));
            }
            listener.onFailure(cause);
        } else {
            RCFPollingResponse result = null;
            switch(inittedEverResultStatus) {
                case INIT_DONE:
                    result = new RCFPollingResponse(requiredSamples + 1);
                    break;
                case INITTING:
                    result = new RCFPollingResponse(requiredSamples - neededSamples);
                    break;
                case EMPTY:
                    result = new RCFPollingResponse(0);
                    break;
                case EXCEPTION:
                    listener.onFailure(new RuntimeException());
                    break;
                default:
                    assertTrue("should not reach here", false);
                    break;
            }
            listener.onResponse(result);
        }
        return null;
    }).when(client).execute(any(RCFPollingAction.class), any(), any());
}
Also used : AnomalyDetectionException(org.opensearch.ad.common.exception.AnomalyDetectionException) RemoteTransportException(org.opensearch.transport.RemoteTransportException) RCFPollingAction(org.opensearch.ad.transport.RCFPollingAction) ResourceNotFoundException(org.opensearch.ad.common.exception.ResourceNotFoundException) AnomalyDetectionException(org.opensearch.ad.common.exception.AnomalyDetectionException) RemoteTransportException(org.opensearch.transport.RemoteTransportException) FailedNodeException(org.opensearch.action.FailedNodeException) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) IOException(java.io.IOException) RCFPollingResponse(org.opensearch.ad.transport.RCFPollingResponse) ActionListener(org.opensearch.action.ActionListener) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) NotSerializableExceptionWrapper(org.opensearch.common.io.stream.NotSerializableExceptionWrapper) ResourceNotFoundException(org.opensearch.ad.common.exception.ResourceNotFoundException)

Aggregations

IOException (java.io.IOException)1 ActionListener (org.opensearch.action.ActionListener)1 FailedNodeException (org.opensearch.action.FailedNodeException)1 AnomalyDetectionException (org.opensearch.ad.common.exception.AnomalyDetectionException)1 ResourceNotFoundException (org.opensearch.ad.common.exception.ResourceNotFoundException)1 RCFPollingAction (org.opensearch.ad.transport.RCFPollingAction)1 RCFPollingResponse (org.opensearch.ad.transport.RCFPollingResponse)1 NotSerializableExceptionWrapper (org.opensearch.common.io.stream.NotSerializableExceptionWrapper)1 IndexNotFoundException (org.opensearch.index.IndexNotFoundException)1 RemoteTransportException (org.opensearch.transport.RemoteTransportException)1