SailPoint IIQ - Create Identity Bulk Operation
How to properly process many IdentityIQ objects in a run rule task
Sometimes, all you need is to update many objects in IIQ, for example, you want to change some attribute, let's say, hundreds of thousands of them.
Because IIQ uses hibernate, you can't just bring all objects into memory at once, or if you do, you can't let them stay in the object cache.
So this code snippet shows how to properly split this task into smaller transaction chunks.
Please notice that the debug's "run rule" feature is subject to the UI timeout for a synchronous request.
So in order to run a long-running task, create a "Run Rule" task and execute it in background.
import sailpoint.api.SailPointContext;
import sailpoint.api.SailPointFactory;
import sailpoint.object.Identity;
import sailpoint.object.QueryOptions;
import sailpoint.spring.SpringStarter;
import sailpoint.tools.GeneralException;
import java.util.Iterator;
public class IdentityCreationBulk {
private static final String IIQ_BEANS = "iiqBeans";
private static final String ATTR_PARTNER = "partner";
private static final String ATTR_TYPE = "type";
private static final String ID = "id";
private static final int BULK_RECORD_COUNT = 500;
public static void main(String[] args) throws GeneralException {
SpringStarter starter = null;
SailPointContext context = null;
try {
starter = new SpringStarter(IIQ_BEANS);
starter.start();
context = SailPointFactory.createContext();
// ------------------- [START]
System.out.println("--------------------------");
bulkCreateIdentity(context);
System.out.println("--------------------------");
// ------------------- [END]
} catch (GeneralException e) {
e.printStackTrace();
} finally {
if (null != context) {
try {
SailPointFactory.releaseContext(context);
} catch (GeneralException e) {
e.printStackTrace();
}
}
if (null != starter) {
starter.close();
}
}
}
private static void bulkCreateIdentity(SailPointContext context) throws GeneralException {
int count = context.countObjects(Identity.class, null);
QueryOptions queryOptions = new QueryOptions();
queryOptions.addOrdering(ID, true);
int slices = count / BULK_RECORD_COUNT;
if (slices == 0) {
Iterator<Identity> identityIterator = context.search(Identity.class, queryOptions);
while (identityIterator.hasNext()) {
Identity i = identityIterator.next();
i.setAttribute(ATTR_TYPE, ATTR_PARTNER);
context.saveObject(i);
}
context.commitTransaction();
context.decache();
} else {
for (int j = 0; j < slices; j++) {
queryOptions.setFirstRow(j * BULK_RECORD_COUNT);
queryOptions.setResultLimit(BULK_RECORD_COUNT);
Iterator<Identity> it = context.search(Identity.class, queryOptions);
while (it.hasNext()) {
Identity i = it.next();
i.setAttribute(ATTR_TYPE, ATTR_PARTNER);
context.saveObject(i);
}
context.commitTransaction();
context.decache();
}
}
}
}
Comments
Post a Comment