Skip to content

Commit 15e7613

Browse files
committed
refactor: Added file reader and writer registries
1 parent 13f2bc4 commit 15e7613

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1469
-945
lines changed

core/riot-core/src/main/java/com/redis/riot/core/AbstractCallableCommand.java

+15-3
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,26 @@ public abstract class AbstractCallableCommand extends BaseCommand implements Cal
1818

1919
@Override
2020
public Integer call() throws Exception {
21+
initialize();
22+
try {
23+
execute();
24+
} finally {
25+
teardown();
26+
}
27+
return 0;
28+
}
29+
30+
protected void initialize() throws RiotInitializationException {
2131
if (log == null) {
2232
log = LoggerFactory.getLogger(getClass());
2333
}
24-
execute();
25-
return 0;
2634
}
2735

28-
protected abstract void execute() throws Exception;
36+
protected abstract void execute() throws RiotExecutionException;
37+
38+
protected void teardown() {
39+
// do nothing
40+
}
2941

3042
public Logger getLog() {
3143
return log;

core/riot-core/src/main/java/com/redis/riot/core/AbstractJobCommand.java

+37-18
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,32 @@ public abstract class AbstractJobCommand extends AbstractCallableCommand {
6565
private PlatformTransactionManager transactionManager;
6666
private JobLauncher jobLauncher;
6767

68-
private TaskExecutorJobLauncher taskExecutorJobLauncher() throws Exception {
68+
@Override
69+
protected void initialize() throws RiotInitializationException {
70+
super.initialize();
71+
if (jobName == null) {
72+
jobName = jobName();
73+
}
74+
if (jobRepository == null) {
75+
try {
76+
jobRepository = JobUtils.jobRepositoryFactoryBean(jobRepositoryName).getObject();
77+
} catch (Exception e) {
78+
throw new RiotInitializationException("Could not create job repository", e);
79+
}
80+
}
81+
if (transactionManager == null) {
82+
transactionManager = JobUtils.resourcelessTransactionManager();
83+
}
84+
if (jobLauncher == null) {
85+
try {
86+
jobLauncher = jobLauncher();
87+
} catch (Exception e) {
88+
throw new RiotInitializationException("Could not create job launcher", e);
89+
}
90+
}
91+
}
92+
93+
private JobLauncher jobLauncher() throws Exception {
6994
TaskExecutorJobLauncher launcher = new TaskExecutorJobLauncher();
7095
launcher.setJobRepository(jobRepository);
7196
launcher.setTaskExecutor(new SyncTaskExecutor());
@@ -82,26 +107,20 @@ private JobBuilder jobBuilder() {
82107
}
83108

84109
@Override
85-
protected void execute() throws Exception {
86-
if (jobName == null) {
87-
jobName = jobName();
88-
}
89-
if (jobRepository == null) {
90-
jobRepository = JobUtils.jobRepositoryFactoryBean(jobRepositoryName).getObject();
91-
}
92-
if (transactionManager == null) {
93-
transactionManager = JobUtils.resourcelessTransactionManager();
94-
}
95-
if (jobLauncher == null) {
96-
jobLauncher = taskExecutorJobLauncher();
110+
protected void execute() throws RiotExecutionException {
111+
Job job = job();
112+
JobExecution jobExecution;
113+
try {
114+
jobExecution = jobLauncher.run(job, new JobParameters());
115+
} catch (JobExecutionException e) {
116+
throw new RiotExecutionException("Could not run job " + job.getName(), e);
97117
}
98-
JobExecution jobExecution = jobLauncher.run(job(), new JobParameters());
99118
if (JobUtils.isFailed(jobExecution.getExitStatus())) {
100119
for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
101120
ExitStatus stepExitStatus = stepExecution.getExitStatus();
102121
if (JobUtils.isFailed(stepExitStatus)) {
103122
if (CollectionUtils.isEmpty(stepExecution.getFailureExceptions())) {
104-
throw new JobExecutionException(stepExitStatus.getExitDescription());
123+
throw new RiotExecutionException(stepExitStatus.getExitDescription());
105124
}
106125
throw wrapException(stepExecution.getFailureExceptions());
107126
}
@@ -117,11 +136,11 @@ private String jobName() {
117136
return commandSpec.name();
118137
}
119138

120-
private JobExecutionException wrapException(List<Throwable> throwables) {
139+
private RiotExecutionException wrapException(List<Throwable> throwables) {
121140
if (throwables.isEmpty()) {
122-
return new JobExecutionException("Job failed");
141+
return new RiotExecutionException("Job failed");
123142
}
124-
return new JobExecutionException("Job failed", throwables.get(0));
143+
return new RiotExecutionException("Job failed", throwables.get(0));
125144
}
126145

127146
protected Job job(Step<?, ?>... steps) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.redis.riot.core;
2+
3+
@SuppressWarnings("serial")
4+
public class RiotExecutionException extends Exception {
5+
6+
public RiotExecutionException(String message, Throwable cause) {
7+
super(message, cause);
8+
}
9+
10+
public RiotExecutionException(String message) {
11+
super(message);
12+
}
13+
14+
public RiotExecutionException(Throwable cause) {
15+
super(cause);
16+
}
17+
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.redis.riot.core;
2+
3+
@SuppressWarnings("serial")
4+
public class RiotInitializationException extends Exception {
5+
6+
public RiotInitializationException(String message, Throwable cause) {
7+
super(message, cause);
8+
}
9+
10+
public RiotInitializationException(String message) {
11+
super(message);
12+
}
13+
14+
public RiotInitializationException(Throwable cause) {
15+
super(cause);
16+
}
17+
18+
}

core/riot-file/src/main/java/com/redis/riot/file/AbstractFactoryRegistry.java

-184
This file was deleted.

0 commit comments

Comments
 (0)