fix rest tests
This commit is contained in:
parent
0c6d19c40c
commit
ae3eb15caa
|
@ -50,7 +50,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError;
|
|||
*/
|
||||
public class RolloverRequest extends AcknowledgedRequest<RolloverRequest> implements IndicesRequest {
|
||||
|
||||
private String sourceAlias;
|
||||
private String alias;
|
||||
private boolean simulate;
|
||||
private Set<Condition> conditions = new HashSet<>(2);
|
||||
private CreateIndexRequest createIndexRequest = new CreateIndexRequest("_na_");
|
||||
|
@ -77,15 +77,15 @@ public class RolloverRequest extends AcknowledgedRequest<RolloverRequest> implem
|
|||
|
||||
RolloverRequest() {}
|
||||
|
||||
public RolloverRequest(String sourceAlias) {
|
||||
this.sourceAlias = sourceAlias;
|
||||
public RolloverRequest(String alias) {
|
||||
this.alias = alias;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionRequestValidationException validate() {
|
||||
ActionRequestValidationException validationException = createIndexRequest == null ? null : createIndexRequest.validate();
|
||||
if (sourceAlias == null) {
|
||||
validationException = addValidationError("source alias is missing", validationException);
|
||||
if (alias == null) {
|
||||
validationException = addValidationError("index alias is missing", validationException);
|
||||
}
|
||||
if (createIndexRequest == null) {
|
||||
validationException = addValidationError("create index request is missing", validationException);
|
||||
|
@ -96,7 +96,7 @@ public class RolloverRequest extends AcknowledgedRequest<RolloverRequest> implem
|
|||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
super.readFrom(in);
|
||||
sourceAlias = in.readString();
|
||||
alias = in.readString();
|
||||
simulate = in.readBoolean();
|
||||
int size = in.readVInt();
|
||||
for (int i = 0; i < size; i++) {
|
||||
|
@ -109,7 +109,7 @@ public class RolloverRequest extends AcknowledgedRequest<RolloverRequest> implem
|
|||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
super.writeTo(out);
|
||||
out.writeString(sourceAlias);
|
||||
out.writeString(alias);
|
||||
out.writeBoolean(simulate);
|
||||
out.writeVInt(conditions.size());
|
||||
for (Condition condition : conditions) {
|
||||
|
@ -120,7 +120,7 @@ public class RolloverRequest extends AcknowledgedRequest<RolloverRequest> implem
|
|||
|
||||
@Override
|
||||
public String[] indices() {
|
||||
return new String[] {sourceAlias};
|
||||
return new String[] {alias};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -128,8 +128,8 @@ public class RolloverRequest extends AcknowledgedRequest<RolloverRequest> implem
|
|||
return IndicesOptions.strictSingleIndexNoExpandForbidClosed();
|
||||
}
|
||||
|
||||
public void setSourceAlias(String sourceAlias) {
|
||||
this.sourceAlias = sourceAlias;
|
||||
public void setAlias(String alias) {
|
||||
this.alias = alias;
|
||||
}
|
||||
|
||||
public void simulate(boolean simulate) {
|
||||
|
@ -152,8 +152,8 @@ public class RolloverRequest extends AcknowledgedRequest<RolloverRequest> implem
|
|||
return conditions;
|
||||
}
|
||||
|
||||
public String getSourceAlias() {
|
||||
return sourceAlias;
|
||||
public String getAlias() {
|
||||
return alias;
|
||||
}
|
||||
|
||||
public CreateIndexRequest getCreateIndexRequest() {
|
||||
|
|
|
@ -34,8 +34,8 @@ public class RolloverRequestBuilder extends MasterNodeOperationRequestBuilder<Ro
|
|||
super(client, action, new RolloverRequest());
|
||||
}
|
||||
|
||||
public RolloverRequestBuilder setSourceAlias(String sourceAlias) {
|
||||
this.request.setSourceAlias(sourceAlias);
|
||||
public RolloverRequestBuilder setAlias(String sourceAlias) {
|
||||
this.request.setAlias(sourceAlias);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ public class TransportRolloverAction extends TransportMasterNodeAction<RolloverR
|
|||
final ActionListener<RolloverResponse> listener) {
|
||||
final MetaData metaData = state.metaData();
|
||||
validate(metaData, rolloverRequest);
|
||||
final AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(rolloverRequest.getSourceAlias());
|
||||
final AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(rolloverRequest.getAlias());
|
||||
final IndexMetaData indexMetaData = aliasOrIndex.getIndices().get(0);
|
||||
final String sourceIndexName = indexMetaData.getIndex().getName();
|
||||
client.admin().indices().prepareStats(sourceIndexName).clear().setDocs(true).execute(
|
||||
|
@ -173,8 +173,8 @@ public class TransportRolloverAction extends TransportMasterNodeAction<RolloverR
|
|||
.ackTimeout(request.ackTimeout())
|
||||
.masterNodeTimeout(request.masterNodeTimeout());
|
||||
AliasAction[] actions = new AliasAction[2];
|
||||
actions[0] = new AliasAction(AliasAction.Type.ADD, newIndex, request.getSourceAlias());
|
||||
actions[1] = new AliasAction(AliasAction.Type.REMOVE, oldIndex, request.getSourceAlias());
|
||||
actions[0] = new AliasAction(AliasAction.Type.ADD, newIndex, request.getAlias());
|
||||
actions[1] = new AliasAction(AliasAction.Type.REMOVE, oldIndex, request.getAlias());
|
||||
updateRequest.actions(actions);
|
||||
return updateRequest;
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ public class TransportRolloverAction extends TransportMasterNodeAction<RolloverR
|
|||
}
|
||||
|
||||
static void validate(MetaData metaData, RolloverRequest request) {
|
||||
final AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(request.getSourceAlias());
|
||||
final AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(request.getAlias());
|
||||
if (aliasOrIndex == null) {
|
||||
throw new IllegalArgumentException("source alias does not exist");
|
||||
}
|
||||
|
|
|
@ -1709,8 +1709,8 @@ public abstract class AbstractClient extends AbstractComponent implements Client
|
|||
}
|
||||
|
||||
@Override
|
||||
public RolloverRequestBuilder prepareRolloverIndex(String sourceAlias) {
|
||||
return new RolloverRequestBuilder(this, RolloverAction.INSTANCE).setSourceAlias(sourceAlias);
|
||||
public RolloverRequestBuilder prepareRolloverIndex(String alias) {
|
||||
return new RolloverRequestBuilder(this, RolloverAction.INSTANCE).setAlias(alias);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -37,16 +37,14 @@ public class RestRolloverIndexAction extends BaseRestHandler {
|
|||
@Inject
|
||||
public RestRolloverIndexAction(Settings settings, RestController controller, Client client) {
|
||||
super(settings, client);
|
||||
controller.registerHandler(RestRequest.Method.POST, "/{alias}/_rollover", this);
|
||||
controller.registerHandler(RestRequest.Method.GET, "/{alias}/_rollover", this);
|
||||
controller.registerHandler(RestRequest.Method.POST, "/{index}/_rollover", this);
|
||||
controller.registerHandler(RestRequest.Method.GET, "/{index}/_rollover", this);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
if (request.param("alias") == null) {
|
||||
throw new IllegalArgumentException("no alias");
|
||||
}
|
||||
RolloverRequest rolloverIndexRequest = new RolloverRequest(request.param("alias"));
|
||||
RolloverRequest rolloverIndexRequest = new RolloverRequest(request.param("index"));
|
||||
if (request.hasContent()) {
|
||||
rolloverIndexRequest.source(request.content());
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"indices.rollover": {
|
||||
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-rollover-index.html",
|
||||
"methods": ["PUT", "POST"],
|
||||
"methods": ["POST"],
|
||||
"url": {
|
||||
"path": "/{alias}/_rollover",
|
||||
"paths": ["/{alias}/_rollover"],
|
||||
"path": "/{index}/_rollover",
|
||||
"paths": ["/{index}/_rollover"],
|
||||
"parts": {
|
||||
"alias": {
|
||||
"index": {
|
||||
"type" : "string",
|
||||
"required" : true,
|
||||
"description" : "The name of the alias to rollover"
|
||||
|
|
|
@ -3,10 +3,8 @@
|
|||
# create index with alias
|
||||
- do:
|
||||
indices.create:
|
||||
index: logs
|
||||
index: logs-1
|
||||
body:
|
||||
settings:
|
||||
number_of_replicas: "0"
|
||||
aliases:
|
||||
logs_index: {}
|
||||
logs_search: {}
|
||||
|
@ -14,7 +12,7 @@
|
|||
# index document
|
||||
- do:
|
||||
index:
|
||||
index: logs
|
||||
index: logs-1
|
||||
type: test
|
||||
id: "1"
|
||||
body: { "foo": "hello world" }
|
||||
|
@ -25,7 +23,7 @@
|
|||
type: test
|
||||
id: "1"
|
||||
|
||||
- match: { _index: logs }
|
||||
- match: { _index: logs-1 }
|
||||
- match: { _type: test }
|
||||
- match: { _id: "1" }
|
||||
- match: { _source: { foo: "hello world" } }
|
||||
|
@ -33,37 +31,46 @@
|
|||
# perform alias rollover
|
||||
- do:
|
||||
indices.rollover:
|
||||
alias: "logs_search"
|
||||
index: "logs_search"
|
||||
body:
|
||||
condition.max_docs: 1
|
||||
conditions:
|
||||
max_docs: 1
|
||||
|
||||
- match: { old_index: logs }
|
||||
- match: { new_index: logs-1 }
|
||||
- match: { old_index: logs-1 }
|
||||
- match: { new_index: logs-2 }
|
||||
- match: { rolled_over: true }
|
||||
- match: { rollover_index_created: true }
|
||||
- match: { simulated: false }
|
||||
- match: { conditions: { "[max_docs: 1]": true } }
|
||||
|
||||
# ensure new index is created
|
||||
- do:
|
||||
indices.exists:
|
||||
index: logs-1
|
||||
index: logs-2
|
||||
|
||||
- is_true: ''
|
||||
|
||||
- do:
|
||||
cluster.health:
|
||||
wait_for_status: yellow
|
||||
|
||||
# index into new index
|
||||
- do:
|
||||
index:
|
||||
index: logs-1
|
||||
index: logs-2
|
||||
type: test
|
||||
id: "2"
|
||||
body: { "foo": "hello world" }
|
||||
|
||||
- do:
|
||||
indices.refresh: {}
|
||||
|
||||
# check alias points to the new index
|
||||
- do:
|
||||
get:
|
||||
search:
|
||||
index: logs_search
|
||||
type: test
|
||||
id: "2"
|
||||
|
||||
- match: { _index: logs-1 }
|
||||
- match: { _type: test }
|
||||
- match: { _id: "2" }
|
||||
- match: { _source: { foo: "hello world" } }
|
||||
- match: { hits.total: 1 }
|
||||
- match: { hits.hits.0._index: "logs-2"}
|
||||
|
||||
|
|
Loading…
Reference in New Issue