Loading…
Loading…
Manages static DNS host entries from DataPower appliances. Stores and retrieves hostname-to-IP mappings for use in traffic enrichment processes.
The DataPowerDnsStaticHostRepository is a server-side component that manages a database of static DNS host entries parsed from DataPower appliances. Its primary function is to persist and provide access to hostname-to-IP address mappings defined in a DataPower appliance's dns > static-host "host" "ip" "comment" configuration.
This repository solves the problem of correlating backend hostnames known to DataPower with services defined in other parts of the platform, such as a service catalog. The data is used during traffic enrichment to resolve DataPower-specific hostnames.
The component interacts with a database table, s2r_datapower_dns_static_host, to store the DNS entries. All operations are scoped to a specific tenant, ensuring that one tenant cannot access or modify another tenant's DNS data.
NOTE
All hostnames are processed and stored in lowercase, as DNS is case-insensitive. Lookups should also use lowercase hostnames.
The repository provides methods to replace the entire set of DNS entries for a given DataPower instance and to load all entries for the current tenant.
The replaceForInstance method provides an idempotent way to update the DNS snapshot for a single DataPower appliance instance. When called, it performs the following sequence of operations:
DELETE statement on the s2r_datapower_dns_static_host table, removing all existing static host entries associated with the specified datapower_instance_id and the current tenant.INSERT operation to add all valid, normalized entries to the s2r_datapower_dns_static_host table. The tenant_id for each new row is automatically set based on the current session context (app.tenant_id).This delete-then-insert process ensures that each call completely replaces the previous state for that instance. Calling the method with an empty or null map of entries effectively clears all static DNS hosts for that instance.
flowchart TD
subgraph "replaceForInstance(instanceId, entries)"
A[Start] --> B{DELETE FROM s2r_datapower_dns_static_host WHERE instance_id = ?};
B --> C{Is `entries` map empty?};
C -- Yes --> D[End];
C -- No --> E[For each entry in map];
E --> F[Normalize: lowercase host, trim fields];
F --> G{Is host or IP blank?};
G -- Yes --> E;
G -- No --> H[Add to batch list];
H --> E;
E -- Done looping --> I[batchUpdate: INSERT INTO s2r_datapower_dns_static_host];
I --> D;
endThe loadAll method retrieves a consolidated map of all static DNS entries across all DataPower instances belonging to the current tenant.
It queries the s2r_datapower_dns_static_host table, fetching the hostname and ip_address for all records within the tenant's scope. It returns a map of lowercased hostnames to their corresponding IP addresses.
IMPORTANT
If the same hostname is defined on multiple DataPower instances with different IP addresses, the loadAll method will return the IP address from the first entry it encounters during its query. The database does not guarantee a specific order, so the "winning" IP address for a given hostname is indeterminate.
All database operations are strictly scoped by tenant ID. This is enforced by appending a SQL clause (AuditRepository.TENANT_SCOPE_SQL) to every query, which filters results based on the current session's tenant ID. This prevents one tenant from reading or overwriting another tenant's DNS configuration data.
The repository is implemented as a Java class, DataPowerDnsStaticHostRepository, with the following public methods.
replaceForInstanceAtomically replaces the entire static DNS host snapshot for a specific DataPower instance within the current tenant's scope.
void replaceForInstance(UUID instanceId, Map<String, DnsEntry> entries)
Parameters
| Name | Type | Description |
|---|---|---|
instanceId | UUID | The unique identifier for the DataPower instance whose DNS entries are being replaced. |
entries | Map<String, DnsEntry> | A map of hostname strings to DnsEntry objects. If null or empty, all existing entries for the specified instance and tenant are deleted. |
Behavior
instanceId and current tenant.entries map in a single batch operation.loadAllLoads every static host entry across all DataPower instances for the current tenant into a single map.
Map<String, String> loadAll()
Returns
A Map<String, String> where keys are lowercased hostnames and values are the corresponding IP addresses. If a hostname exists on multiple instances, the IP address from the first record returned by the database is used.
DnsEntry RecordA data structure representing a single static host entry captured from a DataPower appliance.
public record DnsEntry(String ipAddress, String comment) {}
Fields
| Name | Type | Description |
|---|---|---|
ipAddress | String | The IP address that the hostname resolves to. |
comment | String | An optional comment associated with the entry. |
The repository persists data in the s2r_datapower_dns_static_host table. The schema is implied by the SQL statements in the source.
| Column | Type | Description |
|---|---|---|
datapower_instance_id | uuid | The foreign key to the DataPower instance this entry belongs to. |
tenant_id | uuid | The foreign key to the tenant that owns this entry. |
hostname | text | The static hostname, stored in lowercase. |
ip_address | text | The IP address for the hostname. |
comment | text | An optional comment from the DataPower configuration. |
updated_at | timestamp | The timestamp when the row was last inserted or updated. |
When calling replaceForInstance, any entry in the input map that has a null or blank hostname or ipAddress will be silently skipped and not inserted into the database. No error will be thrown. If you find that DNS entries are missing after an update, verify that the source data contains valid, non-blank values for these fields.
The loadAll method consolidates entries from all DataPower instances. If two or more instances define the same hostname, loadAll will return the IP address from the first record it processes. Since the database query order is not guaranteed, which IP address is chosen is indeterminate. To ensure predictable resolution, each hostname should be unique across all DataPower instances within a tenant.