Search in sources :

Example 21 with AsyncTaskStatus

use of org.ovirt.engine.core.common.businessentities.AsyncTaskStatus in project ovirt-engine by oVirt.

the class AsyncTaskManager method pollTasks.

public synchronized ArrayList<AsyncTaskStatus> pollTasks(ArrayList<Guid> vdsmTaskIdList) {
    ArrayList<AsyncTaskStatus> returnValue = new ArrayList<>();
    if (vdsmTaskIdList != null && vdsmTaskIdList.size() > 0) {
        for (Guid vdsmTaskId : vdsmTaskIdList) {
            if (tasks.containsKey(vdsmTaskId)) {
                // task is still running or is still in the cache:
                tasks.get(vdsmTaskId).setLastStatusAccessTime();
                returnValue.add(tasks.get(vdsmTaskId).getLastTaskStatus());
            } else {
                // task doesn't exist in the manager (shouldn't happen) ->
                // assume it has been ended successfully.
                log.warn("Polling tasks. Task ID '{}' doesn't exist in the manager -> assuming 'finished'.", vdsmTaskId);
                AsyncTaskStatus tempVar = new AsyncTaskStatus();
                tempVar.setStatus(AsyncTaskStatusEnum.finished);
                tempVar.setResult(AsyncTaskResultEnum.success);
                returnValue.add(tempVar);
            }
        }
    }
    return returnValue;
}
Also used : AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid)

Example 22 with AsyncTaskStatus

use of org.ovirt.engine.core.common.businessentities.AsyncTaskStatus in project ovirt-engine by oVirt.

the class CoCoAsyncTaskHelper method revertTasks.

public void revertTasks(CommandBase<?> command) {
    if (command.getParameters().getVdsmTaskIds() != null) {
        // list to send to the pollTasks method
        ArrayList<Guid> taskIdAsList = new ArrayList<>();
        for (Guid taskId : command.getParameters().getVdsmTaskIds()) {
            taskIdAsList.add(taskId);
            ArrayList<AsyncTaskStatus> tasksStatuses = asyncTaskManager.get().pollTasks(taskIdAsList);
            // call revert task only if ended successfully
            if (tasksStatuses.get(0).getTaskEndedSuccessfully()) {
                getBackend().getResourceManager().runVdsCommand(VDSCommandType.SPMRevertTask, new SPMTaskGuidBaseVDSCommandParameters(command.getStoragePool().getId(), taskId));
            }
            taskIdAsList.clear();
        }
    }
}
Also used : SPMTaskGuidBaseVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.SPMTaskGuidBaseVDSCommandParameters) AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid)

Example 23 with AsyncTaskStatus

use of org.ovirt.engine.core.common.businessentities.AsyncTaskStatus in project ovirt-engine by oVirt.

the class BackendDisksResourceTest method testAddIdentifyStorageDomainByName.

@Test
public void testAddIdentifyStorageDomainByName() throws Exception {
    setUriInfo(setUpBasicUriExpectations());
    setUpHttpHeaderExpectations("Expect", "201-created");
    setUpEntityQueryExpectations(QueryType.GetDiskByDiskId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, getEntity(0));
    setUpEntityQueryExpectations(QueryType.GetStorageDomainById, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[2] }, getStorageDomains().get(0));
    Disk model = getModel();
    model.getStorageDomains().getStorageDomains().get(0).setId(null);
    model.getStorageDomains().getStorageDomains().get(0).setName("Storage_Domain_1");
    setUpEntityQueryExpectations(QueryType.GetAllStorageDomains, QueryParametersBase.class, new String[] {}, new Object[] {}, getStorageDomains());
    setUpCreationExpectations(ActionType.AddDisk, AddDiskParameters.class, new String[] {}, new Object[] {}, true, true, GUIDS[0], asList(GUIDS[3]), asList(new AsyncTaskStatus(AsyncTaskStatusEnum.finished)), QueryType.GetDiskByDiskId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, getEntity(0));
    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) AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) Disk(org.ovirt.engine.api.model.Disk) Test(org.junit.Test)

Example 24 with AsyncTaskStatus

use of org.ovirt.engine.core.common.businessentities.AsyncTaskStatus in project ovirt-engine by oVirt.

the class BackendDisksResourceTest method testAdd.

@Test
public void testAdd() throws Exception {
    setUriInfo(setUpBasicUriExpectations());
    setUpHttpHeaderExpectations("Expect", "201-created");
    setUpEntityQueryExpectations(QueryType.GetDiskByDiskId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, getEntity(0));
    setUpEntityQueryExpectations(QueryType.GetStorageDomainById, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[2] }, getStorageDomains().get(0));
    Disk model = getModel();
    setUpCreationExpectations(ActionType.AddDisk, AddDiskParameters.class, new String[] { "StorageDomainId" }, new Object[] { GUIDS[2] }, true, true, GUIDS[0], asList(GUIDS[3]), asList(new AsyncTaskStatus(AsyncTaskStatusEnum.finished)), QueryType.GetDiskByDiskId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, getEntity(0));
    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) AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) Disk(org.ovirt.engine.api.model.Disk) Test(org.junit.Test)

Example 25 with AsyncTaskStatus

use of org.ovirt.engine.core.common.businessentities.AsyncTaskStatus in project ovirt-engine by oVirt.

the class BackendAttachedStorageDomainResourceTest method doTestActivateAsync.

private void doTestActivateAsync(AsyncTaskStatusEnum asyncStatus, CreationStatus actionStatus) throws Exception {
    setUriInfo(setUpActionExpectations(ActionType.ActivateStorageDomain, StorageDomainPoolParametersBase.class, new String[] { "StorageDomainId", "StoragePoolId" }, new Object[] { STORAGE_DOMAIN_ID, DATA_CENTER_ID }, asList(GUIDS[1]), asList(new AsyncTaskStatus(asyncStatus))));
    Response response = resource.activate(new Action());
    verifyActionResponse(response, "datacenters/" + DATA_CENTER_ID + "/storagedomains/" + STORAGE_DOMAIN_ID, true, null);
    Action action = (Action) response.getEntity();
    assertTrue(action.isSetStatus());
    assertEquals(actionStatus.value(), action.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) Action(org.ovirt.engine.api.model.Action) AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) StorageDomainPoolParametersBase(org.ovirt.engine.core.common.action.StorageDomainPoolParametersBase)

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