Skip to content

Commit da0b70f

Browse files
committed
fixed #268 - mark failed mlcp as ERROR
1 parent 20bc35b commit da0b70f

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

marklogic-data-hub/src/main/java/com/marklogic/hub/StatusListener.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
public interface StatusListener {
44

55
public void onStatusChange(int percentComplete, String message);
6+
public void onError();
67
}

quick-start/src/main/java/com/marklogic/quickstart/service/MlcpTasklet.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class MlcpTasklet implements Tasklet {
2222
private JsonNode mlcpOptions;
2323
private JobStatusListener statusListener;
2424
private ArrayList<String> mlcpOutput = new ArrayList<>();
25+
private boolean hasError = false;
2526

2627
public MlcpTasklet(HubConfig hubConfig, JsonNode mlcpOptions, JobStatusListener statusListener) {
2728
this.hubConfig = hubConfig;
@@ -51,6 +52,11 @@ public void onStatusChange(int percentComplete, String message) {
5152
mlcpOutput.add(message);
5253
statusListener.onStatusChange(jobId, percentComplete, message);
5354
}
55+
56+
@Override
57+
public void onError() {
58+
hasError = true;
59+
}
5460
}, sysout);
5561
PrintStream ps = new PrintStream(sos);
5662
System.setOut(ps);
@@ -68,6 +74,10 @@ public void onStatusChange(int percentComplete, String message) {
6874
System.setOut(sysout);
6975
statusListener.onStatusChange(jobId, 100, "");
7076

77+
RepeatStatus status = RepeatStatus.FINISHED;
78+
if (hasError) {
79+
throw new Exception("Error in Mlcp Execution");
80+
}
7181
return RepeatStatus.FINISHED;
7282
}
7383
}

quick-start/src/main/java/com/marklogic/quickstart/util/MlcpOutputStreamInterceptor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public synchronized void write(byte b[], int off, int len) {
3535

3636
byte[] buf = Arrays.copyOfRange(b, off, off + len - 1);
3737
String status = new String(buf);
38+
if (status.contains("ERROR")) {
39+
listener.onError();
40+
}
3841

3942
try {
4043
int pc = Integer.parseInt(status.replaceFirst(".*completed (\\d+)\\%", "$1"));

quick-start/src/main/java/com/marklogic/quickstart/web/ProjectsController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ public ResponseEntity<?> install(@PathVariable int projectId,
174174
public void onStatusChange(int percentComplete, String message) {
175175
template.convertAndSend("/topic/install-status", new StatusMessage(percentComplete, message));
176176
}
177+
178+
@Override
179+
public void onError() {}
177180
});
178181

179182
envConfig.setInitialized(installed);
@@ -206,6 +209,9 @@ public ResponseEntity<?> unInstall(@PathVariable int projectId,
206209
public void onStatusChange(int percentComplete, String message) {
207210
template.convertAndSend("/topic/uninstall-status", new StatusMessage(percentComplete, message));
208211
}
212+
213+
@Override
214+
public void onError() {}
209215
});
210216
return new ResponseEntity<>(HttpStatus.OK);
211217
}

quick-start/src/main/resources/logback.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<logger name="com.marklogic.appdeployer" level="INFO"/>
1919
<logger name="com.marklogic.hub" level="INFO"/>
2020
<logger name="com.marklogic.contentpump" level="INFO"/>
21+
<logger name="org.apache.catalina.webresources.Cache" level="SEVERE"/>
2122

2223
<root level="WARN">
2324
<appender-ref ref="STDOUT" />

0 commit comments

Comments
 (0)