An Application is a collection of building blocks that read and write data through the data abstraction layer in CDAP.
Applications are composed from Programs, Services, and Schedules.
Programs include MapReduce programs, Workflows, Spark programs, and Workers, which are used to process data. Services are used to serve data.
Data abstractions include Datasets.
Applications are created using an Artifact and optional configuration. An Artifact is a JAR file that packages the Java Application class that defines how the Programs, Services, Schedules, and Datasets interact.
It also packages any dependent classes and libraries needed to run the Application.
Implementing an Application Class
To implement an application class, extend the AbstractApplication class, specifying the application metadata and declaring and configuring each of the application components:
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.
Names used for datasets need to be unique across the CDAP namespace, while names used for programs and services need to be unique only to the application.
A Typical CDAP Application Class
A typical design of a CDAP application class consists of:
MapReduce programs, Spark programs, and Workflows for batch processing tasks;
Workers for processing data in an ad-hoc manner that doesn't fit into real-time or batch paradigms
Datasets for storage of data, either raw or the processed results; and
Services for serving data and processed results.
Of course, not all components are required. It depends on the application. A minimal application could include a workflow and a dataset. In the next sections, we'll look at these components, and their interactions.
Applications can be created with a version string. This can be useful when a newer version of the same application needs to be created, and you need to distinguish them and run them at the same time. Programs of a specific version of an application can be started and stopped using the calls of the version-aware Lifecycle Microservices.
If a version is not provided while creating an application (i.e., the application is created using a non-version-aware API), a default version of "-SNAPSHOT" is used.
If an application version is specified that matches one that already exists, it will be overwritten only if the version string ends with "-SNAPSHOT". Otherwise, versions are immutable, and the only way to change a version is to delete the application of that version and then redeploy it.
Application classes can use a Config class to receive a configuration when an Application is created. For example, configuration can be used to specify, at application creation time, a dataset to be read, rather than having them hard-coded in the AbstractApplication's configure method. The configuration class needs to be the type parameter of the AbstractApplication class. It should also extend the Config class present in the CDAP API. The configuration is provided as part of the request body to create an application. It is available during configuration time through the getConfig() method in AbstractApplication.
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: