@@ -48,9 +48,9 @@ public PlatformDeployer(int connectTimeout, int readTimeout, int retryCount, Log
48
48
this .log = log ;
49
49
}
50
50
51
- public void buildApp (String application , String earPath , String buildName , String appName , String profile , int replicas , boolean enableAutoScaling , boolean enableServiceMesh , boolean eula , String platformConfigFile , String dpUrl , String authToken , String baseVersion , String baseImageTag , String namespace ) throws ClientException , IOException , InterruptedException {
51
+ public void buildApp (String earPath , String buildName , String appName , String profile , int replicas , boolean enableAutoScaling , boolean enableServiceMesh , boolean eula , String platformConfigFile , String dpUrl , String authToken , String baseVersion , String baseImageTag , String namespace , boolean deploy ) throws ClientException , IOException , InterruptedException {
52
52
try {
53
- this .log .info ("Deployment to Platform started..." );
53
+ this .log .info ("Application build creation in Platform started..." );
54
54
if (dpUrl == null ) {
55
55
throw new ClientException ("Unable to build the application. Please provide the data plane URL." );
56
56
}
@@ -143,13 +143,15 @@ public void buildApp(String application, String earPath, String buildName, Strin
143
143
.post (Entity .entity (multipart , MediaType .MULTIPART_FORM_DATA ));
144
144
StatusType statusInfo = response .getStatusInfo ();
145
145
if (statusInfo .getFamily ().equals (Family .SUCCESSFUL )) {
146
- String readEntity = response .readEntity (String .class );
147
- ObjectMapper mapper = new ObjectMapper ();
148
- mapper .configure (DeserializationFeature .ACCEPT_SINGLE_VALUE_AS_ARRAY , true );
149
- Map <?, ?> responseMap ;
150
- responseMap = mapper .readValue (readEntity , Map .class );
151
- String buildId = (String ) responseMap .get ("buildId" );
152
- deployApp (buildId , namespace , authToken , eula , replicas , appName , profile , platformConfigFile , enableAutoScaling , enableServiceMesh );
146
+ if (deploy ) {
147
+ String readEntity = response .readEntity (String .class );
148
+ ObjectMapper mapper = new ObjectMapper ();
149
+ mapper .configure (DeserializationFeature .ACCEPT_SINGLE_VALUE_AS_ARRAY , true );
150
+ Map <?, ?> responseMap ;
151
+ responseMap = mapper .readValue (readEntity , Map .class );
152
+ String buildId = (String ) responseMap .get ("buildId" );
153
+ deployApp (null , buildId , namespace , authToken , eula , replicas , appName , profile , platformConfigFile , enableAutoScaling , enableServiceMesh , true );
154
+ }
153
155
}else {
154
156
processErrorResponse (response , statusInfo );
155
157
}
@@ -162,7 +164,7 @@ public void buildApp(String application, String earPath, String buildName, Strin
162
164
}
163
165
}
164
166
165
- public void deployApp (String buildId , String namespace , String authToken , boolean eula , int replicas , String appName , String profile , String platformConfigFile , boolean enableAutoScaling , boolean enableServiceMesh ) throws ClientException , IOException , InterruptedException {
167
+ public void deployApp (String appId , String buildId , String namespace , String authToken , boolean eula , int replicas , String appName , String profile , String platformConfigFile , boolean enableAutoScaling , boolean enableServiceMesh , boolean scale ) throws ClientException , IOException , InterruptedException {
166
168
if (buildId == null || buildId .isEmpty ()) {
167
169
throw new ClientException ("Unable to deploy the application. Please provide a valid build ID." );
168
170
}
@@ -222,6 +224,9 @@ public void deployApp(String buildId, String namespace, String authToken, boolea
222
224
tagsArray = (JSONArray ) tags .get ("tags" );
223
225
}
224
226
}
227
+ if (appId != null && !appId .isEmpty ()) {
228
+ appJsonObject .put ("appId" , appId );
229
+ }
225
230
appJsonObject .put ("buildId" , buildId );
226
231
appJsonObject .put ("enableAutoScaling" , enableAutoScaling );
227
232
appJsonObject .put ("enableServiceMesh" , enableServiceMesh );
@@ -259,18 +264,35 @@ public void deployApp(String buildId, String namespace, String authToken, boolea
259
264
.post (Entity .entity (appJsonObject .toString (), MediaType .APPLICATION_JSON ));
260
265
StatusType statusInfo = response .getStatusInfo ();
261
266
if (statusInfo .getFamily ().equals (Family .SUCCESSFUL )) {
262
- String readEntity = response .readEntity (String .class );
263
- ObjectMapper mapper = new ObjectMapper ();
264
- mapper .configure (DeserializationFeature .ACCEPT_SINGLE_VALUE_AS_ARRAY , true );
265
- Map <?, ?> responseMap ;
266
- responseMap = mapper .readValue (readEntity , Map .class );
267
- String appId = (String ) responseMap .get ("appId" );
268
- scaleApp (appId , replicas , authToken );
267
+ if (scale ) {
268
+ String readEntity = response .readEntity (String .class );
269
+ ObjectMapper mapper = new ObjectMapper ();
270
+ mapper .configure (DeserializationFeature .ACCEPT_SINGLE_VALUE_AS_ARRAY , true );
271
+ Map <?, ?> responseMap ;
272
+ responseMap = mapper .readValue (readEntity , Map .class );
273
+ scaleApp ((String ) responseMap .get ("appId" ), replicas , authToken );
274
+ }
269
275
}else {
270
276
processErrorResponse (response , statusInfo );
271
277
}
272
278
}
273
279
280
+ public void deployApp (String dpUrl , String buildId , String namespace , String authToken , boolean eula , String appName , String profile , String platformConfigFile , boolean enableAutoScaling , boolean enableServiceMesh ) throws ClientException , IOException , InterruptedException {
281
+ try {
282
+ this .log .info ("Build deployment in Platform started..." );
283
+ Client client = ClientBuilder .newClient ();
284
+ webTarget = client .target (new URI (dpUrl ));
285
+ webTarget .register (MultiPartFeature .class );
286
+ deployApp (null , buildId , namespace , authToken , eula , 0 , appName , profile , platformConfigFile , enableAutoScaling , enableServiceMesh , false );
287
+ }catch (ProcessingException pe ) {
288
+ pe .printStackTrace ();
289
+ throw getConnectionException (pe );
290
+ }catch (Exception ex ) {
291
+ ex .printStackTrace ();
292
+ throw new ClientException (500 , ex .getMessage (), ex );
293
+ }
294
+ }
295
+
274
296
public void scaleApp (String appId , int replicas , String authToken ) throws ClientException , IOException , InterruptedException {
275
297
if (appId == null || appId .isEmpty ()) {
276
298
throw new ClientException ("Unable to scale the application. Please provide app ID." );
@@ -292,6 +314,38 @@ public void scaleApp(String appId, int replicas, String authToken) throws Client
292
314
}
293
315
}
294
316
317
+ public void scaleApp (String dpUrl , String appId , int replicas , String authToken ) throws ClientException , IOException , InterruptedException {
318
+ try {
319
+ this .log .info ("Applicatoin scaling in Platform started..." );
320
+ Client client = ClientBuilder .newClient ();
321
+ webTarget = client .target (new URI (dpUrl ));
322
+ webTarget .register (MultiPartFeature .class );
323
+ scaleApp (appId , replicas , authToken );
324
+ }catch (ProcessingException pe ) {
325
+ pe .printStackTrace ();
326
+ throw getConnectionException (pe );
327
+ }catch (Exception ex ) {
328
+ ex .printStackTrace ();
329
+ throw new ClientException (500 , ex .getMessage (), ex );
330
+ }
331
+ }
332
+
333
+ public void upgradeApp (String dpUrl , String appId , String buildId , String namespace , String authToken , boolean eula , String appName , String profile , String platformConfigFile , boolean enableAutoScaling , boolean enableServiceMesh ) throws ClientException , IOException , InterruptedException {
334
+ try {
335
+ this .log .info ("Application upgrade in Platform started..." );
336
+ Client client = ClientBuilder .newClient ();
337
+ webTarget = client .target (new URI (dpUrl ));
338
+ webTarget .register (MultiPartFeature .class );
339
+ deployApp (appId , buildId , namespace , authToken , eula , 0 , appName , profile , platformConfigFile , enableAutoScaling , enableServiceMesh , false );
340
+ }catch (ProcessingException pe ) {
341
+ pe .printStackTrace ();
342
+ throw getConnectionException (pe );
343
+ }catch (Exception ex ) {
344
+ ex .printStackTrace ();
345
+ throw new ClientException (500 , ex .getMessage (), ex );
346
+ }
347
+ }
348
+
295
349
private void processErrorResponse (Response response , StatusType statusInfo ) throws ClientException {
296
350
if (statusInfo .getStatusCode () == 401 ) {
297
351
throw new ClientException (response .getStatus (), statusInfo .getStatusCode () + ": " + statusInfo .getReasonPhrase (), null );
0 commit comments