Skip to content

Commit 0a78323

Browse files
committed
* 修复 quartz-solon-cloud-plugin quartz.Scheduler 定制无效的问题
* 修复 `minio7-solon-cloud-plugin` bucketDef 无效的问题 * 修复 `minio-solon-cloud-plugin` bucketDef 无效的问题 * 添加 `nacos-solon-cloud-plugin` ak/sk 配置支持 * 添加 `nacos2-solon-cloud-plugin` ak/sk 配置支持 * 添加 `nacos3-solon-cloud-plugin` ak/sk 配置支持
1 parent 4d2b80c commit 0a78323

13 files changed

Lines changed: 110 additions & 24 deletions

File tree

UPDATE_LOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11

2+
### 3.7.5
3+
4+
* 修复 `quartz-solon-cloud-plugin` quartz.Scheduler 定制无效的问题
5+
* 修复 `minio7-solon-cloud-plugin` bucketDef 无效的问题
6+
* 修复 `minio-solon-cloud-plugin` bucketDef 无效的问题
7+
* 添加 `nacos-solon-cloud-plugin` ak/sk 配置支持
8+
* 添加 `nacos2-solon-cloud-plugin` ak/sk 配置支持
9+
* 添加 `nacos3-solon-cloud-plugin` ak/sk 配置支持
10+
11+
212
### 3.7.3
313

414
* 新增 solon-cloud-telemetry 插件

