Skip to content

Commit 98166ad

Browse files
committed
merging fixes from 2.x into 1.x
1 parent ca4b165 commit 98166ad

File tree

99 files changed

+1779
-2553
lines changed

Some content is hidden

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

99 files changed

+1779
-2553
lines changed

.travis/Dockerfile-ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ RUN yum -y install /tmp/MarkLogic.rpm 2>&1 > /dev/null
1616

1717
# Expose MarkLogic Server ports - add additional ones for your REST, etc
1818
# endpoints
19-
EXPOSE 7997-8002
19+
EXPOSE 7997-8020
2020

2121
# init
2222
COPY .travis/startml.sh /tmp/startml.sh

.travis/download.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ echo "Logging in to Docker registry"
44
docker login -u ${DOCKER_USER} -p ${DOCKER_PASSWORD}
55

66
echo "Getting Docker Image"
7-
docker pull paxtonhare/marklogic-datahub-1x
7+
docker pull marklogiccommunity/marklogic-datahub-1x

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '2'
22
services:
33
marklogic:
4-
image: paxtonhare/marklogic-datahub-1x
4+
image: marklogiccommunity/marklogic-datahub-1x
55
ports:
66
- "8000-8020"
77
volumes:

examples/spring-batch/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ repositories {
2121
dependencies {
2222
compile 'com.marklogic:marklogic-data-hub:1.1.2'
2323
compile 'com.marklogic:marklogic-spring-batch-core:0.6.0'
24-
compile 'com.marklogic:ml-javaclient-util:2.13.0'
24+
compile 'com.marklogic:ml-javaclient-util:2.14.0'
2525
testCompile 'com.marklogic:marklogic-spring-batch-test:0.6.0'
2626
}
2727

marklogic-data-hub/build.gradle

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,10 @@ sourceCompatibility = 1.8
1919
targetCompatibility = 1.8
2020

2121
dependencies {
22-
compile 'org.springframework.batch:spring-batch-core:3.0.6.RELEASE'
23-
compile 'org.springframework:spring-jdbc:4.2.6.RELEASE'
24-
compile 'com.marklogic:java-client-api:3.0.7'
25-
compile 'com.marklogic:ml-javaclient-util:2.13.0'
22+
compile 'com.marklogic:marklogic-client-api:4.0.1'
23+
compile 'com.marklogic:ml-javaclient-util:4.0.alpha4'
2624
compile 'com.marklogic:ml-app-deployer:2.6.0'
27-
compile 'com.marklogic:marklogic-spring-batch-core:0.7.0'
2825
compile 'commons-io:commons-io:2.4'
29-
testCompile 'org.springframework.batch:spring-batch-test:3.0.6.RELEASE'
3026
testCompile 'junit:junit:4.12'
3127
testCompile 'xmlunit:xmlunit:1.3'
3228
testCompile 'org.skyscreamer:jsonassert:1.3.0'
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Copyright 2015-2017 MarkLogic Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.marklogic.client.datamovement.impl;
17+
18+
import java.util.ArrayList;
19+
import java.util.UUID;
20+
21+
import com.fasterxml.jackson.databind.JsonNode;
22+
import com.marklogic.client.DatabaseClient;
23+
import com.marklogic.client.impl.DatabaseClientImpl;
24+
import com.marklogic.client.io.JacksonHandle;
25+
import com.marklogic.client.datamovement.Batcher;
26+
import com.marklogic.client.datamovement.JobTicket;
27+
import com.marklogic.client.datamovement.JobTicket.JobType;
28+
import com.marklogic.client.datamovement.QueryBatcher;
29+
import com.marklogic.client.datamovement.WriteBatcher;
30+
import com.marklogic.client.datamovement.JobReport;
31+
import com.marklogic.client.datamovement.impl.ForestConfigurationImpl;
32+
import java.util.List;
33+
34+
public class DataMovementServices {
35+
private DatabaseClient client;
36+
37+
public DatabaseClient getClient() {
38+
return client;
39+
}
40+
41+
public DataMovementServices setClient(DatabaseClient client) {
42+
this.client = client;
43+
return this;
44+
}
45+
46+
public ForestConfigurationImpl readForestConfig() {
47+
List<ForestImpl> forests = new ArrayList<>();
48+
JsonNode results = ((DatabaseClientImpl) client).getServices()
49+
.getResource(null, "resources/forest-info", null, null, new JacksonHandle())
50+
.get();
51+
for ( JsonNode forestNode : results ) {
52+
String id = forestNode.get("id").asText();
53+
String name = forestNode.get("name").asText();
54+
String database = forestNode.get("database").asText();
55+
String host = forestNode.get("host").asText();
56+
String openReplicaHost = null;
57+
if ( forestNode.get("openReplicaHost") != null ) openReplicaHost = forestNode.get("openReplicaHost").asText();
58+
String alternateHost = null;
59+
if ( forestNode.get("alternateHost") != null ) alternateHost = forestNode.get("alternateHost").asText();
60+
boolean isUpdateable = "all".equals(forestNode.get("updatesAllowed").asText());
61+
boolean isDeleteOnly = false; // TODO: get this for real after we start using a REST endpoint
62+
forests.add(new ForestImpl(host, alternateHost, openReplicaHost, database, name, id, isUpdateable, isDeleteOnly));
63+
}
64+
65+
return new ForestConfigurationImpl(forests.toArray(new ForestImpl[forests.size()]));
66+
}
67+
68+
public JobTicket startJob(WriteBatcher batcher) {
69+
JobTicket jobTicket = new JobTicketImpl(generateJobId(), JobTicket.JobType.WRITE_BATCHER)
70+
.withWriteBatcher((WriteBatcherImpl) batcher);
71+
((WriteBatcherImpl) batcher).start(jobTicket);
72+
return jobTicket;
73+
}
74+
75+
public JobTicket startJob(QueryBatcher batcher) {
76+
JobTicket jobTicket = new JobTicketImpl(generateJobId(), JobTicket.JobType.QUERY_BATCHER)
77+
.withQueryBatcher((QueryBatcherImpl) batcher);
78+
((QueryBatcherImpl) batcher).start(jobTicket);
79+
return jobTicket;
80+
}
81+
82+
public JobReport getJobReport(JobTicket ticket) {
83+
if ( ticket instanceof JobTicketImpl ) {
84+
JobTicketImpl ticketImpl = (JobTicketImpl) ticket;
85+
if ( ticketImpl.getJobType() == JobType.WRITE_BATCHER ) {
86+
return new JobReportImpl(ticketImpl.getWriteBatcher());
87+
} else if ( ticketImpl.getJobType() == JobType.QUERY_BATCHER ) {
88+
return new JobReportImpl(ticketImpl.getQueryBatcher());
89+
}
90+
}
91+
return null;
92+
}
93+
94+
public void stopJob(JobTicket ticket) {
95+
if ( ticket instanceof JobTicketImpl ) {
96+
JobTicketImpl ticketImpl = (JobTicketImpl) ticket;
97+
if ( ticketImpl.getJobType() == JobType.WRITE_BATCHER ) {
98+
ticketImpl.getWriteBatcher().stop();
99+
} else if ( ticketImpl.getJobType() == JobType.QUERY_BATCHER ) {
100+
ticketImpl.getQueryBatcher().stop();
101+
}
102+
}
103+
}
104+
105+
public void stopJob(Batcher batcher) {
106+
if ( batcher instanceof QueryBatcherImpl ) {
107+
((QueryBatcherImpl) batcher).stop();
108+
} else if ( batcher instanceof WriteBatcherImpl ) {
109+
((WriteBatcherImpl) batcher).stop();
110+
}
111+
}
112+
113+
private String generateJobId() {
114+
return UUID.randomUUID().toString();
115+
}
116+
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import com.marklogic.appdeployer.command.Command;
2222
import com.marklogic.appdeployer.command.CommandMapBuilder;
2323
import com.marklogic.appdeployer.command.appservers.DeployOtherServersCommand;
24+
import com.marklogic.appdeployer.command.security.DeployRolesCommand;
25+
import com.marklogic.appdeployer.command.security.DeployUsersCommand;
2426
import com.marklogic.appdeployer.impl.SimpleAppDeployer;
2527
import com.marklogic.client.DatabaseClient;
2628
import com.marklogic.client.FailedRequestException;
@@ -305,6 +307,10 @@ public List<Command> getCommandList() {
305307
public Map<String, List<Command>> getCommands() {
306308
Map<String, List<Command>> commandMap = new CommandMapBuilder().buildCommandMap();
307309

310+
List<Command> securityCommands = commandMap.get("mlSecurityCommands");
311+
securityCommands.set(0, new DeployHubRolesCommand(hubConfig));
312+
securityCommands.set(1, new DeployHubUsersCommand(hubConfig));
313+
308314
List<Command> dbCommands = new ArrayList<>();
309315
dbCommands.add(new DeployHubDatabasesCommand(hubConfig));
310316
dbCommands.add(new DeployHubOtherDatabasesCommand(hubConfig));
@@ -355,6 +361,15 @@ public void install(HubDeployStatusListener listener) {
355361
deployer.deploy(config);
356362
}
357363

364+
public void updateIndexes() {
365+
AppConfig config = hubConfig.getAppConfig();
366+
HubAppDeployer deployer = new HubAppDeployer(getManageClient(), getAdminManager(), null);
367+
List<Command> commands = new ArrayList<>();
368+
commands.add(new DeployHubDatabasesCommand(hubConfig));
369+
deployer.setCommands(commands);
370+
deployer.deploy(config);
371+
}
372+
358373
/**
359374
* Uninstalls the data hub configuration and server-side modules from MarkLogic
360375
*/

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,22 @@
1616
package com.marklogic.hub;
1717

1818
import com.marklogic.client.DatabaseClient;
19+
import com.marklogic.client.datamovement.DataMovementManager;
1920
import com.marklogic.client.extensions.ResourceManager;
2021
import com.marklogic.client.extensions.ResourceServices.ServiceResult;
2122
import com.marklogic.client.extensions.ResourceServices.ServiceResultIterator;
2223
import com.marklogic.client.io.DOMHandle;
2324
import com.marklogic.client.util.RequestParameters;
2425
import com.marklogic.hub.flow.*;
2526
import com.marklogic.hub.flow.impl.FlowRunnerImpl;
27+
import com.marklogic.hub.job.JobManager;
2628
import org.w3c.dom.Document;
2729
import org.w3c.dom.Element;
2830
import org.w3c.dom.Node;
2931
import org.w3c.dom.NodeList;
3032

3133
import java.util.ArrayList;
3234
import java.util.List;
33-
import java.util.Map;
3435

3536
public class FlowManager extends ResourceManager {
3637
private static final String HUB_NS = "http://marklogic.com/data-hub";
@@ -40,14 +41,18 @@ public class FlowManager extends ResourceManager {
4041
private DatabaseClient finalClient;
4142
private DatabaseClient jobClient;
4243
private HubConfig hubConfig;
43-
private Map<String, Object> userOptions;
44+
private JobManager jobManager;
45+
46+
private DataMovementManager dataMovementManager;
4447

4548
public FlowManager(HubConfig hubConfig) {
4649
super();
4750
this.hubConfig = hubConfig;
4851
this.stagingClient = hubConfig.newStagingClient();
4952
this.finalClient = hubConfig.newFinalClient();
5053
this.jobClient = hubConfig.newJobDbClient();
54+
this.jobManager = new JobManager(this.jobClient);
55+
this.dataMovementManager = this.stagingClient.newDataMovementManager();
5156
this.stagingClient.init(NAME, this);
5257
}
5358

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

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
*/
4444
public class HubConfig {
4545

46+
public static final String USER_MODULES_DEPLOY_TIMESTAMPS_PROPERTIES = "user-modules-deploy-timestamps.properties";
47+
public static final String USER_CONTENT_DEPLOY_TIMESTAMPS_PROPERTIES = "user-content-deploy-timestamps.properties";
48+
4649
public static final String OLD_HUB_CONFIG_DIR = "marklogic-config";
4750
public static final String HUB_CONFIG_DIR = "hub-internal-config";
4851
public static final String USER_CONFIG_DIR = "user-config";
@@ -58,11 +61,18 @@ public class HubConfig {
5861
public static final String DEFAULT_TRIGGERS_DB_NAME = "data-hub-TRIGGERS";
5962
public static final String DEFAULT_SCHEMAS_DB_NAME = "data-hub-SCHEMAS";
6063

64+
public static final String DEFAULT_ROLE_NAME = "data-hub-ROLE";
65+
public static final String DEFAULT_USER_NAME = "data-hub-user";
66+
6167
public static final Integer DEFAULT_STAGING_PORT = 8010;
6268
public static final Integer DEFAULT_FINAL_PORT = 8011;
6369
public static final Integer DEFAULT_TRACE_PORT = 8012;
6470
public static final Integer DEFAULT_JOB_PORT = 8013;
6571

72+
public static final Integer DEFAULT_APP_SERVICES_PORT = 8000;
73+
public static final Integer DEFAULT_ADMIN_PORT = 8001;
74+
public static final Integer DEFAULT_MANAGE_PORT = 8002;
75+
6676
public static final String DEFAULT_PROJECT_DIR = ".";
6777

6878
public static final String DEFAULT_AUTH_METHOD = "digest";
@@ -113,6 +123,13 @@ public class HubConfig {
113123
public String triggersDbName = DEFAULT_TRIGGERS_DB_NAME;
114124
public String schemasDbName = DEFAULT_SCHEMAS_DB_NAME;
115125

126+
public Integer appServicesPort = DEFAULT_APP_SERVICES_PORT;
127+
public Integer adminPort = DEFAULT_ADMIN_PORT;
128+
public Integer managePort = DEFAULT_MANAGE_PORT;
129+
130+
public String hubRoleName = DEFAULT_ROLE_NAME;
131+
public String hubUserName = DEFAULT_USER_NAME;
132+
116133
public String projectDir;
117134

118135
private Properties environmentProperties;
@@ -149,12 +166,24 @@ private Properties getProperties(String environment) {
149166
return environmentProperties;
150167
}
151168

169+
public File getModulesDeployTimestampFile() {
170+
return Paths.get(projectDir, ".tmp", USER_MODULES_DEPLOY_TIMESTAMPS_PROPERTIES).toFile();
171+
}
172+
173+
public File getContentDeployTimestampFile() {
174+
return Paths.get(projectDir, ".tmp", USER_CONTENT_DEPLOY_TIMESTAMPS_PROPERTIES).toFile();
175+
}
176+
152177
public void loadConfigurationFromProperties(Properties environmentProperties) {
153178
this.environmentProperties = environmentProperties;
154179

155180
if (this.environmentProperties != null) {
156181
host = getEnvPropString(environmentProperties, "mlHost", host);
157182

183+
appServicesPort = getEnvPropInteger(environmentProperties, "mlAppServicesPort", appServicesPort);
184+
adminPort = getEnvPropInteger(environmentProperties, "mlAdminPort", adminPort);
185+
managePort = getEnvPropInteger(environmentProperties, "mlManagePort", managePort);
186+
158187
stagingDbName = getEnvPropString(environmentProperties, "mlStagingDbName", stagingDbName);
159188
stagingHttpName = getEnvPropString(environmentProperties, "mlStagingAppserverName", stagingHttpName);
160189
stagingForestsPerHost = getEnvPropInteger(environmentProperties, "mlStagingForestsPerHost", stagingForestsPerHost);
@@ -183,6 +212,9 @@ public void loadConfigurationFromProperties(Properties environmentProperties) {
183212
triggersDbName = getEnvPropString(environmentProperties, "mlTriggersDbName", triggersDbName);
184213
schemasDbName = getEnvPropString(environmentProperties, "mlSchemasDbName", schemasDbName);
185214

215+
hubRoleName = getEnvPropString(environmentProperties, "mlHubUserRole", hubRoleName);
216+
hubUserName = getEnvPropString(environmentProperties, "mlHubUserName", hubUserName);
217+
186218
adminUsername = getEnvPropString(environmentProperties, "mlAdminUsername", adminUsername);
187219
adminPassword = getEnvPropString(environmentProperties, "mlAdminPassword", adminPassword);
188220

@@ -205,13 +237,14 @@ public void loadConfigurationFromProperties(Properties environmentProperties) {
205237
}
206238

207239
public ManageClient newManageClient() {
208-
ManageConfig config = new ManageConfig(host, 8002, username, password);
240+
ManageConfig config = new ManageConfig(host, managePort, getManageUsername(), getManagePassword());
209241
return new ManageClient(config);
210242
}
211243

212244
public AdminManager newAdminManager() {
213245
AdminConfig adminConfig = new AdminConfig();
214246
adminConfig.setHost(host);
247+
adminConfig.setPort(adminPort);
215248
adminConfig.setUsername(getAdminUsername());
216249
adminConfig.setPassword(getAdminPassword());
217250
return new AdminManager(adminConfig);
@@ -348,6 +381,10 @@ public Path getHubSecurityDir() {
348381
return Paths.get(this.projectDir, HUB_CONFIG_DIR, "security");
349382
}
350383

384+
public Path getUserSecurityDir() {
385+
return Paths.get(this.projectDir, USER_CONFIG_DIR, "security");
386+
}
387+
351388
public Path getUserConfigDir() {
352389
return Paths.get(this.projectDir, USER_CONFIG_DIR);
353390
}
@@ -487,6 +524,7 @@ public AppConfig getAppConfig() {
487524
public void updateAppConfig(AppConfig config) {
488525
config.setHost(host);
489526
config.setRestPort(stagingPort);
527+
config.setAppServicesPort(appServicesPort);
490528
config.setRestAdminUsername(getRestAdminUsername());
491529
config.setRestAdminPassword(getRestAdminPassword());
492530
config.setModulesDatabaseName(modulesDbName);
@@ -508,6 +546,8 @@ public void updateAppConfig(AppConfig config) {
508546
ConfigDir configDir = new ConfigDir(getUserConfigDir().toFile());
509547
config.setConfigDir(configDir);
510548

549+
config.setSchemasPath(getUserConfigDir().resolve("schemas").toString());
550+
511551
Map<String, String> customTokens = config.getCustomTokens();
512552

513553
customTokens.put("%%mlStagingAppserverName%%", stagingHttpName);
@@ -534,6 +574,9 @@ public void updateAppConfig(AppConfig config) {
534574
customTokens.put("%%mlTriggersDbName%%", triggersDbName);
535575
customTokens.put("%%mlSchemasDbName%%", schemasDbName);
536576

577+
customTokens.put("%%mlHubUserRole%%", hubRoleName);
578+
customTokens.put("%%mlHubUserName%%", hubUserName);
579+
537580
if (environmentProperties != null) {
538581
Enumeration keyEnum = environmentProperties.propertyNames();
539582
while (keyEnum.hasMoreElements()) {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ public HubProject(HubConfig config) {
6262
customTokens.put("%%mlModulesDbName%%", hubConfig.modulesDbName);
6363
customTokens.put("%%mlTriggersDbName%%", hubConfig.triggersDbName);
6464
customTokens.put("%%mlSchemasDbName%%", hubConfig.schemasDbName);
65+
66+
customTokens.put("%%mlHubUserRole%%", hubConfig.hubRoleName);
67+
customTokens.put("%%mlHubUserName%%", hubConfig.hubUserName);
6568
}
6669

6770
/**

0 commit comments

Comments
 (0)