Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化关联应用功能 #61

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ functions/mock
.umi-production
screenshot
.firebase
application-localhost.properties
application-localhost.properties
/sofa-dashboard-backend/sofa-dashboard-web/docker/sofadashboard/sofa-dashboard-web-1.0.0-SNAPSHOT.jar
/sofa-dashboard-backend/sofa-dashboard-web/docker/jenkins/Jenkins/
/sofa-dashboard-backend/sofa-dashboard-web/docker/sofadashboard/SOFADashboard/
16 changes: 16 additions & 0 deletions sofa-dashboard-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,26 @@
<sofa.common.version>1.0.17</sofa.common.version>
<jmockit.version>1.14</jmockit.version>
<mybatis.spring.boot.version>1.3.2</mybatis.spring.boot.version>
<knife4j.version>2.0.7</knife4j.version>
<guava.version>20.0</guava.version>
</properties>

<dependencyManagement>
<dependencies>
<!--knife4j-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>${knife4j.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>

</dependency>


<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-dashboard-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,12 @@ ArkModuleVersionDO queryByModuleIdAndModuleVersion(@Param("moduleId") int module
* @return
*/
int deletePluginVersion(@Param("id") int id, @Param("version") String version);

/***
* 根据模块id和应用名字 获取模块-应用关联信息
* @param mId
* @param appName
* @return
*/
List<AppArkDO> queryRelationByModuleIdAndAppName(int mId, String appName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@
*/
package com.alipay.sofa.dashboard.impl;

import com.alipay.sofa.ark.spi.service.ArkService;
import com.alipay.sofa.dashboard.app.AppServiceImpl;
import com.alipay.sofa.dashboard.dao.ArkDao;
import com.alipay.sofa.dashboard.model.AppArkDO;
import com.alipay.sofa.dashboard.model.ArkModuleUserDO;
import com.alipay.sofa.dashboard.model.ArkModuleVersionDO;
import com.alipay.sofa.dashboard.model.ArkPluginDO;
import com.alipay.sofa.dashboard.model.ArkPluginModel;
import com.alipay.sofa.dashboard.model.*;
import com.alipay.sofa.dashboard.service.ArkMngService;
import com.alipay.sofa.dashboard.utils.SofaDashboardUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -46,6 +45,13 @@ public class ArkMngServiceImpl implements ArkMngService {

@Autowired
private ArkDao arkDao;
@Autowired
private ZkHelper zkHelper;

@Override
public boolean isRelatedByModuleAndApp(int mId, String appName) {
return arkDao.queryRelationByModuleIdAndAppName(mId, appName).size() > 0;
}

@Override
public List<ArkPluginModel> fetchRegisteredPlugins() {
Expand Down Expand Up @@ -121,12 +127,20 @@ public int relatedAppToPlugin(int moduleId, String appName) {
if (moduleId < 0) {
return -1;
}
AppArkDO appArkDO = new AppArkDO();
appArkDO.setAppName(appName);
appArkDO.setCreateTime(SofaDashboardUtil.now());
appArkDO.setModuleId(moduleId);
arkDao.insertAppArk(appArkDO);
return appArkDO.getId();
List<String> arkAppList = zkHelper.getArkAppList();
boolean relatedByModuleAndApp = isRelatedByModuleAndApp(moduleId, appName);
for (String appApp : arkAppList) {
//zk中已存在应用 并且 未关联
if (appApp.equals(appName) && isRelatedByModuleAndApp(moduleId, appName) == false) {
AppArkDO appArkDO = new AppArkDO();
appArkDO.setAppName(appName);
appArkDO.setCreateTime(SofaDashboardUtil.now());
appArkDO.setModuleId(moduleId);
arkDao.insertAppArk(appArkDO);
return appArkDO.getId();
}
}
return -1;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,29 @@ private List<String> getInstanceIpList(String appName) {
return result;
}

/**
* 获取 /sofa-ark 下面所有的应用
* @return
*/
public List<String> getArkAppList() {
List<String> result = null;
CuratorFramework curatorClient = zkCommandClient.getCuratorClient();
String arkAppBasePath = SofaDashboardConstants.SOFA_ARK_ROOT;
try {
if (checkExist(arkAppBasePath, curatorClient)) {
// 获取所有应用信息
result = curatorClient.getChildren().forPath(arkAppBasePath);
}
} catch (Exception e) {
LOGGER.error("Failed to get ark app list.", e);
} finally {
if (result == null) {
result = new ArrayList<>();
}
}
return result;
}

/**
* 获取当前应用实例的个数
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
**/
public interface ArkMngService {

/***
* 根据模块Id和应用名字 获取模块是否已关联该应用
* @param mId
* @param appName
* @return
*/
boolean isRelatedByModuleAndApp(int mId, String appName);

/**
* 获取当前所有注册的 plugin 信息
*
Expand Down Expand Up @@ -83,9 +91,8 @@ public interface ArkMngService {
*/
List<ArkPluginModel> fetchPluginsByName(String pluginName);

/**
/***
* 关联应用和插件
*
* @param moduleId
* @param appName
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,11 @@ public class SofaDashboardConstants {
public static final String ZOOKEEPER_PREFIX = "zookeeper://";
public static final String SOFA_PREFIX = "sofa://";

// API接口类
public static final String API_ARK_TAGS = "Ark相关接口";
public static final String API_APPLICATION_TAGS = "Application相关接口";
public static final String API_ARK_APPLICATION_TAGS ="Ark与application相关应用";
public static final String API_INSTANCE_TAGS ="Instance相关接口";
public static final String API_SERVICES_TAGS ="Services相关接口";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '3.8'
services:
jenkins:

image: jenkins/jenkins:lts
volumes:
# - ./Jenkins/jenkins_mount/jenkins/:/var/jenkins_mount/
- ./Jenkins/data/jenkins/:/var/jenkins_home
- ./Jenkins/run/docker.sock:/var/run/docker.sock
- ./Jenkins/bin/docker:/usr/bin/docker
- ./Jenkins/lib/x86_64-linux-gnu/libltdl.so.7:/usr/lib/x86_64-linux-gnu/libltdl.so.7
ports:
- "4396:8080"
expose:
- "4396"

privileged: true
user: root
restart: always
container_name: jenkins
environment:
JAVA_OPTS: '-Djava.util.logging.config.file=/var/jenkins_home/log.properties'
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
version: '3.8'
services:
sofadashboard:
build: .
image: sofadashboard
depends_on:
- mysql
- zk01
ports:
- "8099:8099"
links:
- zk01
- mysql

mysql:
container_name: mysql57
image: mysql:5.7.31
restart: always
ports:
- "3306:3306"
privileged: true
volumes:
- ./SOFADashboard/mysql57/log:/var/log/mysql
# - /dockerImages/DockerFileSharing/home/SOFADashboard/mysql57/conf/my.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf
- ./SOFADashboard/mysql57/data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: "123456"
MYSQL_USER: 'root'
MYSQL_PASS: '123456'
command: [
'--character-set-server=utf8mb4',
'--collation-server=utf8mb4_general_ci',
'--max_connections=3000'
]

zk01:
image: zookeeper:3.4.11
restart: always
hostname: zk01
container_name: zk01
ports:
- "2181:2181"
volumes:
- ./SOFADashboard/zookeeper/zk01/data:/data
- ./SOFADashboard/zookeeper/zk01/datalog:/datalog
- ./SOFADashboard/zookeeper/zk01/logs:/logs


networks:
default:
external:
name: my_network
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM java:8

COPY *.jar /app.jar

CMD ["--server.port=8099"]

EXPOSE 8099

ENTRYPOINT ["java","-jar","/app.jar"]
17 changes: 17 additions & 0 deletions sofa-dashboard-backend/sofa-dashboard-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@
</properties>

<dependencies>
<!--knife4j-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>

<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-dashboard-governance</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.alipay.sofa.dashboard.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

@Configuration
@EnableSwagger2WebMvc
public class Swagger2Config {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2).useDefaultResponseMessages(false)
.apiInfo(apiInfo()).groupName("default").select()
.apis(RequestHandlerSelectors.basePackage("com.alipay.sofa.dashboard.controller"))
.paths(PathSelectors.any()).build();

}

private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("SOFADashboard APIs").description("SOFADashboard 接口对接文档")
.termsOfServiceUrl("http://localhost:8099/").version("1.0").build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@
*/
package com.alipay.sofa.dashboard.controller;

import com.alipay.sofa.dashboard.constants.SofaDashboardConstants;
import com.alipay.sofa.dashboard.model.ApplicationInfo;
import com.alipay.sofa.dashboard.spi.AppService;
import com.alipay.sofa.rpc.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -31,12 +35,15 @@
* @author guolei.sgl ([email protected]) 18/12/7 下午5:15
*/
@RestController
@Api(value = SofaDashboardConstants.API_APPLICATION_TAGS, tags = SofaDashboardConstants.API_APPLICATION_TAGS)
@RequestMapping("/api/application")
public class ApplicationController {

@Autowired
private AppService appService;


@ApiOperation(value = "获取应用信息")
@GetMapping
public List<ApplicationInfo> getApplication(@RequestParam(value = "keyword", required = false) String keyword) {
return StringUtils.isEmpty(keyword) ? appService.getAllStatistics() : appService
Expand Down
Loading