Skip to content

Commit 3fc5055

Browse files
committed
MLE-25605 Tweaking support for MarkLogic endpoints in PDC
Did some renaming based on the terminology used by the PDC API. Added some logging to assist with debugging when a MarkLogic endpoint does not exist.
1 parent 06287d7 commit 3fc5055

File tree

8 files changed

+45
-26
lines changed

8 files changed

+45
-26
lines changed

ml-app-deployer/src/main/java/com/marklogic/appdeployer/AppConfig.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import com.marklogic.appdeployer.command.forests.ForestNamingStrategy;
77
import com.marklogic.appdeployer.command.forests.ReplicaBuilderStrategy;
8+
import com.marklogic.appdeployer.util.LogUtil;
89
import com.marklogic.appdeployer.util.MapPropertiesSource;
910
import com.marklogic.client.DatabaseClient;
1011
import com.marklogic.client.DatabaseClientFactory;
@@ -389,13 +390,24 @@ public void setAppServicesSimpleSslConfig(String protocol) {
389390
}
390391

391392
/**
392-
* Convenience method for constructing a MarkLogic Java API DatabaseClient based on the the host and rest*
393+
* Convenience method for constructing a MarkLogic Java API DatabaseClient based on the host and rest*
393394
* properties defined on this class.
394395
*
395396
* @return
396397
*/
397398
public DatabaseClient newDatabaseClient() {
398-
return configuredDatabaseClientFactory.newDatabaseClient(newRestDatabaseClientConfig(getRestPort()));
399+
DatabaseClientConfig config = newRestDatabaseClientConfig(getRestPort());
400+
DatabaseClient client = configuredDatabaseClientFactory.newDatabaseClient(config);
401+
if (StringUtils.hasText(client.getBasePath())) {
402+
LogUtil.APP_DEPLOYER_LOGGER.info("Connecting to REST API server with base path: {}", client.getBasePath());
403+
} else {
404+
boolean isCloudDeployment = client.getSecurityContext() instanceof DatabaseClientFactory.ProgressDataCloudAuthContext;
405+
if (isCloudDeployment) {
406+
LogUtil.APP_DEPLOYER_LOGGER.warn("Connecting to a REST API server in Progress Data Cloud without a base path may not work; " +
407+
"if you encounter an error, you likely need to configure a base path via the 'mlRestBasePath' property.");
408+
}
409+
}
410+
return client;
399411
}
400412

