Zetect Connector Guide Back to zetect.inSwitch portal ⇄

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.

Applies to

Connector API io.cyiam:cyiam-connector-api version 1.4.0.

Limits

One result per request. For a chunked aggregation, one result per chunk, ending with exactly one chunk flagged as the last.

The publisher contract

PublisherPassed toRule
ConnectorPublisherhandle(): SYNC_USER, SYNC_GROUP, IDENTITY_SYNC and legacy actionsCall publish(ConnectorResult) exactly once, or once per chunk when the request asks for chunking.
ProvisioningPublisherhandleProvisioning(): every provisioning actionCall 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 methodUse 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

  1. Your method runs on one of the agent's worker threads.
  2. publish(result) runs synchronously on that same thread. When it returns, the message has been handed to the broker.
  3. The agent serialises the result to JSON. Fields that are null are left out.
  4. The agent publishes the message to the cyiam.agent exchange with the routing key for the channel the request came from.
  5. 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:

FieldValue
chunkIndexThe chunk's position, starting at 1.
chunkCountThe total number of chunks in the run.
lastChunktrue 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 lastChunk is true. It also accepts the key isFinalChunk for 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 lastChunk set to true, or the run never completes.
  • A result with success set to false ends the run as failed at once, even if more chunks were expected.

How Zetect uses the result

ResultWhat 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.
statusSUCCESS completes the request. ERROR marks it failed and shows message to administrators in the provisioning activity.
nativeAccountIdentifierRequired 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.
accountDisplayNameBecomes the account's display name in Zetect when present.
attributeMappingsEchoed 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

ResultExchangeRouting keyMessage headers
ConnectorResult for IDENTITY_SYNCcyiam.agentimport.outbound.<tenantId>x-run-id, x-connector-name, x-action
ConnectorResult for SYNC_USER and SYNC_GROUPcyiam.agentprov.outbound.<tenantId>x-run-id, x-connector-name, x-action
ProvisioningResultcyiam.agentprov.outbound.<tenantId>x-request-id, x-status

The agent sets all of these. Your connector never publishes to the broker directly.

Troubleshooting

SymptomLikely cause
Aggregation stays runningNo chunk had lastChunk set to true, or nothing was published for an empty result.
Accounts deactivated after an aggregationThe connector published a successful last chunk without returning every account, for example after a paging error.
Provisioning succeeds but no account appearsThe success result had no nativeAccountIdentifier.
After aggregation, a second account appears and the provisioned one turns inactiveThe nativeAccountIdentifier returned on provisioning differs from the identity attribute value aggregation reports.