use of org.ovirt.engine.core.common.businessentities.CommandEntity in project ovirt-engine by oVirt.
the class ChildCommandsCallbackBase method shouldWaitForEndMethodsCompletion.
private boolean shouldWaitForEndMethodsCompletion(CommandBase<?> childCommand, CommandBase<?> parentCommand) {
CommandEntity cmdEntity = commandCoordinatorUtil.getCommandEntity(childCommand.getCommandId());
boolean hasNotifiedCallback = cmdEntity.isCallbackEnabled() && cmdEntity.isCallbackNotified();
if (shouldCommandEndOnAsyncOpEnd(childCommand) && !hasNotifiedCallback) {
logWaitingForChildCommand(childCommand, parentCommand);
return true;
}
return false;
}
use of org.ovirt.engine.core.common.businessentities.CommandEntity in project ovirt-engine by oVirt.
the class CommandCallbacksPoller method invokeCallbackMethodsImpl.
private void invokeCallbackMethodsImpl() {
Iterator<Entry<Guid, CallbackTiming>> iterator = commandsRepository.getCallbacksTiming().entrySet().iterator();
while (iterator.hasNext()) {
Entry<Guid, CallbackTiming> entry = iterator.next();
Guid cmdId = entry.getKey();
CallbackTiming callbackTiming = entry.getValue();
CommandEntity commandEntity = commandsRepository.getCommandEntity(cmdId);
CorrelationIdTracker.setCorrelationId(commandEntity != null ? commandEntity.getCommandParameters().getCorrelationId() : null);
if (commandEntity != null && updateCommandWaitingForEvent(commandEntity, callbackTiming)) {
continue;
}
// Decrement counter; execute if it reaches 0
callbackTiming.setRemainingDelay(callbackTiming.getRemainingDelay() - pollingRate);
if (callbackTiming.getRemainingDelay() > 0) {
continue;
}
CommandCallback callback = callbackTiming.getCallback();
CommandStatus status = commandsRepository.getCommandStatus(cmdId);
boolean runCallbackAgain = false;
boolean errorInCallback = false;
try {
switch(status) {
case FAILED:
case SUCCEEDED:
runCallbackAgain = endCallback(cmdId, callback, status);
break;
case ACTIVE:
if (commandEntity != null && commandEntity.isExecuted()) {
callback.doPolling(cmdId, getChildCommandIds(cmdId));
}
break;
case EXECUTION_FAILED:
if (callback.pollOnExecutionFailed()) {
callback.doPolling(cmdId, getChildCommandIds(cmdId));
}
break;
default:
break;
}
} catch (Exception ex) {
errorInCallback = true;
handleError(ex, status, cmdId);
} finally {
if ((CommandStatus.FAILED == status || (CommandStatus.SUCCEEDED == status && !errorInCallback)) && !runCallbackAgain) {
commandsRepository.updateCallbackNotified(cmdId);
iterator.remove();
CommandEntity cmdEntity = commandsRepository.getCommandEntity(entry.getKey());
if (cmdEntity != null) {
// When a child finishes, its parent's callback should execute shortly thereafter
CallbackTiming rootCmdContainer = commandsRepository.getCallbackTiming(cmdEntity.getRootCommandId());
if (rootCmdContainer != null) {
rootCmdContainer.setInitialDelay(pollingRate);
rootCmdContainer.setRemainingDelay(pollingRate);
}
}
} else if (status != commandsRepository.getCommandStatus(cmdId)) {
callbackTiming.setInitialDelay(pollingRate);
callbackTiming.setRemainingDelay(pollingRate);
} else {
long maxDelay = Config.<Long>getValue(ConfigValues.AsyncCommandPollingRateInSeconds);
callbackTiming.setInitialDelay(Math.min(maxDelay, callbackTiming.getInitialDelay() * 2));
callbackTiming.setRemainingDelay(callbackTiming.getInitialDelay());
}
}
}
CorrelationIdTracker.setCorrelationId(null);
commandsRepository.markExpiredCommandsAsFailure();
}
use of org.ovirt.engine.core.common.businessentities.CommandEntity in project ovirt-engine by oVirt.
the class CommandsCacheImpl method updateCommandExecuted.
@Override
public void updateCommandExecuted(final Guid commandId) {
CommandEntity cmdEntity = get(commandId);
if (cmdEntity != null) {
cmdEntity.setExecuted(true);
commandEntityDao.updateExecuted(commandId);
}
}
use of org.ovirt.engine.core.common.businessentities.CommandEntity in project ovirt-engine by oVirt.
the class CommandsRepository method persistCommand.
public void persistCommand(CommandEntity cmdEntity) {
if (Guid.isNullOrEmpty(cmdEntity.getId())) {
return;
}
CommandEntity existingCmdEntity = commandsCache.get(cmdEntity.getId());
if (existingCmdEntity != null) {
cmdEntity.setExecuted(existingCmdEntity.isExecuted());
cmdEntity.setCallbackNotified(existingCmdEntity.isCallbackNotified());
}
commandsCache.put(cmdEntity);
// check if callback is enabled or if parent command has callback enabled
if (cmdEntity.isCallbackEnabled() || (!Guid.isNullOrEmpty(cmdEntity.getParentCommandId()) && commandsCache.get(cmdEntity.getParentCommandId()) != null && commandsCache.get(cmdEntity.getParentCommandId()).isCallbackEnabled())) {
buildCmdHierarchy(cmdEntity);
if (!cmdEntity.isCallbackNotified()) {
addToCallbackMap(cmdEntity);
}
}
}
use of org.ovirt.engine.core.common.businessentities.CommandEntity in project ovirt-engine by oVirt.
the class CommandsRepository method getCommands.
/**
* @param onlyWithCallbackEnabled Specifies if the returned commands' callbacks are enabled or not.
* @return Returns commands with callback enabled or disabled, based on given parameter
*/
public List<CommandEntity> getCommands(boolean onlyWithCallbackEnabled) {
List<CommandEntity> cmdEntities = new ArrayList<>();
CommandEntity cmdEntity;
for (Guid cmdId : commandsCache.keySet()) {
cmdEntity = commandsCache.get(cmdId);
if (!onlyWithCallbackEnabled || commandsCache.get(cmdId).isCallbackEnabled()) {
cmdEntities.add(cmdEntity);
}
}
return cmdEntities;
}
Aggregations