Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 5e8a435

Browse files
authored
Merge pull request #494 from marklogic/feature/qbv-tde-fix
Fixing how TDE validation is disabled
2 parents 57a8aa7 + f797377 commit 5e8a435

File tree

3 files changed

+42
-24
lines changed

3 files changed

+42
-24
lines changed

src/main/java/com/marklogic/appdeployer/command/schemas/LoadSchemasCommand.java

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ protected void loadSchemasFromDatabaseSpecificPaths(CommandContext context) {
8080

8181
protected void loadSchemas(String schemasPath, String schemasDatabaseName, CommandContext context) {
8282
logger.info(format("Loading schemas into database %s from: %s", schemasDatabaseName, schemasPath));
83-
DatabaseClient client = buildDatabaseClient(schemasDatabaseName, context);
83+
DatabaseClient schemasClient = context.getAppConfig().newAppServicesDatabaseClient(schemasDatabaseName);
84+
DatabaseClient contentClient = buildContentClient(context, schemasDatabaseName);
8485
try {
85-
SchemasLoader schemasLoader = buildSchemasLoader(context, client, schemasDatabaseName);
86+
SchemasLoader schemasLoader = buildSchemasLoader(context, schemasClient, contentClient);
8687
schemasLoader.loadSchemas(schemasPath);
8788
logger.info("Finished loading schemas from: " + schemasPath);
8889
} catch (FailedRequestException fre) {
@@ -92,12 +93,29 @@ protected void loadSchemas(String schemasPath, String schemasDatabaseName, Comma
9293
throw fre;
9394
}
9495
} finally {
95-
client.release();
96+
schemasClient.release();
97+
if (contentClient != null) {
98+
contentClient.release();
99+
}
96100
}
97101
}
98102

99-
protected DatabaseClient buildDatabaseClient(String schemasDatabaseName, CommandContext context) {
100-
return context.getAppConfig().newAppServicesDatabaseClient(schemasDatabaseName);
103+
/**
104+
* Construct a content client, for use when validating TDEs and generating QBVs.
105+
*
106+
* @param context
107+
* @param schemasDatabase
108+
* @return
109+
*/
110+
private DatabaseClient buildContentClient(CommandContext context, String schemasDatabase) {
111+
String contentDatabase = findContentDatabaseAssociatedWithSchemasDatabase(context, schemasDatabase);
112+
if (contentDatabase != null) {
113+
logger.info(format("Will use %s as a content database when loading into schemas database: %s", contentDatabase, schemasDatabase));
114+
return context.getAppConfig().newAppServicesDatabaseClient(contentDatabase);
115+
}
116+
logger.warn(format("Unable to find a content database associated with schemas database: %s; this may " +
117+
"result in errors when loading TDE templates and Query-Based-View scripts."));
118+
return null;
101119
}
102120

103121
/**
@@ -106,24 +124,12 @@ protected DatabaseClient buildDatabaseClient(String schemasDatabaseName, Command
106124
* So given a schemasDatabaseName,
107125
*
108126
* @param context
109-
* @param client
127+
* @param schemasClient
110128
* @return
111129
*/
112-
protected SchemasLoader buildSchemasLoader(CommandContext context, DatabaseClient client, String schemasDatabaseName) {
130+
protected SchemasLoader buildSchemasLoader(CommandContext context, DatabaseClient schemasClient, DatabaseClient contentClient) {
113131
AppConfig appConfig = context.getAppConfig();
114-
115-
String tdeValidationDatabase = null;
116-
if (appConfig.isTdeValidationEnabled()) {
117-
tdeValidationDatabase = findContentDatabaseAssociatedWithSchemasDatabase(context, schemasDatabaseName);
118-
if (tdeValidationDatabase != null) {
119-
logger.info(format("TDE templates loaded into %s will be validated against content database %s",
120-
schemasDatabaseName, tdeValidationDatabase));
121-
}
122-
} else {
123-
logger.info("TDE validation is disabled");
124-
}
125-
126-
DefaultSchemasLoader schemasLoader = new DefaultSchemasLoader(client, tdeValidationDatabase);
132+
DefaultSchemasLoader schemasLoader = new DefaultSchemasLoader(schemasClient, contentClient, context.getAppConfig().isTdeValidationEnabled());
127133
schemasLoader.setCascadeCollections(appConfig.isCascadeCollections());
128134
schemasLoader.setCascadePermissions(appConfig.isCascadePermissions());
129135
FileFilter filter = appConfig.getSchemasFileFilter();

src/test/java/com/marklogic/appdeployer/command/schemas/LoadSchemasTest.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class LoadSchemasTest extends AbstractAppDeployerTest {
3939

4040
@AfterEach
4141
public void cleanup() {
42-
undeploySampleApp();
42+
// undeploySampleApp();
4343
}
4444

4545
@Test
@@ -153,6 +153,9 @@ public void multipleSchemaPaths() {
153153
File projectDir = new File("src/test/resources/schemas-project");
154154

155155
initializeAppConfig(projectDir);
156+
157+
// Turn off TDE validation, just to verify that the QBV still gets processed
158+
appConfig.setTdeValidationEnabled(false);
156159
appConfig.getSchemaPaths().add(new File(projectDir, "src/main/more-schemas").getAbsolutePath());
157160

158161
initializeAppDeployer(new DeployOtherDatabasesCommand(1), new LoadSchemasCommand());
@@ -162,9 +165,15 @@ public void multipleSchemaPaths() {
162165
GenericDocumentManager docMgr = client.newDocumentManager();
163166
assertNotNull(docMgr.exists("/tde/template1.json"));
164167
assertNotNull(docMgr.exists("/tde/template2.json"));
165-
166-
assertTrue(docMgr.readMetadata("/tde/template1.json", new DocumentMetadataHandle()).getCollections().contains("http://marklogic.com/xdmp/tde"));
167-
assertTrue(docMgr.readMetadata("/tde/template2.json", new DocumentMetadataHandle()).getCollections().contains("http://marklogic.com/xdmp/tde"));
168+
assertNotNull(docMgr.exists("/qbv/example.sjs.xml"),
169+
"The QBV XML should have been generated, even though TDE validation is disabled.");
170+
171+
assertTrue(docMgr.readMetadata("/tde/template1.json",
172+
new DocumentMetadataHandle()).getCollections().contains("http://marklogic.com/xdmp/tde"));
173+
assertTrue(docMgr.readMetadata("/tde/template2.json",
174+
new DocumentMetadataHandle()).getCollections().contains("http://marklogic.com/xdmp/tde"));
175+
assertTrue(docMgr.readMetadata("/qbv/example.sjs.xml",
176+
new DocumentMetadataHandle()).getCollections().contains("http://marklogic.com/xdmp/qbv"));
168177
}
169178

170179
/**
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
const op = require('/MarkLogic/optic');
3+
op.fromView('Example2', 'default').generateView('qbv', 'example')

0 commit comments

Comments
 (0)