Java Code Examples for org.elasticsearch.rest.RestStatus#NOT_FOUND

The following examples show how to use org.elasticsearch.rest.RestStatus#NOT_FOUND . 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: ESTemplate.java    From canal-1.1.3 with Apache License 2.0 6 votes vote down vote up
/**
 * 提交批次
 */
public void commit() {
    if (getBulk().numberOfActions() > 0) {
        BulkResponse response = getBulk().execute().actionGet();
        if (response.hasFailures()) {
            for (BulkItemResponse itemResponse : response.getItems()) {
                if (!itemResponse.isFailed()) {
                    continue;
                }

                if (itemResponse.getFailure().getStatus() == RestStatus.NOT_FOUND) {
                    logger.error(itemResponse.getFailureMessage());
                } else {
                    throw new RuntimeException("ES sync commit error" + itemResponse.getFailureMessage());
                }
            }
        }
    }
}
 
Example 2
Source File: TestDeleteElasticsearch5.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteNotFound() throws IOException {
    restStatus = RestStatus.NOT_FOUND;
    deleteResponse = new DeleteResponse(null, TYPE1, documentId, 1, true) {

        @Override
        public RestStatus status() {
            return restStatus;
        }

    };
    runner.enqueue(new byte [] {}, new HashMap<String, String>() {{
        put("documentId", documentId);
    }});
    runner.run(1, true, true);

    runner.assertAllFlowFilesTransferred(DeleteElasticsearch5.REL_NOT_FOUND, 1);
    final MockFlowFile out = runner.getFlowFilesForRelationship(DeleteElasticsearch5.REL_NOT_FOUND).get(0);
    assertNotNull(out);
    assertEquals(DeleteElasticsearch5.UNABLE_TO_DELETE_DOCUMENT_MESSAGE,out.getAttribute(DeleteElasticsearch5.ES_ERROR_MESSAGE));
    out.assertAttributeEquals(DeleteElasticsearch5.ES_REST_STATUS, restStatus.toString());
    out.assertAttributeEquals(DeleteElasticsearch5.ES_FILENAME, documentId);
    out.assertAttributeEquals(DeleteElasticsearch5.ES_INDEX, INDEX1);
    out.assertAttributeEquals(DeleteElasticsearch5.ES_TYPE, TYPE1);
}
 
Example 3
Source File: TestElasticsearch5ExceptionHandler.java    From vertexium with Apache License 2.0 6 votes vote down vote up
@Override
public void handleBulkFailure(
    Graph graph,
    Elasticsearch5SearchIndex elasticsearch5SearchIndex,
    BulkItem<?> bulkItem,
    BulkItemResponse bulkItemResponse,
    AtomicBoolean retry
) {
    numberOfTimesCalled.incrementAndGet();
    LOGGER.warn("bulk failure on item %s: %s", bulkItem, bulkItemResponse == null ? null : bulkItemResponse.getFailure());
    if (bulkItemResponse.getFailure().getStatus() == RestStatus.NOT_FOUND) {
        LoadAndAddDocumentMissingHelper.handleDocumentMissingException(graph, elasticsearch5SearchIndex, bulkItem, authorizations);
    } else {
        retry.set(true);
    }
}
 
Example 4
Source File: ESEtlService.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
private void processFailBulkResponse(BulkResponse bulkResponse) {
    for (BulkItemResponse response : bulkResponse.getItems()) {
        if (!response.isFailed()) {
            continue;
        }

        if (response.getFailure().getStatus() == RestStatus.NOT_FOUND) {
            logger.warn(response.getFailureMessage());
        } else {
            logger.error("全量导入数据有误 {}", response.getFailureMessage());
            throw new RuntimeException("全量数据 etl 异常: " + response.getFailureMessage());
        }
    }
}
 
Example 5
Source File: ESConnection.java    From canal with Apache License 2.0 5 votes vote down vote up
@Override
public void processFailBulkResponse(String errorMsg) {
    for (BulkItemResponse itemResponse : bulkResponse.getItems()) {
        if (!itemResponse.isFailed()) {
            continue;
        }

        if (itemResponse.getFailure().getStatus() == RestStatus.NOT_FOUND) {
            logger.error(itemResponse.getFailureMessage());
        } else {
            throw new RuntimeException(errorMsg + itemResponse.getFailureMessage());
        }
    }
}
 
Example 6
Source File: ESConnection.java    From canal with Apache License 2.0 5 votes vote down vote up
@Override
public void processFailBulkResponse(String errorMsg) {
    for (BulkItemResponse itemResponse : bulkResponse.getItems()) {
        if (!itemResponse.isFailed()) {
            continue;
        }

        if (itemResponse.getFailure().getStatus() == RestStatus.NOT_FOUND) {
            logger.error(itemResponse.getFailureMessage());
        } else {
            throw new RuntimeException(errorMsg + itemResponse.getFailureMessage());
        }
    }
}
 
