Skip to content

Commit 06287d7

Browse files
committed
MLE-25605 Not deploying PDC endpoints if no cloud API key
1 parent cbd161c commit 06287d7

File tree

3 files changed

+41
-26
lines changed

3 files changed

+41
-26
lines changed

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

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88
import com.marklogic.appdeployer.command.CommandContext;
99
import com.marklogic.appdeployer.command.SortOrderConstants;
1010
import com.progress.pdc.client.PdcClient;
11-
import com.progress.pdc.client.generated.ApiClient;
1211
import com.progress.pdc.client.generated.ApiException;
1312
import com.progress.pdc.client.generated.api.ServiceApi;
14-
import com.progress.pdc.client.generated.api.ServiceGroupApi;
1513
import com.progress.pdc.client.generated.model.MarkLogicApp;
1614
import com.progress.pdc.client.generated.model.MarkLogicHttpEndpoint;
17-
import com.progress.pdc.client.generated.model.ServiceGroupViewModel;
15+
import org.springframework.util.StringUtils;
1816

1917
import java.io.File;
2018
import java.io.IOException;
@@ -41,18 +39,19 @@ public DeployPdcEndpointsCommand() {
4139
public void execute(CommandContext context) {
4240
final List<String> pdcConfigPaths = context.getAppConfig().getPdcConfigPaths();
4341
if (pdcConfigPaths == null || pdcConfigPaths.isEmpty()) {
44-
if (logger.isInfoEnabled()) {
45-
logger.info("No PDC config paths configured");
46-
}
4742
return;
4843
}
4944

5045
final List<MarkLogicHttpEndpoint> endpoints = readEndpointDefinitionsFromFiles(pdcConfigPaths);
5146
if (!endpoints.isEmpty()) {
52-
if (logger.isInfoEnabled()) {
53-
logger.info("Deploying {} PDC endpoint(s)", endpoints.size());
47+
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());
49+
} else {
50+
if (logger.isInfoEnabled()) {
51+
logger.info("Deploying {} PDC endpoint(s)", endpoints.size());
52+
}
53+
deployEndpoints(context, endpoints);
5454
}
55-
deployEndpoints(context, endpoints);
5655
}
5756
}
5857

@@ -104,8 +103,7 @@ private MarkLogicHttpEndpoint buildEndpointFromFile(File endpointFile) {
104103
private void deployEndpoints(CommandContext context, List<MarkLogicHttpEndpoint> endpoints) {
105104
final String host = context.getManageClient().getManageConfig().getHost();
106105
try (PdcClient pdcClient = new PdcClient(host, context.getAppConfig().getCloudApiKey())) {
107-
final UUID environmentId = getEnvironmentId(pdcClient.getApiClient());
108-
final UUID markLogicServiceId = getFirstMarkLogicServiceId(pdcClient.getApiClient(), environmentId, host);
106+
final UUID markLogicServiceId = getFirstMarkLogicServiceId(pdcClient);
109107
try {
110108
new ServiceApi(pdcClient.getApiClient()).apiServiceMlendpointsIdHttpPut(markLogicServiceId, endpoints);
111109
} catch (ApiException e) {
@@ -114,20 +112,12 @@ private void deployEndpoints(CommandContext context, List<MarkLogicHttpEndpoint>
114112
}
115113
}
116114

117-
private UUID getEnvironmentId(ApiClient apiClient) {
118-
try {
119-
ServiceGroupViewModel viewModel = new ServiceGroupApi(apiClient).apiServicegroupGet(null).get(0);
120-
return viewModel.getId();
121-
} catch (ApiException e) {
122-
throw new RuntimeException("Unable to get service groups from PDC; cause: %s".formatted(e.getMessage()), e);
123-
}
124-
}
125-
126-
private UUID getFirstMarkLogicServiceId(ApiClient apiClient, UUID environmentId, String host) {
115+
private UUID getFirstMarkLogicServiceId(PdcClient pdcClient) {
127116
try {
128-
List<MarkLogicApp> apps = new ServiceApi(apiClient).apiServiceAppsGet(environmentId).getMarkLogic();
117+
final UUID environmentId = pdcClient.getEnvironmentId();
118+
List<MarkLogicApp> apps = new ServiceApi(pdcClient.getApiClient()).apiServiceAppsGet(environmentId).getMarkLogic();
129119
if (apps == null || apps.isEmpty()) {
130-
throw new RuntimeException("No instances of MarkLogic found in PDC tenancy; host: %s".formatted(host));
120+
throw new RuntimeException("No instances of MarkLogic found in PDC tenancy; host: %s".formatted(pdcClient.getHost()));
131121
}
132122
return apps.get(0).getId();
133123
} catch (ApiException e) {

ml-app-deployer/src/test/java/com/marklogic/appdeployer/CloudDebug.java renamed to ml-app-deployer/src/test/java/com/marklogic/appdeployer/command/pdc/DeployPdcEndpointsDebug.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/*
22
* Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
33
*/
4-
package com.marklogic.appdeployer;
4+
package com.marklogic.appdeployer.command.pdc;
55

6+
import com.marklogic.appdeployer.AppConfig;
7+
import com.marklogic.appdeployer.DefaultAppConfigFactory;
68
import com.marklogic.appdeployer.command.CommandContext;
7-
import com.marklogic.appdeployer.command.pdc.DeployPdcEndpointsCommand;
89
import com.marklogic.mgmt.DefaultManageConfigFactory;
910
import com.marklogic.mgmt.ManageClient;
1011
import com.marklogic.mgmt.ManageConfig;
@@ -14,7 +15,7 @@
1415
import java.util.Properties;
1516

1617
// For manual testing of deploying integration endpoints to PDC.
17-
public class CloudDebug {
18+
public class DeployPdcEndpointsDebug {
1819

1920
public static void main(String[] args) {
2021
Properties props = new Properties();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
3+
*/
4+
package com.marklogic.appdeployer.command.pdc;
5+
6+
import com.marklogic.appdeployer.AbstractAppDeployerTest;
7+
import org.junit.jupiter.api.Test;
8+
9+
import java.io.File;
10+
11+
/**
12+
* We don't yet have a PDC instance for automated tests, so this test does what it can in the absence of that.
13+
* For now, relying on manual testing via the DeployPdcEndpointsDebug class.
14+
*/
15+
class DeployPdcEndpointsTest extends AbstractAppDeployerTest {
16+
17+
@Test
18+
void dontDeployWhenCloudApiKeyIsNotSet() {
19+
initializeAppConfig(new File("src/test/resources/cloud-project"));
20+
initializeAppDeployer(new DeployPdcEndpointsCommand());
21+
22+
deploySampleApp();
23+
}
24+
}

0 commit comments

Comments
 (0)