|
@@ -23,6 +23,11 @@ import org.elasticsearch.common.CheckedConsumer;
|
|
|
import org.elasticsearch.common.ValidationException;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
|
|
+import org.elasticsearch.ingest.ConfigurationUtils;
|
|
|
+import org.elasticsearch.ingest.IngestService;
|
|
|
+import org.elasticsearch.ingest.Pipeline;
|
|
|
+import org.elasticsearch.ingest.Processor;
|
|
|
+import org.elasticsearch.ingest.TestProcessor;
|
|
|
import org.elasticsearch.license.License;
|
|
|
import org.elasticsearch.license.RemoteClusterLicenseChecker;
|
|
|
import org.elasticsearch.license.XPackLicenseState;
|
|
@@ -44,7 +49,9 @@ import org.junit.Before;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Collections;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
@@ -56,10 +63,12 @@ import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF
|
|
|
import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_VERSION_CREATED;
|
|
|
import static org.elasticsearch.mock.orig.Mockito.when;
|
|
|
import static org.elasticsearch.xpack.core.common.validation.SourceDestValidator.DESTINATION_IN_SOURCE_VALIDATION;
|
|
|
+import static org.elasticsearch.xpack.core.common.validation.SourceDestValidator.DESTINATION_PIPELINE_MISSING_VALIDATION;
|
|
|
import static org.elasticsearch.xpack.core.common.validation.SourceDestValidator.DESTINATION_SINGLE_INDEX_VALIDATION;
|
|
|
import static org.elasticsearch.xpack.core.common.validation.SourceDestValidator.REMOTE_SOURCE_VALIDATION;
|
|
|
import static org.elasticsearch.xpack.core.common.validation.SourceDestValidator.SOURCE_MISSING_VALIDATION;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
+import static org.mockito.Mockito.mock;
|
|
|
import static org.mockito.Mockito.spy;
|
|
|
|
|
|
public class SourceDestValidatorTests extends ESTestCase {
|
|
@@ -79,6 +88,7 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
SOURCE_MISSING_VALIDATION,
|
|
|
DESTINATION_IN_SOURCE_VALIDATION,
|
|
|
DESTINATION_SINGLE_INDEX_VALIDATION,
|
|
|
+ DESTINATION_PIPELINE_MISSING_VALIDATION,
|
|
|
REMOTE_SOURCE_VALIDATION
|
|
|
);
|
|
|
|
|
@@ -91,10 +101,13 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
private final ThreadPool threadPool = new TestThreadPool(getClass().getName());
|
|
|
private final TransportService transportService = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, threadPool);
|
|
|
private final RemoteClusterService remoteClusterService = transportService.getRemoteClusterService();
|
|
|
+ private final IngestService ingestService = mock(IngestService.class);
|
|
|
+
|
|
|
private final SourceDestValidator simpleNonRemoteValidator = new SourceDestValidator(
|
|
|
new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)),
|
|
|
remoteClusterService,
|
|
|
null,
|
|
|
+ ingestService,
|
|
|
"node_id",
|
|
|
"license"
|
|
|
);
|
|
@@ -205,6 +218,7 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
CLUSTER_STATE,
|
|
|
new String[] { SOURCE_1 },
|
|
|
"dest",
|
|
|
+ null,
|
|
|
TEST_VALIDATIONS,
|
|
|
listener
|
|
|
),
|
|
@@ -219,6 +233,7 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
CLUSTER_STATE,
|
|
|
new String[] {},
|
|
|
"dest",
|
|
|
+ null,
|
|
|
TEST_VALIDATIONS,
|
|
|
listener
|
|
|
),
|
|
@@ -236,6 +251,7 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
CLUSTER_STATE,
|
|
|
new String[] { "missing" },
|
|
|
"dest",
|
|
|
+ null,
|
|
|
TEST_VALIDATIONS,
|
|
|
listener
|
|
|
),
|
|
@@ -251,6 +267,7 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
CLUSTER_STATE,
|
|
|
new String[] { "missing" },
|
|
|
"dest",
|
|
|
+ null,
|
|
|
Collections.emptyList(),
|
|
|
listener
|
|
|
),
|
|
@@ -265,6 +282,7 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
CLUSTER_STATE,
|
|
|
new String[] { SOURCE_1, "missing" },
|
|
|
"dest",
|
|
|
+ null,
|
|
|
TEST_VALIDATIONS,
|
|
|
listener
|
|
|
),
|
|
@@ -280,6 +298,7 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
CLUSTER_STATE,
|
|
|
new String[] { SOURCE_1, "missing" },
|
|
|
"dest",
|
|
|
+ null,
|
|
|
Collections.emptyList(),
|
|
|
listener
|
|
|
),
|
|
@@ -294,6 +313,7 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
CLUSTER_STATE,
|
|
|
new String[] { SOURCE_1, "wildcard*", "missing" },
|
|
|
"dest",
|
|
|
+ null,
|
|
|
TEST_VALIDATIONS,
|
|
|
listener
|
|
|
),
|
|
@@ -309,6 +329,7 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
CLUSTER_STATE,
|
|
|
new String[] { SOURCE_1, "wildcard*", "missing" },
|
|
|
"dest",
|
|
|
+ null,
|
|
|
Collections.emptyList(),
|
|
|
listener
|
|
|
),
|
|
@@ -323,6 +344,7 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
CLUSTER_STATE,
|
|
|
new String[] { "wildcard*" },
|
|
|
"dest",
|
|
|
+ null,
|
|
|
TEST_VALIDATIONS,
|
|
|
listener
|
|
|
),
|
|
@@ -337,6 +359,7 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
CLUSTER_STATE,
|
|
|
new String[] { SOURCE_1 },
|
|
|
SOURCE_1,
|
|
|
+ null,
|
|
|
TEST_VALIDATIONS,
|
|
|
listener
|
|
|
),
|
|
@@ -355,6 +378,7 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
CLUSTER_STATE,
|
|
|
new String[] { SOURCE_1 },
|
|
|
SOURCE_1,
|
|
|
+ null,
|
|
|
Collections.emptyList(),
|
|
|
listener
|
|
|
),
|
|
@@ -369,6 +393,7 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
CLUSTER_STATE,
|
|
|
new String[] { "source-*" },
|
|
|
SOURCE_2,
|
|
|
+ null,
|
|
|
TEST_VALIDATIONS,
|
|
|
listener
|
|
|
),
|
|
@@ -387,6 +412,7 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
CLUSTER_STATE,
|
|
|
new String[] { "source-*" },
|
|
|
SOURCE_2,
|
|
|
+ null,
|
|
|
Collections.emptyList(),
|
|
|
listener
|
|
|
),
|
|
@@ -401,6 +427,7 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
CLUSTER_STATE,
|
|
|
new String[] { "source-1", "source-*" },
|
|
|
SOURCE_2,
|
|
|
+ null,
|
|
|
TEST_VALIDATIONS,
|
|
|
listener
|
|
|
),
|
|
@@ -419,6 +446,7 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
CLUSTER_STATE,
|
|
|
new String[] { "source-1", "source-*" },
|
|
|
SOURCE_2,
|
|
|
+ null,
|
|
|
Collections.emptyList(),
|
|
|
listener
|
|
|
),
|
|
@@ -433,6 +461,7 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
CLUSTER_STATE,
|
|
|
new String[] { "source-1", "source-*", "sou*" },
|
|
|
SOURCE_2,
|
|
|
+ null,
|
|
|
TEST_VALIDATIONS,
|
|
|
listener
|
|
|
),
|
|
@@ -457,6 +486,7 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
CLUSTER_STATE,
|
|
|
new String[] { SOURCE_1 },
|
|
|
DEST_ALIAS,
|
|
|
+ null,
|
|
|
TEST_VALIDATIONS,
|
|
|
listener
|
|
|
),
|
|
@@ -479,6 +509,7 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
CLUSTER_STATE,
|
|
|
new String[] { SOURCE_1 },
|
|
|
DEST_ALIAS,
|
|
|
+ null,
|
|
|
Collections.emptyList(),
|
|
|
listener
|
|
|
),
|
|
@@ -493,6 +524,7 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
CLUSTER_STATE,
|
|
|
new String[] { SOURCE_1 },
|
|
|
ALIAS_READ_WRITE_DEST,
|
|
|
+ null,
|
|
|
TEST_VALIDATIONS,
|
|
|
listener
|
|
|
),
|
|
@@ -519,6 +551,7 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
CLUSTER_STATE,
|
|
|
new String[] { SOURCE_1 },
|
|
|
SOURCE_1_ALIAS,
|
|
|
+ null,
|
|
|
TEST_VALIDATIONS,
|
|
|
listener
|
|
|
),
|
|
@@ -537,6 +570,7 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
CLUSTER_STATE,
|
|
|
new String[] { SOURCE_1 },
|
|
|
SOURCE_1_ALIAS,
|
|
|
+ null,
|
|
|
Collections.emptyList(),
|
|
|
listener
|
|
|
),
|
|
@@ -545,12 +579,60 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ public void testCheck_GivenMissingDestPipeline() throws Exception {
|
|
|
+ assertValidation(
|
|
|
+ listener -> simpleNonRemoteValidator.validate(
|
|
|
+ CLUSTER_STATE,
|
|
|
+ new String[] { SOURCE_1 },
|
|
|
+ "some-dest",
|
|
|
+ "missing-pipeline",
|
|
|
+ TEST_VALIDATIONS,
|
|
|
+ listener
|
|
|
+ ),
|
|
|
+ (Boolean) null,
|
|
|
+ e -> {
|
|
|
+ assertEquals(1, e.validationErrors().size());
|
|
|
+ assertThat(
|
|
|
+ e.validationErrors().get(0),
|
|
|
+ equalTo("Pipeline with id [missing-pipeline] could not be found")
|
|
|
+ );
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
+ // Let's now pretend that pipeline exists
|
|
|
+ Map<String, Object> processorConfig0 = new HashMap<>();
|
|
|
+ Map<String, Object> processorConfig1 = new HashMap<>();
|
|
|
+ processorConfig0.put(ConfigurationUtils.TAG_KEY, "first-processor");
|
|
|
+ Map<String, Object> pipelineConfig = new HashMap<>();
|
|
|
+ pipelineConfig.put(Pipeline.DESCRIPTION_KEY, "_description");
|
|
|
+ pipelineConfig.put(Pipeline.VERSION_KEY, "1");
|
|
|
+ pipelineConfig.put(Pipeline.PROCESSORS_KEY,
|
|
|
+ Arrays.asList(Collections.singletonMap("test", processorConfig0), Collections.singletonMap("test", processorConfig1)));
|
|
|
+ Map<String, Processor.Factory> processorRegistry = Collections.singletonMap("test", new TestProcessor.Factory());
|
|
|
+ Pipeline pipeline = Pipeline.create("missing-pipeline", pipelineConfig, processorRegistry, null);
|
|
|
+ when(ingestService.getPipeline("missing-pipeline")).thenReturn(pipeline);
|
|
|
+
|
|
|
+ assertValidation(
|
|
|
+ listener -> simpleNonRemoteValidator.validate(
|
|
|
+ CLUSTER_STATE,
|
|
|
+ new String[] { SOURCE_1 },
|
|
|
+ "some-dest",
|
|
|
+ "missing-pipeline",
|
|
|
+ TEST_VALIDATIONS,
|
|
|
+ listener
|
|
|
+ ),
|
|
|
+ true,
|
|
|
+ null
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
public void testCheck_MultipleValidationErrors() throws InterruptedException {
|
|
|
assertValidation(
|
|
|
listener -> simpleNonRemoteValidator.validate(
|
|
|
CLUSTER_STATE,
|
|
|
new String[] { SOURCE_1, "missing" },
|
|
|
SOURCE_1_ALIAS,
|
|
|
+ null,
|
|
|
TEST_VALIDATIONS,
|
|
|
listener
|
|
|
),
|
|
@@ -575,8 +657,10 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)),
|
|
|
remoteClusterService,
|
|
|
remoteClusterLicenseCheckerBasic,
|
|
|
+ ingestService,
|
|
|
new String[] { REMOTE_BASIC + ":" + "SOURCE_1" },
|
|
|
"dest",
|
|
|
+ null,
|
|
|
"node_id",
|
|
|
"license"
|
|
|
)
|
|
@@ -600,8 +684,10 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
remoteClusterService,
|
|
|
new RemoteClusterLicenseChecker(clientWithBasicLicense,
|
|
|
operationMode -> XPackLicenseState.isAllowedByOperationMode(operationMode, License.OperationMode.PLATINUM)),
|
|
|
+ ingestService,
|
|
|
new String[] { REMOTE_BASIC + ":" + "SOURCE_1" },
|
|
|
"dest",
|
|
|
+ null,
|
|
|
"node_id",
|
|
|
"platinum"
|
|
|
)
|
|
@@ -630,8 +716,10 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
remoteClusterService,
|
|
|
new RemoteClusterLicenseChecker(clientWithPlatinumLicense,
|
|
|
operationMode -> XPackLicenseState.isAllowedByOperationMode(operationMode, License.OperationMode.PLATINUM)),
|
|
|
+ ingestService,
|
|
|
new String[] { REMOTE_PLATINUM + ":" + "SOURCE_1" },
|
|
|
"dest",
|
|
|
+ null,
|
|
|
"node_id",
|
|
|
"license"
|
|
|
)
|
|
@@ -651,9 +739,11 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
remoteClusterService,
|
|
|
new RemoteClusterLicenseChecker(clientWithPlatinumLicense,
|
|
|
operationMode -> XPackLicenseState.isAllowedByOperationMode(operationMode, License.OperationMode.PLATINUM)),
|
|
|
+ ingestService,
|
|
|
new String[] { REMOTE_PLATINUM + ":" + "SOURCE_1" },
|
|
|
"dest",
|
|
|
"node_id",
|
|
|
+ null,
|
|
|
"platinum"
|
|
|
)
|
|
|
);
|
|
@@ -673,9 +763,11 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
remoteClusterService,
|
|
|
new RemoteClusterLicenseChecker(clientWithTrialLicense,
|
|
|
operationMode -> XPackLicenseState.isAllowedByOperationMode(operationMode, License.OperationMode.PLATINUM)),
|
|
|
+ ingestService,
|
|
|
new String[] { REMOTE_PLATINUM + ":" + "SOURCE_1" },
|
|
|
"dest",
|
|
|
"node_id",
|
|
|
+ null,
|
|
|
"trial"
|
|
|
)
|
|
|
);
|
|
@@ -697,8 +789,10 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
remoteClusterService,
|
|
|
new RemoteClusterLicenseChecker(clientWithExpiredBasicLicense,
|
|
|
operationMode -> XPackLicenseState.isAllowedByOperationMode(operationMode, License.OperationMode.PLATINUM)),
|
|
|
+ ingestService,
|
|
|
new String[] { REMOTE_BASIC + ":" + "SOURCE_1" },
|
|
|
"dest",
|
|
|
+ null,
|
|
|
"node_id",
|
|
|
"license"
|
|
|
)
|
|
@@ -724,8 +818,10 @@ public class SourceDestValidatorTests extends ESTestCase {
|
|
|
remoteClusterService,
|
|
|
new RemoteClusterLicenseChecker(clientWithExpiredBasicLicense,
|
|
|
operationMode -> XPackLicenseState.isAllowedByOperationMode(operationMode, License.OperationMode.PLATINUM)),
|
|
|
+ ingestService,
|
|
|
new String[] { "non_existing_remote:" + "SOURCE_1" },
|
|
|
"dest",
|
|
|
+ null,
|
|
|
"node_id",
|
|
|
"license"
|
|
|
)
|