Example 7
Source File: RepositoryMissingException.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public RestStatus status() {
    return RestStatus.NOT_FOUND;
}
 
Example 8
Source File: IllegalIndexShardStateException.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public RestStatus status() {
    return RestStatus.NOT_FOUND;
}
 
Example 9
Source File: IndexTemplateMissingException.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public RestStatus status() {
    return RestStatus.NOT_FOUND;
}
 
Example 10
Source File: ResourceNotFoundException.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public final RestStatus status() {
    return RestStatus.NOT_FOUND;
}
 
Example 11
Source File: SnapshotMissingException.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public RestStatus status() {
    return RestStatus.NOT_FOUND;
}
 
Example 12
Source File: IllegalIndexShardStateException.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public RestStatus status() {
    return RestStatus.NOT_FOUND;
}
 
Example 13
Source File: DocumentMissingException.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public RestStatus status() {
    return RestStatus.NOT_FOUND;
}
 
Example 14
Source File: SearchContextMissingException.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public RestStatus status() {
    return RestStatus.NOT_FOUND;
}
 
Example 15
Source File: DocumentMissingException.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public RestStatus status() {
    return RestStatus.NOT_FOUND;
}
 
Example 16
Source File: RepositoryMissingException.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public RestStatus status() {
    return RestStatus.NOT_FOUND;
}
 
Example 17
Source File: TypeMissingException.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public RestStatus status() {
    return RestStatus.NOT_FOUND;
}
 
Example 18
Source File: IndexTemplateMissingException.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public RestStatus status() {
    return RestStatus.NOT_FOUND;
}
 
Example 19
Source File: TransportBaseSQLAction.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
/**
 * Create a {@link io.crate.action.sql.SQLActionException} out of a {@link java.lang.Throwable}.
 * If concrete {@link org.elasticsearch.ElasticsearchException} is found, first transform it
 * to a {@link io.crate.exceptions.CrateException}
 */
private SQLActionException buildSQLActionException(Throwable e) {
    logger.error("errors while processing sql", e);
    if (e instanceof SQLActionException) {
        return (SQLActionException) e;
    }
    e = esToCrateException(e);

    int errorCode = 5000;
    RestStatus restStatus = RestStatus.INTERNAL_SERVER_ERROR;
    if (e instanceof CrateException) {
        CrateException crateException = (CrateException) e;
        if (e instanceof ValidationException) {
            errorCode = 4000 + crateException.errorCode();
            restStatus = RestStatus.BAD_REQUEST;
        } else if (e instanceof NoPermissionException) {
            errorCode = 4000 + crateException.errorCode();
            restStatus = RestStatus.UNAUTHORIZED;
            e.setStackTrace(new StackTraceElement[0]);
        } else if (e instanceof ForbiddenException) {
            errorCode = 4030 + crateException.errorCode();
            restStatus = RestStatus.FORBIDDEN;
        } else if (e instanceof ResourceUnknownException) {
            errorCode = 4040 + crateException.errorCode();
            restStatus = RestStatus.NOT_FOUND;
        } else if (e instanceof ConflictException) {
            errorCode = 4090 + crateException.errorCode();
            restStatus = RestStatus.CONFLICT;
        } else if (e instanceof UnhandledServerException) {
            errorCode = 5000 + crateException.errorCode();
        }
    } else if (e instanceof ParsingException) {
        errorCode = 4000;
        restStatus = RestStatus.BAD_REQUEST;
    } else if (e instanceof MapperParsingException) {
        errorCode = 4000;
        restStatus = RestStatus.BAD_REQUEST;
    }

    String message = e.getMessage();
    if (message == null) {
        if (e instanceof CrateException && e.getCause() != null) {
            e = e.getCause();   // use cause because it contains a more meaningful error in most cases
        }
        StackTraceElement[] stackTraceElements = e.getStackTrace();
        if (stackTraceElements.length > 0) {
            message = String.format(Locale.ENGLISH, "%s in %s", e.getClass().getSimpleName(), stackTraceElements[0]);
        } else {
            message = "Error in " + e.getClass().getSimpleName();
        }
    } else {
        message = e.getClass().getSimpleName() + ": " + message;
    }
    return new SQLActionException(message, errorCode, restStatus, e.getStackTrace());
}
 
Example 20
Source File: SnapshotMissingException.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public RestStatus status() {
    return RestStatus.NOT_FOUND;
}