solon-cloud-config-and-discovery/nacos-solon-cloud-plugin/src/main/java/org/noear/solon/cloud/extend/nacos/impl/NacosConfig.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
*/
3030
public class NacosConfig {
3131
public static Properties getServiceProperties(CloudProps cloudProps, Properties properties, String server) {
32-
String username = cloudProps.getUsername();
33-
String password = cloudProps.getPassword();
32+
String username = cloudProps.getUsernameRaw();
33+
String password = cloudProps.getPasswordRaw();
34+
String accessKey = cloudProps.getAccessKeyRaw();
35+
String secretKey = cloudProps.getSecretKeyRaw();
3436

3537
Props parentProps = cloudProps.getProp();
3638
parentProps.forEach((k,v)->{
@@ -57,6 +59,14 @@ public static Properties getServiceProperties(CloudProps cloudProps, Properties
5759
properties.putIfAbsent(PropertyKeyConst.PASSWORD, password);
5860
}
5961

62+
if (Utils.isNotEmpty(accessKey)) {
63+
properties.putIfAbsent(PropertyKeyConst.ACCESS_KEY, username);
64+
}
65+
66+
if (Utils.isNotEmpty(secretKey)) {
67+
properties.putIfAbsent(PropertyKeyConst.SECRET_KEY, password);
68+
}
69+
6070
if (Utils.isNotEmpty(cloudProps.getNamespace())) {
6171
properties.putIfAbsent(PropertyKeyConst.NAMESPACE, cloudProps.getNamespace());
6272
}

solon-cloud-config-and-discovery/nacos2-solon-cloud-plugin/src/main/java/org/noear/solon/cloud/extend/nacos/impl/NacosConfig.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
*/
3030
public class NacosConfig {
3131
public static Properties getServiceProperties(CloudProps cloudProps, Properties properties, String server) {
32-
String username = cloudProps.getUsername();
33-
String password = cloudProps.getPassword();
32+
String username = cloudProps.getUsernameRaw();
33+
String password = cloudProps.getPasswordRaw();
34+
String accessKey = cloudProps.getAccessKeyRaw();
35+
String secretKey = cloudProps.getSecretKeyRaw();
3436

3537
Props parentProps = cloudProps.getProp();
3638
parentProps.forEach((k,v)->{
@@ -57,6 +59,14 @@ public static Properties getServiceProperties(CloudProps cloudProps, Properties
5759
properties.putIfAbsent(PropertyKeyConst.PASSWORD, password);
5860
}
5961

62+
if (Utils.isNotEmpty(accessKey)) {
63+
properties.putIfAbsent(PropertyKeyConst.ACCESS_KEY, username);
64+
}
65+
66+
if (Utils.isNotEmpty(secretKey)) {
67+
properties.putIfAbsent(PropertyKeyConst.SECRET_KEY, password);
68+
}
69+
6070
if (Utils.isNotEmpty(cloudProps.getNamespace())) {
6171
properties.putIfAbsent(PropertyKeyConst.NAMESPACE, cloudProps.getNamespace());
6272
}

solon-cloud-config-and-discovery/nacos3-solon-cloud-plugin/src/main/java/org/noear/solon/cloud/extend/nacos/impl/NacosConfig.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
*/
2929
public class NacosConfig {
3030
public static Properties getServiceProperties(CloudProps cloudProps, Properties properties, String server) {
31-
String username = cloudProps.getUsername();
32-
String password = cloudProps.getPassword();
31+
String username = cloudProps.getUsernameRaw();
32+
String password = cloudProps.getPasswordRaw();
33+
String accessKey = cloudProps.getAccessKeyRaw();
34+
String secretKey = cloudProps.getSecretKeyRaw();
3335

3436
Props parentProps = cloudProps.getProp();
3537
parentProps.forEach((k, v) -> {
@@ -56,6 +58,14 @@ public static Properties getServiceProperties(CloudProps cloudProps, Properties
5658
properties.putIfAbsent(PropertyKeyConst.PASSWORD, password);
5759
}
5860

61+
if (Utils.isNotEmpty(accessKey)) {
62+
properties.putIfAbsent(PropertyKeyConst.ACCESS_KEY, username);
63+
}
64+
65+
if (Utils.isNotEmpty(secretKey)) {
66+
properties.putIfAbsent(PropertyKeyConst.SECRET_KEY, password);
67+
}
68+
5969
if (Utils.isNotEmpty(cloudProps.getNamespace())) {
6070
properties.putIfAbsent(PropertyKeyConst.NAMESPACE, cloudProps.getNamespace());
6171
}

solon-cloud-file/minio-solon-cloud-plugin/src/main/java/org/noear/solon/cloud/extend/minio/service/CloudFileServiceMinioImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ public boolean exists(String bucket, String key) throws CloudFileException {
9696

9797
@Override
9898
public String getTempUrl(String bucket, String key, Duration duration) throws CloudFileException, UnsupportedOperationException {
99+
if (Utils.isEmpty(bucket)) {
100+
bucket = this.bucketDef;
101+
}
99102

100103
long seconds = duration.getSeconds();
101104

solon-cloud-file/minio7-solon-cloud-plugin/src/main/java/org/noear/solon/cloud/extend/minio/service/CloudFileServiceMinioImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ public boolean exists(String bucket, String key) throws CloudFileException {
9898

9999
@Override
100100
public String getTempUrl(String bucket, String key, Duration duration) throws CloudFileException, UnsupportedOperationException {
101+
if (Utils.isEmpty(bucket)) {
102+
bucket = this.bucketDef;
103+
}
101104

102105
long seconds = duration.getSeconds();
103106

solon-cloud-job/quartz-solon-cloud-plugin/src/main/java/org/noear/solon/cloud/extend/quartz/JobManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.noear.solon.cloud.model.JobHolder;
1919

20+
import java.util.Collection;
2021
import java.util.HashMap;
2122
import java.util.Map;
2223

@@ -35,6 +36,10 @@ public static void addJob(String name, JobHolder handler) {
3536
jobMap.put(name, handler);
3637
}
3738

39+
public static Collection<JobHolder> getJobs() {
40+
return jobMap.values();
41+
}
42+
3843
public static JobHolder getJob(String name) {
3944
return jobMap.get(name);
4045
}

solon-cloud-job/quartz-solon-cloud-plugin/src/main/java/org/noear/solon/cloud/extend/quartz/integration/QuartzCloudPlugin.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.noear.solon.core.AppContext;
2323
import org.noear.solon.core.Plugin;
2424
import org.noear.solon.core.event.AppLoadEndEvent;
25+
import org.quartz.Scheduler;
2526

2627
/**
2728
* @author noear
@@ -36,16 +37,17 @@ public void start(AppContext context) throws Throwable {
3637
return;
3738
}
3839

40+
CloudJobServiceImpl jobService = new CloudJobServiceImpl();
41+
3942
//注册Job服务
40-
CloudManager.register(CloudJobServiceImpl.instance);
43+
CloudManager.register(jobService);
4144

42-
// CloudJobBeanBuilder.getInstance().addBuilder(Job.class, (clz, bw, anno) -> {
43-
// String name = Utils.annoAlias(anno.value(), anno.name());
44-
// CloudJobServiceImpl.instance.registerDo(name, anno.cron7x(), anno.description(), ((Job) bw.raw()).getClass());
45-
// });
45+
context.getBeanAsync(Scheduler.class, bean -> {
46+
jobService.setScheduler(bean);
47+
});
4648

4749
Solon.app().onEvent(AppLoadEndEvent.class, e -> {
48-
CloudJobServiceImpl.instance.start();
50+
jobService.start();
4951
});
5052
}
5153
}

solon-cloud-job/quartz-solon-cloud-plugin/src/main/java/org/noear/solon/cloud/extend/quartz/service/CloudJobServiceImpl.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
* @since 1.11
3434
*/
3535
public class CloudJobServiceImpl implements CloudJobService {
36-
public static final CloudJobServiceImpl instance = new CloudJobServiceImpl();
37-
3836
private Scheduler _scheduler = null;
3937

4038
public void setScheduler(Scheduler scheduler) {
@@ -63,30 +61,29 @@ private void tryInitScheduler() throws SchedulerException {
6361
@Override
6462
public boolean register(String name, String cron7x, String description, CloudJobHandler handler) {
6563
JobManager.addJob(name, new JobHolder(name, cron7x, description, handler));
66-
return registerDo(name, cron7x, description, JobQuartzProxy.class);
64+
return true;
6765
}
6866

69-
public boolean registerDo(String name, String cron7xStr, String description, Class<? extends Job> jobClz) {
67+
protected void registerDo(JobHolder jobHolder) {
68+
Class<? extends Job> jobClz = JobQuartzProxy.class;
7069
String jobGroup = Utils.annoAlias(Solon.cfg().appName(), "solon");
71-
JobKey jobKey = JobKey.jobKey(name, jobGroup);
70+
JobKey jobKey = JobKey.jobKey(jobHolder.getName(), jobGroup);
7271

7372
try {
7473
tryInitScheduler();
7574

7675
if (_scheduler.checkExists(jobKey) == false) {
77-
Cron7X cron7X = Cron7X.parse(cron7xStr);
76+
Cron7X cron7X = Cron7X.parse(jobHolder.getCron7x());
7877

7978
if (Utils.isEmpty(cron7X.getCron())) {
80-
regJobByPeriod(jobKey, name, description, cron7X, jobGroup, jobClz);
79+
regJobByPeriod(jobKey, jobHolder.getName(), jobHolder.getDescription(), cron7X, jobGroup, jobClz);
8180
} else {
82-
regJobByCron(jobKey, name, description, cron7X, jobGroup, jobClz);
81+
regJobByCron(jobKey, jobHolder.getName(), jobHolder.getDescription(), cron7X, jobGroup, jobClz);
8382
}
8483
}
8584
} catch (SchedulerException e) {
8685
throw new CloudJobException(e);
8786
}
88-
89-
return true;
9087
}
9188

9289
@Override
@@ -100,6 +97,10 @@ public boolean isRegistered(String name) {
10097
public void start() throws SchedulerException {
10198
tryInitScheduler();
10299

100+
for (JobHolder job : JobManager.getJobs()) {
101+
registerDo(job);
102+
}
103+
103104
if (_scheduler != null) {
104105
_scheduler.start();
105106
}

solon-cloud/solon-cloud/src/main/java/org/noear/solon/cloud/CloudClient.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class CloudClient {
4242
private static boolean enableEvent = true;
4343
private static boolean enableBreaker = true;
4444
private static boolean enableJob = true;
45+
private static boolean enableRegister = true;
4546

4647
/**
4748
* 是否启用 @CloudConfig 注解
@@ -71,6 +72,13 @@ public static boolean enableJob() {
7172
return enableJob;
7273
}
7374

75+
/**
76+
* 是否启用服务注册
77+
*/
78+
public static boolean enableRegister() {
79+
return enableRegister;
80+
}
81+
7482
/**
7583
* 配置:是否启用 @CloudConfig 注解
7684
*/
@@ -99,6 +107,13 @@ public static void enableJob(boolean enable) {
99107
enableJob = enable;
100108
}
101109

110+
/**
111+
* 配置:是否启用服务注册
112+
*/
113+
public static void enableRegister(boolean enable) {
114+
enableRegister = enable;
115+
}
116+
102117

103118
/**
104119
* 获取 负载均衡工厂

0 commit comments

Comments
 (0)