🔗Building and Running CDAP Applications

In the examples, we refer to the Standalone CDAP as CDAP, and the example code that is running on it as an application. We'll assume that you are running your application in the default namespace; if not, you will need to adjust commands accordingly. For example, in a URL such as:

http://localhost:10000/v3/namespaces/default/apps...

to use the namespace my_namespace, you would replace default with my_namespace:

http://localhost:10000/v3/namespaces/my_namespace/apps...

🔗Accessing CLI, curl, and the SDK bin

  • For brevity in the commands given below, we will simply use cdap-cli.sh for the CDAP Command Line Interface. Substitute the actual path of ./<CDAP-SDK-HOME>/bin/cdap-cli.sh, or <CDAP-SDK-HOME>\bin\cdap-cli.bat on Windows, as appropriate.

  • A Windows-version of the application curl is included in the CDAP SDK as libexec\bin\curl.exe; use it as a substitute for curl in examples.

  • If you add the SDK bin directory to your path, you can simplify the commands. From within the CDAP-SDK-home directory, enter:

    $ export PATH=${PATH}:`pwd`/bin
    
    > set path=%PATH%;%CD%\bin;%CD%\libexec\bin
    

    The Windows path has been augmented with a directory where the SDK includes Windows-versions of commands such as curl.

Note: There is an issue with running Microsoft Windows and using the CDAP Standalone scripts when JAVA_HOME is defined as a path with spaces in it. A workaround is to use a definition of JAVA_HOME that does not include spaces, such as C:\PROGRA~1\Java\jdk1.7.0_79\bin or C:\ProgramData\Oracle\Java\javapath.

🔗Building an Example Application Artifact

From the example's project root, build an example with the Apache Maven command:

$ mvn clean package
> mvn clean package

🔗Starting CDAP

Before running an example application, check that an instance of CDAP is running and available; if not, follow the instructions for Starting and Stopping Standalone CDAP.

If you can reach the CDAP UI through a browser at http://localhost:9999/, CDAP is running.

🔗Deploying an Application

Once CDAP is started, you can deploy an application using an example JAR by any of these methods:

  • In the CDAP UI, use the Add App button—found on either the Development Home or Management Applications pages—selecting the Custom App menu item, and then browse and upload an artifact to create an app:

    examples/<example-directory>/target/<example>-3.6.0.jar
    
    examples\<example-directory>\target\<example>-3.6.0.jar
    
  • From the Standalone CDAP SDK directory, use the Command Line Interface (CLI):

    $ cdap-cli.sh load artifact examples/<example-directory>/target/<example>-3.6.0.jar
    Successfully added artifact with name '<example>'
    
    $ cdap-cli.sh create app <app name> <example> 3.6.0 user
    Successfully created application
    
    > cdap-cli.bat load artifact examples\<example-directory>\target\<example>-3.6.0.jar
    Successfully added artifact with name '<example>'
    
    > cdap-cli.bat create app <app name> <example> 3.6.0 user
    Successfully created application
    

    The CLI can be accessed under Windows using the bin\cdap-cli.bat script.

  • Use an application such as curl (a Windows-version is included in the CDAP SDK in libexec\bin\curl.exe):

    $ curl -w"\n" localhost:10000/v3/namespaces/default/artifacts/<example> \
      --data-binary @examples/<example-directory>/target/<example>-3.6.0.jar
    Artifact added successfully
    
    $ curl -w"\n" -X PUT -H "Content-Type: application/json" localhost:10000/v3/namespaces/default/apps/<app name> \
      -d '{ "artifact": { "name": "<example>", "version": "3.6.0", "scope": "user" }, "config": {} }'
    Deploy Complete
    
    > curl localhost:10000/v3/namespaces/default/artifacts/<example> ^
      --data-binary @examples\<example-directory>\target\<example>-3.6.0.jar
    Artifact added successfully
    
    > curl -X PUT -H "Content-Type: application/json" localhost:10000/v3/namespaces/default/apps/<app name> ^
      -d "{ \"artifact\": { \"name\": \"<example>\", \"version\": \"3.6.0\", \"scope\": \"user\" }, \"config\": {} }"
    Deploy Complete
    

🔗Starting an Application

Once an application is deployed, there are multiple methods for starting an application:

  • You can go to the application's detail page in the CDAP UI by clicking on the application's name in either the Development Home page or on the All Applications page. Now you can see the status of any of the programs associated with the application and, by clicking on them, go to their detail page where you can start or stop them.

  • From the Standalone CDAP SDK directory, use the Command Line Interface. In each CDAP example, the CLI commands for that particular example are provided:

    $ cdap-cli.sh start <program-type> <app-id.program-id>
    
    > cdap-cli.bat start <program-type> <app-id.program-id>
    
    Parameter Description
    <program-type> One of flow, mapreduce, service, spark, worker, or workflow
    <app-id> Name of the application being called
    <program-id> Name of the flow, MapReduce, service, spark, worker or workflow being called

🔗Stopping an Application

Once an application is deployed:

  • On an application's detail page in the CDAP UI, you can click on a program to go to its detail page and then click the Stop button there; or

  • From the Standalone CDAP SDK directory, use the Command Line Interface:

    $ cdap-cli.sh stop <program-type> <app-id.program-id>
    
    > cdap-cli.bat stop <program-type> <app-id.program-id>
    

🔗Removing an Application

Once an application is stopped—all of its programs (flows, MapReduce programs, workflows, services, etc.) are stopped—you can go to the All Applications page of the CDAP UI, click on the particular application to go to its detail page, click the Actions menu on the right side and select Manage to go to the Management pane for the application, then click the Actions menu on the right side and select Delete.

After confirmation, the application will be deleted.

From the Standalone CDAP SDK directory, you can also use the Command Line Interface:

$ cdap-cli.sh delete app <app-id>
> cdap-cli.bat delete app <app-id>

Note that any storage (datasets) created or used by the application will remain, as they are independent of the application. Datasets can be deleted from the Management Datasets page of the CDAP UI, or by using the HTTP Restful API, the Java Client API, or the Command Line Interface API.

Streams can be either truncated or deleted, using similar methods.

The artifact used to create the application will also remain, as multiple applications can be created from the same artifact. Artifacts can be deleted using the Http Restful API, the Java Client API, or the Command Line Interface API.