Skip to content
Open
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 @@ -62,16 +62,13 @@ protected void loadModulesIntoMainServer(CommandContext context) {
}

AppConfig config = context.getAppConfig();
DatabaseClient client = config.newDatabaseClient();

final List<String> pathsList = config.getModulePaths();
final String[] pathsArray = pathsList.toArray(new String[]{});

try {
logger.info("Loading modules from paths: " + pathsList);
try (DatabaseClient client = config.newDatabaseClient()) {
logger.info("Loading modules from paths: {}", pathsList);
modulesLoader.loadModules(client, new DefaultModulesFinder(), pathsArray);
} finally {
client.release();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.marklogic.appdeployer.command.AbstractUndoableCommand;
import com.marklogic.appdeployer.command.CommandContext;
import com.marklogic.appdeployer.command.SortOrderConstants;
import com.marklogic.client.ext.helper.DatabaseClientSupplier;
import com.marklogic.client.DatabaseClient;
import com.marklogic.client.document.BinaryDocumentManager;
import com.marklogic.client.eval.ServerEvaluationCall;
Expand Down Expand Up @@ -39,9 +40,10 @@ public void execute(CommandContext context) {
return;
}

DatabaseClient client = determineDatabaseClient(context.getAppConfig());
for (String path : paths) {
installPluginsInPath(path, context.getAppConfig(), client);
try (DatabaseClientSupplier clientSupplier = new DatabaseClientSupplier(() -> determineDatabaseClient(context.getAppConfig()))) {
for (String path : paths) {
installPluginsInPath(path, context.getAppConfig(), clientSupplier);
}
}
}

Expand All @@ -52,9 +54,10 @@ public void undo(CommandContext context) {
return;
}

DatabaseClient client = determineDatabaseClient(context.getAppConfig());
for (String path : paths) {
uninstallPluginsInPath(path, context.getAppConfig(), client);
try (DatabaseClientSupplier clientSupplier = new DatabaseClientSupplier(() -> determineDatabaseClient(context.getAppConfig()))) {
for (String path : paths) {
uninstallPluginsInPath(path, context.getAppConfig(), clientSupplier);
}
}
}

Expand All @@ -72,7 +75,7 @@ protected List<String> getPluginPaths(CommandContext context) {
return config.getPluginPaths();
}

protected void installPluginsInPath(String path, AppConfig appConfig, DatabaseClient client) {
protected void installPluginsInPath(String path, AppConfig appConfig, DatabaseClientSupplier clientSupplier) {
File pluginsDir = new File(path);
if (pluginsDir == null || !pluginsDir.exists()) {
return;
Expand All @@ -86,9 +89,9 @@ protected void installPluginsInPath(String path, AppConfig appConfig, DatabaseCl
}

makePlugin(dir, appConfig);
final String binaryUri = insertPluginZip(dir, appConfig, client);
final String binaryUri = insertPluginZip(dir, appConfig, clientSupplier.get());
if (binaryUri != null) {
installPlugin(binaryUri, appConfig, client);
installPlugin(binaryUri, appConfig, clientSupplier.get());
}
}
}
Expand Down Expand Up @@ -151,7 +154,7 @@ protected void installPlugin(String uri, AppConfig appConfig, DatabaseClient cli
logger.info(format("Installed plugin with scope '%s', result: %s", scope, result));
}

protected void uninstallPluginsInPath(String path, AppConfig appConfig, DatabaseClient client) {
protected void uninstallPluginsInPath(String path, AppConfig appConfig, DatabaseClientSupplier clientSupplier) {
File pluginsDir = new File(path);
if (pluginsDir == null || !pluginsDir.exists()) {
return;
Expand All @@ -166,15 +169,15 @@ protected void uninstallPluginsInPath(String path, AppConfig appConfig, Database

final String pluginName = getPluginName(file, appConfig);
if (pluginName != null) {
uninstallPlugin(pluginName, appConfig, client);
uninstallPlugin(pluginName, appConfig, clientSupplier.get());
}
}
}
}

protected String getPluginName(File dir, AppConfig appConfig) {
File manifestFile = new File(dir, "manifest.xml");
if (manifestFile == null || !manifestFile.exists()) {
if (!manifestFile.exists()) {
// Need to make the plugin so the metadata file is guaranteed to exist
makePlugin(dir, appConfig);
manifestFile = new File(dir, "manifest.xml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ public InsertCertificateHostsTemplateCommand() {

@Override
public void execute(CommandContext context) {
// A query has to be made to MarkLogic here to get the list of certificate template names, because otherwise,
// we don't know what template names to look for in the user's project directory.
List<String> templateNames = new CertificateTemplateManager(context.getManageClient()).getAsXml().getListItemNameRefs();
if (templateNames != null && !templateNames.isEmpty()) {
if (logger.isInfoEnabled()) {
logger.info("Looking for host certificates to insert for certificate templates: " + templateNames);
logger.info("Looking for host certificates to insert for certificate templates: {}", templateNames);
}
for (String templateName : templateNames) {
insertHostCertificatesForTemplate(context, templateName);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
package com.marklogic.client.ext.helper;

import com.marklogic.client.DatabaseClient;

import java.io.Closeable;
import java.util.function.Supplier;

/**
* Preferred mechanism for lazy instantiation of a DatabaseClient. Will eventually deprecate DatabaseClientProvider in
* favor of this.
*
* @since 6.2.0
*/
public class DatabaseClientSupplier implements Closeable, Supplier<DatabaseClient> {

private DatabaseClient databaseClient;
private final Supplier<DatabaseClient> databaseClientSupplier;

/**
* @param databaseClientSupplier delegates construction of the client to the given supplier. Will then hold onto
* an instance of the client after it's created so that it's only created once.
*/
public DatabaseClientSupplier(Supplier<DatabaseClient> databaseClientSupplier) {
this.databaseClientSupplier = databaseClientSupplier;
}

public DatabaseClient get() {
if (databaseClient == null) {
databaseClient = databaseClientSupplier.get();
}
return databaseClient;
}

@Override
public void close() {
if (databaseClient != null) {
databaseClient.close();
}
}
}