Unverified Commit 03116858 authored by ZackYoung's avatar ZackYoung Committed by GitHub

[fix] fix paimon use in win ,login filter failure (#2071)

* fix paimon use in win * fix maven classpath scan * fix git_build web some bug * fix git_build web some bug & login some bug * fix git_build web some bug & login some bug * change charts tooltip
parent 1a149673
......@@ -19,6 +19,7 @@
package org.dinky.controller;
import org.dinky.data.annotation.PublicInterface;
import org.dinky.data.dto.GitProjectDTO;
import org.dinky.data.dto.TreeNodeDTO;
import org.dinky.data.enums.Status;
......@@ -209,6 +210,7 @@ public class GitController {
*/
@GetMapping(path = "/build-step-logs", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
@CrossOrigin("*")
@PublicInterface
public SseEmitter buildStepLogs(@RequestParam("id") Integer id) {
SseEmitter emitter = new SseEmitterUTF8(TimeUnit.MINUTES.toMillis(30));
GitProject gitProject = gitProjectService.getById(id);
......
......@@ -19,6 +19,7 @@
package org.dinky.controller;
import org.dinky.data.annotation.PublicInterface;
import org.dinky.data.result.Result;
import org.dinky.data.vo.MetricsVO;
import org.dinky.service.MonitorService;
......@@ -57,6 +58,7 @@ public class MonitorController {
@GetMapping(value = "/getLastUpdateData", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
@CrossOrigin("*")
@PublicInterface
public SseEmitter getLastUpdateData(Long lastTime) {
SseEmitter emitter = new SseEmitterUTF8(TimeUnit.MINUTES.toMillis(30));
return monitorService.sendLatestData(
......
/*
*
* 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.dinky.data.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface PublicInterface {}
......@@ -21,14 +21,18 @@ package org.dinky.interceptor;
import org.dinky.assertion.Asserts;
import org.dinky.context.TenantContextHolder;
import org.dinky.data.annotation.PublicInterface;
import java.util.Arrays;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.AsyncHandlerInterceptor;
import cn.dev33.satoken.SaManager;
import cn.dev33.satoken.exception.NotLoginException;
import cn.hutool.core.lang.Opt;
import lombok.extern.slf4j.Slf4j;
/** tenant interceptor */
......@@ -39,11 +43,32 @@ public class TenantInterceptor implements AsyncHandlerInterceptor {
public boolean preHandle(
HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
if (Asserts.isNotNull(request.getCookies())) {
Arrays.stream(request.getCookies())
.filter(t -> "tenantId".equals(t.getName()))
.findFirst()
.ifPresent(t -> TenantContextHolder.set(Integer.valueOf(t.getValue())));
boolean isPass = false;
Cookie[] cookies = request.getCookies();
Opt<String> token = Opt.empty();
if (Asserts.isNotNull(cookies)) {
for (Cookie cookie : cookies) {
switch (cookie.getName()) {
case "satoken":
token = Opt.ofBlankAble(cookie.getValue());
if (SaManager.getSaTokenDao().get("satoken:login:token:" + token.get())
!= null) {
isPass = true;
}
break;
case "tenantId":
TenantContextHolder.set(Integer.valueOf(cookie.getValue()));
break;
}
}
}
if (!isPass) {
if (handler instanceof HandlerMethod) {
if (((HandlerMethod) handler).getMethodAnnotation(PublicInterface.class) != null) {
return true;
}
}
throw NotLoginException.newInstance("", "-1", token.get());
}
return AsyncHandlerInterceptor.super.preHandle(request, response, handler);
}
......
......@@ -29,6 +29,7 @@ import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
......@@ -133,6 +134,12 @@ public class MavenUtil {
List<String> goals,
List<String> args) {
List<String> commandLine = new LinkedList<>();
String classpath =
FileUtil.loopFiles(mavenHome + "/boot").stream()
.filter(x -> FileUtil.getSuffix(x).equals("jar"))
.map(x -> x.getAbsolutePath())
.collect(Collectors.joining(File.pathSeparator));
commandLine.add(javaExecutor);
commandLine.add("-Dfile.encoding=UTF-8");
commandLine.add("-Dmaven.multiModuleProjectDirectory=" + projectDir);
......@@ -140,10 +147,7 @@ public class MavenUtil {
Opt.ofBlankAble(repositoryDir)
.ifPresent(x -> commandLine.add("-Dmaven.repo.local=" + repositoryDir));
commandLine.add("-Dclassworlds.conf=" + mavenHome + "/bin/m2.conf");
commandLine.add(
"-classpath "
+ mavenHome
+ "/boot/plexus-classworlds-2.x.jar org.codehaus.classworlds.Launcher");
commandLine.add("-classpath " + classpath + " org.codehaus.classworlds.Launcher");
commandLine.add("-s " + settingsPath);
commandLine.add("-f " + projectDir);
commandLine.add(StrUtil.join(" ", args));
......
......@@ -60,6 +60,7 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.URLUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
......@@ -67,7 +68,8 @@ public class PaimonUtil {
private static final String DINKY_DB = "dinky_db";
private static final Map<Identifier, Schema> SCHEMA_MAP = new HashMap<>();
private static final CatalogContext CONTEXT =
CatalogContext.create(new Path("file://" + PathConstant.TMP_PATH + "paimon"));
CatalogContext.create(
new Path(URLUtil.toURI(URLUtil.url(PathConstant.TMP_PATH + "paimon"))));
private static final Catalog CATALOG = CatalogFactory.createCatalog(CONTEXT);
public static final Identifier METRICS_IDENTIFIER =
Identifier.create(DINKY_DB, "dinky_metrics");
......
......@@ -20,6 +20,7 @@
import React, {useEffect, useState} from "react";
import {Area, AreaConfig} from "@ant-design/plots";
import {MetricsDataType} from "@/pages/Metrics/Server/data";
import {Datum} from "@antv/g2plot";
type CpuProps = {
......@@ -34,7 +35,7 @@ const CPU: React.FC<CpuProps> = (props) => {
const {data} = props;
const dataList: Cpu[] = data.map(x => {
return {time: x.heartTime, value: Number( x.content.jvm.cpuUsed.toFixed(2))};
return {time: x.heartTime, value: Number(x.content.jvm.cpuUsed.toFixed(2))};
})
......@@ -48,10 +49,15 @@ const CPU: React.FC<CpuProps> = (props) => {
type: 'time',
mask: 'HH:mm:ss',
},
yAxis:{
min:0,
max:100
yAxis: {
min: 0,
max: 100
},
tooltip: {
formatter: (datum: Datum) => {
return {name: "Cpu Used", value: datum.value + ' %'};
},
}
};
return <Area {...config} />;
......
......@@ -20,6 +20,7 @@
import React, {useEffect, useState} from "react";
import {Area, AreaConfig} from "@ant-design/plots";
import {MetricsDataType} from "@/pages/Metrics/Server/data";
import {Datum} from "@antv/g2plot";
type HeapProps = {
data: MetricsDataType[];
......@@ -30,15 +31,15 @@ type Heap = {
value: string | number;
}
const Heap: React.FC<HeapProps> = (props) => {
const {data,max} = props;
const {data, max} = props;
const dataList: Heap[] = data.map(x => {
return {time: x.heartTime, value: Number((x.content.jvm.heapUsed/(1024*1024)).toFixed(0))};
return {time: x.heartTime, value: Number((x.content.jvm.heapUsed / (1024 * 1024)).toFixed(0))};
})
const config: AreaConfig = {
data:dataList,
animation:false,
data: dataList,
animation: false,
height: 150,
yField: 'value',
xField: 'time',
......@@ -46,10 +47,15 @@ const Heap: React.FC<HeapProps> = (props) => {
type: 'time',
mask: 'HH:mm:ss',
},
yAxis:{
min:0,
max:max
yAxis: {
min: 0,
max: max
},
tooltip: {
formatter: (datum: Datum) => {
return {name: "Heap Memory", value: datum.value + ' MB'};
},
}
};
return <Area {...config} />;
......
......@@ -20,6 +20,7 @@
import React, {useEffect, useState} from "react";
import {Area, AreaConfig} from "@ant-design/plots";
import {MetricsDataType} from "@/pages/Metrics/Server/data";
import {Datum} from "@antv/g2plot";
type NonHeapProps = {
data: MetricsDataType[];
......@@ -50,6 +51,11 @@ const NonHeap: React.FC<NonHeapProps> = (props) => {
min: 0,
max: max
},
tooltip: {
formatter: (datum: Datum) => {
return {name: "NonHeap Memory", value: datum.value + ' MB'};
},
}
};
return <Area {...config} />;
......
......@@ -42,12 +42,15 @@ const Thread: React.FC<ThreadProps> = (props) => {
const config: AreaConfig = {
padding: 'auto',
smooth: true,
data: dataListAll,
animation: false,
height: 150,
xField: 'time',
yField: 'value',
seriesField: 'name',
isStack:false,
xAxis: {
type: 'time',
mask: 'HH:mm:ss',
......
......@@ -37,9 +37,12 @@ import {
import {getDataByParams, queryDataByParams} from "@/services/BusinessCrud";
import Metrics from "@/pages/Metrics";
import {MetricsDataType} from "@/pages/Metrics/Server/data";
import {API_CONSTANTS} from "@/services/constants";
import {API_CONSTANTS, METHOD_CONSTANTS} from "@/services/constants";
import proxy from "../../../../config/proxy";
import NonHeap from "@/pages/Metrics/Server/OutHeap";
import {getSseData} from "@/services/api";
import {request} from "@@/exports";
import {extend} from "umi-request";
export const imgStyle = {
display: 'block',
......@@ -71,28 +74,23 @@ const Server = () => {
, nonHeapMax: 0, nonHeapLastValue: 0
});
let eventSource: EventSource;
const getLastData = (data: MetricsDataType[]) => {
const {REACT_APP_ENV = 'dev'} = process.env;
// @ts-ignore
const url = proxy[REACT_APP_ENV]["/api/"].target || ""
eventSource = new EventSource(url + API_CONSTANTS.MONITOR_GET_LAST_DATA + "?lastTime=" + endTime.getTime());
eventSource.onmessage = e => {
let result = JSON.parse(e.data);
result.content = JSON.parse(result.content)
data.push(result)
setData(data)
setDataRecord({
cpuLastValue: result.content.jvm.cpuUsed.toFixed(2),
heapMax: Number((result.content.jvm.heapMax / (1024 * 1024)).toFixed(0)),
heapLastValue: Number((result.content.jvm.heapUsed / (1024 * 1024)).toFixed(0)),
nonHeapMax: Number((result.content.jvm.nonHeapMax / (1024 * 1024)).toFixed(0)),
nonHeapLastValue: Number((result.content.jvm.nonHeapUsed / (1024 * 1024)).toFixed(0)),
threadPeakCount: result.content.jvm.threadPeakCount,
threadCount: result.content.jvm.threadCount,
})
}
const getLastData = (data: MetricsDataType[]) => {
eventSource = getSseData(API_CONSTANTS.MONITOR_GET_LAST_DATA + "?lastTime=" + endTime.getTime() );
eventSource.onmessage = e => {
let result = JSON.parse(e.data);
result.content = JSON.parse(result.content)
data.push(result)
setData(data)
setDataRecord({
cpuLastValue: result.content.jvm.cpuUsed.toFixed(2),
heapMax: Number((result.content.jvm.heapMax / (1024 * 1024)).toFixed(0)),
heapLastValue: Number((result.content.jvm.heapUsed / (1024 * 1024)).toFixed(0)),
nonHeapMax: Number((result.content.jvm.nonHeapMax / (1024 * 1024)).toFixed(0)),
nonHeapLastValue: Number((result.content.jvm.nonHeapUsed / (1024 * 1024)).toFixed(0)),
threadPeakCount: result.content.jvm.threadPeakCount,
threadCount: result.content.jvm.threadCount,
})
}
}
const getInitData = () => {
......
......@@ -27,6 +27,7 @@ import {API_CONSTANTS} from "@/services/constants";
import proxy from "../../../../../../config/proxy";
import {renderStatus} from '@/pages/RegCenter/GitProject/function';
import {BuildStepsState} from '@/pages/RegCenter/GitProject/data.d';
import {getSseData} from "@/services/api";
/**
......@@ -69,13 +70,9 @@ export const BuildSteps: React.FC<BuildStepsProps> = (props) => {
setPercent(0);
setCurrentStep(0);
}
const {REACT_APP_ENV = 'dev'} = process.env;
// @ts-ignore
const url = proxy[REACT_APP_ENV]["/api/"].target || ""
// 这里不要代理。sse使用代理会变成同步
// const eventSource = new EventSource("http://127.0.0.1:8888" + API_CONSTANTS.GIT_PROJECT_BUILD_STEP_LOGS + "?id=" + values.id);
const eventSource = new EventSource(url + API_CONSTANTS.GIT_PROJECT_BUILD_STEP_LOGS + "?id=" + values.id);
const eventSource = getSseData( API_CONSTANTS.GIT_PROJECT_BUILD_STEP_LOGS + "?id=" + values.id);
let stepArray: BuildStepsState[] = []; // 步骤数组
let globalCurrentStep: number = 0;
......@@ -84,6 +81,7 @@ export const BuildSteps: React.FC<BuildStepsProps> = (props) => {
let showDataStep = -1;
let showData = "";
let finish = false;
let lastStep=0;
//sse listen event message
eventSource.onmessage = e => {
......@@ -92,6 +90,7 @@ export const BuildSteps: React.FC<BuildStepsProps> = (props) => {
// status // 0是失败 1是进行中 2 完成
let result = JSON.parse(e.data);
const {currentStep, type, data, status, history} = result;
lastStep=currentStep;
if (type === 0) {
if (execNum === 1) {
......@@ -111,7 +110,7 @@ export const BuildSteps: React.FC<BuildStepsProps> = (props) => {
description: item.startTime,
disabled: true,
onClick: () => {
if (finish&& item.step<=currentStep) {
if (finish&& item.step<=lastStep) {
if (item.step === showDataStep) {
setShowList(true)
setLog(showData)
......
......@@ -18,7 +18,7 @@
import {request} from '@umijs/max';
import {METHOD_CONSTANTS} from "@/services/constants";
import proxy from "../../config/proxy";
// ============================ CRUD REQUEST ============================
......@@ -85,6 +85,14 @@ export async function removeData(url: string, params: [any]) {
},
});
}
export function getSseData(url: string) {
const {REACT_APP_ENV = 'dev'} = process.env;
// @ts-ignore
const address = proxy[REACT_APP_ENV]["/api/"].target || ""
return new EventSource(address + url);
}
......@@ -142,4 +150,4 @@ export async function getDataByRequestBody(url: string, body: any) {
method: METHOD_CONSTANTS.POST,
data: {...body},
});
}
\ No newline at end of file
}
......@@ -100,7 +100,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<protobuf-java.version>2.5.0</protobuf-java.version>
<reflections.version>0.10.2</reflections.version>
<sa-token.version>1.31.0</sa-token.version>
<sa-token.version>1.34.0</sa-token.version>
<scala.binary.version>2.12</scala.binary.version>
<scala.version>2.12.10</scala.version>
<!-- `provided` for product environment ,`compile` for dev environment -->
......
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