use of org.opencastproject.util.data.Effect0 in project opencast by opencast.
the class SchedulerServiceImpl method removeTransactionsAfterRestart.
/**
* Remove incomplete transactions after a restart
*/
private void removeTransactionsAfterRestart() {
logger.info("Checking for incomplete transactions from a shutdown or restart.");
for (final Organization org : orgDirectoryService.getOrganizations()) {
SecurityUtil.runAs(securityService, org, SecurityUtil.createSystemUser(systemUserName, org), new Effect0() {
private void rollbackTransaction(String transactionID) throws NotFoundException, UnauthorizedException, SchedulerException {
SchedulerTransaction transaction = getTransaction(transactionID);
logger.info("Rolling back transaction with id: {}", transactionID);
transaction.rollback();
logger.info("Finished rolling back transaction with id: {}", transactionID);
}
@Override
protected void run() {
try {
for (String transactionID : persistence.getTransactions()) {
try {
rollbackTransaction(transactionID);
} catch (NotFoundException e) {
logger.info("Unable to find the transaction with id {}, so it wasn't rolled back.", transactionID);
} catch (UnauthorizedException e) {
logger.error("Unable to delete transaction with id: {} using organization {} because: {}", new Object[] { transactionID, org, getStackTrace(e) });
} catch (Exception e) {
logger.error("Unable to rollback transaction because: {}", getStackTrace(e));
}
}
} catch (SchedulerServiceDatabaseException e) {
logger.error("Unable to get transactions to cleanup incomplete transactions because: {}", getStackTrace(e));
}
}
});
}
logger.info("Finished checking for incomplete transactions from a shutdown or a restart.");
}
use of org.opencastproject.util.data.Effect0 in project opencast by opencast.
the class WorkflowServiceImpl method repopulate.
@Override
public void repopulate(final String indexName) throws Exception {
List<String> workflows = serviceRegistry.getJobPayloads(Operation.START_WORKFLOW.toString());
final String destinationId = WorkflowItem.WORKFLOW_QUEUE_PREFIX + indexName.substring(0, 1).toUpperCase() + indexName.substring(1);
if (workflows.size() > 0) {
final int total = workflows.size();
logger.info("Populating index '{}' with {} workflows", indexName, total);
final int responseInterval = (total < 100) ? 1 : (total / 100);
int current = 0;
for (final String workflow : workflows) {
current += 1;
if (StringUtils.isEmpty(workflow)) {
logger.warn("Skipping restoring of workflow no {}: Payload is empty", current);
continue;
}
WorkflowInstance instance;
try {
instance = WorkflowParser.parseWorkflowInstance(workflow);
} catch (WorkflowParsingException e) {
logger.warn("Skipping restoring of workflow. Error parsing: {}", workflow, e);
continue;
}
Organization organization = instance.getOrganization();
SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(componentContext, organization), new Effect0() {
@Override
public void run() {
// Send message to update index item
messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, WorkflowItem.updateInstance(instance));
}
});
if ((current % responseInterval == 0) || (current == total)) {
logger.info("Updating {} workflow index {}/{}: {} percent complete.", indexName, current, total, current * 100 / total);
}
}
}
logger.info("Finished populating {} index with workflows", indexName);
Organization organization = new DefaultOrganization();
SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(componentContext, organization), new Effect0() {
@Override
protected void run() {
messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.end(indexName, IndexRecreateObject.Service.Workflow));
}
});
}
Aggregations