|
32 | 32 | import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
33 | 33 | import org.elasticsearch.action.index.IndexRequestBuilder;
|
34 | 34 | import org.elasticsearch.action.support.ActiveShardCount;
|
| 35 | +import org.elasticsearch.client.AdminClient; |
35 | 36 | import org.elasticsearch.client.Client;
|
36 | 37 | import org.elasticsearch.client.node.NodeClient;
|
37 | 38 | import org.elasticsearch.cluster.ClusterState;
|
|
41 | 42 | import org.elasticsearch.cluster.SnapshotDeletionsInProgress;
|
42 | 43 | import org.elasticsearch.cluster.SnapshotsInProgress;
|
43 | 44 | import org.elasticsearch.cluster.health.ClusterHealthStatus;
|
| 45 | +import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; |
44 | 46 | import org.elasticsearch.cluster.metadata.MetaData;
|
45 | 47 | import org.elasticsearch.cluster.metadata.MetaDataIndexStateService;
|
46 | 48 | import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider;
|
|
49 | 51 | import org.elasticsearch.common.Nullable;
|
50 | 52 | import org.elasticsearch.common.ParseField;
|
51 | 53 | import org.elasticsearch.common.Priority;
|
| 54 | +import org.elasticsearch.common.Strings; |
52 | 55 | import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
53 | 56 | import org.elasticsearch.common.io.stream.StreamInput;
|
54 | 57 | import org.elasticsearch.common.io.stream.Writeable;
|
55 | 58 | import org.elasticsearch.common.settings.Settings;
|
56 | 59 | import org.elasticsearch.common.settings.SettingsFilter;
|
57 | 60 | import org.elasticsearch.common.unit.ByteSizeUnit;
|
58 | 61 | import org.elasticsearch.common.unit.TimeValue;
|
| 62 | +import org.elasticsearch.common.util.set.Sets; |
59 | 63 | import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
60 | 64 | import org.elasticsearch.common.xcontent.XContentParser;
|
61 | 65 | import org.elasticsearch.discovery.zen.ElectMasterService;
|
|
68 | 72 | import org.elasticsearch.rest.RestController;
|
69 | 73 | import org.elasticsearch.rest.RestRequest;
|
70 | 74 | import org.elasticsearch.rest.RestResponse;
|
| 75 | +import org.elasticsearch.rest.RestStatus; |
71 | 76 | import org.elasticsearch.rest.action.admin.cluster.RestClusterStateAction;
|
72 | 77 | import org.elasticsearch.rest.action.admin.cluster.RestGetRepositoriesAction;
|
73 | 78 | import org.elasticsearch.snapshots.mockstore.MockRepository;
|
|
96 | 101 | import static org.hamcrest.Matchers.equalTo;
|
97 | 102 | import static org.hamcrest.Matchers.greaterThan;
|
98 | 103 | import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
| 104 | +import static org.hamcrest.Matchers.hasSize; |
99 | 105 | import static org.hamcrest.Matchers.lessThan;
|
100 | 106 | import static org.hamcrest.Matchers.not;
|
101 | 107 | import static org.hamcrest.Matchers.notNullValue;
|
@@ -981,6 +987,38 @@ public void testRestoreShrinkIndex() throws Exception {
|
981 | 987 | ensureYellow();
|
982 | 988 | }
|
983 | 989 |
|
| 990 | + public void testSnapshotWithDateMath() { |
| 991 | + final String repo = "repo"; |
| 992 | + final AdminClient admin = client().admin(); |
| 993 | + |
| 994 | + final IndexNameExpressionResolver nameExpressionResolver = new IndexNameExpressionResolver(Settings.EMPTY); |
| 995 | + final String snapshotName = "<snapshot-{now/d}>"; |
| 996 | + |
| 997 | + logger.info("--> creating repository"); |
| 998 | + assertAcked(admin.cluster().preparePutRepository(repo).setType("fs") |
| 999 | + .setSettings(Settings.builder().put("location", randomRepoPath()) |
| 1000 | + .put("compress", randomBoolean()))); |
| 1001 | + |
| 1002 | + final String expression1 = nameExpressionResolver.resolveDateMathExpression(snapshotName); |
| 1003 | + logger.info("--> creating date math snapshot"); |
| 1004 | + CreateSnapshotResponse snapshotResponse = |
| 1005 | + admin.cluster().prepareCreateSnapshot(repo, snapshotName) |
| 1006 | + .setIncludeGlobalState(true) |
| 1007 | + .setWaitForCompletion(true) |
| 1008 | + .get(); |
| 1009 | + assertThat(snapshotResponse.status(), equalTo(RestStatus.OK)); |
| 1010 | + // snapshot could be taken before or after a day rollover |
| 1011 | + final String expression2 = nameExpressionResolver.resolveDateMathExpression(snapshotName); |
| 1012 | + |
| 1013 | + SnapshotsStatusResponse response = admin.cluster().prepareSnapshotStatus(repo) |
| 1014 | + .setSnapshots(Sets.newHashSet(expression1, expression2).toArray(Strings.EMPTY_ARRAY)) |
| 1015 | + .setIgnoreUnavailable(true) |
| 1016 | + .get(); |
| 1017 | + List<SnapshotStatus> snapshots = response.getSnapshots(); |
| 1018 | + assertThat(snapshots, hasSize(1)); |
| 1019 | + assertThat(snapshots.get(0).getState().completed(), equalTo(true)); |
| 1020 | + } |
| 1021 | + |
984 | 1022 | public static class SnapshottableMetadata extends TestCustomMetaData {
|
985 | 1023 | public static final String TYPE = "test_snapshottable";
|
986 | 1024 |
|
|
0 commit comments