From 2b083c4b7b24e814e784ff7c3d29cdb099a06ae9 Mon Sep 17 00:00:00 2001 From: wenweihuang Date: Tue, 31 Oct 2023 19:44:10 +0800 Subject: [PATCH 1/2] [INLONG-9182][Agent] Delete useless code --- .../inlong/agent/pojo/DbCollectorTask.java | 45 ------ .../agent/pojo/DbCollectorTaskReportDto.java | 27 ---- .../pojo/DbCollectorTaskReportResponse.java | 27 ---- .../agent/pojo/DbCollectorTaskRequestDto.java | 27 ---- .../agent/pojo/DbCollectorTaskResult.java | 47 ------- .../inlong/agent/pojo/SqlJobProfileDto.java | 130 ------------------ 6 files changed, 303 deletions(-) delete mode 100644 inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/pojo/DbCollectorTask.java delete mode 100644 inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/pojo/DbCollectorTaskReportDto.java delete mode 100644 inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/pojo/DbCollectorTaskReportResponse.java delete mode 100644 inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/pojo/DbCollectorTaskRequestDto.java delete mode 100644 inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/pojo/DbCollectorTaskResult.java delete mode 100644 inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/pojo/SqlJobProfileDto.java diff --git a/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/pojo/DbCollectorTask.java b/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/pojo/DbCollectorTask.java deleted file mode 100644 index c566bec780c..00000000000 --- a/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/pojo/DbCollectorTask.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.inlong.agent.pojo; - -import lombok.Data; - -@Data -public class DbCollectorTask { - - private String id; - private Integer type; - private Integer dbType; - private String ip; - private Integer dbport; - private String dbName; - private String user; - private String password; - private String sqlStatement; - private Integer totalLimit; - private Integer onceLimit; - private Integer timeLimit; - private Integer retryTimes; - private String inlongGroupId; - private String inlongStreamId; - private String seperator; - - public boolean isValid() { - return true; - } -} diff --git a/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/pojo/DbCollectorTaskReportDto.java b/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/pojo/DbCollectorTaskReportDto.java deleted file mode 100644 index f5065d3264f..00000000000 --- a/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/pojo/DbCollectorTaskReportDto.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.inlong.agent.pojo; - -import lombok.Data; - -@Data -public class DbCollectorTaskReportDto { - - private String version; - private String md5; -} diff --git a/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/pojo/DbCollectorTaskReportResponse.java b/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/pojo/DbCollectorTaskReportResponse.java deleted file mode 100644 index 2f5bc13e456..00000000000 --- a/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/pojo/DbCollectorTaskReportResponse.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.inlong.agent.pojo; - -import lombok.Data; - -@Data -public class DbCollectorTaskReportResponse { - - private String version; - private String md5; -} diff --git a/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/pojo/DbCollectorTaskRequestDto.java b/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/pojo/DbCollectorTaskRequestDto.java deleted file mode 100644 index aecdf074e82..00000000000 --- a/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/pojo/DbCollectorTaskRequestDto.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.inlong.agent.pojo; - -import lombok.Data; - -@Data -public class DbCollectorTaskRequestDto { - - private String version; - private String md5; -} diff --git a/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/pojo/DbCollectorTaskResult.java b/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/pojo/DbCollectorTaskResult.java deleted file mode 100644 index b7c6385ae31..00000000000 --- a/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/pojo/DbCollectorTaskResult.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.inlong.agent.pojo; - -import org.apache.inlong.agent.conf.JobProfile; - -import lombok.Data; - -@Data -public class DbCollectorTaskResult { - - private String version; - private boolean result; - private Integer errCode; - private String md5; - - private DbCollectorTask data = new DbCollectorTask(); - - /** - * get JobProfile based on DbCollectorTask - * - * @return JobProfile - */ - public JobProfile getJobProfile() { - JobProfile profile = null; - if (data == null) { - return profile; - } - profile = SqlJobProfileDto.convertToJobProfile(data); - return profile; - } -} diff --git a/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/pojo/SqlJobProfileDto.java b/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/pojo/SqlJobProfileDto.java deleted file mode 100644 index b719ce3550b..00000000000 --- a/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/pojo/SqlJobProfileDto.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.inlong.agent.pojo; - -import org.apache.inlong.agent.conf.AgentConfiguration; -import org.apache.inlong.agent.conf.JobProfile; - -import com.google.gson.Gson; -import lombok.Data; - -import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_VIP_HTTP_HOST; -import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_VIP_HTTP_PORT; - -@Data -public class SqlJobProfileDto { - - public static final String SQL_JOB = "SQL_JOB"; - public static final String DEFAULT_CHANNEL = "org.apache.inlong.agent.plugin.channel.MemoryChannel"; - public static final String DEFAULT_DATAPROXY_SINK = "org.apache.inlong.agent.plugin.sinks.ProxySink"; - public static final String DEFAULT_SOURCE = "org.apache.inlong.agent.plugin.sources.DatabaseSqlSource"; - private static final Gson GSON = new Gson(); - - private Job job; - private Proxy proxy; - - private static Job getJob(DbCollectorTask task) { - Sql sql = new Sql(); - sql.setHostname(task.getIp()); - sql.setPort(task.getDbport()); - sql.setUser(task.getUser()); - sql.setPassword(task.getPassword()); - sql.setCommand(task.getSqlStatement()); - Job job = new Job(); - job.setId(Integer.parseInt(task.getId())); - job.setName(SQL_JOB); - job.setSource(DEFAULT_SOURCE); - job.setSink(DEFAULT_DATAPROXY_SINK); - job.setChannel(DEFAULT_CHANNEL); - job.setDbName(task.getDbName()); - job.setTotalLimit(task.getTotalLimit()); - job.setOnceLimit(task.getOnceLimit()); - job.setTimeLimit(task.getTimeLimit()); - job.setRetryTimes(task.getRetryTimes()); - job.setSql(sql); - return job; - } - - private static Proxy getProxy(DbCollectorTask task) { - Proxy proxy = new Proxy(); - Manager manager = new Manager(); - AgentConfiguration agentConf = AgentConfiguration.getAgentConf(); - manager.setHost(agentConf.get(AGENT_MANAGER_VIP_HTTP_HOST)); - manager.setPort(agentConf.get(AGENT_MANAGER_VIP_HTTP_PORT)); - proxy.setInlongGroupId(task.getInlongGroupId()); - proxy.setInlongStreamId(task.getInlongStreamId()); - proxy.setManager(manager); - return proxy; - } - - /** - * convert DbCollectorTask to JobProfile - */ - public static JobProfile convertToJobProfile(DbCollectorTask task) { - if (!task.isValid()) { - throw new IllegalArgumentException("input task" + task + "is invalid please check"); - } - SqlJobProfileDto profileDto = new SqlJobProfileDto(); - Proxy proxy = getProxy(task); - Job job = getJob(task); - profileDto.setProxy(proxy); - profileDto.setJob(job); - return JobProfile.parseJsonStr(GSON.toJson(profileDto)); - } - - @Data - public static class Sql { - - private String user; - private String password; - private String hostname; - private Integer port; - private String command; - } - - @Data - public static class Job { - - private int id; - private String name; - private String source; - private String sink; - private String channel; - private String dbName; - private Integer totalLimit; - private Integer onceLimit; - private Integer timeLimit; - private Integer retryTimes; - private Sql sql; - } - - @Data - public static class Manager { - - private String port; - private String host; - } - - @Data - public static class Proxy { - - private String inlongGroupId; - private String inlongStreamId; - private Manager manager; - } -} \ No newline at end of file From 68f3e2d76b271c557c31549905094b045e94d16c Mon Sep 17 00:00:00 2001 From: wenweihuang Date: Tue, 31 Oct 2023 20:46:43 +0800 Subject: [PATCH 2/2] [INLONG-9182][Agent] Delete useless code --- .../agent/core/instance/TestInstanceManager.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/inlong-agent/agent-core/src/test/java/org/apache/inlong/agent/core/instance/TestInstanceManager.java b/inlong-agent/agent-core/src/test/java/org/apache/inlong/agent/core/instance/TestInstanceManager.java index 62bfa85d8a8..0745c13c72f 100755 --- a/inlong-agent/agent-core/src/test/java/org/apache/inlong/agent/core/instance/TestInstanceManager.java +++ b/inlong-agent/agent-core/src/test/java/org/apache/inlong/agent/core/instance/TestInstanceManager.java @@ -47,7 +47,7 @@ public class TestInstanceManager { @BeforeClass public static void setup() { helper = new AgentBaseTestsHelper(TestInstanceManager.class.getName()).setupAgentHome(); - String pattern = helper.getTestRootDir() + "/YYYYMMDD.log_[0-9]+"; + String pattern = helper.getTestRootDir() + "/YYYYMMDD_[0-9]+.txt"; Db basicDb = TaskManager.initDb("/localdb"); taskProfile = helper.getTaskProfile(1, pattern, false, 0L, 0L, TaskStateEnum.RUNNING); manager = new InstanceManager("1", basicDb); @@ -64,7 +64,7 @@ public static void teardown() { public void testInstanceManager() { long timeBefore = AgentUtils.getCurrentTime(); InstanceProfile profile = taskProfile.createInstanceProfile(MockInstance.class.getCanonicalName(), - helper.getTestRootDir() + "/20230927.log_1", "20230927"); + helper.getTestRootDir() + "/20230927_1.txt", "20230927"); String instanceId = profile.getInstanceId(); InstanceAction action = new InstanceAction(); action.setActionType(ActionType.ADD); @@ -95,8 +95,8 @@ public void testInstanceManager() { action.setActionType(ActionType.DELETE); manager.submitAction(action); await().atMost(1, TimeUnit.SECONDS).until(() -> manager.getInstanceProfile(instanceId) == null); - Assert.assertTrue(instance.initTime == MockInstance.INIT_TIME); - Assert.assertTrue(instance.runtime == MockInstance.RUN_TIME); - Assert.assertTrue(instance.destroyTime == MockInstance.DESTROY_TIME); + Assert.assertTrue(String.valueOf(instance.initTime), instance.initTime == MockInstance.INIT_TIME); + Assert.assertTrue(String.valueOf(instance.runtime), instance.runtime == MockInstance.RUN_TIME); + Assert.assertTrue(String.valueOf(instance.destroyTime), instance.destroyTime == MockInstance.DESTROY_TIME); } }