Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
ml-app-deployer for loadSchemasData
  • Loading branch information
Charles Greer committed Mar 15, 2016
commit a14d3e7f956d1571df46d728b4b33ea7502434d6
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ targetCompatibility = "1.7"

repositories {
jcenter()
mavenLocal()
}

dependencies {
compile 'com.marklogic:ml-javaclient-util:2.5'
compile 'com.marklogic:ml-javaclient-util:2.6'
compile 'jaxen:jaxen:1.1.6'
compile 'org.apache.httpcomponents:httpclient:4.3.5'
compile 'org.springframework:spring-web:4.1.5.RELEASE'
Expand Down
21 changes: 17 additions & 4 deletions src/main/java/com/marklogic/appdeployer/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.marklogic.client.modulesloader.impl.XccAssetLoader;
import com.marklogic.client.modulesloader.ssl.SimpleX509TrustManager;
import com.marklogic.client.modulesloader.xcc.DefaultDocumentFormatGetter;
import com.marklogic.mgmt.ManageClient;

/**
* Encapsulates common configuration properties for an application deployed to MarkLogic. These properties include not
Expand Down Expand Up @@ -56,7 +57,7 @@ public class AppConfig {

private String name = DEFAULT_APP_NAME;
private String host = DEFAULT_HOST;

// Username/password combo for using the client REST API - e.g. to load modules
private String restAdminUsername = DEFAULT_USERNAME;
private String restAdminPassword = DEFAULT_PASSWORD;
Expand Down Expand Up @@ -100,7 +101,8 @@ public class AppConfig {
// Comma-delimited string used for configuring forest replicas
private String databaseNamesAndReplicaCounts;

public AppConfig() {

public AppConfig() {
this(DEFAULT_MODULES_PATH);
}

Expand Down Expand Up @@ -135,6 +137,18 @@ public DatabaseClient newTestDatabaseClient() {
return DatabaseClientFactory.newClient(getHost(), getTestRestPort(), getRestAdminUsername(),
getRestAdminPassword(), getRestAuthentication(), getRestSslContext(), getRestSslHostnameVerifier());
}

/**
* Like newDatabaseClient, but connects to schemas database.
*
* @return
*/
public DatabaseClient newSchemasDatabaseClient() {
return DatabaseClientFactory.newClient(getHost(), getRestPort(), getSchemasDatabaseName(),
getRestAdminUsername(), getRestAdminPassword(), getRestAuthentication(),
getRestSslContext(), getRestSslHostnameVerifier());
}


/**
* @return an XccAssetLoader based on the configuration properties in this class
Expand Down Expand Up @@ -225,7 +239,7 @@ public String getTriggersDatabaseName() {
public String getSchemasDatabaseName() {
return schemasDatabaseName != null ? schemasDatabaseName : name + "-schemas";
}

/**
* @return the name of the application, which is then used to generate app server and database names unless those
* are set via their respective properties
Expand Down Expand Up @@ -458,5 +472,4 @@ public FileFilter getAssetFileFilter() {
public void setAssetFileFilter(FileFilter assetFileFilter) {
this.assetFileFilter = assetFileFilter;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.marklogic.appdeployer.command.schemas;

import java.io.File;

import com.marklogic.appdeployer.AppConfig;
import com.marklogic.appdeployer.command.AbstractCommand;
import com.marklogic.appdeployer.command.CommandContext;
import com.marklogic.appdeployer.command.SortOrderConstants;
import com.marklogic.client.DatabaseClient;
import com.marklogic.client.dataloader.SchemasDataLoader;
import com.marklogic.client.dataloader.impl.DefaultSchemasDataFinder;
import com.marklogic.client.dataloader.impl.DefaultSchemasDataLoader;

public class LoadSchemasDataCommand extends AbstractCommand {

private SchemasDataLoader schemasDataLoader;

public LoadSchemasDataCommand() {
setExecuteSortOrder(SortOrderConstants.DEPLOY_SQL_VIEWS);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this use a different sort order? I'm wondering if its sort order should be right around when modules are loaded. I don't know enough about schemas to know if there are any dependencies on them that would govern when they should be loaded.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right -- there could be modules that depend on shemas. I'll figure out where it goes, or make a new key for schemas

Created new sort order == 350 for this operation.

}

@Override
public void execute(CommandContext context) {
loadSchemasDataIntoSchemasDatabase(context);
}

protected void loadSchemasDataIntoSchemasDatabase(CommandContext context) {
if (schemasDataLoader == null) {
initializeDefaultSchemasDataLoader(context);
}


AppConfig config = context.getAppConfig();
DatabaseClient client = config.newSchemasDatabaseClient();
try {
File schemasDataDir = config.getConfigDir().getBaseDir();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename this to baseDir? Just for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, done


logger.info("Loading schemas database data from dir: " + schemasDataDir);
schemasDataLoader.loadSchemasData(schemasDataDir, new DefaultSchemasDataFinder(), client);

} finally {
client.release();
}
}

private void initializeDefaultSchemasDataLoader(CommandContext context) {
logger.info("Initializing instance of DefaultSchemasLoader");
this.schemasDataLoader = new DefaultSchemasDataLoader();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.marklogic.appdeployer.command.schemas;

import org.junit.Test;

import com.marklogic.appdeployer.AbstractAppDeployerTest;
import com.marklogic.appdeployer.command.Command;
import com.marklogic.appdeployer.command.databases.DeployContentDatabasesCommand;
import com.marklogic.appdeployer.command.databases.DeploySchemasDatabaseCommand;
import com.marklogic.appdeployer.command.databases.DeployTriggersDatabaseCommand;
import com.marklogic.appdeployer.command.restapis.DeployRestApiServersCommand;

public class LoadSchemasDataTest extends AbstractAppDeployerTest {

@Test
public void testSchemaLoading() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the test should do 2 more things - verify that the test schema files are now in the application's schemas database (should be able to use appConfig.newSchemasDatabaseClient() for that), and then include an @after method that calls undeploySampleApp() to ensure everything is cleaned up.

I don't have a Travis/Jenkins/etc job for running these tests, but I do run them before creating new builds, so I put a lot of value in them. They take just under 20 minutes right now to run - a lot of the time is spent deleting app servers and waiting for ML to restart.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

initializeAppDeployer(new DeploySchemasDatabaseCommand(),
new DeployTriggersDatabaseCommand(),
new DeployContentDatabasesCommand(1),
new DeployRestApiServersCommand(),
newCommand());
appDeployer.deploy(appConfig);



//.undeploy(appConfig);
}

private Command newCommand() {
return new LoadSchemasDataCommand();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2014-2016 MarkLogic Corporation. All Rights Reserved.

prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>

tbox {
?p rdfs:domain ?c .
}

rule "domain axioms" construct {
rdfs:domain rdfs:domain rdf:Property .
rdfs:domain rdfs:range rdfs:Class .
} {}

rule "domain rdfs2" construct {
?x a ?c
} {
?x ?p ?y .
?p rdfs:domain ?c
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<xsm>
</xsm>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"scalar-type": "int"
}
],
"triple-index":true,
"collection-lexicon":true,
"triggers-database": "%%TRIGGERS_DATABASE%%",
"schema-database": "%%SCHEMAS_DATABASE%%"
}