brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rich...@apache.org
Subject [04/14] git commit: Creates first-pass at outputting entities, policies, locations and locationResolvers
Date Mon, 08 Sep 2014 12:39:04 GMT
Creates first-pass at outputting entities, policies, locations and locationResolvers


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/37ec238f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/37ec238f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/37ec238f

Branch: refs/heads/master
Commit: 37ec238f9e67d25fdca9e20e1176e97efa76d17c
Parents: af85653
Author: Martin Harris <github@nakomis.com>
Authored: Fri Aug 22 11:54:33 2014 +0100
Committer: Martin Harris <github@nakomis.com>
Committed: Mon Sep 8 11:20:33 2014 +0100

----------------------------------------------------------------------
 .../brooklyn/cli/itemlister/ItemLister.java     | 88 ++++++++++++++++----
 .../main/resources/brooklyn-object-list.html    | 70 ++++++++++++++++
 usage/cli/src/main/resources/enricher.html      | 34 ++++++++
 usage/cli/src/main/resources/entity.html        | 59 +++++++++++++
 usage/cli/src/main/resources/location.html      | 34 ++++++++
 usage/cli/src/main/resources/policy.html        | 34 ++++++++
 6 files changed, 304 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/37ec238f/usage/cli/src/main/java/brooklyn/cli/itemlister/ItemLister.java
----------------------------------------------------------------------
diff --git a/usage/cli/src/main/java/brooklyn/cli/itemlister/ItemLister.java b/usage/cli/src/main/java/brooklyn/cli/itemlister/ItemLister.java
index bc3782d..4375c38 100644
--- a/usage/cli/src/main/java/brooklyn/cli/itemlister/ItemLister.java
+++ b/usage/cli/src/main/java/brooklyn/cli/itemlister/ItemLister.java
@@ -1,16 +1,5 @@
 package brooklyn.cli.itemlister;
 
-import io.airlift.command.Cli;
-import io.airlift.command.Cli.CliBuilder;
-import io.airlift.command.Command;
-import io.airlift.command.Option;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.List;
-import java.util.Map;
-import java.util.ServiceLoader;
-
 import brooklyn.basic.BrooklynObject;
 import brooklyn.catalog.Catalog;
 import brooklyn.cli.AbstractMain;
@@ -20,8 +9,10 @@ import brooklyn.location.Location;
 import brooklyn.location.LocationResolver;
 import brooklyn.policy.Enricher;
 import brooklyn.policy.Policy;
+import brooklyn.util.ResourceUtils;
 import brooklyn.util.collections.MutableSet;
-
+import brooklyn.util.os.Os;
+import brooklyn.util.text.TemplateProcessor;
 import com.fasterxml.jackson.annotation.JsonAutoDetect;
 import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.annotation.PropertyAccessor;
@@ -29,10 +20,23 @@ import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.SerializationFeature;
+import com.google.common.base.Charsets;
 import com.google.common.collect.FluentIterable;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Lists;
+import com.google.common.io.Files;
+import io.airlift.command.Cli;
+import io.airlift.command.Cli.CliBuilder;
+import io.airlift.command.Command;
+import io.airlift.command.Option;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+import java.util.ServiceLoader;
 
 public class ItemLister extends AbstractMain {
 
@@ -50,13 +54,16 @@ public class ItemLister extends AbstractMain {
         public String typeRegex = null;
 
         @Option(name = { "--catalog-only" }, title = "Whether to only list items annotated
with @Catalog")
-        public boolean catalogOnly;
+        public boolean catalogOnly = true;
 
         @Option(name = { "--ignore-impls" }, title = "Ignore Entity implementations, where
there is an Entity interface with @ImplementedBy")
         public boolean ignoreImpls;
 
         @Option(name = { "--headings-only" }, title = "Whether to only show name/type, and
not config keys etc")
         public boolean headingsOnly;
+        
+        @Option(name = { "--output-folder" }, title = "Whether to only show name/type, and
not config keys etc")
+        public String outputFolder;
 
         @Override
         public Void call() throws Exception {
@@ -75,11 +82,62 @@ public class ItemLister extends AbstractMain {
                     .put("locations", ItemDescriptors.toItemDescriptors(locationTypes, headingsOnly))
                     .put("locationResolvers", ItemDescriptors.toItemDescriptors(ImmutableList.copyOf(ServiceLoader.load(LocationResolver.class))))
                     .build();
-            
-            System.out.println(toJson(result));
+
+            String json = toJson(result);
+
+            if (outputFolder == null) {
+                System.out.println(json);
+            } else {
+                String outputPath = Os.mergePaths(outputFolder, "index.html");
+                String parentDir = (new File(outputPath).getParentFile()).getAbsolutePath();
+                mkdir(parentDir, "entities");
+                mkdir(parentDir, "policies");
+                mkdir(parentDir, "enrichers");
+                mkdir(parentDir, "locations");
+                mkdir(parentDir, "locationResolvers");
+                Files.write("var items = " + json, new File(Os.mergePaths(outputFolder, "items.js")),
Charsets.UTF_8);
+                ResourceUtils resourceUtils = ResourceUtils.create(this);
+                String mainHtml = resourceUtils.getResourceAsString("brooklyn-object-list.html");
+                Files.write(mainHtml, new File(Os.mergePaths(outputFolder, "index.html")),
Charsets.UTF_8);
+                List<Map<String, Object>> entities = (List<Map<String,
Object>>) result.get("entities");
+                String entityTemplateHtml = resourceUtils.getResourceAsString("entity.html");
+                for (Map<String, Object> entity : entities) {
+                    String type = (String) entity.get("type");
+                    String name = (String) entity.get("name");
+                    String entityHtml = TemplateProcessor.processTemplateContents(entityTemplateHtml,
ImmutableMap.of("type", type, "name", name));
+                    Files.write(entityHtml, new File(Os.mergePaths(outputFolder, "entities",
type + ".html")), Charsets.UTF_8);
+                }
+                List<Map<String, Object>> policies = (List<Map<String,
Object>>) result.get("policies");
+                String policyTemplateHtml = resourceUtils.getResourceAsString("policy.html");
+                for (Map<String, Object> policy : policies) {
+                    String type = (String) policy.get("type");
+                    String name = (String) policy.get("name");
+                    String policyHtml = TemplateProcessor.processTemplateContents(policyTemplateHtml,
ImmutableMap.of("type", type, "name", name));
+                    Files.write(policyHtml, new File(Os.mergePaths(outputFolder, "policies",
type + ".html")), Charsets.UTF_8);
+                }
+                List<Map<String, Object>> enrichers = (List<Map<String,
Object>>) result.get("enrichers");
+                String enricherTemplateHtml = resourceUtils.getResourceAsString("enricher.html");
+                for (Map<String, Object> enricher : enrichers) {
+                    String type = (String) enricher.get("type");
+                    String name = (String) enricher.get("name");
+                    String enricherHtml = TemplateProcessor.processTemplateContents(enricherTemplateHtml,
ImmutableMap.of("type", type, "name", name));
+                    Files.write(enricherHtml, new File(Os.mergePaths(outputFolder, "enrichers",
type + ".html")), Charsets.UTF_8);
+                }
+                List<Map<String, Object>> locations = (List<Map<String,
Object>>) result.get("locations");
+                String locationTemplateHtml = resourceUtils.getResourceAsString("location.html");
+                for (Map<String, Object> location : locations) {
+                    String type = (String) location.get("type");
+                    String locationHtml = TemplateProcessor.processTemplateContents(locationTemplateHtml,
ImmutableMap.of("type", type));
+                    Files.write(locationHtml, new File(Os.mergePaths(outputFolder, "locations",
type + ".html")), Charsets.UTF_8);
+                }
+            }
             return null;
         }
 
+        private void mkdir(String rootDir, String dirName) {
+            (new File(Os.mergePaths(rootDir, dirName))).mkdirs();
+        }
+
         protected List<URL> getUrls() throws MalformedURLException {
             List<URL> urls = Lists.newArrayList();
             for (String jar : jars) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/37ec238f/usage/cli/src/main/resources/brooklyn-object-list.html
----------------------------------------------------------------------
diff --git a/usage/cli/src/main/resources/brooklyn-object-list.html b/usage/cli/src/main/resources/brooklyn-object-list.html
new file mode 100644
index 0000000..338da2b
--- /dev/null
+++ b/usage/cli/src/main/resources/brooklyn-object-list.html
@@ -0,0 +1,70 @@
+<html lang="en">
+    <head>
+        <meta charset="utf-8">
+        <title>Brooklyn Object List</title>
+    </head>
+    <body>
+        <h1>Entities</h1>
+        <table id="entities">
+            <tr>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+            </tr>
+        </table>
+        <br>
+        <h1>Policies</h1>
+        <table id="policies">
+            <tr>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+            </tr>
+        </table>
+        <h1>Enrichers</h1>
+        <table id="enrichers">
+            <tr>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+            </tr>
+        </table>
+        <br>
+        <h1>Locations</h1>
+        <table id="locations">
+            <tr>
+                <th>Type</th>
+            </tr>
+        </table>
+        <br>
+        <h1>Location Resolvers</h1>
+        <table id="locationResolvers">
+            <tr>
+                <th>Name</th>
+            </tr>
+        </table>
+        <br>
+        <br>
+        <script src="http://code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script>
+        <script src="items.js" type="text/javascript"></script>
+        <script type="text/javascript">
+            $(document).ready(function() {
+                items.entities.forEach(function(element) {
+                    $("#entities").find("tr:last").after("<tr><td>" + element.name
+ "</td><td><a href='entities/" + element.type + ".html'>" + element.type
+ "</a></td><td>" + element.description + "</td></tr>")
+                });
+                items.policies.forEach(function(element) {
+                    $("#policies").find("tr:last").after("<tr><td>" + element.name
+ "</td><td><a href='policies/" + element.type + ".html'>" + element.type
+ "</a></td><td>" + element.description + "</td></tr>")
+                });
+                items.enrichers.forEach(function(element) {
+                    $("#enrichers").find("tr:last").after("<tr><td>" + element.name
+ "</td><td><a href='enrichers/" + element.type + ".html'>" + element.type
+ "</a></td><td>" + element.description + "</td></tr>")
+                });
+                items.locations.forEach(function(element) {
+                    $("#locations").find("tr:last").after("<tr><td><a href='locations/"
+ element.type + ".html'>" + element.type + "</a></td></tr>")
+                });
+                items.locationResolvers.forEach(function(element) {
+                    $("#locationResolvers").find("tr:last").after("<tr><td>"
+ element + "</td></tr>")
+                });
+            });
+        </script>
+    </body>
+</html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/37ec238f/usage/cli/src/main/resources/enricher.html
----------------------------------------------------------------------
diff --git a/usage/cli/src/main/resources/enricher.html b/usage/cli/src/main/resources/enricher.html
new file mode 100644
index 0000000..783af00
--- /dev/null
+++ b/usage/cli/src/main/resources/enricher.html
@@ -0,0 +1,34 @@
+<html lang="en">
+<head>
+    <meta charset="utf-8">
+    <title>Brooklyn Enricher - ${name}</title>
+</head>
+<body>
+<h1>${name}</h1>
+Type: <span id="type"></span>
+<h2>Config Keys</h2>
+<table id="configKeys">
+    <tr>
+        <th>Name</th>
+        <th>Type</th>
+        <th>Default Value</th>
+        <th>Description</th>
+    </tr>
+</table>
+<br>
+
+<script src="http://code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script>
+<script src="../items.js" type="text/javascript"></script>
+<script type="text/javascript">
+    $(document).ready(function() {
+        var item = $.grep((items.enrichers), function(entity) {
+            return entity.type == "${type}";
+        })[0];
+        $("#type").html(item.type);
+        item.config.forEach(function(element) {
+            $("#configKeys").find("tr:last").after("<tr><td>" + element.name
+ "</td><td>" + element.type + "</td><td>" + element.defaultValue
+ "</td><td>" + element.description + "</td></tr>")
+        });
+    });
+</script>
+</body>
+</html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/37ec238f/usage/cli/src/main/resources/entity.html
----------------------------------------------------------------------
diff --git a/usage/cli/src/main/resources/entity.html b/usage/cli/src/main/resources/entity.html
new file mode 100644
index 0000000..2255e78
--- /dev/null
+++ b/usage/cli/src/main/resources/entity.html
@@ -0,0 +1,59 @@
+<html lang="en">
+<head>
+    <meta charset="utf-8">
+    <title>Brooklyn - ${name}</title>
+</head>
+<body>
+<h1>${name}</h1>
+Type: <span id="type"></span>
+<h2>Config Keys</h2>
+<table id="configKeys">
+    <tr>
+        <th>Name</th>
+        <th>Type</th>
+        <th>Default Value</th>
+        <th>Description</th>
+    </tr>
+</table>
+<br>
+<h2>Sensors</h2>
+<table id="sensors">
+    <tr>
+        <th>Name</th>
+        <th>Type</th>
+        <th>Description</th>
+    </tr>
+</table>
+<br>
+<h2>Effectors</h2>
+<table id="effectors">
+    <tr>
+        <th>Name</th>
+        <th>Type</th>
+        <th>Description</th>
+    </tr>
+</table>
+<br>
+<script src="http://code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script>
+<script src="../items.js" type="text/javascript"></script>
+<script type="text/javascript">
+    $(document).ready(function() {
+        var item = $.grep((items.entities), function(entity) {
+            return entity.type == "${type}";
+        })[0];
+        $("#type").html(item.type);
+        item.config.forEach(function(element) {
+            $("#configKeys").find("tr:last").after("<tr><td>" + element.name
+ "</td><td>" + element.type + "</td><td>" + element.defaultValue
+ "</td><td>" + element.description + "</td></tr>")
+        });
+        item.sensors.forEach(function(element) {
+            $("#sensors").find("tr:last").after("<tr><td>" + element.name + "</td><td>"
+ element.type + "</td><td>" + element.description + "</td></tr>")
+        });
+        if (item.effectors != undefined) {
+            item.effectors.forEach(function (element) {
+                $("#effectors").find("tr:last").after("<tr><td>" + element.name
+ "</td><td>" + element.type + "</td><td>" + element.description +
"</td></tr>")
+            });
+        }
+    });
+</script>
+</body>
+</html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/37ec238f/usage/cli/src/main/resources/location.html
----------------------------------------------------------------------
diff --git a/usage/cli/src/main/resources/location.html b/usage/cli/src/main/resources/location.html
new file mode 100644
index 0000000..6c9aad5
--- /dev/null
+++ b/usage/cli/src/main/resources/location.html
@@ -0,0 +1,34 @@
+<html lang="en">
+<head>
+    <meta charset="utf-8">
+    <title>Brooklyn Location - ${type}</title>
+</head>
+<body>
+<h1>${type}</h1>
+Type: <span id="type"></span>
+<h2>Config Keys</h2>
+<table id="configKeys">
+    <tr>
+        <th>Name</th>
+        <th>Type</th>
+        <th>Default Value</th>
+        <th>Description</th>
+    </tr>
+</table>
+<br>
+
+<script src="http://code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script>
+<script src="../items.js" type="text/javascript"></script>
+<script type="text/javascript">
+    $(document).ready(function() {
+        var item = $.grep((items.locations), function(entity) {
+            return entity.type == "${type}";
+        })[0];
+        $("#type").html(item.type);
+        item.config.forEach(function(element) {
+            $("#configKeys").find("tr:last").after("<tr><td>" + element.name
+ "</td><td>" + element.type + "</td><td>" + element.defaultValue
+ "</td><td>" + element.description + "</td></tr>")
+        });
+    });
+</script>
+</body>
+</html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/37ec238f/usage/cli/src/main/resources/policy.html
----------------------------------------------------------------------
diff --git a/usage/cli/src/main/resources/policy.html b/usage/cli/src/main/resources/policy.html
new file mode 100644
index 0000000..c2f3ea8
--- /dev/null
+++ b/usage/cli/src/main/resources/policy.html
@@ -0,0 +1,34 @@
+<html lang="en">
+<head>
+    <meta charset="utf-8">
+    <title>Brooklyn Policy - ${name}</title>
+</head>
+<body>
+<h1>${name}</h1>
+Type: <span id="type"></span>
+<h2>Config Keys</h2>
+<table id="configKeys">
+    <tr>
+        <th>Name</th>
+        <th>Type</th>
+        <th>Default Value</th>
+        <th>Description</th>
+    </tr>
+</table>
+<br>
+
+<script src="http://code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script>
+<script src="../items.js" type="text/javascript"></script>
+<script type="text/javascript">
+    $(document).ready(function() {
+        var item = $.grep((items.policies), function(entity) {
+            return entity.type == "${type}";
+        })[0];
+        $("#type").html(item.type);
+        item.config.forEach(function(element) {
+            $("#configKeys").find("tr:last").after("<tr><td>" + element.name
+ "</td><td>" + element.type + "</td><td>" + element.defaultValue
+ "</td><td>" + element.description + "</td></tr>")
+        });
+    });
+</script>
+</body>
+</html>
\ No newline at end of file


Mime
View raw message