From 60710d4fc35c25cdf42cfd70ecb7f2cc59aa2bd3 Mon Sep 17 00:00:00 2001 From: David Yan Date: Fri, 2 Oct 2015 01:44:04 -0700 Subject: [PATCH] APEX-177 added description for app and in the app info within app package --- .../api/annotation/ApplicationAnnotation.java | 8 +++-- .../datatorrent/stram/client/AppPackage.java | 3 ++ .../stram/client/StramAppLauncher.java | 29 ++++++++++++++++++- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/com/datatorrent/api/annotation/ApplicationAnnotation.java b/api/src/main/java/com/datatorrent/api/annotation/ApplicationAnnotation.java index b568ade2f7..aa336315e0 100644 --- a/api/src/main/java/com/datatorrent/api/annotation/ApplicationAnnotation.java +++ b/api/src/main/java/com/datatorrent/api/annotation/ApplicationAnnotation.java @@ -43,6 +43,10 @@ *
  • Runtime application alias -- specified in application code
  • * */ - public String name(); - + String name(); + + /** + * Description of the application. Optional. + */ + String description() default ""; } 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 cbe63f2934..cdf03c8260 100644 --- a/engine/src/main/java/com/datatorrent/stram/client/AppPackage.java +++ b/engine/src/main/java/com/datatorrent/stram/client/AppPackage.java @@ -74,6 +74,7 @@ public static class AppInfo public final String file; public final String type; public String displayName; + public String description; public LogicalPlan dag; public String error; public String errorStackTrace; @@ -322,6 +323,7 @@ private void processAppDirectory(File dir) } AppInfo appInfo = new AppInfo(appName, entry.getName(), "class"); appInfo.displayName = appFactory.getDisplayName(); + appInfo.description = appFactory.getDescription(); try { appInfo.dag = appFactory.createApp(stramAppLauncher.getLogicalPlanConfiguration()); appInfo.dag.validate(); @@ -353,6 +355,7 @@ private void processAppDirectory(File dir) stramAppLauncher.loadDependencies(); AppInfo appInfo = new AppInfo(appFactory.getName(), entry.getName(), "json"); appInfo.displayName = appFactory.getDisplayName(); + appInfo.description = appFactory.getDescription(); try { appInfo.dag = appFactory.createApp(stramAppLauncher.getLogicalPlanConfiguration()); appInfo.dag.validate(); diff --git a/engine/src/main/java/com/datatorrent/stram/client/StramAppLauncher.java b/engine/src/main/java/com/datatorrent/stram/client/StramAppLauncher.java index f1e7261051..90087cf787 100644 --- a/engine/src/main/java/com/datatorrent/stram/client/StramAppLauncher.java +++ b/engine/src/main/java/com/datatorrent/stram/client/StramAppLauncher.java @@ -92,22 +92,30 @@ public static interface AppFactory String getName(); String getDisplayName(); + + String getDescription(); } public static class PropertyFileAppFactory implements AppFactory { final File propertyFile; + final Properties properties; public PropertyFileAppFactory(File file) { this.propertyFile = file; + try { + this.properties = LogicalPlanConfiguration.readProperties(propertyFile.getAbsolutePath()); + } catch (IOException e) { + throw new IllegalArgumentException("Failed to load: " + this + "\n" + e.getMessage(), e); + } } @Override public LogicalPlan createApp(LogicalPlanConfiguration conf) { try { - return conf.createFromProperties(LogicalPlanConfiguration.readProperties(propertyFile.getAbsolutePath()), getName()); + return conf.createFromProperties(properties, getName()); } catch (IOException e) { throw new IllegalArgumentException("Failed to load: " + this + "\n" + e.getMessage(), e); @@ -132,6 +140,12 @@ public String getDisplayName() return getName(); } + @Override + public String getDescription() + { + return properties.getProperty("description", ""); + } + } public static class JsonFileAppFactory implements AppFactory @@ -186,6 +200,12 @@ public String getDisplayName() String displayName = json.optString("displayName", null); return displayName == null ? getName() : displayName; } + + @Override + public String getDescription() + { + return json.optString("description", ""); + } } public StramAppLauncher(File appJarFile, Configuration conf) throws Exception @@ -397,6 +417,13 @@ public String getDisplayName() } } + @Override + public String getDescription() + { + ApplicationAnnotation an = clazz.getAnnotation(ApplicationAnnotation.class); + return (an != null) ? an.description() : ""; + } + @Override public LogicalPlan createApp(LogicalPlanConfiguration conf) {