Search in sources :

Example 6 with NoneConnectorClientConfigOverridePolicy

use of org.apache.kafka.connect.connector.policy.NoneConnectorClientConfigOverridePolicy in project kafka by apache.

the class AbstractHerderTest method taskStatus.

@Test
public void taskStatus() {
    ConnectorTaskId taskId = new ConnectorTaskId("connector", 0);
    String workerId = "workerId";
    AbstractHerder herder = partialMockBuilder(AbstractHerder.class).withConstructor(Worker.class, String.class, String.class, StatusBackingStore.class, ConfigBackingStore.class, ConnectorClientConfigOverridePolicy.class).withArgs(worker, workerId, kafkaClusterId, statusStore, configStore, noneConnectorClientConfigOverridePolicy).addMockedMethod("generation").createMock();
    EasyMock.expect(herder.generation()).andStubReturn(5);
    final Capture<TaskStatus> statusCapture = EasyMock.newCapture();
    statusStore.putSafe(EasyMock.capture(statusCapture));
    EasyMock.expectLastCall();
    EasyMock.expect(statusStore.get(taskId)).andAnswer(statusCapture::getValue);
    replayAll();
    herder.onFailure(taskId, new RuntimeException());
    ConnectorStateInfo.TaskState taskState = herder.taskStatus(taskId);
    assertEquals(workerId, taskState.workerId());
    assertEquals("FAILED", taskState.state());
    assertEquals(0, taskState.id());
    assertNotNull(taskState.trace());
    verifyAll();
}
Also used : StatusBackingStore(org.apache.kafka.connect.storage.StatusBackingStore) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) AllConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.AllConnectorClientConfigOverridePolicy) PrincipalConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.PrincipalConnectorClientConfigOverridePolicy) ConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.ConnectorClientConfigOverridePolicy) NoneConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.NoneConnectorClientConfigOverridePolicy) ConfigBackingStore(org.apache.kafka.connect.storage.ConfigBackingStore) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with NoneConnectorClientConfigOverridePolicy

use of org.apache.kafka.connect.connector.policy.NoneConnectorClientConfigOverridePolicy in project kafka by apache.

the class AbstractHerderTest method testConfigValidationPredicatesExtendResults.

