Skip to content

Commit

Permalink
[INLONG-10010][Agent] Adjust source encapsulation, keep public initia…
Browse files Browse the repository at this point in the history
…lization in the base class init, and place specific source related initialization in the subclass's initSource (#10011)
  • Loading branch information
justinwwhuang authored Apr 19, 2024
1 parent b206b83 commit a3cc501
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.inlong.agent.plugin.sources;

import org.apache.inlong.agent.conf.InstanceProfile;
import org.apache.inlong.agent.conf.TaskProfile;
import org.apache.inlong.agent.plugin.Message;
import org.apache.inlong.agent.plugin.file.Reader;
Expand Down Expand Up @@ -93,6 +94,11 @@ protected String getThreadName() {
return null;
}

@Override
protected void initSource(InstanceProfile profile) {

}

@Override
protected void printCurrentState() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ public KafkaSource() {
}

@Override
public void init(InstanceProfile profile) {
protected void initSource(InstanceProfile profile) {
try {
LOGGER.info("KafkaSource init: {}", profile.toJsonStr());
this.profile = profile;
super.init(profile);
topic = profile.getInstanceId();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, profile.get(TASK_KAFKA_BOOTSTRAP_SERVERS));
props.put(ConsumerConfig.GROUP_ID_CONFIG, taskId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ public LogFileSource() {
}

@Override
public void init(InstanceProfile profile) {
protected void initSource(InstanceProfile profile) {
try {
LOGGER.info("LogFileSource init: {}", profile.toJsonStr());
super.init(profile);
fileName = profile.getInstanceId();
bufferToReadFile = new byte[SIZE_OF_BUFFER_TO_READ_FILE];
isIncrement = isIncrement(profile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ public MongoDBSource() {
}

@Override
public void init(InstanceProfile profile) {
protected void initSource(InstanceProfile profile) {
try {
LOGGER.info("MongoDBSource init: {}", profile.toJsonStr());
this.profile = profile;
super.init(profile);
debeziumQueue = new LinkedBlockingQueue<>(DEBEZIUM_QUEUE_SIZE);
database = profile.get(TaskConstants.TASK_MONGO_DATABASE_INCLUDE_LIST);
collection = profile.get(TaskConstants.TASK_MONGO_COLLECTION_INCLUDE_LIST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.inlong.agent.plugin.sources;

import org.apache.inlong.agent.conf.InstanceProfile;
import org.apache.inlong.agent.conf.TaskProfile;
import org.apache.inlong.agent.constant.CommonConstants;
import org.apache.inlong.agent.plugin.Message;
Expand Down Expand Up @@ -84,6 +85,11 @@ protected String getThreadName() {
return null;
}

@Override
protected void initSource(InstanceProfile profile) {

}

@Override
protected void printCurrentState() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.inlong.agent.plugin.sources;

import org.apache.inlong.agent.conf.InstanceProfile;
import org.apache.inlong.agent.conf.TaskProfile;
import org.apache.inlong.agent.plugin.Message;
import org.apache.inlong.agent.plugin.file.Reader;
Expand Down Expand Up @@ -53,6 +54,11 @@ protected String getThreadName() {
return null;
}

@Override
protected void initSource(InstanceProfile profile) {

}

@Override
protected void printCurrentState() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.inlong.agent.plugin.sources;

import org.apache.inlong.agent.conf.InstanceProfile;
import org.apache.inlong.agent.conf.TaskProfile;
import org.apache.inlong.agent.plugin.Message;
import org.apache.inlong.agent.plugin.file.Reader;
Expand Down Expand Up @@ -54,6 +55,11 @@ protected String getThreadName() {
return null;
}

@Override
protected void initSource(InstanceProfile profile) {

}

@Override
protected void printCurrentState() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ public PulsarSource() {
}

@Override
public void init(InstanceProfile profile) {
protected void initSource(InstanceProfile profile) {
try {
LOGGER.info("PulsarSource init: {}", profile.toJsonStr());
super.init(profile);
topic = profile.getInstanceId();
serviceUrl = profile.get(TASK_PULSAR_SERVICE_URL);
subscription = profile.get(TASK_PULSAR_SUBSCRIPTION, PULSAR_SUBSCRIPTION_PREFIX + inlongStreamId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.inlong.agent.plugin.sources;

import org.apache.inlong.agent.conf.InstanceProfile;
import org.apache.inlong.agent.conf.TaskProfile;
import org.apache.inlong.agent.plugin.Message;
import org.apache.inlong.agent.plugin.file.Reader;
Expand Down Expand Up @@ -54,6 +55,11 @@ protected String getThreadName() {
return null;
}

@Override
protected void initSource(InstanceProfile profile) {

}

@Override
protected void printCurrentState() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.inlong.agent.plugin.sources;

import org.apache.inlong.agent.conf.InstanceProfile;
import org.apache.inlong.agent.conf.TaskProfile;
import org.apache.inlong.agent.plugin.Message;
import org.apache.inlong.agent.plugin.file.Reader;
Expand Down Expand Up @@ -53,6 +54,11 @@ protected String getThreadName() {
return null;
}

@Override
protected void initSource(InstanceProfile profile) {

}

@Override
protected void printCurrentState() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.inlong.agent.common.AgentThreadFactory;
import org.apache.inlong.agent.conf.InstanceProfile;
import org.apache.inlong.agent.conf.OffsetProfile;
import org.apache.inlong.agent.conf.TaskProfile;
import org.apache.inlong.agent.constant.CycleUnitType;
import org.apache.inlong.agent.constant.TaskConstants;
import org.apache.inlong.agent.core.task.MemoryManager;
Expand All @@ -29,6 +30,7 @@
import org.apache.inlong.agent.metrics.AgentMetricItemSet;
import org.apache.inlong.agent.metrics.audit.AuditUtils;
import org.apache.inlong.agent.plugin.Message;
import org.apache.inlong.agent.plugin.file.Reader;
import org.apache.inlong.agent.plugin.file.Source;
import org.apache.inlong.agent.plugin.sources.file.extend.ExtendedHandler;
import org.apache.inlong.agent.utils.AgentUtils;
Expand Down Expand Up @@ -128,8 +130,11 @@ public void init(InstanceProfile profile) {
initOffset();
registerMetric();
initExtendHandler();
initSource(profile);
}

protected abstract void initSource(InstanceProfile profile);

protected void initOffset() {
offsetProfile = OffsetManager.getInstance().getOffset(taskId, instanceId);
}
Expand Down Expand Up @@ -396,4 +401,9 @@ public boolean sourceFinish() {
}
return emptyCount > EMPTY_CHECK_COUNT_AT_LEAST;
}

@Override
public List<Reader> split(TaskProfile conf) {
return null;
}
}

0 comments on commit a3cc501

Please sign in to comment.