You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apex.apache.org by vr...@apache.org on 2017/03/23 14:03:30 UTC

apex-core git commit: APEXCORE-676 Show description for DefaultProperties in get-app-package-info command only when user requests it by providing -withDescription flag

Repository: apex-core
Updated Branches:
  refs/heads/master 3c063a441 -> df8bc7e00


APEXCORE-676 Show description for DefaultProperties in get-app-package-info command  only when user requests it by providing -withDescription flag


Project: http://git-wip-us.apache.org/repos/asf/apex-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/apex-core/commit/df8bc7e0
Tree: http://git-wip-us.apache.org/repos/asf/apex-core/tree/df8bc7e0
Diff: http://git-wip-us.apache.org/repos/asf/apex-core/diff/df8bc7e0

Branch: refs/heads/master
Commit: df8bc7e001041808a52a194375c3fcd1ae45f3b8
Parents: 3c063a4
Author: ajaygit158 <aj...@gmail.com>
Authored: Thu Mar 23 03:25:55 2017 +0530
Committer: ajaygit158 <aj...@gmail.com>
Committed: Thu Mar 23 12:10:32 2017 +0530

----------------------------------------------------------------------
 .../java/com/datatorrent/stram/cli/ApexCli.java | 33 ++++++++++++++++++--
 .../datatorrent/stram/client/AppPackage.java    | 29 +++++++++++++++++
 .../stram/client/AppPackageTest.java            | 18 +++++++++++
 3 files changed, 77 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/apex-core/blob/df8bc7e0/engine/src/main/java/com/datatorrent/stram/cli/ApexCli.java
----------------------------------------------------------------------
diff --git a/engine/src/main/java/com/datatorrent/stram/cli/ApexCli.java b/engine/src/main/java/com/datatorrent/stram/cli/ApexCli.java
index e95a391..dfaae97 100644
--- a/engine/src/main/java/com/datatorrent/stram/cli/ApexCli.java
+++ b/engine/src/main/java/com/datatorrent/stram/cli/ApexCli.java
@@ -672,10 +672,11 @@ public class ApexCli
         null,
         new Arg[]{new FileArg("parameter-name")},
         "Get the configuration parameter"));
