Skip to content

Commit

Permalink
DHFPROD-10497: Update Marklogic Version Compatability
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulvudutala authored and MarkLogic Builder committed Jul 24, 2023
1 parent 226b68f commit d229c56
Show file tree
Hide file tree
Showing 31 changed files with 115 additions and 475 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,12 @@ protected ObjectNode canInstallDhs(){
protected ObjectNode canInstallDhs(String installedHubVersion, MarkLogicVersion mlVersion) {
ObjectMapper mapper = new ObjectMapper();
ObjectNode node = mapper.createObjectNode();
if (installedHubVersion != null && Character.getNumericValue(installedHubVersion.charAt(0)) < 5) {

if(mlVersion.supportsDataHubFramework()) {
node.put("canBeInstalled", true);
} else {
node.put("canBeInstalled", false);
node.put("message", "DHF cannot be upgraded when the major version of the existing DHF instance is 4");
}
else {
if (mlVersion.isVersionCompatibleWith520Roles()) {
node.put("canBeInstalled", true);
}
else {
node.put("canBeInstalled", false);
node.put("message", "DHF 5.3.0 and higher require MarkLogic 10.0-3 or higher for the use of granular privileges");
}
node.put("message", String.format("DHF cannot be installed on the %s marklogic version", mlVersion));
}
return node;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
package com.marklogic.hub;

import com.marklogic.mgmt.ManageClient;
import org.apache.commons.lang3.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
* Can parse the version string returned by the Manage API so that clients can determine if the version of MarkLogic
Expand Down Expand Up @@ -60,88 +62,43 @@ public String getVersionString() {
return versionString;
}

/*
* The DHF 5.2.0 roles depend on granular privileges that are first available in ML 10.0-3.
*/
public boolean isVersionCompatibleWith520Roles() {
if (nightly) {
return major >= 10;
}

return major > 10 || (major == 10 && minor >= 300);
}

/*
* Users should be able to update amps on versions > 10.0-4.4
*/
public boolean cannotUpdateAmps() {
if (nightly) {
return false;
}

return major == 10 && minor == 404;
}

/*
* Compares current ML version with the minimum required version and fails immediately
* if current ML version is lower than the minimum required version.
*/
public boolean supportsDataHubFramework() {
if (nightly) {
if (nightly && major >= 10) {
return true;
}

return major > 10 || (major == 10 && minor >= 201) || (major == 9 && minor >= 1100);
return major >= 11 || (major == 10 && minor >= 1000);
}

/*
* Range constraints from Entity Services weren't returned until ML 10.0-4
*/
public boolean supportsRangeIndexConstraints() {
if (nightly) {
return major >= 10;
}

return major > 10 || (major == 10 && minor >= 400);
}
private void parseMarkLogicVersionString(String version) {
String[] versionArr = version.split("[.-]");

private void parseMarkLogicVersionString(String versionString) {
this.major = Integer.parseInt(versionArr[0]);
try {
int major = Integer.parseInt(versionString.replaceAll("([^.]+)\\..*", "$1"));
int minor = 0;
boolean isNightly = versionString.matches("[^-]+[-|.](\\d{4})(\\d{2})(\\d{2})($|-\\d{1})");

if (isNightly) {
this.dateString = versionString.replaceAll("[^-]+[-|.](\\d{4})(\\d{2})(\\d{2})($|-\\d{1})", "$1-$2-$3");
this.nightly = true;
}
else {
//Extract minor version in cases where versions is of type 9.0-6 or 9.0-6.2
if (versionString.matches("^.*[-|.](.+)\\..*")) {
minor = Integer.parseInt(versionString.replaceAll("^.*[-|.](.+)\\..*", "$1"));
}
else if (versionString.matches("^.*[-|.](.+)$")) {
minor = Integer.parseInt(versionString.replaceAll("^.*[-|.](.+)$", "$1"));
}
//left pad minor version with 0 if it is < 10
String modifiedMinor = minor < 10 ? StringUtils.leftPad(String.valueOf(minor), 2, "0") : String.valueOf(minor);

int hotFixNum = 0;

//Extract hotfix in cases where versions is of type 9.0-6.2, if not it will be 0
if (versionString.matches("^.*[-|.](.+)\\.(.*)")) {
hotFixNum = Integer.parseInt(versionString.replaceAll("^.*[-|.](.+)\\.(.*)", "$2"));
}
//left pad minor version with 0 if it is < 10
String modifiedHotFixNum = hotFixNum < 10 ? StringUtils.leftPad(String.valueOf(hotFixNum), 2, "0") : String.valueOf(hotFixNum);
String alteredString = StringUtils.join(modifiedMinor, modifiedHotFixNum);
this.minor = Integer.parseInt(alteredString);
}
this.major = major;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = dateFormat.parse(versionArr[2]);

this.nightly = true;
this.dateString = outputFormat.format(date);
return;
} catch (Exception e) {
this.nightly = false;
}
catch (Exception e) {
throw new RuntimeException("Unable to parse MarkLogic version string, cause: " + e.getMessage(), e);

int minor, patch;
if(major <= 10) {
minor = versionArr.length > 2 ? Integer.parseInt(versionArr[2]) : 0;
patch = versionArr.length > 3 ? Integer.parseInt(versionArr[3]) : 0;
} else {
minor = versionArr.length > 1 ? Integer.parseInt(versionArr[1]) : 0;
patch = versionArr.length > 2 ? Integer.parseInt(versionArr[2]) : 0;
}
this.minor = minor * 100 + patch;
}

private String getMarkLogicVersionString(ManageClient manageClient) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ void testRowExportFromStagingDatabase() throws Exception {

@Test
void testRowExportWithPathRangeQuery() throws Exception {
assumeTrue(new Versions(getHubConfig()).getMarkLogicVersion().supportsRangeIndexConstraints());
ReferenceModelProject project = installOnlyReferenceModelEntities(true);
deployEntityIndexes();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ public class FlowControllerTest extends AbstractMvcTest {
private final static String PATH = "/api/flows";
private int initialFlowCount;

@BeforeEach
void beforeEach() {
Assumptions.assumeTrue(isVersionCompatibleWith520Roles(),
"A bug in ML 9 prevents amps from working on exported SJS functions correctly, " +
"such that job/batch documents cannot be updated unless the user has flow-operator-role or greater");
}

@Test
void test() throws Exception {
installReferenceModelProject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ void loadHubArtifactsInCaseAnythingWentWrongAndTheyreNoLongerThere() {

@Test
void permittedUser() throws Exception {
if (!isVersionCompatibleWith520Roles()) {
return;
}

installReferenceModelProject();

loginAsTestUserWithRoles("hub-central-clear-user-data");
Expand All @@ -36,9 +32,6 @@ void permittedUser() throws Exception {

@Test
void forbiddenUser() throws Exception {
if (!isVersionCompatibleWith520Roles()) {
return;
}
loginAsTestUserWithRoles("hub-central-user","data-hub-developer");
verifyRequestIsForbidden(post(PATH));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ public class ModelTest extends AbstractHubCentralTest {
@AfterEach
void cleanUp() {
deleteProtectedPaths();
if (isVersionCompatibleWith520Roles()) {
applyDatabasePropertiesForTests(getHubConfig());
}
applyDatabasePropertiesForTests(getHubConfig());
}

protected void createNamespacedModel() {
Expand Down Expand Up @@ -150,7 +148,6 @@ protected void verifyGraphConfig(JsonNode model){
}

protected void updateModelWithGraphConfig(){
Assumptions.assumeTrue(isVersionCompatibleWith520Roles());
String entityTypes = "[\n" +
"{\n" +
"\"entityName\": \"Customer\", \n" +
Expand Down Expand Up @@ -239,8 +236,6 @@ public void deleteModel() {
}

protected void updateModelEntityTypes() {
Assumptions.assumeTrue(isVersionCompatibleWith520Roles());

// Loading unrelated indexes so that we can check for them after updating entity model
loadUnrelatedIndexes();

Expand Down Expand Up @@ -282,8 +277,6 @@ protected void updateModelEntityTypes() {
}

protected void updateDataType(String datatype) {
Assumptions.assumeTrue(isVersionCompatibleWith520Roles());

String entityTypes = "[\n" +
" {\n" +
" \"entityName\": \"" + MODEL_NAME + "\",\n" +
Expand All @@ -308,8 +301,6 @@ protected void updateDataType(String datatype) {
}

protected void addProperty() {
Assumptions.assumeTrue(isVersionCompatibleWith520Roles());

String entityTypes = "[\n" +
" {\n" +
" \"entityName\": \"" + MODEL_NAME + "\",\n" +
Expand Down Expand Up @@ -475,20 +466,12 @@ protected void deployDataHubDefaultFields() {
}

protected void publishDraftModels() {
if (isVersionCompatibleWith520Roles()) {
runAsDataHubDeveloper();
} else {
runAsAdmin();
}
runAsDataHubDeveloper();
assertDoesNotThrow(() -> controller.publishDraftModels(), "Should publish the deleted draft with no issues.");
}

protected void clearDraftModels() {
if (isVersionCompatibleWith520Roles()) {
runAsDataHubDeveloper();
} else {
runAsAdmin();
}
runAsDataHubDeveloper();
assertDoesNotThrow(() -> controller.clearDraftModels(), "Should clear the unpublished entities data");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ public class EntitySearchManagerTest extends AbstractHubCentralTest {

@AfterEach
public void resetData() {
if (isVersionCompatibleWith520Roles()) {
runAsDataHubDeveloper();
} else {
runAsDeprecatedFlowDeveloper();
}
runAsDataHubDeveloper();
applyDatabasePropertiesForTests(getHubConfig());
}

Expand Down Expand Up @@ -109,10 +105,6 @@ public void testSearchResultsWithSorting() {
runAsDataHubDeveloper();
installProjectInFolder("customer-entity-with-indexes", true);

if (!isVersionCompatibleWith520Roles()) {
runAsDeprecatedFlowDeveloper();
}

new EntityManagerImpl(getHubConfig()).saveDbIndexes();
deployAsDeveloper(getHubConfig());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,15 @@ private void verifyPersonSearchResults() {
assertEquals("/person1990.json", results.get(0).get("uri").asText());
assertEquals("/person1991.json", results.get(1).get("uri").asText());

if (supportsRangeIndexConstraints()) {
// Verify an entity-specific facet
JsonNode statusFacet = response.get("facets").get("Person.status");
assertNotNull(statusFacet, "Expecting Person.status facet to exist; response: " + response.toPrettyString());
assertEquals(1, statusFacet.get("facetValues").size(), "Expecting the status value to be returned; this ensures " +
"that both the database indexes and the range constraints were modified to conform to the project-specific path " +
"of /customEnvelope/Person/status/value instead of assuming the ES-specific path");
assertEquals("Active", statusFacet.get("facetValues").get(0).get("name").asText());
assertEquals(2, statusFacet.get("facetValues").get(0).get("count").asInt(), "Expecting a count of 2 since each of " +
"the 2 persons has a status of 'Active'");
}
// Verify an entity-specific facet
JsonNode statusFacet = response.get("facets").get("Person.status");
assertNotNull(statusFacet, "Expecting Person.status facet to exist; response: " + response.toPrettyString());
assertEquals(1, statusFacet.get("facetValues").size(), "Expecting the status value to be returned; this ensures " +
"that both the database indexes and the range constraints were modified to conform to the project-specific path " +
"of /customEnvelope/Person/status/value instead of assuming the ES-specific path");
assertEquals("Active", statusFacet.get("facetValues").get(0).get("name").asText());
assertEquals(2, statusFacet.get("facetValues").get(0).get("count").asInt(), "Expecting a count of 2 since each of " +
"the 2 persons has a status of 'Active'");
// Verify entity-specific property values
ArrayNode entityProps = (ArrayNode) results.get(0).get("entityProperties");
assertEquals(3, entityProps.size(), "Expecting name, status, and birthYear properties, since those are the 3 " +
Expand Down Expand Up @@ -184,10 +182,8 @@ private void verifySearchOptionsWereModified() {
options.getElementValue("/s:options/s:operator/s:state[@name = 'Person_birthYearAscending']/s:sort-order/s:path-index"));
assertEquals("/customEnvelope/Person/birthYear/value",
options.getElementValue("/s:options/s:operator/s:state[@name = 'Person_birthYearDescending']/s:sort-order/s:path-index"));
if (supportsRangeIndexConstraints()) {
assertEquals("/customEnvelope/Person/status/value",
options.getElementValue("/s:options/s:constraint[@name = 'Person.status']/s:range/s:path-index"));
}
assertEquals("/customEnvelope/Person/status/value",
options.getElementValue("/s:options/s:constraint[@name = 'Person.status']/s:range/s:path-index"));
}

private void verifyDatabaseIndexesWereModified() {
Expand Down
Loading

0 comments on commit d229c56

Please sign in to comment.