Loading…
Loading…
Explains the Connector Instance Bridge Service, which synchronizes DataPower gateway and cluster records into the generic connector instance table for
The Connector Instance Bridge Service provides continuous, on-write synchronization between DataPower-specific records and the generic s2r_connector_instance table. This service ensures that when an API publisher creates, updates, or deletes a DataPower gateway or cluster, a corresponding generic representation is maintained.
This component solves the problem of traffic attribution for DataPower instances modified after an initial, one-time data migration. Without this continuous sync, traffic from new or renamed gateways would not be correctly attributed, as the generic ingest resolver would be unable to find a matching connector_instance_id.
The service is invoked by the administrative services responsible for managing DataPower gateway and cluster entities immediately after they persist a change to the database. It acts as a secondary, fault-tolerant persistence step.
The service ensures data consistency by translating DataPower-specific records into a vendor-agnostic format in the s2r_connector_instance table. This process follows a strict set of rules to guarantee data integrity and operational stability.
sequenceDiagram
actor User as API Publisher
participant AdminSvc as DataPower Admin Service
participant BridgeSvc as Connector Instance Bridge Service
participant DB as Database
User->>AdminSvc: Create/Update/Delete DataPower Gateway
AdminSvc->>DB: Persist change to s2r_datapower_instance
DB-->>AdminSvc: Success
AdminSvc->>BridgeSvc: syncGateway(gatewayRecord)
BridgeSvc->>DB: UPSERT to s2r_connector_instance
alt on database error
BridgeSvc->>BridgeSvc: Catch exception, log S2R-ADM-0453
end
BridgeSvc-->>AdminSvc: Return (void)
AdminSvc-->>User: Operation successfulThe core mechanism is governed by the following principles:
ID-Keyed Synchronization: The primary key of a record in s2r_connector_instance is the same UUID as the source DataPower gateway or cluster (s2r_datapower_instance or s2r_datapower_cluster). All write operations use an ON CONFLICT (id) DO UPDATE clause (an "upsert"). This makes operations idempotent and simplifies renames into a standard field update, avoiding the need to manage multiple records for the same entity.
Soft Deletes: When a DataPower gateway or cluster is deleted, its corresponding record in s2r_connector_instance is not removed. Instead, its enabled flag is set to false. This is critical because a hard delete would cascade through foreign key relationships (ON DELETE SET NULL), stripping historical traffic data of its attribution.
Fault Tolerance: The service is designed to never cause the primary administrative operation (e.g., saving a gateway configuration) to fail. All internal exceptions, such as database connection errors, are caught and logged with the warning code S2R-ADM-0453. A failed sync can be corrected by the next successful update to the same entity or by a periodic backfill process.
Single Source of Truth for Derived Data: The data_plane_ips field is not calculated in the service. Instead, its value is derived within the database by the PostgreSQL function s2r_derive_data_plane_ips(text). This ensures that the derivation logic is consistent between this service and any backfill utilities.
Tenant Scoping: All database operations are strictly scoped to the tenant associated with the current connection. SQL queries include explicit WHERE clauses on the tenant_id column to enforce data isolation between tenants, complementing the database's Row-Level Security (RLS) policies.
The service exposes methods for synchronizing and disabling bridge records. These methods are called internally by other platform services.
syncGatewayRegisters or updates the bridge record for a single DataPower gateway instance. This method is idempotent and can be safely called for create, update, enable, or disable operations.
public void syncGateway(DataPowerInstanceRecord instance)
Parameters:
| Name | Type | Description |
|---|---|---|
instance | DataPowerInstanceRecord | The full record of the gateway to sync. |
The method performs an upsert into s2r_connector_instance. If the gateway belongs to a cluster, the cluster_instance_id is resolved via a subselect that only links to a valid, existing cluster bridge record. This prevents errors from out-of-order writes.
syncClusterRegisters or updates the bridge record for a DataPower HA cluster.
public void syncCluster(DataPowerClusterRecord cluster)
Parameters:
| Name | Type | Description |
|---|---|---|
cluster | DataPowerClusterRecord | The full record of the cluster to sync. |
disableGatewayMarks a gateway's bridge record as disabled (enabled = false). This is a soft delete.
public void disableGateway(UUID instanceId, String actor)
Parameters:
| Name | Type | Description |
|---|---|---|
instanceId | UUID | The ID of the gateway instance to disable. |
actor | String | The identifier of the user or system performing the action. |
disableClusterMarks a cluster's bridge record as disabled (enabled = false). This is a soft delete.
public void disableCluster(UUID clusterId, String actor)
Parameters:
| Name | Type | Description |
|---|---|---|
clusterId | UUID | The ID of the cluster to disable. |
actor | String | The identifier of the user or system performing the action. |
The service writes to the s2r_connector_instance table. The following table describes the columns managed by this service for DataPower entities.
| Column | Type | Source / Value |
|---|---|---|
id | uuid | The ID from the source DataPowerInstanceRecord or DataPowerClusterRecord. |
vendor | text | The static string "datapower". |
name | text | The instanceName or clusterName from the source record. |
enabled | boolean | The enabled status from the source DataPowerInstanceRecord. Set to true on cluster sync and false on disable operations. |
management_url | text | The managementUrl from the source DataPowerInstanceRecord. Set to null for clusters. |
is_cluster | boolean | false for gateways, true for clusters. |
cluster_instance_id | uuid | The clusterId from the source DataPowerInstanceRecord, resolved against an existing cluster record. Set to null for clusters. |
data_plane_ips | text | Derived by the s2r_derive_data_plane_ips() PostgreSQL function from the management_url. Set to null for clusters. |
updated_by | text | The actor performing the change. Defaults to "system" if the provided actor is null or blank. |
tenant_id | uuid | The tenant ID associated with the database connection. Used in WHERE clauses to enforce data isolation. The source does not specify a default. |
When syncGateway is called, it executes a SQL INSERT ... ON CONFLICT statement to create or update the record. The following is the template for this operation. The ? placeholders are filled with values from the DataPowerInstanceRecord.
insert into s2r_connector_instance
(id, vendor, name, enabled, management_url, is_cluster, cluster_instance_id,
data_plane_ips, created_at, updated_at, updated_by)
values (?, ?, ?, ?, ?, false,
(select ci.id from s2r_connector_instance ci
where ci.id = ? and ci.is_cluster
and ci.tenant_id = '...' -- Tenant scope predicate
),
s2r_derive_data_plane_ips(?),
now(), now(), ?)
on conflict (id) do update set
vendor = excluded.vendor,
name = excluded.name,
enabled = excluded.enabled,
management_url = excluded.management_url,
is_cluster = false,
cluster_instance_id = excluded.cluster_instance_id,
data_plane_ips = excluded.data_plane_ips,
updated_at = now(),
updated_by = excluded.updated_by
where s2r_connector_instance.tenant_id = excluded.tenant_id
The service is designed for high resilience and to prevent cascading failures.
S2R-ADM-0453 connector_instance bridge sync failed for DataPower <kind> <id>: <error_message>s2r_connector_instance table will not reflect the latest change. This may cause traffic from the affected gateway to be temporarily unattributed or attributed to its parent cluster until the sync is successful.