Skip to content

Commit 376cc2e

Browse files
committed
Merge remote-tracking branch 'origin/master' into 72_define_search_options
# Conflicts: # quick-start/src/main/java/com/marklogic/hub/factory/DomainModelFactory.java # quick-start/src/main/java/com/marklogic/hub/service/DomainManagerService.java # quick-start/src/main/java/com/marklogic/hub/service/SyncStatusService.java # quick-start/src/main/java/com/marklogic/hub/web/controller/api/DataHubServerApiController.java
2 parents e121f9e + f64e06c commit 376cc2e

File tree

87 files changed

+1651
-890
lines changed

Some content is hidden

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

87 files changed

+1651
-890
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.DS_Store
22
.gradle/
33
.settings/
4+
.metadata/
45
data-hub/bin/
56
quick-start/bin/
67
build/

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ This project allows you to deploy a skeleton Data Hub into MarkLogic. With some
1111
- create a data-hub/gradle-local.properties file and point it to your MarkLogic server _(see data-hub/gradle-local.sample)_
1212
- run ```./gradlew mlDeploy```
1313

14+
- currently, use quickstart to deploy. just run ./gradlew build -x test to build, then use quickstart
15+
1416
## Running Tests
1517
- run ```./gradlew test```
1618

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

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@
4545
import com.marklogic.appdeployer.impl.SimpleAppDeployer;
4646
import com.marklogic.client.DatabaseClient;
4747
import com.marklogic.client.DatabaseClientFactory;
48-
import com.marklogic.client.modulesloader.impl.DefaultModulesLoader;
4948
import com.marklogic.client.modulesloader.impl.PropertiesModuleManager;
49+
import com.marklogic.client.modulesloader.impl.XccAssetLoader;
5050
import com.marklogic.hub.commands.DeployHubDatabaseCommand;
5151
import com.marklogic.hub.commands.DeployModulesDatabaseCommand;
5252
import com.marklogic.hub.commands.DeployRestApiCommand;
5353
import com.marklogic.hub.commands.LoadModulesCommand;
54+
import com.marklogic.hub.util.HubFileFilter;
5455
import com.marklogic.hub.util.HubModulesLoader;
5556
import com.marklogic.mgmt.ManageClient;
5657
import com.marklogic.mgmt.ManageConfig;
@@ -63,9 +64,9 @@
6364
public class DataHub {
6465

6566
static final private Logger LOGGER = LoggerFactory.getLogger(DataHub.class);
66-
static final private String STAGING_NAME = "data-hub-in-a-box-STAGING";
67-
static final private String FINAL_NAME = "data-hub-in-a-box-FINAL";
68-
static final private String MODULES_DB_NAME = "data-hub-in-a-box-modules";
67+
static final public String STAGING_NAME = "data-hub-in-a-box-STAGING";
68+
static final public String FINAL_NAME = "data-hub-in-a-box-FINAL";
69+
static final public String MODULES_DB_NAME = "data-hub-in-a-box-modules";
6970
private ManageConfig config;
7071
private ManageClient client;
7172
public static String HUB_NAME = "data-hub-in-a-box";
@@ -76,7 +77,7 @@ public class DataHub {
7677
private String username;
7778
private String password;
7879

79-
private File assetInstallTimeFile;
80+
private File assetInstallTimeFile = new File("./assetInstallTime.properties");
8081

8182
private final static int DEFAULT_STAGING_REST_PORT = 8010;
8283
private final static int DEFAULT_FINAL_REST_PORT = 8011;
@@ -186,6 +187,10 @@ private AppConfig getAppConfig() throws IOException {
186187
* @throws IOException
187188
*/
188189
public void install() throws IOException {
190+
// clean up any lingering cache for deployed modules
191+
PropertiesModuleManager moduleManager = new PropertiesModuleManager(this.assetInstallTimeFile);
192+
moduleManager.deletePropertiesFile();
193+
189194
AdminManager manager = new AdminManager();
190195
AppConfig config = getAppConfig();
191196
SimpleAppDeployer deployer = new SimpleAppDeployer(client, manager);
@@ -215,39 +220,37 @@ public Set<File> installUserModules(String pathToUserModules) throws IOException
215220
DatabaseClient finalClient = DatabaseClientFactory.newClient(host, finalRestPort, username, password,
216221
config.getRestAuthentication(), config.getRestSslContext(), config.getRestSslHostnameVerifier());
217222

218-
PropertiesModuleManager modulesManager = new PropertiesModuleManager(assetInstallTimeFile);
219223

220224
Set<File> loadedFiles = new HashSet<File>();
221225

222-
DefaultModulesLoader modulesLoader = new DefaultModulesLoader(config.newXccAssetLoader());
223-
HubModulesLoader hubModulesLoader = new HubModulesLoader(config.newXccAssetLoader());
224-
if (assetInstallTimeFile != null) {
225-
modulesLoader.setModulesManager(modulesManager);
226-
hubModulesLoader.setModulesManager(modulesManager);
227-
}
228-
Path startPath = Paths.get(pathToUserModules, "domains");
226+
XccAssetLoader assetLoader = config.newXccAssetLoader();
227+
assetLoader.setFileFilter(new HubFileFilter());
228+
229+
PropertiesModuleManager moduleManager = new PropertiesModuleManager(this.assetInstallTimeFile);
230+
HubModulesLoader hubModulesLoader = new HubModulesLoader(assetLoader, moduleManager);
231+
File baseDir = Paths.get(pathToUserModules).normalize().toAbsolutePath().toFile();
232+
loadedFiles.addAll(hubModulesLoader.loadModules(baseDir, new AssetModulesFinder(), stagingClient));
233+
Path startPath = Paths.get(pathToUserModules, "entities");
234+
229235
Files.walkFileTree(startPath, new SimpleFileVisitor<Path>() {
230236
@Override
231237
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
232238
throws IOException
233239
{
234-
boolean isRest = dir.endsWith("REST") || dir.endsWith("rest");
240+
boolean isRest = dir.endsWith("REST");
241+
235242
String dirStr = dir.toString();
236243
boolean isInputDir = dirStr.matches(".*/input/.*");
237-
boolean isConformanceDir = dirStr.matches(".*conformance/.*");
244+
boolean isConformanceDir = dirStr.matches(".*/conformance/.*");
238245
if (isRest) {
239246
if (isInputDir) {
240-
loadedFiles.addAll(modulesLoader.loadModules(dir.normalize().toAbsolutePath().toFile(), new AllButAssetsModulesFinder(), stagingClient));
247+
loadedFiles.addAll(hubModulesLoader.loadModules(dir.normalize().toAbsolutePath().toFile(), new AllButAssetsModulesFinder(), stagingClient));
241248
}
242249
else if (isConformanceDir) {
243-
loadedFiles.addAll(modulesLoader.loadModules(dir.normalize().toAbsolutePath().toFile(), new AllButAssetsModulesFinder(), finalClient));
250+
loadedFiles.addAll(hubModulesLoader.loadModules(dir.normalize().toAbsolutePath().toFile(), new AllButAssetsModulesFinder(), finalClient));
244251
}
245252
return FileVisitResult.SKIP_SUBTREE;
246253
}
247-
else if (isInputDir || isConformanceDir) {
248-
loadedFiles.addAll(hubModulesLoader.loadModules(dir.normalize().toAbsolutePath().toFile(), new AssetModulesFinder(), stagingClient));
249-
return FileVisitResult.SKIP_SUBTREE;
250-
}
251254
else {
252255
return FileVisitResult.CONTINUE;
253256
}
@@ -302,5 +305,9 @@ public void uninstall() throws IOException {
302305
SimpleAppDeployer deployer = new SimpleAppDeployer(client, manager);
303306
deployer.setCommands(getCommands(config));
304307
deployer.undeploy(config);
308+
309+
// clean up any lingering cache for deployed modules
310+
PropertiesModuleManager moduleManager = new PropertiesModuleManager(this.assetInstallTimeFile);
311+
moduleManager.deletePropertiesFile();
305312
}
306313
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.marklogic.hub;
22

3-
import java.io.File;
43
import java.util.List;
54

65
import com.marklogic.contentpump.ContentPump;
@@ -17,10 +16,10 @@ public DataHubContentPump(List<String> arguments) {
1716
public DataHubContentPump(String[] arguments) {
1817
this.arguments = arguments;
1918
}
20-
19+
2120
/**
2221
* Run the Content Pump.
23-
*
22+
*
2423
* @return true if the content pump executed successfully, false otherwise.
2524
*/
2625
public boolean execute() {
@@ -34,7 +33,7 @@ public boolean execute() {
3433
System.err.println(ex.getMessage());
3534
System.err.println("Try 'mlcp help' for usage.");
3635
}
37-
36+
3837
return rc == 0;
3938
}
4039
}

data-hub/src/main/java/com/marklogic/hub/DomainManager.java renamed to data-hub/src/main/java/com/marklogic/hub/EntityManager.java

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,25 @@
2929
import com.marklogic.client.extensions.ResourceServices.ServiceResultIterator;
3030
import com.marklogic.client.io.DOMHandle;
3131
import com.marklogic.client.util.RequestParameters;
32-
import com.marklogic.hub.domain.Domain;
33-
import com.marklogic.hub.domain.DomainImpl;
32+
import com.marklogic.hub.entity.Entity;
33+
import com.marklogic.hub.entity.EntityImpl;
3434

35-
public class DomainManager extends ResourceManager {
36-
static final public String NAME = "domain";
35+
public class EntityManager extends ResourceManager {
36+
static final public String NAME = "entity";
3737
private DatabaseClient client;
3838

39-
public DomainManager(DatabaseClient client) {
39+
public EntityManager(DatabaseClient client) {
4040
super();
4141
this.client = client;
4242
this.client.init(NAME, this);
4343
}
4444

4545
/**
46-
* Retrieves a list of domains from the Server
47-
* @return a list of domains
46+
* Retrieves a list of entities from the Server
47+
*
48+
* @return a list of entities
4849
*/
49-
public List<Domain> getDomains() {
50+
public List<Entity> getEntities() {
5051
RequestParameters params = new RequestParameters();
5152
ServiceResultIterator resultItr = this.getServices().get(params);
5253
if (resultItr == null || ! resultItr.hasNext()) {
@@ -57,42 +58,44 @@ public List<Domain> getDomains() {
5758
Document parent = res.getContent(handle).get();
5859
NodeList children = parent.getDocumentElement().getChildNodes();
5960

60-
ArrayList<Domain> domains = null;
61+
ArrayList<Entity> entities = null;
6162
if (children.getLength() > 0) {
62-
domains = new ArrayList<Domain>();
63+
entities = new ArrayList<Entity>();
6364
}
6465

6566
Node node;
6667
for (int i = 0; i < children.getLength(); i++) {
6768
node = children.item(i);
6869
if (node.getNodeType() == Node.ELEMENT_NODE) {
69-
domains.add(domainFromXml((Element)children.item(i)));
70+
entities.add(entityFromXml((Element) children.item(i)));
7071
}
7172
}
72-
return domains;
73+
return entities;
7374
}
7475

7576
/**
76-
* Retrieve a named domain
77-
* @param domainName - the name of the domain to retrieve
78-
* @return a domain
77+
* Retrieve a named entity
78+
*
79+
* @param entityName
80+
* - the name of the entity to retrieve
81+
* @return a entity
7982
*/
80-
public Domain getDomain(String domainName) {
83+
public Entity getEntity(String entityName) {
8184
RequestParameters params = new RequestParameters();
82-
params.add("domain-name", domainName);
85+
params.add("entity-name", entityName);
8386
ServiceResultIterator resultItr = this.getServices().get(params);
8487
if (resultItr == null || ! resultItr.hasNext()) {
8588
return null;
8689
}
8790
ServiceResult res = resultItr.next();
8891
DOMHandle handle = new DOMHandle();
8992
Document parent = res.getContent(handle).get();
90-
return new DomainImpl(parent.getDocumentElement());
93+
return new EntityImpl(parent.getDocumentElement());
9194
}
9295

9396

94-
private Domain domainFromXml(Element doc) {
95-
Domain d = new DomainImpl(doc);
97+
private Entity entityFromXml(Element doc) {
98+
Entity d = new EntityImpl(doc);
9699
return d;
97100
}
98101
}

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

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.slf4j.Logger;
2525
import org.slf4j.LoggerFactory;
2626
import org.springframework.batch.core.Job;
27+
import org.springframework.batch.core.JobExecution;
2728
import org.springframework.batch.core.JobExecutionListener;
2829
import org.springframework.batch.core.JobParameters;
2930
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
@@ -116,12 +117,14 @@ protected void initializeDefaultSpringBatchComponents() {
116117

117118
/**
118119
* Retrieves a list of flows installed on the MarkLogic server
119-
* @param domainName - the domain from which to fetch the flows
120-
* @return - a list of flows for the given domain
120+
*
121+
* @param entityName
122+
* - the entity from which to fetch the flows
123+
* @return - a list of flows for the given entity
121124
*/
122-
public List<Flow> getFlows(String domainName) {
125+
public List<Flow> getFlows(String entityName) {
123126
RequestParameters params = new RequestParameters();
124-
params.add("domain-name", domainName);
127+
params.add("entity-name", entityName);
125128
ServiceResultIterator resultItr = this.getServices().get(params);
126129
if (resultItr == null || ! resultItr.hasNext()) {
127130
return null;
@@ -147,18 +150,21 @@ public List<Flow> getFlows(String domainName) {
147150
}
148151

149152
/**
150-
* Retrieves a named flow from a given domain
151-
* @param domainName - the domain that the flow belongs to
152-
* @param flowName - the name of the flow to get
153+
* Retrieves a named flow from a given entity
154+
*
155+
* @param entityName
156+
* - the entity that the flow belongs to
157+
* @param flowName
158+
* - the name of the flow to get
153159
* @return the flow
154160
*/
155-
public Flow getFlow(String domainName, String flowName) {
156-
return getFlow(domainName, flowName, null);
161+
public Flow getFlow(String entityName, String flowName) {
162+
return getFlow(entityName, flowName, null);
157163
}
158164

159-
public Flow getFlow(String domainName, String flowName, FlowType flowType) {
165+
public Flow getFlow(String entityName, String flowName, FlowType flowType) {
160166
RequestParameters params = new RequestParameters();
161-
params.add("domain-name", domainName);
167+
params.add("entity-name", entityName);
162168
params.add("flow-name", flowName);
163169
if (flowType != null) {
164170
params.add("flow-type", flowType.toString());
@@ -181,8 +187,8 @@ public void uninstallFlow(String flowName) {
181187

182188
}
183189

184-
public void runFlow(Flow flow, int batchSize) {
185-
runFlow(flow, batchSize, null);
190+
public JobExecution runFlow(Flow flow, int batchSize) {
191+
return runFlow(flow, batchSize, null);
186192
}
187193

188194
// might want to add Job tracking support
@@ -193,8 +199,9 @@ public void runFlow(Flow flow, int batchSize) {
193199
* @param flow - the flow to run
194200
* @param batchSize - the size to use for batching transactions
195201
* @param listener - the JobExecutionListener to receive status updates about the job
202+
* @return
196203
*/
197-
public void runFlow(Flow flow, int batchSize, JobExecutionListener listener) {
204+
public JobExecution runFlow(Flow flow, int batchSize, JobExecutionListener listener) {
198205
Collector c = flow.getCollector();
199206
if (c instanceof ServerCollector) {
200207
((ServerCollector)c).setClient(client);
@@ -206,15 +213,16 @@ public void runFlow(Flow flow, int batchSize, JobExecutionListener listener) {
206213
.<String, String> chunk(batchSize)
207214
.reader(reader).writer(writer).build();
208215

209-
String jobName = flow.getDomainName() + ":" + flow.getType() + ":" + flow.getName() + "-" + System.currentTimeMillis();
216+
String jobName = flow.getEntityName() + ":" + flow.getType() + ":"
217+
+ flow.getName() + "-" + System.currentTimeMillis();
210218
SimpleJobBuilder builder = jobBuilderFactory.get(jobName).start(step);
211219
if (listener != null) {
212220
builder = builder.listener(listener);
213221
}
214222
Job job = builder.build();
215223

216224
try {
217-
jobLauncher.run(job, new JobParameters());
225+
return jobLauncher.run(job, new JobParameters());
218226
}
219227
catch (Exception e) {
220228
throw new RuntimeException(e);
@@ -224,12 +232,16 @@ public void runFlow(Flow flow, int batchSize, JobExecutionListener listener) {
224232
public void runInputFlow(Flow flow, HubConfig config) {
225233
try {
226234
Mlcp mlcp = new Mlcp(config.getHost(), config.getStagingPort(), config.getAdminUsername(), config.getAdminPassword());
227-
SourceOptions sourceOptions = new SourceOptions(flow.getDomainName(), flow.getName(), FlowType.INPUT.toString());
235+
SourceOptions sourceOptions = new SourceOptions(
236+
flow.getEntityName(), flow.getName(),
237+
FlowType.INPUT.toString());
228238
mlcp.addSourceDirectory(config.getModulesPath(), sourceOptions);
229239
mlcp.loadContent();
230240
}
231241
catch (IOException e) {
232-
LOGGER.error("Error encountered while trying to run flow: " + flow.getDomainName() + " > " + flow.getName(), e);
242+
LOGGER.error(
243+
"Error encountered while trying to run flow: "
244+
+ flow.getEntityName() + " > " + flow.getName(), e);
233245
}
234246
}
235247

@@ -286,7 +298,7 @@ public void run(Flow flow, String identifier, Transaction transaction) {
286298
this.getServices().post(params, handle, transaction);
287299
}
288300
}
289-
public void testFlow(Flow flow) {
290-
301+
public JobExecution testFlow(Flow flow) {
302+
return null;
291303
}
292304
}

0 commit comments

Comments
 (0)