Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add whitelist #672

Merged
merged 3 commits into from
Jan 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ public class HubConfig {
public String hubRoleName = DEFAULT_ROLE_NAME;
public String hubUserName = DEFAULT_USER_NAME;

public String[] loadBalancerHosts;

public String customForestPath = DEFAULT_CUSTOM_FOREST_PATH;

public String modulePermissions = "rest-reader,read,rest-writer,insert,rest-writer,update,rest-extension-user,execute";
Expand Down Expand Up @@ -345,6 +347,11 @@ private void loadConfigurationFromProperties(Properties environmentProperties) {
hubRoleName = getEnvPropString(environmentProperties, "mlHubUserRole", hubRoleName);
hubUserName = getEnvPropString(environmentProperties, "mlHubUserName", hubUserName);

String lbh = getEnvPropString(environmentProperties, "mlLoadBalancerHosts", null);
if (lbh != null && lbh.length() > 0) {
loadBalancerHosts = lbh.split(",");
}

projectDir = getEnvPropString(environmentProperties, "hubProjectDir", projectDir);

logger.info("Hub Project Dir: " + projectDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public JobTicket run() {

HashMap<String, JobTicket> ticketWrapper = new HashMap<>();

QueryBatcher queryBatcher = dataMovementManager.newQueryBatcher(uris.iterator())
QueryBatcher tempQueryBatcher = dataMovementManager.newQueryBatcher(uris.iterator())
.withBatchSize(batchSize)
.withThreadCount(threadCount)
.onUrisReady((QueryBatch batch) -> {
Expand Down Expand Up @@ -275,6 +275,17 @@ public JobTicket run() {
failedEvents.addAndGet(batchSize);
});


if (hubConfig.loadBalancerHosts != null && hubConfig.loadBalancerHosts.length > 0){
tempQueryBatcher = tempQueryBatcher.withForestConfig(
new FilteredForestConfiguration(
dataMovementManager.readForestConfig()
).withWhiteList(hubConfig.loadBalancerHosts)
);
}
QueryBatcher queryBatcher = tempQueryBatcher;


JobTicket jobTicket = dataMovementManager.startJob(queryBatcher);
ticketWrapper.put("jobTicket", jobTicket);
jobManager.saveJob(job.withStatus(JobStatus.RUNNING_HARMONIZE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,9 @@ mlHubUserRole=%%mlHubUserRole%%
mlHubUserName=%%mlHubUserName%%
# this password is autogenerated for you via the 'gradle hubInit' task
mlHubUserPassword=%%mlHubUserPassword%%

# If you are working with a load balancer you can
# specify the hostname(s) of the load balancer here separated by commas
# see: https://docs.marklogic.com/guide/java/data-movement#id_26583
# for more info about what's happening under the hood
# mlLoadBalancerHosts=your-load-balancer-hostnames,separated,by-commas
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.marklogic.hub;

import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

public class HubConfigTest extends HubTestBase {

private static File projectPath = new File(PROJECT_PATH);

@Before
public void setup() throws IOException {
FileUtils.deleteDirectory(projectPath);
HubConfig config = getHubConfig();
config.initHubProject();
}

@After
public void teardown() throws IOException {
FileUtils.deleteDirectory(projectPath);
}

private void deleteProp(String key) {
try {
File gradleProperties = new File(projectPath, "gradle.properties");
Properties props = new Properties();
props.load(new FileInputStream(gradleProperties));
props.remove(key);
props.store(new FileOutputStream(gradleProperties), "");
}
catch(IOException e) {
throw new RuntimeException(e);
}
}

private void writeProp(String key, String value) {
try {
File gradleProperties = new File(projectPath, "gradle.properties");
Properties props = new Properties();
props.load(new FileInputStream(gradleProperties));
props.put(key, value);
props.store(new FileOutputStream(gradleProperties), "");
}
catch(IOException e) {
throw new RuntimeException(e);
}
}

@Test
public void testLoadBalancerProps() {
deleteProp("mlLoadBalancerHosts");
assertNull(getHubConfig().loadBalancerHosts);

writeProp("mlLoadBalancerHosts", "");
assertNull(getHubConfig().loadBalancerHosts);

writeProp("mlLoadBalancerHosts", "host1,host2");
HubConfig config = getHubConfig();
assertEquals(2, config.loadBalancerHosts.length);
assertEquals("host1", config.loadBalancerHosts[0]);
assertEquals("host2", config.loadBalancerHosts[1]);

writeProp("mlLoadBalancerHosts", "host1");
config = getHubConfig();
assertEquals(1, config.loadBalancerHosts.length);
assertEquals("host1", config.loadBalancerHosts[0]);
}

}