Search in sources :

Example 36 with AsyncTaskStatus

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

the class BackendTemplatesResourceTest method testAddUseExistingIcons.

@Test
public void testAddUseExistingIcons() throws Exception {
    setUpGetGraphicsExpectations(1);
    setUpGetConsoleExpectations(0, 0, 1);
    setUpGetSoundcardExpectations(1);
    setUpGetBallooningExpectations(0, 0);
    setUpGetEntityExpectations(QueryType.GetVmByVmId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[1] }, setUpVm(GUIDS[1]));
    setUpAddExpectations();
    setUpCreationExpectations(ActionType.AddVmTemplate, AddVmTemplateParameters.class, new String[] { "Name", "Description" }, new Object[] { NAMES[0], DESCRIPTIONS[0] }, true, true, GUIDS[0], asList(GUIDS[2]), asList(new AsyncTaskStatus(AsyncTaskStatusEnum.finished)), QueryType.GetVmTemplate, GetVmTemplateParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, getEntity(0));
    final Template restModel = getRestModel(0);
    restModel.setSmallIcon(IconTestHelpler.createIcon(GUIDS[2]));
    restModel.setLargeIcon(IconTestHelpler.createIcon(GUIDS[3]));
    Response response = doAdd(restModel);
    assertEquals(201, response.getStatus());
    verifyModel((Template) response.getEntity(), 0);
    assertNull(((Template) response.getEntity()).getCreationStatus());
}
Also used : Response(javax.ws.rs.core.Response) AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) Template(org.ovirt.engine.api.model.Template) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) Test(org.junit.Test)

Example 37 with AsyncTaskStatus

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

the class BackendStorageDomainDisksResourceTest 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));
    Disk model = getModel();
    setUpCreationExpectations(ActionType.AddDisk, AddDiskParameters.class, new String[] { "StorageDomainId" }, new Object[] { GUIDS[3] }, true, true, GUIDS[0], asList(storagePoolId), 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 38 with AsyncTaskStatus

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

the class CreationMapper method map.

@Mapping(from = List.class, to = Creation.class)
public static Creation map(List<AsyncTaskStatus> entity, Creation template) {
    Creation model = template != null ? template : new Creation();
    CreationStatus asyncStatus = null;
    for (AsyncTaskStatus task : entity) {
        asyncStatus = AsyncTaskMapper.map(task, asyncStatus);
    }
    model.setStatus(asyncStatus.value());
    if (asyncStatus == CreationStatus.FAILED) {
        model.setFault(new Fault());
        for (AsyncTaskStatus task : entity) {
            if (task.getException() != null) {
                model.getFault().setDetail(task.getException().toString());
                break;
            }
        }
    }
    return model;
}
Also used : Creation(org.ovirt.engine.api.model.Creation) AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) Fault(org.ovirt.engine.api.model.Fault) CreationStatus(org.ovirt.engine.api.model.CreationStatus)

Example 39 with AsyncTaskStatus

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

the class ActionMapper method map.

@Mapping(from = List.class, to = Action.class)
public static Action map(List<AsyncTaskStatus> entity, Action template) {
    Action model = template != null ? template : new Action();
    CreationStatus asyncStatus = null;
    for (AsyncTaskStatus task : entity) {
        asyncStatus = AsyncTaskMapper.map(task, asyncStatus);
    }
    model.setStatus(asyncStatus.value());
    if (asyncStatus == CreationStatus.FAILED) {
        model.setFault(new Fault());
        for (AsyncTaskStatus task : entity) {
            if (task.getException() != null) {
                model.getFault().setDetail(task.getException().toString());
                break;
            }
        }
    }
    return model;
}
Also used : Action(org.ovirt.engine.api.model.Action) AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) Fault(org.ovirt.engine.api.model.Fault) CreationStatus(org.ovirt.engine.api.model.CreationStatus)

Example 40 with AsyncTaskStatus

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

the class SPMAsyncTask method stopTask.

@Override
public void stopTask(boolean forceFinish) {
    if (getState() != AsyncTaskState.AttemptingEndAction && getState() != AsyncTaskState.Cleared && getState() != AsyncTaskState.ClearFailed && !getLastTaskStatus().getTaskIsInUnusualState()) {
        try {
            log.info("SPMAsyncTask::StopTask: Attempting to stop task '{}' (Parent Command '{}', Parameters" + " Type '{}').", getVdsmTaskId(), getParameters().getDbAsyncTask().getActionType(), getParameters().getClass().getName());
            coco.stopTask(getStoragePoolID(), getVdsmTaskId());
        } catch (RuntimeException e) {
            log.error("SPMAsyncTask::StopTask: Error during stopping task '{}': {}", getVdsmTaskId(), e.getMessage());
            log.debug("Exception", e);
        } finally {
            if (forceFinish) {
                // Force finish flag allows to force the task completion, regardless of the result from call to SPMStopTask
                setState(AsyncTaskState.Ended);
                setLastTaskStatus(new AsyncTaskStatus(AsyncTaskStatusEnum.finished));
            } else {
                setState(AsyncTaskState.Polling);
            }
        }
    }
}
Also used : AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus)

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