Search in sources :

Example 1 with Configuration

use of org.apache.inlong.sort.configuration.Configuration in project incubator-inlong by apache.

the class ZkTools method updateDataFlowInfo.

/**
 * Update DataFlowInfo.
 * @param dataFlowInfo DataFlowInfo to be updated to.
 * @param cluster cluster name of the etl job.
 * @param dataFlowId dataFlow id
 * @param zkQuorum zk quorum
 * @param zkRoot zk root path
 * @throws Exception
 */
public static void updateDataFlowInfo(DataFlowInfo dataFlowInfo, String cluster, long dataFlowId, String zkQuorum, String zkRoot) throws Exception {
    final Configuration config = new Configuration();
    config.setString(Constants.ZOOKEEPER_QUORUM, zkQuorum);
    config.setString(Constants.ZOOKEEPER_ROOT, zkRoot);
    final ObjectMapper objectMapper = new ObjectMapper();
    final String dataFlowInfoPath = getNodePathOfDataFlowInfo(dataFlowId);
    final String dataFlowStorageInfoPath = getNodePathOfDataFlowStorageInfoInCluster(cluster, dataFlowId);
    try (CuratorFramework zkClient = ZooKeeperUtils.startCuratorFramework(config)) {
        // update DataFlowInfo
        final byte[] dataFlowInfoData = objectMapper.writeValueAsBytes(dataFlowInfo);
        if (zkClient.checkExists().forPath(dataFlowInfoPath) == null) {
            ZooKeeperUtils.createRecursive(zkClient, dataFlowInfoPath, dataFlowInfoData, CreateMode.PERSISTENT);
        } else {
            zkClient.setData().forPath(dataFlowInfoPath, dataFlowInfoData);
        }
        // update DataFlowStorageInfo
        DataFlowStorageInfo dataFlowStorageInfo = new DataFlowStorageInfo(ZK, dataFlowInfoPath);
        final byte[] dataFlowStorageInfoData = objectMapper.writeValueAsBytes(dataFlowStorageInfo);
        if (zkClient.checkExists().forPath(dataFlowStorageInfoPath) == null) {
            ZooKeeperUtils.createRecursive(zkClient, dataFlowStorageInfoPath, dataFlowStorageInfoData, CreateMode.PERSISTENT);
        } else {
            zkClient.setData().forPath(dataFlowStorageInfoPath, dataFlowStorageInfoData);
        }
    }
    LOG.info("Update DataFlowInfo with id {} on zk successfully", dataFlowId);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) Configuration(org.apache.inlong.sort.configuration.Configuration) DataFlowStorageInfo(org.apache.inlong.sort.protocol.DataFlowStorageInfo) ObjectMapper(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with Configuration

use of org.apache.inlong.sort.configuration.Configuration in project incubator-inlong by apache.

the class CommonUtils method mergeConfAndProp.

public static Configuration mergeConfAndProp(Configuration conf, Map<String, Object> props) {
    final Configuration newConf = new Configuration(conf);
    newConf.addAll(props);
    return newConf;
}
Also used : Configuration(org.apache.inlong.sort.configuration.Configuration)

Example 3 with Configuration

use of org.apache.inlong.sort.configuration.Configuration in project incubator-inlong by apache.

the class MultiTopicTubeSourceFunctionTest method testCommitTubeSubscriptionDescriptionPreview.

@Test
public void testCommitTubeSubscriptionDescriptionPreview() {
    final TestingMultiTenancyTubeConsumer tubeConsumer = generateTubeConsumer();
    final MultiTopicTubeSourceFunction sourceFunction = new MultiTopicTubeSourceFunction(new Configuration());
    sourceFunction.setTubeConsumer(tubeConsumer);
    sourceFunction.setTubeTopicSubscriptions(Collections.emptyMap());
    final Map<String, TubeSubscriptionDescription> descriptionPreview = new HashMap<>();
    descriptionPreview.put(topicAdded, TubeSubscriptionDescription.generate(dataFlowId1, generateTubeSourceInfo(topicAdded, tid1)));
    sourceFunction.commitTubeSubscriptionDescriptionPreview(descriptionPreview);
    assertEquals(sourceFunction.getTubeTopicSubscriptions(), descriptionPreview);
    assertEquals(1, tubeConsumer.addedTopics.size());
    assertEquals(topicAdded, tubeConsumer.addedTopics.get(0).getTopic());
    assertEquals(masterAddress, tubeConsumer.addedTopics.get(0).getMasterAddress());
    assertNull(tubeConsumer.addedTopics.get(0).getConsumerGroup());
    assertEquals(Collections.singletonList(tid1), tubeConsumer.addedTopics.get(0).getTids());
}
Also used : Configuration(org.apache.inlong.sort.configuration.Configuration) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 4 with Configuration

use of org.apache.inlong.sort.configuration.Configuration in project incubator-inlong by apache.

the class MultiTopicTubeSourceFunctionTest method testProcessSourceEvent.

@Test
public void testProcessSourceEvent() {
    final TestingMultiTenancyTubeConsumer tubeConsumer = generateTubeConsumer();
    final MultiTopicTubeSourceFunction sourceFunction = new MultiTopicTubeSourceFunction(new Configuration());
    sourceFunction.setTubeConsumer(tubeConsumer);
    final Map<String, TubeSubscriptionDescription> descriptions = new HashMap<>();
    // add event1
    final SourceEvent addEvent1 = new SourceEvent(SourceEventType.ADDED, dataFlowId1, generateTubeSourceInfo(topicAdded, tid1));
    sourceFunction.processSourceEvent(addEvent1, descriptions);
    // add event should only change the preview
    assertTrue(tubeConsumer.addedTopics.isEmpty());
    assertTrue(tubeConsumer.updatedTopics.isEmpty());
    assertTrue(tubeConsumer.removedTopics.isEmpty());
    // add event1 again, should affect nothing
    sourceFunction.processSourceEvent(addEvent1, descriptions);
    // add event2
    final SourceEvent addEvent2 = new SourceEvent(SourceEventType.ADDED, dataFlowId2, generateTubeSourceInfo(topicAdded, tid2));
    sourceFunction.processSourceEvent(addEvent2, descriptions);
    // add event should only change the preview
    assertTrue(tubeConsumer.addedTopics.isEmpty());
    assertTrue(tubeConsumer.updatedTopics.isEmpty());
    assertTrue(tubeConsumer.removedTopics.isEmpty());
    assertEquals(1, descriptions.size());
    assertEquals(2, descriptions.get(topicAdded).getDataFlows().size());
    // remove event
    final TubeSubscriptionDescription existingDescription = new TubeSubscriptionDescription(topicRemoved, masterAddress, null);
    existingDescription.addDataFlow(dataFlowId3, generateTubeSourceInfo(topicRemoved, tid1));
    descriptions.put(topicRemoved, existingDescription);
    final SourceEvent removeEvent = new SourceEvent(SourceEventType.REMOVED, dataFlowId3, generateTubeSourceInfo(topicRemoved, tid1));
    sourceFunction.processSourceEvent(removeEvent, descriptions);
    assertTrue(tubeConsumer.addedTopics.isEmpty());
    assertTrue(tubeConsumer.updatedTopics.isEmpty());
    // remove event should be fired immediately
    assertEquals(1, tubeConsumer.removedTopics.size());
    assertEquals(topicRemoved, tubeConsumer.removedTopics.get(0));
    assertEquals(1, descriptions.size());
    assertEquals(2, descriptions.get(topicAdded).getDataFlows().size());
}
Also used : Configuration(org.apache.inlong.sort.configuration.Configuration) HashMap(java.util.HashMap) SourceEvent(org.apache.inlong.sort.flink.multitenant.tubemq.MultiTopicTubeSourceFunction.SourceEvent) Test(org.junit.Test)

Example 5 with Configuration

use of org.apache.inlong.sort.configuration.Configuration in project incubator-inlong by apache.

the class MultiTopicTubeSourceFunctionTest method generateTubeConsumer.

private TestingMultiTenancyTubeConsumer generateTubeConsumer() {
    final Configuration configuration = new Configuration();
    configuration.setString(Constants.CLUSTER_ID, "cluster_id");
    return new TestingMultiTenancyTubeConsumer(configuration);
}
Also used : Configuration(org.apache.inlong.sort.configuration.Configuration)

Aggregations

Configuration (org.apache.inlong.sort.configuration.Configuration)30 Test (org.junit.Test)19 HashMap (java.util.HashMap)9 Row (org.apache.flink.types.Row)8 File (java.io.File)5 LocalDataOutputStream (org.apache.flink.core.fs.local.LocalDataOutputStream)5 DataFlowInfo (org.apache.inlong.sort.protocol.DataFlowInfo)5 Map (java.util.Map)4 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)4 TextFileFormat (org.apache.inlong.sort.protocol.sink.HiveSinkInfo.TextFileFormat)4 Timestamp (java.sql.Timestamp)3 ArrayList (java.util.ArrayList)3 ExecutorService (java.util.concurrent.ExecutorService)3 CuratorFramework (org.apache.curator.framework.CuratorFramework)3 BigIntType (org.apache.flink.table.types.logical.BigIntType)3 CharType (org.apache.flink.table.types.logical.CharType)3 IntType (org.apache.flink.table.types.logical.IntType)3 TubePullThread (org.apache.inlong.sort.flink.multitenant.tubemq.MultiTenancyTubeConsumer.TubePullThread)3 BuiltInFieldInfo (org.apache.inlong.sort.protocol.BuiltInFieldInfo)3 FieldInfo (org.apache.inlong.sort.protocol.FieldInfo)3