401413
/**

ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/CommandMapBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import com.marklogic.appdeployer.command.mimetypes.DeployMimetypesCommand;
2626
import com.marklogic.appdeployer.command.modules.DeleteTestModulesCommand;
2727
import com.marklogic.appdeployer.command.modules.LoadModulesCommand;
28-
import com.marklogic.appdeployer.command.pdc.DeployPdcEndpointsCommand;
28+
import com.marklogic.appdeployer.command.pdc.DeployMarkLogicEndpointsCommand;
2929
import com.marklogic.appdeployer.command.plugins.InstallPluginsCommand;
3030
import com.marklogic.appdeployer.command.rebalancer.DeployPartitionQueriesCommand;
3131
import com.marklogic.appdeployer.command.rebalancer.DeployPartitionsCommand;
@@ -142,7 +142,7 @@ private void addCommandsThatDoNotWriteToDatabases(Map<String, List<Command>> map
142142
map.put("mlRestApiCommands", restApiCommands);
143143

144144
List<Command> pdcCommands = new ArrayList<>();
145-
pdcCommands.add(new DeployPdcEndpointsCommand());
145+
pdcCommands.add(new DeployMarkLogicEndpointsCommand());
146146
map.put("mlPdcCommands", pdcCommands);
147147

148148
List<Command> securityCommands = new ArrayList<>();
Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,11 @@
2323
import java.util.UUID;
2424
import java.util.stream.Stream;
2525

26-
/**
27-
* Deploys Progress Data Cloud (PDC) integration endpoints by reading JSON configuration files
28-
* from the src/main/pdc-config/service/endpoints directory.
29-
*/
30-
public class DeployPdcEndpointsCommand extends AbstractCommand {
26+
public class DeployMarkLogicEndpointsCommand extends AbstractCommand {
3127

3228
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
3329

34-
public DeployPdcEndpointsCommand() {
30+
public DeployMarkLogicEndpointsCommand() {
3531
setExecuteSortOrder(SortOrderConstants.DEPLOY_PDC_MARKLOGIC_ENDPOINTS);
3632
}
3733

@@ -45,10 +41,10 @@ public void execute(CommandContext context) {
4541
final List<MarkLogicHttpEndpoint> endpoints = readEndpointDefinitionsFromFiles(pdcConfigPaths);
4642
if (!endpoints.isEmpty()) {
4743
if (!StringUtils.hasText(context.getAppConfig().getCloudApiKey())) {
48-
logger.warn("Found configuration for {} PDC endpoint(s), but not deploying them because no cloud API key has been specified.", endpoints.size());
44+
logger.warn("Found configuration for {} MarkLogic endpoint(s), but not deploying them because no cloud API key has been specified.", endpoints.size());
4945
} else {
5046
if (logger.isInfoEnabled()) {
51-
logger.info("Deploying {} PDC endpoint(s)", endpoints.size());
47+
logger.info("Deploying {} MarkLogic endpoint(s)", endpoints.size());
5248
}
5349
deployEndpoints(context, endpoints);
5450
}
@@ -60,24 +56,24 @@ private List<MarkLogicHttpEndpoint> readEndpointDefinitionsFromFiles(List<String
6056

6157
for (String pdcConfigPath : pdcConfigPaths) {
6258
File serviceDir = new File(pdcConfigPath, "service");
63-
File endpointsDir = new File(serviceDir, "endpoints");
59+
File endpointsDir = new File(serviceDir, "mlendpoints");
6460
if (!endpointsDir.exists()) {
6561
if (logger.isDebugEnabled()) {
66-
logger.debug("PDC endpoints directory does not exist: {}", endpointsDir.getAbsolutePath());
62+
logger.debug("MarkLogic endpoints directory does not exist: {}", endpointsDir.getAbsolutePath());
6763
}
6864
continue;
6965
}
7066

7167
if (logger.isInfoEnabled()) {
72-
logger.info("Reading PDC integration endpoints from: {}", endpointsDir.getAbsolutePath());
68+
logger.info("Reading MarkLogic endpoints from: {}", endpointsDir.getAbsolutePath());
7369
}
7470

7571
try (Stream<Path> paths = Files.walk(endpointsDir.toPath())) {
7672
paths.filter(Files::isRegularFile)
7773
.filter(path -> path.toString().endsWith(".json"))
7874
.forEach(path -> endpoints.add(buildEndpointFromFile(path.toFile())));
7975
} catch (IOException e) {
80-
throw new RuntimeException("Failed to read PDC endpoint configuration files from: " +
76+
throw new RuntimeException("Failed to read MarkLogic endpoint configuration files from: " +
8177
endpointsDir.getAbsolutePath(), e);
8278
}
8379
}
@@ -88,14 +84,14 @@ private List<MarkLogicHttpEndpoint> readEndpointDefinitionsFromFiles(List<String
8884
private MarkLogicHttpEndpoint buildEndpointFromFile(File endpointFile) {
8985
try {
9086
MarkLogicHttpEndpoint endpoint = OBJECT_MAPPER.readValue(endpointFile, MarkLogicHttpEndpoint.class);
91-
if (logger.isInfoEnabled()) {
92-
logger.info("Built PDC endpoint: name={}, displayName={}, port={}, type={}, path={}",
87+
if (logger.isDebugEnabled()) {
88+
logger.debug("Built MarkLogic endpoint: name={}, displayName={}, port={}, type={}, path={}",
9389
endpoint.getName(), endpoint.getDisplayName(), endpoint.getPort(),
9490
endpoint.getType(), endpoint.getPath());
9591
}
9692
return endpoint;
9793
} catch (IOException e) {
98-
throw new RuntimeException("Failed to parse PDC endpoint configuration file: " +
94+
throw new RuntimeException("Failed to parse MarkLogic endpoint configuration file: " +
9995
endpointFile.getAbsolutePath(), e);
10096
}
10197
}
@@ -107,7 +103,7 @@ private void deployEndpoints(CommandContext context, List<MarkLogicHttpEndpoint>
107103
try {
108104
new ServiceApi(pdcClient.getApiClient()).apiServiceMlendpointsIdHttpPut(markLogicServiceId, endpoints);
109105
} catch (ApiException e) {
110-
throw new RuntimeException("Unable to create MarkLogic HTTP endpoints in PDC; cause: %s".formatted(e.getMessage()), e);
106+
throw new RuntimeException("Unable to create MarkLogic endpoints in PDC; cause: %s".formatted(e.getMessage()), e);
111107
}
112108
}
113109
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
3+
*/
4+
package com.marklogic.appdeployer.util;
5+
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
9+
public interface LogUtil {
10+
11+
Logger APP_DEPLOYER_LOGGER = LoggerFactory.getLogger("com.marklogic.appdeployer");
12+
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import java.util.Properties;
1616

1717
// For manual testing of deploying integration endpoints to PDC.
18-
public class DeployPdcEndpointsDebug {
18+
public class DeployMarkLogicEndpointsDebug {
1919

2020
public static void main(String[] args) {
2121
Properties props = new Properties();
@@ -29,13 +29,12 @@ public static void main(String[] args) {
2929
new SimplePropertySource(props)
3030
).newManageConfig();
3131
final ManageClient manageClient = new ManageClient(manageConfig);
32-
33-
32+
3433
DefaultAppConfigFactory factory = new DefaultAppConfigFactory(new SimplePropertySource(props));
3534
factory.setProjectDir(new File("ml-app-deployer/src/test/resources/cloud-project"));
3635
AppConfig appConfig = factory.newAppConfig();
3736

3837
CommandContext context = new CommandContext(appConfig, manageClient, null);
39-
new DeployPdcEndpointsCommand().execute(context);
38+
new DeployMarkLogicEndpointsCommand().execute(context);
4039
}
4140
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
* We don't yet have a PDC instance for automated tests, so this test does what it can in the absence of that.
1313
* For now, relying on manual testing via the DeployPdcEndpointsDebug class.
1414
*/
15-
class DeployPdcEndpointsTest extends AbstractAppDeployerTest {
15+
class DeployMarkLogicEndpointsTest extends AbstractAppDeployerTest {
1616

1717
@Test
1818
void dontDeployWhenCloudApiKeyIsNotSet() {
1919
initializeAppConfig(new File("src/test/resources/cloud-project"));
20-
initializeAppDeployer(new DeployPdcEndpointsCommand());
20+
initializeAppDeployer(new DeployMarkLogicEndpointsCommand());
2121

2222
deploySampleApp();
2323
}

0 commit comments

Comments
 (0)