use of org.ovirt.engine.core.bll.context.EngineContext 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.EngineContext 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.EngineContext 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.EngineContext in project ovirt-engine by oVirt.
the class ImportHostedEngineStorageDomainCommandTest method prepareCommand.
protected void prepareCommand() {
parameters.setStoragePoolId(HE_SP_ID);
parameters.setVdsId(HE_VDS_ID);
parameters.setStorageDomainId(HE_SD_ID);
// vds
VDS vds = new VDS();
vds.setId(Guid.Empty);
vds.setStoragePoolId(HE_SP_ID);
when(vdsDao.get(any())).thenReturn(vds);
List<BaseDisk> baseDisks = Collections.singletonList(new BaseDisk());
when(baseDiskDao.getDisksByAlias(any())).thenReturn(baseDisks);
// Data center
StoragePool pool = new StoragePool();
pool.setStatus(StoragePoolStatus.Up);
pool.setId(HE_SP_ID);
when(storagePoolDao.get(HE_SP_ID)).thenReturn(pool);
// compensation
CompensationContext compensationContext = mock(CompensationContext.class);
when(cmd.getCompensationContext()).thenReturn(compensationContext);
when(cmd.getContext()).thenReturn(new CommandContext(new EngineContext()));
}
use of org.ovirt.engine.core.bll.context.EngineContext in project ovirt-engine by oVirt.
the class VMConsoleProxyServlet method availableConsoles.
private List<Map<String, String>> availableConsoles(String userIdAsString) {
List<Map<String, String>> jsonVms = new ArrayList<>();
Guid userGuid = null;
try {
if (StringUtils.isNotEmpty(userIdAsString)) {
userGuid = Guid.createGuidFromString(userIdAsString);
}
} catch (IllegalArgumentException e) {
log.debug("Could not read User GUID");
}
if (userGuid != null) {
ActionReturnValue loginResult = backend.runInternalAction(ActionType.LoginOnBehalf, new LoginOnBehalfParameters(userGuid));
if (!loginResult.getSucceeded()) {
throw new RuntimeException("Unable to create session using LoginOnBehalf");
}
String engineSessionId = loginResult.getActionReturnValue();
try {
QueryReturnValue retVms = backend.runInternalQuery(QueryType.GetAllVmsForUserAndActionGroup, new GetEntitiesWithPermittedActionParameters(ActionGroup.CONNECT_TO_SERIAL_CONSOLE), new EngineContext().withSessionId(engineSessionId));
if (retVms != null) {
List<VM> vmsList = retVms.getReturnValue();
for (VM vm : vmsList) {
Map<String, String> jsonVm = new HashMap<>();
if (vm.getRunOnVds() != null) {
// TODO: avoid one query per loop. Bulk query?
QueryReturnValue retValue = backend.runInternalQuery(QueryType.GetVdsByVdsId, new IdQueryParameters(vm.getRunOnVds()));
if (retValue != null && retValue.getReturnValue() != null) {
VDS vds = retValue.getReturnValue();
jsonVm.put("vmid", vm.getId().toString());
jsonVm.put("vmname", vm.getName());
jsonVm.put("host", vds.getHostName());
/* there is only one serial console, no need and no way to distinguish them */
jsonVm.put("console", "default");
jsonVms.add(jsonVm);
}
}
}
}
} finally {
backend.runInternalAction(ActionType.LogoutSession, new ActionParametersBase(engineSessionId));
}
}
return jsonVms;
}
Aggregations