@Test()
public void testConfigValidationPredicatesExtendResults() {
    AbstractHerder herder = createConfigValidationHerder(TestSourceConnector.class, noneConnectorClientConfigOverridePolicy);
    // 2 transform aliases defined -> 2 plugin lookups
    Set<PluginDesc<Transformation<?>>> transformations = new HashSet<>();
    transformations.add(transformationPluginDesc());
    EasyMock.expect(plugins.transformations()).andReturn(transformations).times(1);
    Set<PluginDesc<Predicate<?>>> predicates = new HashSet<>();
    predicates.add(predicatePluginDesc());
    EasyMock.expect(plugins.predicates()).andReturn(predicates).times(2);
    replayAll();
    // Define 2 transformations. One has a class defined and so can get embedded configs, the other is missing
    // class info that should generate an error.
    Map<String, String> config = new HashMap<>();
    config.put(ConnectorConfig.CONNECTOR_CLASS_CONFIG, TestSourceConnector.class.getName());
    config.put(ConnectorConfig.NAME_CONFIG, "connector-name");
    config.put(ConnectorConfig.TRANSFORMS_CONFIG, "xformA");
    config.put(ConnectorConfig.TRANSFORMS_CONFIG + ".xformA.type", SampleTransformation.class.getName());
    config.put(ConnectorConfig.TRANSFORMS_CONFIG + ".xformA.predicate", "predX");
    config.put(ConnectorConfig.PREDICATES_CONFIG, "predX,predY");
    config.put(ConnectorConfig.PREDICATES_CONFIG + ".predX.type", SamplePredicate.class.getName());
    // connector required config
    config.put("required", "value");
    ConfigInfos result = herder.validateConnectorConfig(config, false);
    assertEquals(herder.connectorTypeForClass(config.get(ConnectorConfig.CONNECTOR_CLASS_CONFIG)), ConnectorType.SOURCE);
    // We expect there to be errors due to the missing name and .... Note that these assertions depend heavily on
    // the config fields for SourceConnectorConfig, but we expect these to change rarely.
    assertEquals(TestSourceConnector.class.getName(), result.name());
    // Each transform also gets its own group
    List<String> expectedGroups = Arrays.asList(ConnectorConfig.COMMON_GROUP, ConnectorConfig.TRANSFORMS_GROUP, ConnectorConfig.PREDICATES_GROUP, ConnectorConfig.ERROR_GROUP, SourceConnectorConfig.TOPIC_CREATION_GROUP, "Transforms: xformA", "Predicates: predX", "Predicates: predY");
    assertEquals(expectedGroups, result.groups());
    assertEquals(2, result.errorCount());
    Map<String, ConfigInfo> infos = result.values().stream().collect(Collectors.toMap(info -> info.configKey().name(), Function.identity()));
    assertEquals(24, infos.size());
    // Should get 2 type fields from the transforms, first adds its own config since it has a valid class
    assertEquals("transforms.xformA.type", infos.get("transforms.xformA.type").configValue().name());
    assertTrue(infos.get("transforms.xformA.type").configValue().errors().isEmpty());
    assertEquals("transforms.xformA.subconfig", infos.get("transforms.xformA.subconfig").configValue().name());
    assertEquals("transforms.xformA.predicate", infos.get("transforms.xformA.predicate").configValue().name());
    assertTrue(infos.get("transforms.xformA.predicate").configValue().errors().isEmpty());
    assertEquals("transforms.xformA.negate", infos.get("transforms.xformA.negate").configValue().name());
    assertTrue(infos.get("transforms.xformA.negate").configValue().errors().isEmpty());
    assertEquals("predicates.predX.type", infos.get("predicates.predX.type").configValue().name());
    assertEquals("predicates.predX.predconfig", infos.get("predicates.predX.predconfig").configValue().name());
    assertEquals("predicates.predY.type", infos.get("predicates.predY.type").configValue().name());
    assertFalse(infos.get("predicates.predY.type").configValue().errors().isEmpty());
    verifyAll();
}
Also used : Arrays(java.util.Arrays) EasyMock.strictMock(org.easymock.EasyMock.strictMock) Plugins(org.apache.kafka.connect.runtime.isolation.Plugins) Transformation(org.apache.kafka.connect.transforms.Transformation) MockStrict(org.powermock.api.easymock.annotation.MockStrict) SourceConnector(org.apache.kafka.connect.source.SourceConnector) AllConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.AllConnectorClientConfigOverridePolicy) Map(java.util.Map) ConnectorType(org.apache.kafka.connect.runtime.rest.entities.ConnectorType) PowerMock.replayAll(org.powermock.api.easymock.PowerMock.replayAll) ConfigDef(org.apache.kafka.common.config.ConfigDef) PrincipalConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.PrincipalConnectorClientConfigOverridePolicy) CommonClientConfigs(org.apache.kafka.clients.CommonClientConfigs) Collection(java.util.Collection) ConnectRecord(org.apache.kafka.connect.connector.ConnectRecord) Set(java.util.Set) ConfigValue(org.apache.kafka.common.config.ConfigValue) PowerMock(org.powermock.api.easymock.PowerMock) Collectors(java.util.stream.Collectors) EasyMock.partialMockBuilder(org.easymock.EasyMock.partialMockBuilder) ConfigValueInfo(org.apache.kafka.connect.runtime.rest.entities.ConfigValueInfo) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo) ConfigInfo(org.apache.kafka.connect.runtime.rest.entities.ConfigInfo) List(java.util.List) Predicate(org.apache.kafka.connect.transforms.predicates.Predicate) ConfigInfos(org.apache.kafka.connect.runtime.rest.entities.ConfigInfos) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) BadRequestException(org.apache.kafka.connect.runtime.rest.errors.BadRequestException) ConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.ConnectorClientConfigOverridePolicy) SourceTask(org.apache.kafka.connect.source.SourceTask) Connector(org.apache.kafka.connect.connector.Connector) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) Assert.assertThrows(org.junit.Assert.assertThrows) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) ConfigBackingStore(org.apache.kafka.connect.storage.ConfigBackingStore) Function(java.util.function.Function) NoneConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.NoneConnectorClientConfigOverridePolicy) PluginDesc(org.apache.kafka.connect.runtime.isolation.PluginDesc) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PowerMock.verifyAll(org.powermock.api.easymock.PowerMock.verifyAll) SaslConfigs(org.apache.kafka.common.config.SaslConfigs) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) ProducerConfig(org.apache.kafka.clients.producer.ProducerConfig) Capture(org.easymock.Capture) AbstractHerder.keysWithVariableValues(org.apache.kafka.connect.runtime.AbstractHerder.keysWithVariableValues) Assert.assertNotNull(org.junit.Assert.assertNotNull) ClusterConfigState(org.apache.kafka.connect.runtime.distributed.ClusterConfigState) ConfigTransformer(org.apache.kafka.common.config.ConfigTransformer) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) EasyMock(org.easymock.EasyMock) ConfigException(org.apache.kafka.common.config.ConfigException) StatusBackingStore(org.apache.kafka.connect.storage.StatusBackingStore) OAuthBearerUnsecuredLoginCallbackHandler(org.apache.kafka.common.security.oauthbearer.internals.unsecured.OAuthBearerUnsecuredLoginCallbackHandler) Assert.assertNull(org.junit.Assert.assertNull) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) HashMap(java.util.HashMap) ConfigInfo(org.apache.kafka.connect.runtime.rest.entities.ConfigInfo) PluginDesc(org.apache.kafka.connect.runtime.isolation.PluginDesc) HashSet(java.util.HashSet) ConfigInfos(org.apache.kafka.connect.runtime.rest.entities.ConfigInfos) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with NoneConnectorClientConfigOverridePolicy

