Skip to content

Commit

Permalink
action name changed
Browse files Browse the repository at this point in the history
  • Loading branch information
probakowski committed Jan 8, 2020
1 parent 1033a92 commit 0d7e025
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContentObject;

/**
Expand All @@ -28,7 +29,17 @@ protected Client getClient() {
return client;
}

public abstract void evaluateCondition(IndexMetaData indexMetaData, Listener listener);
public void evaluateCondition(Settings settings, IndexMetaData indexMetaData, Listener listener){
evaluateCondition(indexMetaData, listener);
}

public void evaluateCondition(IndexMetaData indexMetaData, Listener listener){
try {
throw new UnsupportedOperationException();
} catch (UnsupportedOperationException e) {
listener.onFailure(e);
}
}

public interface Listener {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ void performDuringNoSnapshot(IndexMetaData indexMetaData, ClusterState currentCl
}

if (indexMetaData.getState() == IndexMetaData.State.OPEN) {
CloseIndexRequest closeIndexRequest = new CloseIndexRequest(followerIndex);
CloseIndexRequest closeIndexRequest = new CloseIndexRequest(followerIndex)
.masterNodeTimeout(getMasterTimeout(currentClusterState));
getClient().admin().indices().close(closeIndexRequest, ActionListener.wrap(
r -> {
assert r.isAcknowledged() : "close index response is not acknowledged";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public DeleteStep(StepKey key, StepKey nextStepKey, Client client) {
@Override
public void performDuringNoSnapshot(IndexMetaData indexMetaData, ClusterState currentState, Listener listener) {
getClient().admin().indices()
.delete(new DeleteIndexRequest(indexMetaData.getIndex().getName()),
.delete(new DeleteIndexRequest(indexMetaData.getIndex().getName()).masterNodeTimeout(getMasterTimeout(currentState)),
ActionListener.wrap(response -> listener.onResponse(true), listener::onFailure));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public FreezeStep(StepKey key, StepKey nextStepKey, Client client) {
@Override
public void performDuringNoSnapshot(IndexMetaData indexMetaData, ClusterState currentState, Listener listener) {
getClient().admin().indices().execute(FreezeIndexAction.INSTANCE,
new FreezeRequest(indexMetaData.getIndex().getName()),
new FreezeRequest(indexMetaData.getIndex().getName()).masterNodeTimeout(getMasterTimeout(currentState)),
ActionListener.wrap(response -> listener.onResponse(true), listener::onFailure));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ final class OpenFollowerIndexStep extends AsyncActionStep {
public void performAction(IndexMetaData indexMetaData, ClusterState currentClusterState,
ClusterStateObserver observer, Listener listener) {
if (indexMetaData.getState() == IndexMetaData.State.CLOSE) {
OpenIndexRequest request = new OpenIndexRequest(indexMetaData.getIndex().getName());
OpenIndexRequest request = new OpenIndexRequest(indexMetaData.getIndex().getName())
.masterNodeTimeout(getMasterTimeout(currentClusterState));
getClient().admin().indices().open(request, ActionListener.wrap(
r -> {
assert r.isAcknowledged() : "open index response is not acknowledged";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.elasticsearch.cluster.ClusterStateObserver;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.unit.TimeValue;

import java.util.Locale;
import java.util.Objects;
Expand Down Expand Up @@ -64,7 +66,8 @@ public void performAction(IndexMetaData indexMetaData, ClusterState currentClust
}

// Calling rollover with no conditions will always roll over the index
RolloverRequest rolloverRequest = new RolloverRequest(rolloverAlias, null);
RolloverRequest rolloverRequest = new RolloverRequest(rolloverAlias, null)
.masterNodeTimeout(getMasterTimeout(currentClusterState));
getClient().admin().indices().rolloverIndex(rolloverRequest,
ActionListener.wrap(response -> {
assert response.isRolledOver() : "the only way this rollover call should fail is with an exception";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public void performAction(IndexMetaData indexMetaData, ClusterState clusterState
Settings settings = Settings.builder()
.put(IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + "_id", nodeId.get()).build();
UpdateSettingsRequest updateSettingsRequest = new UpdateSettingsRequest(indexMetaData.getIndex().getName())
.masterNodeTimeout(getMasterTimeout(clusterState))
.settings(settings);
getClient().admin().indices().updateSettings(updateSettingsRequest,
ActionListener.wrap(response -> listener.onResponse(true), listener::onFailure));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void performDuringNoSnapshot(IndexMetaData indexMetaData, ClusterState cu
// get target shrink index
String targetIndexName = shrunkIndexPrefix + index;
IndicesAliasesRequest aliasesRequest = new IndicesAliasesRequest()
.masterNodeTimeout(getMasterTimeout(currentState))
.addAliasAction(IndicesAliasesRequest.AliasActions.removeIndex().index(index))
.addAliasAction(IndicesAliasesRequest.AliasActions.add().index(targetIndexName).alias(index));
// copy over other aliases from original index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public void performAction(IndexMetaData indexMetaData, ClusterState currentState
.build();

String shrunkenIndexName = shrunkIndexPrefix + indexMetaData.getIndex().getName();
ResizeRequest resizeRequest = new ResizeRequest(shrunkenIndexName, indexMetaData.getIndex().getName());
ResizeRequest resizeRequest = new ResizeRequest(shrunkenIndexName, indexMetaData.getIndex().getName())
.masterNodeTimeout(getMasterTimeout(currentState));
resizeRequest.getTargetIndexRequest().settings(relevantTargetSettings);

getClient().admin().indices().resizeIndex(resizeRequest, ActionListener.wrap(response -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
*/
package org.elasticsearch.xpack.core.ilm;

