CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-co-cask-cdap--cdap-api

Core application programming interface for the Cask Data Application Platform enabling development of scalable data processing applications on Hadoop ecosystems.

Pending
Overview
Eval results
Files

system-services.mddocs/

System Services

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.

Capabilities

Metrics Collection

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);
}

Service Discovery

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);
}

Administrative Operations

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
}

Runtime Metrics

Interface for accessing runtime metrics and performance information.

/**
 * Interface providing access to runtime metrics
 */
public interface RuntimeMetrics {
    // Methods for accessing runtime performance metrics
}

Metrics Collection

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
    }
}

Service Access Patterns

Metrics Integration

  • Built-in collection: Metrics automatically integrate with CDAP monitoring
  • Custom metrics: Applications can define domain-specific metrics
  • Aggregation: Platform provides aggregation and reporting capabilities
  • Alerting: Metrics can trigger alerts and notifications

Service Communication

  • Dynamic discovery: Services can be discovered at runtime
  • Load balancing: Platform handles load balancing for discovered services
  • Health checking: Automatic health monitoring of discovered services
  • Failover: Built-in failover mechanisms for service communication

Administrative Access

  • Dataset operations: Create, update, and manage datasets programmatically
  • Security management: Access secure storage and credential management
  • Messaging control: Administrative control over messaging systems
  • Resource management: Monitor and control application resources

Best Practices

Metrics Collection:

  • Use descriptive metric names with consistent naming conventions
  • Avoid high-cardinality metrics that can impact performance
  • Aggregate metrics appropriately for your monitoring needs
  • Include error and success metrics for operational visibility

Service Discovery:

  • Cache service URLs when appropriate to reduce discovery overhead
  • Handle null returns gracefully when services are unavailable
  • Implement retry logic for transient discovery failures
  • Use circuit breaker patterns for external service calls

Administrative Operations:

  • Use administrative interfaces sparingly and only when necessary
  • Implement proper error handling for administrative operations
  • Consider security implications of administrative access
  • Log administrative operations for audit purposes

Install with Tessl CLI

npx tessl i tessl/maven-co-cask-cdap--cdap-api

docs

annotations.md

application-framework.md

dataset-management.md

index.md

mapreduce-programs.md

plugin-framework.md

scheduling.md

service-programs.md

spark-programs.md

system-services.md

transactions.md

worker-programs.md

workflow-programs.md

tile.json