<commit_before>.. meta::
    :author: Cask Data, Inc.
    :copyright: Copyright © 2014-2015 Cask Data, Inc.

.. _client-api:

.. _java-client-api:

===============
Java Client API
===============

The Cask Data Application Platform (CDAP) Java Client API provides methods for interacting
with CDAP from Java applications.

Maven Dependency
----------------

.. highlight:: console

To use the Java Client API in your project, add this Maven dependency::

  <dependency>
    <groupId>co.cask.cdap</groupId>
    <artifactId>cdap-client</artifactId>
    <version>${cdap.version}</version>
  </dependency>

.. highlight:: java

Components
----------

The Java Client API allows you to interact with these CDAP components:

- `ApplicationClient: <#application-client>`_ interacting with applications
- `ProgramClient: <#program-client>`_ interacting with flows, MapReduce programs, user services, workflows, and workers
- `StreamClient: <#stream-client>`_ interacting with streams
- `DatasetClient: <#dataset-client>`_ interacting with datasets
- `DatasetModuleClient: <#dataset-module-client>`_ interacting with dataset Modules
- `DatasetTypeClient: <#dataset-type-client>`_ interacting with dataset Types
- `QueryClient: <#query-client>`_ querying datasets
- `ServiceClient: <#service-client>`_ interacting with user services
- `MetricsClient: <#metrics-client>`_ interacting with metrics
- `MonitorClient: <#monitor-client>`_ monitoring system services
- `PreferencesClient: <#preferences-client>`_ interacting with preferences

Alphabetical list:

- `ApplicationClient: <#application-client>`_ interacting with applications
- `DatasetClient: <#dataset-client>`_ interacting with datasets
- `DatasetModuleClient: <#dataset-module-client>`_ interacting with dataset Modules
- `DatasetTypeClient: <#dataset-type-client>`_ interacting with dataset Types
- `MetricsClient: <#metrics-client>`_ interacting with metrics
- `MonitorClient: <#monitor-client>`_ monitoring system services
- `PreferencesClient: <#preferences-client>`_ interacting with preferences
- `ProgramClient: <#program-client>`_ interacting with flows, MapReduce Programs, user services, workflows, and workers
- `QueryClient: <#query-client>`_ querying datasets
- `ServiceClient: <#service-client>`_ interacting with user services
- `StreamClient: <#stream-client>`_ interacting with streams

The above lists link to the examples below for each portion of the API.

.. _client-api-configuring-client:

Configuring your \*Client
-------------------------

Every *\*Client* constructor requires a `ClientConfig` instance which configures the hostname and port of the CDAP
instance that you wish to interact with.

In a non-secure (default) CDAP instance, instantiate as follows::

  // Interact with the CDAP instance located at example.com, port 10000
  ClientConfig clientConfig = new ClientConfig("example.com", 10000);

In a secure CDAP instance, first pull in the ``cdap-authentication-client`` Maven dependency::

  <dependency>
    <groupId>co.cask.cdap</groupId>
    <artifactId>cdap-authentication-client</artifactId>
    <version>${cdap.client.version}</version>
  </dependency>

Then, instantiate as follows::

  // Obtain AccessToken
  AuthenticationClient authenticationClient = new BasicAuthenticationClient();
  authenticationClient.setConnectionInfo("example.com", 10000, sslEnabled);
  // Configure the AuthenticationClient as documented in
  // https://github.com/caskdata/cdap-clients/blob/develop/cdap-authentication-clients/java
  AccessToken accessToken = authenticationClient.getAccessToken();

  // Interact with the secure CDAP instance located at example.com, port 10000, with the provided accessToken
  ClientConfig clientConfig = ClientConfig.builder()
    .setConnectionConfig(new ConnectionConfig("example.com", 10000, accessToken))
    .build();

.. _application-client:

ApplicationClient
-----------------
::

  ClientConfig clientConfig;

  // Construct the client used to interact with CDAP
  ApplicationClient appClient = new ApplicationClient(clientConfig);

  // Fetch the list of applications
  List<ApplicationRecord> apps = appClient.list(Id.Namespace.DEFAULT);

  // Deploy an application
  File appJarFile = new File("your-app.jar");
  appClient.deploy(Id.Namespace.DEFAULT, appJarFile);

  // Delete an application
  appClient.delete(Id.Application.from(Id.Namespace.DEFAULT, "Purchase"));

  // List programs belonging to an application
  appClient.listPrograms(Id.Application.from(Id.Namespace.DEFAULT, "Purchase"));<commit_msg>Update oudated documentation around instantiating a ClientConfig and setting its AccessToken.<commit_after>.. meta::
    :author: Cask Data, Inc.
    :copyright: Copyright © 2014-2015 Cask Data, Inc.

.. _client-api:

