use of org.elasticsearch.cluster.metadata.AliasAction in project elasticsearch by elastic.
the class TransportIndicesAliasesAction method masterOperation.
@Override
protected void masterOperation(final IndicesAliasesRequest request, final ClusterState state, final ActionListener<IndicesAliasesResponse> listener) {
//Expand the indices names
List<AliasActions> actions = request.aliasActions();
List<AliasAction> finalActions = new ArrayList<>();
// Resolve all the AliasActions into AliasAction instances and gather all the aliases
Set<String> aliases = new HashSet<>();
for (AliasActions action : actions) {
String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, request.indicesOptions(), action.indices());
Collections.addAll(aliases, action.aliases());
for (String index : concreteIndices) {
switch(action.actionType()) {
case ADD:
for (String alias : action.concreteAliases(state.metaData(), index)) {
finalActions.add(new AliasAction.Add(index, alias, action.filter(), action.indexRouting(), action.searchRouting()));
}
break;
case REMOVE:
for (String alias : action.concreteAliases(state.metaData(), index)) {
finalActions.add(new AliasAction.Remove(index, alias));
}
break;
case REMOVE_INDEX:
finalActions.add(new AliasAction.RemoveIndex(index));
break;
default:
throw new IllegalArgumentException("Unsupported action [" + action.actionType() + "]");
}
}
}
if (finalActions.isEmpty() && false == actions.isEmpty()) {
throw new AliasesNotFoundException(aliases.toArray(new String[aliases.size()]));
}
request.aliasActions().clear();
IndicesAliasesClusterStateUpdateRequest updateRequest = new IndicesAliasesClusterStateUpdateRequest(unmodifiableList(finalActions)).ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout());
indexAliasesService.indicesAliases(updateRequest, new ActionListener<ClusterStateUpdateResponse>() {
@Override
public void onResponse(ClusterStateUpdateResponse response) {
listener.onResponse(new IndicesAliasesResponse(response.isAcknowledged()));
}
@Override
public void onFailure(Exception t) {
logger.debug("failed to perform aliases", t);
listener.onFailure(t);
}
});
}
use of org.elasticsearch.cluster.metadata.AliasAction in project elasticsearch by elastic.
the class TransportRolloverAction method prepareRolloverAliasesUpdateRequest.
static IndicesAliasesClusterStateUpdateRequest prepareRolloverAliasesUpdateRequest(String oldIndex, String newIndex, RolloverRequest request) {
List<AliasAction> actions = unmodifiableList(Arrays.asList(new AliasAction.Add(newIndex, request.getAlias(), null, null, null), new AliasAction.Remove(oldIndex, request.getAlias())));
final IndicesAliasesClusterStateUpdateRequest updateRequest = new IndicesAliasesClusterStateUpdateRequest(actions).ackTimeout(request.ackTimeout()).masterNodeTimeout(request.masterNodeTimeout());
return updateRequest;
}
use of org.elasticsearch.cluster.metadata.AliasAction in project elasticsearch by elastic.
the class TransportRolloverActionTests method testCreateUpdateAliasRequest.
public void testCreateUpdateAliasRequest() throws Exception {
String sourceAlias = randomAsciiOfLength(10);
String sourceIndex = randomAsciiOfLength(10);
String targetIndex = randomAsciiOfLength(10);
final RolloverRequest rolloverRequest = new RolloverRequest(sourceAlias, targetIndex);
final IndicesAliasesClusterStateUpdateRequest updateRequest = TransportRolloverAction.prepareRolloverAliasesUpdateRequest(sourceIndex, targetIndex, rolloverRequest);
List<AliasAction> actions = updateRequest.actions();
assertThat(actions, hasSize(2));
boolean foundAdd = false;
boolean foundRemove = false;
for (AliasAction action : actions) {
if (action.getIndex().equals(targetIndex)) {
assertEquals(sourceAlias, ((AliasAction.Add) action).getAlias());
foundAdd = true;
} else if (action.getIndex().equals(sourceIndex)) {
assertEquals(sourceAlias, ((AliasAction.Remove) action).getAlias());
foundRemove = true;
} else {
throw new AssertionError("Unknow index [" + action.getIndex() + "]");
}
}
assertTrue(foundAdd);
assertTrue(foundRemove);
}
Aggregations