Skip to content

Commit

Permalink
Merge pull request #254 from erupts/develop
Browse files Browse the repository at this point in the history
1.12.13
  • Loading branch information
erupts authored May 27, 2024
2 parents ae45638 + 38c5537 commit c121e55
Show file tree
Hide file tree
Showing 58 changed files with 386 additions and 232 deletions.
2 changes: 1 addition & 1 deletion erupt-admin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>xyz.erupt</groupId>
<artifactId>erupt</artifactId>
<version>1.12.12</version>
<version>1.12.13</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion erupt-annotation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>xyz.erupt</groupId>
<artifactId>erupt</artifactId>
<version>1.12.12</version>
<version>1.12.13</version>
<relativePath>../pom.xml</relativePath>
</parent>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@
* @author YuePeng
* date 2018-10-09.
*/
public interface OperationHandler<@Comment("行数据类型") Target, @Comment("表单输入对象类型") EruptObject> {
public interface OperationHandler<@Comment("行数据类型") Row, @Comment("表单输入对象类型") EruptForm> {

/**
* @param data 行数据
* @param eruptObject 表单输入数据
* @param param 注解回传参数
* @param data 行数据
* @param eruptForm 表单输入数据
* @param param 注解回传参数
* @return 事件触发成功后需要前端执行的 js 表达式
*/
@Comment("按钮事件触发类")
@Comment("返回值:事件触发成功后需要前端执行的 js 表达式,不需要此参数返回空即可")
String exec(List<Target> data, EruptObject eruptObject, String[] param);
String exec(List<Row> data, EruptForm eruptForm, String[] param);

@Comment("初始化 erupt 表单的值")
default EruptForm eruptFormValue(List<Row> data, EruptForm eruptForm, String[] param) {
return eruptForm;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
//可选分页数
int[] pageSizes() default {10, 20, 30, 50, 100, 300, 500};

//数据更新时间,单位:毫秒
int refreshTime() default -1;

enum FormSize {
//默认
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@
@Transient
@Comment("Column in linkErupt → this.column = linkErupt.joinColumn")
String joinColumn();

@Comment("Other conditions for the link")
String linkCondition() default "";
}
2 changes: 1 addition & 1 deletion erupt-cloud/erupt-cloud-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>xyz.erupt</groupId>
<artifactId>erupt</artifactId>
<version>1.12.12</version>
<version>1.12.13</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion erupt-cloud/erupt-cloud-node-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>xyz.erupt</groupId>
<artifactId>erupt</artifactId>
<version>1.12.12</version>
<version>1.12.13</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion erupt-cloud/erupt-cloud-node/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>xyz.erupt</groupId>
<artifactId>erupt</artifactId>
<version>1.12.12</version>
<version>1.12.13</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion erupt-cloud/erupt-cloud-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>xyz.erupt</groupId>
<artifactId>erupt</artifactId>
<version>1.12.12</version>
<version>1.12.13</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import xyz.erupt.annotation.fun.PowerObject;
import xyz.erupt.cloud.common.consts.CloudCommonConst;
import xyz.erupt.cloud.common.consts.CloudRestApiConst;
import xyz.erupt.cloud.server.model.CloudNode;
import xyz.erupt.cloud.server.service.EruptNodeMicroservice;
import xyz.erupt.core.annotation.EruptRouter;
import xyz.erupt.core.constant.EruptConst;
Expand Down Expand Up @@ -62,10 +63,8 @@ public PowerObject eruptPower(@RequestParam String eruptName, @RequestParam Stri

@GetMapping(CloudRestApiConst.NODE_CONFIG + "/{nodeName}")
public String getNodeConfig(@PathVariable String nodeName, @RequestHeader(CloudCommonConst.HEADER_ACCESS_TOKEN) String accessToken) {
return (String) eruptDao.getEntityManager()
.createQuery("select config from CloudNode where nodeName = :nodeName and accessToken = :accessToken")
.setParameter("nodeName", nodeName)
.setParameter("accessToken", accessToken).getSingleResult();
return eruptDao.lambdaQuery(CloudNode.class).eq(CloudNode::getNodeName, nodeName)
.eq(CloudNode::getAccessToken, accessToken).oneSelect(CloudNode::getConfig);
}

@GetMapping(CloudRestApiConst.NODE_GROUP_CONFIG + "/{nodeName}")
Expand All @@ -77,7 +76,6 @@ public String getNodeGroupConfig(@PathVariable String nodeName, @RequestHeader(C
}



//用户信息
@GetMapping(CloudRestApiConst.ERUPT_USER_INFO + "/{nodeName}")
@EruptRouter(verifyType = EruptRouter.VerifyType.LOGIN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import xyz.erupt.annotation.EruptI18n;
import xyz.erupt.annotation.constant.AnnotationConst;
import xyz.erupt.annotation.expr.ExprBool;
import xyz.erupt.annotation.fun.DataProxy;
import xyz.erupt.annotation.fun.TagsFetchHandler;
import xyz.erupt.annotation.sub_erupt.Layout;
import xyz.erupt.annotation.sub_erupt.RowOperation;
import xyz.erupt.annotation.sub_erupt.Tpl;
Expand All @@ -24,23 +22,10 @@
import xyz.erupt.annotation.sub_field.sub_edit.Search;
import xyz.erupt.annotation.sub_field.sub_edit.TagsType;
import xyz.erupt.cloud.server.base.CloudServerConst;
import xyz.erupt.cloud.server.node.MetaNode;
import xyz.erupt.cloud.server.node.NodeManager;
import xyz.erupt.core.config.GsonFactory;
import xyz.erupt.core.util.Erupts;
import xyz.erupt.jpa.dao.EruptDao;
import xyz.erupt.jpa.model.MetaModelUpdateVo;
import xyz.erupt.linq.lambda.LambdaSee;
import xyz.erupt.tpl.engine.EngineConst;
import xyz.erupt.upms.handler.ViaMenuValueCtrl;

import javax.annotation.Resource;
import javax.persistence.*;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;

/**
* @author YuePeng
Expand All @@ -52,7 +37,7 @@
@Entity
@Table(name = "e_cloud_node")
@Erupt(
name = "节点配置", dataProxy = CloudNode.class,
name = "节点配置", dataProxy = CloudNodeProcess.class,
rowOperation = @RowOperation(
title = "查看令牌", icon = "fa fa-shield", mode = RowOperation.Mode.SINGLE,
show = @ExprBool(exprHandler = ViaMenuValueCtrl.class, params = CloudServerConst.CLOUD_ACCESS_TOKEN_PERMISSION),
Expand All @@ -61,11 +46,7 @@
)
@Component
@EruptI18n
public class CloudNode extends MetaModelUpdateVo implements DataProxy<CloudNode>, TagsFetchHandler, Tpl.TplHandler {

public static final String NODE_NAME = LambdaSee.field(CloudNode::getNodeName);

public static final String ACCESS_TOKEN = LambdaSee.field(CloudNode::getAccessToken);
public class CloudNode extends MetaModelUpdateVo {

@Column(unique = true)
@EruptField(
Expand Down Expand Up @@ -110,7 +91,7 @@ public class CloudNode extends MetaModelUpdateVo implements DataProxy<CloudNode>
@Transient
@EruptField(
views = @View(title = "实例数", className = "text-center", width = "70px"
, tpl = @Tpl(path = "/tpl/node-instance.ftl", width = "400px", tplHandler = CloudNode.class)
, tpl = @Tpl(path = "/tpl/node-instance.ftl", width = "400px", tplHandler = CloudNodeProcess.class)
)
)
private Integer instanceNum;
Expand All @@ -124,7 +105,7 @@ public class CloudNode extends MetaModelUpdateVo implements DataProxy<CloudNode>
@EruptField(
views = @View(title = "负责人", sortable = true),
edit = @Edit(title = "负责人", type = EditType.TAGS,
tagsType = @TagsType(fetchHandler = CloudNode.class), notNull = true)
tagsType = @TagsType(fetchHandler = CloudNodeProcess.class), notNull = true)
)
private String duty;

Expand All @@ -148,75 +129,5 @@ public class CloudNode extends MetaModelUpdateVo implements DataProxy<CloudNode>
)
private String remark;

@Transient
@Resource
private NodeManager nodeManager;

@Transient
@Resource
private EruptDao eruptDao;

@Override
public void afterUpdate(CloudNode cloudNode) {
DataProxy.super.afterUpdate(cloudNode);
}

@Override
public void beforeAdd(CloudNode cloudNode) {
if (null == cloudNode.getAccessToken()) cloudNode.setAccessToken(Erupts.generateCode(16).toUpperCase());
}

@Override
public void beforeUpdate(CloudNode cloudNode) {
this.beforeAdd(cloudNode);
}

@Override
public void afterFetch(Collection<Map<String, Object>> list) {
for (Map<String, Object> map : list) {
Optional.ofNullable(map.get(ACCESS_TOKEN)).ifPresent(it -> {
String token = it.toString();
map.put(ACCESS_TOKEN, token.substring(0, 3) + "******" + token.substring(token.length() - 3));
});
map.put(LambdaSee.field(CloudNode::getEruptNum), '-');
map.put(LambdaSee.field(CloudNode::getInstanceNum), '-');
map.put(LambdaSee.field(CloudNode::getVersion), '-');
map.put(LambdaSee.field(CloudNode::getEruptModuleNum), '-');
try {
MetaNode metaNode = nodeManager.getNode(map.get(NODE_NAME).toString());
Optional.ofNullable(nodeManager.getNode(map.get(NODE_NAME).toString())).ifPresent(metaNode1 -> {
Function<Collection<String>, Object> function = (it) -> null == it ? 0 : String.format("<a href='javascript:alert(`%s`);'>%d</a>", String.join("\\u000a", it), it.size());
map.put(LambdaSee.field(CloudNode::getEruptNum), function.apply(metaNode.getErupts()));
map.put(LambdaSee.field(CloudNode::getInstanceNum), metaNode.getLocations().size());
map.put(LambdaSee.field(CloudNode::getEruptModuleNum), function.apply(metaNode.getEruptModules()));
map.put(LambdaSee.field(CloudNode::getVersion), metaNode.getVersion());
});
} catch (Exception e) {
map.put(LambdaSee.field(CloudNode::getVersion), String.format("<span style='color:#f00'>%s</span>", e.getMessage()));
log.warn("node warn → " + map.get(NODE_NAME), e);
}
}
}

@Override
public void afterDelete(CloudNode cloudNode) {
nodeManager.removeNode(cloudNode.getNodeName());
}

@Override
public List<String> fetchTags(String[] params) {
return eruptDao.getJdbcTemplate().queryForList("select name from e_upms_user", String.class);
}

@Override
public void bindTplData(Map<String, Object> binding, String[] params) {
CloudNode cloudNode = (CloudNode) binding.get(EngineConst.INJECT_ROW);
MetaNode metaNode = nodeManager.getNode(cloudNode.getNodeName());
if (null == metaNode) {
binding.put("instances", "[]");
} else {
binding.put("instances", GsonFactory.getGson().toJson(metaNode.getLocations()));
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package xyz.erupt.cloud.server.model;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import xyz.erupt.annotation.fun.DataProxy;
import xyz.erupt.annotation.fun.TagsFetchHandler;
import xyz.erupt.annotation.sub_erupt.Tpl;
import xyz.erupt.cloud.server.node.MetaNode;
import xyz.erupt.cloud.server.node.NodeManager;
import xyz.erupt.core.config.GsonFactory;
import xyz.erupt.core.util.Erupts;
import xyz.erupt.jpa.dao.EruptDao;
import xyz.erupt.linq.lambda.LambdaSee;
import xyz.erupt.tpl.engine.EngineConst;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;

/**
* @author YuePeng
* date 2024/5/7 22:02
*/
@Component
@Slf4j
public class CloudNodeProcess implements DataProxy<CloudNode>, TagsFetchHandler, Tpl.TplHandler {

@Resource
private NodeManager nodeManager;

@Resource
private EruptDao eruptDao;

@Override
public void afterUpdate(CloudNode cloudNode) {
DataProxy.super.afterUpdate(cloudNode);
}

@Override
public void beforeAdd(CloudNode cloudNode) {
if (null == cloudNode.getAccessToken()) cloudNode.setAccessToken(Erupts.generateCode(16).toUpperCase());
}

@Override
public void beforeUpdate(CloudNode cloudNode) {
this.beforeAdd(cloudNode);
}

@Override
public void afterFetch(Collection<Map<String, Object>> list) {
String nodeNameField = LambdaSee.field(CloudNode::getNodeName);
for (Map<String, Object> map : list) {
Optional.ofNullable(map.get(LambdaSee.field(CloudNode::getAccessToken))).ifPresent(it -> {
String token = it.toString();
map.put(LambdaSee.field(CloudNode::getAccessToken), token.substring(0, 3) + "******" + token.substring(token.length() - 3));
});
map.put(LambdaSee.field(CloudNode::getEruptNum), '-');
map.put(LambdaSee.field(CloudNode::getInstanceNum), '-');
map.put(LambdaSee.field(CloudNode::getVersion), '-');
map.put(LambdaSee.field(CloudNode::getEruptModuleNum), '-');
try {
MetaNode metaNode = nodeManager.getNode(map.get(nodeNameField).toString());
Optional.ofNullable(nodeManager.getNode(map.get(nodeNameField).toString())).ifPresent(metaNode1 -> {
Function<Collection<String>, Object> function = (it) -> null == it ? 0 : String.format("<a href='javascript:alert(`%s`);'>%d</a>", String.join("\\u000a", it), it.size());
map.put(LambdaSee.field(CloudNode::getEruptNum), function.apply(metaNode.getErupts()));
map.put(LambdaSee.field(CloudNode::getInstanceNum), metaNode.getLocations().size());
map.put(LambdaSee.field(CloudNode::getEruptModuleNum), function.apply(metaNode.getEruptModules()));
map.put(LambdaSee.field(CloudNode::getVersion), metaNode.getVersion());
});
} catch (Exception e) {
map.put(LambdaSee.field(CloudNode::getVersion), String.format("<span style='color:#f00'>%s</span>", e.getMessage()));
log.warn("node warn → " + map.get(nodeNameField), e);
}
}
}

@Override
public void afterDelete(CloudNode cloudNode) {
nodeManager.removeNode(cloudNode.getNodeName());
}

@Override
public List<String> fetchTags(String[] params) {
return eruptDao.getJdbcTemplate().queryForList("select name from e_upms_user", String.class);
}

@Override
public void bindTplData(Map<String, Object> binding, String[] params) {
CloudNode cloudNode = (CloudNode) binding.get(EngineConst.INJECT_ROW);
MetaNode metaNode = nodeManager.getNode(cloudNode.getNodeName());
if (null == metaNode) {
binding.put("instances", "[]");
} else {
binding.put("instances", GsonFactory.getGson().toJson(metaNode.getLocations()));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void removeNodeInstance(String nodeName, String instanceAddress) {


public List<MetaNode> findAllNodes() {
List<String> keys = eruptDao.queryEntityList(CloudNode.class).stream().map(it ->
List<String> keys = eruptDao.lambdaQuery(CloudNode.class).list().stream().map(it ->
eruptCloudServerProp.getCloudNameSpace() + NODE_SPACE + it.getNodeName()
).collect(Collectors.toList());
if (!keys.isEmpty()) {
Expand Down
Loading

0 comments on commit c121e55

Please sign in to comment.