-
Notifications
You must be signed in to change notification settings - Fork 21
Complete the migration of the collector node project #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
|
|
||
| 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. | ||
|
|
||
| --> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>org.apache.iotdb</groupId> | ||
| <artifactId>iotdb-collector</artifactId> | ||
| <version>1.3.2</version> | ||
| </parent> | ||
| <artifactId>collector-core</artifactId> | ||
| <name>IoTDB: Collector: Core</name> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.apache.iotdb</groupId> | ||
| <artifactId>collector-openapi</artifactId> | ||
| <version>1.3.2</version> | ||
| <exclusions> | ||
| <exclusion> | ||
| <groupId>org.eclipse.jetty</groupId> | ||
| <artifactId>jetty-http</artifactId> | ||
| </exclusion> | ||
| <exclusion> | ||
| <groupId>org.eclipse.jetty</groupId> | ||
| <artifactId>jetty-util</artifactId> | ||
| </exclusion> | ||
| <exclusion> | ||
| <groupId>org.glassfish.jersey.inject</groupId> | ||
| <artifactId>jersey-hk2</artifactId> | ||
| </exclusion> | ||
| </exclusions> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.iotdb</groupId> | ||
| <artifactId>node-commons</artifactId> | ||
| <version>1.3.2</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.iotdb</groupId> | ||
| <artifactId>service-rpc</artifactId> | ||
| <version>1.3.2</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.iotdb</groupId> | ||
| <artifactId>pipe-api</artifactId> | ||
| <version>1.3.2</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>jakarta.servlet</groupId> | ||
| <artifactId>jakarta.servlet-api</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>jakarta.ws.rs</groupId> | ||
| <artifactId>jakarta.ws.rs-api</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.slf4j</groupId> | ||
| <artifactId>slf4j-api</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.eclipse.jetty</groupId> | ||
| <artifactId>jetty-http</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.eclipse.jetty</groupId> | ||
| <artifactId>jetty-util</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.eclipse.jetty</groupId> | ||
| <artifactId>jetty-server</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.eclipse.jetty</groupId> | ||
| <artifactId>jetty-servlet</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.glassfish.jersey.containers</groupId> | ||
| <artifactId>jersey-container-servlet-core</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.glassfish.jersey.inject</groupId> | ||
| <artifactId>jersey-hk2</artifactId> | ||
| </dependency> | ||
| </dependencies> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-dependency-plugin</artifactId> | ||
| <configuration> | ||
| <ignoredDependencies> | ||
| <!-- For some reason the plugin complains if this artifact is included --> | ||
| <ignoredDependency>org.eclipse.jetty:jetty-http</ignoredDependency> | ||
| <ignoredDependency>org.eclipse.jetty:jetty-util</ignoredDependency> | ||
| <ignoredDependency>org.glassfish.jersey.inject:jersey-hk2</ignoredDependency> | ||
| </ignoredDependencies> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> |
93 changes: 93 additions & 0 deletions
93
iotdb-collector/collector-core/src/main/java/org/apache/iotdb/collector/Application.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| * 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.iotdb.collector; | ||
|
|
||
| import org.apache.iotdb.collector.config.Configuration; | ||
| import org.apache.iotdb.collector.service.ApiService; | ||
| import org.apache.iotdb.collector.service.IService; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.util.LinkedList; | ||
|
|
||
| public class Application { | ||
|
|
||
| private static final Logger LOGGER = LoggerFactory.getLogger(Application.class); | ||
|
|
||
| private final Configuration configuration = new Configuration(); | ||
| private final LinkedList<IService> services = new LinkedList<>(); | ||
|
|
||
| private Application() { | ||
| services.add(new ApiService()); | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| LOGGER.info("[Application] Starting ..."); | ||
| final long startTime = System.currentTimeMillis(); | ||
|
|
||
| final Application application = new Application(); | ||
|
|
||
| application.logAllOptions(); | ||
| application.registerShutdownHook(); | ||
| application.startServices(); | ||
|
|
||
| LOGGER.info( | ||
| "[Application] Successfully started in {}ms", System.currentTimeMillis() - startTime); | ||
| } | ||
|
|
||
| private void logAllOptions() { | ||
| configuration.logAllOptions(); | ||
| } | ||
|
|
||
| private void registerShutdownHook() { | ||
| Runtime.getRuntime() | ||
| .addShutdownHook( | ||
| new Thread( | ||
| () -> { | ||
| LOGGER.warn("[Application] Exiting ..."); | ||
|
|
||
| for (final IService service : services) { | ||
| try { | ||
| service.stop(); | ||
| } catch (final Exception e) { | ||
| LOGGER.warn( | ||
| "[{}] Unexpected exception occurred when stopping: {}", | ||
| service.name(), | ||
| e.getMessage(), | ||
| e); | ||
| } | ||
| } | ||
|
|
||
| LOGGER.warn( | ||
| "[Application] JVM report: total memory {}, free memory {}, used memory {}", | ||
| Runtime.getRuntime().totalMemory(), | ||
| Runtime.getRuntime().freeMemory(), | ||
| Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()); | ||
| LOGGER.warn("[Application] Exited."); | ||
| })); | ||
| } | ||
|
|
||
| private void startServices() { | ||
| for (final IService service : services) { | ||
| service.start(); | ||
| } | ||
| } | ||
| } |
50 changes: 50 additions & 0 deletions
50
...llector/collector-core/src/main/java/org/apache/iotdb/collector/agent/CollectorAgent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * 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.iotdb.collector.agent; | ||
|
|
||
| import org.apache.iotdb.collector.agent.executor.CollectorTaskExecutorAgent; | ||
| import org.apache.iotdb.collector.agent.plugin.CollectorPluginAgent; | ||
| import org.apache.iotdb.collector.agent.task.CollectorTaskAgent; | ||
|
|
||
| public class CollectorAgent { | ||
|
|
||
| private final CollectorTaskAgent collectorTaskAgent = CollectorTaskAgent.instance(); | ||
| private final CollectorTaskExecutorAgent collectorTaskExecutorAgent = | ||
| CollectorTaskExecutorAgent.instance(); | ||
| private final CollectorPluginAgent collectorPluginAgent = CollectorPluginAgent.instance(); | ||
|
|
||
| private CollectorAgent() {} | ||
|
|
||
| public static CollectorTaskAgent task() { | ||
| return CollectorAgentHolder.INSTANCE.collectorTaskAgent; | ||
| } | ||
|
|
||
| public static CollectorTaskExecutorAgent executor() { | ||
| return CollectorAgentHolder.INSTANCE.collectorTaskExecutorAgent; | ||
| } | ||
|
|
||
| public static CollectorPluginAgent plugin() { | ||
| return CollectorAgentHolder.INSTANCE.collectorPluginAgent; | ||
| } | ||
|
|
||
| private static class CollectorAgentHolder { | ||
| private static final CollectorAgent INSTANCE = new CollectorAgent(); | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
...-core/src/main/java/org/apache/iotdb/collector/agent/collect/CollectorEventCollector.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * 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.iotdb.collector.agent.collect; | ||
|
|
||
| import org.apache.iotdb.pipe.api.collector.EventCollector; | ||
| import org.apache.iotdb.pipe.api.event.Event; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.util.concurrent.BlockingQueue; | ||
|
|
||
| public class CollectorEventCollector implements EventCollector { | ||
|
|
||
| private static final Logger LOGGER = LoggerFactory.getLogger(CollectorEventCollector.class); | ||
|
|
||
| private final BlockingQueue<Event> pendingQueue; | ||
|
|
||
| public CollectorEventCollector(final BlockingQueue<Event> pendingQueue) { | ||
| this.pendingQueue = pendingQueue; | ||
| } | ||
|
|
||
| @Override | ||
| public void collect(final Event event) { | ||
| try { | ||
| pendingQueue.put(event); | ||
| } catch (final InterruptedException e) { | ||
| LOGGER.warn("collect event failed because {}", e.getMessage(), e); | ||
| } | ||
| } | ||
| } |
68 changes: 68 additions & 0 deletions
68
...c/main/java/org/apache/iotdb/collector/agent/executor/CollectorProcessorTaskExecutor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * 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.iotdb.collector.agent.executor; | ||
|
|
||
| import org.apache.iotdb.collector.agent.task.CollectorTask; | ||
| import org.apache.iotdb.commons.concurrent.IoTDBThreadPoolFactory; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.concurrent.ExecutorService; | ||
|
|
||
| public class CollectorProcessorTaskExecutor extends CollectorTaskExecutor { | ||
|
|
||
| private static final Logger LOGGER = | ||
| LoggerFactory.getLogger(CollectorProcessorTaskExecutor.class); | ||
|
|
||
| private static final Map<String, ExecutorService> PROCESSOR_EXECUTOR = new ConcurrentHashMap<>(); | ||
| private static final Map<String, CollectorTask> PROCESSOR_TASK_MAP = new ConcurrentHashMap<>(); | ||
|
|
||
| public boolean validateIfAbsent(final String taskId) { | ||
| return !PROCESSOR_EXECUTOR.containsKey(taskId) && !PROCESSOR_TASK_MAP.containsKey(taskId); | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<ExecutorService> getExecutor(final String taskId) { | ||
| return Optional.of( | ||
| IoTDBThreadPoolFactory.newSingleThreadExecutor("collector-processor-executor-" + taskId)); | ||
| } | ||
|
|
||
| @Override | ||
| public void recordExecution( | ||
| final CollectorTask collectorTask, final ExecutorService executorService) { | ||
| final String taskId = collectorTask.getTaskId(); | ||
| PROCESSOR_EXECUTOR.putIfAbsent(taskId, executorService); | ||
| PROCESSOR_TASK_MAP.putIfAbsent(taskId, collectorTask); | ||
|
|
||
| LOGGER.info("register collector processor task {}", taskId); | ||
| } | ||
|
|
||
| @Override | ||
| public void eraseExecution(final String taskId) { | ||
| PROCESSOR_TASK_MAP.remove(taskId).stop(); | ||
| PROCESSOR_EXECUTOR.remove(taskId).shutdownNow(); | ||
|
|
||
| LOGGER.info("deregister collector processor task {}", taskId); | ||
Check failureCode scanning / CodeQL Log Injection High
This log entry depends on a
user-provided value Error loading related location Loading |
||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / CodeQL
Log Injection High