use of org.ovirt.engine.core.bll.context.CommandContext in project ovirt-engine by oVirt.
the class ExportOvaCommand method createOvaCreationStepContext.
protected CommandContext createOvaCreationStepContext() {
CommandContext commandCtx = null;
StepEnum step = StepEnum.CREATING_OVA;
try {
Step ovaCreationStep = executionHandler.addSubStep(getExecutionContext(), getExecutionContext().getJob().getStep(StepEnum.EXECUTING), step, ExecutionMessageDirector.resolveStepMessage(step, Collections.emptyMap()));
ExecutionContext ctx = new ExecutionContext();
ctx.setStep(ovaCreationStep);
ctx.setMonitored(true);
commandCtx = cloneContext().withoutCompensationContext().withExecutionContext(ctx).withoutLock();
} catch (RuntimeException e) {
log.error("Failed to create command context of creating OVA '{}': {}", getVmName(), e.getMessage());
log.debug("Exception", e);
}
return commandCtx;
}
use of org.ovirt.engine.core.bll.context.CommandContext in project ovirt-engine by oVirt.
the class VdsEventListener method vdsUpEvent.
@Override
public boolean vdsUpEvent(final VDS vds) {
HostStoragePoolParametersBase params = new HostStoragePoolParametersBase(vds);
CommandContext commandContext = new CommandContext(new EngineContext()).withoutExecutionContext();
commandContext.getExecutionContext().setJobRequired(true);
boolean isSucceeded = backend.runInternalAction(ActionType.InitVdsOnUp, params, commandContext).getSucceeded();
if (isSucceeded) {
ThreadPoolUtil.execute(() -> {
try {
// migrate vms that its their default vds and failback
// is on
List<VmStatic> vmsToMigrate = vmStaticDao.getAllWithFailbackByVds(vds.getId());
if (!vmsToMigrate.isEmpty()) {
CommandContext ctx = new CommandContext(new EngineContext());
ctx.getExecutionContext().setMonitored(true);
backend.runInternalMultipleActions(ActionType.MigrateVmToServer, new ArrayList<>(createMigrateVmToServerParametersList(vmsToMigrate, vds, null)), ctx);
}
} catch (RuntimeException e) {
log.error("Failed to initialize Vds on up: {}", e.getMessage());
log.error("Exception", e);
}
});
}
return isSucceeded;
}
use of org.ovirt.engine.core.bll.context.CommandContext in project ovirt-engine by oVirt.
the class CommandContextsCacheImpl method buildCommandContext.
private CommandContext buildCommandContext(CommandEntity cmdEntity) {
ExecutionContext executionContext = new ExecutionContext();
PersistedCommandContext persistedCommandContext = cmdEntity.getCommandContext();
if (!Guid.isNullOrEmpty(persistedCommandContext.getJobId())) {
executionContext.setJob(jobRepository.getJobWithSteps(persistedCommandContext.getJobId()));
} else if (!Guid.isNullOrEmpty(persistedCommandContext.getStepId())) {
executionContext.setStep(jobRepository.getStep(persistedCommandContext.getStepId(), false));
}
executionContext.setExecutionMethod(persistedCommandContext.getExecutionMethod());
executionContext.setCompleted(persistedCommandContext.isCompleted());
executionContext.setJobRequired(persistedCommandContext.isJobRequired());
executionContext.setMonitored(persistedCommandContext.isMonitored());
executionContext.setShouldEndJob(persistedCommandContext.shouldEndJob());
executionContext.setTasksMonitored(persistedCommandContext.isTasksMonitored());
return new CommandContext(new EngineContext()).withExecutionContext(executionContext);
}
use of org.ovirt.engine.core.bll.context.CommandContext in project ovirt-engine by oVirt.
the class CommandsRepository method retrieveCommand.
private CommandBase<?> retrieveCommand(CommandEntity cmdEntity, CommandContext cmdContext) {
CommandBase<?> command = null;
if (cmdEntity != null) {
if (cmdContext == null) {
cmdContext = new CommandContext(new EngineContext()).withExecutionContext(new ExecutionContext());
}
command = CommandsFactory.createCommand(cmdEntity.getCommandType(), cmdEntity.getCommandParameters(), cmdContext);
if (command != null) {
command.setCommandStatus(cmdEntity.getCommandStatus(), false);
command.setCommandData(cmdEntity.getData());
command.setReturnValue(cmdEntity.getReturnValue());
if (!Guid.isNullOrEmpty(cmdEntity.getParentCommandId()) && !cmdEntity.getParentCommandId().equals(cmdEntity.getId()) && command.getParameters().getParentParameters() == null) {
CommandBase<?> parentCommand = retrieveCommand(cmdEntity.getParentCommandId());
if (parentCommand != null) {
command.getParameters().setParentParameters(parentCommand.getParameters());
}
}
}
}
return command;
}
use of org.ovirt.engine.core.bll.context.CommandContext in project ovirt-engine by oVirt.
the class InitVdsOnUpCommand method initializeStorage.
private boolean initializeStorage() {
boolean returnValue = false;
// connect any storage
if (getStoragePool() == null || StoragePoolStatus.Uninitialized == getStoragePool().getStatus() || StoragePoolStatus.Maintenance == getStoragePool().getStatus()) {
returnValue = true;
connectPoolSucceeded = true;
} else {
ConnectHostToStoragePoolServersParameters params = new ConnectHostToStoragePoolServersParameters(getStoragePool(), getVds());
CommandContext ctx = cloneContext();
ctx.getExecutionContext().setJobRequired(false);
runInternalAction(ActionType.ConnectHostToStoragePoolServers, params, ctx);
EventResult connectResult = connectHostToPool();
if (connectResult != null) {
returnValue = connectResult.isSuccess();
problematicDomains = (List<StorageDomainStatic>) connectResult.getResultData();
}
connectPoolSucceeded = returnValue;
}
return returnValue;
}
Aggregations