Obeys the after parameter on phases excpet the first
This commit is contained in:
parent
3f0cf05dcc
commit
9cba84b6fc
|
@ -90,6 +90,8 @@ public class LifecyclePolicy extends AbstractDiffable<LifecyclePolicy> implement
|
|||
|
||||
public void execute(IndexMetaData idxMeta, InternalClient client) {
|
||||
String currentPhaseName = IndexLifecycle.LIFECYCLE_TIMESERIES_PHASE_SETTING.get(idxMeta.getSettings());
|
||||
boolean currentPhaseActionsComplete = IndexLifecycle.LIFECYCLE_TIMESERIES_ACTION_SETTING.get(idxMeta.getSettings())
|
||||
.equals(Phase.PHASE_COMPLETED);
|
||||
String indexName = idxMeta.getIndex().getName();
|
||||
if (Strings.isNullOrEmpty(currentPhaseName)) {
|
||||
String firstPhaseName = phases.get(0).getName();
|
||||
|
@ -109,6 +111,39 @@ public class LifecyclePolicy extends AbstractDiffable<LifecyclePolicy> implement
|
|||
logger.error("Failed to initialised phase [" + firstPhaseName + "] for index [" + indexName + "]", e);
|
||||
}
|
||||
});
|
||||
} else if (currentPhaseActionsComplete) {
|
||||
int currentPhaseIndex = -1;
|
||||
for (int i = 0; i < phases.size(); i++) {
|
||||
if (phases.get(i).getName().equals(currentPhaseName)) {
|
||||
currentPhaseIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (currentPhaseIndex < phases.size() - 1) {
|
||||
Phase nextPhase = phases.get(currentPhaseIndex + 1);
|
||||
if (nextPhase.canExecute(idxMeta)) {
|
||||
String nextPhaseName = nextPhase.getName();
|
||||
client.admin().indices().prepareUpdateSettings(indexName)
|
||||
.setSettings(Settings.builder()
|
||||
.put(IndexLifecycle.LIFECYCLE_TIMESERIES_PHASE_SETTING.getKey(), nextPhaseName)
|
||||
.put(IndexLifecycle.LIFECYCLE_TIMESERIES_ACTION_SETTING.getKey(), ""))
|
||||
.execute(new ActionListener<UpdateSettingsResponse>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(UpdateSettingsResponse response) {
|
||||
if (response.isAcknowledged() == false) {
|
||||
logger.error(
|
||||
"Successfully initialised phase [" + nextPhaseName + "] for index [" + indexName + "]");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
logger.error("Failed to initialised phase [" + nextPhaseName + "] for index [" + indexName + "]", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Phase currentPhase = phases.stream().filter(phase -> phase.getName().equals(currentPhaseName)).findAny()
|
||||
.orElseThrow(() -> new IllegalStateException("Current phase [" + currentPhaseName + "] not found in lifecycle ["
|
||||
|
|
|
@ -30,7 +30,7 @@ import java.io.IOException;
|
|||
import java.util.List;
|
||||
|
||||
public class Phase implements ToXContentObject, Writeable {
|
||||
private static final String PHASE_COMPLETED = "PHASE COMPLETED";
|
||||
public static final String PHASE_COMPLETED = "ACTIONS COMPLETED";
|
||||
|
||||
private static final Logger logger = ESLoggerFactory.getLogger(Phase.class);
|
||||
|
||||
|
@ -88,30 +88,40 @@ public class Phase implements ToXContentObject, Writeable {
|
|||
return actions;
|
||||
}
|
||||
|
||||
protected boolean canExecute(IndexMetaData idxMeta) {
|
||||
long now = System.currentTimeMillis(); // NOCOMMIT use ES way for
|
||||
// getting current time.
|
||||
long indexCreated = idxMeta.getCreationDate();
|
||||
logger.error("canExecute: now: " + now + ", indexCreated: " + indexCreated + ", (indexCreated + after.millis()): "
|
||||
+ (indexCreated + after.millis()) + ", (indexCreated + after.millis()) >= now: "
|
||||
+ ((indexCreated + after.millis()) >= now));
|
||||
return (indexCreated + after.millis()) <= now;
|
||||
}
|
||||
|
||||
protected void execute(IndexMetaData idxMeta, InternalClient client) {
|
||||
String currentActionName = IndexLifecycle.LIFECYCLE_TIMESERIES_ACTION_SETTING.get(idxMeta.getSettings());
|
||||
String indexName = idxMeta.getIndex().getName();
|
||||
if (Strings.isNullOrEmpty(currentActionName)) {
|
||||
String firstPhaseName;
|
||||
String firstActionName;
|
||||
if (actions.isEmpty()) {
|
||||
firstPhaseName = PHASE_COMPLETED;
|
||||
firstActionName = PHASE_COMPLETED;
|
||||
} else {
|
||||
firstPhaseName = actions.get(0).getWriteableName();
|
||||
firstActionName = actions.get(0).getWriteableName();
|
||||
}
|
||||
client.admin().indices().prepareUpdateSettings(indexName)
|
||||
.setSettings(Settings.builder().put(IndexLifecycle.LIFECYCLE_TIMESERIES_ACTION_SETTING.getKey(), firstPhaseName))
|
||||
.setSettings(Settings.builder().put(IndexLifecycle.LIFECYCLE_TIMESERIES_ACTION_SETTING.getKey(), firstActionName))
|
||||
.execute(new ActionListener<UpdateSettingsResponse>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(UpdateSettingsResponse response) {
|
||||
if (response.isAcknowledged() == false) {
|
||||
logger.info("Successfully initialised phase [" + firstPhaseName + "] for index [" + indexName + "]");
|
||||
logger.error("Successfully initialised action [" + firstActionName + "] for index [" + indexName + "]");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
logger.error("Failed to initialised phase [" + firstPhaseName + "] for index [" + indexName + "]", e);
|
||||
logger.error("Failed to initialised action [" + firstActionName + "] for index [" + indexName + "]", e);
|
||||
}
|
||||
});
|
||||
} else if (currentActionName.equals(PHASE_COMPLETED) == false) {
|
||||
|
|
Loading…
Reference in New Issue