Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions iotdb-collector/collector-core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-collector</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<artifactId>collector-core</artifactId>
<name>IoTDB: Collector: Core</name>
<dependencies>
<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>collector-openapi</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>service-rpc</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>pipe-api</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>node-commons</artifactId>
<version>2.0.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-common</artifactId>
</exclusion>
<exclusion>
<groupId>net.minidev</groupId>
<artifactId>json-smart</artifactId>
</exclusion>
</exclusions>
</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-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>
</dependencies>
</project>
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();
}
}
}
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();
}
}
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);
}
}
}
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);
}
}
Loading
Loading