Skip to content

Commit 486ab3e

Browse files
georgeajitgeorgeajit
authored andcommitted
No Task - Added support for distribute timestamp set to cluster on REST
server
1 parent 8458802 commit 486ab3e

File tree

1 file changed

+46
-0
lines changed
  • marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/functionaltest

1 file changed

+46
-0
lines changed

marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/functionaltest/ConnectedRESTQA.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ public abstract class ConnectedRESTQA {
105105
private static String ml_certificate_path = null;
106106
private static String mlDataConfigDirPath = null;
107107
private static Boolean isLBHost = false;
108+
109+
private static int PROPERTY_WAIT = 0;
108110

109111
SSLContext sslContext = null;
110112

@@ -2325,6 +2327,8 @@ public static void configureRESTServer(String dbName, String[] fNames) throws Ex
23252327
setupJavaRESTServer(dbName, fNames[0], restSslServerName, getRestServerPort());
23262328
else
23272329
setupJavaRESTServer(dbName, fNames[0], restServerName, getRestServerPort());
2330+
if (isLBHost())
2331+
setRESTServerWithDistributeTimestamps(restServerName, "cluster");
23282332
}
23292333

23302334
/**
@@ -2541,6 +2545,7 @@ public static void loadGradleProperties() {
25412545
ml_certificate_path = property.getProperty("ml_certificate_path");
25422546
mlDataConfigDirPath = property.getProperty("mlDataConfigDirPath");
25432547
isLBHost = Boolean.parseBoolean(property.getProperty("lbHost"));
2548+
PROPERTY_WAIT = Integer.parseInt(isLBHost ? "15000" : "0");
25442549
}
25452550

25462551
public static boolean isLBHost() {
@@ -2986,4 +2991,45 @@ public static int getDocumentCount(String dbName) throws IOException {
29862991
}
29872992
return nCount;
29882993
}
2994+
// Wait for all nodes to be informed when property is updated in AWS env
2995+
public static void waitForPropertyPropagate() {
2996+
waitFor(PROPERTY_WAIT);
2997+
}
2998+
2999+
public static void waitFor(int milliseconds) {
3000+
if (milliseconds > 0) {
3001+
try {
3002+
Thread.sleep(milliseconds);
3003+
} catch (InterruptedException e) {
3004+
e.printStackTrace(System.out);
3005+
}
3006+
}
3007+
}
3008+
/*
3009+
* Associate REST server with timestamps in "distribute timestamps" to specify distribution of commit timestamps
3010+
* For example set to "strict" for Application Load Balancing (AWS)
3011+
*
3012+
*/
3013+
private static void setRESTServerWithDistributeTimestamps(String restServerName, String distributeTimestampType) throws Exception {
3014+
DefaultHttpClient client = new DefaultHttpClient();
3015+
3016+
client.getCredentialsProvider().setCredentials(new AuthScope(host_name, getAdminPort()),
3017+
new UsernamePasswordCredentials("admin", "admin"));
3018+
String extSecurityrName = "";
3019+
String body = "{\"group-name\": \"Default\",\"distribute-timestamps\": \"" + distributeTimestampType + "\"}";
3020+
;
3021+
3022+
HttpPut put = new HttpPut("http://" + host_name + ":" + admin_port + "/manage/v2/servers/" + restServerName
3023+
+ "/properties?server-type=http");
3024+
put.addHeader("Content-type", "application/json");
3025+
put.setEntity(new StringEntity(body));
3026+
3027+
HttpResponse response2 = client.execute(put);
3028+
HttpEntity respEntity = response2.getEntity();
3029+
if (respEntity != null) {
3030+
String content = EntityUtils.toString(respEntity);
3031+
System.out.println(content);
3032+
}
3033+
client.getConnectionManager().shutdown();
3034+
}
29893035
}

0 commit comments

Comments
 (0)