Publishing Results
Every request your connector receives must end with a result published back to Zetect. This page covers the publisher contract, how to split a large aggregation into chunks, what Zetect does with each result, and how the result travels back.
Connector API io.cyiam:cyiam-connector-api version 1.4.0.
One result per request. For a chunked aggregation, one result per chunk, ending with exactly one chunk flagged as the last.
The publisher contract
| Publisher | Passed to | Rule |
|---|---|---|
| ConnectorPublisher | handle(): SYNC_USER, SYNC_GROUP, IDENTITY_SYNC and legacy actions | Call publish(ConnectorResult) exactly once, or once per chunk when the request asks for chunking. |
| ProvisioningPublisher | handleProvisioning(): every provisioning action | Call publish(ProvisioningResult) exactly once. Provisioning results are never chunked. |
Use the factory methods rather than building results by hand. They copy the identifying fields from the request for you.
| Factory method | Use for |
|---|---|
| ConnectorResult.successWithRecords(cmd, records) | An aggregation that returns all records in one result. |
| ConnectorResult.successWithRecords(cmd, records, chunkIndex, chunkCount, lastChunk) | One chunk of a chunked aggregation. |
| ConnectorResult.success(cmd, result) | A legacy action that returns a single object instead of records. |
| ConnectorResult.failure(cmd, error) | A failed aggregation. Sets success to false. |
| ProvisioningResult.success(cmd, nativeAccountIdentifier, accountDisplayName) | A successful provisioning action. Sets status to SUCCESS. |
| ProvisioningResult.failure(cmd, message) | A failed provisioning action. Sets status to ERROR. |
| ConnectorResult.notSupported(cmd), ProvisioningResult.notSupported(cmd) | An action your connector doesn't implement. The error reads actionNotSupported: <action>. |
What happens when you call publish
- Your method runs on one of the agent's worker threads.
publish(result)runs synchronously on that same thread. When it returns, the message has been handed to the broker.- The agent serialises the result to JSON. Fields that are
nullare left out. - The agent publishes the message to the
cyiam.agentexchange with the routing key for the channel the request came from. - If your method throws instead, the agent publishes a failure result with the exception's class name and message, so Zetect never waits forever. Publish your own failure on every path anyway; it gives administrators a clearer message.
Publishing a chunked aggregation
When a SYNC_USER, SYNC_GROUP or IDENTITY_SYNC request has a positive chunkSize, split the records into groups of at most that many and publish one result per group. When chunkSize is missing, null, zero or negative, publish a single result without chunk fields.
private static void publishRecords(ConnectorCommand cmd, ArrayNode records,
ConnectorPublisher publisher) {
Integer chunkSize = cmd.getChunkSize();
if (chunkSize == null || chunkSize <= 0) {
publisher.publish(ConnectorResult.successWithRecords(cmd, records));
return;
}
int total = records.size();
int chunkCount = total == 0 ? 1 : (int) Math.ceil(total / (double) chunkSize);
for (int chunkIndex = 1; chunkIndex <= chunkCount; chunkIndex++) {
int start = (chunkIndex - 1) * chunkSize;
int end = Math.min(start + chunkSize, total);
ArrayNode chunk = JsonNodeFactory.instance.arrayNode();
for (int i = start; i < end; i++) chunk.add(records.get(i));
publisher.publish(ConnectorResult.successWithRecords(
cmd, chunk, chunkIndex, chunkCount, chunkIndex == chunkCount));
}
}
Each chunk carries three fields:
| Field | Value |
|---|---|
| chunkIndex | The chunk's position, starting at 1. |
| chunkCount | The total number of chunks in the run. |
| lastChunk | true on the final chunk, false on every other chunk. |
How Zetect reads the chunks:
- All chunks share the request's
runId. Zetect adds each chunk's records to the run as it arrives. - Zetect finishes the run when it receives a chunk whose
lastChunkistrue. It also accepts the keyisFinalChunkfor the same purpose. A result with neither key is treated as the only, and so the final, chunk. - Even an empty result set must publish one chunk with
lastChunkset totrue, or the run never completes. - A result with
successset tofalseends the run as failed at once, even if more chunks were expected.
How Zetect uses the result
| Result | What Zetect does |
|---|---|
| Account records (SYNC_USER) | Identifies each account by the application's identity attribute, the account identityAttribute in the provisioning XML. If the record lacks it, Zetect tries uid, cn, distinguishedName, dn, nativeIdentifier, then id. Records with none of these are skipped. Other keys become account attributes, filtered by the application's account attribute list. |
| Group records (SYNC_GROUP) | Identifies each group the same way, trying cn, distinguishedName, dn, nativeIdentifier, then id as fallbacks. Takes the display name from displayName, cn or name. If a record has an objectType that matches a group block in the provisioning XML, that block's identityAttribute is used instead. |
| status | SUCCESS completes the request. ERROR marks it failed and shows message to administrators in the provisioning activity. |
| nativeAccountIdentifier | Required on success for CREATE_ACCOUNT, ADD_TO_GROUP and the other account actions. Zetect uses it to find or create the account and link it to the identity. Return the same value aggregation reports for that account. |
| accountDisplayName | Becomes the account's display name in Zetect when present. |
| attributeMappings | Echoed from the request by default. On a successful CREATE_ACCOUNT, Zetect stores these values as the new account's attributes, so you may replace them with a fresh read of the account from the target. |
Exchange, routing keys and headers
| Result | Exchange | Routing key | Message headers |
|---|---|---|---|
| ConnectorResult for IDENTITY_SYNC | cyiam.agent | import.outbound.<tenantId> | x-run-id, x-connector-name, x-action |
| ConnectorResult for SYNC_USER and SYNC_GROUP | cyiam.agent | prov.outbound.<tenantId> | x-run-id, x-connector-name, x-action |
| ProvisioningResult | cyiam.agent | prov.outbound.<tenantId> | x-request-id, x-status |
The agent sets all of these. Your connector never publishes to the broker directly.
Troubleshooting
| Symptom | Likely cause |
|---|---|
| Aggregation stays running | No chunk had lastChunk set to true, or nothing was published for an empty result. |
| Accounts deactivated after an aggregation | The connector published a successful last chunk without returning every account, for example after a paging error. |
| Provisioning succeeds but no account appears | The success result had no nativeAccountIdentifier. |
| After aggregation, a second account appears and the provisioned one turns inactive | The nativeAccountIdentifier returned on provisioning differs from the identity attribute value aggregation reports. |
