Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注意格式化

}
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 @@ -45,8 +44,13 @@ public class ArkMngServiceImpl implements ArkMngService {
private static final Logger LOGGER = LoggerFactory.getLogger(ArkMngServiceImpl.class);

@Autowired
private ArkDao arkDao;

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() {
return doFetchPluginsByName(null);
Expand Down Expand Up @@ -121,12 +125,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 @@ -53,7 +53,6 @@ public class ZkHelper {

@Autowired
ZkCommandClient zkCommandClient;

/**
* 根据应用名获取当前应用的所有实例
*
Expand Down Expand Up @@ -87,7 +86,7 @@ private List<String> getInstanceIpList(String appName) {
List<String> result = null;
CuratorFramework curatorClient = zkCommandClient.getCuratorClient();
String arkAppBasePath = SofaDashboardConstants.SOFA_ARK_ROOT
+ SofaDashboardConstants.SEPARATOR + appName;
+ SofaDashboardConstants.SEPARATOR + appName;
try {
if (checkExist(arkAppBasePath, curatorClient)) {
// 根据应用名获取所有实例信息
Expand All @@ -103,6 +102,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 Expand Up @@ -136,13 +158,13 @@ private boolean checkExist(String path, CuratorFramework curatorClient) {
* @return
*/
public String getAppState(String appName, String ip, String pluginName, String version)
throws Exception {
throws Exception {
String bizPath = SofaDashboardConstants.SOFA_BOOT_CLIENT_ROOT
+ SofaDashboardConstants.SOFA_BOOT_CLIENT_BIZ;
+ SofaDashboardConstants.SOFA_BOOT_CLIENT_BIZ;
CuratorFramework curatorClient = zkCommandClient.getCuratorClient();
if (curatorClient.checkExists().forPath(bizPath) != null) {
String bizAppPath = bizPath + SofaDashboardConstants.SEPARATOR + appName
+ SofaDashboardConstants.SEPARATOR + ip;
+ SofaDashboardConstants.SEPARATOR + ip;
if (curatorClient.checkExists().forPath(bizAppPath) != null) {
byte[] bytes = curatorClient.getData().forPath(bizAppPath);
String data = new String(bytes);
Expand All @@ -154,7 +176,7 @@ public String getAppState(String appName, String ip, String pluginName, String v
String bizName = FastJsonUtils.getString(item, "bizName");
String bizVersion = FastJsonUtils.getString(item, "bizVersion");
if (bizName.equalsIgnoreCase(pluginName)
&& bizVersion.equalsIgnoreCase(version)) {
&& bizVersion.equalsIgnoreCase(version)) {
return FastJsonUtils.getString(item, "bizState");
}
}
Expand All @@ -172,11 +194,11 @@ public String getAppState(String appName, String ip, String pluginName, String v
public ClientResponseModel getBizState(String appName, String ip) throws Exception {
ClientResponseModel result = new ClientResponseModel();
String bizPath = SofaDashboardConstants.SOFA_BOOT_CLIENT_ROOT
+ SofaDashboardConstants.SOFA_BOOT_CLIENT_BIZ;
+ SofaDashboardConstants.SOFA_BOOT_CLIENT_BIZ;
CuratorFramework curatorClient = zkCommandClient.getCuratorClient();
if (curatorClient.checkExists().forPath(bizPath) != null) {
String bizAppPath = bizPath + SofaDashboardConstants.SEPARATOR + appName
+ SofaDashboardConstants.SEPARATOR + ip;
+ SofaDashboardConstants.SEPARATOR + ip;
if (curatorClient.checkExists().forPath(bizAppPath) != null) {
byte[] bytes = curatorClient.getData().forPath(bizAppPath);
String data = new String(bytes);
Expand All @@ -199,12 +221,12 @@ public ClientResponseModel getBizState(String appName, String ip) throws Excepti
bizModel.setClassPath(getUrls("classPath", item));
bizModel.setDenyImportClasses(parseBizStateByKey("denyImportClasses", item));
bizModel.setDenyImportPackageNodes(parseBizStateByKey("denyImportPackageNodes",
item));
item));
bizModel.setDenyImportPackageStems(parseBizStateByKey("denyImportPackageStems",
item));
item));
bizModel.setDenyImportPackages(parseBizStateByKey("denyImportPackages", item));
bizModel
.setDenyImportResources(parseBizStateByKey("denyImportResources", item));
.setDenyImportResources(parseBizStateByKey("denyImportResources", item));
bizModel.setWebContextPath(FastJsonUtils.getString(item, "webContextPath"));
bizModel.setPriority(FastJsonUtils.getInteger(item, "priority"));
bizModel.setBizClassLoader(getClassLoader(item));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
**/
public interface ArkMngService {

/***
* 根据模块Id和应用名字 获取模块是否已关联该应用
* @param mId
* @param appName
* @return
*/
boolean isRelatedByModuleAndApp(int mId,String appName);
/**
* 获取当前所有注册的 plugin 信息
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,10 @@ 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相关接口";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是不是可以考虑使用一个枚举来描述下所有的接口类型,而不是在 常量类中定义

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是个不错的建议

public static final String API_APPLICATION_TAGS = "Application相关接口";
public static final String API_GOVERNANCE_TAGS = "Governance相关接口";
public static final String API_WEB_TAGS = "Web相关接口";

}
19 changes: 19 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,25 @@
</properties>

<dependencies>
<!--knife4j-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>2.0.7</version>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

版本管理在主pom 的 dependentmanagement 中

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

收到

</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
</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,42 @@
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("1.0版本")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不建议在代码中直接使用这种常量,同时也不建议使用中文

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的,这个打算后面换成5个分类,application、arkmng、core、governance、web这样方便开发者对接。

.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 (guolei.sgl@antfin.com) 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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.alipay.sofa.dashboard.response.ResponseEntity;
import com.alipay.sofa.dashboard.service.ArkMngService;
import com.alipay.sofa.dashboard.spi.CommandPushManager;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -44,6 +45,7 @@
* @author: guolei.sgl (guolei.sgl@antfin.com) 18/12/21 下午2:26
* @since:
**/

@RestController
@RequestMapping("/api/arkapp")
public class ArkAppMngController {
Expand Down
Loading