88import com .marklogic .appdeployer .command .CommandContext ;
99import com .marklogic .appdeployer .command .SortOrderConstants ;
1010import com .progress .pdc .client .PdcClient ;
11- import com .progress .pdc .client .generated .ApiClient ;
1211import com .progress .pdc .client .generated .ApiException ;
1312import com .progress .pdc .client .generated .api .ServiceApi ;
14- import com .progress .pdc .client .generated .api .ServiceGroupApi ;
1513import com .progress .pdc .client .generated .model .MarkLogicApp ;
1614import com .progress .pdc .client .generated .model .MarkLogicHttpEndpoint ;
17- import com . progress . pdc . client . generated . model . ServiceGroupViewModel ;
15+ import org . springframework . util . StringUtils ;
1816
1917import java .io .File ;
2018import 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 ) {
0 commit comments