Search in sources :

Example 6 with AsyncTaskStatus

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);
}
Also used : SpmStatusVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.SpmStatusVDSCommandParameters) SpmStatusResult(org.ovirt.engine.core.common.businessentities.SpmStatusResult) AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) Guid(org.ovirt.engine.core.compat.Guid) HSMTaskGuidBaseVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.HSMTaskGuidBaseVDSCommandParameters)

Example 7 with AsyncTaskStatus

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;
}
Also used : AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) HashMap(java.util.HashMap) Guid(org.ovirt.engine.core.compat.Guid) AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) Map(java.util.Map) HashMap(java.util.HashMap)

Example 8 with AsyncTaskStatus

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;
}
Also used : AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus)

Example 9 with AsyncTaskStatus

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());
}
Also used : Response(javax.ws.rs.core.Response) StorageDomain(org.ovirt.engine.api.model.StorageDomain) AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) StorageDomains(org.ovirt.engine.api.model.StorageDomains) Disk(org.ovirt.engine.api.model.Disk) Test(org.junit.Test)

Example 10 with AsyncTaskStatus

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());
}
Also used : Response(javax.ws.rs.core.Response) AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) Disk(org.ovirt.engine.api.model.Disk)

Aggregations

AsyncTaskStatus (org.ovirt.engine.core.common.businessentities.AsyncTaskStatus)41 Response (javax.ws.rs.core.Response)26 Test (org.junit.Test)15 Template (org.ovirt.engine.api.model.Template)12 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)9 Action (org.ovirt.engine.api.model.Action)7 Disk (org.ovirt.engine.api.model.Disk)7 Guid (org.ovirt.engine.core.compat.Guid)7 StorageDomain (org.ovirt.engine.api.model.StorageDomain)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 CreationStatus (org.ovirt.engine.api.model.CreationStatus)3 Vm (org.ovirt.engine.api.model.Vm)3 Collections (java.util.Collections)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 Fault (org.ovirt.engine.api.model.Fault)2 SPMTask (org.ovirt.engine.core.bll.tasks.interfaces.SPMTask)2 SpmStatusResult (org.ovirt.engine.core.common.businessentities.SpmStatusResult)2