Overview
The purpose of this page is to illustrate the plan for ApplicationTemplate and Application consolidation. This work is being tracked in
Why do we want to consolidate templates and applications? In CDAP 3.0, an ApplicationTemplate is a way for somebody to write an Application that can be given some configuration to create an Adapter. The story is confusing; one would expect an ApplicationTemplate to create... Applications. Instead, we use the term Adapter because Application means something else already. In addition an ApplicationTemplate can only include a single workflow or a single worker, giving people different experiences for templates and applications.
Really, the goal of templates was to be able to write one piece of Application code that could be used to create multiple Applications. To do this requires that an Application can be configured at creation time instead of at compile time. For example, a user should be able to set the name of their dataset based on configuration instead of hardcoding it in the code. To support this, we plan on making it possible to get a configuration object from the ApplicationContext available in Application's configure() method. This allows somebody to pass in a config when creating an Application through the RESTful API, which can be used to configure an Application. The relevant programmatic API changes are shown below, with an example of how they might be used:
public interface ApplicationContext<T extends Config> { T getConfig(); } public interface Application<T extends Config> { void configure(ApplicationConfigurer configurer, ApplicationContext<T> context); } public abstract class AbstractApplication<T> implements Application<T extends Config> { ... protected final ApplicationContext<T> getContext() { return context; } } public class MyApp extends AbstractApplication<MyApp.MyConfig> { public static class MyConfig { private String stream; private String table; private MyFlowConfig flowOptions; } public void configure() { // ApplicationContext now has a method to get a custom config object whose fields will // be injected using the values given in the RESTful API MyConfig config = getContext().getConfig(); addStream(new Stream(config.stream)); createDataset(config.table, Table.class); addFlow(config.stream, config.table, config.flowOptions); } }
Details
The sequence of events now looks like: (insert sequence diagram)