Skip to content

Commit

Permalink
[Feature] Unified Front and back end (#192)
Browse files Browse the repository at this point in the history
* fix ui deploy

* add npmDownloadRoot

* fix:修复运行报错问题

* feat:将前端产物“搬运”到指定目录

* feat:publicPath设置(/${path},后端配置)

* replace path to /ddh

* feat:前端文件移动,路径配置(/ddh)

* fix ui deploy

* revert some code

* revert some code

* [Improvement-190][MinaUtils] Improve get id_rsa file path to support different user home path on MinaUtils (#191)

* 1.delete read hosts file code and host_ip/ip_host cache
2.add utils get ip and hostname use InetAddress
3.delete  unused code related this functions

* Improve get id_rsa file path on MinaUtils

---------

Co-authored-by: chenshaosong <chenss131@chinaunicom.cn>

* perf: Remove constant Constants.ID/ALERT_GROUP_ID/ALERT_QUOTA_NAME/ALERT_GROUP_NAME/ALERT_LEVEL, and use SFunction instead. (#200)

* A bug fix for querying the list of all service roles (#202)

* perf: Remove constant Constants.ID/ALERT_GROUP_ID/ALERT_QUOTA_NAME/ALERT_GROUP_NAME/ALERT_LEVEL, and use SFunction instead.

* fix: NullpointerException will be thrown, when target value of query is null.

* add   options.mode = 'history'

* add   options.mode = 'history'

* revert

* fix some error

---------

Co-authored-by: huangli <huangli@iflytek.com>
Co-authored-by: chenss <shaosongfirst@163.com>
Co-authored-by: chenshaosong <chenss131@chinaunicom.cn>
Co-authored-by: renwujie <rwj005@outlook.com>
  • Loading branch information
5 people authored Mar 9, 2023
1 parent bfa3d1d commit 8931221
Show file tree
Hide file tree
Showing 12 changed files with 279 additions and 83 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ config.gypi
test/coverage
/docs/zh_CN/介绍
/docs/zh_CN/贡献代码.md

front/
node/
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.i18n.CookieLocaleResolver;

import java.util.Locale;
Expand Down Expand Up @@ -93,13 +97,16 @@ public void addInterceptors(InterceptorRegistry registry) {
.addPathPatterns("/**").excludePathPatterns("/login","/error",
"/service/install/downloadPackage",
"/cluster/alert/history/save",
"/cluster/kerberos/downloadKeytab"
"/cluster/kerberos/downloadKeytab",
"/index.html",
"/",
"/static/**"
);
}

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
registry.addResourceHandler("/static/**").addResourceLocations("classpath:/front/static/resources/bundle-main/static/");
registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
Expand All @@ -109,7 +116,7 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/ui/").setViewName("forward:/ui/index.html");
registry.addViewController("/").setViewName("forward:/ui/index.html");
registry.addViewController("/").setViewName("index");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,27 @@ public class UserPermissionHandler implements HandlerInterceptor {

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
HandlerMethod handlerMethod = (HandlerMethod) handler;
UserPermission annotation = handlerMethod.getMethod().getAnnotation(UserPermission.class);
if (Objects.nonNull(annotation)) {
UserInfoEntity authUser = (UserInfoEntity) request.getSession().getAttribute(Constants.SESSION_USER);
Map<String, String[]> parameterMap = request.getParameterMap();
if (Objects.nonNull(authUser) && !SecurityUtils.isAdmin(authUser)) {
logger.info("step into authrization");
if(parameterMap.containsKey("clusterId")){
logger.info("find clusterId");
String[] clusterIds = parameterMap.get("clusterId");
if(clusterUserService.isClusterManager(authUser.getId(),clusterIds[0])){
logger.info("{} is cluster manager",authUser.getUsername());
return true;
if(handler instanceof HandlerMethod){
HandlerMethod handlerMethod = (HandlerMethod) handler;
UserPermission annotation = handlerMethod.getMethod().getAnnotation(UserPermission.class);
if (Objects.nonNull(annotation)) {
UserInfoEntity authUser = (UserInfoEntity) request.getSession().getAttribute(Constants.SESSION_USER);
Map<String, String[]> parameterMap = request.getParameterMap();
if (Objects.nonNull(authUser) && !SecurityUtils.isAdmin(authUser)) {
logger.info("step into authrization");
if(parameterMap.containsKey("clusterId")){
logger.info("find clusterId");
String[] clusterIds = parameterMap.get("clusterId");
if(clusterUserService.isClusterManager(authUser.getId(),clusterIds[0])){
logger.info("{} is cluster manager",authUser.getUsername());
return true;
}
}
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
}
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
}
}

return true;
}
}
10 changes: 7 additions & 3 deletions datasophon-api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ spring:
username: root
password: root
driver-class-name: com.mysql.jdbc.Driver
#json格式化全局配置
resources:
static-locations: classpath:/front/views/
#json格式化全局配置
jackson:
time-zone: GMT+8
date-format: yyyy-MM-dd HH:mm:ss
mvc:
date-format: yyyy-MM-dd HH:mm:ss
#国际化配置
view:
suffix: .html
#国际化配置
messages:
basename: i18n/messages
encoding: UTF-8
Expand Down Expand Up @@ -48,4 +52,4 @@ mybatis-plus:
cache-enabled: false
call-setters-on-nulls: true
jdbc-type-for-null: 'null'
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
4 changes: 2 additions & 2 deletions datasophon-ui/.env
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!--
* @Author: mjzhu
* @describe:
* @describe:
* @Date: 2022-05-24 10:28:22
* @LastEditTime: 2022-07-16 16:28:29
* @FilePath: \ddh-ui\.env
-->
VUE_APP_PUBLIC_PATH=/
VUE_APP_PUBLIC_PATH=/ddh
VUE_APP_NAME=DataSophon
VUE_APP_ROUTES_KEY=admin.routes
VUE_APP_PERMISSIONS_KEY=admin.permissions
Expand Down
14 changes: 14 additions & 0 deletions datasophon-ui/deploy.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const PATH = '../datasophon-api/src/main/resources/front/'

module.exports = [
{
source: './dist',
clean: true,
target: `${PATH}/static/resources/bundle-main`,
},
{
source: './dist/index.html',
target: `${PATH}/views/index.html`,
replace: [{ pattern: /\/static\//g, replacement: '/static/' }],
},
]
54 changes: 54 additions & 0 deletions datasophon-ui/deploy.sh.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const fs = require('fs-extra')
const path = require('path')
const deployTasks = require('./deploy.config.js')

// 将前端产物“搬运”到指定目录
console.log(deployTasks)
const promisedDeployTasks = deployTasks.map((deployTask) => {
const { clean, source, target, replace } = deployTask
return new Promise((resolve, reject) => {
if (!source || !target) {
return reject(new Error('必须指定 ${source} 和 ${target} !'))
}
try {
const stat = fs.lstatSync(source)
if (clean === true) {
// 显式指定clean时,将目标目录清空
fs.emptyDirSync(path.resolve(__dirname, target))
}
if (!stat.isFile()) {
fs.copySync(
path.resolve(__dirname, source),
path.resolve(__dirname, target)
)
}
if (stat.isFile() && replace) {
let content = fs.readFileSync(source, 'utf-8')
replace.forEach((item) => {
content = content.replace(item.pattern, item.replacement)
})
fs.outputFileSync(target, content)
}
resolve()
} catch (e) {
reject(e)
}
})
})

async function runTasks() {
async function runner() {
for (const task of promisedDeployTasks) {
await task
}
}
try {
await runner()
console.log('部署完成!')
} catch (e) {
console.error('部署失败!')
console.log(e)
}
}

runTasks()
8 changes: 5 additions & 3 deletions datasophon-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"predeploy": "yarn build",
"deploy": "gh-pages -d dist -b pages -r https://gitee.com/iczer/vue-antd-admin.git",
"predeploy-yarn": "yarn build",
"deploy": "node deploy.sh.js",
"deploy-git": "gh-pages -d dist -b pages -r https://gitee.com/iczer/vue-antd-admin.git",
"docs:dev": "vuepress dev docs",
"docs:build": "vuepress build docs",
"docs:deploy": "vuepress build docs && gh-pages -d docs/.vuepress/dist -b master -r https://gitee.com/iczer/vue-antd-admin-docs.git"
Expand Down Expand Up @@ -65,7 +66,8 @@
"vue-template-compiler": "^2.6.11",
"vuepress": "^1.5.2",
"webpack-theme-color-replacer": "1.3.18",
"whatwg-fetch": "^3.0.0"
"whatwg-fetch": "^3.0.0",
"fs-extra": "^7.0.1"
},
"eslintConfig": {
"root": true,
Expand Down
117 changes: 114 additions & 3 deletions datasophon-ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,119 @@
<artifactId>datasophon-ui</artifactId>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<build.node.version>v12.16.3</build.node.version>
<build.npm.version>6.14.4</build.npm.version>
<nodemodules.dir>node_modules</nodemodules.dir>
<dist.dir>dist</dist.dir>
<deployed.dir>.deployed</deployed.dir>
</properties>

</project>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.10.3</version>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<phase>generate-resources</phase>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>install --registry=https://registry.npm.taobao.org --sass-binary-site=https://npm.taobao.org/mirrors/node-sass
</arguments>
</configuration>
</execution>
<execution>
<id>npm run build</id>
<goals>
<goal>npm</goal>
</goals>
<phase>install</phase>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
<execution>
<id>npm run deploy</id>
<goals>
<goal>npm</goal>
</goals>
<phase>install</phase>
<configuration>
<arguments>run deploy</arguments>
</configuration>
</execution>
</executions>
<configuration>
<nodeVersion>${build.node.version}</nodeVersion>
<npmVersion>${build.npm.version}</npmVersion>

<nodeDownloadRoot>https://npm.taobao.org/mirrors/node/</nodeDownloadRoot>
<npmDownloadRoot>https://registry.npm.taobao.org/npm/-/</npmDownloadRoot>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>windows</id>
<activation>
<os>
<family>win</family>
</os>
</activation>
<properties>
<envClassifier>win</envClassifier>
<dirsep>\</dirsep>
<executable.brunch>cmd</executable.brunch>
<executable.gzip>${basedir}\gzip-content.cmd</executable.gzip>
<args.brunch>/C brunch</args.brunch>
<node.executable>node.exe</node.executable>
<executable.mkdir>cmd</executable.mkdir>
<args.mkdir>/C mkdir</args.mkdir>
<executable.npm>cmd</executable.npm>
<args.npm>/C npm</args.npm>
<executable.rmdir>cmd</executable.rmdir>
<args.rm.clean>/C rmdir /S /Q</args.rm.clean>
<executable.shell>cmd</executable.shell>
<fileextension.shell>cmd</fileextension.shell>
<args.shell>/C</args.shell>
</properties>
</profile>
<profile>
<id>linux</id>
<activation>
<os>
<family>unix</family>
</os>
</activation>
<properties>
<envClassifier>linux</envClassifier>
<dirsep>/</dirsep>
<executable.brunch>brunch</executable.brunch>
<executable.gzip>gzip</executable.gzip>
<args.brunch/>
<node.executable>node</node.executable>
<executable.mkdir>mkdir</executable.mkdir>
<args.mkdir/>
<executable.npm>npm</executable.npm>
<args.npm/>
<executable.rmdir>rm</executable.rmdir>
<args.rm.clean>-rf</args.rm.clean>
<executable.shell>sh</executable.shell>
<fileextension.shell>sh</fileextension.shell>
<args.shell/>
</properties>
</profile>
</profiles>
</project>
8 changes: 4 additions & 4 deletions datasophon-ui/src/pages/serviceManage/setting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<a-button class="mgr10" type="primary" @click="handleSubmit">保存</a-button>
</div>
</a-spin>

</div>

</div>
Expand Down Expand Up @@ -210,7 +210,7 @@ export default {
},
handlerClick(item,childIndex){
console.log(item);
this.currentId = item.id
this.currentId = item.id
this.getConfigVersion()
},
handlearrayWithData(a) {
Expand Down Expand Up @@ -349,7 +349,7 @@ export default {
this.currentId = val.target.value
this.getConfigVersion()
},

//获取角色组
getServiceRoleType() {
this.loading = true;
Expand Down Expand Up @@ -492,4 +492,4 @@ export default {
}
}
}
</style>
</style>
4 changes: 2 additions & 2 deletions datasophon-ui/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

/*
* @Author: mjzhu
* @describe:
* @describe:
* @Date: 2022-05-24 10:22:10
* @LastEditTime: 2022-06-20 15:29:03
* @FilePath: \ddh-ui\src\router\index.js
Expand Down Expand Up @@ -48,7 +48,7 @@ const loginIgnore = {
* @returns {VueRouter}
*/
function initRouter(isAsync) {
const options = isAsync ? require('./config-cluster').default : require('./config').default
const options = isAsync ? require('./config-cluster').default : require('./config').default;
formatRoutes(options.routes)
return new Router(options)
}
Expand Down
Loading

0 comments on commit 8931221

Please sign in to comment.