use of org.apache.kafka.connect.connector.policy.NoneConnectorClientConfigOverridePolicy in project kafka by apache.

the class AbstractHerderTest method testBuildRestartPlanForNoRestart.

@Test
public void testBuildRestartPlanForNoRestart() {
    RestartRequest restartRequest = new RestartRequest(connector, true, false);
    ConnectorTaskId taskId1 = new ConnectorTaskId(connector, 1);
    ConnectorTaskId taskId2 = new ConnectorTaskId(connector, 2);
    List<TaskStatus> taskStatuses = new ArrayList<>();
    taskStatuses.add(new TaskStatus(taskId1, AbstractStatus.State.RUNNING, workerId, generation));
    taskStatuses.add(new TaskStatus(taskId2, AbstractStatus.State.FAILED, workerId, generation));
    AbstractHerder herder = partialMockBuilder(AbstractHerder.class).withConstructor(Worker.class, String.class, String.class, StatusBackingStore.class, ConfigBackingStore.class, ConnectorClientConfigOverridePolicy.class).withArgs(worker, workerId, kafkaClusterId, statusStore, configStore, noneConnectorClientConfigOverridePolicy).addMockedMethod("generation").createMock();
    EasyMock.expect(herder.generation()).andStubReturn(generation);
    EasyMock.expect(herder.rawConfig(connector)).andReturn(null);
    EasyMock.expect(statusStore.get(connector)).andReturn(new ConnectorStatus(connector, AbstractStatus.State.RUNNING, workerId, generation));
    EasyMock.expect(statusStore.getAll(connector)).andReturn(taskStatuses);
    EasyMock.expect(worker.getPlugins()).andStubReturn(plugins);
    replayAll();
    Optional<RestartPlan> mayBeRestartPlan = herder.buildRestartPlan(restartRequest);
    assertTrue(mayBeRestartPlan.isPresent());
    RestartPlan restartPlan = mayBeRestartPlan.get();
    assertFalse(restartPlan.shouldRestartConnector());
    assertFalse(restartPlan.shouldRestartTasks());
    assertTrue(restartPlan.taskIdsToRestart().isEmpty());
    PowerMock.verifyAll();
}
Also used : StatusBackingStore(org.apache.kafka.connect.storage.StatusBackingStore) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) ArrayList(java.util.ArrayList) AllConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.AllConnectorClientConfigOverridePolicy) PrincipalConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.PrincipalConnectorClientConfigOverridePolicy) ConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.ConnectorClientConfigOverridePolicy) NoneConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.NoneConnectorClientConfigOverridePolicy) ConfigBackingStore(org.apache.kafka.connect.storage.ConfigBackingStore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

AllConnectorClientConfigOverridePolicy (org.apache.kafka.connect.connector.policy.AllConnectorClientConfigOverridePolicy)8 ConnectorClientConfigOverridePolicy (org.apache.kafka.connect.connector.policy.ConnectorClientConfigOverridePolicy)8 NoneConnectorClientConfigOverridePolicy (org.apache.kafka.connect.connector.policy.NoneConnectorClientConfigOverridePolicy)8 PrincipalConnectorClientConfigOverridePolicy (org.apache.kafka.connect.connector.policy.PrincipalConnectorClientConfigOverridePolicy)8 ConfigBackingStore (org.apache.kafka.connect.storage.ConfigBackingStore)8 StatusBackingStore (org.apache.kafka.connect.storage.StatusBackingStore)8 ConnectorTaskId (org.apache.kafka.connect.util.ConnectorTaskId)8 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 ConnectorStateInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo)6 ArrayList (java.util.ArrayList)5 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 Collections (java.util.Collections)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Set (java.util.Set)3