From 7500084fe063ecdc238508445ad269bc2fade596 Mon Sep 17 00:00:00 2001 From: Zhiguo Wu Date: Thu, 20 Jun 2024 17:04:44 +0800 Subject: [PATCH] BIGTOP-4146: Reorganize task log files --- .gitignore | 1 + .../executor/AbstractCommandExecutor.java | 12 --- .../executor/ComponentCommandExecutor.java | 2 +- .../scheduler/DefaultCommandScheduler.java | 4 + .../src/main/resources/logback-spring.xml | 76 +++++++---------- .../entity/command/CommandLogMessage.java | 45 ----------- .../message/serializer/KryoPoolHolder.java | 2 - .../bigtop/manager/dao/entity/CommandLog.java | 81 ------------------- .../dao/repository/CommandLogRepository.java | 28 ------- .../stage/runner/AbstractStageRunner.java | 2 + .../service/impl/CommandLogServiceImpl.java | 40 +-------- .../server/ws/ServerWebSocketHandler.java | 9 --- .../src/main/resources/application.yml | 8 +- .../src/main/resources/logback-spring.xml | 43 ++-------- .../stack/bigtop/v3_3_0/hdfs/HdfsSetup.java | 13 ++- .../v3_3_0/zookeeper/ZookeeperSetup.java | 3 +- .../stack/common/log/TaskLogWriter.java | 66 --------------- .../stack/common/repo/AptPackageManager.java | 7 +- .../stack/common/repo/DnfPackageManager.java | 7 +- .../stack/common/repo/YumPackageManager.java | 7 +- .../stack/common/utils/BaseParams.java | 3 +- .../stack/common/utils/LocalSettings.java | 3 +- .../stack/common/utils/PropertiesUtils.java | 9 +-- .../manager/stack/common/utils/XmlUtils.java | 7 +- .../common/utils/linux/LinuxAccountUtils.java | 13 ++- .../common/utils/linux/LinuxFileUtils.java | 27 +++---- .../common/utils/linux/LinuxOSUtils.java | 9 +-- .../common/utils/template/BaseTemplate.java | 13 ++- .../common/utils/template/TemplateUtils.java | 5 +- .../stack/core/executor/StackExecutor.java | 14 +--- .../manager/stack/core/hook/AbstractHook.java | 3 +- .../nop/v1_0_0/kafka/KafkaBrokerScript.java | 13 ++- .../zookeeper/ZookeeperClientScript.java | 5 +- .../zookeeper/ZookeeperServerScript.java | 11 ++- 34 files changed, 121 insertions(+), 470 deletions(-) delete mode 100644 bigtop-manager-common/src/main/java/org/apache/bigtop/manager/common/message/entity/command/CommandLogMessage.java delete mode 100644 bigtop-manager-dao/src/main/java/org/apache/bigtop/manager/dao/entity/CommandLog.java delete mode 100644 bigtop-manager-dao/src/main/java/org/apache/bigtop/manager/dao/repository/CommandLogRepository.java delete mode 100644 bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/log/TaskLogWriter.java diff --git a/.gitignore b/.gitignore index aa3e64d78..e99a1b643 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,7 @@ build/ ### Log ### logs +tasklogs *.log npm-debug.log* yarn-debug.log* diff --git a/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/executor/AbstractCommandExecutor.java b/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/executor/AbstractCommandExecutor.java index 8beffd951..e54bd6149 100644 --- a/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/executor/AbstractCommandExecutor.java +++ b/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/executor/AbstractCommandExecutor.java @@ -20,7 +20,6 @@ import org.apache.bigtop.manager.agent.holder.SpringContextHolder; import org.apache.bigtop.manager.common.constants.MessageConstants; -import org.apache.bigtop.manager.common.message.entity.command.CommandLogMessage; import org.apache.bigtop.manager.common.message.entity.command.CommandRequestMessage; import org.apache.bigtop.manager.common.message.entity.command.CommandResponseMessage; import org.apache.bigtop.manager.common.shell.ShellResult; @@ -68,15 +67,4 @@ protected void doExecuteOnDevMode() { } protected abstract void doExecute(); - - protected void writeBackCommandLog(String log) { - CommandLogMessage logMessage = new CommandLogMessage(); - logMessage.setLog(log); - logMessage.setMessageId(commandRequestMessage.getMessageId()); - logMessage.setHostname(commandRequestMessage.getHostname()); - logMessage.setTaskId(commandRequestMessage.getTaskId()); - logMessage.setStageId(commandRequestMessage.getStageId()); - logMessage.setJobId(commandRequestMessage.getJobId()); - SpringContextHolder.getAgentWebSocket().sendMessage(logMessage); - } } diff --git a/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/executor/ComponentCommandExecutor.java b/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/executor/ComponentCommandExecutor.java index 6d4fb0434..c7af47431 100644 --- a/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/executor/ComponentCommandExecutor.java +++ b/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/executor/ComponentCommandExecutor.java @@ -49,7 +49,7 @@ public void doExecute() { CommandPayload commandPayload = JsonUtils.readFromString(commandRequestMessage.getMessagePayload(), CommandPayload.class); log.info("[agent executeTask] taskEvent is: {}", commandRequestMessage); - ShellResult shellResult = StackExecutor.execute(commandPayload, this::writeBackCommandLog); + ShellResult shellResult = StackExecutor.execute(commandPayload); commandResponseMessage.setCode(shellResult.getExitCode()); commandResponseMessage.setResult(shellResult.getResult()); diff --git a/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/scheduler/DefaultCommandScheduler.java b/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/scheduler/DefaultCommandScheduler.java index 230a62e41..55eb8ba1d 100644 --- a/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/scheduler/DefaultCommandScheduler.java +++ b/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/scheduler/DefaultCommandScheduler.java @@ -22,6 +22,7 @@ import org.apache.bigtop.manager.agent.executor.CommandExecutors; import org.apache.bigtop.manager.common.message.entity.command.CommandRequestMessage; +import org.slf4j.MDC; import org.springframework.stereotype.Component; import lombok.extern.slf4j.Slf4j; @@ -45,10 +46,13 @@ public class DefaultCommandScheduler implements CommandScheduler { public void submit(CommandRequestMessage message) { queue.offer(() -> { try { + MDC.put("taskId", message.getTaskId().toString()); CommandExecutor commandExecutor = CommandExecutors.getCommandExecutor(message.getCommandMessageType()); commandExecutor.execute(message); } catch (Exception e) { log.error("Error when running command", e); + } finally { + MDC.clear(); } }); } diff --git a/bigtop-manager-agent/src/main/resources/logback-spring.xml b/bigtop-manager-agent/src/main/resources/logback-spring.xml index 5f50ee165..dbde0dbbe 100644 --- a/bigtop-manager-agent/src/main/resources/logback-spring.xml +++ b/bigtop-manager-agent/src/main/resources/logback-spring.xml @@ -19,76 +19,58 @@ --> - - + + - [%-5level] %date{yyyy-MM-dd HH:mm:ss.SSS Z} [%thread] %logger{96}:[%line] - %msg%n + [%-5level] %date{yyyy-MM-dd HH:mm:ss.SSS Z} [%thread] %logger{1}:[%line] - %m%n UTF-8 - - ${log.base}/ws.log - - ${log.base}/ws.%d{yyyy-MM-dd}.%i.log - 30 - 200MB - 10GB - true - - - [%-5level] %date{yyyy-MM-dd HH:mm:ss.SSS Z} [%thread] %logger{96}:[%line] - %msg%n - UTF-8 - - - - ${log.base}/bigtop-manager-stack.log + + ${log.base}/bigtop-manager-agent.log - ${log.base}/bigtop-manager-stack.%d{yyyy-MM-dd}.%i.log + ${log.base}/bigtop-manager-agent.%d{yyyy-MM-dd}.%i.log 30 200MB 10GB true - [%-5level] %date{yyyy-MM-dd HH:mm:ss.SSS Z} [%thread] %logger{96}:[%line] - %msg%n + [%-5level] %date{yyyy-MM-dd HH:mm:ss.SSS Z} [%thread] %logger{1}:[%line] - %m%n UTF-8 - - ${log.base}/bigtop-manager-agent.log + + - logger.contains("org.apache.bigtop.manager.stack") + mdc.get("taskId") != null - DENY - ACCEPT + ACCEPT + DENY - - ${log.base}/bigtop-manager-agent.%d{yyyy-MM-dd}.%i.log - 30 - 200MB - 10GB - true - - - [%-5level] %date{yyyy-MM-dd HH:mm:ss.SSS Z} [%thread] %logger{96}:[%line] - %msg%n - UTF-8 - + + taskId + 0 + + + + tasklogs/task-${taskId}.log + + [%-5level] %date{yyyy-MM-dd HH:mm:ss.SSS Z} - %m%n + UTF-8 + + true + + - - - - - - - - - - + + + diff --git a/bigtop-manager-common/src/main/java/org/apache/bigtop/manager/common/message/entity/command/CommandLogMessage.java b/bigtop-manager-common/src/main/java/org/apache/bigtop/manager/common/message/entity/command/CommandLogMessage.java deleted file mode 100644 index a092d9648..000000000 --- a/bigtop-manager-common/src/main/java/org/apache/bigtop/manager/common/message/entity/command/CommandLogMessage.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 - * - * https://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.bigtop.manager.common.message.entity.command; - -import org.apache.bigtop.manager.common.message.entity.BaseMessage; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; -import lombok.ToString; - -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -@NoArgsConstructor -@AllArgsConstructor -public class CommandLogMessage extends BaseMessage { - - private String log; - - private String hostname; - - private Long jobId; - - private Long stageId; - - private Long taskId; -} diff --git a/bigtop-manager-common/src/main/java/org/apache/bigtop/manager/common/message/serializer/KryoPoolHolder.java b/bigtop-manager-common/src/main/java/org/apache/bigtop/manager/common/message/serializer/KryoPoolHolder.java index e036967b0..b690d3793 100644 --- a/bigtop-manager-common/src/main/java/org/apache/bigtop/manager/common/message/serializer/KryoPoolHolder.java +++ b/bigtop-manager-common/src/main/java/org/apache/bigtop/manager/common/message/serializer/KryoPoolHolder.java @@ -23,7 +23,6 @@ import org.apache.bigtop.manager.common.message.entity.BaseRequestMessage; import org.apache.bigtop.manager.common.message.entity.BaseResponseMessage; import org.apache.bigtop.manager.common.message.entity.HeartbeatMessage; -import org.apache.bigtop.manager.common.message.entity.command.CommandLogMessage; import org.apache.bigtop.manager.common.message.entity.command.CommandMessageType; import org.apache.bigtop.manager.common.message.entity.command.CommandRequestMessage; import org.apache.bigtop.manager.common.message.entity.command.CommandResponseMessage; @@ -62,7 +61,6 @@ protected Kryo create() { kryo.register(HeartbeatMessage.class); kryo.register(CommandResponseMessage.class); kryo.register(CommandRequestMessage.class); - kryo.register(CommandLogMessage.class); // message pojo kryo.register(HostInfo.class); diff --git a/bigtop-manager-dao/src/main/java/org/apache/bigtop/manager/dao/entity/CommandLog.java b/bigtop-manager-dao/src/main/java/org/apache/bigtop/manager/dao/entity/CommandLog.java deleted file mode 100644 index 728bbff8c..000000000 --- a/bigtop-manager-dao/src/main/java/org/apache/bigtop/manager/dao/entity/CommandLog.java +++ /dev/null @@ -1,81 +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 - * - * https://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.bigtop.manager.dao.entity; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -import jakarta.persistence.Basic; -import jakarta.persistence.Column; -import jakarta.persistence.ConstraintMode; -import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.ForeignKey; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.Index; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.Lob; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; -import jakarta.persistence.TableGenerator; - -@Data -@EqualsAndHashCode(callSuper = true) -@Entity -@Table( - name = "command_log", - indexes = { - @Index(name = "idx_cl_job_id", columnList = "job_id"), - @Index(name = "idx_cl_stage_id", columnList = "stage_id"), - @Index(name = "idx_cl_task_id", columnList = "task_id") - }) -@TableGenerator( - name = "command_log_generator", - table = "sequence", - pkColumnName = "seq_name", - valueColumnName = "seq_count") -public class CommandLog extends BaseEntity { - - @Id - @GeneratedValue(strategy = GenerationType.TABLE, generator = "command_log_generator") - @Column(name = "id") - private Long id; - - @Lob - @Basic(fetch = FetchType.LAZY) - @Column(name = "\"log\"", length = 16777216) - private String log; - - @Column(name = "hostname") - private String hostname; - - @ManyToOne - @JoinColumn(name = "job_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) - private Job job; - - @ManyToOne - @JoinColumn(name = "stage_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) - private Stage stage; - - @ManyToOne - @JoinColumn(name = "task_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) - private Task task; -} diff --git a/bigtop-manager-dao/src/main/java/org/apache/bigtop/manager/dao/repository/CommandLogRepository.java b/bigtop-manager-dao/src/main/java/org/apache/bigtop/manager/dao/repository/CommandLogRepository.java deleted file mode 100644 index 65eb7062f..000000000 --- a/bigtop-manager-dao/src/main/java/org/apache/bigtop/manager/dao/repository/CommandLogRepository.java +++ /dev/null @@ -1,28 +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 - * - * https://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.bigtop.manager.dao.repository; - -import org.apache.bigtop.manager.dao.entity.CommandLog; - -import org.springframework.data.jpa.repository.JpaRepository; - -public interface CommandLogRepository extends JpaRepository { - - CommandLog findByTaskIdEquals(Long taskId); -} diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/stage/runner/AbstractStageRunner.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/stage/runner/AbstractStageRunner.java index 57f1563f5..d7c085bf0 100644 --- a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/stage/runner/AbstractStageRunner.java +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/stage/runner/AbstractStageRunner.java @@ -89,8 +89,10 @@ public void run() { boolean taskSuccess = res != null && res.getCode() == MessageConstants.SUCCESS_CODE; if (taskSuccess) { + commandLogService.onLogReceived(task.getId(), task.getHostname(), "Success!"); onTaskSuccess(task); } else { + commandLogService.onLogReceived(task.getId(), task.getHostname(), "Failed!"); onTaskFailure(task); } diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/CommandLogServiceImpl.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/CommandLogServiceImpl.java index 67d340e6f..945eb47d1 100644 --- a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/CommandLogServiceImpl.java +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/CommandLogServiceImpl.java @@ -18,10 +18,6 @@ */ package org.apache.bigtop.manager.server.service.impl; -import org.apache.bigtop.manager.dao.entity.CommandLog; -import org.apache.bigtop.manager.dao.entity.Task; -import org.apache.bigtop.manager.dao.repository.CommandLogRepository; -import org.apache.bigtop.manager.dao.repository.TaskRepository; import org.apache.bigtop.manager.server.service.CommandLogService; import org.apache.commons.collections4.CollectionUtils; @@ -30,7 +26,6 @@ import reactor.core.publisher.FluxSink; -import jakarta.annotation.Resource; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -39,12 +34,6 @@ @Service public class CommandLogServiceImpl implements CommandLogService { - @Resource - private TaskRepository taskRepository; - - @Resource - private CommandLogRepository commandLogRepository; - private final Map> taskSinks = new HashMap<>(); private final Map> logs = new HashMap<>(); @@ -60,16 +49,7 @@ public void registerSink(Long taskId, FluxSink sink) { } } else { // Task already completed, get logs from database - CommandLog commandLog = commandLogRepository.findByTaskIdEquals(taskId); - if (commandLog != null && commandLog.getLog() != null) { - list = List.of(commandLog.getLog().split("\n")); - for (String log : list) { - sink.next(log); - } - } else { - sink.next("Cannot find log for task: " + taskId + ", there might be something wrong."); - } - + sink.next("Task finished, please check the log details on agent machine."); sink.complete(); } } @@ -80,15 +60,6 @@ public void unregisterSink(Long taskId) { @Override public void onLogStarted(Long taskId, String hostname) { - Task task = taskRepository.getReferenceById(taskId); - - CommandLog commandLog = new CommandLog(); - commandLog.setHostname(hostname); - commandLog.setTask(task); - commandLog.setStage(task.getStage()); - commandLog.setJob(task.getJob()); - commandLogRepository.save(commandLog); - logs.put(taskId, new ArrayList<>()); } @@ -116,14 +87,5 @@ public void onLogEnded(Long taskId, String hostname) { } logs.remove(taskId); - if (CollectionUtils.isNotEmpty(list)) { - CommandLog commandLog = commandLogRepository.findByTaskIdEquals(taskId); - commandLog.setLog(String.join("\n", list)); - commandLogRepository.save(commandLog); - } - } - - public static void sink(Long taskId, FluxSink sink) { - sink.next("aaa"); } } diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/ws/ServerWebSocketHandler.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/ws/ServerWebSocketHandler.java index 1ad30c06d..b1c163cac 100644 --- a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/ws/ServerWebSocketHandler.java +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/ws/ServerWebSocketHandler.java @@ -21,11 +21,9 @@ import org.apache.bigtop.manager.common.message.entity.BaseMessage; import org.apache.bigtop.manager.common.message.entity.BaseRequestMessage; import org.apache.bigtop.manager.common.message.entity.HeartbeatMessage; -import org.apache.bigtop.manager.common.message.entity.command.CommandLogMessage; import org.apache.bigtop.manager.common.message.entity.command.CommandResponseMessage; import org.apache.bigtop.manager.common.message.entity.pojo.HostInfo; import org.apache.bigtop.manager.common.ws.AbstractBinaryWebSocketHandler; -import org.apache.bigtop.manager.server.service.CommandLogService; import org.springframework.stereotype.Component; import org.springframework.web.socket.BinaryMessage; @@ -35,7 +33,6 @@ import lombok.extern.slf4j.Slf4j; import jakarta.annotation.Nonnull; -import jakarta.annotation.Resource; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -48,9 +45,6 @@ @Component public class ServerWebSocketHandler extends AbstractBinaryWebSocketHandler { - @Resource - private CommandLogService commandLogService; - private final Map sessions = new ConcurrentHashMap<>(); public static final Map HEARTBEAT_MESSAGE_MAP = new ConcurrentHashMap<>(); @@ -93,9 +87,6 @@ private void handleMessage(WebSocketSession session, BaseMessage baseMessage) { handleHeartbeatMessage(session, heartbeatMessage); } else if (baseMessage instanceof CommandResponseMessage commandResponseMessage) { super.handleResponseMessage(commandResponseMessage); - } else if (baseMessage instanceof CommandLogMessage commandLogMessage) { - commandLogService.onLogReceived( - commandLogMessage.getTaskId(), commandLogMessage.getHostname(), commandLogMessage.getLog()); } else { log.error("Unrecognized message type: {}", baseMessage.getClass().getSimpleName()); } diff --git a/bigtop-manager-server/src/main/resources/application.yml b/bigtop-manager-server/src/main/resources/application.yml index 06c1babab..4a2aadf42 100644 --- a/bigtop-manager-server/src/main/resources/application.yml +++ b/bigtop-manager-server/src/main/resources/application.yml @@ -31,10 +31,10 @@ spring: main: banner-mode: log datasource: - driver-class-name: org.postgresql.Driver - url: jdbc:postgresql://localhost:5432/bigtop_manager - username: postgres - password: postgres + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3306/bigtop_manager + username: root + password: root type: com.zaxxer.hikari.HikariDataSource hikari: auto-commit: true diff --git a/bigtop-manager-server/src/main/resources/logback-spring.xml b/bigtop-manager-server/src/main/resources/logback-spring.xml index c4a1add70..4a42d8578 100644 --- a/bigtop-manager-server/src/main/resources/logback-spring.xml +++ b/bigtop-manager-server/src/main/resources/logback-spring.xml @@ -19,40 +19,18 @@ --> - - + + - [%-5level] %date{yyyy-MM-dd HH:mm:ss.SSS Z} [%thread] %logger{96}:[%line] - %msg%n + [%-5level] %date{yyyy-MM-dd HH:mm:ss.SSS Z} [%thread] %logger{1}:[%line] - %m%n UTF-8 - - ${log.base}/ws.log - - ${log.base}/ws.%d{yyyy-MM-dd}.%i.log - 30 - 200MB - 10GB - true - - - [%-5level] %date{yyyy-MM-dd HH:mm:ss.SSS Z} [%thread] %logger{96}:[%line] - %msg%n - UTF-8 - - - - + ${log.base}/bigtop-manager-server.log - - - logger.contains("org.apache.bigtop.manager.server.ws.ServerWebSocketHandler") - - DENY - ACCEPT - ${log.base}/bigtop-manager-server.%d{yyyy-MM-dd}.%i.log 30 @@ -61,20 +39,15 @@ true - [%-5level] %date{yyyy-MM-dd HH:mm:ss.SSS Z} [%thread] %logger{96}:[%line] - %msg%n + [%-5level] %date{yyyy-MM-dd HH:mm:ss.SSS Z} [%thread] %logger{1}:[%line] - %m%n UTF-8 - - - - - - + - - + + diff --git a/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/hdfs/HdfsSetup.java b/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/hdfs/HdfsSetup.java index 90466b5bc..0fca2f6e2 100644 --- a/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/hdfs/HdfsSetup.java +++ b/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/hdfs/HdfsSetup.java @@ -24,7 +24,6 @@ import org.apache.bigtop.manager.stack.bigtop.v3_3_0.kafka.KafkaParams; import org.apache.bigtop.manager.stack.common.enums.ConfigType; import org.apache.bigtop.manager.stack.common.exception.StackException; -import org.apache.bigtop.manager.stack.common.log.TaskLogWriter; import org.apache.bigtop.manager.stack.common.utils.linux.LinuxFileUtils; import org.apache.bigtop.manager.stack.common.utils.linux.LinuxOSUtils; @@ -47,7 +46,7 @@ public static ShellResult config(Params params) { } public static ShellResult config(Params params, String componentName) { - TaskLogWriter.info("starting HDFS config"); + log.info("starting HDFS config"); HdfsParams hdfsParams = (HdfsParams) params; String confDir = hdfsParams.confDir(); @@ -177,7 +176,7 @@ public static boolean isNameNodeFormatted(HdfsParams hdfsParams) { for (String nameNodeFormattedDir : hdfsParams.getNameNodeFormattedDirs()) { File file = new File(nameNodeFormattedDir); if (file.exists() && file.isDirectory()) { - TaskLogWriter.info(nameNodeFormattedDir + "exists. Namenode DFS already formatted"); + log.info("{} exists. Namenode DFS already formatted", nameNodeFormattedDir); isFormatted = true; } } @@ -196,14 +195,14 @@ public static boolean isNameNodeFormatted(HdfsParams hdfsParams) { for (String nameNodeDir : nameNodeDirs) { File file = new File(nameNodeDir); if (!file.exists()) { - TaskLogWriter.info("NameNode will not be formatted because the directory " + nameNodeDir - + " is missing or cannot be checked for content."); + log.info( + "NameNode will not be formatted because the directory {} is missing or cannot be checked for content.", + nameNodeDir); return true; } else { File[] files = file.listFiles(); if (files != null && files.length > 0) { - TaskLogWriter.info( - "NameNode will not be formatted since " + nameNodeDir + " exists and contains content"); + log.info("NameNode will not be formatted since {} exists and contains content", nameNodeDir); return true; } } diff --git a/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/zookeeper/ZookeeperSetup.java b/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/zookeeper/ZookeeperSetup.java index 380c3e536..57ee22044 100644 --- a/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/zookeeper/ZookeeperSetup.java +++ b/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/zookeeper/ZookeeperSetup.java @@ -22,7 +22,6 @@ import org.apache.bigtop.manager.common.utils.NetUtils; import org.apache.bigtop.manager.spi.stack.Params; import org.apache.bigtop.manager.stack.common.enums.ConfigType; -import org.apache.bigtop.manager.stack.common.log.TaskLogWriter; import org.apache.bigtop.manager.stack.common.utils.LocalSettings; import org.apache.bigtop.manager.stack.common.utils.linux.LinuxFileUtils; @@ -43,7 +42,7 @@ public class ZookeeperSetup { public static ShellResult config(Params params) { - TaskLogWriter.info("ZookeeperSetup config"); + log.info("ZookeeperSetup config"); ZookeeperParams zookeeperParams = (ZookeeperParams) params; String confDir = zookeeperParams.confDir(); diff --git a/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/log/TaskLogWriter.java b/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/log/TaskLogWriter.java deleted file mode 100644 index cff92658a..000000000 --- a/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/log/TaskLogWriter.java +++ /dev/null @@ -1,66 +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 - * - * https://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.bigtop.manager.stack.common.log; - -import java.time.ZoneId; -import java.time.ZoneOffset; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; -import java.util.function.Consumer; - -public class TaskLogWriter { - - private static Consumer writer; - - public static void setWriter(Consumer writer) { - TaskLogWriter.writer = writer; - } - - public static void info(String str) { - if (TaskLogWriter.writer != null) { - TaskLogWriter.writer.accept("[INFO ] " + getFormattedTime() + " - " + str); - } - } - - public static void warn(String str) { - if (TaskLogWriter.writer != null) { - TaskLogWriter.writer.accept("[WARN ] " + getFormattedTime() + " - " + str); - } - } - - public static void error(String str) { - if (TaskLogWriter.writer != null) { - TaskLogWriter.writer.accept("[ERROR] " + getFormattedTime() + " - " + str); - } - } - - private static String getFormattedTime() { - ZoneId zoneId = ZoneOffset.systemDefault(); - ZonedDateTime zonedDateTime = ZonedDateTime.now(zoneId); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); - String time = zonedDateTime.format(formatter); - String offset = zonedDateTime.getOffset().getId().replace("Z", "+00:00"); - - return time + " " + offset; - } - - public static void clearWriter() { - TaskLogWriter.writer = null; - } -} diff --git a/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/repo/AptPackageManager.java b/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/repo/AptPackageManager.java index 3b239e5be..cf2ebd3c8 100644 --- a/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/repo/AptPackageManager.java +++ b/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/repo/AptPackageManager.java @@ -23,7 +23,6 @@ import org.apache.bigtop.manager.spi.stack.PackageManager; import org.apache.bigtop.manager.stack.common.enums.PackageManagerType; import org.apache.bigtop.manager.stack.common.exception.StackException; -import org.apache.bigtop.manager.stack.common.log.TaskLogWriter; import com.google.auto.service.AutoService; import lombok.extern.slf4j.Slf4j; @@ -50,7 +49,7 @@ public ShellResult installPackage(Collection packages) { try { ShellResult output = ShellExecutor.execCommand(builderParameters, log::info); - TaskLogWriter.info("[AptPackageManager] [installPackage] output: " + output); + log.info("[AptPackageManager] [installPackage] output: {}", output); return output; } catch (IOException e) { throw new StackException(e); @@ -67,7 +66,7 @@ public ShellResult uninstallPackage(Collection packages) { try { ShellResult output = ShellExecutor.execCommand(builderParameters, log::info); - TaskLogWriter.info("[AptPackageManager] [uninstallPackage] output: " + output); + log.info("[AptPackageManager] [uninstallPackage] output: {}", output); return output; } catch (IOException e) { throw new StackException(e); @@ -82,7 +81,7 @@ public String listPackages() { try { ShellResult output = ShellExecutor.execCommand(builderParameters, log::info); - TaskLogWriter.info("[AptPackageManager] [listPackages] output: " + output); + log.info("[AptPackageManager] [listPackages] output: {}", output); return output.getOutput(); } catch (IOException e) { throw new StackException(e); diff --git a/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/repo/DnfPackageManager.java b/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/repo/DnfPackageManager.java index a800da383..59a5fb88e 100644 --- a/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/repo/DnfPackageManager.java +++ b/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/repo/DnfPackageManager.java @@ -23,7 +23,6 @@ import org.apache.bigtop.manager.spi.stack.PackageManager; import org.apache.bigtop.manager.stack.common.enums.PackageManagerType; import org.apache.bigtop.manager.stack.common.exception.StackException; -import org.apache.bigtop.manager.stack.common.log.TaskLogWriter; import com.google.auto.service.AutoService; import lombok.extern.slf4j.Slf4j; @@ -49,7 +48,7 @@ public ShellResult installPackage(Collection packages) { try { ShellResult output = ShellExecutor.execCommand(builderParameters, log::info); - TaskLogWriter.info("[DnfPackageManager] [installPackage] output: " + output); + log.info("[DnfPackageManager] [installPackage] output: {}", output); return output; } catch (IOException e) { throw new StackException(e); @@ -66,7 +65,7 @@ public ShellResult uninstallPackage(Collection packages) { try { ShellResult output = ShellExecutor.execCommand(builderParameters, log::info); - TaskLogWriter.info("[DnfPackageManager] [uninstallPackage] output: " + output); + log.info("[DnfPackageManager] [uninstallPackage] output: {}", output); return output; } catch (IOException e) { throw new StackException(e); @@ -81,7 +80,7 @@ public String listPackages() { try { ShellResult output = ShellExecutor.execCommand(builderParameters, log::info); - TaskLogWriter.info("[DnfPackageManager] [listPackages] output: " + output); + log.info("[DnfPackageManager] [listPackages] output: {}", output); return output.getOutput(); } catch (IOException e) { throw new StackException(e); diff --git a/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/repo/YumPackageManager.java b/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/repo/YumPackageManager.java index acbee9cbf..2df789cf4 100644 --- a/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/repo/YumPackageManager.java +++ b/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/repo/YumPackageManager.java @@ -23,7 +23,6 @@ import org.apache.bigtop.manager.spi.stack.PackageManager; import org.apache.bigtop.manager.stack.common.enums.PackageManagerType; import org.apache.bigtop.manager.stack.common.exception.StackException; -import org.apache.bigtop.manager.stack.common.log.TaskLogWriter; import com.google.auto.service.AutoService; import lombok.extern.slf4j.Slf4j; @@ -49,7 +48,7 @@ public ShellResult installPackage(Collection packages) { try { ShellResult output = ShellExecutor.execCommand(builderParameters, log::info); - TaskLogWriter.info("[RpmPackageManager] [installPackage] output: " + output); + log.info("[RpmPackageManager] [installPackage] output: {}", output); return output; } catch (IOException e) { throw new StackException(e); @@ -66,7 +65,7 @@ public ShellResult uninstallPackage(Collection packages) { try { ShellResult output = ShellExecutor.execCommand(builderParameters, log::info); - TaskLogWriter.info("[RpmPackageManager] [uninstallPackage] output: " + output); + log.info("[RpmPackageManager] [uninstallPackage] output: {}", output); return output; } catch (IOException e) { throw new StackException(e); @@ -81,7 +80,7 @@ public String listPackages() { try { ShellResult output = ShellExecutor.execCommand(builderParameters, log::info); - TaskLogWriter.info("[RpmPackageManager] [listPackages] output: " + output); + log.info("[RpmPackageManager] [listPackages] output: {}", output); return output.getOutput(); } catch (IOException e) { throw new StackException(e); diff --git a/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/BaseParams.java b/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/BaseParams.java index 34681e4c0..9bf2d6001 100644 --- a/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/BaseParams.java +++ b/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/BaseParams.java @@ -25,7 +25,6 @@ import org.apache.bigtop.manager.common.utils.os.OSDetection; import org.apache.bigtop.manager.spi.stack.Params; import org.apache.bigtop.manager.stack.common.annotations.GlobalParams; -import org.apache.bigtop.manager.stack.common.log.TaskLogWriter; import org.apache.commons.lang3.StringUtils; @@ -67,7 +66,7 @@ protected BaseParams(CommandPayload commandPayload) { globalParamsMap.putAll(invoke); } } catch (Exception e) { - TaskLogWriter.warn("Get " + declaredMethod + " Params error: " + e.getMessage()); + log.warn("Get {} Params error", declaredMethod, e); } } globalParamsMap.remove("content"); diff --git a/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/LocalSettings.java b/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/LocalSettings.java index fa04b2219..5d444651d 100644 --- a/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/LocalSettings.java +++ b/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/LocalSettings.java @@ -24,7 +24,6 @@ import org.apache.bigtop.manager.common.message.entity.pojo.ComponentInfo; import org.apache.bigtop.manager.common.message.entity.pojo.RepoInfo; import org.apache.bigtop.manager.common.utils.JsonUtils; -import org.apache.bigtop.manager.stack.common.log.TaskLogWriter; import com.fasterxml.jackson.core.type.TypeReference; import lombok.extern.slf4j.Slf4j; @@ -58,7 +57,7 @@ public static Map configurations(String service, String type) { } } } catch (Exception e) { - TaskLogWriter.warn(CacheFiles.CONFIGURATIONS_INFO + " parse error: " + e.getMessage()); + log.warn("{} parse error", CacheFiles.CONFIGURATIONS_INFO, e); } return configDataMap; diff --git a/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/PropertiesUtils.java b/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/PropertiesUtils.java index 23738bce7..14348da06 100644 --- a/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/PropertiesUtils.java +++ b/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/PropertiesUtils.java @@ -19,7 +19,6 @@ package org.apache.bigtop.manager.stack.common.utils; import org.apache.bigtop.manager.stack.common.exception.StackException; -import org.apache.bigtop.manager.stack.common.log.TaskLogWriter; import lombok.extern.slf4j.Slf4j; @@ -48,7 +47,7 @@ public static Map readProperties(String fileName) { try { properties.load(new FileReader(fileName, StandardCharsets.UTF_8)); } catch (IOException e) { - TaskLogWriter.error("readProperties error: " + e.getMessage()); + log.error("readProperties error", e); throw new StackException(e); } @@ -74,7 +73,7 @@ public static void writeProperties(String fileName, Map configMa os.flush(); os.close(); } catch (Exception e) { - TaskLogWriter.error("writeProperties error: " + e.getMessage()); + log.error("writeProperties error", e); } } @@ -93,11 +92,11 @@ public static void writeProperties(String fileName, List> co properties.setProperty(String.valueOf(map.get("name")), String.valueOf(map.get("value"))); } - TaskLogWriter.info("writeProperties: " + properties); + log.info("writeProperties: {}", properties); try { properties.store(new FileWriter(fileName, StandardCharsets.UTF_8), "Generated by Apache BigTop Manager."); } catch (IOException e) { - TaskLogWriter.error("writeProperties error: " + e.getMessage()); + log.error("writeProperties error", e); throw new StackException(e); } } diff --git a/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/XmlUtils.java b/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/XmlUtils.java index 4d55d845b..e007beafb 100644 --- a/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/XmlUtils.java +++ b/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/XmlUtils.java @@ -19,7 +19,6 @@ package org.apache.bigtop.manager.stack.common.utils; import org.apache.bigtop.manager.stack.common.exception.StackException; -import org.apache.bigtop.manager.stack.common.log.TaskLogWriter; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -67,7 +66,7 @@ public static void writeXml(String fileName, Map configMap) { Element configuration = document.createElement("configuration"); for (Map.Entry entry : configMap.entrySet()) { - TaskLogWriter.info(entry.getKey() + " " + entry.getValue()); + log.info("{} {}", entry.getKey(), entry.getValue()); Element property = document.createElement("property"); Element name = document.createElement("name"); @@ -90,9 +89,9 @@ public static void writeXml(String fileName, Map configMap) { tf.setOutputProperty(OutputKeys.INDENT, "yes"); tf.transform(new DOMSource(document), new StreamResult(new File(fileName))); - TaskLogWriter.info("writeXml " + fileName + " success"); + log.info("writeXml {} success", fileName); } catch (TransformerException e) { - TaskLogWriter.error("writeXml error: " + e.getLocationAsString()); + log.error("writeXml error", e); throw new StackException(e); } } diff --git a/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/linux/LinuxAccountUtils.java b/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/linux/LinuxAccountUtils.java index 1ed58c2de..1e9467fc8 100644 --- a/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/linux/LinuxAccountUtils.java +++ b/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/linux/LinuxAccountUtils.java @@ -21,7 +21,6 @@ import org.apache.bigtop.manager.common.shell.ShellExecutor; import org.apache.bigtop.manager.common.shell.ShellResult; import org.apache.bigtop.manager.stack.common.exception.StackException; -import org.apache.bigtop.manager.stack.common.log.TaskLogWriter; import org.apache.commons.lang3.StringUtils; @@ -66,7 +65,7 @@ public static void userDel(String user) { try { ShellResult output = ShellExecutor.execCommand(builderParameters); - TaskLogWriter.info("[AccountGroupUtils] [userDel] output: " + output); + log.info("[AccountGroupUtils] [userDel] output: {}", output); } catch (IOException e) { throw new StackException(e); } @@ -154,7 +153,7 @@ public static void userAdd( try { ShellResult output = ShellExecutor.execCommand(builderParameters); - TaskLogWriter.info("[AccountGroupUtils] [userAdd] output: " + output); + log.info("[AccountGroupUtils] [userAdd] output: {}", output); } catch (IOException e) { throw new StackException(e); } @@ -180,7 +179,7 @@ public static void groupDel(String group) { try { ShellResult output = ShellExecutor.execCommand(builderParameters); - TaskLogWriter.info("[AccountGroupUtils] [addGroup] output: " + output); + log.info("[AccountGroupUtils] [addGroup] output: {}", output); } catch (IOException e) { throw new StackException(e); } @@ -229,7 +228,7 @@ public static void groupAdd(String group, String gid, String password) { try { ShellResult output = ShellExecutor.execCommand(builderParameters); - TaskLogWriter.info("[AccountGroupUtils] [addGroup] output: " + output); + log.info("[AccountGroupUtils] [addGroup] output: {}", output); } catch (IOException e) { throw new StackException(e); } @@ -252,7 +251,7 @@ public static boolean isGroupExists(String group) { try { ShellResult output = ShellExecutor.execCommand(builderParameters); - TaskLogWriter.info("[AccountGroupUtils] [checkIfExistsGroup] output: " + output); + log.info("[AccountGroupUtils] [checkIfExistsGroup] output: {}", output); return output.getExitCode() == 0; } catch (IOException e) { throw new StackException(e); @@ -275,7 +274,7 @@ public static boolean isUserExists(String user) { try { ShellResult output = ShellExecutor.execCommand(builderParameters); - TaskLogWriter.info("[AccountGroupUtils] [checkIfExistsUser] output: " + output); + log.info("[AccountGroupUtils] [checkIfExistsUser] output: {}", output); return output.getExitCode() == 0; } catch (IOException e) { throw new StackException(e); diff --git a/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/linux/LinuxFileUtils.java b/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/linux/LinuxFileUtils.java index ed524ae67..028be6eea 100644 --- a/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/linux/LinuxFileUtils.java +++ b/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/linux/LinuxFileUtils.java @@ -22,7 +22,6 @@ import org.apache.bigtop.manager.common.utils.JsonUtils; import org.apache.bigtop.manager.common.utils.YamlUtils; import org.apache.bigtop.manager.stack.common.enums.ConfigType; -import org.apache.bigtop.manager.stack.common.log.TaskLogWriter; import org.apache.bigtop.manager.stack.common.utils.template.TemplateUtils; import org.apache.commons.lang3.StringUtils; @@ -73,7 +72,7 @@ public static void toFile( Object content, Object paramMap) { if (type == null || StringUtils.isBlank(filename) || content == null) { - TaskLogWriter.error("type, filename, content must not be null"); + log.error("type, filename, content must not be null"); return; } @@ -88,7 +87,7 @@ public static void toFile( JsonUtils.writeToFile(filename, content); break; case UNKNOWN: - TaskLogWriter.info("no need to write"); + log.info("no need to write"); break; } @@ -121,7 +120,7 @@ public static void toFileByTemplate( Object modelMap, Object paramMap) { if (StringUtils.isBlank(filename) || modelMap == null || StringUtils.isEmpty(template)) { - TaskLogWriter.error("type, filename, content, template must not be null"); + log.error("type, filename, content, template must not be null"); return; } TemplateUtils.map2CustomTemplate(template, filename, modelMap, paramMap); @@ -139,7 +138,7 @@ public static void toFileByTemplate( */ public static void updatePermissions(String dir, String permissions, boolean recursive) { if (StringUtils.isBlank(dir)) { - TaskLogWriter.error("dir must not be null"); + log.error("dir must not be null"); return; } permissions = StringUtils.isBlank(permissions) ? Constants.PERMISSION_644 : permissions; @@ -148,9 +147,9 @@ public static void updatePermissions(String dir, String permissions, boolean rec Set perms = PosixFilePermissions.fromString(permissions); try { Files.setPosixFilePermissions(path, perms); - TaskLogWriter.info("Permissions set successfully."); + log.info("Permissions set successfully."); } catch (IOException e) { - TaskLogWriter.error("[updatePermissions] error: " + e.getMessage()); + log.error("[updatePermissions] error", e); } // When is a directory, recursive update @@ -160,7 +159,7 @@ public static void updatePermissions(String dir, String permissions, boolean rec updatePermissions(dir + File.separator + subPath.getFileName(), permissions, true); } } catch (IOException e) { - TaskLogWriter.error("[updatePermissions] error: " + e.getMessage()); + log.error("[updatePermissions] error", e); } } } @@ -175,7 +174,7 @@ public static void updatePermissions(String dir, String permissions, boolean rec */ public static void updateOwner(String dir, String owner, String group, boolean recursive) { if (StringUtils.isBlank(dir)) { - TaskLogWriter.error("dir must not be null"); + log.error("dir must not be null"); return; } owner = StringUtils.isBlank(owner) ? "root" : owner; @@ -193,7 +192,7 @@ public static void updateOwner(String dir, String owner, String group, boolean r fileAttributeView.setOwner(userPrincipal); fileAttributeView.setGroup(groupPrincipal); } catch (IOException e) { - TaskLogWriter.error("[updateOwner] error: " + e.getMessage()); + log.error("[updateOwner] error", e); } // When it is a directory, recursively set the file owner @@ -203,7 +202,7 @@ public static void updateOwner(String dir, String owner, String group, boolean r updateOwner(dir + File.separator + subPath.getFileName(), owner, group, true); } } catch (IOException e) { - TaskLogWriter.error("[updateOwner] error: " + e.getMessage()); + log.error("[updateOwner] error", e); } } } @@ -220,20 +219,20 @@ public static void updateOwner(String dir, String owner, String group, boolean r public static void createDirectories( String dirPath, String owner, String group, String permissions, boolean recursive) { if (StringUtils.isBlank(dirPath)) { - TaskLogWriter.error("dirPath must not be null"); + log.error("dirPath must not be null"); return; } Path path = Paths.get(dirPath); if (Files.isSymbolicLink(path)) { - TaskLogWriter.warn("unable to create symbolic link: " + dirPath); + log.warn("unable to create symbolic link: {}", dirPath); return; } try { Files.createDirectories(path); } catch (IOException e) { - TaskLogWriter.error("[createDirectories] error: " + e.getMessage()); + log.error("[createDirectories] error", e); } updateOwner(dirPath, owner, group, recursive); diff --git a/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/linux/LinuxOSUtils.java b/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/linux/LinuxOSUtils.java index 5a47ccd3a..2b6800d96 100644 --- a/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/linux/LinuxOSUtils.java +++ b/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/linux/LinuxOSUtils.java @@ -21,7 +21,6 @@ import org.apache.bigtop.manager.common.shell.ShellExecutor; import org.apache.bigtop.manager.common.shell.ShellResult; import org.apache.bigtop.manager.common.utils.FileUtils; -import org.apache.bigtop.manager.stack.common.log.TaskLogWriter; import org.apache.commons.lang3.StringUtils; @@ -100,22 +99,20 @@ public static ShellResult execCmd(String command) throws IOException { public static ShellResult checkProcess(String filepath) { File file = new File(filepath); if (!file.exists() || !file.isFile()) { - TaskLogWriter.warn("Pid file " + filepath + " is empty or does not exist"); + log.warn("Pid file {} is empty or does not exist", filepath); return new ShellResult(-1, "", "Component is not running"); } int pid; try { pid = Integer.parseInt(FileUtils.readFile2Str(file).replaceAll("\r|\n", "")); } catch (Exception e) { - TaskLogWriter.warn("Pid file " + filepath - + " does not exist or does not contain a process id number, error: " + e.getMessage()); + log.warn("Pid file {} does not exist or does not contain a process id number, error", filepath, e); return new ShellResult(-1, "", "Component is not running"); } try { return execCmd("kill -0 " + pid); } catch (IOException e) { - TaskLogWriter.warn("Process with pid " + pid + " is not running. Stale pid file at " + filepath - + ", error: " + e.getMessage()); + log.warn("Process with pid {} is not running. Stale pid file at {}, error", pid, filepath, e); return new ShellResult(-1, "", "Component is not running"); } } diff --git a/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/template/BaseTemplate.java b/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/template/BaseTemplate.java index 8ff4e5681..309ff8ccc 100644 --- a/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/template/BaseTemplate.java +++ b/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/template/BaseTemplate.java @@ -19,7 +19,6 @@ package org.apache.bigtop.manager.stack.common.utils.template; import org.apache.bigtop.manager.stack.common.exception.StackException; -import org.apache.bigtop.manager.stack.common.log.TaskLogWriter; import freemarker.core.UndefinedOutputFormat; import freemarker.template.Configuration; @@ -58,7 +57,7 @@ public static void writeTemplate(String path, Object dataModel, String type) { Template template = CONFIGURATION.getTemplate(type + ".ftl"); writeTemplate(path, dataModel, template); } catch (IOException e) { - TaskLogWriter.error("Failed to writeTemplate: " + e.getMessage()); + log.error("Failed to writeTemplate", e); } } @@ -68,7 +67,7 @@ public static void writeCustomTemplate(String path, Object dataModel, String sou Template template = new Template("tmpTemplate", sourceStr, CONFIGURATION); writeTemplate(path, dataModel, template); } catch (IOException e) { - TaskLogWriter.error("Failed to writeTemplate: " + e.getMessage()); + log.error("Failed to writeTemplate", e); } } @@ -80,7 +79,7 @@ public static void writeTemplate(String path, Object dataModel, Template templat template.process(dataModel, fileWriter); fileWriter.flush(); } catch (TemplateException | IOException e) { - TaskLogWriter.error("Failed to writeTemplate: " + e.getMessage()); + log.error("Failed to writeTemplate", e); } finally { try { if (fileWriter != null) { @@ -98,7 +97,7 @@ public static String writeTemplateAsString(Object dataModel, String type) { template = CONFIGURATION.getTemplate(type + ".ftl"); return writeTemplateAsString(dataModel, template); } catch (IOException e) { - TaskLogWriter.error("Failed to writeTemplate: " + e.getMessage()); + log.error("Failed to writeTemplate", e); throw new StackException(e); } } @@ -109,7 +108,7 @@ public static String writeCustomTemplateAsString(Object dataModel, String source Template template = new Template("tmpTemplate", sourceStr, CONFIGURATION); return writeTemplateAsString(dataModel, template); } catch (IOException e) { - TaskLogWriter.error("Failed to writeTemplate: " + e.getMessage()); + log.error("Failed to writeTemplate", e); throw new StackException(e); } } @@ -122,7 +121,7 @@ public static String writeTemplateAsString(Object dataModel, Template template) template.process(dataModel, stringWriter); stringWriter.flush(); } catch (TemplateException | IOException e) { - TaskLogWriter.error("Failed to writeTemplate: " + e.getMessage()); + log.error("Failed to writeTemplate", e); } finally { try { if (stringWriter != null) { diff --git a/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/template/TemplateUtils.java b/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/template/TemplateUtils.java index 6437eb658..7fb67794d 100644 --- a/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/template/TemplateUtils.java +++ b/bigtop-manager-stack/bigtop-manager-stack-common/src/main/java/org/apache/bigtop/manager/stack/common/utils/template/TemplateUtils.java @@ -19,7 +19,6 @@ package org.apache.bigtop.manager.stack.common.utils.template; import org.apache.bigtop.manager.stack.common.enums.ConfigType; -import org.apache.bigtop.manager.stack.common.log.TaskLogWriter; import lombok.extern.slf4j.Slf4j; @@ -47,7 +46,7 @@ public static void map2Template(ConfigType configType, String fileName, Object c BaseTemplate.writeCustomTemplate(fileName, paramMap, paramTemplate); } } catch (Exception e) { - TaskLogWriter.error("writeProperties error: " + e.getMessage()); + log.error("writeProperties error", e); } } @@ -63,7 +62,7 @@ public static void map2CustomTemplate(String template, String fileName, Object c BaseTemplate.writeCustomTemplate(fileName, paramMap, paramTemplate); } } catch (Exception e) { - TaskLogWriter.error("writeProperties error: " + e.getMessage()); + log.error("writeProperties error", e); } } } diff --git a/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/executor/StackExecutor.java b/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/executor/StackExecutor.java index 85aaaebe4..55da1caab 100644 --- a/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/executor/StackExecutor.java +++ b/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/executor/StackExecutor.java @@ -28,14 +28,12 @@ import org.apache.bigtop.manager.spi.stack.Params; import org.apache.bigtop.manager.spi.stack.Script; import org.apache.bigtop.manager.stack.common.exception.StackException; -import org.apache.bigtop.manager.stack.common.log.TaskLogWriter; import lombok.extern.slf4j.Slf4j; import java.lang.reflect.Method; import java.util.List; import java.util.Map; -import java.util.function.Consumer; @Slf4j public class StackExecutor { @@ -83,13 +81,7 @@ private static void runAfterHook(String command) { } public static ShellResult execute(CommandPayload commandPayload) { - return execute(commandPayload, s -> {}); - } - - public static ShellResult execute(CommandPayload commandPayload, Consumer consumer) { try { - TaskLogWriter.setWriter(consumer); - String command; Script script; if (commandPayload.getCommand().name().equals(Command.CUSTOM.name())) { @@ -111,17 +103,15 @@ public static ShellResult execute(CommandPayload commandPayload, Consumer> user : users.entrySet()) { Set groups = user.getValue(); - TaskLogWriter.info("user: " + user.getKey() + " , groups: " + user.getValue()); + log.info("user: {}, groups: {}", user.getKey(), user.getValue()); for (String group : groups) { LinuxAccountUtils.groupAdd(group); } diff --git a/bigtop-manager-stack/bigtop-manager-stack-nop/src/main/java/org/apache/bigtop/manager/stack/nop/v1_0_0/kafka/KafkaBrokerScript.java b/bigtop-manager-stack/bigtop-manager-stack-nop/src/main/java/org/apache/bigtop/manager/stack/nop/v1_0_0/kafka/KafkaBrokerScript.java index b25c8d35b..fc173c32c 100644 --- a/bigtop-manager-stack/bigtop-manager-stack-nop/src/main/java/org/apache/bigtop/manager/stack/nop/v1_0_0/kafka/KafkaBrokerScript.java +++ b/bigtop-manager-stack/bigtop-manager-stack-nop/src/main/java/org/apache/bigtop/manager/stack/nop/v1_0_0/kafka/KafkaBrokerScript.java @@ -21,7 +21,6 @@ import org.apache.bigtop.manager.common.shell.ShellResult; import org.apache.bigtop.manager.spi.stack.Params; import org.apache.bigtop.manager.spi.stack.Script; -import org.apache.bigtop.manager.stack.common.log.TaskLogWriter; import com.google.auto.service.AutoService; import lombok.extern.slf4j.Slf4j; @@ -32,36 +31,36 @@ public class KafkaBrokerScript implements Script { @Override public ShellResult install(Params params) { - TaskLogWriter.info("Success on dev mode"); + log.info("Default to success in dev mode"); return ShellResult.success(); } @Override public ShellResult configure(Params params) { - TaskLogWriter.info("Success on dev mode"); + log.info("Default to success in dev mode"); return ShellResult.success(); } @Override public ShellResult start(Params params) { - TaskLogWriter.info("Success on dev mode"); + log.info("Default to success in dev mode"); return ShellResult.success(); } @Override public ShellResult stop(Params params) { - TaskLogWriter.info("Success on dev mode"); + log.info("Default to success in dev mode"); return ShellResult.success(); } @Override public ShellResult status(Params params) { - TaskLogWriter.info("Success on dev mode"); + log.info("Default to success in dev mode"); return ShellResult.success(); } public ShellResult test(Params params) { - TaskLogWriter.info("Success on dev mode"); + log.info("Default to success in dev mode"); return ShellResult.success(); } } diff --git a/bigtop-manager-stack/bigtop-manager-stack-nop/src/main/java/org/apache/bigtop/manager/stack/nop/v1_0_0/zookeeper/ZookeeperClientScript.java b/bigtop-manager-stack/bigtop-manager-stack-nop/src/main/java/org/apache/bigtop/manager/stack/nop/v1_0_0/zookeeper/ZookeeperClientScript.java index 7818c21ad..08e3bf063 100644 --- a/bigtop-manager-stack/bigtop-manager-stack-nop/src/main/java/org/apache/bigtop/manager/stack/nop/v1_0_0/zookeeper/ZookeeperClientScript.java +++ b/bigtop-manager-stack/bigtop-manager-stack-nop/src/main/java/org/apache/bigtop/manager/stack/nop/v1_0_0/zookeeper/ZookeeperClientScript.java @@ -22,7 +22,6 @@ import org.apache.bigtop.manager.spi.stack.ClientScript; import org.apache.bigtop.manager.spi.stack.Params; import org.apache.bigtop.manager.spi.stack.Script; -import org.apache.bigtop.manager.stack.common.log.TaskLogWriter; import com.google.auto.service.AutoService; import lombok.extern.slf4j.Slf4j; @@ -33,13 +32,13 @@ public class ZookeeperClientScript implements ClientScript { @Override public ShellResult install(Params params) { - TaskLogWriter.info("Success on dev mode"); + log.info("Default to success in dev mode"); return ShellResult.success(); } @Override public ShellResult configure(Params params) { - TaskLogWriter.info("Success on dev mode"); + log.info("Default to success in dev mode"); return ShellResult.success(); } } diff --git a/bigtop-manager-stack/bigtop-manager-stack-nop/src/main/java/org/apache/bigtop/manager/stack/nop/v1_0_0/zookeeper/ZookeeperServerScript.java b/bigtop-manager-stack/bigtop-manager-stack-nop/src/main/java/org/apache/bigtop/manager/stack/nop/v1_0_0/zookeeper/ZookeeperServerScript.java index 996c41168..48d75dac0 100644 --- a/bigtop-manager-stack/bigtop-manager-stack-nop/src/main/java/org/apache/bigtop/manager/stack/nop/v1_0_0/zookeeper/ZookeeperServerScript.java +++ b/bigtop-manager-stack/bigtop-manager-stack-nop/src/main/java/org/apache/bigtop/manager/stack/nop/v1_0_0/zookeeper/ZookeeperServerScript.java @@ -21,7 +21,6 @@ import org.apache.bigtop.manager.common.shell.ShellResult; import org.apache.bigtop.manager.spi.stack.Params; import org.apache.bigtop.manager.spi.stack.Script; -import org.apache.bigtop.manager.stack.common.log.TaskLogWriter; import com.google.auto.service.AutoService; import lombok.extern.slf4j.Slf4j; @@ -32,31 +31,31 @@ public class ZookeeperServerScript implements Script { @Override public ShellResult install(Params params) { - TaskLogWriter.info("Success on dev mode"); + log.info("Default to success in dev mode"); return ShellResult.success(); } @Override public ShellResult configure(Params params) { - TaskLogWriter.info("Success on dev mode"); + log.info("Default to success in dev mode"); return ShellResult.success(); } @Override public ShellResult start(Params params) { - TaskLogWriter.info("Success on dev mode"); + log.info("Default to success in dev mode"); return ShellResult.success(); } @Override public ShellResult stop(Params params) { - TaskLogWriter.info("Success on dev mode"); + log.info("Default to success in dev mode"); return ShellResult.success(); } @Override public ShellResult status(Params params) { - TaskLogWriter.info("Success on dev mode"); + log.info("Default to success in dev mode"); return ShellResult.success(); } }