mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-09 14:34:43 +00:00
Moves Index-Lifecycle classes over to new module
These changes are necessary following the x-pack split.
This commit is contained in:
parent
3cdf1216cd
commit
a6f6335e86
@ -1,21 +1,32 @@
|
||||
apply plugin: 'elasticsearch.build'
|
||||
|
||||
apply plugin: 'elasticsearch.esplugin'
|
||||
esplugin {
|
||||
name 'x-pack-index-lifecycle'
|
||||
description 'Elasticsearch Expanded Pack Plugin - Index Lifecycle'
|
||||
classname 'org.elasticsearch.xpack.indexlifecycle.IndexLifecycle'
|
||||
hasNativeController false
|
||||
requiresKeystore true
|
||||
extendedPlugins = ['x-pack-core']
|
||||
licenseFile project(':x-pack-elasticsearch').file('LICENSE.txt')
|
||||
noticeFile project(':x-pack-elasticsearch').file('NOTICE.txt')
|
||||
}
|
||||
archivesBaseName = 'x-pack-index-lifecycle'
|
||||
|
||||
// TODO: enable this once we have tests
|
||||
test.enabled=false
|
||||
licenseHeaders.enabled = false
|
||||
|
||||
integTest.enabled = false
|
||||
|
||||
dependencies {
|
||||
provided "org.elasticsearch:elasticsearch:${version}"
|
||||
|
||||
compile "org.elasticsearch.plugin:x-pack-core:${version}"
|
||||
provided "org.elasticsearch.plugin:x-pack-core:${version}"
|
||||
testCompile project(path: ':x-pack-elasticsearch:plugin:core', configuration: 'testArtifacts')
|
||||
}
|
||||
|
||||
dependencyLicenses {
|
||||
ignoreSha 'x-pack-core'
|
||||
}
|
||||
|
||||
parent.bundlePlugin {
|
||||
from jar
|
||||
run {
|
||||
plugin ':x-pack-elasticsearch:plugin:core'
|
||||
}
|
||||
|
@ -11,8 +11,8 @@ import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.license.XPackLicenseState;
|
||||
import org.elasticsearch.xpack.XPackFeatureSet;
|
||||
import org.elasticsearch.xpack.XPackField;
|
||||
import org.elasticsearch.xpack.XPackSettings;
|
||||
import org.elasticsearch.xpack.XpackField;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@ -29,7 +29,7 @@ public class IndexLifecycleFeatureSet implements XPackFeatureSet {
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return XpackField.INDEX_LIFECYCLE;
|
||||
return XPackField.INDEX_LIFECYCLE;
|
||||
}
|
||||
|
||||
@Override
|
@ -5,8 +5,6 @@
|
||||
*/
|
||||
package org.elasticsearch.xpack.indexlifecycle;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.message.FormattedMessage;
|
||||
import org.apache.lucene.util.SetOnce;
|
||||
@ -17,15 +15,13 @@ import org.elasticsearch.cluster.ClusterStateListener;
|
||||
import org.elasticsearch.cluster.ClusterStateUpdateTask;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.logging.ESLoggerFactory;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.xpack.scheduler.SchedulerEngine;
|
||||
import org.elasticsearch.xpack.watcher.trigger.schedule.IntervalSchedule;
|
||||
import org.elasticsearch.xpack.watcher.trigger.schedule.IntervalSchedule.Interval;
|
||||
import org.elasticsearch.xpack.watcher.trigger.schedule.IntervalSchedule.Interval.Unit;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
@ -88,11 +84,11 @@ public class IndexLifecycleService extends AbstractComponent
|
||||
scheduler.set(new SchedulerEngine(clock));
|
||||
scheduler.get().register(this);
|
||||
scheduledJob = new SchedulerEngine.Job(IndexLifecycle.NAME,
|
||||
new IntervalSchedule(new Interval(pollInterval.seconds(), Unit.SECONDS)));
|
||||
new TimeValueSchedule(pollInterval));
|
||||
scheduler.get().add(scheduledJob);
|
||||
} else if (pollIntervalSettingChanged) { // all engines are running, just need to update with latest interval
|
||||
scheduledJob = new SchedulerEngine.Job(IndexLifecycle.NAME,
|
||||
new IntervalSchedule(new Interval(pollInterval.seconds(), Unit.SECONDS)));
|
||||
new TimeValueSchedule(pollInterval));
|
||||
scheduler.get().add(scheduledJob);
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.xpack.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.xpack.scheduler.SchedulerEngine.Schedule;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class TimeValueSchedule implements Schedule {
|
||||
|
||||
private TimeValue interval;
|
||||
|
||||
public TimeValueSchedule(TimeValue interval) {
|
||||
this.interval = interval;
|
||||
}
|
||||
|
||||
public TimeValue getInterval() {
|
||||
return interval;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long nextScheduledTimeAfter(long startTime, long time) {
|
||||
assert time >= startTime;
|
||||
if (startTime == time) {
|
||||
time++;
|
||||
}
|
||||
long delta = time - startTime;
|
||||
return startTime + (delta / interval.millis() + 1) * interval.millis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(interval);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
TimeValueSchedule other = (TimeValueSchedule) obj;
|
||||
return Objects.equals(interval, other.interval);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.action.admin.indices.rollover;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public final class RolloverIndexTestHelper {
|
||||
|
||||
// NORELEASE this isn't nice but it's currently the only way to inspect the
|
||||
// settings in an update settings request. Need to see if we can make the
|
||||
// getter public in ES
|
||||
public static void assertRolloverIndexRequest(RolloverRequest request, String alias, Set<Condition<?>> expectedConditions) {
|
||||
assertNotNull(request);
|
||||
assertEquals(1, request.indices().length);
|
||||
assertEquals(alias, request.indices()[0]);
|
||||
assertEquals(alias, request.getAlias());
|
||||
assertEquals(expectedConditions.size(), request.getConditions().size());
|
||||
Set<Object> expectedConditionValues = expectedConditions.stream().map(condition -> condition.value).collect(Collectors.toSet());
|
||||
Set<Object> actualConditionValues = request.getConditions().stream().map(condition -> condition.value).collect(Collectors.toSet());
|
||||
assertEquals(expectedConditionValues, actualConditionValues);
|
||||
}
|
||||
|
||||
// NORELEASE this isn't nice but it's currently the only way to create an
|
||||
// UpdateSettingsResponse. Need to see if we can make the constructor public
|
||||
// in ES
|
||||
public static RolloverResponse createMockResponse(RolloverRequest request, boolean rolledOver) {
|
||||
return new RolloverResponse(null, null, Collections.emptySet(), request.isDryRun(), rolledOver, true, true);
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.action.admin.indices.settings.put;
|
||||
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public final class UpdateSettingsTestHelper {
|
||||
|
||||
// NORELEASE this isn't nice but it's currently the only way to inspect the
|
||||
// settings in an update settings request. Need to see if we can make the
|
||||
// getter public in ES
|
||||
public static void assertSettingsRequest(UpdateSettingsRequest request, Settings expectedSettings, String... expectedIndices) {
|
||||
assertNotNull(request);
|
||||
assertArrayEquals(expectedIndices, request.indices());
|
||||
assertEquals(expectedSettings, request.settings());
|
||||
}
|
||||
|
||||
// NORELEASE this isn't nice but it's currently the only way to create an
|
||||
// UpdateSettingsResponse. Need to see if we can make the constructor public
|
||||
// in ES
|
||||
public static UpdateSettingsResponse createMockResponse(boolean acknowledged) {
|
||||
return new UpdateSettingsResponse(acknowledged);
|
||||
}
|
||||
}
|
@ -30,7 +30,6 @@ import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.xpack.scheduler.SchedulerEngine;
|
||||
import org.elasticsearch.xpack.watcher.trigger.schedule.IntervalSchedule;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.mockito.Mockito;
|
||||
@ -163,16 +162,14 @@ public class IndexLifecycleServiceTests extends ESTestCase {
|
||||
|
||||
indexLifecycleService.clusterChanged(new ClusterChangedEvent("_source", previousState, previousState));
|
||||
assertThat(indexLifecycleService.getScheduler().jobCount(), equalTo(1));
|
||||
assertThat(((IntervalSchedule)indexLifecycleService.getScheduledJob().getSchedule()).interval(),
|
||||
equalTo(new IntervalSchedule.Interval(3, IntervalSchedule.Interval.Unit.SECONDS)));
|
||||
assertThat(((TimeValueSchedule) indexLifecycleService.getScheduledJob().getSchedule()).getInterval(),
|
||||
equalTo(TimeValue.timeValueSeconds(3)));
|
||||
indexLifecycleService.clusterChanged(event);
|
||||
assertThat(indexLifecycleService.getScheduler().jobCount(), equalTo(1));
|
||||
assertThat(((IntervalSchedule)indexLifecycleService.getScheduledJob().getSchedule()).interval(),
|
||||
equalTo(new IntervalSchedule.Interval(pollInterval.seconds(), IntervalSchedule.Interval.Unit.SECONDS)));
|
||||
assertThat(((TimeValueSchedule) indexLifecycleService.getScheduledJob().getSchedule()).getInterval(), equalTo(pollInterval));
|
||||
indexLifecycleService.clusterChanged(new ClusterChangedEvent("_source", currentState, currentState));
|
||||
assertThat(indexLifecycleService.getScheduler().jobCount(), equalTo(1));
|
||||
assertThat(((IntervalSchedule) indexLifecycleService.getScheduledJob().getSchedule()).interval(),
|
||||
equalTo(new IntervalSchedule.Interval(pollInterval.seconds(), IntervalSchedule.Interval.Unit.SECONDS)));
|
||||
assertThat(((TimeValueSchedule) indexLifecycleService.getScheduledJob().getSchedule()).getInterval(), equalTo(pollInterval));
|
||||
|
||||
verify(clusterService, only()).addListener(any());
|
||||
verify(clusterService, never()).submitStateUpdateTask(anyString(), any(ClusterStateUpdateTask.class));
|
Loading…
x
Reference in New Issue
Block a user