org.elasticsearch.action.support.replication.ReplicationResponse Java Examples

The following examples show how to use org.elasticsearch.action.support.replication.ReplicationResponse. 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: DeleteBlobResponseTest.java    From crate with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteBlobResponseStreaming() throws Exception {
    DeleteBlobResponse response = new DeleteBlobResponse(true);
    response.setShardInfo(new ReplicationResponse.ShardInfo(10, 10));
    BytesStreamOutput out = new BytesStreamOutput();
    response.writeTo(out);

    DeleteBlobResponse fromStream = new DeleteBlobResponse(out.bytes().streamInput());

    assertThat(fromStream.deleted, is(true));
}
 
Example #2
Source File: EsHighLevelRestTest1.java    From java-study with Apache License 2.0 4 votes vote down vote up
private static void insert() throws IOException {
	String index = "test1";
	String type = "_doc";
	// 唯一编号
	String id = "1";
	IndexRequest request = new IndexRequest(index, type, id);
	/*
	 * 第一种方式,通过jsonString进行创建
	 */
	// json
	String jsonString = "{" + "\"uid\":\"1234\","+ "\"phone\":\"12345678909\","+ "\"msgcode\":\"1\"," + "\"sendtime\":\"2019-03-14 01:57:04\","
			+ "\"message\":\"xuwujing study Elasticsearch\"" + "}";
	request.source(jsonString, XContentType.JSON);

	/*
	 * 第二种方式,通过map创建,,会自动转换成json的数据
	 */
	Map<String, Object> jsonMap = new HashMap<>();
	jsonMap.put("uid", 1234);
	jsonMap.put("phone", 12345678909L);
	jsonMap.put("msgcode", 1);
	jsonMap.put("sendtime", "2019-03-14 01:57:04");
	jsonMap.put("message", "xuwujing study Elasticsearch");
	request.source(jsonMap);

	/*
	 * 第三种方式 : 通过XContentBuilder对象进行创建
	 */

	XContentBuilder builder = XContentFactory.jsonBuilder();
	builder.startObject();
	{
		builder.field("uid", 1234);
		builder.field("phone", 12345678909L);
		builder.field("msgcode", 1);
		builder.timeField("sendtime", "2019-03-14 01:57:04");
		builder.field("message", "xuwujing study Elasticsearch");
	}
	builder.endObject();
	request.source(builder);

	IndexResponse indexResponse = client.index(request, RequestOptions.DEFAULT);

	//如果是200则表示成功,否则就是失败
	if(200 == indexResponse.status().getStatus()){

	}

	// 对响应结果进行处理
	String index1 = indexResponse.getIndex();
	String type1 = indexResponse.getType();
	String id1 = indexResponse.getId();
	long version = indexResponse.getVersion();
	// 如果是新增/修改的话的话
	if (indexResponse.getResult() == DocWriteResponse.Result.CREATED) {

	} else if (indexResponse.getResult() == DocWriteResponse.Result.UPDATED) {

	}
	ReplicationResponse.ShardInfo shardInfo = indexResponse.getShardInfo();
	if (shardInfo.getTotal() != shardInfo.getSuccessful()) {

	}
	if (shardInfo.getFailed() > 0) {
		for (ReplicationResponse.ShardInfo.Failure failure : shardInfo.getFailures()) {
			String reason = failure.reason();
		}
	}
}
 
Example #3
Source File: ElasticSearchServiceMapper.java    From vertx-elasticsearch-service with Apache License 2.0 4 votes vote down vote up
private static Shards mapToShards(ReplicationResponse.ShardInfo shardInfo) {
    return new Shards()
            .setFailed(shardInfo.getFailed())
            .setSuccessful(shardInfo.getSuccessful())
            .setTotal(shardInfo.getTotal());
}
 
Example #4
Source File: GlobalCheckpointSyncAction.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
protected ReplicationResponse read(StreamInput in) throws IOException {
    return new ReplicationResponse(in);
}
 
