@Override
public void addIndexer(IndexerDefinition indexer)
throws IndexerExistsException, IndexerModelException, IndexerValidityException {
assertValid(indexer);
if (indexer.getIncrementalIndexingState() != IndexerDefinition.IncrementalIndexingState.DO_NOT_SUBSCRIBE) {
indexer = new IndexerDefinitionBuilder().startFrom(indexer).subscriptionTimestamp(System.currentTimeMillis()).build();
}
final String indexerPath = indexerCollectionPath + "/" + indexer.getName();
final byte[] data = IndexerDefinitionJsonSerDeser.INSTANCE.toJsonBytes(indexer);
try {
zk.retryOperation(new ZooKeeperOperation<String>() {
@Override
public String execute() throws KeeperException, InterruptedException {
return zk.create(indexerPath, data, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
});
} catch (KeeperException.NodeExistsException e) {
throw new IndexerExistsException(indexer.getName());
} catch (Exception e) {
throw new IndexerModelException("Error creating indexer.", e);
}
}