Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

An Application is a collection of building blocks that read and write data through the data abstraction layer in CDAP.

Applications are Applications are composed from Programs, Services, and Schedules.

...

Code Block
public class MyApp extends AbstractApplication {
  @Override
  public void configure() {
    setName("myApp");
    setDescription("My Sample Application");
    createDataset("myAppDataset", Table.class);
    addService(new MyService());
    addMapReduce(new MyMapReduce());
    addWorkflow(new MyAppWorkflow());
  }
}

Components are defined using user-written classes that implement correspondent interfaces and are referenced by passing an object, in addition to being assigned a unique name.

...

Code Block
public class MyApp extends AbstractApplication<MyApp.MyAppConfig> {

  public static class MyAppConfig extends Config {
    String datasetName;

    public MyAppConfig() {
      // Default values
      this.datasetName = "myAppDataset";
    }
  }

  @Override
  public void configure() {
    MyAppConfig config = getConfig();
    setName("myApp");
    setDescription("My Sample Application");
    createDataset(config.datasetName, Table.class);
    addService(new MyService(config.datasetName));
    addMapReduce(new MyMapReduce(config.datasetName));
    addWorkflow(new MyAppWorkflow());
  }
}

In order to use the configuration in programs, we pass it to individual programs using their constructor. If the configuration parameter is also required during runtime, you can use the @Property annotation. In the example below, the uniqueCountTableName is used in the configure method to register the usage of the dataset. It is also used during the runtime to get the dataset instance using getDataset() method:

...