Core application programming interface for the Cask Data Application Platform enabling development of scalable data processing applications on Hadoop ecosystems.
—
CDAP provides access to various system services for metrics collection, service discovery, administrative operations, and security management. These services enable applications to integrate with the CDAP platform infrastructure.
Interface for collecting custom application metrics that integrate with CDAP's monitoring system.
/**
* Interface for collecting user-defined metrics in CDAP applications
*/
public interface Metrics {
/**
* Increases the value of a counter metric by the specified amount
* @param metricName Name of the counter (use alphanumeric characters)
* @param delta The value to increase by
*/
void count(String metricName, int delta);
/**
* Sets a gauge metric to the provided value
* @param metricName Name of the gauge (use alphanumeric characters)
* @param value The value to be set
*/
void gauge(String metricName, long value);
}Interface for discovering and accessing services within the CDAP environment.
/**
* Interface for discovering service endpoints within CDAP
*/
public interface ServiceDiscoverer {
/**
* Discover the base URL for a service in a specific application
* @param applicationId Application name
* @param serviceId Service name
* @return URL for the discovered service or null if not found
*/
@Nullable
URL getServiceURL(String applicationId, String serviceId);
/**
* Discover the base URL for a service in the same application
* @param serviceId Service name
* @return URL for the discovered service or null if not found
*/
@Nullable
URL getServiceURL(String serviceId);
}Interface providing access to administrative operations for datasets, messaging, and security.
/**
* Interface for operational administrative calls within CDAP applications
*/
@Beta
public interface Admin extends DatasetManager, SecureStoreManager, MessagingAdmin {
// Inherits methods for dataset management, secure storage, and messaging administration
}Interface for accessing runtime metrics and performance information.
/**
* Interface providing access to runtime metrics
*/
public interface RuntimeMetrics {
// Methods for accessing runtime performance metrics
}Interface for advanced metrics collection with additional capabilities.
/**
* Extended interface for metrics collection
*/
public interface MetricsCollector {
// Advanced metrics collection methods
}Usage Examples:
import co.cask.cdap.api.metrics.Metrics;
import co.cask.cdap.api.ServiceDiscoverer;
import co.cask.cdap.api.Admin;
public class SystemServicesExample extends AbstractService {
// Metrics collection example
public void collectMetrics(Metrics metrics) {
// Count events
metrics.count("user.logins", 1);
metrics.count("data.processed.records", 100);
// Set gauge values
metrics.gauge("queue.size", getCurrentQueueSize());
metrics.gauge("memory.usage.bytes", getMemoryUsage());
// Error counting
try {
processData();
metrics.count("operations.success", 1);
} catch (Exception e) {
metrics.count("operations.error", 1);
throw e;
}
}
// Service discovery example
public void discoverServices(ServiceDiscoverer discoverer) {
// Discover service in same application
URL dataService = discoverer.getServiceURL("data-processor");
if (dataService != null) {
callDataService(dataService);
}
// Discover service in different application
URL analyticsService = discoverer.getServiceURL("analytics-app", "analytics-service");
if (analyticsService != null) {
callAnalyticsService(analyticsService);
}
}
// Administrative operations example
public void performAdminOperations(Admin admin) {
// Dataset management operations
// Secure store operations
// Messaging administration
// (Specific methods depend on inherited interfaces)
}
private void callDataService(URL serviceURL) {
// Make HTTP calls to discovered service
String endpoint = serviceURL.toString() + "/api/process";
// HTTP client implementation
}
private void callAnalyticsService(URL serviceURL) {
// Make HTTP calls to analytics service
String endpoint = serviceURL.toString() + "/api/analyze";
// HTTP client implementation
}
private int getCurrentQueueSize() {
// Implementation to get current queue size
return 42;
}
private long getMemoryUsage() {
// Implementation to get memory usage
return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
}
private void processData() throws Exception {
// Data processing implementation
}
}Metrics Collection:
Service Discovery:
Administrative Operations:
Install with Tessl CLI
npx tessl i tessl/maven-co-cask-cdap--cdap-api