Example #5
Source File: GlobalCheckpointSyncAction.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
protected PrimaryResult<Request, ReplicationResponse> shardOperationOnPrimary(
        final Request request, final IndexShard indexShard) throws Exception {
    maybeSyncTranslog(indexShard);
    return new PrimaryResult<>(request, new ReplicationResponse());
}
 
Example #6
Source File: PrimaryReplicaSyncer.java    From crate with Apache License 2.0 4 votes vote down vote up
void sync(ResyncReplicationRequest request, Task parentTask, String primaryAllocationId, long primaryTerm,
ActionListener<ReplicationResponse> listener);
 
Example #7
Source File: PrimaryReplicaSyncer.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public void onResponse(ReplicationResponse response) {
    run();
}
 
Example #8
Source File: TransportResyncReplicationAction.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
protected ReplicationResponse read(StreamInput in) throws IOException {
    return new ReplicationResponse(in);
}
 
Example #9
Source File: TransportResyncReplicationAction.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
protected WritePrimaryResult<ResyncReplicationRequest, ReplicationResponse> shardOperationOnPrimary(
    ResyncReplicationRequest request, IndexShard primary) throws Exception {
    final ResyncReplicationRequest replicaRequest = performOnPrimary(request, primary);
    return new WritePrimaryResult<>(replicaRequest, new ReplicationResponse(), null, null, primary);
}
 
Example #10
Source File: TransportResyncReplicationAction.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public void sync(ResyncReplicationRequest request, Task parentTask, String primaryAllocationId, long primaryTerm,
                 ActionListener<ReplicationResponse> listener) {
    // skip reroute phase
    transportService.sendChildRequest(
        clusterService.localNode(),
        transportPrimaryAction,
        new ConcreteShardRequest<>(request, primaryAllocationId, primaryTerm),
        parentTask,
        transportOptions,
        new TransportResponseHandler<ReplicationResponse>() {

            @Override
            public ReplicationResponse read(StreamInput in) throws IOException {
                return TransportResyncReplicationAction.this.read(in);
            }

            @Override
            public String executor() {
                return ThreadPool.Names.SAME;
            }

            @Override
            public void handleResponse(ReplicationResponse response) {
                final ReplicationResponse.ShardInfo.Failure[] failures = response.getShardInfo().getFailures();
                // noinspection ForLoopReplaceableByForEach
                for (int i = 0; i < failures.length; i++) {
                    final ReplicationResponse.ShardInfo.Failure f = failures[i];
                    logger.info(
                            new ParameterizedMessage(
                                    "{} primary-replica resync to replica on node [{}] failed", f.fullShardId(), f.nodeId()),
                            f.getCause());
                }
                listener.onResponse(response);
            }

            @Override
            public void handleException(TransportException exp) {
                listener.onFailure(exp);
            }
        });
}
 
Example #11
Source File: TransportFlushAction.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
protected ReplicationResponse newShardResponse() {
    return new ReplicationResponse();
}
 
Example #12
Source File: TransportShardFlushAction.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
protected ReplicationResponse read(StreamInput in) throws IOException {
    return new ReplicationResponse(in);
}
 
Example #13
Source File: TransportShardFlushAction.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
protected PrimaryResult shardOperationOnPrimary(ShardFlushRequest shardRequest, IndexShard primary) {
    primary.flush(shardRequest.getRequest());
    logger.trace("{} flush request executed on primary", primary.shardId());
    return new PrimaryResult<>(shardRequest, new ReplicationResponse());
}
 
Example #14
Source File: TransportShardRefreshAction.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
protected ReplicationResponse read(StreamInput in) throws IOException {
    return new ReplicationResponse(in);
}
 
Example #15
Source File: TransportShardRefreshAction.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
protected PrimaryResult shardOperationOnPrimary(BasicReplicationRequest shardRequest, IndexShard primary) {
    primary.refresh("api");
    logger.trace("{} refresh request executed on primary", primary.shardId());
    return new PrimaryResult<>(shardRequest, new ReplicationResponse());
}
 
Example #16
Source File: TransportRefreshAction.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
protected ReplicationResponse newShardResponse() {
    return new ReplicationResponse();
}