|
@@ -32,6 +32,7 @@ import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusRe
|
|
|
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
|
|
import org.elasticsearch.action.index.IndexRequestBuilder;
|
|
|
import org.elasticsearch.action.support.ActiveShardCount;
|
|
|
+import org.elasticsearch.client.AdminClient;
|
|
|
import org.elasticsearch.client.Client;
|
|
|
import org.elasticsearch.client.node.NodeClient;
|
|
|
import org.elasticsearch.cluster.ClusterState;
|
|
@@ -41,6 +42,7 @@ import org.elasticsearch.cluster.RestoreInProgress;
|
|
|
import org.elasticsearch.cluster.SnapshotDeletionsInProgress;
|
|
|
import org.elasticsearch.cluster.SnapshotsInProgress;
|
|
|
import org.elasticsearch.cluster.health.ClusterHealthStatus;
|
|
|
+import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
|
|
import org.elasticsearch.cluster.metadata.MetaData;
|
|
|
import org.elasticsearch.cluster.metadata.MetaDataIndexStateService;
|
|
|
import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider;
|
|
@@ -49,6 +51,7 @@ import org.elasticsearch.common.CheckedFunction;
|
|
|
import org.elasticsearch.common.Nullable;
|
|
|
import org.elasticsearch.common.ParseField;
|
|
|
import org.elasticsearch.common.Priority;
|
|
|
+import org.elasticsearch.common.Strings;
|
|
|
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
import org.elasticsearch.common.io.stream.Writeable;
|
|
@@ -56,6 +59,7 @@ import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.common.settings.SettingsFilter;
|
|
|
import org.elasticsearch.common.unit.ByteSizeUnit;
|
|
|
import org.elasticsearch.common.unit.TimeValue;
|
|
|
+import org.elasticsearch.common.util.set.Sets;
|
|
|
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
|
|
import org.elasticsearch.common.xcontent.XContentParser;
|
|
|
import org.elasticsearch.discovery.zen.ElectMasterService;
|
|
@@ -68,6 +72,7 @@ import org.elasticsearch.rest.AbstractRestChannel;
|
|
|
import org.elasticsearch.rest.RestController;
|
|
|
import org.elasticsearch.rest.RestRequest;
|
|
|
import org.elasticsearch.rest.RestResponse;
|
|
|
+import org.elasticsearch.rest.RestStatus;
|
|
|
import org.elasticsearch.rest.action.admin.cluster.RestClusterStateAction;
|
|
|
import org.elasticsearch.rest.action.admin.cluster.RestGetRepositoriesAction;
|
|
|
import org.elasticsearch.snapshots.mockstore.MockRepository;
|
|
@@ -96,6 +101,7 @@ import static org.hamcrest.Matchers.containsString;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
import static org.hamcrest.Matchers.greaterThan;
|
|
|
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
|
|
+import static org.hamcrest.Matchers.hasSize;
|
|
|
import static org.hamcrest.Matchers.lessThan;
|
|
|
import static org.hamcrest.Matchers.not;
|
|
|
import static org.hamcrest.Matchers.notNullValue;
|
|
@@ -981,6 +987,38 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest
|
|
|
ensureYellow();
|
|
|
}
|
|
|
|
|
|
+ public void testSnapshotWithDateMath() {
|
|
|
+ final String repo = "repo";
|
|
|
+ final AdminClient admin = client().admin();
|
|
|
+
|
|
|
+ final IndexNameExpressionResolver nameExpressionResolver = new IndexNameExpressionResolver(Settings.EMPTY);
|
|
|
+ final String snapshotName = "<snapshot-{now/d}>";
|
|
|
+
|
|
|
+ logger.info("--> creating repository");
|
|
|
+ assertAcked(admin.cluster().preparePutRepository(repo).setType("fs")
|
|
|
+ .setSettings(Settings.builder().put("location", randomRepoPath())
|
|
|
+ .put("compress", randomBoolean())));
|
|
|
+
|
|
|
+ final String expression1 = nameExpressionResolver.resolveDateMathExpression(snapshotName);
|
|
|
+ logger.info("--> creating date math snapshot");
|
|
|
+ CreateSnapshotResponse snapshotResponse =
|
|
|
+ admin.cluster().prepareCreateSnapshot(repo, snapshotName)
|
|
|
+ .setIncludeGlobalState(true)
|
|
|
+ .setWaitForCompletion(true)
|
|
|
+ .get();
|
|
|
+ assertThat(snapshotResponse.status(), equalTo(RestStatus.OK));
|
|
|
+ // snapshot could be taken before or after a day rollover
|
|
|
+ final String expression2 = nameExpressionResolver.resolveDateMathExpression(snapshotName);
|
|
|
+
|
|
|
+ SnapshotsStatusResponse response = admin.cluster().prepareSnapshotStatus(repo)
|
|
|
+ .setSnapshots(Sets.newHashSet(expression1, expression2).toArray(Strings.EMPTY_ARRAY))
|
|
|
+ .setIgnoreUnavailable(true)
|
|
|
+ .get();
|
|
|
+ List<SnapshotStatus> snapshots = response.getSnapshots();
|
|
|
+ assertThat(snapshots, hasSize(1));
|
|
|
+ assertThat(snapshots.get(0).getState().completed(), equalTo(true));
|
|
|
+ }
|
|
|
+
|
|
|
public static class SnapshottableMetadata extends TestCustomMetaData {
|
|
|
public static final String TYPE = "test_snapshottable";
|
|
|
|