use of org.ovirt.engine.core.bll.job.ExecutionContext 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.job.ExecutionContext in project ovirt-engine by oVirt.
the class AddVdsCommand method executeCommand.
@Override
protected void executeCommand() {
Guid oVirtId = getParameters().getVdsForUniqueId();
if (oVirtId != null) {
// if fails to remove deprecated entry, we might attempt to add new oVirt host with an existing unique-id.
if (!removeDeprecatedOvirtEntry(oVirtId)) {
log.error("Failed to remove duplicated oVirt entry with id '{}'. Abort adding oVirt Host type", oVirtId);
throw new EngineException(EngineError.HOST_ALREADY_EXISTS);
}
}
completeOpenstackNetworkProviderId();
TransactionSupport.executeInNewTransaction(() -> {
addVdsStaticToDb();
addVdsDynamicToDb();
addVdsStatisticsToDb();
addAffinityLabels();
getCompensationContext().stateChanged();
return null;
});
if (getParameters().isProvisioned()) {
HostProviderProxy proxy = providerProxyFactory.create(getHostProvider());
proxy.provisionHost(getParameters().getvds(), getParameters().getHostGroup(), getParameters().getComputeResource(), getParameters().getHostMac(), getParameters().getDiscoverName(), getParameters().getPassword(), getParameters().getDiscoverIp());
addCustomValue("HostGroupName", getParameters().getHostGroup().getName());
auditLogDirector.log(this, AuditLogType.VDS_PROVISION);
}
// set vds spm id
if (getCluster().getStoragePoolId() != null) {
VdsActionParameters tempVar = new VdsActionParameters(getVdsIdRef());
tempVar.setSessionId(getParameters().getSessionId());
tempVar.setCompensationEnabled(true);
ActionReturnValue addVdsSpmIdReturn = runInternalAction(ActionType.AddVdsSpmId, tempVar, cloneContext().withoutLock().withoutExecutionContext());
if (!addVdsSpmIdReturn.getSucceeded()) {
setSucceeded(false);
getReturnValue().setFault(addVdsSpmIdReturn.getFault());
return;
}
}
TransactionSupport.executeInNewTransaction(() -> {
initializeVds(true);
alertIfPowerManagementNotConfigured(getParameters().getVdsStaticData());
testVdsPowerManagementStatus(getParameters().getVdsStaticData());
setSucceeded(true);
setActionReturnValue(getVdsIdRef());
// If the installation failed, we don't want to compensate for the failure since it will remove the
// host, but instead the host should be left in an "install failed" status.
getCompensationContext().cleanupCompensationDataAfterSuccessfulCommand();
return null;
});
// clients). they are installed as part of the approve process or automatically after provision
if (Config.<Boolean>getValue(ConfigValues.InstallVds) && !getParameters().isPending() && !getParameters().isProvisioned()) {
final InstallVdsParameters installVdsParameters = new InstallVdsParameters(getVdsId(), getParameters().getPassword());
installVdsParameters.setAuthMethod(getParameters().getAuthMethod());
installVdsParameters.setOverrideFirewall(getParameters().getOverrideFirewall());
installVdsParameters.setActivateHost(getParameters().getActivateHost());
installVdsParameters.setNetworkProviderId(getParameters().getVdsStaticData().getOpenstackNetworkProviderId());
installVdsParameters.setNetworkMappings(getParameters().getNetworkMappings());
installVdsParameters.setEnableSerialConsole(getParameters().getEnableSerialConsole());
if (getParameters().getHostedEngineDeployConfiguration() != null) {
Map<String, String> vdsDeployParams = hostedEngineHelper.createVdsDeployParams(getVdsId(), getParameters().getHostedEngineDeployConfiguration().getDeployAction());
installVdsParameters.setHostedEngineConfiguration(vdsDeployParams);
}
Map<String, String> values = new HashMap<>();
values.put(VdcObjectType.VDS.name().toLowerCase(), getParameters().getvds().getName());
Step installStep = executionHandler.addSubStep(getExecutionContext(), getExecutionContext().getJob().getStep(StepEnum.EXECUTING), StepEnum.INSTALLING_HOST, ExecutionMessageDirector.resolveStepMessage(StepEnum.INSTALLING_HOST, values));
final ExecutionContext installCtx = new ExecutionContext();
installCtx.setJob(getExecutionContext().getJob());
installCtx.setStep(installStep);
installCtx.setMonitored(true);
installCtx.setShouldEndJob(true);
ThreadPoolUtil.execute(() -> runInternalAction(ActionType.InstallVdsInternal, installVdsParameters, cloneContextAndDetachFromParent().withExecutionContext(installCtx)));
ExecutionHandler.setAsyncJob(getExecutionContext(), true);
}
}
use of org.ovirt.engine.core.bll.job.ExecutionContext in project ovirt-engine by oVirt.
the class GlusterTaskUtils method endStepJob.
public void endStepJob(Step step) {
jobRepository.updateStep(step);
ExecutionContext finalContext = executionHandler.createFinalizingContext(step.getId());
executionHandler.endTaskStepAndJob(finalContext, isTaskSuccess(step.getStatus()));
}
use of org.ovirt.engine.core.bll.job.ExecutionContext in project ovirt-engine by oVirt.
the class CreateGlusterVolumeCommand method createCommandContext.
/**
* Creates command context for setting a given option on the given volume
*/
private CommandContext createCommandContext(GlusterVolumeEntity volume, GlusterVolumeOptionEntity option) {
// Add sub-step for setting given option
Step setOptionStep = addSubStep(StepEnum.EXECUTING, StepEnum.SETTING_GLUSTER_OPTION, getOptionValues(volume, option));
// Create execution context for setting option
ExecutionContext setOptionCtx = new ExecutionContext();
setOptionCtx.setMonitored(true);
setOptionCtx.setStep(setOptionStep);
return cloneContext().withExecutionContext(setOptionCtx).withoutLock();
}
use of org.ovirt.engine.core.bll.job.ExecutionContext in project ovirt-engine by oVirt.
the class RunVmCommand method createContextForStatelessSnapshotCreation.
private CommandContext createContextForStatelessSnapshotCreation() {
Map<String, String> values = getVmValuesForMsgResolving();
// Creating snapshots as sub step of run stateless
Step createSnapshotsStep = addSubStep(StepEnum.EXECUTING, StepEnum.CREATING_SNAPSHOTS, values);
// Add the step as the first step of the new context
ExecutionContext createSnapshotsCtx = new ExecutionContext();
createSnapshotsCtx.setMonitored(true);
createSnapshotsCtx.setStep(createSnapshotsStep);
getContext().withExecutionContext(createSnapshotsCtx);
persistCommandIfNeeded();
return getContext().clone().withoutCompensationContext();
}
Aggregations