ClassPool pool = ClassPoolFactory.getClassPoolForCurrentContextClassLoader();
Configuration parameters = ConfigurationClassBuilder.translateParametersToConfig(pool,
definition.getParametersConfigurationDefinition(), args);
OperationManagerRemote operationManager = remoteClient.getProxy(OperationManagerRemote.class);
ResourceOperationSchedule schedule = operationManager.scheduleResourceOperation(remoteClient.getSubject(),
resourceId, definition.getName(), 0, 0, 0, 30000, parameters, "Executed from commandline");
ResourceOperationHistoryCriteria criteria = new ResourceOperationHistoryCriteria();
criteria.addFilterJobId(schedule.getJobId());
criteria.addFilterResourceIds(resourceId);
criteria.addSortStartTime(PageOrdering.DESC); // put most recent at top of results
criteria.setPaging(0, 1); // only return one result, in effect the latest
criteria.fetchOperationDefinition(true);
criteria.fetchParameters(true);
criteria.fetchResults(true);
int retries = 10;
ResourceOperationHistory history = null;
while (history == null && retries-- > 0) {
Thread.sleep(1000);
PageList<ResourceOperationHistory> histories = operationManager
.findResourceOperationHistoriesByCriteria(remoteClient.getSubject(), criteria);
if (histories.size() > 0 && histories.get(0).getStatus() != OperationRequestStatus.INPROGRESS) {
history = histories.get(0);
}
}