-    globalCommands.put("get-app-package-info", new CommandSpec(new GetAppPackageInfoCommand(),
+    globalCommands.put("get-app-package-info", new OptionsCommandSpec(new GetAppPackageInfoCommand(),
         new Arg[]{new FileArg("app-package-file")},
-        null,
-        "Get info on the app package file"));
+        new Arg[]{new Arg("-withDescription")},
+        "Get info on the app package file",
+        GET_APP_PACKAGE_INFO_OPTIONS));
     globalCommands.put("get-app-package-operators", new OptionsCommandSpec(new GetAppPackageOperatorsCommand(),
         new Arg[]{new FileArg("app-package-file")},
         new Arg[]{new Arg("search-term")},
@@ -2996,6 +2997,13 @@ public class ApexCli
     return tmpDir;
   }
 
+  private static Options GET_APP_PACKAGE_INFO_OPTIONS = new Options();
+
+  static {
+    GET_APP_PACKAGE_INFO_OPTIONS
+        .addOption(new Option("withDescription", false, "Get default properties with description"));
+  }
+
   public static class GetOperatorClassesCommandLineOptions
   {
     final Options options = new Options();
@@ -3011,6 +3019,20 @@ public class ApexCli
 
   private static GetOperatorClassesCommandLineOptions GET_OPERATOR_CLASSES_OPTIONS = new GetOperatorClassesCommandLineOptions();
 
+  static class GetAppPackageInfoCommandLineInfo
+  {
+    boolean provideDescription;
+  }
+
+  static GetAppPackageInfoCommandLineInfo getGetAppPackageInfoCommandLineInfo(String[] args) throws ParseException
+  {
+    CommandLineParser parser = new PosixParser();
+    GetAppPackageInfoCommandLineInfo result = new GetAppPackageInfoCommandLineInfo();
+    CommandLine line = parser.parse(GET_APP_PACKAGE_INFO_OPTIONS, args);
+    result.provideDescription = line.hasOption("withDescription");
+    return result;
+  }
+
   static class GetOperatorClassesCommandLineInfo
   {
     String parent;
@@ -3474,8 +3496,13 @@ public class ApexCli
     @Override
     public void execute(String[] args, ConsoleReader reader) throws Exception
     {
+      String[] tmpArgs = new String[args.length - 2];
+      System.arraycopy(args, 2, tmpArgs, 0, args.length - 2);
+      GetAppPackageInfoCommandLineInfo commandLineInfo = getGetAppPackageInfoCommandLineInfo(tmpArgs);
       try (AppPackage ap = newAppPackageInstance(new File(expandFileName(args[1], true)))) {
         JSONSerializationProvider jomp = new JSONSerializationProvider();
+        jomp.addSerializer(PropertyInfo.class,
+            new AppPackage.PropertyInfoSerializer(commandLineInfo.provideDescription));
         JSONObject apInfo = new JSONObject(jomp.getContext(null).writeValueAsString(ap));
         apInfo.remove("name");
         printJson(apInfo);

http://git-wip-us.apache.org/repos/asf/apex-core/blob/df8bc7e0/engine/src/main/java/com/datatorrent/stram/client/AppPackage.java
----------------------------------------------------------------------
diff --git a/engine/src/main/java/com/datatorrent/stram/client/AppPackage.java b/engine/src/main/java/com/datatorrent/stram/client/AppPackage.java
index fcb1612..fd95649 100644
--- a/engine/src/main/java/com/datatorrent/stram/client/AppPackage.java
+++ b/engine/src/main/java/com/datatorrent/stram/client/AppPackage.java
@@ -34,6 +34,10 @@ import java.util.jar.Attributes;
 import java.util.jar.JarFile;
 import java.util.jar.Manifest;
 
+import org.codehaus.jackson.JsonGenerator;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.map.JsonSerializer;
+import org.codehaus.jackson.map.SerializerProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -131,6 +135,31 @@ public class AppPackage extends JarFile
     }
   }
 
+  public static class PropertyInfoSerializer extends JsonSerializer<PropertyInfo>
+  {
+    private boolean provideDescription;
+
+    public PropertyInfoSerializer(boolean provideDescription)
+    {
+      this.provideDescription = provideDescription;
+    }
+
+    @Override
+    public void serialize(
+        PropertyInfo propertyInfo, JsonGenerator jgen, SerializerProvider provider)
+      throws IOException, JsonProcessingException
+    {
+      if (provideDescription) {
+        jgen.writeStartObject();
+        jgen.writeStringField("value", propertyInfo.value);
+        jgen.writeStringField("description", propertyInfo.description);
+        jgen.writeEndObject();
+      } else {
+        jgen.writeString(propertyInfo.value);
+      }
+    }
+  }
+
   public AppPackage(File file) throws IOException, ZipException
   {
     this(file, false);

http://git-wip-us.apache.org/repos/asf/apex-core/blob/df8bc7e0/engine/src/test/java/com/datatorrent/stram/client/AppPackageTest.java
----------------------------------------------------------------------
diff --git a/engine/src/test/java/com/datatorrent/stram/client/AppPackageTest.java b/engine/src/test/java/com/datatorrent/stram/client/AppPackageTest.java
index 9f3276d..aae3913 100644
--- a/engine/src/test/java/com/datatorrent/stram/client/AppPackageTest.java
+++ b/engine/src/test/java/com/datatorrent/stram/client/AppPackageTest.java
@@ -25,6 +25,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.codehaus.jackson.JsonGenerationException;
+import org.codehaus.jackson.map.JsonMappingException;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
 import org.junit.AfterClass;
@@ -34,6 +36,7 @@ import org.junit.Test;
 
 import org.apache.commons.io.IOUtils;
 
+import com.datatorrent.stram.client.AppPackage.PropertyInfo;
 import com.datatorrent.stram.support.StramTestSupport;
 import com.datatorrent.stram.util.JSONSerializationProvider;
 
@@ -140,4 +143,19 @@ public class AppPackageTest
     }
     Assert.fail("Should consist of an app called MyFirstApplication");
   }
+
+  @Test
+  public void testPropertyInfoSerializer() throws JsonGenerationException, JsonMappingException, IOException
+  {
+    AppPackage.PropertyInfo propertyInfo = new AppPackage.PropertyInfo("test-value", "test-description");
+    JSONSerializationProvider jomp = new JSONSerializationProvider();
+    jomp.addSerializer(PropertyInfo.class, new AppPackage.PropertyInfoSerializer(false));
+    String result = jomp.getContext(null).writeValueAsString(propertyInfo);
+    Assert.assertEquals("\"test-value\"", result);
+
+    jomp = new JSONSerializationProvider();
+    jomp.addSerializer(PropertyInfo.class, new AppPackage.PropertyInfoSerializer(true));
+    result = jomp.getContext(null).writeValueAsString(propertyInfo);
+    Assert.assertEquals("{\"value\":\"test-value\",\"description\":\"test-description\"}", result);
+  }
 }