org.elasticsearch.common.io.stream.NotSerializableExceptionWrapper Java Examples

The following examples show how to use org.elasticsearch.common.io.stream.NotSerializableExceptionWrapper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnomalyResultTransportAction.java    From anomaly-detection with Apache License 2.0 6 votes vote down vote up
/**
 * Elasticsearch restricts the kind of exceptions can be thrown over the wire
 * (See ElasticsearchException.ElasticsearchExceptionHandle). Since we cannot
 * add our own exception like ResourceNotFoundException without modifying
 * Elasticsearch's code, we have to unwrap the remote transport exception and
 * check its root cause message.
 *
 * @param exception exception thrown locally or over the wire
 * @param expected  expected root cause
 * @return whether the exception wraps the expected exception as the cause
 */
private boolean isException(Throwable exception, Class<? extends Exception> expected, String expectedErrorName) {
    if (exception == null) {
        return false;
    }

    if (expected.isAssignableFrom(exception.getClass())) {
        return true;
    }

    // all exception that has not been registered to sent over wire can be wrapped
    // inside NotSerializableExceptionWrapper.
    // see StreamOutput.writeException
    // ElasticsearchException.getExceptionName(exception) returns exception
    // separated by underscore. For example, ResourceNotFoundException is converted
    // to "resource_not_found_exception".
    if (exception instanceof NotSerializableExceptionWrapper && exception.getMessage().trim().startsWith(expectedErrorName)) {
        return true;
    }
    return false;
}
 
Example #2
Source File: AnomalyResultTests.java    From anomaly-detection with Apache License 2.0 5 votes vote down vote up
public void testNormalColdStartRemoteException() {
    noModelExceptionTemplate(
        new NotSerializableExceptionWrapper(new ResourceNotFoundException(adID, "")),
        runner,
        adID,
        AnomalyDetectionException.class,
        AnomalyResultTransportAction.NO_MODEL_ERR_MSG
    );
}
 
Example #3
Source File: AnomalyResultTests.java    From anomaly-detection with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void testInsufficientCapacityExceptionDuringRestoringModel() {

    ModelManager rcfManager = mock(ModelManager.class);
    doThrow(new NotSerializableExceptionWrapper(new LimitExceededException(adID, CommonErrorMessages.MEMORY_LIMIT_EXCEEDED_ERR_MSG)))
        .when(rcfManager)
        .getRcfResult(any(String.class), any(String.class), any(double[].class), any(ActionListener.class));

    // These constructors register handler in transport service
    new RCFResultTransportAction(new ActionFilters(Collections.emptySet()), transportService, rcfManager, adCircuitBreakerService);
    new ThresholdResultTransportAction(new ActionFilters(Collections.emptySet()), transportService, normalModelManager);

    AnomalyResultTransportAction action = new AnomalyResultTransportAction(
        new ActionFilters(Collections.emptySet()),
        transportService,
        settings,
        stateManager,
        runner,
        featureQuery,
        normalModelManager,
        hashRing,
        clusterService,
        indexNameResolver,
        adCircuitBreakerService,
        adStats
    );

    AnomalyResultRequest request = new AnomalyResultRequest(adID, 100, 200);
    PlainActionFuture<AnomalyResultResponse> listener = new PlainActionFuture<>();
    action.doExecute(null, request, listener);

    assertException(listener, LimitExceededException.class);
}
 
Example #4
Source File: SQLActionException.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Nullable
public static SQLActionException fromSerializationWrapper(NotSerializableExceptionWrapper wrapper){
    List<String> errorCodeHeader = wrapper.getHeader(ERROR_CODE_KEY);
    if (errorCodeHeader != null && errorCodeHeader.size() == 1){
        int ec = Integer.parseInt(errorCodeHeader.get(0));

        /**
         * wrapper includes className of original exception which is: "s_q_l_action_exception: "
         * see {@link ElasticsearchException#getExceptionName(Throwable)}
         */
        String message = wrapper.getMessage().substring(24);
        return new SQLActionException(message, ec, wrapper.status(), wrapper.getStackTrace());
    }
    return null;
}
 
Example #5
Source File: Elasticsearch7SearchIndexTest.java    From vertexium with Apache License 2.0 5 votes vote down vote up
@Test
public void testDisallowLeadingWildcardsInQueryString() {
    graph.prepareVertex("v1", VISIBILITY_A).setProperty("prop1", "value1", VISIBILITY_A).save(AUTHORIZATIONS_A);
    graph.flush();

    try {
        graph.query("*alue1", AUTHORIZATIONS_A).search().getTotalHits();
        fail("Wildcard prefix of query string should have caused an exception");
    } catch (Exception e) {
        if (!(getRootCause(e) instanceof NotSerializableExceptionWrapper)) {
            fail("Wildcard prefix of query string should have caused a NotSerializableExceptionWrapper exception");
        }
    }
}
 
Example #6
Source File: Elasticsearch5SearchIndexTest.java    From vertexium with Apache License 2.0 5 votes vote down vote up
@Test
public void testDisallowLeadingWildcardsInQueryString() {
    graph.prepareVertex("v1", VISIBILITY_A).setProperty("prop1", "value1", VISIBILITY_A).save(AUTHORIZATIONS_A);
    graph.flush();

    try {
        graph.query("*alue1", AUTHORIZATIONS_A).limit(0).search().getTotalHits();
        fail("Wildcard prefix of query string should have caused an exception");
    } catch (Exception e) {
        if (!(getRootCause(e) instanceof NotSerializableExceptionWrapper)) {
            fail("Wildcard prefix of query string should have caused a NotSerializableExceptionWrapper exception");
        }
    }
}
 
Example #7
Source File: InsertFromValues.java    From crate with Apache License 2.0 4 votes vote down vote up
private static boolean mixedArgumentTypesFailure(Throwable throwable) {
    return throwable instanceof ClassCastException
           || throwable instanceof NotSerializableExceptionWrapper;
}