Skip to content

Commit 0913016

Browse files
committed
Merging 1.0 fixes into 2.0
- fixes for #336 - fixes for #331
2 parents 6aaf7ff + d622855 commit 0913016

File tree

9 files changed

+78
-55
lines changed

9 files changed

+78
-55
lines changed

marklogic-data-hub/src/main/resources/ml-modules/services/flow.xqy

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ declare function delete(
9898
$params as map:map
9999
) as document-node()?
100100
{
101-
let $_ := flow:invalidate-flow-caches()
102-
return
103-
document { () }
101+
debug:dump-env("INVALIDATE FLOW CACHES"),
102+
103+
perf:log('/v1/resources/flow:delete', function() {
104+
let $_ := flow:invalidate-flow-caches()
105+
return
106+
document { () }
107+
})
104108
};

quick-start/src/main/java/com/marklogic/quickstart/Application.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package com.marklogic.quickstart;
1717

18+
import com.marklogic.contentpump.ContentPump;
19+
import org.apache.commons.lang.ArrayUtils;
1820
import org.springframework.boot.SpringApplication;
1921
import org.springframework.boot.autoconfigure.SpringBootApplication;
2022
import org.springframework.boot.builder.SpringApplicationBuilder;
@@ -31,7 +33,13 @@ protected SpringApplicationBuilder configure(SpringApplicationBuilder applicatio
3133
return application.sources(Application.class);
3234
}
3335

