Search in sources :

Example 1 with Sessions

use of org.ovirt.engine.api.model.Sessions in project ovirt-engine by oVirt.

the class BackendVmSessionsResource method list.

@Override
public Sessions list() {
    Object obj = getEntity(entityType, QueryType.GetVmByVmId, new IdQueryParameters(vmId), vmId.toString(), true);
    VM vm = (VM) obj;
    Sessions sessions = VmMapper.map(vm, new Sessions());
    org.ovirt.engine.api.model.Vm vmModel = new org.ovirt.engine.api.model.Vm();
    vmModel.setId(vm.getId().toString());
    if (sessions.isSetSessions()) {
        for (Session session : sessions.getSessions()) {
            setSessionId(session);
            setSessionVmId(vmModel, session);
            // only console user assumed to be an ovirt user, and only an ovirt-user has an ID & href
            if (session.isSetConsoleUser() && session.isConsoleUser()) {
                addLinksIncludingUser(session);
            } else {
                addLinks(session, org.ovirt.engine.api.model.Vm.class);
            }
        }
    }
    return sessions;
}
Also used : IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) VM(org.ovirt.engine.core.common.businessentities.VM) Sessions(org.ovirt.engine.api.model.Sessions) Session(org.ovirt.engine.api.model.Session)

Example 2 with Sessions

use of org.ovirt.engine.api.model.Sessions in project ovirt-engine by oVirt.

the class V3SessionsInAdapter method adapt.

@Override
public Sessions adapt(V3Sessions from) {
    Sessions to = new Sessions();
    if (from.isSetActions()) {
        to.setActions(adaptIn(from.getActions()));
    }
    if (from.isSetActive()) {
        to.setActive(from.getActive());
    }
    if (from.isSetSize()) {
        to.setSize(from.getSize());
    }
    if (from.isSetTotal()) {
        to.setTotal(from.getTotal());
    }
    to.getSessions().addAll(adaptIn(from.getSessions()));
    return to;
}
Also used : V3Sessions(org.ovirt.engine.api.v3.types.V3Sessions) Sessions(org.ovirt.engine.api.model.Sessions)

Example 3 with Sessions

use of org.ovirt.engine.api.model.Sessions in project ovirt-engine by oVirt.

the class VmMapper method map.

/**
 * This method maps the VM's open sessions with users. Engine currently does not regard sessions as business
 * entities, and therefore a session doesn't have an ID. Generating IDs for sessions is outside the scope of this
 * method and should be done by the method's invoker.
 *
 * The session involves a user. Sometimes this is an ovirt-user, and sometimes not. Engine provides only the user
 * name, and this method maps it by placing it inside a 'User' object in the session. If invokers want to identify
 * the ovirt user and provide a link to it, it's their responsibility to do so; this is out of the scope of this
 * method.
 */
public static Sessions map(org.ovirt.engine.core.common.businessentities.VM vm, Sessions sessions) {
    if (sessions == null) {
        sessions = new Sessions();
    }
    mapConsoleSession(vm, sessions);
    mapGuestSessions(vm, sessions);
    return sessions;
}
Also used : Sessions(org.ovirt.engine.api.model.Sessions)

Example 4 with Sessions

use of org.ovirt.engine.api.model.Sessions in project ovirt-engine by oVirt.

the class BackendVmSessionsResourceTest method testList.

@Test
public void testList() throws Exception {
    BackendUserResource userResourceMock = mock(BackendUserResource.class);
    resource.setUserResource(userResourceMock);
    resource.setUriInfo(setUpBasicUriExpectations());
    setUpGetEntityExpectations(QueryType.GetVmByVmId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, getEntity(0));
    setUpGetEntityExpectations(QueryType.GetDbUserByUserNameAndDomain, GetDbUserByUserNameAndDomainQueryParameters.class, new String[] { "UserName", "DomainName" }, new Object[] { "admin", "internal" }, null);
    Sessions sessions = resource.list();
    assertEquals(2, sessions.getSessions().size());
    assertNotNull(sessions.getSessions().get(0).getVm());
    assertNotNull(sessions.getSessions().get(1).getVm());
    assertNotNull(sessions.getSessions().get(0).getId());
    assertNotNull(sessions.getSessions().get(1).getId());
}
Also used : BackendUserResource(org.ovirt.engine.api.restapi.resource.aaa.BackendUserResource) Sessions(org.ovirt.engine.api.model.Sessions) Test(org.junit.Test)

Example 5 with Sessions

use of org.ovirt.engine.api.model.Sessions in project ovirt-engine by oVirt.

the class VmMapperTest method testMapSessions.

@Test
public void testMapSessions() {
    org.ovirt.engine.core.common.businessentities.VM vm = new org.ovirt.engine.core.common.businessentities.VM();
    VmDynamic vmDynamic = new VmDynamic();
    vmDynamic.setConsoleCurrentUserName("admin");
    vmDynamic.setClientIp("1.1.1.1");
    vmDynamic.setGuestCurrentUserName("Ori");
    vm.setDynamicData(vmDynamic);
    Sessions sessions = VmMapper.map(vm, new Sessions());
    assertNotNull(sessions);
    assertEquals(2, sessions.getSessions().size());
    Session consoleSession = sessions.getSessions().get(0).getUser().getUserName().equals("admin") ? sessions.getSessions().get(0) : sessions.getSessions().get(1);
    Session guestSession = sessions.getSessions().get(0).getUser().getUserName().equals("Ori") ? sessions.getSessions().get(0) : sessions.getSessions().get(1);
    assertEquals("admin", consoleSession.getUser().getUserName());
    assertEquals("1.1.1.1", consoleSession.getIp().getAddress());
    assertTrue(consoleSession.isConsoleUser());
    assertEquals("Ori", guestSession.getUser().getUserName());
}
Also used : VmDynamic(org.ovirt.engine.core.common.businessentities.VmDynamic) Sessions(org.ovirt.engine.api.model.Sessions) Session(org.ovirt.engine.api.model.Session) Test(org.junit.Test)

Aggregations

Sessions (org.ovirt.engine.api.model.Sessions)5 Test (org.junit.Test)2 Session (org.ovirt.engine.api.model.Session)2 BackendUserResource (org.ovirt.engine.api.restapi.resource.aaa.BackendUserResource)1 V3Sessions (org.ovirt.engine.api.v3.types.V3Sessions)1 VM (org.ovirt.engine.core.common.businessentities.VM)1 VmDynamic (org.ovirt.engine.core.common.businessentities.VmDynamic)1 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)1