add rest statuses but need to discuss if they are the right ones
This commit is contained in:
parent
c4f9a41581
commit
f039c5de7a
|
@ -26,6 +26,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.indices.SyncedFlushService;
|
import org.elasticsearch.indices.SyncedFlushService;
|
||||||
|
import org.elasticsearch.rest.RestStatus;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -37,12 +38,25 @@ public class SealIndicesResponse extends ActionResponse implements ToXContent {
|
||||||
|
|
||||||
final private Set<SyncedFlushService.SyncedFlushResult> results;
|
final private Set<SyncedFlushService.SyncedFlushResult> results;
|
||||||
|
|
||||||
|
private RestStatus restStatus;
|
||||||
|
|
||||||
SealIndicesResponse() {
|
SealIndicesResponse() {
|
||||||
results = new HashSet<>();
|
results = new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
SealIndicesResponse(Set<SyncedFlushService.SyncedFlushResult> results) {
|
SealIndicesResponse(Set<SyncedFlushService.SyncedFlushResult> results) {
|
||||||
this.results = results;
|
this.results = results;
|
||||||
|
if (allShardsFailed()) {
|
||||||
|
restStatus = RestStatus.CONFLICT;
|
||||||
|
} else if (someShardsFailed()) {
|
||||||
|
restStatus = RestStatus.PARTIAL_CONTENT;
|
||||||
|
} else {
|
||||||
|
restStatus = RestStatus.OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public RestStatus status() {
|
||||||
|
return restStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -55,6 +69,7 @@ public class SealIndicesResponse extends ActionResponse implements ToXContent {
|
||||||
syncedFlushResult.readFrom(in);
|
syncedFlushResult.readFrom(in);
|
||||||
results.add(syncedFlushResult);
|
results.add(syncedFlushResult);
|
||||||
}
|
}
|
||||||
|
restStatus = RestStatus.readFrom(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -64,6 +79,7 @@ public class SealIndicesResponse extends ActionResponse implements ToXContent {
|
||||||
for (SyncedFlushService.SyncedFlushResult syncedFlushResult : results) {
|
for (SyncedFlushService.SyncedFlushResult syncedFlushResult : results) {
|
||||||
syncedFlushResult.writeTo(out);
|
syncedFlushResult.writeTo(out);
|
||||||
}
|
}
|
||||||
|
RestStatus.writeTo(out, restStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<SyncedFlushService.SyncedFlushResult> results() {
|
public Set<SyncedFlushService.SyncedFlushResult> results() {
|
||||||
|
@ -120,4 +136,36 @@ public class SealIndicesResponse extends ActionResponse implements ToXContent {
|
||||||
}
|
}
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean allShardsFailed() {
|
||||||
|
for (SyncedFlushService.SyncedFlushResult result : results) {
|
||||||
|
if (result.success()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (result.shardResponses().size() > 0) {
|
||||||
|
for (Map.Entry<ShardRouting, SyncedFlushService.SyncedFlushResponse> shardResponse : result.shardResponses().entrySet()) {
|
||||||
|
if (shardResponse.getValue().success()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean someShardsFailed() {
|
||||||
|
for (SyncedFlushService.SyncedFlushResult result : results) {
|
||||||
|
if (result.success() == false) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (result.shardResponses().size() > 0) {
|
||||||
|
for (Map.Entry<ShardRouting, SyncedFlushService.SyncedFlushResponse> shardResponse : result.shardResponses().entrySet()) {
|
||||||
|
if (shardResponse.getValue().success() == false) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,6 @@ import org.elasticsearch.rest.action.support.RestBuilderListener;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||||
import static org.elasticsearch.rest.RestStatus.OK;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -60,7 +59,7 @@ public class RestSealIndicesAction extends BaseRestHandler {
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
builder = response.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
builder = response.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
return new BytesRestResponse(OK, builder);
|
return new BytesRestResponse(response.status(), builder);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue