|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License; |
| 4 | + * you may not use this file except in compliance with the Elastic License. |
| 5 | + */ |
| 6 | +package org.elasticsearch.xpack.slm; |
| 7 | + |
| 8 | +import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryAction; |
| 9 | +import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest; |
| 10 | +import org.elasticsearch.cluster.ClusterState; |
| 11 | +import org.elasticsearch.cluster.service.ClusterService; |
| 12 | +import org.elasticsearch.common.settings.Settings; |
| 13 | +import org.elasticsearch.env.Environment; |
| 14 | +import org.elasticsearch.plugins.Plugin; |
| 15 | +import org.elasticsearch.test.ESSingleNodeTestCase; |
| 16 | +import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin; |
| 17 | +import org.elasticsearch.xpack.core.XPackSettings; |
| 18 | +import org.elasticsearch.xpack.core.ilm.OperationMode; |
| 19 | +import org.elasticsearch.xpack.core.slm.SnapshotLifecycleMetadata; |
| 20 | +import org.elasticsearch.xpack.core.slm.SnapshotLifecyclePolicy; |
| 21 | +import org.elasticsearch.xpack.core.slm.SnapshotRetentionConfiguration; |
| 22 | +import org.elasticsearch.xpack.core.slm.action.PutSnapshotLifecycleAction; |
| 23 | +import org.elasticsearch.xpack.core.slm.action.PutSnapshotLifecycleAction.Request; |
| 24 | +import org.elasticsearch.xpack.ilm.IndexLifecycle; |
| 25 | +import org.junit.BeforeClass; |
| 26 | + |
| 27 | +import java.nio.file.Path; |
| 28 | +import java.util.Arrays; |
| 29 | +import java.util.Collection; |
| 30 | +import java.util.Collections; |
| 31 | +import java.util.concurrent.TimeUnit; |
| 32 | + |
| 33 | +import static org.hamcrest.core.Is.is; |
| 34 | + |
| 35 | +public class SnapshotLifecycleInitialisationTests extends ESSingleNodeTestCase { |
| 36 | + |
| 37 | + private static Path repositoryLocation; |
| 38 | + |
| 39 | + @BeforeClass |
| 40 | + public static void setupRepositoryPath() { |
| 41 | + repositoryLocation = createTempDir(); |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + protected Settings nodeSettings() { |
| 46 | + Settings.Builder settings = Settings.builder().put(super.nodeSettings()); |
| 47 | + settings.put(XPackSettings.INDEX_LIFECYCLE_ENABLED.getKey(), false); |
| 48 | + settings.put(XPackSettings.MACHINE_LEARNING_ENABLED.getKey(), false); |
| 49 | + settings.put(XPackSettings.SECURITY_ENABLED.getKey(), false); |
| 50 | + settings.put(XPackSettings.WATCHER_ENABLED.getKey(), false); |
| 51 | + settings.put(XPackSettings.MONITORING_ENABLED.getKey(), false); |
| 52 | + settings.put(XPackSettings.GRAPH_ENABLED.getKey(), false); |
| 53 | + settings.put(XPackSettings.LOGSTASH_ENABLED.getKey(), false); |
| 54 | + settings.put(Environment.PATH_REPO_SETTING.getKey(), repositoryLocation); |
| 55 | + |
| 56 | + settings.put(XPackSettings.SNAPSHOT_LIFECYCLE_ENABLED.getKey(), true); |
| 57 | + return settings.build(); |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + protected Collection<Class<? extends Plugin>> getPlugins() { |
| 62 | + return Arrays.asList(LocalStateCompositeXPackPlugin.class, IndexLifecycle.class); |
| 63 | + } |
| 64 | + |
| 65 | + public void testSLMIsInRunningModeWhenILMIsDisabled() throws Exception { |
| 66 | + client().execute(PutRepositoryAction.INSTANCE, |
| 67 | + new PutRepositoryRequest().name("repo").type("fs") |
| 68 | + .settings(Settings.builder().put("repositories.fs.location", repositoryLocation).build()) |
| 69 | + ).get(10, TimeUnit.SECONDS); |
| 70 | + |
| 71 | + client().execute(PutSnapshotLifecycleAction.INSTANCE, |
| 72 | + new Request("snapshot-policy", new SnapshotLifecyclePolicy("test-policy", "snap", |
| 73 | + "*/1 * * * * ?", "repo", Collections.emptyMap(), SnapshotRetentionConfiguration.EMPTY)) |
| 74 | + ).get(10, TimeUnit.SECONDS); |
| 75 | + |
| 76 | + ClusterState state = getInstanceFromNode(ClusterService.class).state(); |
| 77 | + SnapshotLifecycleMetadata snapMeta = state.metaData().custom(SnapshotLifecycleMetadata.TYPE); |
| 78 | + assertThat(snapMeta.getOperationMode(), is(OperationMode.RUNNING)); |
| 79 | + } |
| 80 | +} |
0 commit comments