import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
Expand All @@ -22,6 +25,11 @@
* Represents one part of the execution of a {@link LifecycleAction}.
*/
public abstract class Step {

private static final String ILM_STEP_MASTER_TIMEOUT = "ilm.step.master.timeout";
protected static final Setting<TimeValue> ILM_STEP_MASTER_TIMEOUT_SETTING = Setting.positiveTimeSetting(ILM_STEP_MASTER_TIMEOUT,
TimeValue.timeValueSeconds(30), Setting.Property.Dynamic, Setting.Property.NodeScope);

private final StepKey key;
private final StepKey nextStepKey;

Expand Down Expand Up @@ -60,14 +68,18 @@ public boolean equals(Object obj) {
}
Step other = (Step) obj;
return Objects.equals(key, other.key) &&
Objects.equals(nextStepKey, other.nextStepKey);
Objects.equals(nextStepKey, other.nextStepKey);
}

@Override
public String toString() {
return key + " => " + nextStepKey;
}

protected TimeValue getMasterTimeout(ClusterState clusterState){
return ILM_STEP_MASTER_TIMEOUT_SETTING.get(clusterState.metaData().settings());
}

public static final class StepKey implements Writeable, ToXContentObject {
private final String phase;
private final String action;
Expand All @@ -78,6 +90,7 @@ public static final class StepKey implements Writeable, ToXContentObject {
public static final ParseField NAME_FIELD = new ParseField("name");
private static final ConstructingObjectParser<StepKey, Void> PARSER =
new ConstructingObjectParser<>("stepkey", a -> new StepKey((String) a[0], (String) a[1], (String) a[2]));

static {
PARSER.declareString(ConstructingObjectParser.constructorArg(), PHASE_FIELD);
PARSER.declareString(ConstructingObjectParser.constructorArg(), ACTION_FIELD);
Expand Down Expand Up @@ -134,8 +147,8 @@ public boolean equals(Object obj) {
}
StepKey other = (StepKey) obj;
return Objects.equals(phase, other.phase) &&
Objects.equals(action, other.action) &&
Objects.equals(name, other.name);
Objects.equals(action, other.action) &&
Objects.equals(name, other.name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public UpdateSettingsStep(StepKey key, StepKey nextStepKey, Client client, Setti

@Override
public void performAction(IndexMetaData indexMetaData, ClusterState currentState, ClusterStateObserver observer, Listener listener) {
UpdateSettingsRequest updateSettingsRequest = new UpdateSettingsRequest(indexMetaData.getIndex().getName()).settings(settings);
UpdateSettingsRequest updateSettingsRequest = new UpdateSettingsRequest(indexMetaData.getIndex().getName())
.masterNodeTimeout(getMasterTimeout(currentState))
.settings(settings);
getClient().admin().indices().updateSettings(updateSettingsRequest,
ActionListener.wrap(response -> listener.onResponse(true), listener::onFailure));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ToXContentObject;
Expand Down Expand Up @@ -48,7 +49,7 @@ public boolean isRetryable() {
}

@Override
public void evaluateCondition(IndexMetaData indexMetaData, Listener listener) {
public void evaluateCondition(Settings settings, IndexMetaData indexMetaData, Listener listener) {
String rolloverAlias = RolloverAction.LIFECYCLE_ROLLOVER_ALIAS_SETTING.get(indexMetaData.getSettings());

if (Strings.isNullOrEmpty(rolloverAlias)) {
Expand Down Expand Up @@ -113,7 +114,8 @@ public void evaluateCondition(IndexMetaData indexMetaData, Listener listener) {
"index [%s] is not the write index for alias [%s]", indexMetaData.getIndex().getName(), rolloverAlias)));
}

RolloverRequest rolloverRequest = new RolloverRequest(rolloverAlias, null);
RolloverRequest rolloverRequest = new RolloverRequest(rolloverAlias, null)
.masterNodeTimeout(ILM_STEP_MASTER_TIMEOUT_SETTING.get(settings));
rolloverRequest.dryRun(true);
if (maxAge != null) {
rolloverRequest.addMaxIndexAgeCondition(maxAge);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
public class WaitForSnapshotAction implements LifecycleAction {

public static final String NAME = "snapshot";
public static final String NAME = "waitforsnapshot";
public static final ParseField POLICY_FIELD = new ParseField("policy");

private static final ConstructingObjectParser<WaitForSnapshotAction, Void> PARSER = new ConstructingObjectParser<>(NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void runPeriodicStep(String policy, IndexMetaData indexMetaData) {
}
} else if (currentStep instanceof AsyncWaitStep) {
logger.debug("[{}] running periodic policy with current-step [{}]", index, currentStep.getKey());
((AsyncWaitStep) currentStep).evaluateCondition(indexMetaData, new AsyncWaitStep.Listener() {
((AsyncWaitStep) currentStep).evaluateCondition(clusterService.getSettings(), indexMetaData, new AsyncWaitStep.Listener() {

@Override
public void onResponse(boolean conditionMet, ToXContentObject stepInfo) {
Expand Down

0 comments on commit 0d7e025

Please sign in to comment.