|
13 | 13 | import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse; |
14 | 14 | import org.elasticsearch.cluster.ClusterState; |
15 | 15 | import org.elasticsearch.cluster.health.ClusterHealthStatus; |
16 | | -import org.elasticsearch.cluster.metadata.IndexMetadata; |
17 | 16 | import org.elasticsearch.cluster.metadata.Metadata; |
18 | | -import org.elasticsearch.cluster.metadata.RepositoryMetadata; |
19 | | -import org.elasticsearch.cluster.service.ClusterService; |
20 | 17 | import org.elasticsearch.common.settings.Settings; |
21 | | -import org.elasticsearch.common.util.BigArrays; |
22 | | -import org.elasticsearch.env.Environment; |
23 | | -import org.elasticsearch.indices.recovery.RecoverySettings; |
24 | 18 | import org.elasticsearch.license.DeleteLicenseAction; |
25 | 19 | import org.elasticsearch.license.License; |
26 | 20 | import org.elasticsearch.license.LicensesMetadata; |
|
29 | 23 | import org.elasticsearch.license.PostStartTrialAction; |
30 | 24 | import org.elasticsearch.license.PostStartTrialRequest; |
31 | 25 | import org.elasticsearch.license.PostStartTrialResponse; |
32 | | -import org.elasticsearch.plugins.Plugin; |
33 | | -import org.elasticsearch.plugins.RepositoryPlugin; |
34 | 26 | import org.elasticsearch.protocol.xpack.XPackUsageRequest; |
35 | 27 | import org.elasticsearch.protocol.xpack.license.DeleteLicenseRequest; |
36 | | -import org.elasticsearch.repositories.IndexId; |
37 | | -import org.elasticsearch.repositories.Repository; |
38 | | -import org.elasticsearch.repositories.RepositoryData; |
39 | | -import org.elasticsearch.repositories.fs.FsRepository; |
40 | | -import org.elasticsearch.snapshots.AbstractSnapshotIntegTestCase; |
41 | | -import org.elasticsearch.snapshots.SnapshotId; |
42 | 28 | import org.elasticsearch.snapshots.SnapshotRestoreException; |
43 | | -import org.elasticsearch.snapshots.mockstore.MockRepository; |
44 | | -import org.elasticsearch.test.ESIntegTestCase; |
45 | | -import org.elasticsearch.xcontent.NamedXContentRegistry; |
46 | 29 | import org.elasticsearch.xpack.core.action.XPackUsageFeatureAction; |
47 | 30 | import org.elasticsearch.xpack.core.action.XPackUsageFeatureResponse; |
48 | 31 | import org.elasticsearch.xpack.core.archive.ArchiveFeatureSetUsage; |
49 | | -import org.junit.Before; |
50 | | - |
51 | | -import java.io.IOException; |
52 | | -import java.util.Arrays; |
53 | | -import java.util.Collection; |
54 | | -import java.util.Map; |
55 | 32 |
|
56 | 33 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; |
57 | 34 | import static org.hamcrest.Matchers.containsString; |
58 | 35 | import static org.hamcrest.Matchers.equalTo; |
59 | 36 | import static org.hamcrest.Matchers.instanceOf; |
60 | 37 | import static org.hamcrest.Matchers.oneOf; |
61 | 38 |
|
62 | | -@ESIntegTestCase.ClusterScope(supportsDedicatedMasters = false, numClientNodes = 0, scope = ESIntegTestCase.Scope.TEST) |
63 | | -public class ArchiveLicenseIntegTests extends AbstractSnapshotIntegTestCase { |
64 | | - |
65 | | - @Override |
66 | | - protected Collection<Class<? extends Plugin>> nodePlugins() { |
67 | | - return Arrays.asList(LocalStateOldLuceneVersions.class, TestRepositoryPlugin.class, MockRepository.Plugin.class); |
68 | | - } |
69 | | - |
70 | | - public static class TestRepositoryPlugin extends Plugin implements RepositoryPlugin { |
71 | | - public static final String FAKE_VERSIONS_TYPE = "fakeversionsrepo"; |
72 | | - |
73 | | - @Override |
74 | | - public Map<String, Repository.Factory> getRepositories( |
75 | | - Environment env, |
76 | | - NamedXContentRegistry namedXContentRegistry, |
77 | | - ClusterService clusterService, |
78 | | - BigArrays bigArrays, |
79 | | - RecoverySettings recoverySettings |
80 | | - ) { |
81 | | - return Map.of( |
82 | | - FAKE_VERSIONS_TYPE, |
83 | | - metadata -> new FakeVersionsRepo(metadata, env, namedXContentRegistry, clusterService, bigArrays, recoverySettings) |
84 | | - ); |
85 | | - } |
86 | | - |
87 | | - // fakes an old index version format to activate license checks |
88 | | - private static class FakeVersionsRepo extends FsRepository { |
89 | | - FakeVersionsRepo( |
90 | | - RepositoryMetadata metadata, |
91 | | - Environment env, |
92 | | - NamedXContentRegistry namedXContentRegistry, |
93 | | - ClusterService clusterService, |
94 | | - BigArrays bigArrays, |
95 | | - RecoverySettings recoverySettings |
96 | | - ) { |
97 | | - super(metadata, env, namedXContentRegistry, clusterService, bigArrays, recoverySettings); |
98 | | - } |
99 | | - |
100 | | - @Override |
101 | | - public IndexMetadata getSnapshotIndexMetaData(RepositoryData repositoryData, SnapshotId snapshotId, IndexId index) |
102 | | - throws IOException { |
103 | | - final IndexMetadata original = super.getSnapshotIndexMetaData(repositoryData, snapshotId, index); |
104 | | - return IndexMetadata.builder(original) |
105 | | - .settings( |
106 | | - Settings.builder() |
107 | | - .put(original.getSettings()) |
108 | | - .put( |
109 | | - IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(), |
110 | | - metadata.settings() |
111 | | - .getAsVersion("version", randomBoolean() ? Version.fromString("5.0.0") : Version.fromString("6.0.0")) |
112 | | - ) |
113 | | - ) |
114 | | - .build(); |
115 | | - } |
116 | | - } |
117 | | - } |
118 | | - |
119 | | - private static final String repoName = "test-repo"; |
120 | | - private static final String indexName = "test-index"; |
121 | | - private static final String snapshotName = "test-snapshot"; |
122 | | - |
123 | | - @Before |
124 | | - public void createAndRestoreArchive() throws Exception { |
125 | | - createRepository(repoName, TestRepositoryPlugin.FAKE_VERSIONS_TYPE); |
126 | | - createIndex(indexName); |
127 | | - createFullSnapshot(repoName, snapshotName); |
128 | | - |
129 | | - assertAcked(client().admin().indices().prepareDelete(indexName)); |
130 | | - |
131 | | - PostStartTrialRequest request = new PostStartTrialRequest().setType(License.LicenseType.TRIAL.getTypeName()).acknowledge(true); |
132 | | - client().execute(PostStartTrialAction.INSTANCE, request).get(); |
133 | | - } |
| 39 | +public class ArchiveLicenseIntegTests extends AbstractArchiveTestCase { |
134 | 40 |
|
135 | 41 | public void testFeatureUsage() throws Exception { |
136 | 42 | XPackUsageFeatureResponse usage = client().execute(XPackUsageFeatureAction.ARCHIVE, new XPackUsageRequest()).get(); |
|
0 commit comments