34-
public static void main(String[] args) {
35-
SpringApplication.run(Application.class, args);
36+
public static void main(String[] args) throws Exception {
37+
if (args.length > 0 && args[0].equals("mlcp")) {
38+
String[] newArgs = (String[]) ArrayUtils.subarray(args, 1, args.length);
39+
ContentPump.main(newArgs);
40+
}
41+
else {
42+
SpringApplication.run(Application.class, args);
43+
}
3644
}
3745
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
@Component
1010
public interface FileSystemEventListener {
1111

12-
void onWatchEvent(HubConfig hubConfig, Path path);
12+
void onWatchEvent(HubConfig hubConfig);
1313
}

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

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ public void removeListener(FileSystemEventListener listener) {
6464
listeners.remove(listener);
6565
}
6666

67-
private void notifyListeners(HubConfig hubConfig, Path path) {
67+
private void notifyListeners(HubConfig hubConfig) {
6868
// notify global listeners
6969
synchronized (listeners) {
7070
for (FileSystemEventListener listener : listeners) {
7171
try {
72-
listener.onWatchEvent(hubConfig, path);
72+
listener.onWatchEvent(hubConfig);
7373
}
7474
catch (Exception e) {
7575
logger.error("Exception occured on listener", e);
@@ -146,50 +146,28 @@ public synchronized void destroy() throws Exception {
146146
private class DirectoryWatcherThread extends Thread {
147147

148148
private HubConfig hubConfig;
149-
private final int DELAY = 500;
149+
private final int DELAY = 1000;
150150

151-
// Use a SET to prevent duplicates from being added when multiple events on the
152-
// same file arrive in quick succession.
153-
HashSet<Path> filesToReload = new HashSet<>();
154151
Timer processDelayTimer = null;
155152

156153
DirectoryWatcherThread(String name, HubConfig hubConfig) {
157154
super(name);
158155
this.hubConfig = hubConfig;
159156
}
160157

161-
private synchronized void addFileToProcess(Path path) {
162-
boolean alreadyAdded = !filesToReload.add(path);
163-
logger.info("Queuing file for processing: "
164-
+ path.toString() + (alreadyAdded?"(already queued)":""));
158+
private synchronized void queueReload() {
165159
if (processDelayTimer != null) {
166160
processDelayTimer.cancel();
167161
}
168162
processDelayTimer = new Timer();
169163
processDelayTimer.schedule(new TimerTask() {
170164
@Override
171165
public void run() {
172-
processFiles();
166+
notifyListeners(hubConfig);
173167
}
174168
}, DELAY);
175169
}
176170

177-
private synchronized void processFiles() {
178-
// Iterate over the set of file to be processed
179-
for (Iterator<Path> it = filesToReload.iterator(); it.hasNext();) {
180-
Path path = it.next();
181-
182-
// Sometimes you just have to do what you have to do...
183-
logger.info("Processing file: " + path.toString());
184-
185-
// notify listeners
186-
notifyListeners(hubConfig, path);
187-
188-
// Remove this file from the set.
189-
it.remove();
190-
}
191-
}
192-
193171
@Override
194172
public void run() {
195173
for (;;) {
@@ -220,8 +198,8 @@ public void run() {
220198
Path child = dir.resolve(context);
221199

222200
// print out event
223-
logger.info("Event received: {} for: {}", event.kind().name(), child);
224-
addFileToProcess(child);
201+
logger.debug("Event received: {} for: {}", event.kind().name(), child);
202+
queueReload();
225203

226204
// if directory is created, then register it and its sub-directories
227205
// we are always listening recursively

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

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,30 @@
22

33
import com.fasterxml.jackson.databind.JsonNode;
44
import com.fasterxml.jackson.databind.ObjectMapper;
5-
import com.marklogic.contentpump.ContentPump;
65
import com.marklogic.contentpump.bean.MlcpBean;
76
import com.marklogic.hub.HubConfig;
87
import com.marklogic.hub.JobStatusListener;
98
import com.marklogic.quickstart.util.StreamGobbler;
109
import org.apache.commons.io.FileUtils;
10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
1112
import org.springframework.batch.core.StepContribution;
1213
import org.springframework.batch.core.scope.context.ChunkContext;
1314
import org.springframework.batch.core.step.tasklet.Tasklet;
1415
import org.springframework.batch.repeat.RepeatStatus;
1516

1617
import java.io.File;
1718
import java.io.IOException;
19+
import java.net.URL;
20+
import java.net.URLClassLoader;
1821
import java.util.ArrayList;
1922
import java.util.Arrays;
2023
import java.util.function.Consumer;
2124

2225
class MlcpTasklet implements Tasklet {
2326

27+
protected final Logger logger = LoggerFactory.getLogger(getClass());
28+
2429
private HubConfig hubConfig;
2530
private JsonNode mlcpOptions;
2631
private JobStatusListener statusListener;
@@ -66,34 +71,53 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon
6671
}
6772

6873
private void runMlcp(long jobId, MlcpBean bean) throws IOException, InterruptedException {
74+
ClassLoader cl = ClassLoader.getSystemClassLoader();
75+
76+
URL[] urls = ((URLClassLoader)cl).getURLs();
77+
6978
String javaHome = System.getProperty("java.home");
7079
String javaBin = javaHome +
7180
File.separator + "bin" +
7281
File.separator + "java";
7382
String classpath = System.getProperty("java.class.path");
74-
String className = ContentPump.class.getCanonicalName();
75-
76-
File loggerFile = File.createTempFile("mlcp-", "-logger");
77-
String loggerData = "log4j.rootLogger=INFO,console\n" +
78-
"log4j.appender.console=org.apache.log4j.ConsoleAppender\n" +
79-
"log4j.appender.console.target=System.err\n" +
80-
"log4j.appender.console.layout=org.apache.log4j.PatternLayout\n" +
81-
"log4j.appender.console.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n\n" +
83+
84+
File loggerFile = File.createTempFile("mlcp-", "-logger.xml");
85+
String loggerData = "<configuration>\n" +
8286
"\n" +
83-
"# To suppress not native warn on Mac and Solaris\n" +
84-
"log4j.logger.org.apache.hadoop.util.NativeCodeLoader=ERROR\n" +
87+
" <appender name=\"STDOUT\" class=\"ch.qos.logback.core.ConsoleAppender\">\n" +
88+
" <!-- encoders are assigned the type\n" +
89+
" ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->\n" +
90+
" <encoder>\n" +
91+
" <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>\n" +
92+
" </encoder>\n" +
93+
" </appender>\n" +
8594
"\n" +
86-
"# To enable debug\n" +
87-
"#log4j.logger.com.marklogic.mapreduce=DEBUG\n" +
88-
"#log4j.logger.com.marklogic.contentpump=DEBUG\n";
95+
" <logger name=\"org.apache.http\" level=\"WARN\"/>\n" +
96+
"\n" +
97+
" <logger name=\"com.marklogic.spring.batch.core.repository.dao.MarkLogicStepExecutionDao\" level=\"WARN\"/>\n" +
98+
" <logger name=\"com.marklogic.spring.batch.core.repository.dao.MarkLogicJobExecutionDao\" level=\"WARN\"/>\n" +
99+
" <logger name=\"com.marklogic.client.impl.DocumentManagerImpl\" level=\"WARN\"/>\n" +
100+
" <logger name=\"com.marklogic.client.impl.DatabaseClientImpl\" level=\"WARN\"/>\n" +
101+
" <logger name=\"com.marklogic\" level=\"INFO\"/>\n" +
102+
" <logger name=\"com.marklogic.appdeployer\" level=\"INFO\"/>\n" +
103+
" <logger name=\"com.marklogic.hub\" level=\"INFO\"/>\n" +
104+
" <logger name=\"com.marklogic.contentpump\" level=\"INFO\"/>\n" +
105+
" <logger name=\"org.apache.catalina.webresources.Cache\" level=\"ERROR\"/>\n" +
106+
" <logger name=\"org.apache.hadoop.util.Shell\" level=\"OFF\"/>\n" +
107+
" <logger name=\"org.apache.hadoop.util.NativeCodeLoader\" level=\"ERROR\"/>\n" +
108+
"\n" +
109+
" <root level=\"WARN\">\n" +
110+
" <appender-ref ref=\"STDOUT\" />\n" +
111+
" </root>\n" +
112+
"</configuration>\n";
89113
FileUtils.writeStringToFile(loggerFile, loggerData);
90114

91115
ArrayList<String> args = new ArrayList<>();
92116
args.add(javaBin);
93-
args.add("-Dlog4j.configurationFile=" + loggerFile.getAbsolutePath());
94-
args.add("-cp");
117+
args.add("-Dlogback.configurationFile=" + loggerFile.toURI());//logback);
118+
args.add("-jar");
95119
args.add(classpath);
96-
args.add(className);
120+
args.add("mlcp");
97121
args.addAll(Arrays.asList(bean.buildArgs()));
98122

99123
ProcessBuilder pb = new ProcessBuilder(args);
@@ -104,7 +128,7 @@ private void runMlcp(long jobId, MlcpBean bean) throws IOException, InterruptedE
104128

105129
@Override
106130
public void accept(String status) {
107-
131+
System.out.println(status);
108132
// don't log an error if the winutils binary is missing
109133
if (status.contains("ERROR") && !status.contains("winutils binary")) {
110134
hasError = true;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public StreamGobbler(InputStream inputStream, Consumer<String> consumeInputLine)
1616

1717
@Override
1818
public void run() {
19-
System.out.println("gobbler running");
2019
new BufferedReader(new InputStreamReader(inputStream)).lines().forEach(consumeInputLine);
2120
}
2221
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,13 @@ public void onValidate(JsonNode validation) {
352352
template.convertAndSend("/topic/validate-status", validation);
353353
}
354354

355+
/**
356+
* Called when the filesystem watcher detects a file change. We then install the user modules
357+
* @param hubConfig - must pass the hub config because this runs in a separate thread and doesn't
358+
* have access to the current spring boot context
359+
*/
355360
@Override
356-
public void onWatchEvent(HubConfig hubConfig, Path path) {
361+
public void onWatchEvent(HubConfig hubConfig) {
357362
installUserModules(hubConfig, false);
358363
}
359364

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
log4j.logger.httpclient.wire=DEBUG
2+
log4j.logger.org.apache.hadoop.util.NativeCodeLoader=ERROR
3+
log4j.logger.com.marklogic.mapreduce=ERROR
4+
log4j.logger.com.marklogic.contentpump=ERROR

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
<logger name="com.marklogic.appdeployer" level="INFO"/>
2020
<logger name="com.marklogic.hub" level="INFO"/>
2121
<logger name="com.marklogic.contentpump" level="INFO"/>
22+
<logger name="com.marklogic.mapreduce" level="INFO"/>
2223
<logger name="org.apache.catalina.webresources.Cache" level="SEVERE"/>
24+
<logger name="org.apache.hadoop.util.NativeCodeLoader" level="SEVERE"/>
2325

2426
<root level="WARN">
2527
<appender-ref ref="STDOUT" />

0 commit comments

Comments
 (0)