1717
1818import java .io .File ;
1919import java .io .IOException ;
20- import java .util .ArrayList ;
2120import java .util .Collections ;
2221import java .util .Iterator ;
2322import java .util .List ;
23+ import java .util .stream .Collectors ;
2424
2525import javax .net .ssl .HttpsURLConnection ;
2626
@@ -207,6 +207,8 @@ public static class DeploymentStatus {
207207 @ Key
208208 public List <PodStatus > pods ;
209209 @ Key
210+ public List <Error > errors ;
211+ @ Key
210212 public String organization ;
211213 }
212214
@@ -230,6 +232,22 @@ public static class PodStatus {
230232 @ Key
231233 public String statusCodeDetails ;
232234 }
235+
236+ public static class Error {
237+ @ Key
238+ public Integer code ;
239+ @ Key
240+ public String message ;
241+
242+ public String getMessage () {
243+ return message ;
244+ }
245+
246+ public void setMessage (String message ) {
247+ this .message = message ;
248+ }
249+
250+ }
233251
234252 public static class AppConfig {
235253 @ Key
@@ -418,24 +436,24 @@ public static boolean getDeploymentStateForRevision(ServerProfile profile, Strin
418436 restRequest .setHeaders (headers );
419437 HttpResponse response = executeAPI (profile , restRequest );
420438 deploymentStatus = response .parseAs (DeploymentStatus .class );
421- /*if(deploymentStatus!=null && deploymentStatus.pods!=null && deploymentStatus.pods.size()>0) {
422- for (PodStatus p: deploymentStatus.pods) {
423- if(p.deploymentStatus!=null && p.deploymentStatus.equals("deployed")) {
424- deployed = true;
425- }else {
426- deployed = false;
427- break;
428- }
429-
430- }
431- }*/
432- if (deploymentStatus !=null && deploymentStatus .state != null && deploymentStatus .state .equalsIgnoreCase ("READY" )) {
439+ //For https://github.com/apigee/apigee-deploy-maven-plugin/issues/158
440+ if (deploymentStatus !=null && deploymentStatus .state != null && deploymentStatus .state .equalsIgnoreCase ("ERROR" )) {
441+ if (deploymentStatus .errors !=null && deploymentStatus .errors .size ()>0 ) {
442+ String errorString = deploymentStatus .errors .stream ().map (Error ::getMessage )
443+ .collect (Collectors .joining ("\n " ));
444+ throw new IOException ("Deployment error: " +errorString );
445+ }
446+ }
447+ else if (deploymentStatus !=null && deploymentStatus .state != null && deploymentStatus .state .equalsIgnoreCase ("READY" )) {
433448 deployed = true ;
434449 }else {
435450 deployed = false ;
436451 }
437452 }catch (HttpResponseException e ) {
438453 logger .error (e .getMessage ());
454+ } catch (IOException e ) {
455+ logger .error (e .getMessage ());
456+ throw e ;
439457 } catch (Exception e ) {
440458 logger .error (e .getMessage ());
441459 }
0 commit comments