incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgog...@apache.org
Subject svn commit: r1185439 - in /incubator/ambari/trunk: client/src/main/java/org/apache/ambari/client/BlueprintList.java controller/src/main/java/org/apache/ambari/controller/Blueprints.java
Date Tue, 18 Oct 2011 00:28:19 GMT
Author: vgogate
Date: Tue Oct 18 00:28:19 2011
New Revision: 1185439

URL: http://svn.apache.org/viewvc?rev=1185439&view=rev
Log:
AMBARI-79

Modified:
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/BlueprintList.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Blueprints.java

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/BlueprintList.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/BlueprintList.java?rev=1185439&r1=1185438&r2=1185439&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/BlueprintList.java
(original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/BlueprintList.java
Tue Oct 18 00:28:19 2011
@@ -133,40 +133,103 @@ public class BlueprintList extends Comma
         boolean tree = line.hasOption("tree");
         
         /*
-         * Import blueprint 
+         * Get blueprint 
+         * TODO: Ignore does not exist case?
          */
         if (name != null) {
             ClientResponse response = service.path("blueprints/"+name)
                     .accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).get(ClientResponse.class);
+            if (response.getStatus() != 404 && response.getStatus() != 200) { 
+                System.err.println("Blueprint list command failed. Reason [Code: <"+response.getStatus()+">,
Message: <"+response.getHeaders().getFirst("ErrorMessage")+">]");
+                System.exit(-1);
+            }
+            if (response.getStatus() == 404) {
+                System.exit(0);
+            }
             /* 
              * Retrieve the blueprint from the response
              */
             Blueprint blueprint = response.getEntity(Blueprint.class);
-            printBlueprintInformation (blueprint, tree);
+            printBlueprintInformation (service, blueprint, tree);
            
         } else {
             ClientResponse response = service.path("blueprints")
                     .accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).get(ClientResponse.class);
+            if (response.getStatus() != 200 || response.getStatus() != 204) { 
+                System.err.println("Blueprint list command failed. Reason [Code: <"+response.getStatus()+">,
Message: <"+response.getHeaders().getFirst("ErrorMessage")+">]");
+                System.exit(-1);
+            }
+            if (response.getStatus() == 204) {
+                System.exit(0);
+            }
+            
             /* 
              * Retrieve the blueprint Information list from the response
              */
             List<BlueprintInformation> bpInfos = response.getEntity(new GenericType<List<BlueprintInformation>>(){});
             for (BlueprintInformation bpInfo : bpInfos) {
-                printBlueprintInformation (bpInfo, tree);
+                printBlueprintInformation (service, bpInfo, tree);
             }
         }
         
     }
     
-    public void printBlueprintInformation (BlueprintInformation bpInfo, boolean tree) {
+    /*
+     * TODO: Return Blueprint objects instead of BlueprintInformation???
+     */
+    public void printBlueprintInformation (WebResource service, BlueprintInformation bpInfo,
boolean tree) {
+        
+        System.out.println("Name:["+bpInfo.getName()+"], Revision:["+bpInfo.getRevision()+"]");
         
+        if (tree) {
+            String tab = "";
+            while (bpInfo.getParentName() != null) {
+                tab = tab+"\t";
+                System.out.println(tab+"Name:["+bpInfo.getParentName()+"], Revision:["+bpInfo.getParentRevision()+"]");
+                ClientResponse response = service.path("blueprints/"+bpInfo.getParentName())
+                        .accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).get(ClientResponse.class);
+                if (response.getStatus() != 404 && response.getStatus() != 200) {

+                    System.err.println("Blueprint list command failed. Reason [Code: <"+response.getStatus()+">,
Message: <"+response.getHeaders().getFirst("ErrorMessage")+">]");
+                    System.exit(-1);
+                }
+                if (response.getStatus() == 404) {
+                    System.exit(0);
+                }
+                /* 
+                 * Retrieve the blueprint from the response
+                 * TODO: 
+                 */
+                Blueprint bp = response.getEntity(Blueprint.class);
+                bpInfo.setName(bp.getName());
+                bpInfo.setParentName(bp.getParentName());
+                bpInfo.setRevision(bp.getRevision());
+                bpInfo.setParentRevision(bp.getParentRevision());
+            }
+        } 
     }
     
-    public void printBlueprintInformation (Blueprint bp, boolean tree) {
+    public void printBlueprintInformation (WebResource service, Blueprint bp, boolean tree)
{
         System.out.println("Name:["+bp.getName()+"], Revision:["+bp.getRevision()+"]");
-        System.out.println("     ParentName:["+bp.getParentName()+"], ParentRevision:["+bp.getParentRevision()+"]");
+        
         if (tree) {
-            
+            String tab = "";
+            while (bp.getParentName() != null) {
+                tab = tab+"\t";
+                System.out.println(tab+"Name:["+bp.getParentName()+"], Revision:["+bp.getParentRevision()+"]");
+                ClientResponse response = service.path("blueprints/"+bp.getParentName())
+                        .accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).get(ClientResponse.class);
+                if (response.getStatus() != 404 && response.getStatus() != 200) {

+                    System.err.println("Blueprint list command failed. Reason [Code: <"+response.getStatus()+">,
Message: <"+response.getHeaders().getFirst("ErrorMessage")+">]");
+                    System.exit(-1);
+                }
+                if (response.getStatus() == 404) {
+                    System.exit(0);
+                }
+                /* 
+                 * Retrieve the blueprint from the response
+                 */
+                bp = response.getEntity(Blueprint.class);
+            }
         }
     }
 }
\ No newline at end of file

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Blueprints.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Blueprints.java?rev=1185439&r1=1185438&r2=1185439&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Blueprints.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Blueprints.java
Tue Oct 18 00:28:19 2011
@@ -255,7 +255,7 @@ public class Blueprints {
         Blueprint bp = null;
         if (!this.blueprints.containsKey(blueprintName)) {  
             String msg = "Blueprint ["+blueprintName+"] is not defined";
-            throw new WebApplicationException ((new ExceptionResponse(msg, Response.Status.BAD_REQUEST)).get());
+            throw new WebApplicationException ((new ExceptionResponse(msg, Response.Status.NOT_FOUND)).get());
         }
         if (revision == -1) {
             this.blueprints.get(blueprintName).keySet();
@@ -266,7 +266,7 @@ public class Blueprints {
         } else {
             if (!this.blueprints.get(blueprintName).containsKey(revision)) {  
                 String msg = "Blueprint ["+blueprintName+"], revision ["+revision+"] does
not exists";
-                throw new WebApplicationException ((new ExceptionResponse(msg, Response.Status.BAD_REQUEST)).get());
+                throw new WebApplicationException ((new ExceptionResponse(msg, Response.Status.NOT_FOUND)).get());
             }
             bp = this.blueprints.get(blueprintName).get(revision);
         }



Mime
View raw message