Skip to content

Commit 168b1c9

Browse files
cgardenscgardens
authored andcommitted
remove init and done (#5)
* remove concepts of init and done from core captain library * replace done with an exception if a next step cannot be found * replace done with no op if using ramming speed * adjust tests to reflect removal of init / done
1 parent 0cfda3a commit 168b1c9

File tree

7 files changed

+25
-48
lines changed

7 files changed

+25
-48
lines changed

src/main/java/com/liveramp/captain/daemon/CaptainJoblet.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.slf4j.LoggerFactory;
88
import org.slf4j.MDC;
99

10+
import com.liveramp.captain.exception.CaptainCouldNotFindNextStep;
1011
import com.liveramp.captain.exception.CaptainPersistorException;
1112
import com.liveramp.captain.lib.CaptainAlertHelpers;
1213
import com.liveramp.captain.manifest.Manifest;
@@ -138,7 +139,9 @@ private void goToNextStep(CaptainRequestConfig config) {
138139
Optional<CaptainStep> nextStepOptional = manifest.getNextStep(config.getStep(), config.getId());
139140

140141
LOG.info(String.format("current step: %s, current status: %s, next step: %s, next status: %s", config.getStep(), config.getStatus(), nextStepOptional, CaptainStatus.READY));
142+
141143
if (nextStepOptional.isPresent()) {
144+
142145
requestUpdater.setStepAndStatus(jobId, config.getStep(), config.getStatus(), nextStepOptional.get(), CaptainStatus.READY);
143146

144147
if (rammingSpeed) {
@@ -150,10 +153,12 @@ private void goToNextStep(CaptainRequestConfig config) {
150153
);
151154
CaptainJoblet.of(newConfig, notifier, requestUpdater, manifestManager, supportsPending, rammingSpeed, failedRequestPolicy).run();
152155
}
153-
154156
} else {
155-
requestUpdater.setStepAndStatus(jobId, config.getStep(), config.getStatus(), CaptainStep.fromString("DONE"), CaptainStatus.COMPLETED);
157+
if (!rammingSpeed) {
158+
throw new CaptainCouldNotFindNextStep(config.getStep(), config.getStatus());
159+
}
156160
}
161+
157162
} catch (Exception e) {
158163
String subject = String.format("%s: error while transitioning steps for request %s from step: %s.",
159164
CaptainAlertHelpers.getHostName(), config.getId(), config.getStep()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.liveramp.captain.exception;
2+
3+
import com.liveramp.captain.status.CaptainStatus;
4+
import com.liveramp.captain.step.CaptainStep;
5+
6+
public class CaptainCouldNotFindNextStep extends RuntimeException {
7+
public CaptainCouldNotFindNextStep(CaptainStep step, CaptainStatus status) {
8+
super(String.format("could not find a next step after current step: %s, current status: %s", step, status));
9+
}
10+
}

src/main/java/com/liveramp/captain/exception/CaptainPersistorException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.liveramp.captain.exception;
22

3-
public class CaptainPersistorException extends Exception {
3+
public class CaptainPersistorException extends RuntimeException {
44
public CaptainPersistorException(String message, Exception e) {
55
super(message, e);
66
}

src/main/java/com/liveramp/captain/manifest/DefaultManifestImpl.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,11 @@ public DefaultManifestImpl(List<Waypoint> steps) {
4343

4444
@Override
4545
public Optional<CaptainStep> getNextStep(CaptainStep step, long jobId) {
46-
Integer nextStepIndex;
47-
if (CaptainStep.fromString("INITIALIZING").equals(step)) {
48-
nextStepIndex = 0;
49-
} else {
50-
Integer stepIndex = indexByStep.get(step);
51-
if (null == stepIndex) {
52-
throw new RuntimeException(String.format("could not find step: %s in manifest: %s", step, waypointByStep.keySet()));
53-
}
54-
nextStepIndex = indexByStep.get(step) + 1;
46+
Integer stepIndex = indexByStep.get(step);
47+
if (null == stepIndex) {
48+
throw new RuntimeException(String.format("could not find step: %s in manifest: %s", step, waypointByStep.keySet()));
5549
}
50+
Integer nextStepIndex = indexByStep.get(step) + 1;
5651

5752
if (nextStepIndex < steps.size()) {
5853
CaptainStep nextStep = stepByIndex.get(nextStepIndex);

src/test/java/com/liveramp/captain/daemon/TestCaptainJoblet.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.mockito.verification.VerificationMode;
1313

1414
import com.liveramp.captain.app_type.CaptainAppType;
15+
import com.liveramp.captain.exception.CaptainCouldNotFindNextStep;
1516
import com.liveramp.captain.handle_persistor.HandlePersistor;
1617
import com.liveramp.captain.manifest.DefaultManifestImpl;
1718
import com.liveramp.captain.manifest.Manifest;
@@ -78,15 +79,13 @@ public class TestCaptainJoblet {
7879
private ManifestManager manifestManager;
7980
private RequestUpdater requestUpdater;
8081

81-
private final CaptainStep INITIALIZING = CaptainStep.fromString("INITIALIZING");
8282
private final CaptainStep CAPTAIN_STEP1 = CaptainStep.fromString("CAPTAIN_STEP1");
8383
private final CaptainStep CAPTAIN_STEP2_A = CaptainStep.fromString("CAPTAIN_STEP2_A");
8484
private final CaptainStep CAPTAIN_STEP2_B = CaptainStep.fromString("CAPTAIN_STEP2_B");
8585
private final CaptainStep CAPTAIN_STEP3 = CaptainStep.fromString("CAPTAIN_STEP3");
8686
private final CaptainStep CAPTAIN_STEP4 = CaptainStep.fromString("CAPTAIN_STEP4");
8787
private final CaptainStep CAPTAIN_STEP5 = CaptainStep.fromString("CAPTAIN_STEP5");
8888
private final CaptainStep CAPTAIN_STEP6 = CaptainStep.fromString("CAPTAIN_STEP6");
89-
private final CaptainStep DONE = CaptainStep.fromString("DONE");
9089

9190

9291
private final CaptainAppType APP_TYPE_1 = CaptainAppType.fromString("APP_TYPE_1");
@@ -133,22 +132,13 @@ public void testGoToNextStep() throws Exception {
133132
verify(requestUpdater, times(1)).setStepAndStatus(config.getId(), CAPTAIN_STEP1, CaptainStatus.COMPLETED, CAPTAIN_STEP2_A, CaptainStatus.READY);
134133
}
135134

136-
@Test
137-
public void testGoToNextStepInitializing() throws Exception {
138-
final CaptainRequestConfig config = new SimpleCaptainConfig(JOB_ID, CaptainStatus.COMPLETED, INITIALIZING, APP_TYPE_1);
139-
140-
new CaptainJoblet(config, notifier, requestUpdater, manifestManager, true, false, FAILED_REQUEST_POLICY).run();
141-
142-
verify(requestUpdater, times(1)).setStepAndStatus(config.getId(), INITIALIZING, CaptainStatus.COMPLETED, CAPTAIN_STEP1, CaptainStatus.READY);
143-
}
144-
145135
@Test
146136
public void testGoToNextStepLastStep() throws Exception {
147137
CaptainRequestConfig config = new SimpleCaptainConfig(JOB_ID, CaptainStatus.COMPLETED, CAPTAIN_STEP6, APP_TYPE_1);
148138

149139
new CaptainJoblet(config, notifier, requestUpdater, manifestManager, true, false, FAILED_REQUEST_POLICY).run();
150140

151-
verify(requestUpdater, times(1)).setStepAndStatus(config.getId(), CAPTAIN_STEP6, CaptainStatus.COMPLETED, DONE, CaptainStatus.COMPLETED);
141+
verify(requestUpdater, times(1)).fail(config.getId());
152142
}
153143

154144
@Test

src/test/java/com/liveramp/captain/daemon/TestCaptainJobletWithRammingSpeed.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,13 @@ public class TestCaptainJobletWithRammingSpeed {
8080
private ManifestManager manifestManager;
8181
private RequestUpdater requestUpdater;
8282

83-
private final CaptainStep INITIALIZING = CaptainStep.fromString("INITIALIZING");
8483
private final CaptainStep CAPTAIN_STEP1 = CaptainStep.fromString("CAPTAIN_STEP1");
8584
private final CaptainStep CAPTAIN_STEP2_A = CaptainStep.fromString("CAPTAIN_STEP2_A");
8685
private final CaptainStep CAPTAIN_STEP2_B = CaptainStep.fromString("CAPTAIN_STEP2_B");
8786
private final CaptainStep CAPTAIN_STEP3 = CaptainStep.fromString("CAPTAIN_STEP3");
8887
private final CaptainStep CAPTAIN_STEP4 = CaptainStep.fromString("CAPTAIN_STEP4");
8988
private final CaptainStep CAPTAIN_STEP5 = CaptainStep.fromString("CAPTAIN_STEP5");
9089
private final CaptainStep CAPTAIN_STEP6 = CaptainStep.fromString("CAPTAIN_STEP6");
91-
private final CaptainStep DONE = CaptainStep.fromString("DONE");
9290

9391

9492
private final CaptainAppType APP_TYPE_1 = CaptainAppType.fromString("APP_TYPE_1");
@@ -171,24 +169,12 @@ public void testGoToNextStepFromAsync() throws Exception {
171169
.setStatus(config.getId(), CAPTAIN_STEP4, CaptainStatus.READY, CaptainStatus.IN_PROGRESS);
172170
}
173171

174-
@Test
175-
public void testGoToNextStepInitializing() throws Exception {
176-
CaptainRequestConfig config = new SimpleCaptainConfig(JOB_ID, CaptainStatus.COMPLETED, INITIALIZING, APP_TYPE_1);
177-
178-
new CaptainJoblet(
179-
config, notifier, requestUpdater, manifestManager, true, true, FAILED_REQUEST_POLICY).run();
180-
181-
verify(requestUpdater, times(1))
182-
.setStepAndStatus(config.getId(), INITIALIZING, CaptainStatus.COMPLETED, CAPTAIN_STEP1, CaptainStatus.READY);
183-
}
184-
185172
@Test
186173
public void testGoToNextStepLastStep() throws Exception {
187174
CaptainRequestConfig config = new SimpleCaptainConfig(JOB_ID, CaptainStatus.COMPLETED, CAPTAIN_STEP6, APP_TYPE_1);
188175
new CaptainJoblet(config, notifier, requestUpdater, manifestManager, true, true, FAILED_REQUEST_POLICY).run();
189176

190-
verify(requestUpdater, times(1))
191-
.setStepAndStatus(config.getId(), CAPTAIN_STEP6, CaptainStatus.COMPLETED, DONE, CaptainStatus.COMPLETED);
177+
verify(requestUpdater, times(0)).fail(config.getId());
192178
}
193179

194180
@Test

src/test/java/com/liveramp/captain/daemon/manifest/TestDefaultManifestImpl.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,6 @@ public void testGetNextStepOptional() {
6868
checkExpectedNextStep(testManifest, nonOptionalWaypoint1.getStep(), nonOptionalWaypoint2.getStep());
6969
}
7070

71-
@Test
72-
public void testFirstStepOptional() {
73-
Manifest testManifest = new DefaultManifestImpl(Lists.newArrayList(
74-
optionalWaypoint1,
75-
nonOptionalWaypoint1
76-
));
77-
checkExpectedNextStep(testManifest, CaptainStep.fromString("INITIALIZING"), nonOptionalWaypoint1.getStep());
78-
}
79-
8071
@Test
8172
public void testGetNextStepOptionalLastStep() {
8273
Manifest testManifest = new DefaultManifestImpl(Lists.newArrayList(

0 commit comments

Comments
 (0)