/** Special handling of adding links to the user and domain of the session. */ private void addLinksIncludingUser(Session session) { String domainName = session.getUser().getDomain().getName(); addLinks(session, org.ovirt.engine.api.model.VM.class); session.getUser().setDomain(new Domain()); session.getUser().getDomain().setName(domainName); setSessionUser(session); }
@Override public Sessions list() { Object obj = getEntity( entityType, VdcQueryType.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; }
/** * The console user, if exists, is a real ovirt-user. Use its name to get ID and herf information, * and set them inside the user object, inside the session. */ private void setSessionUser(Session session) { User user = getUserResource() .getUserByNameAndDomain( session.getUser().getUserName(), session.getUser().getDomain().getName()); if (user != null) { session.getUser().setId(user.getId()); session.getUser().setHref(user.getHref()); session.getUser().getDomain().setId(user.getDomain().getId()); session.getUser().getDomain().setHref(user.getDomain().getHref()); } }
@Override public Session get() { // Get all sessions and search for the session with this ID. Must be done this way because // there's no way to get session by ID from the engine. Sessions sessions = parent.list(); if (sessions.isSetSessions()) { for (Session session : sessions.getSessions()) { if (session.getId().equals(id)) { return session; } } } throw new WebApplicationException(Response.Status.NOT_FOUND); // shouldn't happen. }
/** * A session is not a business-entity in the engine and does not have an ID. This method generates * an ID for the session object, based on its attributes. */ private void setSessionId(Session session) { String idString = session.getUser().getName(); if (session.isSetIp() && session.getIp().isSetAddress()) { idString += session.getIp().getAddress(); } if (session.isSetProtocol()) { idString += session.getProtocol(); } session.setId(GuidUtils.generateGuidUsingMd5(idString).toString()); }
private void setSessionVmId(org.ovirt.engine.api.model.VM vmModel, Session session) { session.setVm(vmModel); }