API for CDAP System Applications - provides interfaces and abstract classes for building system services that run in the CDAP system namespace
—
Core system service functionality for creating services that run with elevated privileges in the CDAP system namespace. System services can create tables, access all namespaces, and perform operations not available to regular user services.
Abstract base class for system services that can only be deployed in the system namespace.
/**
* Abstract class for system services. System services can only be used in
* applications that are deployed in the system namespace.
*/
@Beta
public abstract class AbstractSystemService
extends AbstractService<SystemServiceConfigurer, SystemServiceContext> {
/**
* Creates a system table that conforms to the given table specification
* when the application is deployed.
* @param tableSpecification the specification for the system table
*/
protected void createTable(StructuredTableSpecification tableSpecification);
}Usage Example:
import io.cdap.cdap.api.service.AbstractSystemService;
import io.cdap.cdap.api.service.SystemServiceConfigurer;
import io.cdap.cdap.spi.data.StructuredTableSpecification;
public class MySystemService extends AbstractSystemService {
@Override
public void configure(SystemServiceConfigurer configurer) {
setName("my-system-service");
setDescription("Example system service");
// Create a system table
StructuredTableSpecification tableSpec = StructuredTableSpecification.builder()
.withId("system-metadata")
.withFields(/* field definitions */)
.build();
createTable(tableSpec);
}
@Override
protected void startUp() throws Exception {
// Service startup logic
}
@Override
protected void shutDown() throws Exception {
// Service shutdown logic
}
}Configurer interface for system application services with capabilities beyond those available to user services.
/**
* Configurer for system application services. Allows additional capabilities
* beyond those available to user services.
*/
@Beta
public interface SystemServiceConfigurer extends ServiceConfigurer, SystemTableConfigurer {
// Inherits all methods from ServiceConfigurer and SystemTableConfigurer
}Service context for system services with enhanced capabilities including transaction running and namespace administration.
/**
* A System ServiceContext that exposes capabilities beyond those available
* to service contexts for user services.
*/
public interface SystemServiceContext extends ServiceContext, TransactionRunner, SystemNamespaceAdmin {
// Inherits all methods from ServiceContext, TransactionRunner, and SystemNamespaceAdmin
}Interface providing namespace administration capabilities for system services.
/**
* Interface for listing all namespaces for system service.
*/
public interface SystemNamespaceAdmin {
/**
* Lists all the namespaces.
* @return list of namespace summaries
* @throws Exception if listing namespaces fails
*/
List<NamespaceSummary> listNamespaces() throws Exception;
}Usage Example:
import io.cdap.cdap.api.service.SystemServiceContext;
import io.cdap.cdap.proto.NamespaceSummary;
public class NamespaceManagerService extends AbstractSystemService {
@Override
protected void startUp() throws Exception {
SystemServiceContext context = getContext();
// List all namespaces
List<NamespaceSummary> namespaces = context.listNamespaces();
for (NamespaceSummary namespace : namespaces) {
// Process each namespace
LOG.info("Found namespace: {}", namespace.getName());
}
}
}Interface for creating system tables during application deployment.
/**
* Allows registering system tables for creation.
*/
@Beta
public interface SystemTableConfigurer {
/**
* Creates a system table that conforms to the given specification when
* application is deployed.
* @param tableSpecification the table specification
*/
void createTable(StructuredTableSpecification tableSpecification);
}Usage Example:
import io.cdap.cdap.api.SystemTableConfigurer;
import io.cdap.cdap.spi.data.StructuredTableSpecification;
import io.cdap.cdap.spi.data.table.field.FieldType;
import io.cdap.cdap.spi.data.table.field.Fields;
public void configureSystemTable(SystemTableConfigurer configurer) {
StructuredTableSpecification tableSpec = StructuredTableSpecification.builder()
.withId("system-audit-log")
.withFields(
Fields.stringField("timestamp"),
Fields.stringField("user_id"),
Fields.stringField("action"),
Fields.stringField("details")
)
.withPrimaryKeys("timestamp", "user_id")
.withIndexes("action")
.build();
configurer.createTable(tableSpec);
}@Beta annotation are subject to changeInstall with Tessl CLI
npx tessl i tessl/maven-io-cdap-cdap--cdap-system-app-api