.. _java-client-api:

===============
Java Client API
===============

The Cask Data Application Platform (CDAP) Java Client API provides methods for interacting
with CDAP from Java applications.

Maven Dependency
----------------

.. highlight:: console

To use the Java Client API in your project, add this Maven dependency::

  <dependency>
    <groupId>co.cask.cdap</groupId>
    <artifactId>cdap-client</artifactId>
    <version>${cdap.version}</version>
  </dependency>

.. highlight:: java

Components
----------

The Java Client API allows you to interact with these CDAP components:

- `ApplicationClient: <#application-client>`_ interacting with applications
- `ProgramClient: <#program-client>`_ interacting with flows, MapReduce programs, user services, workflows, and workers
- `StreamClient: <#stream-client>`_ interacting with streams
- `DatasetClient: <#dataset-client>`_ interacting with datasets
- `DatasetModuleClient: <#dataset-module-client>`_ interacting with dataset Modules
- `DatasetTypeClient: <#dataset-type-client>`_ interacting with dataset Types
- `QueryClient: <#query-client>`_ querying datasets
- `ServiceClient: <#service-client>`_ interacting with user services
- `MetricsClient: <#metrics-client>`_ interacting with metrics
- `MonitorClient: <#monitor-client>`_ monitoring system services
- `PreferencesClient: <#preferences-client>`_ interacting with preferences

Alphabetical list:

- `ApplicationClient: <#application-client>`_ interacting with applications
- `DatasetClient: <#dataset-client>`_ interacting with datasets
- `DatasetModuleClient: <#dataset-module-client>`_ interacting with dataset Modules
- `DatasetTypeClient: <#dataset-type-client>`_ interacting with dataset Types
- `MetricsClient: <#metrics-client>`_ interacting with metrics
- `MonitorClient: <#monitor-client>`_ monitoring system services
- `PreferencesClient: <#preferences-client>`_ interacting with preferences
- `ProgramClient: <#program-client>`_ interacting with flows, MapReduce Programs, user services, workflows, and workers
- `QueryClient: <#query-client>`_ querying datasets
- `ServiceClient: <#service-client>`_ interacting with user services
- `StreamClient: <#stream-client>`_ interacting with streams

The above lists link to the examples below for each portion of the API.

.. _client-api-configuring-client:

Configuring your \*Client
-------------------------

Every *\*Client* constructor requires a `ClientConfig` instance which configures the hostname and port of the CDAP
instance that you wish to interact with.

In a non-secure (default) CDAP instance, instantiate as follows::

  // Interact with the CDAP instance located at example.com, port 10000
  ClientConfig clientConfig = ClientConfig.builder()
    .setConnectionConfig(new ConnectionConfig("example.com", 10000, false))
    .build();

In a secure CDAP instance, first pull in the ``cdap-authentication-client`` Maven dependency::

  <dependency>
    <groupId>co.cask.cdap</groupId>
    <artifactId>cdap-authentication-client</artifactId>
    <version>${cdap.client.version}</version>
  </dependency>

Then, instantiate as follows::

  // Obtain AccessToken
  AuthenticationClient authenticationClient = new BasicAuthenticationClient();
  authenticationClient.setConnectionInfo("example.com", 10000, sslEnabled);
  // Configure the AuthenticationClient as documented in
  // https://github.com/caskdata/cdap-clients/blob/develop/cdap-authentication-clients/java
  AccessToken accessToken = authenticationClient.getAccessToken();

  // Interact with the secure CDAP instance located at example.com, port 10000, with the provided accessToken
  ClientConfig clientConfig = ClientConfig.builder()
    .setConnectionConfig(new ConnectionConfig("example.com", 10000, sslEnabled))
    .setAccessToken(accessToken)
    .build();

.. _application-client:

ApplicationClient
-----------------
::

  ClientConfig clientConfig;

  // Construct the client used to interact with CDAP
  ApplicationClient appClient = new ApplicationClient(clientConfig);

  // Fetch the list of applications
  List<ApplicationRecord> apps = appClient.list(Id.Namespace.DEFAULT);

  // Deploy an application
  File appJarFile = new File("your-app.jar");
  appClient.deploy(Id.Namespace.DEFAULT, appJarFile);

  // Delete an application
  appClient.delete(Id.Application.from(Id.Namespace.DEFAULT, "Purchase"));

  // List programs belonging to an application
  appClient.listPrograms(Id.Application.from(Id.Namespace.DEFAULT, "Purchase"));
{'fraction_non_alphanumeric': 0.12277099319139738, 'fraction_numerical': 0.007132821787528369, 'mean_word_length': 4.820125786163522, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 81, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3627551', 'n_tokens_mistral': 2617, 'n_tokens_neox': 2407, 'n_words': 767}