falcon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pall...@apache.org
Subject falcon git commit: FALCON-1477 Adding -debug option to Falcon CLI for debug statements to stdout(Narayan Periwal)
Date Thu, 08 Oct 2015 05:05:42 GMT
Repository: falcon
Updated Branches:
  refs/heads/master 1cd7f0b45 -> 4bc38989d


FALCON-1477 Adding -debug option to Falcon CLI for debug statements to stdout(Narayan Periwal)


Project: http://git-wip-us.apache.org/repos/asf/falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/falcon/commit/4bc38989
Tree: http://git-wip-us.apache.org/repos/asf/falcon/tree/4bc38989
Diff: http://git-wip-us.apache.org/repos/asf/falcon/diff/4bc38989

Branch: refs/heads/master
Commit: 4bc38989d34321f7498a2244f05b1d7c51399ad7
Parents: 1cd7f0b
Author: Pallavi Rao <pallavi.rao@inmobi.com>
Authored: Thu Oct 8 10:30:02 2015 +0530
Committer: Pallavi Rao <pallavi.rao@inmobi.com>
Committed: Thu Oct 8 10:30:02 2015 +0530

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 +
 .../org/apache/falcon/cli/FalconAdminCLI.java   |  2 +
 .../java/org/apache/falcon/cli/FalconCLI.java   | 15 +++++
 .../org/apache/falcon/cli/FalconEntityCLI.java  |  2 +
 .../apache/falcon/cli/FalconInstanceCLI.java    |  2 +
 .../apache/falcon/cli/FalconMetadataCLI.java    |  2 +
 .../org/apache/falcon/client/FalconClient.java  | 63 +++++++++++++++++++-
 docs/src/site/twiki/FalconCLI.twiki             |  7 +++
 8 files changed, 93 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/falcon/blob/4bc38989/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index bc37b3a..b7fd6a1 100755
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -15,6 +15,8 @@ Trunk (Unreleased)
     FALCON-1027 Falcon proxy user support(Sowmya Ramesh)
 
   IMPROVEMENTS
+    FALCON-1477 Adding "-debug" option to Falcon CLI for debug statements to stdout(Narayan
Periwal)
+
     FALCON-1476 Maintaining threshold on monitoring entities for SLA service(Ajay Yadava)
 
     FALCON-592 Refactor FalconCLI to make it more manageable(Balu Vellanki via Ajay Yadava)

http://git-wip-us.apache.org/repos/asf/falcon/blob/4bc38989/client/src/main/java/org/apache/falcon/cli/FalconAdminCLI.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/falcon/cli/FalconAdminCLI.java b/client/src/main/java/org/apache/falcon/cli/FalconAdminCLI.java
index 32c0e8c..6360743 100644
--- a/client/src/main/java/org/apache/falcon/cli/FalconAdminCLI.java
+++ b/client/src/main/java/org/apache/falcon/cli/FalconAdminCLI.java
@@ -55,6 +55,7 @@ public class FalconAdminCLI extends FalconCLI {
         Option doAs = new Option(DO_AS_OPT, true,
                 "doAs user");
         Option help = new Option("help", false, "show Falcon help");
+        Option debug = new Option(DEBUG_OPTION, false, "Use debug mode to see debugging statements
on stdout");
         group.addOption(status);
         group.addOption(version);
         group.addOption(stack);
@@ -62,6 +63,7 @@ public class FalconAdminCLI extends FalconCLI {
 
         adminOptions.addOptionGroup(group);
         adminOptions.addOption(doAs);
+        adminOptions.addOption(debug);
         return adminOptions;
     }
 

http://git-wip-us.apache.org/repos/asf/falcon/blob/4bc38989/client/src/main/java/org/apache/falcon/cli/FalconCLI.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/falcon/cli/FalconCLI.java b/client/src/main/java/org/apache/falcon/cli/FalconCLI.java
index 67420ec..24f230a 100644
--- a/client/src/main/java/org/apache/falcon/cli/FalconCLI.java
+++ b/client/src/main/java/org/apache/falcon/cli/FalconCLI.java
@@ -46,6 +46,8 @@ public class FalconCLI {
     public static final AtomicReference<PrintStream> ERR = new AtomicReference<PrintStream>(System.err);
     public static final AtomicReference<PrintStream> OUT = new AtomicReference<PrintStream>(System.out);
 
+    public static final String ENV_FALCON_DEBUG = "FALCON_DEBUG";
+    public static final String DEBUG_OPTION = "debug";
     public static final String URL_OPTION = "url";
     private static final String FALCON_URL = "FALCON_URL";
 
@@ -155,6 +157,7 @@ public class FalconCLI {
                 String falconUrl = getFalconEndpoint(commandLine);
                 FalconClient client = new FalconClient(falconUrl, clientProperties);
 
+                setDebugMode(client, commandLine.hasOption(DEBUG_OPTION));
                 if (command.getName().equals(ADMIN_CMD)) {
                     exitValue = adminCLI.adminCommand(commandLine, client, falconUrl);
                 } else if (command.getName().equals(ENTITY_CMD)) {
@@ -298,6 +301,18 @@ public class FalconCLI {
         return url;
     }
 
+    private void setDebugMode(FalconClient client, boolean debugOpt) {
+        String debug = System.getenv(ENV_FALCON_DEBUG);
+        if (debugOpt) {  // CLI argument "-debug" used
+            client.setDebugMode(true);
+        } else if (StringUtils.isNotBlank(debug)) {
+            System.out.println(ENV_FALCON_DEBUG + ": " + debug);
+            if (debug.trim().toLowerCase().equals("true")) {
+                client.setDebugMode(true);
+            }
+        }
+    }
+
     private Properties getClientProperties() throws IOException {
         InputStream inputStream = null;
         try {

http://git-wip-us.apache.org/repos/asf/falcon/blob/4bc38989/client/src/main/java/org/apache/falcon/cli/FalconEntityCLI.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/falcon/cli/FalconEntityCLI.java b/client/src/main/java/org/apache/falcon/cli/FalconEntityCLI.java
index 98f3176..cb39a2f 100644
--- a/client/src/main/java/org/apache/falcon/cli/FalconEntityCLI.java
+++ b/client/src/main/java/org/apache/falcon/cli/FalconEntityCLI.java
@@ -148,6 +148,7 @@ public class FalconEntityCLI extends FalconCLI {
         Option skipDryRun = new Option(SKIPDRYRUN_OPT, false, "skip dry run in workflow engine");
         Option doAs = new Option(DO_AS_OPT, true, "doAs user");
         Option userProps = new Option(PROPS_OPT, true, "User supplied comma separated key
value properties");
+        Option debug = new Option(DEBUG_OPTION, false, "Use debug mode to see debugging statements
on stdout");
 
         entityOptions.addOption(url);
         entityOptions.addOption(path);
@@ -172,6 +173,7 @@ public class FalconEntityCLI extends FalconCLI {
         entityOptions.addOption(skipDryRun);
         entityOptions.addOption(doAs);
         entityOptions.addOption(userProps);
+        entityOptions.addOption(debug);
 
         return entityOptions;
     }

http://git-wip-us.apache.org/repos/asf/falcon/blob/4bc38989/client/src/main/java/org/apache/falcon/cli/FalconInstanceCLI.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/falcon/cli/FalconInstanceCLI.java b/client/src/main/java/org/apache/falcon/cli/FalconInstanceCLI.java
index 24be7f1..6ea34da 100644
--- a/client/src/main/java/org/apache/falcon/cli/FalconInstanceCLI.java
+++ b/client/src/main/java/org/apache/falcon/cli/FalconInstanceCLI.java
@@ -147,6 +147,7 @@ public class FalconInstanceCLI extends FalconCLI {
         Option forceRerun = new Option(FORCE_RERUN_FLAG, false,
                 "Flag to forcefully rerun entire workflow of an instance");
         Option doAs = new Option(DO_AS_OPT, true, "doAs user");
+        Option debug = new Option(DEBUG_OPTION, false, "Use debug mode to see debugging statements
on stdout");
 
         Option instanceTime = new Option(INSTANCE_TIME_OPT, true, "Time for an instance");
 
@@ -169,6 +170,7 @@ public class FalconInstanceCLI extends FalconCLI {
         instanceOptions.addOption(numResults);
         instanceOptions.addOption(forceRerun);
         instanceOptions.addOption(doAs);
+        instanceOptions.addOption(debug);
         instanceOptions.addOption(instanceTime);
 
         return instanceOptions;

http://git-wip-us.apache.org/repos/asf/falcon/blob/4bc38989/client/src/main/java/org/apache/falcon/cli/FalconMetadataCLI.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/falcon/cli/FalconMetadataCLI.java b/client/src/main/java/org/apache/falcon/cli/FalconMetadataCLI.java
index aaf59ff..36dd613 100644
--- a/client/src/main/java/org/apache/falcon/cli/FalconMetadataCLI.java
+++ b/client/src/main/java/org/apache/falcon/cli/FalconMetadataCLI.java
@@ -102,6 +102,7 @@ public class FalconMetadataCLI extends FalconCLI {
         Option key = new Option(KEY_OPT, true, "key property");
         Option value = new Option(VALUE_OPT, true, "value property");
         Option direction = new Option(DIRECTION_OPT, true, "edge direction property");
+        Option debug = new Option(DEBUG_OPTION, false, "Use debug mode to see debugging statements
on stdout");
 
         metadataOptions.addOption(vertex);
         metadataOptions.addOption(vertices);
@@ -111,6 +112,7 @@ public class FalconMetadataCLI extends FalconCLI {
         metadataOptions.addOption(key);
         metadataOptions.addOption(value);
         metadataOptions.addOption(direction);
+        metadataOptions.addOption(debug);
 
         Option doAs = new Option(FalconCLI.DO_AS_OPT, true, "doAs user");
         metadataOptions.addOption(doAs);

http://git-wip-us.apache.org/repos/asf/falcon/blob/4bc38989/client/src/main/java/org/apache/falcon/client/FalconClient.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/falcon/client/FalconClient.java b/client/src/main/java/org/apache/falcon/client/FalconClient.java
index 20f6447..6c3a7a4 100644
--- a/client/src/main/java/org/apache/falcon/client/FalconClient.java
+++ b/client/src/main/java/org/apache/falcon/client/FalconClient.java
@@ -65,12 +65,14 @@ import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.PrintStream;
 import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Method;
 import java.net.URL;
 import java.security.SecureRandom;
 import java.util.List;
 import java.util.Properties;
+import java.util.concurrent.atomic.AtomicReference;
 
 /**
  * Client API to submit and manage Falcon Entities (Cluster, Feed, Process) jobs
@@ -78,6 +80,8 @@ import java.util.Properties;
  */
 public class FalconClient extends AbstractFalconClient {
 
+    public static final AtomicReference<PrintStream> OUT = new AtomicReference<PrintStream>(System.out);
+
     public static final String WS_HEADER_PREFIX = "header:";
     public static final String USER = System.getProperty("user.name");
     public static final String AUTH_URL = "api/options?" + PseudoAuthenticator.USER_NAME
+ "=" + USER;
@@ -106,6 +110,11 @@ public class FalconClient extends AbstractFalconClient {
     private final WebResource service;
     private final AuthenticatedURL.Token authenticationToken;
 
+    /**
+     * debugMode=false means no debugging. debugMode=true means debugging on.
+     */
+    private boolean debugMode = false;
+
     private final Properties clientProperties;
 
     /**
@@ -158,6 +167,22 @@ public class FalconClient extends AbstractFalconClient {
         return sslContext;
     }
 
+    /**
+     * @return current debug Mode
+     */
+    public boolean getDebugMode() {
+        return debugMode;
+    }
+
+    /**
+     * Set debug mode.
+     *
+     * @param debugMode : debugMode=false means no debugging. debugMode=true means debugging
on
+     */
+    public void setDebugMode(boolean debugMode) {
+        this.debugMode = debugMode;
+    }
+
     public Properties getClientProperties() {
         return clientProperties;
     }
@@ -351,6 +376,7 @@ public class FalconClient extends AbstractFalconClient {
                 .header("Cookie", AUTH_COOKIE_EQ + authenticationToken)
                 .accept(operation.mimeType).type(MediaType.TEXT_XML)
                 .method(operation.method, ClientResponse.class, entityStream);
+        printClientResponse(clientResponse);
         checkIfSuccessful(clientResponse);
         return parseAPIResult(clientResponse);
     }
@@ -404,13 +430,15 @@ public class FalconClient extends AbstractFalconClient {
 
     public TriageResult triage(String entityType, String entityName, String instanceTime,
String colo)
         throws FalconCLIException {
-        ClientResponse clientResponse = service
+        WebResource resource = service
                 .path(Instances.TRIAGE.path).path(entityType).path(entityName)
-                .queryParam("start", instanceTime).queryParam("colo", colo)
+                .queryParam("start", instanceTime).queryParam("colo", colo);
+        ClientResponse clientResponse = resource
                 .header("Cookie", AUTH_COOKIE_EQ + authenticationToken)
                 .accept(Instances.TRIAGE.mimeType).type(MediaType.TEXT_XML)
                 .method(Instances.TRIAGE.method, ClientResponse.class);
 
+        printClientResponse(clientResponse);
         checkIfSuccessful(clientResponse);
         return clientResponse.getEntity(TriageResult.class);
     }
@@ -448,6 +476,7 @@ public class FalconClient extends AbstractFalconClient {
                 .header("Cookie", AUTH_COOKIE_EQ + authenticationToken)
                 .accept(operation.mimeType).type(MediaType.TEXT_XML)
                 .method(operation.method, ClientResponse.class);
+        printClientResponse(clientResponse);
         checkIfSuccessful(clientResponse);
         return parseAPIResult(clientResponse);
     }
@@ -589,6 +618,7 @@ public class FalconClient extends AbstractFalconClient {
                 .header("Cookie", AUTH_COOKIE_EQ + authenticationToken)
                 .accept(job.mimeType).type(MediaType.TEXT_PLAIN)
                 .method(job.method, ClientResponse.class);
+        printClientResponse(clientResponse);
         return clientResponse.getStatus();
     }
 
@@ -610,6 +640,7 @@ public class FalconClient extends AbstractFalconClient {
             .header("Cookie", AUTH_COOKIE_EQ + authenticationToken)
             .accept(operation.mimeType).type(operation.mimeType)
             .method(operation.method, ClientResponse.class);
+        printClientResponse(clientResponse);
         checkIfSuccessful(clientResponse);
         return clientResponse.getEntity(LineageGraphResult.class);
     }
@@ -685,6 +716,8 @@ public class FalconClient extends AbstractFalconClient {
                 .accept(entities.mimeType).type(MediaType.TEXT_XML)
                 .method(entities.method, ClientResponse.class);
 
+        printClientResponse(clientResponse);
+
         checkIfSuccessful(clientResponse);
 
         // should be removed return parseAPIResult(clientResponse);
@@ -770,6 +803,8 @@ public class FalconClient extends AbstractFalconClient {
                 .accept(entities.mimeType).type(MediaType.TEXT_XML)
                 .method(entities.method, ClientResponse.class);
 
+        printClientResponse(clientResponse);
+
         checkIfSuccessful(clientResponse);
         return clientResponse.getEntity(EntitySummaryResult.class);
     }
@@ -788,6 +823,8 @@ public class FalconClient extends AbstractFalconClient {
                 .accept(entities.mimeType).type(MediaType.TEXT_XML)
                 .method(entities.method, ClientResponse.class);
 
+        printClientResponse(clientResponse);
+
         checkIfSuccessful(clientResponse);
         String entity = clientResponse.getEntity(String.class);
 
@@ -807,6 +844,8 @@ public class FalconClient extends AbstractFalconClient {
                 .accept(entities.mimeType).type(MediaType.TEXT_XML)
                 .method(entities.method, ClientResponse.class);
 
+        printClientResponse(clientResponse);
+
         checkIfSuccessful(clientResponse);
 
         return parseEntityList(clientResponse);
@@ -832,11 +871,14 @@ public class FalconClient extends AbstractFalconClient {
         if (StringUtils.isNotEmpty(properties)) {
             resource = resource.queryParam("properties", properties);
         }
+
         ClientResponse clientResponse = resource
                 .header("Cookie", AUTH_COOKIE_EQ + authenticationToken)
                 .accept(entities.mimeType).type(MediaType.TEXT_XML)
                 .method(entities.method, ClientResponse.class, requestObject);
 
+        printClientResponse(clientResponse);
+
         checkIfSuccessful(clientResponse);
 
         //remove this return parseAPIResult(clientResponse);
@@ -853,6 +895,7 @@ public class FalconClient extends AbstractFalconClient {
         ClientResponse response = resource.header("Cookie", AUTH_COOKIE_EQ + authenticationToken)
                 .accept(api.mimeType)
                 .method(api.method, ClientResponse.class);
+        printClientResponse(response);
         checkIfSuccessful(response);
         return response.getEntity(FeedLookupResult.class);
     }
@@ -917,6 +960,7 @@ public class FalconClient extends AbstractFalconClient {
                     .accept(instances.mimeType)
                     .method(instances.method, ClientResponse.class, props);
         }
+        printClientResponse(clientResponse);
         checkIfSuccessful(clientResponse);
         return clientResponse;
     }
@@ -933,6 +977,7 @@ public class FalconClient extends AbstractFalconClient {
                     .header("Cookie", AUTH_COOKIE_EQ + authenticationToken)
                     .accept(api.mimeType)
                     .method(api.method, ClientResponse.class);
+        printClientResponse(clientResponse);
         checkIfSuccessful(clientResponse);
         return clientResponse.getEntity(InstanceDependencyResult.class);
     }
@@ -977,6 +1022,8 @@ public class FalconClient extends AbstractFalconClient {
                 .accept(entities.mimeType).type(MediaType.TEXT_XML)
                 .method(entities.method, ClientResponse.class);
 
+        printClientResponse(clientResponse);
+
         checkIfSuccessful(clientResponse);
 
         return parseEntityList(clientResponse);
@@ -995,6 +1042,7 @@ public class FalconClient extends AbstractFalconClient {
                 .accept(job.mimeType)
                 .type(job.mimeType)
                 .method(job.method, ClientResponse.class);
+        printClientResponse(clientResponse);
         return clientResponse.getEntity(String.class);
     }
 
@@ -1035,6 +1083,8 @@ public class FalconClient extends AbstractFalconClient {
                 .accept(operation.mimeType).type(operation.mimeType)
                 .method(operation.method, ClientResponse.class);
 
+        printClientResponse(clientResponse);
+
         checkIfSuccessful(clientResponse);
         return clientResponse.getEntity(String.class);
     }
@@ -1141,6 +1191,7 @@ public class FalconClient extends AbstractFalconClient {
                 .accept(job.mimeType)
                 .type(job.mimeType)
                 .method(job.method, ClientResponse.class);
+        printClientResponse(clientResponse);
         return clientResponse.getEntity(String.class);
     }
 
@@ -1157,6 +1208,7 @@ public class FalconClient extends AbstractFalconClient {
                 .accept(job.mimeType)
                 .type(job.mimeType)
                 .method(job.method, ClientResponse.class);
+        printClientResponse(clientResponse);
         return clientResponse.getEntity(String.class);
     }
 
@@ -1174,6 +1226,7 @@ public class FalconClient extends AbstractFalconClient {
                 .accept(job.mimeType)
                 .type(job.mimeType)
                 .method(job.method, ClientResponse.class);
+        printClientResponse(clientResponse);
         return clientResponse.getEntity(String.class);
     }
 
@@ -1184,4 +1237,10 @@ public class FalconClient extends AbstractFalconClient {
             throw FalconCLIException.fromReponse(clientResponse);
         }
     }
+
+    private void printClientResponse(ClientResponse clientResponse) {
+        if (getDebugMode()) {
+            OUT.get().println(clientResponse.toString());
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/falcon/blob/4bc38989/docs/src/site/twiki/FalconCLI.twiki
----------------------------------------------------------------------
diff --git a/docs/src/site/twiki/FalconCLI.twiki b/docs/src/site/twiki/FalconCLI.twiki
index 22003d3..d994866 100644
--- a/docs/src/site/twiki/FalconCLI.twiki
+++ b/docs/src/site/twiki/FalconCLI.twiki
@@ -16,6 +16,13 @@ which hosts a user may impersonate users, as well as users of which groups
can b
 
 <a href="./FalconDocumentation.html#Proxyuser_support">Proxyuser support described
here.</a>
 
+---+++Debug Mode
+
+If you export FALCON_DEBUG=true then the Falcon CLI will output the Web Services API details
used by any commands you execute. This is useful for debugging purposes to or see how the
Falcon CLI works with the WS API.
+Alternately, you can specify '-debug' through the CLI arguments to get the debug statements.
+Example:
+$FALCON_HOME/bin/falcon entity -submit -type cluster -file /cluster/definition.xml -debug
+
 ---++Entity Management Operations
 
 ---+++Submit


Mime
View raw message