Class ModuleRepository
java.lang.Object
ai.pipestream.registration.repository.ModuleRepository
Repository for managing service module registrations in PostgreSQL.
This is the primary data store (system of record).
Blocking Hibernate ORM (Panache active-record) over JDBC. Write methods are
@Transactional; reads run without a transaction. Callers invoke these from
virtual threads, so the blocking JDBC work never pins the event loop.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCount registered services by status.Get service by ID.findCurrentSchemaByServiceName(String serviceName) Resolve the schema of the module's CURRENT registration: the instance with the freshest heartbeat wins.findLatestSchemaByServiceName(String serviceName) Get the latest schema for a service (most recently created).findSchemaById(String schemaId) Get schema by ID.Get all schemas needing sync to Apicurio.findSchemaVersionsByServiceName(String serviceName) Get all schema versions for a service name, ordered by version descending.Find stale services (no heartbeat for > 30 seconds).Get all active services.Get all services (for admin dashboard).markUnhealthy(String serviceId) Mark service as unhealthy.registerModule(String serviceName, String host, int port, String version, Map<String, Object> metadata, String jsonSchema) Register a new service module with optional schema.saveSchema(String serviceName, String version, String jsonSchema) Save a configuration schema (dual storage: PostgreSQL + Apicurio).booleanunregisterModule(String serviceId) Unregister a service.updateHeartbeat(String serviceId) Update heartbeat for a service.upsertNamedArtifact(String artifactName, String version, String json) Upsert a NAMED schema artifact (recipe schema, uischema, ...) as a ConfigSchema row keyed by the artifact name — same update-on-change semantics as module config schemas, so SNAPSHOT re-registrations refresh content and mark PENDING for Apicurio re-sync.
-
Constructor Details
-
ModuleRepository
public ModuleRepository()Creates the repository bean. The Apicurio client used for schema sync is supplied by CDI field injection.
-
-
Method Details
-
registerModule
public ServiceModule registerModule(String serviceName, String host, int port, String version, Map<String, Object> metadata, String jsonSchema) Register a new service module with optional schema. Updates existing module if it already exists.- Parameters:
serviceName- the service namehost- the advertised hostport- the advertised portversion- the module versionmetadata- free-form registration metadatajsonSchema- the config JSON schema to persist, or null/blank to skip schema handling- Returns:
- the created or updated module entity
-
saveSchema
Save a configuration schema (dual storage: PostgreSQL + Apicurio).- Parameters:
serviceName- the service nameversion- the schema versionjsonSchema- the JSON schema content- Returns:
- the persisted schema entity; its sync status reflects whether the Apicurio sync succeeded
-
updateHeartbeat
Update heartbeat for a service.- Parameters:
serviceId- the service ID to refresh- Returns:
- the updated module, or null when no module with that ID exists
-
markUnhealthy
Mark service as unhealthy.- Parameters:
serviceId- the service ID to mark- Returns:
- the updated module, or null when no module with that ID exists
-
unregisterModule
Unregister a service.- Parameters:
serviceId- the service ID to remove- Returns:
trueif a module was found and deleted,falseotherwise
-
getActiveServices
Get all active services.- Returns:
- all modules whose status is
ServiceStatus.ACTIVE
-
getAllServices
Get all services (for admin dashboard).- Returns:
- every registered module regardless of status
-
findStaleServices
Find stale services (no heartbeat for > 30 seconds).- Returns:
- active modules whose last heartbeat is older than 30 seconds
-
findById
Get service by ID.- Parameters:
serviceId- the service ID to look up- Returns:
- the module, or null when none exists with that ID
-
findSchemaById
Get schema by ID.- Parameters:
schemaId- the schema ID to look up- Returns:
- the schema, or null when none exists with that ID
-
upsertNamedArtifact
Upsert a NAMED schema artifact (recipe schema, uischema, ...) as a ConfigSchema row keyed by the artifact name — same update-on-change semantics as module config schemas, so SNAPSHOT re-registrations refresh content and mark PENDING for Apicurio re-sync.- Parameters:
artifactName- the artifact name used as the schema keyversion- the artifact versionjson- the artifact JSON content- Returns:
- the existing (possibly updated) or newly created schema row
-
findLatestSchemaByServiceName
Get the latest schema for a service (most recently created).- Parameters:
serviceName- the service name- Returns:
- the most recently created schema for the service, or null when none exist
-
findCurrentSchemaByServiceName
Resolve the schema of the module's CURRENT registration: the instance with the freshest heartbeat wins. "Latest by createdAt" is wrong once historical version rows exist (e.g. a branch-suffixed snapshot version registered after the canonical one shadows it forever).- Parameters:
serviceName- the service name- Returns:
- the config schema of the freshest-heartbeat module instance, or null when none resolves
-
findSchemaVersionsByServiceName
Get all schema versions for a service name, ordered by version descending.- Parameters:
serviceName- the service name- Returns:
- the service's schemas ordered by version descending
-
findSchemasNeedingSync
Get all schemas needing sync to Apicurio.- Returns:
- schemas whose sync status is PENDING, FAILED, or OUT_OF_SYNC
-
countServicesByStatus
Count registered services by status.- Returns:
- a map of each
ServiceStatusto the number of modules in that status
-