!258 针对nacos增加阿里云MSE的鉴权方式
Merge pull request !258 from 卑微小韩/issues/I8H1LT
This commit is contained in:
commit
ae42bfc31d
|
@ -1,6 +1,7 @@
|
|||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
*
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
|
@ -14,6 +15,6 @@ package com.yomahub.liteflow.enums;
|
|||
*/
|
||||
public enum CmpStepTypeEnum {
|
||||
|
||||
START, END, SINGLE;
|
||||
START, END, SINGLE, WHEN_START, WHEN_END;
|
||||
|
||||
}
|
||||
|
|
|
@ -8,13 +8,17 @@
|
|||
package com.yomahub.liteflow.flow.element.condition;
|
||||
|
||||
import com.yomahub.liteflow.common.LocalDefaultFlowConstant;
|
||||
import com.yomahub.liteflow.enums.CmpStepTypeEnum;
|
||||
import com.yomahub.liteflow.enums.ConditionTypeEnum;
|
||||
import com.yomahub.liteflow.enums.ParallelStrategyEnum;
|
||||
import com.yomahub.liteflow.flow.element.Condition;
|
||||
import com.yomahub.liteflow.flow.entity.CmpStep;
|
||||
import com.yomahub.liteflow.flow.parallel.strategy.ParallelStrategyExecutor;
|
||||
import com.yomahub.liteflow.flow.parallel.strategy.ParallelStrategyHelper;
|
||||
import com.yomahub.liteflow.log.LFLog;
|
||||
import com.yomahub.liteflow.log.LFLoggerManager;
|
||||
import com.yomahub.liteflow.slot.DataBus;
|
||||
import com.yomahub.liteflow.slot.Slot;
|
||||
import com.yomahub.liteflow.thread.ExecutorHelper;
|
||||
|
||||
import java.util.Set;
|
||||
|
@ -64,13 +68,16 @@ public class WhenCondition extends Condition {
|
|||
// 使用线程池执行 when 并发流程
|
||||
// 这块涉及到挺多的多线程逻辑,所以注释比较详细,看到这里的童鞋可以仔细阅读
|
||||
private void executeAsyncCondition(Integer slotIndex) throws Exception {
|
||||
|
||||
Slot slot = DataBus.getSlot(slotIndex);
|
||||
slot.addStep(new CmpStep("-1", "-1", CmpStepTypeEnum.WHEN_START));
|
||||
// 获取并发执行策略
|
||||
ParallelStrategyExecutor parallelStrategyExecutor = ParallelStrategyHelper.loadInstance().buildParallelExecutor(this.getParallelStrategy());
|
||||
|
||||
try {
|
||||
// 执行并发逻辑
|
||||
parallelStrategyExecutor.execute(this, slotIndex);
|
||||
|
||||
} finally {
|
||||
slot.addStep(new CmpStep("-1", "-1", CmpStepTypeEnum.WHEN_END));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isIgnoreError() {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
*
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
|
@ -11,6 +12,7 @@ import cn.hutool.core.collection.ConcurrentHashSet;
|
|||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.enums.CmpStepTypeEnum;
|
||||
import com.yomahub.liteflow.exception.NoSuchContextBeanException;
|
||||
import com.yomahub.liteflow.exception.NullParamException;
|
||||
import com.yomahub.liteflow.flow.element.Condition;
|
||||
|
@ -340,6 +342,21 @@ public class Slot {
|
|||
CmpStep cmpStep;
|
||||
for (Iterator<CmpStep> it = executeSteps.iterator(); it.hasNext();) {
|
||||
cmpStep = it.next();
|
||||
if (CmpStepTypeEnum.WHEN_START.equals(cmpStep.getStepType())) {
|
||||
str.append("【");
|
||||
continue;
|
||||
}
|
||||
if (CmpStepTypeEnum.WHEN_END.equals(cmpStep.getStepType())) {
|
||||
// 如果最后一个是==>则移除最后一个==>
|
||||
if (str.toString().endsWith("==>")) {
|
||||
str.delete(str.length() - 3, str.length());
|
||||
}
|
||||
str.append("】");
|
||||
if (it.hasNext()) {
|
||||
str.append("==>");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (withTimeSpent) {
|
||||
str.append(cmpStep.buildStringWithTime());
|
||||
}
|
||||
|
@ -376,6 +393,21 @@ public class Slot {
|
|||
CmpStep cmpStep;
|
||||
for (Iterator<CmpStep> it = rollbackSteps.iterator(); it.hasNext();) {
|
||||
cmpStep = it.next();
|
||||
if (CmpStepTypeEnum.WHEN_START.equals(cmpStep.getStepType())) {
|
||||
str.append("【");
|
||||
continue;
|
||||
}
|
||||
if (CmpStepTypeEnum.WHEN_END.equals(cmpStep.getStepType())) {
|
||||
// 如果最后一个是==>则移除最后一个==>
|
||||
if (str.toString().endsWith("==>")) {
|
||||
str.delete(str.length() - 3, str.length());
|
||||
}
|
||||
str.append("】");
|
||||
if (it.hasNext()) {
|
||||
str.append("==>");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (withRollbackTimeSpent) {
|
||||
str.append(cmpStep.buildRollbackStringWithTime());
|
||||
}
|
||||
|
|
|
@ -60,6 +60,12 @@ public class NacosXmlELParser extends ClassXmlFlowELParser {
|
|||
if (StrUtil.isBlank(nacosParserVO.getPassword())) {
|
||||
nacosParserVO.setPassword("");
|
||||
}
|
||||
if (StrUtil.isBlank(nacosParserVO.getAccessKey())){
|
||||
nacosParserVO.setAccessKey("");
|
||||
}
|
||||
if (StrUtil.isBlank(nacosParserVO.getSecretKey())){
|
||||
nacosParserVO.setSecretKey("");
|
||||
}
|
||||
helper = new NacosParserHelper(nacosParserVO);
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
|
|
@ -11,7 +11,6 @@ import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Consumer;
|
||||
|
@ -40,11 +39,7 @@ public class NacosParserHelper {
|
|||
catch (Exception ignored) {
|
||||
}
|
||||
if (this.configService == null) {
|
||||
Properties properties = new Properties();
|
||||
properties.put(PropertyKeyConst.SERVER_ADDR, nacosParserVO.getServerAddr());
|
||||
properties.put(PropertyKeyConst.NAMESPACE, nacosParserVO.getNamespace());
|
||||
properties.put(PropertyKeyConst.USERNAME, nacosParserVO.getUsername());
|
||||
properties.put(PropertyKeyConst.PASSWORD, nacosParserVO.getPassword());
|
||||
Properties properties = getProperties(nacosParserVO);
|
||||
this.configService = new NacosConfigService(properties);
|
||||
}
|
||||
}
|
||||
|
@ -53,6 +48,29 @@ public class NacosParserHelper {
|
|||
}
|
||||
}
|
||||
|
||||
private static Properties getProperties(NacosParserVO nacosParserVO) {
|
||||
Properties properties = new Properties();
|
||||
properties.put(PropertyKeyConst.SERVER_ADDR, nacosParserVO.getServerAddr());
|
||||
properties.put(PropertyKeyConst.NAMESPACE, nacosParserVO.getNamespace());
|
||||
if (StrUtil.isNotEmpty(nacosParserVO.getUsername())) {
|
||||
// 用户名密码模式 填写用户名就必有密码
|
||||
if (StrUtil.isEmpty(PropertyKeyConst.PASSWORD)){
|
||||
throw new NacosException("Nacos config password is empty");
|
||||
}
|
||||
// 历史版本会使用用户名密码
|
||||
properties.put(PropertyKeyConst.USERNAME, nacosParserVO.getUsername());
|
||||
properties.put(PropertyKeyConst.PASSWORD, nacosParserVO.getPassword());
|
||||
} else if (StrUtil.isNotEmpty(PropertyKeyConst.ACCESS_KEY)){
|
||||
// 以下为阿里云RAM子账号使用 填写了ak就必有sk
|
||||
if (StrUtil.isEmpty(PropertyKeyConst.SECRET_KEY)){
|
||||
throw new NacosException("Nacos config secretKey is empty");
|
||||
}
|
||||
properties.put(PropertyKeyConst.ACCESS_KEY, nacosParserVO.getAccessKey());
|
||||
properties.put(PropertyKeyConst.SECRET_KEY, nacosParserVO.getSecretKey());
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
try {
|
||||
return configService.getConfig(nacosParserVO.getDataId(), nacosParserVO.getGroup(), 3000L);
|
||||
|
|
|
@ -16,6 +16,10 @@ public class NacosParserVO {
|
|||
|
||||
private String group;
|
||||
|
||||
private String accessKey;
|
||||
|
||||
private String secretKey;
|
||||
|
||||
private String username;
|
||||
|
||||
private String password;
|
||||
|
@ -68,11 +72,33 @@ public class NacosParserVO {
|
|||
this.password = password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NacosParserVO{" + "serverAddr='" + serverAddr + '\'' + ", namespace='" + namespace + '\'' + ", dataId='"
|
||||
+ dataId + '\'' + ", group='" + group + '\'' + ", username='" + username + '\'' + ", password='"
|
||||
+ password + '\'' + '}';
|
||||
public String getAccessKey() {
|
||||
return accessKey;
|
||||
}
|
||||
|
||||
public void setAccessKey(String accessKey) {
|
||||
this.accessKey = accessKey;
|
||||
}
|
||||
|
||||
public String getSecretKey() {
|
||||
return secretKey;
|
||||
}
|
||||
|
||||
public void setSecretKey(String secretKey) {
|
||||
this.secretKey = secretKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NacosParserVO{" +
|
||||
"serverAddr='" + serverAddr + '\'' +
|
||||
", namespace='" + namespace + '\'' +
|
||||
", dataId='" + dataId + '\'' +
|
||||
", group='" + group + '\'' +
|
||||
", accessKey='" + accessKey + '\'' +
|
||||
", secretKey='" + secretKey + '\'' +
|
||||
", username='" + username + '\'' +
|
||||
", password='" + password + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue