You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@fluo.apache.org by gi...@git.apache.org on 2017/06/13 18:01:30 UTC

[GitHub] mikewalch commented on a change in pull request #58: Adding 1.1.0 documentation to the website

mikewalch commented on a change in pull request #58: Adding 1.1.0 documentation to the website
URL: https://github.com/apache/incubator-fluo-website/pull/58#discussion_r121752468
 
 

 ##########
 File path: docs/fluo/1.1.0-incubating/applications.md
 ##########
 @@ -0,0 +1,209 @@
+---
+layout: fluo-doc
+title:  Fluo Applications
+version:  1.1.0-incubating
+---
+Once you have Fluo installed and running on your cluster, you can now run Fluo applications which
+consist of clients and observers.
+
+For both clients and observers, you will need to include the following in your Maven pom:
+
+```xml
+<dependency>
+  <groupId>org.apache.fluo</groupId>
+  <artifactId>fluo-api</artifactId>
+  <version>1.x.x-incubating</version>
+</dependency>
+<dependency>
+  <groupId>org.apache.fluo</groupId>
+  <artifactId>fluo-core</artifactId>
+  <version>1.x.x-incubating</version>
+  <scope>runtime</scope>
+</dependency>
+```
+
+Fluo provides a classpath command to help users build a runtime classpath. This command along with
+the `hadoop jar` command is useful when writing scripts to run Fluo client code. These commands
+allow the scripts to use the versions of Hadoop, Accumulo, and Zookeeper installed on a cluster.
+
+## Creating a Fluo client
+
+To create a [FluoClient], you will need to provide it with a [FluoConfiguration] object that is
+configured to connect to your Fluo instance.
+
+If you have access to the [fluo.properties] file that was used to configure your Fluo instance, you
+can use it to build a [FluoConfiguration] object with all necessary properties which are all
+properties with the `fluo.client.*` prefix in [fluo.properties]:
+
+```java
+FluoConfiguration config = new FluoConfiguration(new File("fluo.properties"));
+```
+
+You can also create an empty [FluoConfiguration] object and set properties using Java:
+
+```java
+FluoConfiguration config = new FluoConfiguration();
+config.setAccumuloUser("user");
+config.setAccumuloPassword("pass");
+config.setAccumuloInstance("instance");
+```
+
+Once you have [FluoConfiguration] object, pass it to the `newClient()` method of [FluoFactory] to
+create a [FluoClient]:
+
+```java
+FluoClient client = FluoFactory.newClient(config)
+```
+
+It may help to reference the [API javadocs][API] while you are learning the Fluo API.
+
+## Running application code
+
+The `fluo exec <app name> <class> {arguments}` provides an easy way to execute application code. It
+will execute a class with a main method if a jar containing the class is placed in the lib directory
+of the application. When the class is run, Fluo classes and dependencies will be on the classpath.
+The `fluo exec` command can inject the applications configuration if the class is written in the
+following way. Defining the injection point is optional.
+
+```java
+import javax.inject.Inject;
+
+public class AppCommand {
+
+  //when run with fluo exec command, the applications configuration will be injected
+  @Inject
+  private static FluoConfiguration fluoConfig;
+
+  public static void main(String[] args) throws Exception {
+    try(FluoClient fluoClient = FluoFactory.newClient(fluoConfig)) {
+      //do stuff with Fluo
+    }
+  }
+}
+```
+
+## Creating a Fluo observer
+
+To create an observer, follow these steps:
+
+1.  Create one or more classes that extend [Observer] like the example below. Please use [slf4j] for
+    any logging in observers as [slf4j] supports multiple logging implementations. This is
+    necessary as Fluo applications have a hard requirement on [logback] when running in YARN.
+
+    ```java
+    public class InvertObserver implements Observer {
+
+      @Override
+      public void process(TransactionBase tx, Bytes row, Column col) throws Exception {
+        // read value
+        Bytes value = tx.get(row, col);
+        // invert row and value
+        tx.set(value, new Column("inv", "data"), row);
+      }
+    }
+    ```
+
+2.  Create a class that implements [ObserverProvider] like the example below.  The purpose of this
+    class is associate a set Observers with columns that trigger the observers.  The class can
+    register multiple observers.
+
+    ```java
+    class AppObserverProvider implements ObserverProvider {
+      @Override
+      public void provide(Registry or, Context ctx) {
+        //setup InvertObserver to be triggered when the column obs:data is modified
+        or.forColumn(new Column("obs", "data"), NotificationType.STRONG)
+          .useObserver(new InvertObserver());
+        
+        //Observer is a Functional interface.  So Obsevers can be written as lambdas.
 
 Review comment:
   Merged before this comment.  Fixed in db72ef51ffb1110f1
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services