use of org.ovirt.engine.core.common.businessentities.AsyncTaskStatus in project ovirt-engine by oVirt.
the class SpmStartVDSCommand method executeVdsBrokerCommand.
@Override
protected void executeVdsBrokerCommand() {
result = getBroker().spmStart(getParameters().getStoragePoolId().toString(), getParameters().getPrevId(), getParameters().getPrevLVER(), getParameters().getRecoveryMode().getValue(), String.valueOf(getParameters().getSCSIFencing()).toLowerCase(), Config.getValue(ConfigValues.MaxNumberOfHostsInStoragePool), getParameters().getStoragePoolFormatType().getValue());
proceedProxyReturnValue();
Guid taskId = new Guid(result.uuid);
AsyncTaskStatus taskStatus;
log.info("spmStart polling started: taskId '{}'", taskId);
do {
// TODO: make configurable
ThreadUtils.sleep(1000L);
taskStatus = (AsyncTaskStatus) resourceManager.runVdsCommand(VDSCommandType.HSMGetTaskStatus, new HSMTaskGuidBaseVDSCommandParameters(vdsId, taskId)).getReturnValue();
log.debug("spmStart polling - task status: '{}'", taskStatus.getStatus());
} while (taskStatus.getStatus() != AsyncTaskStatusEnum.finished && taskStatus.getStatus() != AsyncTaskStatusEnum.unknown);
log.info("spmStart polling ended: taskId '{}' task status '{}'", taskId, taskStatus.getStatus());
if (!taskStatus.getTaskEndedSuccessfully()) {
log.error("Start SPM Task failed - result: '{}', message: {}", taskStatus.getResult(), taskStatus.getMessage());
}
SpmStatusResult spmStatus = (SpmStatusResult) resourceManager.runVdsCommand(VDSCommandType.SpmStatus, new SpmStatusVDSCommandParameters(vdsId, getParameters().getStoragePoolId())).getReturnValue();
if (spmStatus != null) {
log.info("spmStart polling ended, spm status: {}", spmStatus.getSpmStatus());
} else {
log.error("spmStart polling ended, failed to get the spm status");
}
try {
resourceManager.runVdsCommand(VDSCommandType.HSMClearTask, new HSMTaskGuidBaseVDSCommandParameters(vdsId, taskId));
} catch (Exception e) {
log.error("Could not clear spmStart task '{}', continuing with SPM selection: {}", taskId, e.getMessage());
log.debug("Exception", e);
}
setReturnValue(spmStatus);
}
use of org.ovirt.engine.core.common.businessentities.AsyncTaskStatus in project ovirt-engine by oVirt.
the class HSMGetAllTasksStatusesVDSCommand method parseTaskStatusList.
protected HashMap<Guid, AsyncTaskStatus> parseTaskStatusList(Map<String, ?> taskStatusList) {
HashMap<Guid, AsyncTaskStatus> result = new HashMap<>(taskStatusList.size());
for (Map.Entry<String, ?> entry : taskStatusList.entrySet()) {
try {
Guid taskGuid = new Guid(entry.getKey().toString());
Map<String, Object> xrsTaskStatusAsMAp = (Map<String, Object>) entry.getValue();
if (xrsTaskStatusAsMAp == null) {
log.error("Task ID {} has no task data", entry.getKey());
} else {
Map<String, Object> xrsTaskStatus = xrsTaskStatusAsMAp;
TaskStatus tempVar = new TaskStatus();
tempVar.code = Integer.parseInt(xrsTaskStatus.get("code").toString());
tempVar.message = xrsTaskStatus.get("message").toString();
tempVar.taskResult = xrsTaskStatus.get("taskResult").toString();
tempVar.taskState = xrsTaskStatus.get("taskState").toString();
TaskStatus taskStatus = tempVar;
AsyncTaskStatus task = parseTaskStatus(taskStatus);
result.put(taskGuid, task);
}
} catch (RuntimeException exp) {
log.error("HSMGetAllTasksStatusesVDSCommand: Ignoring error while parsing task status from list. key: '{}', value: '{}': {}", entry.getKey(), entry.getValue(), exp.getMessage());
log.debug("Exception", exp);
}
}
return result;
}
use of org.ovirt.engine.core.common.businessentities.AsyncTaskStatus in project ovirt-engine by oVirt.
the class HSMGetAllTasksStatusesVDSCommand method parseTaskStatus.
protected AsyncTaskStatus parseTaskStatus(TaskStatus taskStatus) {
AsyncTaskStatus task = new AsyncTaskStatus();
task.setStatus((taskStatus != null && taskStatus.taskState != null) ? AsyncTaskStatusEnum.valueOf(taskStatus.taskState) : AsyncTaskStatusEnum.unknown);
if (task.getStatus() == AsyncTaskStatusEnum.finished) {
updateReturnStatus(taskStatus);
try {
proceedProxyReturnValue();
} catch (RuntimeException ex) {
task.setException(ex);
}
task.setResult(taskStatus != null ? AsyncTaskResultEnum.valueOf(taskStatus.taskResult) : AsyncTaskResultEnum.unknown);
// we throw a special one here:
if (task.getResult() != AsyncTaskResultEnum.success && task.getException() == null) {
task.setException(new VDSTaskResultNotSuccessException(String.format("TaskState contained successful return code, but a non-success result ('%1$s').", taskStatus.taskResult)));
}
}
return task;
}
use of org.ovirt.engine.core.common.businessentities.AsyncTaskStatus in project ovirt-engine by oVirt.
the class BackendVmDisksResourceTest method testAddDiskWithinStorageDomain.
@Test
public void testAddDiskWithinStorageDomain() throws Exception {
setUriInfo(setUpBasicUriExpectations());
setUpHttpHeaderExpectations("Expect", "201-created");
setUpGetDiskExpectations();
setUpEntityQueryExpectations(QueryType.GetStorageDomainById, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[3] }, getStorageDomain(GUIDS[3]));
setUpCreationExpectations(ActionType.AddDisk, AddDiskParameters.class, new String[] { "VmId", "StorageDomainId" }, new Object[] { VM_ID, GUIDS[3] }, true, true, GUIDS[0], asList(GUIDS[3]), asList(new AsyncTaskStatus(AsyncTaskStatusEnum.finished)), QueryType.GetDiskByDiskId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { DISK_ID }, asList(getEntity(0)));
Disk model = getModel();
model.setStorageDomains(new StorageDomains());
StorageDomain storageDomain = new StorageDomain();
storageDomain.setId(GUIDS[3].toString());
model.getStorageDomains().getStorageDomains().add(storageDomain);
model.setProvisionedSize(1024 * 1024L);
Response response = collection.add(model);
assertEquals(201, response.getStatus());
assertTrue(response.getEntity() instanceof Disk);
verifyModel((Disk) response.getEntity(), 0);
assertNull(((Disk) response.getEntity()).getCreationStatus());
}
use of org.ovirt.engine.core.common.businessentities.AsyncTaskStatus in project ovirt-engine by oVirt.
the class BackendVmDisksResourceTest method doTestAddAsync.
private void doTestAddAsync(AsyncTaskStatusEnum asyncStatus, CreationStatus creationStatus) throws Exception {
setUriInfo(setUpBasicUriExpectations());
setUpEntityQueryExpectations(QueryType.GetStorageDomainById, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[2] }, getStorageDomain(GUIDS[2]));
setUpCreationExpectations(ActionType.AddDisk, AddDiskParameters.class, new String[] { "VmId" }, new Object[] { VM_ID }, true, true, GUIDS[0], asList(GUIDS[3]), asList(new AsyncTaskStatus(asyncStatus)), QueryType.GetDiskByDiskId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { DISK_ID }, asList(getEntity(0)));
Disk model = getModel();
model.setProvisionedSize(1024 * 1024L);
Response response = collection.add(model);
assertEquals(202, response.getStatus());
assertTrue(response.getEntity() instanceof Disk);
verifyModel((Disk) response.getEntity(), 0);
Disk created = (Disk) response.getEntity();
assertNotNull(created.getCreationStatus());
assertEquals(creationStatus.value(), created.getCreationStatus());
}
Aggregations