Skip to content

Commit 96bda95

Browse files
committed
#570 fix for branch 3.3.1
1 parent 19ee9a9 commit 96bda95

File tree

3 files changed

+84
-79
lines changed

3 files changed

+84
-79
lines changed

saturn-console-api/src/main/java/com/vip/saturn/job/console/domain/JobConfig.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
import java.io.Serializable;
66

7-
/**
8-
* @author chembo.huang
9-
*/
107
public class JobConfig implements Serializable {
118

129
private static final long serialVersionUID = 7366583369937964951L;
@@ -38,7 +35,7 @@ public class JobConfig implements Serializable {
3835
private Boolean useSerial;
3936
private Boolean failover;
4037
private String jobMode; // 系统作业等
41-
private String customContext;
38+
private String customContext; // 仅仅用于动态更新cron时携带的上下文数据
4239
/**
4340
* @deprecated replaced by downStream
4441
*/
@@ -63,6 +60,7 @@ public void setDefaultValues() {
6360
cron = getDefaultIfNull(cron, "");
6461
pausePeriodDate = getDefaultIfNull(pausePeriodDate, "");
6562
pausePeriodTime = getDefaultIfNull(pausePeriodTime, "");
63+
shardingItemParameters = getDefaultIfNull(shardingItemParameters, "");
6664
jobParameter = getDefaultIfNull(jobParameter, "");
6765
processCountIntervalSeconds = getDefaultIfNull(processCountIntervalSeconds, 300);
6866
description = getDefaultIfNull(description, "");
@@ -84,6 +82,7 @@ public void setDefaultValues() {
8482
useSerial = getDefaultIfNull(useSerial, Boolean.FALSE);
8583
failover = getDefaultIfNull(failover, !localMode); // 已经设置localMode
8684
jobMode = getDefaultIfNull(jobMode, "");
85+
customContext = getDefaultIfNull(customContext, "{}");
8786
dependencies = getDefaultIfNull(dependencies, "");
8887
groups = getDefaultIfNull(groups, "");
8988
rerun = getDefaultIfNull(rerun, Boolean.FALSE);

saturn-console-api/src/main/java/com/vip/saturn/job/console/repository/zookeeper/CuratorRepository.java

+12-16
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import java.util.Collection;
1717
import java.util.List;
18-
import java.util.concurrent.atomic.AtomicInteger;
1918

2019
public interface CuratorRepository {
2120

@@ -27,21 +26,21 @@ public interface CuratorRepository {
2726

2827
interface CuratorFrameworkOp {
2928

30-
boolean checkExists(String znode);
29+
boolean checkExists(String node);
3130

32-
String getData(String znode);
31+
String getData(String node);
3332

34-
List<String> getChildren(String znode);
33+
List<String> getChildren(String node);
3534

36-
void create(String znode);
35+
void create(String node);
3736

38-
void create(final String znode, Object value);
37+
void create(final String node, Object value);
3938

40-
void update(String znode, Object value);
39+
void update(String node, Object value);
4140

42-
void delete(String znode);
41+
void delete(String node);
4342

44-
void deleteRecursive(String znode);
43+
void deleteRecursive(String node);
4544

4645
void fillJobNodeIfNotExist(String node, Object value);
4746

@@ -57,16 +56,13 @@ interface CuratorFrameworkOp {
5756

5857
interface CuratorTransactionOp {
5958

60-
CuratorTransactionOp replace(String znode, Object value) throws Exception;
59+
CuratorTransactionOp replace(String node, Object value) throws Exception;
6160

62-
CuratorTransactionOp replaceIfChanged(String znode, Object value) throws Exception;
61+
CuratorTransactionOp replaceIfChanged(String node, Object value) throws Exception;
6362

64-
CuratorTransactionOp replaceIfChanged(String znode, Object value, AtomicInteger changedCount)
65-
throws Exception;
63+
CuratorTransactionOp create(String node, Object value) throws Exception;
6664

67-
CuratorTransactionOp create(String znode, Object value) throws Exception;
68-
69-
CuratorTransactionOp delete(String znode) throws Exception;
65+
CuratorTransactionOp delete(String node) throws Exception;
7066

7167
Collection<CuratorTransactionResult> commit() throws Exception;
7268
}

saturn-console-api/src/main/java/com/vip/saturn/job/console/repository/zookeeper/impl/CuratorRepositoryImpl.java

+69-59
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import java.util.Collection;
3737
import java.util.List;
3838
import java.util.concurrent.TimeUnit;
39-
import java.util.concurrent.atomic.AtomicInteger;
4039

4140
@Repository
4241
public class CuratorRepositoryImpl implements CuratorRepository {
@@ -109,9 +108,9 @@ public CuratorFrameworkOpImpl(CuratorFramework curatorFramework) {
109108
}
110109

111110
@Override
112-
public boolean checkExists(final String znode) {
111+
public boolean checkExists(final String node) {
113112
try {
114-
return null != curatorFramework.checkExists().forPath(znode);
113+
return null != curatorFramework.checkExists().forPath(node);
115114
// CHECKSTYLE:OFF
116115
} catch (final Exception ex) {
117116
// CHECKSTYLE:ON
@@ -120,15 +119,15 @@ public boolean checkExists(final String znode) {
120119
}
121120

122121
@Override
123-
public String getData(final String znode) {
122+
public String getData(final String node) {
124123
try {
125-
if (checkExists(znode)) {
126-
byte[] getZnodeData = curatorFramework.getData().forPath(znode);
127-
if (getZnodeData == null) {// executor的分片可能存在全部飘走的情况,sharding节点有可能获取到的是null,需要对null做判断,否则new
124+
if (checkExists(node)) {
125+
byte[] nodeData = curatorFramework.getData().forPath(node);
126+
if (nodeData == null) {// executor的分片可能存在全部飘走的情况,sharding节点有可能获取到的是null,需要对null做判断,否则new
128127
// String时会报空指针异常
129128
return null;
130129
}
131-
return new String(getZnodeData, Charset.forName("UTF-8"));
130+
return new String(nodeData, Charset.forName("UTF-8"));
132131
} else {
133132
return null;
134133
}
@@ -142,9 +141,9 @@ public String getData(final String znode) {
142141
}
143142

144143
@Override
145-
public List<String> getChildren(final String znode) {
144+
public List<String> getChildren(final String node) {
146145
try {
147-
return curatorFramework.getChildren().forPath(znode);
146+
return curatorFramework.getChildren().forPath(node);
148147
// CHECKSTYLE:OFF
149148
} catch (final NoNodeException ignore) {
150149
return null;
@@ -156,15 +155,19 @@ public List<String> getChildren(final String znode) {
156155
}
157156

158157
@Override
159-
public void create(final String znode) {
160-
create(znode, "");
158+
public void create(final String node) {
159+
create(node, "");
161160
}
162161

163162
@Override
164-
public void create(final String znode, Object data) {
163+
public void create(final String node, Object value) {
164+
if (value == null) {
165+
log.info("node value is null, won't create, node: {}", node);
166+
return;
167+
}
165168
try {
166169
curatorFramework.create().creatingParentsIfNeeded()
167-
.forPath(znode, data.toString().getBytes(Charset.forName("UTF-8")));
170+
.forPath(node, value.toString().getBytes(Charset.forName("UTF-8")));
168171
} catch (final NodeExistsException ignore) {
169172
// CHECKSTYLE:OFF
170173
} catch (final Exception ex) {
@@ -173,13 +176,18 @@ public void create(final String znode, Object data) {
173176
}
174177
}
175178

176-
public void update(final String znode, final Object value) {
179+
@Override
180+
public void update(final String node, final Object value) {
181+
if (value == null) {
182+
log.info("node value is null, won't update, node: {}", node);
183+
return;
184+
}
177185
try {
178-
if (this.checkExists(znode)) {
179-
curatorFramework.inTransaction().check().forPath(znode).and().setData()
180-
.forPath(znode, value.toString().getBytes(Charset.forName("UTF-8"))).and().commit();
186+
if (this.checkExists(node)) {
187+
curatorFramework.inTransaction().check().forPath(node).and().setData()
188+
.forPath(node, value.toString().getBytes(Charset.forName("UTF-8"))).and().commit();
181189
} else {
182-
this.create(znode, value);
190+
this.create(node, value);
183191
}
184192
} catch (final NoNodeException ignore) {
185193
// CHECKSTYLE:OFF
@@ -190,10 +198,10 @@ public void update(final String znode, final Object value) {
190198
}
191199

192200
@Override
193-
public void delete(final String znode) {
201+
public void delete(final String node) {
194202
try {
195-
if (null != curatorFramework.checkExists().forPath(znode)) {
196-
curatorFramework.delete().forPath(znode);
203+
if (null != curatorFramework.checkExists().forPath(node)) {
204+
curatorFramework.delete().forPath(node);
197205
}
198206
} catch (final NoNodeException ignore) {
199207
// CHECKSTYLE:OFF
@@ -204,10 +212,10 @@ public void delete(final String znode) {
204212
}
205213

206214
@Override
207-
public void deleteRecursive(final String znode) {
215+
public void deleteRecursive(final String node) {
208216
try {
209-
if (null != curatorFramework.checkExists().forPath(znode)) {
210-
CuratorUtils.deletingChildrenIfNeeded(curatorFramework, znode);
217+
if (null != curatorFramework.checkExists().forPath(node)) {
218+
CuratorUtils.deletingChildrenIfNeeded(curatorFramework, node);
211219
}
212220
} catch (final NoNodeException ignore) {
213221
// CHECKSTYLE:OFF
@@ -225,8 +233,8 @@ public void deleteRecursive(final String znode) {
225233
*/
226234
@Override
227235
public void fillJobNodeIfNotExist(final String node, final Object value) {
228-
if (null == value) {
229-
log.info("job node value is null, node:{}", node);
236+
if (value == null) {
237+
log.info("node value is null, won't fillJobNodeIfNotExist, node: {}", node);
230238
return;
231239
}
232240
if (!checkExists(node)) {
@@ -311,22 +319,18 @@ public CuratorTransactionOpImpl(CuratorFramework curatorClient) {
311319
}
312320
}
313321

314-
private boolean checkExists(String znode) throws Exception {
315-
return curatorClient.checkExists().forPath(znode) != null;
322+
private boolean checkExists(String node) throws Exception {
323+
return curatorClient.checkExists().forPath(node) != null;
316324
}
317325

318-
private CuratorTransactionOpImpl create(String znode, byte[] data) throws Exception {
326+
private CuratorTransactionOpImpl create(String node, byte[] data) throws Exception {
319327
curatorTransactionFinal = curatorTransactionFinal.create().withMode(CreateMode.PERSISTENT)
320-
.forPath(znode, data).and();
328+
.forPath(node, data).and();
321329
return this;
322330
}
323331

324-
private byte[] getData(String znode) throws Exception {
325-
return curatorClient.getData().forPath(znode);
326-
}
327-
328-
private byte[] toData(Object value) {
329-
return (value == null ? "" : value.toString()).getBytes(Charset.forName("UTF-8"));
332+
private byte[] getData(String node) throws Exception {
333+
return curatorClient.getData().forPath(node);
330334
}
331335

332336
private boolean bytesEquals(byte[] a, byte[] b) {
@@ -345,44 +349,50 @@ private boolean bytesEquals(byte[] a, byte[] b) {
345349
}
346350

347351
@Override
348-
public CuratorTransactionOpImpl replace(String znode, Object value) throws Exception {
349-
byte[] data = toData(value);
350-
curatorTransactionFinal = curatorTransactionFinal.setData().forPath(znode, data).and();
352+
public CuratorTransactionOpImpl replace(String node, Object value) throws Exception {
353+
if (value == null) {
354+
log.info("node value is null, won't replace, node: {}", node);
355+
return this;
356+
}
357+
byte[] data = value.toString().getBytes(Charset.forName("UTF-8"));
358+
curatorTransactionFinal = curatorTransactionFinal.setData().forPath(node, data).and();
351359
return this;
352360
}
353361

354-
public CuratorTransactionOpImpl replaceIfChanged(String znode, Object value) throws Exception {
355-
return replaceIfChanged(znode, value, new AtomicInteger(0));
356-
}
357-
358-
public CuratorTransactionOpImpl replaceIfChanged(String znode, Object value, AtomicInteger changedCount)
359-
throws Exception {
360-
byte[] newData = toData(value);
361-
if (this.checkExists(znode)) {
362-
byte[] oldData = this.getData(znode);
362+
@Override
363+
public CuratorTransactionOpImpl replaceIfChanged(String node, Object value) throws Exception {
364+
if (value == null) {
365+
log.info("node value is null, won't replaceIfChanged, node: {}", node);
366+
return this;
367+
}
368+
byte[] newData = value.toString().getBytes(Charset.forName("UTF-8"));
369+
if (this.checkExists(node)) {
370+
byte[] oldData = this.getData(node);
363371
if (!bytesEquals(newData, oldData)) {
364-
curatorTransactionFinal = curatorTransactionFinal.check().forPath(znode).and().setData()
365-
.forPath(znode, newData).and();
366-
changedCount.incrementAndGet();
372+
curatorTransactionFinal = curatorTransactionFinal.check().forPath(node).and().setData()
373+
.forPath(node, newData).and();
367374
}
368375
} else {
369-
this.create(znode, newData);
370-
changedCount.incrementAndGet();
376+
this.create(node, newData);
371377
}
372378
return this;
373379
}
374380

375381
@Override
376-
public CuratorTransactionOp create(String znode, Object value) throws Exception {
377-
byte[] data = toData(value);
382+
public CuratorTransactionOp create(String node, Object value) throws Exception {
383+
if (value == null) {
384+
log.info("node value is null, won't create, node: {}", node);
385+
return this;
386+
}
387+
byte[] data = value.toString().getBytes(Charset.forName("UTF-8"));
378388
curatorTransactionFinal = curatorTransactionFinal.create().withMode(CreateMode.PERSISTENT)
379-
.forPath(znode, data).and();
389+
.forPath(node, data).and();
380390
return this;
381391
}
382392

383393
@Override
384-
public CuratorTransactionOp delete(String znode) throws Exception {
385-
curatorTransactionFinal = curatorTransactionFinal.delete().forPath(znode).and();
394+
public CuratorTransactionOp delete(String node) throws Exception {
395+
curatorTransactionFinal = curatorTransactionFinal.delete().forPath(node).and();
386396
return this;
387397
}
388398

0 commit comments

Comments
 (0)