Unverified Commit 0ee0a855 authored by aiwenmo's avatar aiwenmo Committed by GitHub

[Feature-1108][admin,web] Add system log and fix import order (#1109)

Co-authored-by: 's avatarwenmo <32723967+wenmo@users.noreply.github.com>
parent e52e5d3b
......@@ -15,16 +15,14 @@
~ 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"
<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>
<artifactId>dlink</artifactId>
<groupId>com.dlink</groupId>
<artifactId>dlink</artifactId>
<version>0.6.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>dlink-admin</artifactId>
......@@ -206,7 +204,6 @@
<groupId>com.dlink</groupId>
<artifactId>dlink-scheduler</artifactId>
</dependency>
</dependencies>
<build>
......@@ -225,10 +222,10 @@
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
......@@ -239,10 +236,10 @@
<executions>
<execution>
<id>copy-static</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<phase>validate</phase>
<configuration>
<outputDirectory>src/main/resources/static</outputDirectory>
<overwrite>true</overwrite>
......
......@@ -56,8 +56,12 @@ public class Result<T> implements Serializable {
return of(model, CodeEnum.SUCCESS.getCode(), "");
}
public static <T> Result<T> data(T model) {
return of(model, CodeEnum.SUCCESS.getCode(), "");
}
public static <T> Result<T> of(T datas, Integer code, String msg) {
return new Result<>(datas, code, msg,new DateTime().toString());
return new Result<>(datas, code, msg, new DateTime().toString());
}
public static <T> Result<T> failed(String msg) {
......@@ -72,4 +76,3 @@ public class Result<T> implements Serializable {
return of(model, CodeEnum.ERROR.getCode(), msg);
}
}
/*
*
* 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 com.dlink.constant;
import com.dlink.Dlink;
import org.springframework.boot.system.ApplicationHome;
/**
* DirConstant
*
* @author wenmo
* @since 2022/10/15 18:37
*/
public class DirConstant {
public static final String LOG_DIR_PATH;
public static final String ROOT_LOG_PATH;
static {
// String rootPath = new ApplicationHome(Dlink.class).getSource().getParent();
String rootPath = new ApplicationHome(Dlink.class).getDir().getPath();
LOG_DIR_PATH = rootPath + "/../logs";
ROOT_LOG_PATH = rootPath + "/../logs/dlink.log";
}
}
/*
*
* 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 com.dlink.controller;
import com.dlink.common.result.Result;
import com.dlink.constant.DirConstant;
import com.dlink.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* SystemController
*
* @author wenmo
* @since 2022/10/15 19:20
*/
@RestController
@RequestMapping("/api/system")
public class SystemController {
@Autowired
private SystemService systemService;
@GetMapping("/listLogDir")
public Result listLogDir() {
return Result.data(systemService.listLogDir());
}
@GetMapping("/getRootLog")
public Result getRootLog() {
return Result.data(systemService.readFile(DirConstant.ROOT_LOG_PATH));
}
@GetMapping("/listDirByPath")
public Result listDirByPath(@RequestParam String path) {
return Result.data(systemService.listDirByPath(path));
}
@GetMapping("/readFile")
public Result readFile(@RequestParam String path) {
return Result.data(systemService.readFile(path));
}
}
......@@ -30,7 +30,6 @@ import com.mysql.cj.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
/**
* tenant interceptor
*/
......@@ -38,9 +37,9 @@ import lombok.extern.slf4j.Slf4j;
public class TenantInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object handler) throws Exception {
String tenantId = request.getHeader("tenantId");
log.info("tenant interceptor preHandle execute ; current tenant id: 【" + tenantId + "】");
if (!StringUtils.isNullOrEmpty(tenantId)) {
RequestContext.set(Integer.valueOf(tenantId));
}
......
/*
*
* 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 com.dlink.model;
/**
* FileNode
*
* @author wenmo
* @since 2022/10/15 18:41
*/
public class FileNode {
private String name;
private boolean isDir;
private long size;
private String path;
public FileNode(String name, boolean isDir, long size, String path) {
this.name = name;
this.isDir = isDir;
this.size = size;
this.path = path;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isDir() {
return isDir;
}
public void setDir(boolean dir) {
isDir = dir;
}
public long getSize() {
return size;
}
public void setSize(long size) {
this.size = size;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
}
/*
*
* 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 com.dlink.service;
import com.dlink.model.FileNode;
import java.util.List;
/**
* SystemService
*
* @author wenmo
* @since 2022/10/15 19:16
*/
public interface SystemService {
/**
* list all dir and file by dir path
*
* @param path
* @return {@link List<FileNode>}
*/
List<FileNode> listDirByPath(String path);
/**
* List log root dir.
*
* @return {@link List<FileNode>}
*/
List<FileNode> listLogDir();
/**
* readFile
*
* @param path
* @return {@link String}
*/
String readFile(String path);
}
/*
*
* 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 com.dlink.service.impl;
import com.dlink.constant.DirConstant;
import com.dlink.model.FileNode;
import com.dlink.service.SystemService;
import com.dlink.utils.DirUtil;
import java.util.List;
import org.springframework.stereotype.Service;
/**
* SystemServiceImpl
*
* @author wenmo
* @since 2022/10/15 19:17
*/
@Service
public class SystemServiceImpl implements SystemService {
@Override
public List<FileNode> listDirByPath(String path) {
return DirUtil.listDirByPath(path);
}
@Override
public List<FileNode> listLogDir() {
return DirUtil.listDirByPath(DirConstant.LOG_DIR_PATH);
}
@Override
public String readFile(String path) {
return DirUtil.readFile(path);
}
}
/*
*
* 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 com.dlink.utils;
import com.dlink.assertion.Asserts;
import com.dlink.exception.BusException;
import com.dlink.model.FileNode;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import cn.hutool.core.util.StrUtil;
/**
* DirUtil
*
* @author wenmo
* @since 2022/10/14 21:43
*/
public class DirUtil {
public static List<FileNode> listDirByPath(String path) {
List<FileNode> dirList = new ArrayList<>();
File logDir = new File(path);
if (logDir.isFile()) {
throw new BusException(StrUtil.format("Directory path {} is a file.", path));
}
File[] files = logDir.listFiles();
if (Asserts.isNull(files)) {
throw new BusException(StrUtil.format("Directory path {} does not exist.", path));
}
for (File file : files) {
FileNode fileNode = new FileNode(file.getName(), file.isDirectory(), 0, file.getAbsolutePath());
if (!fileNode.isDir()) {
fileNode.setSize(file.length());
}
dirList.add(fileNode);
}
return dirList;
}
public static String readFile(String path) {
StringBuilder builder = new StringBuilder();
File file = new File(path);
if (!file.isFile()) {
throw new BusException(StrUtil.format("File path {} is not a file.", path));
}
try (
InputStreamReader inputStreamReader =
new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
String content = "";
while ((content = bufferedReader.readLine()) != null) {
builder.append("\n");
builder.append(content);
}
} catch (Exception e) {
e.printStackTrace();
}
return builder.toString();
}
}
......@@ -93,10 +93,10 @@ dinky:
dolphinscheduler:
enabled: false
# dolphinscheduler 地址
url: http://127.0.0.1:12345/dolphinscheduler
url: http://127.0.0.1:5173/dolphinscheduler
# dolphinscheduler 生成的token
token: 466cb6f6455b1b8689fff770746e2e79
token: ad54eb8f57fadea95f52763517978b26
# dolphinscheduler 中指定的项目名不区分大小写
project-name: dinky
project-name: Dinky
# Dolphinscheduler DinkyTask Address
address: http://127.0.0.1:8888
/*
*
* 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 com.dlink.utils;
import com.dlink.constant.DirConstant;
import com.dlink.model.FileNode;
import java.util.List;
import org.assertj.core.api.Assertions;
import org.junit.Test;
/**
* DirUtilTest
*
* @author wenmo
* @since 2022/10/14 22:00
*/
public class DirUtilTest {
@Test
public void testListDirByPath() {
List<FileNode> dirList = DirUtil.listDirByPath(DirConstant.LOG_DIR_PATH);
Assertions.assertThat(dirList).isNotNull();
}
@Test
public void testReadFile() {
String result = DirUtil.readFile(DirConstant.LOG_DIR_PATH + "/dlink.log");
Assertions.assertThat(result).isNotNull();
}
@Test
public void testReadRootLog() {
String result = DirUtil.readFile(DirConstant.ROOT_LOG_PATH);
Assertions.assertThat(result).isNotNull();
}
}
......@@ -176,6 +176,12 @@ export default [
icon: 'setting',
component: './SettingCenter/FlinkSettings',
},
{
path: '/settingcenter/systeminfo',
name: 'systemInfo',
icon: 'desktop',
component: './SettingCenter/SystemInfo',
},
],
},
{
......
......@@ -57,7 +57,7 @@
"@ant-design/charts": "^1.3.4",
"@ant-design/icons": "^4.5.0",
"@ant-design/plots": "^1.0.7",
"@ant-design/pro-components": "^1.1.23",
"@ant-design/pro-components": "^1.1.24",
"@ant-design/pro-descriptions": "^1.6.8",
"@ant-design/pro-form": "^1.18.3",
"@ant-design/pro-layout": "^6.18.0",
......
......@@ -66,8 +66,6 @@ export default {
'menu.editor.mind': 'Mind Editor',
'menu.editor.koni': 'Koni Editor',
// ------------------------------------------------------------------------------
'menu.account.center': 'Account Center',
'menu.account.settings': 'Account Settings',
'menu.account.changePassword': 'Change Password',
......@@ -103,6 +101,7 @@ export default {
'menu.settings': 'Setting Center',
'menu.settings.flinkConfig': 'Flink Settings',
'menu.settings.systemInfo': 'System Info',
'menu.about': 'About',
};
......@@ -72,15 +72,12 @@ export default {
'menu.dev.ant-design.docs': '官方文档',
'menu.dev.ant-design.preview': '官方预览',
// ------------------------------------------------------------------------------
'menu.account.center': '个人中心',
'menu.account.settings': '个人设置',
'menu.account.changePassword': '修改密码',
'menu.account.checkTenant': '切换租户',
'menu.account.logout': '退出登录',
'menu.datastudio': '数据开发',
'menu.devops': '运维中心',
......@@ -101,16 +98,15 @@ export default {
'menu.registration.document': '文档管理',
'menu.registration.fragment': '全局变量管理',
'menu.authenticationcenter': '认证中心',
'menu.authenticationcenter.usermanager': '用户管理',
'menu.authenticationcenter.namespacemanager': '命名空间管理',
'menu.authenticationcenter.rolemanager': '角色管理',
'menu.authenticationcenter.tenantmanager': '租户管理',
'menu.settings': '配置中心',
'menu.settings.flinkConfig': 'Flink 配置',
'menu.settings.systemInfo': '系统信息',
'menu.about': '关于',
};
/*
*
* 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.
*
*/
/*
*
* 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.
*
*/
import React, {useEffect, useState} from 'react';
import {PageContainer} from "@ant-design/pro-layout";
import {Button, Empty, Tabs} from "antd";
import CodeShow from "@/components/Common/CodeShow";
import {getRootLog} from "@/pages/SettingCenter/SystemInfo/service";
import {RedoOutlined} from "@ant-design/icons";
const {TabPane} = Tabs;
const SystemInfo = (props: any) => {
const [log, setLog] = useState<string>("Nothing.");
useEffect(() => {
refreshRootLog();
}, []);
const refreshRootLog = () => {
const res = getRootLog();
res.then((result) => {
result.datas && setLog(result.datas);
});
}
return (
<PageContainer title={false}>
<Tabs defaultActiveKey="metrics" size="small" tabPosition="top"
style={{
border: "1px solid #f0f0f0",
backgroundColor: '#fff',
}}
tabBarExtraContent={<Button
icon={<RedoOutlined />}
onClick={refreshRootLog}
></Button>}>
<TabPane tab={<span>&nbsp; Metrics &nbsp;</span>} key="metrics">
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description='Coming soon'/>
</TabPane>
<TabPane tab={<span>&nbsp; Configuration &nbsp;</span>} key="configuration">
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description='Coming soon'/>
</TabPane>
<TabPane tab={<span>&nbsp; Logs &nbsp;</span>} key="logs">
<CodeShow code={log} language='java' height='500px'/>
</TabPane>
<TabPane tab={<span>&nbsp; Log List &nbsp;</span>} key="logList">
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description='Coming soon'/>
</TabPane>
</Tabs>
</PageContainer>
);
};
export default SystemInfo;
/*
*
* 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.
*
*/
import {getData} from "@/components/Common/crud";
export function getRootLog() {
return getData("api/system/getRootLog");
}
......@@ -21,8 +21,8 @@
<groupId>com.dlink</groupId>
<artifactId>dlink</artifactId>
<packaging>pom</packaging>
<version>0.6.8-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>dlink-flink</module>
......@@ -535,8 +535,11 @@
</eclipse>
<removeUnusedImports />
<importOrder>
<file>style/eclipse.importorder</file>
<order>com.dlink,org.apache,java,javax,org,com,,\#</order>
</importOrder>
<licenseHeader>
<file>style/license_header</file>
</licenseHeader>
<replaceRegex>
<name>Remove wildcard imports</name>
<searchRegex>import\s+[^\*\s]+\*;(\r\n|\r|\n)</searchRegex>
......
#
# 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.
#
#Organize Import Order
0=com.dlink
1=org.apache
2=java
3=javax
4=org
5=com
\ No newline at end of file
/*
*
* 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.
*
*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment