github-advanced-security[bot] commented on code in PR #48:
URL: https://github.com/apache/iotdb-extras/pull/48#discussion_r1977354640
##
iotdb-collector/collector-core/src/main/java/org/apache/iotdb/collector/runtime/task/TaskRuntime.java:
##
@@ -0,0 +1,138 @@
+/*
+ * 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.runtime.task;
+
+import org.apache.iotdb.collector.runtime.task.def.ProcessorTask;
+import org.apache.iotdb.collector.runtime.task.def.PushSourceTask;
+import org.apache.iotdb.collector.runtime.task.def.SinkTask;
+import org.apache.iotdb.collector.runtime.task.def.SourceTask;
+import org.apache.iotdb.collector.runtime.task.def.TaskRepository;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.core.Response;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class TaskRuntime {
+
+ private static final Logger LOGGER =
LoggerFactory.getLogger(TaskRuntime.class);
+
+ private static final Map TASK_REPOSITORY_MAP = new
ConcurrentHashMap<>();
+
+ public Response createTask(
+ final String taskId,
+ final Map sourceAttribute,
+ final Map processorAttribute,
+ final Map sinkAttribute) {
+try {
+ if (validateTaskIsExist(taskId)) {
+return Response.status(Response.Status.CONFLICT)
+.entity(String.format("task %s has existed", taskId))
+.build();
+ }
+
+ final SinkTask sinkTask = new SinkTask(sinkAttribute);
+ final ProcessorTask processorTask = new
ProcessorTask(processorAttribute, sinkTask);
+ final SourceTask sourceTask = new PushSourceTask(taskId,
sourceAttribute, processorTask);
+ final TaskRepository taskRepository = new TaskRepository(sourceTask,
processorTask, sinkTask);
+
+ TASK_REPOSITORY_MAP.put(taskId, taskRepository);
+ taskRepository.create();
+
+ LOGGER.info("Successfully created task {}", taskId);
+ return Response.status(Response.Status.CREATED)
+ .entity(String.format("Successfully created task %s", taskId))
+ .build();
+} catch (final Exception e) {
+ LOGGER.warn("Failed to create task", e);
+ return Response.serverError()
+ .entity(String.format("Failed to create task %s, because %s",
taskId, e.getMessage()))
+ .build();
+}
+ }
+
+ public boolean alterTask() {
+return true;
+ }
+
+ public Response startTask(final String taskId) {
+if (!validateTaskIsExist(taskId)) {
+ return Response.status(Response.Status.NOT_FOUND)
+ .entity(String.format("task %s not found", taskId))
+ .build();
+}
+
+TASK_REPOSITORY_MAP.get(taskId).start();
+LOGGER.info("Task {} started successfully", taskId);
+return Response.status(Response.Status.OK)
+.entity(String.format("task %s start successfully", taskId))
+.build();
+ }
+
+ public Response stopTask(final String taskId) {
+if (!validateTaskIsExist(taskId)) {
+ return Response.status(Response.Status.NOT_FOUND)
+ .entity(String.format("task %s not found", taskId))
+ .build();
+}
+
+try {
+ final TaskRepository taskRepository = TASK_REPOSITORY_MAP.get(taskId);
+ if (taskRepository != null) {
+taskRepository.stop();
+ }
+} catch (final Exception e) {
+ LOGGER.warn("Failed to stop task", e);
+ return Response.serverError()
+ .entity(String.format("Failed to stop task %s, because %s", taskId,
e.getMessage()))
+ .build();
+}
+
+LOGGER.info("Task {} stopped successfully", taskId);
+return Response.status(Response.Status.OK)
+.entity(String.format("task %s stop successfully", taskId))
+.build();
+ }
+
+ public Response dropTask(final String taskId) {
+if (!validateTaskIsExist(taskId)) {
+ return Response.status(Response.Status.NOT_FOUND)
+ .entity(String.format("task %s not found", taskId))
+ .build();
+}
+
+TASK_REPOSITORY_MAP.remove(taskId).drop();
+LOGGER.info("Task {} dropped successfully", taskId);
Review Comment:
## Log Injection
This log entry depends on a [user-provided value](1).